blob: 0dd6b988820f8ed32be3d4c2b9ec607aca3eca12 [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"
Hartmut Hackmann5823b3a2008-04-22 14:46:08 -030036#include <dvb_frontend.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
Andrew de Quincey1f10c7a2006-08-08 09:10:09 -030038#include "mt352.h"
39#include "mt352_priv.h" /* FIXME */
40#include "tda1004x.h"
41#include "nxt200x.h"
Mauro Carvalho Chehabbc36a682008-04-22 14:45:27 -030042#include "tuner-xc2028.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
Igor M. Liplianine2ac28f2006-08-08 09:10:10 -030044#include "tda10086.h"
45#include "tda826x.h"
Michael Krufky8ce47da2007-04-27 12:31:14 -030046#include "tda827x.h"
Igor M. Liplianine2ac28f2006-08-08 09:10:10 -030047#include "isl6421.h"
Hartmut Hackmann4b1431c2008-04-22 14:42:09 -030048#include "isl6405.h"
Hartmut Hackmann6ab465a2008-04-22 14:42:11 -030049#include "lnbp21.h"
Michael Krufkycb89cd32008-04-22 14:46:16 -030050#include "tuner-simple.h"
Michael Krufky8ce47da2007-04-27 12:31:14 -030051
Linus Torvalds1da177e2005-04-16 15:20:36 -070052MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
53MODULE_LICENSE("GPL");
54
Douglas Schilling Landgrafff699e62008-04-22 14:41:48 -030055static unsigned int antenna_pwr;
Mauro Carvalho Chehab86ddd962005-07-12 13:58:47 -070056
Linus Torvalds1da177e2005-04-16 15:20:36 -070057module_param(antenna_pwr, int, 0444);
58MODULE_PARM_DESC(antenna_pwr,"enable antenna power (Pinnacle 300i)");
59
Douglas Schilling Landgrafff699e62008-04-22 14:41:48 -030060static int use_frontend;
Stephan Berberigb331daa2006-12-20 09:37:05 -030061module_param(use_frontend, int, 0644);
62MODULE_PARM_DESC(use_frontend,"for cards with multiple frontends (0: terrestrial, 1: satellite)");
Nico Sabbi1f683cd2006-11-15 22:06:56 -030063
Douglas Schilling Landgrafff699e62008-04-22 14:41:48 -030064static int debug;
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -030065module_param(debug, int, 0644);
66MODULE_PARM_DESC(debug, "Turn on/off module debugging (default:off).");
67
Janne Grunau78e92002008-04-09 19:13:13 -030068DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
69
Trent Piephocf3c34c2007-03-07 18:19:48 -030070#define dprintk(fmt, arg...) do { if (debug) \
71 printk(KERN_DEBUG "%s/dvb: " fmt, dev->name , ## arg); } while(0)
72
73/* Print a warning */
74#define wprintk(fmt, arg...) \
75 printk(KERN_WARNING "%s/dvb: " fmt, dev->name, ## arg)
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -030076
77/* ------------------------------------------------------------------
78 * mt352 based DVB-T cards
79 */
80
Linus Torvalds1da177e2005-04-16 15:20:36 -070081static int pinnacle_antenna_pwr(struct saa7134_dev *dev, int on)
82{
83 u32 ok;
84
85 if (!on) {
86 saa_setl(SAA7134_GPIO_GPMODE0 >> 2, (1 << 26));
87 saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 26));
88 return 0;
89 }
90
91 saa_setl(SAA7134_GPIO_GPMODE0 >> 2, (1 << 26));
92 saa_setl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 26));
93 udelay(10);
94
95 saa_setl(SAA7134_GPIO_GPMODE0 >> 2, (1 << 28));
96 saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 28));
97 udelay(10);
98 saa_setl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 28));
99 udelay(10);
100 ok = saa_readl(SAA7134_GPIO_GPSTATUS0) & (1 << 27);
Hartmut Hackmann5823b3a2008-04-22 14:46:08 -0300101 dprintk("%s %s\n", __func__, ok ? "on" : "off");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102
103 if (!ok)
104 saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 26));
105 return ok;
106}
107
108static int mt352_pinnacle_init(struct dvb_frontend* fe)
109{
110 static u8 clock_config [] = { CLOCK_CTL, 0x3d, 0x28 };
111 static u8 reset [] = { RESET, 0x80 };
112 static u8 adc_ctl_1_cfg [] = { ADC_CTL_1, 0x40 };
113 static u8 agc_cfg [] = { AGC_TARGET, 0x28, 0xa0 };
114 static u8 capt_range_cfg[] = { CAPT_RANGE, 0x31 };
115 static u8 fsm_ctl_cfg[] = { 0x7b, 0x04 };
116 static u8 gpp_ctl_cfg [] = { GPP_CTL, 0x0f };
117 static u8 scan_ctl_cfg [] = { SCAN_CTL, 0x0d };
118 static u8 irq_cfg [] = { INTERRUPT_EN_0, 0x00, 0x00, 0x00, 0x00 };
119 struct saa7134_dev *dev= fe->dvb->priv;
120
Hartmut Hackmann5823b3a2008-04-22 14:46:08 -0300121 dprintk("%s called\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
123 mt352_write(fe, clock_config, sizeof(clock_config));
124 udelay(200);
125 mt352_write(fe, reset, sizeof(reset));
126 mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
127 mt352_write(fe, agc_cfg, sizeof(agc_cfg));
128 mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
129 mt352_write(fe, gpp_ctl_cfg, sizeof(gpp_ctl_cfg));
130
131 mt352_write(fe, fsm_ctl_cfg, sizeof(fsm_ctl_cfg));
132 mt352_write(fe, scan_ctl_cfg, sizeof(scan_ctl_cfg));
133 mt352_write(fe, irq_cfg, sizeof(irq_cfg));
Hartmut Hackmanndf8cf702006-03-03 12:09:26 -0300134
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 return 0;
136}
137
Jose Alberto Regueroa78d0bf2006-02-07 06:25:14 -0200138static int mt352_aver777_init(struct dvb_frontend* fe)
139{
140 static u8 clock_config [] = { CLOCK_CTL, 0x38, 0x2d };
141 static u8 reset [] = { RESET, 0x80 };
142 static u8 adc_ctl_1_cfg [] = { ADC_CTL_1, 0x40 };
143 static u8 agc_cfg [] = { AGC_TARGET, 0x28, 0xa0 };
144 static u8 capt_range_cfg[] = { CAPT_RANGE, 0x33 };
145
146 mt352_write(fe, clock_config, sizeof(clock_config));
147 udelay(200);
148 mt352_write(fe, reset, sizeof(reset));
149 mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
150 mt352_write(fe, agc_cfg, sizeof(agc_cfg));
151 mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
152
153 return 0;
154}
155
Tim Farrington6e501a32008-06-15 13:33:42 -0300156static int mt352_avermedia_xc3028_init(struct dvb_frontend *fe)
Mauro Carvalho Chehab95a2fdb2008-03-28 17:52:44 -0300157{
Tim Farrington6e501a32008-06-15 13:33:42 -0300158 static u8 clock_config [] = { CLOCK_CTL, 0x38, 0x2d };
159 static u8 reset [] = { RESET, 0x80 };
160 static u8 adc_ctl_1_cfg [] = { ADC_CTL_1, 0x40 };
161 static u8 agc_cfg [] = { AGC_TARGET, 0xe };
Mauro Carvalho Chehab95a2fdb2008-03-28 17:52:44 -0300162 static u8 capt_range_cfg[] = { CAPT_RANGE, 0x33 };
163
164 mt352_write(fe, clock_config, sizeof(clock_config));
165 udelay(200);
166 mt352_write(fe, reset, sizeof(reset));
167 mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
168 mt352_write(fe, agc_cfg, sizeof(agc_cfg));
169 mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
Mauro Carvalho Chehab95a2fdb2008-03-28 17:52:44 -0300170 return 0;
171}
172
Andrew de Quincey0463f122006-05-16 17:22:02 -0300173static int mt352_pinnacle_tuner_set_params(struct dvb_frontend* fe,
174 struct dvb_frontend_parameters* params)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175{
Hartmut Hackmanndf8cf702006-03-03 12:09:26 -0300176 u8 off[] = { 0x00, 0xf1};
177 u8 on[] = { 0x00, 0x71};
178 struct i2c_msg msg = {.addr=0x43, .flags=0, .buf=off, .len = sizeof(off)};
179
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 struct saa7134_dev *dev = fe->dvb->priv;
181 struct v4l2_frequency f;
182
183 /* set frequency (mt2050) */
184 f.tuner = 0;
185 f.type = V4L2_TUNER_DIGITAL_TV;
186 f.frequency = params->frequency / 1000 * 16 / 1000;
Patrick Boettcherdea74862006-05-14 05:01:31 -0300187 if (fe->ops.i2c_gate_ctrl)
188 fe->ops.i2c_gate_ctrl(fe, 1);
Hartmut Hackmanndf8cf702006-03-03 12:09:26 -0300189 i2c_transfer(&dev->i2c_adap, &msg, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190 saa7134_i2c_call_clients(dev,VIDIOC_S_FREQUENCY,&f);
Hartmut Hackmanndf8cf702006-03-03 12:09:26 -0300191 msg.buf = on;
Patrick Boettcherdea74862006-05-14 05:01:31 -0300192 if (fe->ops.i2c_gate_ctrl)
193 fe->ops.i2c_gate_ctrl(fe, 1);
Hartmut Hackmanndf8cf702006-03-03 12:09:26 -0300194 i2c_transfer(&dev->i2c_adap, &msg, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195
196 pinnacle_antenna_pwr(dev, antenna_pwr);
197
198 /* mt352 setup */
Andrew de Quincey0463f122006-05-16 17:22:02 -0300199 return mt352_pinnacle_init(fe);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200}
201
202static struct mt352_config pinnacle_300i = {
203 .demod_address = 0x3c >> 1,
204 .adc_clock = 20333,
205 .if2 = 36150,
206 .no_tuner = 1,
207 .demod_init = mt352_pinnacle_init,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208};
Jose Alberto Regueroa78d0bf2006-02-07 06:25:14 -0200209
210static struct mt352_config avermedia_777 = {
211 .demod_address = 0xf,
212 .demod_init = mt352_aver777_init,
Jose Alberto Regueroa78d0bf2006-02-07 06:25:14 -0200213};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214
Tim Farrington6e501a32008-06-15 13:33:42 -0300215static struct mt352_config avermedia_xc3028_mt352_dev = {
Mauro Carvalho Chehabbc36a682008-04-22 14:45:27 -0300216 .demod_address = (0x1e >> 1),
217 .no_tuner = 1,
Tim Farrington6e501a32008-06-15 13:33:42 -0300218 .demod_init = mt352_avermedia_xc3028_init,
Mauro Carvalho Chehabbc36a682008-04-22 14:45:27 -0300219};
220
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300221/* ==================================================================
222 * tda1004x based DVB-T cards, helper functions
223 */
224
225static int philips_tda1004x_request_firmware(struct dvb_frontend *fe,
226 const struct firmware **fw, char *name)
Mauro Carvalho Chehab86ddd962005-07-12 13:58:47 -0700227{
228 struct saa7134_dev *dev = fe->dvb->priv;
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300229 return request_firmware(fw, name, &dev->pci->dev);
230}
231
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300232/* ------------------------------------------------------------------
233 * these tuners are tu1216, td1316(a)
234 */
235
236static int philips_tda6651_pll_set(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
237{
238 struct saa7134_dev *dev = fe->dvb->priv;
239 struct tda1004x_state *state = fe->demodulator_priv;
240 u8 addr = state->config->tuner_address;
Mauro Carvalho Chehab86ddd962005-07-12 13:58:47 -0700241 u8 tuner_buf[4];
Hartmut Hackmann2cf36ac2005-11-08 21:36:32 -0800242 struct i2c_msg tuner_msg = {.addr = addr,.flags = 0,.buf = tuner_buf,.len =
Mauro Carvalho Chehab86ddd962005-07-12 13:58:47 -0700243 sizeof(tuner_buf) };
244 int tuner_frequency = 0;
245 u8 band, cp, filter;
246
247 /* determine charge pump */
248 tuner_frequency = params->frequency + 36166000;
249 if (tuner_frequency < 87000000)
250 return -EINVAL;
251 else if (tuner_frequency < 130000000)
252 cp = 3;
253 else if (tuner_frequency < 160000000)
254 cp = 5;
255 else if (tuner_frequency < 200000000)
256 cp = 6;
257 else if (tuner_frequency < 290000000)
258 cp = 3;
259 else if (tuner_frequency < 420000000)
260 cp = 5;
261 else if (tuner_frequency < 480000000)
262 cp = 6;
263 else if (tuner_frequency < 620000000)
264 cp = 3;
265 else if (tuner_frequency < 830000000)
266 cp = 5;
267 else if (tuner_frequency < 895000000)
268 cp = 7;
269 else
270 return -EINVAL;
271
272 /* determine band */
273 if (params->frequency < 49000000)
274 return -EINVAL;
275 else if (params->frequency < 161000000)
276 band = 1;
277 else if (params->frequency < 444000000)
278 band = 2;
279 else if (params->frequency < 861000000)
280 band = 4;
281 else
282 return -EINVAL;
283
284 /* setup PLL filter */
285 switch (params->u.ofdm.bandwidth) {
286 case BANDWIDTH_6_MHZ:
287 filter = 0;
288 break;
289
290 case BANDWIDTH_7_MHZ:
291 filter = 0;
292 break;
293
294 case BANDWIDTH_8_MHZ:
295 filter = 1;
296 break;
297
298 default:
299 return -EINVAL;
300 }
301
302 /* calculate divisor
303 * ((36166000+((1000000/6)/2)) + Finput)/(1000000/6)
304 */
305 tuner_frequency = (((params->frequency / 1000) * 6) + 217496) / 1000;
306
307 /* setup tuner buffer */
308 tuner_buf[0] = (tuner_frequency >> 8) & 0x7f;
309 tuner_buf[1] = tuner_frequency & 0xff;
310 tuner_buf[2] = 0xca;
311 tuner_buf[3] = (cp << 5) | (filter << 3) | band;
312
Patrick Boettcherdea74862006-05-14 05:01:31 -0300313 if (fe->ops.i2c_gate_ctrl)
314 fe->ops.i2c_gate_ctrl(fe, 1);
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300315 if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1) {
Trent Piephocf3c34c2007-03-07 18:19:48 -0300316 wprintk("could not write to tuner at addr: 0x%02x\n",
317 addr << 1);
Mauro Carvalho Chehab86ddd962005-07-12 13:58:47 -0700318 return -EIO;
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300319 }
Mauro Carvalho Chehab86ddd962005-07-12 13:58:47 -0700320 msleep(1);
321 return 0;
322}
323
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300324static int philips_tu1216_init(struct dvb_frontend *fe)
Hartmut Hackmann2cf36ac2005-11-08 21:36:32 -0800325{
326 struct saa7134_dev *dev = fe->dvb->priv;
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300327 struct tda1004x_state *state = fe->demodulator_priv;
328 u8 addr = state->config->tuner_address;
Hartmut Hackmann2cf36ac2005-11-08 21:36:32 -0800329 static u8 tu1216_init[] = { 0x0b, 0xf5, 0x85, 0xab };
330 struct i2c_msg tuner_msg = {.addr = addr,.flags = 0,.buf = tu1216_init,.len = sizeof(tu1216_init) };
331
332 /* setup PLL configuration */
Patrick Boettcherdea74862006-05-14 05:01:31 -0300333 if (fe->ops.i2c_gate_ctrl)
334 fe->ops.i2c_gate_ctrl(fe, 1);
Hartmut Hackmann2cf36ac2005-11-08 21:36:32 -0800335 if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1)
336 return -EIO;
337 msleep(1);
338
339 return 0;
340}
341
342/* ------------------------------------------------------------------ */
343
Hartmut Hackmann2cf36ac2005-11-08 21:36:32 -0800344static struct tda1004x_config philips_tu1216_60_config = {
Mauro Carvalho Chehab86ddd962005-07-12 13:58:47 -0700345 .demod_address = 0x8,
346 .invert = 1,
Hartmut Hackmann2cf36ac2005-11-08 21:36:32 -0800347 .invert_oclk = 0,
Mauro Carvalho Chehab86ddd962005-07-12 13:58:47 -0700348 .xtal_freq = TDA10046_XTAL_4M,
349 .agc_config = TDA10046_AGC_DEFAULT,
350 .if_freq = TDA10046_FREQ_3617,
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300351 .tuner_address = 0x60,
352 .request_firmware = philips_tda1004x_request_firmware
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353};
354
Hartmut Hackmann2cf36ac2005-11-08 21:36:32 -0800355static struct tda1004x_config philips_tu1216_61_config = {
356
357 .demod_address = 0x8,
358 .invert = 1,
359 .invert_oclk = 0,
360 .xtal_freq = TDA10046_XTAL_4M,
361 .agc_config = TDA10046_AGC_DEFAULT,
362 .if_freq = TDA10046_FREQ_3617,
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300363 .tuner_address = 0x61,
364 .request_firmware = philips_tda1004x_request_firmware
Hartmut Hackmann2cf36ac2005-11-08 21:36:32 -0800365};
366
367/* ------------------------------------------------------------------ */
368
Hartmut Hackmanncbb94522006-10-30 20:00:16 -0300369static int philips_td1316_tuner_init(struct dvb_frontend *fe)
Hartmut Hackmann2cf36ac2005-11-08 21:36:32 -0800370{
371 struct saa7134_dev *dev = fe->dvb->priv;
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300372 struct tda1004x_state *state = fe->demodulator_priv;
373 u8 addr = state->config->tuner_address;
Hartmut Hackmann2cf36ac2005-11-08 21:36:32 -0800374 static u8 msg[] = { 0x0b, 0xf5, 0x86, 0xab };
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300375 struct i2c_msg init_msg = {.addr = addr,.flags = 0,.buf = msg,.len = sizeof(msg) };
Hartmut Hackmann2cf36ac2005-11-08 21:36:32 -0800376
377 /* setup PLL configuration */
Patrick Boettcherdea74862006-05-14 05:01:31 -0300378 if (fe->ops.i2c_gate_ctrl)
379 fe->ops.i2c_gate_ctrl(fe, 1);
Hartmut Hackmann2cf36ac2005-11-08 21:36:32 -0800380 if (i2c_transfer(&dev->i2c_adap, &init_msg, 1) != 1)
381 return -EIO;
Hartmut Hackmann2cf36ac2005-11-08 21:36:32 -0800382 return 0;
383}
384
Andrew de Quinceya79ddae2006-04-18 17:47:11 -0300385static int philips_td1316_tuner_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
Hartmut Hackmann2cf36ac2005-11-08 21:36:32 -0800386{
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300387 return philips_tda6651_pll_set(fe, params);
Hartmut Hackmann2cf36ac2005-11-08 21:36:32 -0800388}
389
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300390static int philips_td1316_tuner_sleep(struct dvb_frontend *fe)
391{
392 struct saa7134_dev *dev = fe->dvb->priv;
393 struct tda1004x_state *state = fe->demodulator_priv;
394 u8 addr = state->config->tuner_address;
395 static u8 msg[] = { 0x0b, 0xdc, 0x86, 0xa4 };
396 struct i2c_msg analog_msg = {.addr = addr,.flags = 0,.buf = msg,.len = sizeof(msg) };
397
398 /* switch the tuner to analog mode */
399 if (fe->ops.i2c_gate_ctrl)
400 fe->ops.i2c_gate_ctrl(fe, 1);
401 if (i2c_transfer(&dev->i2c_adap, &analog_msg, 1) != 1)
402 return -EIO;
403 return 0;
404}
405
406/* ------------------------------------------------------------------ */
407
Hartmut Hackmanncbb94522006-10-30 20:00:16 -0300408static int philips_europa_tuner_init(struct dvb_frontend *fe)
409{
410 struct saa7134_dev *dev = fe->dvb->priv;
411 static u8 msg[] = { 0x00, 0x40};
412 struct i2c_msg init_msg = {.addr = 0x43,.flags = 0,.buf = msg,.len = sizeof(msg) };
413
414
415 if (philips_td1316_tuner_init(fe))
416 return -EIO;
417 msleep(1);
418 if (i2c_transfer(&dev->i2c_adap, &init_msg, 1) != 1)
419 return -EIO;
420
421 return 0;
422}
423
Andrew de Quinceya79ddae2006-04-18 17:47:11 -0300424static int philips_europa_tuner_sleep(struct dvb_frontend *fe)
Hartmut Hackmann2cf36ac2005-11-08 21:36:32 -0800425{
426 struct saa7134_dev *dev = fe->dvb->priv;
Hartmut Hackmann2cf36ac2005-11-08 21:36:32 -0800427
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300428 static u8 msg[] = { 0x00, 0x14 };
429 struct i2c_msg analog_msg = {.addr = 0x43,.flags = 0,.buf = msg,.len = sizeof(msg) };
430
431 if (philips_td1316_tuner_sleep(fe))
432 return -EIO;
Hartmut Hackmann2cf36ac2005-11-08 21:36:32 -0800433
434 /* switch the board to analog mode */
Patrick Boettcherdea74862006-05-14 05:01:31 -0300435 if (fe->ops.i2c_gate_ctrl)
436 fe->ops.i2c_gate_ctrl(fe, 1);
Hartmut Hackmann2cf36ac2005-11-08 21:36:32 -0800437 i2c_transfer(&dev->i2c_adap, &analog_msg, 1);
Andrew de Quinceya79ddae2006-04-18 17:47:11 -0300438 return 0;
439}
440
441static int philips_europa_demod_sleep(struct dvb_frontend *fe)
442{
443 struct saa7134_dev *dev = fe->dvb->priv;
444
445 if (dev->original_demod_sleep)
446 dev->original_demod_sleep(fe);
Patrick Boettcherdea74862006-05-14 05:01:31 -0300447 fe->ops.i2c_gate_ctrl(fe, 1);
Andrew de Quinceya79ddae2006-04-18 17:47:11 -0300448 return 0;
Hartmut Hackmann2cf36ac2005-11-08 21:36:32 -0800449}
450
451static struct tda1004x_config philips_europa_config = {
452
453 .demod_address = 0x8,
454 .invert = 0,
455 .invert_oclk = 0,
456 .xtal_freq = TDA10046_XTAL_4M,
457 .agc_config = TDA10046_AGC_IFO_AUTO_POS,
458 .if_freq = TDA10046_FREQ_052,
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300459 .tuner_address = 0x61,
460 .request_firmware = philips_tda1004x_request_firmware
Hartmut Hackmann2cf36ac2005-11-08 21:36:32 -0800461};
462
Mauro Carvalho Chehab86ddd962005-07-12 13:58:47 -0700463static struct tda1004x_config medion_cardbus = {
464 .demod_address = 0x08,
465 .invert = 1,
466 .invert_oclk = 0,
467 .xtal_freq = TDA10046_XTAL_16M,
468 .agc_config = TDA10046_AGC_IFO_AUTO_NEG,
469 .if_freq = TDA10046_FREQ_3613,
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300470 .tuner_address = 0x61,
471 .request_firmware = philips_tda1004x_request_firmware
Mauro Carvalho Chehab86ddd962005-07-12 13:58:47 -0700472};
473
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300474/* ------------------------------------------------------------------
475 * tda 1004x based cards with philips silicon tuner
476 */
477
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300478static int tda8290_i2c_gate_ctrl( struct dvb_frontend* fe, int enable)
479{
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300480 struct tda1004x_state *state = fe->demodulator_priv;
481
482 u8 addr = state->config->i2c_gate;
483 static u8 tda8290_close[] = { 0x21, 0xc0};
484 static u8 tda8290_open[] = { 0x21, 0x80};
485 struct i2c_msg tda8290_msg = {.addr = addr,.flags = 0, .len = 2};
486 if (enable) {
487 tda8290_msg.buf = tda8290_close;
488 } else {
489 tda8290_msg.buf = tda8290_open;
490 }
Hartmut Hackmann06be3032007-04-27 12:31:15 -0300491 if (i2c_transfer(state->i2c, &tda8290_msg, 1) != 1) {
Trent Piephocf3c34c2007-03-07 18:19:48 -0300492 struct saa7134_dev *dev = fe->dvb->priv;
493 wprintk("could not access tda8290 I2C gate\n");
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300494 return -EIO;
495 }
496 msleep(20);
497 return 0;
498}
499
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300500static int philips_tda827x_tuner_init(struct dvb_frontend *fe)
Hartmut Hackmann587d2fd2006-10-06 19:13:50 -0300501{
502 struct saa7134_dev *dev = fe->dvb->priv;
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300503 struct tda1004x_state *state = fe->demodulator_priv;
Michael Krufky8ce47da2007-04-27 12:31:14 -0300504
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300505 switch (state->config->antenna_switch) {
506 case 0: break;
507 case 1: dprintk("setting GPIO21 to 0 (TV antenna?)\n");
508 saa7134_set_gpio(dev, 21, 0);
509 break;
510 case 2: dprintk("setting GPIO21 to 1 (Radio antenna?)\n");
511 saa7134_set_gpio(dev, 21, 1);
512 break;
513 }
Andrew de Quinceya79ddae2006-04-18 17:47:11 -0300514 return 0;
Hartmut Hackmann90e9df72005-11-08 21:38:42 -0800515}
516
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300517static int philips_tda827x_tuner_sleep(struct dvb_frontend *fe)
518{
519 struct saa7134_dev *dev = fe->dvb->priv;
520 struct tda1004x_state *state = fe->demodulator_priv;
Michael Krufky8ce47da2007-04-27 12:31:14 -0300521
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300522 switch (state->config->antenna_switch) {
523 case 0: break;
524 case 1: dprintk("setting GPIO21 to 1 (Radio antenna?)\n");
525 saa7134_set_gpio(dev, 21, 1);
526 break;
527 case 2: dprintk("setting GPIO21 to 0 (TV antenna?)\n");
528 saa7134_set_gpio(dev, 21, 0);
529 break;
530 }
531 return 0;
532}
533
Mauro Carvalho Chehabd557dab2008-04-30 15:27:55 -0300534static int configure_tda827x_fe(struct saa7134_dev *dev,
535 struct tda1004x_config *cdec_conf,
536 struct tda827x_config *tuner_conf)
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300537{
Hartmut Hackmann7bff4b42008-04-22 14:46:08 -0300538 dev->dvb.frontend = dvb_attach(tda10046_attach, cdec_conf, &dev->i2c_adap);
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300539 if (dev->dvb.frontend) {
Hartmut Hackmann7bff4b42008-04-22 14:46:08 -0300540 if (cdec_conf->i2c_gate)
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300541 dev->dvb.frontend->ops.i2c_gate_ctrl = tda8290_i2c_gate_ctrl;
Mauro Carvalho Chehabd557dab2008-04-30 15:27:55 -0300542 if (dvb_attach(tda827x_attach, dev->dvb.frontend,
543 cdec_conf->tuner_address,
544 &dev->i2c_adap, tuner_conf))
545 return 0;
546
547 wprintk("no tda827x tuner found at addr: %02x\n",
Hartmut Hackmann7bff4b42008-04-22 14:46:08 -0300548 cdec_conf->tuner_address);
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300549 }
Mauro Carvalho Chehabd557dab2008-04-30 15:27:55 -0300550 return -EINVAL;
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300551}
552
Hartmut Hackmann90e9df72005-11-08 21:38:42 -0800553/* ------------------------------------------------------------------ */
Edgar Simo261f5082007-08-20 14:06:00 -0300554
Hartmut Hackmann7bff4b42008-04-22 14:46:08 -0300555static struct tda827x_config tda827x_cfg_0 = {
Hartmut Hackmann7bff4b42008-04-22 14:46:08 -0300556 .init = philips_tda827x_tuner_init,
557 .sleep = philips_tda827x_tuner_sleep,
558 .config = 0,
559 .switch_addr = 0
560};
561
562static struct tda827x_config tda827x_cfg_1 = {
Hartmut Hackmann7bff4b42008-04-22 14:46:08 -0300563 .init = philips_tda827x_tuner_init,
564 .sleep = philips_tda827x_tuner_sleep,
565 .config = 1,
566 .switch_addr = 0x4b
567};
568
569static struct tda827x_config tda827x_cfg_2 = {
Hartmut Hackmann7bff4b42008-04-22 14:46:08 -0300570 .init = philips_tda827x_tuner_init,
571 .sleep = philips_tda827x_tuner_sleep,
572 .config = 2,
573 .switch_addr = 0x4b
574};
575
576static struct tda827x_config tda827x_cfg_2_sw42 = {
Hartmut Hackmann7bff4b42008-04-22 14:46:08 -0300577 .init = philips_tda827x_tuner_init,
578 .sleep = philips_tda827x_tuner_sleep,
579 .config = 2,
580 .switch_addr = 0x42
581};
582
583/* ------------------------------------------------------------------ */
584
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300585static struct tda1004x_config tda827x_lifeview_config = {
586 .demod_address = 0x08,
587 .invert = 1,
588 .invert_oclk = 0,
589 .xtal_freq = TDA10046_XTAL_16M,
590 .agc_config = TDA10046_AGC_TDA827X,
591 .gpio_config = TDA10046_GP11_I,
592 .if_freq = TDA10046_FREQ_045,
593 .tuner_address = 0x60,
594 .request_firmware = philips_tda1004x_request_firmware
595};
Hartmut Hackmann90e9df72005-11-08 21:38:42 -0800596
597static struct tda1004x_config philips_tiger_config = {
598 .demod_address = 0x08,
599 .invert = 1,
600 .invert_oclk = 0,
601 .xtal_freq = TDA10046_XTAL_16M,
Hartmut Hackmann1bb0e862007-04-27 12:31:10 -0300602 .agc_config = TDA10046_AGC_TDA827X,
603 .gpio_config = TDA10046_GP11_I,
Hartmut Hackmann550a9a52006-11-15 21:31:54 -0300604 .if_freq = TDA10046_FREQ_045,
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300605 .i2c_gate = 0x4b,
606 .tuner_address = 0x61,
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300607 .antenna_switch= 1,
608 .request_firmware = philips_tda1004x_request_firmware
Hartmut Hackmann550a9a52006-11-15 21:31:54 -0300609};
Hartmut Hackmann550a9a52006-11-15 21:31:54 -0300610
611static struct tda1004x_config cinergy_ht_config = {
612 .demod_address = 0x08,
613 .invert = 1,
614 .invert_oclk = 0,
615 .xtal_freq = TDA10046_XTAL_16M,
Hartmut Hackmann1bb0e862007-04-27 12:31:10 -0300616 .agc_config = TDA10046_AGC_TDA827X,
617 .gpio_config = TDA10046_GP01_I,
Hartmut Hackmann90e9df72005-11-08 21:38:42 -0800618 .if_freq = TDA10046_FREQ_045,
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300619 .i2c_gate = 0x4b,
620 .tuner_address = 0x61,
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300621 .request_firmware = philips_tda1004x_request_firmware
Hartmut Hackmann90e9df72005-11-08 21:38:42 -0800622};
623
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300624static struct tda1004x_config cinergy_ht_pci_config = {
625 .demod_address = 0x08,
626 .invert = 1,
627 .invert_oclk = 0,
628 .xtal_freq = TDA10046_XTAL_16M,
629 .agc_config = TDA10046_AGC_TDA827X,
630 .gpio_config = TDA10046_GP01_I,
631 .if_freq = TDA10046_FREQ_045,
632 .i2c_gate = 0x4b,
633 .tuner_address = 0x60,
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300634 .request_firmware = philips_tda1004x_request_firmware
635};
636
637static struct tda1004x_config philips_tiger_s_config = {
638 .demod_address = 0x08,
639 .invert = 1,
640 .invert_oclk = 0,
641 .xtal_freq = TDA10046_XTAL_16M,
642 .agc_config = TDA10046_AGC_TDA827X,
643 .gpio_config = TDA10046_GP01_I,
644 .if_freq = TDA10046_FREQ_045,
645 .i2c_gate = 0x4b,
646 .tuner_address = 0x61,
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300647 .antenna_switch= 1,
648 .request_firmware = philips_tda1004x_request_firmware
649};
Hartmut Hackmanndf42eaf2006-02-07 06:49:10 -0200650
Hartmut Hackmann587d2fd2006-10-06 19:13:50 -0300651static struct tda1004x_config pinnacle_pctv_310i_config = {
652 .demod_address = 0x08,
653 .invert = 1,
654 .invert_oclk = 0,
655 .xtal_freq = TDA10046_XTAL_16M,
Hartmut Hackmann1bb0e862007-04-27 12:31:10 -0300656 .agc_config = TDA10046_AGC_TDA827X,
657 .gpio_config = TDA10046_GP11_I,
Hartmut Hackmann587d2fd2006-10-06 19:13:50 -0300658 .if_freq = TDA10046_FREQ_045,
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300659 .i2c_gate = 0x4b,
660 .tuner_address = 0x61,
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300661 .request_firmware = philips_tda1004x_request_firmware
Hartmut Hackmann587d2fd2006-10-06 19:13:50 -0300662};
663
Thomas Gentyc6e53da2006-11-05 14:17:30 -0300664static struct tda1004x_config hauppauge_hvr_1110_config = {
665 .demod_address = 0x08,
666 .invert = 1,
667 .invert_oclk = 0,
668 .xtal_freq = TDA10046_XTAL_16M,
Hartmut Hackmann1bb0e862007-04-27 12:31:10 -0300669 .agc_config = TDA10046_AGC_TDA827X,
670 .gpio_config = TDA10046_GP11_I,
Thomas Gentyc6e53da2006-11-05 14:17:30 -0300671 .if_freq = TDA10046_FREQ_045,
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300672 .i2c_gate = 0x4b,
673 .tuner_address = 0x61,
674 .request_firmware = philips_tda1004x_request_firmware
Thomas Gentyc6e53da2006-11-05 14:17:30 -0300675};
676
Hartmut Hackmann83646812006-10-12 20:38:51 -0300677static struct tda1004x_config asus_p7131_dual_config = {
678 .demod_address = 0x08,
679 .invert = 1,
680 .invert_oclk = 0,
681 .xtal_freq = TDA10046_XTAL_16M,
Hartmut Hackmann1bb0e862007-04-27 12:31:10 -0300682 .agc_config = TDA10046_AGC_TDA827X,
683 .gpio_config = TDA10046_GP11_I,
Hartmut Hackmann83646812006-10-12 20:38:51 -0300684 .if_freq = TDA10046_FREQ_045,
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300685 .i2c_gate = 0x4b,
686 .tuner_address = 0x61,
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300687 .antenna_switch= 2,
688 .request_firmware = philips_tda1004x_request_firmware
Hartmut Hackmann83646812006-10-12 20:38:51 -0300689};
690
Nico Sabbi420f32f2006-03-03 12:11:28 -0300691static struct tda1004x_config lifeview_trio_config = {
692 .demod_address = 0x09,
693 .invert = 1,
694 .invert_oclk = 0,
695 .xtal_freq = TDA10046_XTAL_16M,
Hartmut Hackmann1bb0e862007-04-27 12:31:10 -0300696 .agc_config = TDA10046_AGC_TDA827X,
697 .gpio_config = TDA10046_GP00_I,
Nico Sabbi420f32f2006-03-03 12:11:28 -0300698 .if_freq = TDA10046_FREQ_045,
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300699 .tuner_address = 0x60,
700 .request_firmware = philips_tda1004x_request_firmware
Nico Sabbi420f32f2006-03-03 12:11:28 -0300701};
702
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300703static struct tda1004x_config tevion_dvbt220rf_config = {
704 .demod_address = 0x08,
705 .invert = 1,
706 .invert_oclk = 0,
707 .xtal_freq = TDA10046_XTAL_16M,
708 .agc_config = TDA10046_AGC_TDA827X,
709 .gpio_config = TDA10046_GP11_I,
710 .if_freq = TDA10046_FREQ_045,
711 .tuner_address = 0x60,
712 .request_firmware = philips_tda1004x_request_firmware
713};
Nico Sabbi420f32f2006-03-03 12:11:28 -0300714
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300715static struct tda1004x_config md8800_dvbt_config = {
716 .demod_address = 0x08,
717 .invert = 1,
718 .invert_oclk = 0,
719 .xtal_freq = TDA10046_XTAL_16M,
720 .agc_config = TDA10046_AGC_TDA827X,
721 .gpio_config = TDA10046_GP01_I,
722 .if_freq = TDA10046_FREQ_045,
723 .i2c_gate = 0x4b,
724 .tuner_address = 0x60,
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300725 .request_firmware = philips_tda1004x_request_firmware
726};
Hartmut Hackmanndf42eaf2006-02-07 06:49:10 -0200727
Hartmut Hackmanne06cea42007-03-13 20:58:29 -0300728static struct tda1004x_config asus_p7131_4871_config = {
729 .demod_address = 0x08,
730 .invert = 1,
731 .invert_oclk = 0,
732 .xtal_freq = TDA10046_XTAL_16M,
733 .agc_config = TDA10046_AGC_TDA827X,
734 .gpio_config = TDA10046_GP01_I,
735 .if_freq = TDA10046_FREQ_045,
736 .i2c_gate = 0x4b,
737 .tuner_address = 0x61,
Hartmut Hackmanne06cea42007-03-13 20:58:29 -0300738 .antenna_switch= 2,
739 .request_firmware = philips_tda1004x_request_firmware
740};
741
Hartmut Hackmannf3eec0c02007-03-14 20:33:55 -0300742static struct tda1004x_config asus_p7131_hybrid_lna_config = {
Hartmut Hackmanne06cea42007-03-13 20:58:29 -0300743 .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_GP11_I,
749 .if_freq = TDA10046_FREQ_045,
750 .i2c_gate = 0x4b,
751 .tuner_address = 0x61,
Hartmut Hackmanne06cea42007-03-13 20:58:29 -0300752 .antenna_switch= 2,
753 .request_firmware = philips_tda1004x_request_firmware
754};
Edgar Simo261f5082007-08-20 14:06:00 -0300755
Simon Farnsworthb39423a2007-05-01 10:01:20 -0300756static struct tda1004x_config kworld_dvb_t_210_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_GP11_I,
763 .if_freq = TDA10046_FREQ_045,
764 .i2c_gate = 0x4b,
765 .tuner_address = 0x61,
Simon Farnsworthb39423a2007-05-01 10:01:20 -0300766 .antenna_switch= 1,
767 .request_firmware = philips_tda1004x_request_firmware
768};
Edgar Simo261f5082007-08-20 14:06:00 -0300769
Edgar Simod90d9f52007-08-20 14:14:50 -0300770static struct tda1004x_config avermedia_super_007_config = {
771 .demod_address = 0x08,
772 .invert = 1,
773 .invert_oclk = 0,
774 .xtal_freq = TDA10046_XTAL_16M,
775 .agc_config = TDA10046_AGC_TDA827X,
776 .gpio_config = TDA10046_GP01_I,
777 .if_freq = TDA10046_FREQ_045,
778 .i2c_gate = 0x4b,
779 .tuner_address = 0x60,
Edgar Simod90d9f52007-08-20 14:14:50 -0300780 .antenna_switch= 1,
781 .request_firmware = philips_tda1004x_request_firmware
782};
783
Hermann Pitton4ba24372008-01-20 19:27:51 -0300784static struct tda1004x_config twinhan_dtv_dvb_3056_config = {
785 .demod_address = 0x08,
786 .invert = 1,
787 .invert_oclk = 0,
788 .xtal_freq = TDA10046_XTAL_16M,
789 .agc_config = TDA10046_AGC_TDA827X,
790 .gpio_config = TDA10046_GP01_I,
791 .if_freq = TDA10046_FREQ_045,
792 .i2c_gate = 0x42,
793 .tuner_address = 0x61,
Hermann Pitton4ba24372008-01-20 19:27:51 -0300794 .antenna_switch = 1,
795 .request_firmware = philips_tda1004x_request_firmware
796};
797
hermann pitton301e9d62008-09-14 17:49:14 -0300798static struct tda1004x_config asus_tiger_3in1_config = {
799 .demod_address = 0x0b,
800 .invert = 1,
801 .invert_oclk = 0,
802 .xtal_freq = TDA10046_XTAL_16M,
803 .agc_config = TDA10046_AGC_TDA827X,
804 .gpio_config = TDA10046_GP11_I,
805 .if_freq = TDA10046_FREQ_045,
806 .i2c_gate = 0x4b,
807 .tuner_address = 0x61,
808 .antenna_switch = 1,
809 .request_firmware = philips_tda1004x_request_firmware
810};
811
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300812/* ------------------------------------------------------------------
813 * special case: this card uses saa713x GPIO22 for the mode switch
814 */
Hartmut Hackmanndf42eaf2006-02-07 06:49:10 -0200815
Andrew de Quinceya79ddae2006-04-18 17:47:11 -0300816static int ads_duo_tuner_init(struct dvb_frontend *fe)
Hartmut Hackmanndf42eaf2006-02-07 06:49:10 -0200817{
818 struct saa7134_dev *dev = fe->dvb->priv;
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300819 philips_tda827x_tuner_init(fe);
Hartmut Hackmanndf42eaf2006-02-07 06:49:10 -0200820 /* route TDA8275a AGC input to the channel decoder */
Hartmut Hackmann06be3032007-04-27 12:31:15 -0300821 saa7134_set_gpio(dev, 22, 1);
Hartmut Hackmanndf42eaf2006-02-07 06:49:10 -0200822 return 0;
823}
824
Andrew de Quinceya79ddae2006-04-18 17:47:11 -0300825static int ads_duo_tuner_sleep(struct dvb_frontend *fe)
Hartmut Hackmanndf42eaf2006-02-07 06:49:10 -0200826{
827 struct saa7134_dev *dev = fe->dvb->priv;
828 /* route TDA8275a AGC input to the analog IF chip*/
Hartmut Hackmann06be3032007-04-27 12:31:15 -0300829 saa7134_set_gpio(dev, 22, 0);
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300830 philips_tda827x_tuner_sleep(fe);
Andrew de Quinceya79ddae2006-04-18 17:47:11 -0300831 return 0;
Hartmut Hackmanndf42eaf2006-02-07 06:49:10 -0200832}
833
Michael Krufky8ce47da2007-04-27 12:31:14 -0300834static struct tda827x_config ads_duo_cfg = {
Michael Krufky8ce47da2007-04-27 12:31:14 -0300835 .init = ads_duo_tuner_init,
Hartmut Hackmann7bff4b42008-04-22 14:46:08 -0300836 .sleep = ads_duo_tuner_sleep,
837 .config = 0
Michael Krufky8ce47da2007-04-27 12:31:14 -0300838};
839
Hartmut Hackmanndf42eaf2006-02-07 06:49:10 -0200840static struct tda1004x_config ads_tech_duo_config = {
841 .demod_address = 0x08,
842 .invert = 1,
843 .invert_oclk = 0,
844 .xtal_freq = TDA10046_XTAL_16M,
Hartmut Hackmann1bb0e862007-04-27 12:31:10 -0300845 .agc_config = TDA10046_AGC_TDA827X,
846 .gpio_config = TDA10046_GP00_I,
Hartmut Hackmanndf42eaf2006-02-07 06:49:10 -0200847 .if_freq = TDA10046_FREQ_045,
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300848 .tuner_address = 0x61,
849 .request_firmware = philips_tda1004x_request_firmware
Hartmut Hackmanndf42eaf2006-02-07 06:49:10 -0200850};
851
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300852/* ==================================================================
853 * tda10086 based DVB-S cards, helper functions
854 */
Hartmut Hackmann5eda2272006-08-07 14:03:32 -0300855
Igor M. Liplianine2ac28f2006-08-08 09:10:10 -0300856static struct tda10086_config flydvbs = {
857 .demod_address = 0x0e,
858 .invert = 0,
Hartmut Hackmannea75baf2008-02-09 23:54:24 -0300859 .diseqc_tone = 0,
Hartmut Hackmann9a1b04e2008-04-09 23:07:11 -0300860 .xtal_freq = TDA10086_XTAL_16M,
861};
862
863static struct tda10086_config sd1878_4m = {
864 .demod_address = 0x0e,
865 .invert = 0,
866 .diseqc_tone = 0,
867 .xtal_freq = TDA10086_XTAL_4M,
Igor M. Liplianine2ac28f2006-08-08 09:10:10 -0300868};
869
Hartmut Hackmann1b1cee32008-04-22 14:42:12 -0300870/* ------------------------------------------------------------------
871 * special case: lnb supply is connected to the gated i2c
872 */
873
874static int md8800_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
875{
876 int res = -EIO;
877 struct saa7134_dev *dev = fe->dvb->priv;
878 if (fe->ops.i2c_gate_ctrl) {
879 fe->ops.i2c_gate_ctrl(fe, 1);
880 if (dev->original_set_voltage)
881 res = dev->original_set_voltage(fe, voltage);
882 fe->ops.i2c_gate_ctrl(fe, 0);
883 }
884 return res;
885};
886
887static int md8800_set_high_voltage(struct dvb_frontend *fe, long arg)
888{
889 int res = -EIO;
890 struct saa7134_dev *dev = fe->dvb->priv;
891 if (fe->ops.i2c_gate_ctrl) {
892 fe->ops.i2c_gate_ctrl(fe, 1);
893 if (dev->original_set_high_voltage)
894 res = dev->original_set_high_voltage(fe, arg);
895 fe->ops.i2c_gate_ctrl(fe, 0);
896 }
897 return res;
898};
899
Hartmut Hackmann5823b3a2008-04-22 14:46:08 -0300900static int md8800_set_voltage2(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
901{
902 struct saa7134_dev *dev = fe->dvb->priv;
903 u8 wbuf[2] = { 0x1f, 00 };
904 u8 rbuf;
905 struct i2c_msg msg[] = { { .addr = 0x08, .flags = 0, .buf = wbuf, .len = 1 },
906 { .addr = 0x08, .flags = I2C_M_RD, .buf = &rbuf, .len = 1 } };
907
908 if (i2c_transfer(&dev->i2c_adap, msg, 2) != 2)
909 return -EIO;
910 /* NOTE: this assumes that gpo1 is used, it might be bit 5 (gpo2) */
911 if (voltage == SEC_VOLTAGE_18)
912 wbuf[1] = rbuf | 0x10;
913 else
914 wbuf[1] = rbuf & 0xef;
915 msg[0].len = 2;
916 i2c_transfer(&dev->i2c_adap, msg, 1);
917 return 0;
918}
919
920static int md8800_set_high_voltage2(struct dvb_frontend *fe, long arg)
921{
922 struct saa7134_dev *dev = fe->dvb->priv;
923 wprintk("%s: sorry can't set high LNB supply voltage from here\n", __func__);
924 return -EIO;
925}
926
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300927/* ==================================================================
928 * nxt200x based ATSC cards, helper functions
929 */
Hartmut Hackmann90e9df72005-11-08 21:38:42 -0800930
Michael Krufky3b64e8e2005-11-08 21:38:20 -0800931static struct nxt200x_config avertvhda180 = {
932 .demod_address = 0x0a,
Michael Krufky3b64e8e2005-11-08 21:38:20 -0800933};
Andrew Burri3e1410a2006-02-27 00:08:23 -0300934
935static struct nxt200x_config kworldatsc110 = {
936 .demod_address = 0x0a,
Andrew Burri3e1410a2006-02-27 00:08:23 -0300937};
Michael Krufky3b64e8e2005-11-08 21:38:20 -0800938
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -0300939/* ==================================================================
940 * Core code
941 */
Mauro Carvalho Chehab86ddd962005-07-12 13:58:47 -0700942
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943static int dvb_init(struct saa7134_dev *dev)
944{
Hartmut Hackmann1c4f76a2007-04-27 12:31:16 -0300945 int ret;
Mauro Carvalho Chehabbc36a682008-04-22 14:45:27 -0300946 int attach_xc3028 = 0;
947
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948 /* init struct videobuf_dvb */
949 dev->ts.nr_bufs = 32;
950 dev->ts.nr_packets = 32*4;
951 dev->dvb.name = dev->name;
Guennadi Liakhovetski07051352008-04-22 14:42:13 -0300952 videobuf_queue_sg_init(&dev->dvb.dvbq, &saa7134_ts_qops,
953 &dev->pci->dev, &dev->slock,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954 V4L2_BUF_TYPE_VIDEO_CAPTURE,
955 V4L2_FIELD_ALTERNATE,
956 sizeof(struct saa7134_buf),
957 dev);
958
959 switch (dev->board) {
960 case SAA7134_BOARD_PINNACLE_300I_DVBT_PAL:
Trent Piephocf3c34c2007-03-07 18:19:48 -0300961 dprintk("pinnacle 300i dvb setup\n");
Andrew de Quincey2bfe0312006-08-08 09:10:08 -0300962 dev->dvb.frontend = dvb_attach(mt352_attach, &pinnacle_300i,
Michael Krufkyf7b54b12006-08-08 15:48:08 -0300963 &dev->i2c_adap);
Andrew de Quincey6b3ccab2006-04-20 12:01:47 -0300964 if (dev->dvb.frontend) {
Patrick Boettcherdea74862006-05-14 05:01:31 -0300965 dev->dvb.frontend->ops.tuner_ops.set_params = mt352_pinnacle_tuner_set_params;
Andrew de Quincey6b3ccab2006-04-20 12:01:47 -0300966 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967 break;
Jose Alberto Regueroa78d0bf2006-02-07 06:25:14 -0200968 case SAA7134_BOARD_AVERMEDIA_777:
Petr Baudis515c2082006-09-26 16:53:53 -0300969 case SAA7134_BOARD_AVERMEDIA_A16AR:
Trent Piephocf3c34c2007-03-07 18:19:48 -0300970 dprintk("avertv 777 dvb setup\n");
Andrew de Quincey2bfe0312006-08-08 09:10:08 -0300971 dev->dvb.frontend = dvb_attach(mt352_attach, &avermedia_777,
Michael Krufkyf7b54b12006-08-08 15:48:08 -0300972 &dev->i2c_adap);
Andrew de Quincey6b3ccab2006-04-20 12:01:47 -0300973 if (dev->dvb.frontend) {
Michael Krufkyfb147e92008-04-22 14:46:16 -0300974 dvb_attach(simple_tuner_attach, dev->dvb.frontend,
975 &dev->i2c_adap, 0x61,
976 TUNER_PHILIPS_TD1316);
Andrew de Quincey6b3ccab2006-04-20 12:01:47 -0300977 }
Jose Alberto Regueroa78d0bf2006-02-07 06:25:14 -0200978 break;
Mauro Carvalho Chehab95a2fdb2008-03-28 17:52:44 -0300979 case SAA7134_BOARD_AVERMEDIA_A16D:
Tim Farrington6e501a32008-06-15 13:33:42 -0300980 dprintk("AverMedia A16D dvb setup\n");
981 dev->dvb.frontend = dvb_attach(mt352_attach,
982 &avermedia_xc3028_mt352_dev,
983 &dev->i2c_adap);
Mauro Carvalho Chehab95a2fdb2008-03-28 17:52:44 -0300984 attach_xc3028 = 1;
985 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986 case SAA7134_BOARD_MD7134:
Michael Krufkyf7b54b12006-08-08 15:48:08 -0300987 dev->dvb.frontend = dvb_attach(tda10046_attach,
988 &medion_cardbus,
989 &dev->i2c_adap);
Andrew de Quincey6b3ccab2006-04-20 12:01:47 -0300990 if (dev->dvb.frontend) {
Michael Krufkycb89cd32008-04-22 14:46:16 -0300991 dvb_attach(simple_tuner_attach, dev->dvb.frontend,
992 &dev->i2c_adap, medion_cardbus.tuner_address,
993 TUNER_PHILIPS_FMD1216ME_MK3);
Andrew de Quincey6b3ccab2006-04-20 12:01:47 -0300994 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995 break;
Mauro Carvalho Chehab86ddd962005-07-12 13:58:47 -0700996 case SAA7134_BOARD_PHILIPS_TOUGH:
Michael Krufkyf7b54b12006-08-08 15:48:08 -0300997 dev->dvb.frontend = dvb_attach(tda10046_attach,
998 &philips_tu1216_60_config,
999 &dev->i2c_adap);
Andrew de Quincey6b3ccab2006-04-20 12:01:47 -03001000 if (dev->dvb.frontend) {
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -03001001 dev->dvb.frontend->ops.tuner_ops.init = philips_tu1216_init;
1002 dev->dvb.frontend->ops.tuner_ops.set_params = philips_tda6651_pll_set;
Andrew de Quincey6b3ccab2006-04-20 12:01:47 -03001003 }
Mauro Carvalho Chehab86ddd962005-07-12 13:58:47 -07001004 break;
1005 case SAA7134_BOARD_FLYDVBTDUO:
Peter Missel10b7a902006-01-23 17:11:06 -02001006 case SAA7134_BOARD_FLYDVBT_DUO_CARDBUS:
Mauro Carvalho Chehabd557dab2008-04-30 15:27:55 -03001007 if (configure_tda827x_fe(dev, &tda827x_lifeview_config,
1008 &tda827x_cfg_0) < 0)
1009 goto dettach_frontend;
Mauro Carvalho Chehab86ddd962005-07-12 13:58:47 -07001010 break;
Hartmut Hackmann2cf36ac2005-11-08 21:36:32 -08001011 case SAA7134_BOARD_PHILIPS_EUROPA:
Hartmut Hackmann2cf36ac2005-11-08 21:36:32 -08001012 case SAA7134_BOARD_VIDEOMATE_DVBT_300:
Michael Krufkyf7b54b12006-08-08 15:48:08 -03001013 dev->dvb.frontend = dvb_attach(tda10046_attach,
1014 &philips_europa_config,
1015 &dev->i2c_adap);
Andrew de Quincey6b3ccab2006-04-20 12:01:47 -03001016 if (dev->dvb.frontend) {
Hartmut Hackmann588f9832006-10-18 17:30:42 -03001017 dev->original_demod_sleep = dev->dvb.frontend->ops.sleep;
1018 dev->dvb.frontend->ops.sleep = philips_europa_demod_sleep;
Patrick Boettcherdea74862006-05-14 05:01:31 -03001019 dev->dvb.frontend->ops.tuner_ops.init = philips_europa_tuner_init;
1020 dev->dvb.frontend->ops.tuner_ops.sleep = philips_europa_tuner_sleep;
1021 dev->dvb.frontend->ops.tuner_ops.set_params = philips_td1316_tuner_set_params;
Andrew de Quincey6b3ccab2006-04-20 12:01:47 -03001022 }
Hartmut Hackmann2cf36ac2005-11-08 21:36:32 -08001023 break;
1024 case SAA7134_BOARD_VIDEOMATE_DVBT_200:
Michael Krufkyf7b54b12006-08-08 15:48:08 -03001025 dev->dvb.frontend = dvb_attach(tda10046_attach,
1026 &philips_tu1216_61_config,
1027 &dev->i2c_adap);
Andrew de Quincey6b3ccab2006-04-20 12:01:47 -03001028 if (dev->dvb.frontend) {
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -03001029 dev->dvb.frontend->ops.tuner_ops.init = philips_tu1216_init;
1030 dev->dvb.frontend->ops.tuner_ops.set_params = philips_tda6651_pll_set;
Andrew de Quincey6b3ccab2006-04-20 12:01:47 -03001031 }
Hartmut Hackmann2cf36ac2005-11-08 21:36:32 -08001032 break;
Simon Farnsworthb39423a2007-05-01 10:01:20 -03001033 case SAA7134_BOARD_KWORLD_DVBT_210:
Mauro Carvalho Chehabd557dab2008-04-30 15:27:55 -03001034 if (configure_tda827x_fe(dev, &kworld_dvb_t_210_config,
1035 &tda827x_cfg_2) < 0)
1036 goto dettach_frontend;
Simon Farnsworthb39423a2007-05-01 10:01:20 -03001037 break;
Hartmut Hackmann90e9df72005-11-08 21:38:42 -08001038 case SAA7134_BOARD_PHILIPS_TIGER:
Mauro Carvalho Chehabd557dab2008-04-30 15:27:55 -03001039 if (configure_tda827x_fe(dev, &philips_tiger_config,
1040 &tda827x_cfg_0) < 0)
1041 goto dettach_frontend;
Hartmut Hackmann587d2fd2006-10-06 19:13:50 -03001042 break;
1043 case SAA7134_BOARD_PINNACLE_PCTV_310i:
Mauro Carvalho Chehabd557dab2008-04-30 15:27:55 -03001044 if (configure_tda827x_fe(dev, &pinnacle_pctv_310i_config,
1045 &tda827x_cfg_1) < 0)
1046 goto dettach_frontend;
Hartmut Hackmann90e9df72005-11-08 21:38:42 -08001047 break;
Thomas Gentyc6e53da2006-11-05 14:17:30 -03001048 case SAA7134_BOARD_HAUPPAUGE_HVR1110:
Mauro Carvalho Chehabd557dab2008-04-30 15:27:55 -03001049 if (configure_tda827x_fe(dev, &hauppauge_hvr_1110_config,
1050 &tda827x_cfg_1) < 0)
1051 goto dettach_frontend;
Thomas Gentyc6e53da2006-11-05 14:17:30 -03001052 break;
Hartmut Hackmannd4b0aba2005-11-08 21:38:44 -08001053 case SAA7134_BOARD_ASUSTeK_P7131_DUAL:
Mauro Carvalho Chehabd557dab2008-04-30 15:27:55 -03001054 if (configure_tda827x_fe(dev, &asus_p7131_dual_config,
1055 &tda827x_cfg_0) < 0)
1056 goto dettach_frontend;
Hartmut Hackmannd4b0aba2005-11-08 21:38:44 -08001057 break;
Giampiero Giancipoli3d8466e2006-02-07 06:49:09 -02001058 case SAA7134_BOARD_FLYDVBT_LR301:
Mauro Carvalho Chehabd557dab2008-04-30 15:27:55 -03001059 if (configure_tda827x_fe(dev, &tda827x_lifeview_config,
1060 &tda827x_cfg_0) < 0)
1061 goto dettach_frontend;
Giampiero Giancipoli3d8466e2006-02-07 06:49:09 -02001062 break;
Nico Sabbi420f32f2006-03-03 12:11:28 -03001063 case SAA7134_BOARD_FLYDVB_TRIO:
Mauro Carvalho Chehabd557dab2008-04-30 15:27:55 -03001064 if (!use_frontend) { /* terrestrial */
1065 if (configure_tda827x_fe(dev, &lifeview_trio_config,
1066 &tda827x_cfg_0) < 0)
1067 goto dettach_frontend;
Hartmut Hackmann7bff4b42008-04-22 14:46:08 -03001068 } else { /* satellite */
Nico Sabbi1f683cd2006-11-15 22:06:56 -03001069 dev->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs, &dev->i2c_adap);
1070 if (dev->dvb.frontend) {
1071 if (dvb_attach(tda826x_attach, dev->dvb.frontend, 0x63,
1072 &dev->i2c_adap, 0) == NULL) {
Hartmut Hackmann5823b3a2008-04-22 14:46:08 -03001073 wprintk("%s: Lifeview Trio, No tda826x found!\n", __func__);
Mauro Carvalho Chehabd557dab2008-04-30 15:27:55 -03001074 goto dettach_frontend;
Nico Sabbi1f683cd2006-11-15 22:06:56 -03001075 }
1076 if (dvb_attach(isl6421_attach, dev->dvb.frontend, &dev->i2c_adap,
1077 0x08, 0, 0) == NULL) {
Hartmut Hackmann5823b3a2008-04-22 14:46:08 -03001078 wprintk("%s: Lifeview Trio, No ISL6421 found!\n", __func__);
Mauro Carvalho Chehabd557dab2008-04-30 15:27:55 -03001079 goto dettach_frontend;
Nico Sabbi1f683cd2006-11-15 22:06:56 -03001080 }
1081 }
Andrew de Quincey6b3ccab2006-04-20 12:01:47 -03001082 }
Nico Sabbi420f32f2006-03-03 12:11:28 -03001083 break;
Hartmut Hackmanndf42eaf2006-02-07 06:49:10 -02001084 case SAA7134_BOARD_ADS_DUO_CARDBUS_PTV331:
Hartmut Hackmannd95b8942006-03-27 19:39:30 -03001085 case SAA7134_BOARD_FLYDVBT_HYBRID_CARDBUS:
Michael Krufkyf7b54b12006-08-08 15:48:08 -03001086 dev->dvb.frontend = dvb_attach(tda10046_attach,
1087 &ads_tech_duo_config,
1088 &dev->i2c_adap);
Andrew de Quincey6b3ccab2006-04-20 12:01:47 -03001089 if (dev->dvb.frontend) {
Hartmut Hackmannede22002007-04-27 12:31:32 -03001090 if (dvb_attach(tda827x_attach,dev->dvb.frontend,
Hartmut Hackmann7bff4b42008-04-22 14:46:08 -03001091 ads_tech_duo_config.tuner_address, &dev->i2c_adap,
1092 &ads_duo_cfg) == NULL) {
Trent Piephocf3c34c2007-03-07 18:19:48 -03001093 wprintk("no tda827x tuner found at addr: %02x\n",
Hartmut Hackmannede22002007-04-27 12:31:32 -03001094 ads_tech_duo_config.tuner_address);
Mauro Carvalho Chehabd557dab2008-04-30 15:27:55 -03001095 goto dettach_frontend;
Hartmut Hackmannede22002007-04-27 12:31:32 -03001096 }
Mauro Carvalho Chehabbc36ec72008-06-14 10:44:04 -03001097 } else
1098 wprintk("failed to attach tda10046\n");
Hartmut Hackmannd95b8942006-03-27 19:39:30 -03001099 break;
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -03001100 case SAA7134_BOARD_TEVION_DVBT_220RF:
Mauro Carvalho Chehabd557dab2008-04-30 15:27:55 -03001101 if (configure_tda827x_fe(dev, &tevion_dvbt220rf_config,
1102 &tda827x_cfg_0) < 0)
1103 goto dettach_frontend;
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -03001104 break;
Hartmut Hackmann5eda2272006-08-07 14:03:32 -03001105 case SAA7134_BOARD_MEDION_MD8800_QUADRO:
Hartmut Hackmann4b1431c2008-04-22 14:42:09 -03001106 if (!use_frontend) { /* terrestrial */
Mauro Carvalho Chehabd557dab2008-04-30 15:27:55 -03001107 if (configure_tda827x_fe(dev, &md8800_dvbt_config,
1108 &tda827x_cfg_0) < 0)
1109 goto dettach_frontend;
Hartmut Hackmann4b1431c2008-04-22 14:42:09 -03001110 } else { /* satellite */
1111 dev->dvb.frontend = dvb_attach(tda10086_attach,
1112 &flydvbs, &dev->i2c_adap);
1113 if (dev->dvb.frontend) {
Hartmut Hackmann5823b3a2008-04-22 14:46:08 -03001114 struct dvb_frontend *fe = dev->dvb.frontend;
1115 u8 dev_id = dev->eedata[2];
1116 u8 data = 0xc4;
1117 struct i2c_msg msg = {.addr = 0x08, .flags = 0, .len = 1};
1118
Hartmut Hackmann4b1431c2008-04-22 14:42:09 -03001119 if (dvb_attach(tda826x_attach, dev->dvb.frontend,
Mauro Carvalho Chehabd557dab2008-04-30 15:27:55 -03001120 0x60, &dev->i2c_adap, 0) == NULL) {
Hartmut Hackmann4b1431c2008-04-22 14:42:09 -03001121 wprintk("%s: Medion Quadro, no tda826x "
Hartmut Hackmann5823b3a2008-04-22 14:46:08 -03001122 "found !\n", __func__);
Mauro Carvalho Chehabd557dab2008-04-30 15:27:55 -03001123 goto dettach_frontend;
1124 }
Hartmut Hackmann5823b3a2008-04-22 14:46:08 -03001125 if (dev_id != 0x08) {
1126 /* we need to open the i2c gate (we know it exists) */
1127 fe->ops.i2c_gate_ctrl(fe, 1);
1128 if (dvb_attach(isl6405_attach, fe,
Mauro Carvalho Chehabd557dab2008-04-30 15:27:55 -03001129 &dev->i2c_adap, 0x08, 0, 0) == NULL) {
Hartmut Hackmann5823b3a2008-04-22 14:46:08 -03001130 wprintk("%s: Medion Quadro, no ISL6405 "
1131 "found !\n", __func__);
Mauro Carvalho Chehabd557dab2008-04-30 15:27:55 -03001132 goto dettach_frontend;
1133 }
Hartmut Hackmanne9c1ac92008-04-22 14:46:10 -03001134 if (dev_id == 0x07) {
1135 /* fire up the 2nd section of the LNB supply since
1136 we can't do this from the other section */
1137 msg.buf = &data;
1138 i2c_transfer(&dev->i2c_adap, &msg, 1);
1139 }
Hartmut Hackmann5823b3a2008-04-22 14:46:08 -03001140 fe->ops.i2c_gate_ctrl(fe, 0);
1141 dev->original_set_voltage = fe->ops.set_voltage;
1142 fe->ops.set_voltage = md8800_set_voltage;
1143 dev->original_set_high_voltage = fe->ops.enable_high_lnb_voltage;
1144 fe->ops.enable_high_lnb_voltage = md8800_set_high_voltage;
1145 } else {
1146 fe->ops.set_voltage = md8800_set_voltage2;
1147 fe->ops.enable_high_lnb_voltage = md8800_set_high_voltage2;
1148 }
Hartmut Hackmann4b1431c2008-04-22 14:42:09 -03001149 }
1150 }
Hartmut Hackmann5eda2272006-08-07 14:03:32 -03001151 break;
Michael Krufky3b64e8e2005-11-08 21:38:20 -08001152 case SAA7134_BOARD_AVERMEDIA_AVERTVHD_A180:
Michael Krufkyf7b54b12006-08-08 15:48:08 -03001153 dev->dvb.frontend = dvb_attach(nxt200x_attach, &avertvhda180,
1154 &dev->i2c_adap);
Mauro Carvalho Chehabd557dab2008-04-30 15:27:55 -03001155 if (dev->dvb.frontend)
Michael Krufky4ad8eee52006-08-08 15:48:08 -03001156 dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
Michael Krufky47a99912007-06-12 16:10:51 -03001157 NULL, DVB_PLL_TDHU2);
Michael Krufky3b64e8e2005-11-08 21:38:20 -08001158 break;
Andrew Burri3e1410a2006-02-27 00:08:23 -03001159 case SAA7134_BOARD_KWORLD_ATSC110:
Michael Krufkyf7b54b12006-08-08 15:48:08 -03001160 dev->dvb.frontend = dvb_attach(nxt200x_attach, &kworldatsc110,
1161 &dev->i2c_adap);
Mauro Carvalho Chehabd557dab2008-04-30 15:27:55 -03001162 if (dev->dvb.frontend)
Michael Krufky62ff817a2008-04-22 14:46:17 -03001163 dvb_attach(simple_tuner_attach, dev->dvb.frontend,
1164 &dev->i2c_adap, 0x61,
1165 TUNER_PHILIPS_TUV1236D);
Andrew Burri3e1410a2006-02-27 00:08:23 -03001166 break;
Igor M. Liplianine2ac28f2006-08-08 09:10:10 -03001167 case SAA7134_BOARD_FLYDVBS_LR300:
Michael Krufkyf7b54b12006-08-08 15:48:08 -03001168 dev->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs,
1169 &dev->i2c_adap);
Igor M. Liplianine2ac28f2006-08-08 09:10:10 -03001170 if (dev->dvb.frontend) {
Michael Krufkyf7b54b12006-08-08 15:48:08 -03001171 if (dvb_attach(tda826x_attach, dev->dvb.frontend, 0x60,
1172 &dev->i2c_adap, 0) == NULL) {
Hartmut Hackmann5823b3a2008-04-22 14:46:08 -03001173 wprintk("%s: No tda826x found!\n", __func__);
Mauro Carvalho Chehabd557dab2008-04-30 15:27:55 -03001174 goto dettach_frontend;
Igor M. Liplianine2ac28f2006-08-08 09:10:10 -03001175 }
Michael Krufkyf7b54b12006-08-08 15:48:08 -03001176 if (dvb_attach(isl6421_attach, dev->dvb.frontend,
1177 &dev->i2c_adap, 0x08, 0, 0) == NULL) {
Hartmut Hackmann5823b3a2008-04-22 14:46:08 -03001178 wprintk("%s: No ISL6421 found!\n", __func__);
Mauro Carvalho Chehabd557dab2008-04-30 15:27:55 -03001179 goto dettach_frontend;
Igor M. Liplianine2ac28f2006-08-08 09:10:10 -03001180 }
1181 }
1182 break;
Hartmut Hackmanncf146ca2006-10-02 20:49:24 -03001183 case SAA7134_BOARD_ASUS_EUROPA2_HYBRID:
Matthias Schwarzott0e8f4cc2008-01-28 12:01:11 -03001184 dev->dvb.frontend = dvb_attach(tda10046_attach,
1185 &medion_cardbus,
1186 &dev->i2c_adap);
Hartmut Hackmanncf146ca2006-10-02 20:49:24 -03001187 if (dev->dvb.frontend) {
1188 dev->original_demod_sleep = dev->dvb.frontend->ops.sleep;
1189 dev->dvb.frontend->ops.sleep = philips_europa_demod_sleep;
Trent Piephob7754d72007-05-08 18:05:16 -03001190
Michael Krufkycb89cd32008-04-22 14:46:16 -03001191 dvb_attach(simple_tuner_attach, dev->dvb.frontend,
1192 &dev->i2c_adap, medion_cardbus.tuner_address,
1193 TUNER_PHILIPS_FMD1216ME_MK3);
Hartmut Hackmanncf146ca2006-10-02 20:49:24 -03001194 }
1195 break;
Hartmut Hackmanncbb94522006-10-30 20:00:16 -03001196 case SAA7134_BOARD_VIDEOMATE_DVBT_200A:
1197 dev->dvb.frontend = dvb_attach(tda10046_attach,
1198 &philips_europa_config,
1199 &dev->i2c_adap);
1200 if (dev->dvb.frontend) {
1201 dev->dvb.frontend->ops.tuner_ops.init = philips_td1316_tuner_init;
1202 dev->dvb.frontend->ops.tuner_ops.set_params = philips_td1316_tuner_set_params;
1203 }
1204 break;
Hartmut Hackmann550a9a52006-11-15 21:31:54 -03001205 case SAA7134_BOARD_CINERGY_HT_PCMCIA:
Mauro Carvalho Chehabd557dab2008-04-30 15:27:55 -03001206 if (configure_tda827x_fe(dev, &cinergy_ht_config,
1207 &tda827x_cfg_0) < 0)
1208 goto dettach_frontend;
Hartmut Hackmann550a9a52006-11-15 21:31:54 -03001209 break;
Michael Krufky9de271e2007-01-16 18:36:40 -03001210 case SAA7134_BOARD_CINERGY_HT_PCI:
Mauro Carvalho Chehabd557dab2008-04-30 15:27:55 -03001211 if (configure_tda827x_fe(dev, &cinergy_ht_pci_config,
1212 &tda827x_cfg_0) < 0)
1213 goto dettach_frontend;
Hartmut Hackmann58ef4f92007-04-27 12:31:12 -03001214 break;
1215 case SAA7134_BOARD_PHILIPS_TIGER_S:
Mauro Carvalho Chehabd557dab2008-04-30 15:27:55 -03001216 if (configure_tda827x_fe(dev, &philips_tiger_s_config,
1217 &tda827x_cfg_2) < 0)
1218 goto dettach_frontend;
Michael Krufky9de271e2007-01-16 18:36:40 -03001219 break;
Hartmut Hackmanne06cea42007-03-13 20:58:29 -03001220 case SAA7134_BOARD_ASUS_P7131_4871:
Mauro Carvalho Chehabd557dab2008-04-30 15:27:55 -03001221 if (configure_tda827x_fe(dev, &asus_p7131_4871_config,
1222 &tda827x_cfg_2) < 0)
1223 goto dettach_frontend;
Hartmut Hackmanne06cea42007-03-13 20:58:29 -03001224 break;
Hartmut Hackmannf3eec0c02007-03-14 20:33:55 -03001225 case SAA7134_BOARD_ASUSTeK_P7131_HYBRID_LNA:
Mauro Carvalho Chehabd557dab2008-04-30 15:27:55 -03001226 if (configure_tda827x_fe(dev, &asus_p7131_hybrid_lna_config,
1227 &tda827x_cfg_2) < 0)
1228 goto dettach_frontend;
Hartmut Hackmanne06cea42007-03-13 20:58:29 -03001229 break;
Edgar Simod90d9f52007-08-20 14:14:50 -03001230 case SAA7134_BOARD_AVERMEDIA_SUPER_007:
Mauro Carvalho Chehabd557dab2008-04-30 15:27:55 -03001231 if (configure_tda827x_fe(dev, &avermedia_super_007_config,
1232 &tda827x_cfg_0) < 0)
1233 goto dettach_frontend;
Edgar Simod90d9f52007-08-20 14:14:50 -03001234 break;
Hermann Pitton4ba24372008-01-20 19:27:51 -03001235 case SAA7134_BOARD_TWINHAN_DTV_DVB_3056:
Mauro Carvalho Chehabd557dab2008-04-30 15:27:55 -03001236 if (configure_tda827x_fe(dev, &twinhan_dtv_dvb_3056_config,
1237 &tda827x_cfg_2_sw42) < 0)
1238 goto dettach_frontend;
Hermann Pitton4ba24372008-01-20 19:27:51 -03001239 break;
Hartmut Hackmann6ab465a2008-04-22 14:42:11 -03001240 case SAA7134_BOARD_PHILIPS_SNAKE:
1241 dev->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs,
1242 &dev->i2c_adap);
1243 if (dev->dvb.frontend) {
1244 if (dvb_attach(tda826x_attach, dev->dvb.frontend, 0x60,
Mauro Carvalho Chehabd557dab2008-04-30 15:27:55 -03001245 &dev->i2c_adap, 0) == NULL) {
Hartmut Hackmann5823b3a2008-04-22 14:46:08 -03001246 wprintk("%s: No tda826x found!\n", __func__);
Mauro Carvalho Chehabd557dab2008-04-30 15:27:55 -03001247 goto dettach_frontend;
1248 }
Hartmut Hackmann6ab465a2008-04-22 14:42:11 -03001249 if (dvb_attach(lnbp21_attach, dev->dvb.frontend,
Mauro Carvalho Chehabd557dab2008-04-30 15:27:55 -03001250 &dev->i2c_adap, 0, 0) == NULL) {
Hartmut Hackmann5823b3a2008-04-22 14:46:08 -03001251 wprintk("%s: No lnbp21 found!\n", __func__);
Mauro Carvalho Chehabd557dab2008-04-30 15:27:55 -03001252 goto dettach_frontend;
1253 }
Hartmut Hackmann6ab465a2008-04-22 14:42:11 -03001254 }
1255 break;
Hermann Pitton7b5b3f12008-04-22 14:42:12 -03001256 case SAA7134_BOARD_CREATIX_CTX953:
Mauro Carvalho Chehabd557dab2008-04-30 15:27:55 -03001257 if (configure_tda827x_fe(dev, &md8800_dvbt_config,
1258 &tda827x_cfg_0) < 0)
1259 goto dettach_frontend;
Hermann Pitton7b5b3f12008-04-22 14:42:12 -03001260 break;
Russell Kliese6a6179b62008-04-22 14:42:12 -03001261 case SAA7134_BOARD_MSI_TVANYWHERE_AD11:
Mauro Carvalho Chehabd557dab2008-04-30 15:27:55 -03001262 if (configure_tda827x_fe(dev, &philips_tiger_s_config,
1263 &tda827x_cfg_2) < 0)
1264 goto dettach_frontend;
Russell Kliese6a6179b62008-04-22 14:42:12 -03001265 break;
Mauro Carvalho Chehabbc36a682008-04-22 14:45:27 -03001266 case SAA7134_BOARD_AVERMEDIA_CARDBUS_506:
Tim Farrington6e501a32008-06-15 13:33:42 -03001267 dprintk("AverMedia E506R dvb setup\n");
1268 saa7134_set_gpio(dev, 25, 0);
1269 msleep(10);
1270 saa7134_set_gpio(dev, 25, 1);
Mauro Carvalho Chehabbc36a682008-04-22 14:45:27 -03001271 dev->dvb.frontend = dvb_attach(mt352_attach,
Tim Farrington6e501a32008-06-15 13:33:42 -03001272 &avermedia_xc3028_mt352_dev,
1273 &dev->i2c_adap);
Mauro Carvalho Chehabbc36a682008-04-22 14:45:27 -03001274 attach_xc3028 = 1;
Massimo Piccionie2fc00c2008-07-11 13:48:02 -03001275 break;
Hartmut Hackmann637afdb2008-04-22 14:46:08 -03001276 case SAA7134_BOARD_MD7134_BRIDGE_2:
1277 dev->dvb.frontend = dvb_attach(tda10086_attach,
Hartmut Hackmann9a1b04e2008-04-09 23:07:11 -03001278 &sd1878_4m, &dev->i2c_adap);
Hartmut Hackmann637afdb2008-04-22 14:46:08 -03001279 if (dev->dvb.frontend) {
1280 struct dvb_frontend *fe;
1281 if (dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x60,
Mauro Carvalho Chehabd557dab2008-04-30 15:27:55 -03001282 &dev->i2c_adap, DVB_PLL_PHILIPS_SD1878_TDA8261) == NULL) {
Hartmut Hackmann637afdb2008-04-22 14:46:08 -03001283 wprintk("%s: MD7134 DVB-S, no SD1878 "
Hartmut Hackmann5823b3a2008-04-22 14:46:08 -03001284 "found !\n", __func__);
Mauro Carvalho Chehabd557dab2008-04-30 15:27:55 -03001285 goto dettach_frontend;
1286 }
Hartmut Hackmann637afdb2008-04-22 14:46:08 -03001287 /* we need to open the i2c gate (we know it exists) */
1288 fe = dev->dvb.frontend;
1289 fe->ops.i2c_gate_ctrl(fe, 1);
1290 if (dvb_attach(isl6405_attach, fe,
Mauro Carvalho Chehabd557dab2008-04-30 15:27:55 -03001291 &dev->i2c_adap, 0x08, 0, 0) == NULL) {
Hartmut Hackmann637afdb2008-04-22 14:46:08 -03001292 wprintk("%s: MD7134 DVB-S, no ISL6405 "
Hartmut Hackmann5823b3a2008-04-22 14:46:08 -03001293 "found !\n", __func__);
Mauro Carvalho Chehabd557dab2008-04-30 15:27:55 -03001294 goto dettach_frontend;
1295 }
Hartmut Hackmann637afdb2008-04-22 14:46:08 -03001296 fe->ops.i2c_gate_ctrl(fe, 0);
1297 dev->original_set_voltage = fe->ops.set_voltage;
1298 fe->ops.set_voltage = md8800_set_voltage;
1299 dev->original_set_high_voltage = fe->ops.enable_high_lnb_voltage;
1300 fe->ops.enable_high_lnb_voltage = md8800_set_high_voltage;
1301 }
1302 break;
Massimo Piccionie2fc00c2008-07-11 13:48:02 -03001303 case SAA7134_BOARD_AVERMEDIA_M103:
1304 saa7134_set_gpio(dev, 25, 0);
1305 msleep(10);
1306 saa7134_set_gpio(dev, 25, 1);
1307 dev->dvb.frontend = dvb_attach(mt352_attach,
1308 &avermedia_xc3028_mt352_dev,
1309 &dev->i2c_adap);
1310 attach_xc3028 = 1;
1311 break;
hermann pitton301e9d62008-09-14 17:49:14 -03001312 case SAA7134_BOARD_ASUSTeK_TIGER_3IN1:
1313 if (!use_frontend) { /* terrestrial */
1314 if (configure_tda827x_fe(dev, &asus_tiger_3in1_config,
1315 &tda827x_cfg_2) < 0)
1316 goto dettach_frontend;
1317 } else { /* satellite */
1318 dev->dvb.frontend = dvb_attach(tda10086_attach,
1319 &flydvbs, &dev->i2c_adap);
1320 if (dev->dvb.frontend) {
1321 if (dvb_attach(tda826x_attach,
1322 dev->dvb.frontend, 0x60,
1323 &dev->i2c_adap, 0) == NULL) {
1324 wprintk("%s: Asus Tiger 3in1, no "
1325 "tda826x found!\n", __func__);
1326 goto dettach_frontend;
1327 }
1328 if (dvb_attach(lnbp21_attach, dev->dvb.frontend,
1329 &dev->i2c_adap, 0, 0) == NULL) {
1330 wprintk("%s: Asus Tiger 3in1, no lnbp21"
1331 " found!\n", __func__);
1332 goto dettach_frontend;
1333 }
1334 }
1335 }
1336 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337 default:
Trent Piephocf3c34c2007-03-07 18:19:48 -03001338 wprintk("Huh? unknown DVB card?\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339 break;
1340 }
1341
Mauro Carvalho Chehabbc36a682008-04-22 14:45:27 -03001342 if (attach_xc3028) {
1343 struct dvb_frontend *fe;
1344 struct xc2028_config cfg = {
1345 .i2c_adap = &dev->i2c_adap,
1346 .i2c_addr = 0x61,
Mauro Carvalho Chehabbc36a682008-04-22 14:45:27 -03001347 };
Mauro Carvalho Chehab95a2fdb2008-03-28 17:52:44 -03001348
1349 if (!dev->dvb.frontend)
1350 return -1;
1351
Mauro Carvalho Chehabbc36a682008-04-22 14:45:27 -03001352 fe = dvb_attach(xc2028_attach, dev->dvb.frontend, &cfg);
1353 if (!fe) {
1354 printk(KERN_ERR "%s/2: xc3028 attach failed\n",
1355 dev->name);
Mauro Carvalho Chehabd557dab2008-04-30 15:27:55 -03001356 goto dettach_frontend;
Mauro Carvalho Chehabbc36a682008-04-22 14:45:27 -03001357 }
1358 }
1359
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360 if (NULL == dev->dvb.frontend) {
Trent Piephocf3c34c2007-03-07 18:19:48 -03001361 printk(KERN_ERR "%s/dvb: frontend initialization failed\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362 return -1;
1363 }
Michael Krufkyd7cba042008-09-12 13:31:45 -03001364 /* define general-purpose callback pointer */
1365 dev->dvb.frontend->callback = saa7134_tuner_callback;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366
1367 /* register everything else */
Janne Grunau78e92002008-04-09 19:13:13 -03001368 ret = videobuf_dvb_register(&dev->dvb, THIS_MODULE, dev, &dev->pci->dev,
1369 adapter_nr);
Hartmut Hackmann1c4f76a2007-04-27 12:31:16 -03001370
1371 /* this sequence is necessary to make the tda1004x load its firmware
1372 * and to enter analog mode of hybrid boards
1373 */
1374 if (!ret) {
1375 if (dev->dvb.frontend->ops.init)
1376 dev->dvb.frontend->ops.init(dev->dvb.frontend);
1377 if (dev->dvb.frontend->ops.sleep)
1378 dev->dvb.frontend->ops.sleep(dev->dvb.frontend);
Hartmut Hackmann9971f4f2007-03-23 21:00:07 -03001379 if (dev->dvb.frontend->ops.tuner_ops.sleep)
1380 dev->dvb.frontend->ops.tuner_ops.sleep(dev->dvb.frontend);
Hartmut Hackmann1c4f76a2007-04-27 12:31:16 -03001381 }
1382 return ret;
Mauro Carvalho Chehabd557dab2008-04-30 15:27:55 -03001383
1384dettach_frontend:
Mauro Carvalho Chehabbf67cac2008-06-07 15:54:10 -03001385 if (dev->dvb.frontend)
1386 dvb_frontend_detach(dev->dvb.frontend);
Mauro Carvalho Chehabd557dab2008-04-30 15:27:55 -03001387 dev->dvb.frontend = NULL;
1388
1389 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390}
1391
1392static int dvb_fini(struct saa7134_dev *dev)
1393{
Mauro Carvalho Chehab7f171122007-10-18 19:56:47 -03001394 /* FIXME: I suspect that this code is bogus, since the entry for
1395 Pinnacle 300I DVB-T PAL already defines the proper init to allow
1396 the detection of mt2032 (TDA9887_PORT2_INACTIVE)
1397 */
1398 if (dev->board == SAA7134_BOARD_PINNACLE_300I_DVBT_PAL) {
1399 struct v4l2_priv_tun_config tda9887_cfg;
1400 static int on = TDA9887_PRESENT | TDA9887_PORT2_INACTIVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401
Mauro Carvalho Chehab7f171122007-10-18 19:56:47 -03001402 tda9887_cfg.tuner = TUNER_TDA9887;
1403 tda9887_cfg.priv = &on;
1404
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405 /* otherwise we don't detect the tuner on next insmod */
Mauro Carvalho Chehab7f171122007-10-18 19:56:47 -03001406 saa7134_i2c_call_clients(dev, TUNER_SET_CONFIG, &tda9887_cfg);
Hartmut Hackmann5823b3a2008-04-22 14:46:08 -03001407 } else if (dev->board == SAA7134_BOARD_MEDION_MD8800_QUADRO) {
Hartmut Hackmanne9c1ac92008-04-22 14:46:10 -03001408 if ((dev->eedata[2] == 0x07) && use_frontend) {
Hartmut Hackmann5823b3a2008-04-22 14:46:08 -03001409 /* turn off the 2nd lnb supply */
1410 u8 data = 0x80;
1411 struct i2c_msg msg = {.addr = 0x08, .buf = &data, .flags = 0, .len = 1};
1412 struct dvb_frontend *fe;
1413 fe = dev->dvb.frontend;
1414 if (fe->ops.i2c_gate_ctrl) {
1415 fe->ops.i2c_gate_ctrl(fe, 1);
1416 i2c_transfer(&dev->i2c_adap, &msg, 1);
1417 fe->ops.i2c_gate_ctrl(fe, 0);
1418 }
1419 }
Mauro Carvalho Chehab7f171122007-10-18 19:56:47 -03001420 }
Mauro Carvalho Chehab9950c1b2008-04-11 11:29:44 -03001421 if (dev->dvb.frontend)
1422 videobuf_dvb_unregister(&dev->dvb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423 return 0;
1424}
1425
1426static struct saa7134_mpeg_ops dvb_ops = {
1427 .type = SAA7134_MPEG_DVB,
1428 .init = dvb_init,
1429 .fini = dvb_fini,
1430};
1431
1432static int __init dvb_register(void)
1433{
1434 return saa7134_ts_register(&dvb_ops);
1435}
1436
1437static void __exit dvb_unregister(void)
1438{
1439 saa7134_ts_unregister(&dvb_ops);
1440}
1441
1442module_init(dvb_register);
1443module_exit(dvb_unregister);
1444
1445/* ------------------------------------------------------------------ */
1446/*
1447 * Local variables:
1448 * c-basic-offset: 8
1449 * End:
1450 */