blob: 2607de134fa68e511c90f37f4da5a31b9684b7af [file] [log] [blame]
Steven Tothd19770e2007-03-11 20:44:05 -03001/*
2 * Driver for the Conexant CX23885 PCIe bridge
3 *
Steven Toth6d897612008-09-03 17:12:12 -03004 * Copyright (c) 2006 Steven Toth <stoth@linuxtv.org>
Steven Tothd19770e2007-03-11 20:44:05 -03005 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 *
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22#include <linux/module.h>
23#include <linux/init.h>
24#include <linux/device.h>
25#include <linux/fs.h>
26#include <linux/kthread.h>
27#include <linux/file.h>
28#include <linux/suspend.h>
29
30#include "cx23885.h"
Steven Tothd19770e2007-03-11 20:44:05 -030031#include <media/v4l2-common.h>
32
Igor M. Liplianin5a23b072009-03-03 12:06:09 -030033#include "dvb_ca_en50221.h"
Steven Tothd19770e2007-03-11 20:44:05 -030034#include "s5h1409.h"
Michael Krufky52b50452008-07-09 02:18:49 -030035#include "s5h1411.h"
Steven Tothd19770e2007-03-11 20:44:05 -030036#include "mt2131.h"
Michael Krufky3ba71d22007-12-07 01:40:36 -030037#include "tda8290.h"
Michael Krufky4041f1a2007-12-24 04:52:08 -030038#include "tda18271.h"
Michael Krufky9bc37ca2007-09-08 15:17:13 -030039#include "lgdt330x.h"
Steven Tothd1987d52007-12-18 01:57:06 -030040#include "xc5000.h"
David T. L. Wongea5697f2009-10-26 08:54:04 -030041#include "max2165.h"
Steven Tothb3ea0162008-04-19 01:14:19 -030042#include "tda10048.h"
Michael Krufky07b4a832007-12-18 01:09:11 -030043#include "tuner-xc2028.h"
Michael Krufky827855d2008-04-22 14:46:16 -030044#include "tuner-simple.h"
Steven Toth66762372008-04-22 15:38:26 -030045#include "dib7000p.h"
46#include "dibx000_common.h"
Steven Tothaef2d182008-08-04 21:39:53 -030047#include "zl10353.h"
Igor M. Liplianin5a23b072009-03-03 12:06:09 -030048#include "stv0900.h"
Igor M. Liplianinf867c3f2009-06-19 05:45:23 -030049#include "stv0900_reg.h"
Igor M. Liplianin5a23b072009-03-03 12:06:09 -030050#include "stv6110.h"
51#include "lnbh24.h"
Igor M. Liplianin96318d02009-01-17 12:11:20 -030052#include "cx24116.h"
Igor M. Liplianin5a23b072009-03-03 12:06:09 -030053#include "cimax2.h"
David Wong493b7122009-05-18 05:25:49 -030054#include "lgs8gxx.h"
Igor M. Liplianin5a23b072009-03-03 12:06:09 -030055#include "netup-eeprom.h"
56#include "netup-init.h"
Michael Krufkya5dbf452009-05-03 23:27:02 -030057#include "lgdt3305.h"
David T. L. Wongea5697f2009-10-26 08:54:04 -030058#include "atbm8830.h"
Igor M. Liplianin09ea33e2009-11-24 20:16:04 -030059#include "ds3000.h"
60#include "cx23885-f300.h"
Steven Tothd19770e2007-03-11 20:44:05 -030061
Steven Toth4513fc692008-01-12 11:36:36 -030062static unsigned int debug;
Steven Tothd19770e2007-03-11 20:44:05 -030063
Steven Toth4513fc692008-01-12 11:36:36 -030064#define dprintk(level, fmt, arg...)\
65 do { if (debug >= level)\
66 printk(KERN_DEBUG "%s/0: " fmt, dev->name, ## arg);\
67 } while (0)
Steven Tothd19770e2007-03-11 20:44:05 -030068
69/* ------------------------------------------------------------------ */
70
Michael Krufky3ba71d22007-12-07 01:40:36 -030071static unsigned int alt_tuner;
72module_param(alt_tuner, int, 0644);
73MODULE_PARM_DESC(alt_tuner, "Enable alternate tuner configuration");
74
Janne Grunau78e92002008-04-09 19:13:13 -030075DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
76
Michael Krufky3ba71d22007-12-07 01:40:36 -030077/* ------------------------------------------------------------------ */
78
Steven Tothd19770e2007-03-11 20:44:05 -030079static int dvb_buf_setup(struct videobuf_queue *q,
80 unsigned int *count, unsigned int *size)
81{
82 struct cx23885_tsport *port = q->priv_data;
83
84 port->ts_packet_size = 188 * 4;
85 port->ts_packet_count = 32;
86
87 *size = port->ts_packet_size * port->ts_packet_count;
88 *count = 32;
89 return 0;
90}
91
Michael Krufky44a64812007-03-20 23:00:18 -030092static int dvb_buf_prepare(struct videobuf_queue *q,
93 struct videobuf_buffer *vb, enum v4l2_field field)
Steven Tothd19770e2007-03-11 20:44:05 -030094{
95 struct cx23885_tsport *port = q->priv_data;
Steven Toth9c8ced52008-10-16 20:18:44 -030096 return cx23885_buf_prepare(q, port, (struct cx23885_buffer *)vb, field);
Steven Tothd19770e2007-03-11 20:44:05 -030097}
98
99static void dvb_buf_queue(struct videobuf_queue *q, struct videobuf_buffer *vb)
100{
101 struct cx23885_tsport *port = q->priv_data;
Steven Toth9c8ced52008-10-16 20:18:44 -0300102 cx23885_buf_queue(port, (struct cx23885_buffer *)vb);
Steven Tothd19770e2007-03-11 20:44:05 -0300103}
104
Michael Krufky44a64812007-03-20 23:00:18 -0300105static void dvb_buf_release(struct videobuf_queue *q,
106 struct videobuf_buffer *vb)
Steven Tothd19770e2007-03-11 20:44:05 -0300107{
Steven Toth9c8ced52008-10-16 20:18:44 -0300108 cx23885_free_buffer(q, (struct cx23885_buffer *)vb);
Steven Tothd19770e2007-03-11 20:44:05 -0300109}
110
111static struct videobuf_queue_ops dvb_qops = {
112 .buf_setup = dvb_buf_setup,
113 .buf_prepare = dvb_buf_prepare,
114 .buf_queue = dvb_buf_queue,
115 .buf_release = dvb_buf_release,
116};
117
Steven Toth86184e02007-09-04 21:40:47 -0300118static struct s5h1409_config hauppauge_generic_config = {
Steven Tothd19770e2007-03-11 20:44:05 -0300119 .demod_address = 0x32 >> 1,
120 .output_mode = S5H1409_SERIAL_OUTPUT,
Steven Tothfc959be2007-09-08 19:08:17 -0300121 .gpio = S5H1409_GPIO_ON,
Michael Krufky2b032382007-12-13 10:04:10 -0300122 .qam_if = 44000,
Steven Tothfc959be2007-09-08 19:08:17 -0300123 .inversion = S5H1409_INVERSION_OFF,
Steven Tothdfc1c082008-01-15 21:35:22 -0300124 .status_mode = S5H1409_DEMODLOCKING,
125 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
Steven Tothfc959be2007-09-08 19:08:17 -0300126};
127
Steven Tothb3ea0162008-04-19 01:14:19 -0300128static struct tda10048_config hauppauge_hvr1200_config = {
129 .demod_address = 0x10 >> 1,
130 .output_mode = TDA10048_SERIAL_OUTPUT,
131 .fwbulkwritelen = TDA10048_BULKWRITE_200,
Steven Toth484d9e02009-05-02 11:08:23 -0300132 .inversion = TDA10048_INVERSION_ON,
Steven Toth8816bef2009-05-15 21:04:18 -0300133 .dtv6_if_freq_khz = TDA10048_IF_3300,
134 .dtv7_if_freq_khz = TDA10048_IF_3800,
135 .dtv8_if_freq_khz = TDA10048_IF_4300,
Steven Toth484d9e02009-05-02 11:08:23 -0300136 .clk_freq_khz = TDA10048_CLK_16000,
Steven Tothb3ea0162008-04-19 01:14:19 -0300137};
138
Michael Krufky6b926ec2009-05-12 17:32:17 -0300139static struct tda10048_config hauppauge_hvr1210_config = {
140 .demod_address = 0x10 >> 1,
141 .output_mode = TDA10048_SERIAL_OUTPUT,
142 .fwbulkwritelen = TDA10048_BULKWRITE_200,
143 .inversion = TDA10048_INVERSION_ON,
Michael Krufkyc27586e2009-05-16 11:00:23 -0300144 .dtv6_if_freq_khz = TDA10048_IF_3300,
145 .dtv7_if_freq_khz = TDA10048_IF_3500,
146 .dtv8_if_freq_khz = TDA10048_IF_4000,
Michael Krufky6b926ec2009-05-12 17:32:17 -0300147 .clk_freq_khz = TDA10048_CLK_16000,
148};
149
Michael Krufky3ba71d22007-12-07 01:40:36 -0300150static struct s5h1409_config hauppauge_ezqam_config = {
151 .demod_address = 0x32 >> 1,
152 .output_mode = S5H1409_SERIAL_OUTPUT,
153 .gpio = S5H1409_GPIO_OFF,
154 .qam_if = 4000,
155 .inversion = S5H1409_INVERSION_ON,
Steven Tothdfc1c082008-01-15 21:35:22 -0300156 .status_mode = S5H1409_DEMODLOCKING,
157 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
Michael Krufky3ba71d22007-12-07 01:40:36 -0300158};
159
Steven Tothfc959be2007-09-08 19:08:17 -0300160static struct s5h1409_config hauppauge_hvr1800lp_config = {
161 .demod_address = 0x32 >> 1,
162 .output_mode = S5H1409_SERIAL_OUTPUT,
Steven Tothd19770e2007-03-11 20:44:05 -0300163 .gpio = S5H1409_GPIO_OFF,
Michael Krufky2b032382007-12-13 10:04:10 -0300164 .qam_if = 44000,
Steven Tothfe4751632007-03-20 15:27:53 -0300165 .inversion = S5H1409_INVERSION_OFF,
Steven Tothdfc1c082008-01-15 21:35:22 -0300166 .status_mode = S5H1409_DEMODLOCKING,
167 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
Steven Tothd19770e2007-03-11 20:44:05 -0300168};
169
Michael Krufky07b4a832007-12-18 01:09:11 -0300170static struct s5h1409_config hauppauge_hvr1500_config = {
171 .demod_address = 0x32 >> 1,
172 .output_mode = S5H1409_SERIAL_OUTPUT,
173 .gpio = S5H1409_GPIO_OFF,
174 .inversion = S5H1409_INVERSION_OFF,
Steven Tothdfc1c082008-01-15 21:35:22 -0300175 .status_mode = S5H1409_DEMODLOCKING,
176 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
Michael Krufky07b4a832007-12-18 01:09:11 -0300177};
178
Steven Toth86184e02007-09-04 21:40:47 -0300179static struct mt2131_config hauppauge_generic_tunerconfig = {
Steven Totha77743b2007-08-22 21:01:20 -0300180 0x61
181};
182
Michael Krufky9bc37ca2007-09-08 15:17:13 -0300183static struct lgdt330x_config fusionhdtv_5_express = {
184 .demod_address = 0x0e,
185 .demod_chip = LGDT3303,
186 .serial_mpeg = 0x40,
187};
188
Steven Tothd1987d52007-12-18 01:57:06 -0300189static struct s5h1409_config hauppauge_hvr1500q_config = {
190 .demod_address = 0x32 >> 1,
191 .output_mode = S5H1409_SERIAL_OUTPUT,
192 .gpio = S5H1409_GPIO_ON,
193 .qam_if = 44000,
194 .inversion = S5H1409_INVERSION_OFF,
Steven Tothdfc1c082008-01-15 21:35:22 -0300195 .status_mode = S5H1409_DEMODLOCKING,
196 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
Steven Tothd1987d52007-12-18 01:57:06 -0300197};
198
Michael Krufky335377b2008-05-07 01:43:10 -0300199static struct s5h1409_config dvico_s5h1409_config = {
200 .demod_address = 0x32 >> 1,
201 .output_mode = S5H1409_SERIAL_OUTPUT,
202 .gpio = S5H1409_GPIO_ON,
203 .qam_if = 44000,
204 .inversion = S5H1409_INVERSION_OFF,
205 .status_mode = S5H1409_DEMODLOCKING,
206 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
207};
208
Michael Krufky52b50452008-07-09 02:18:49 -0300209static struct s5h1411_config dvico_s5h1411_config = {
210 .output_mode = S5H1411_SERIAL_OUTPUT,
211 .gpio = S5H1411_GPIO_ON,
212 .qam_if = S5H1411_IF_44000,
213 .vsb_if = S5H1411_IF_44000,
214 .inversion = S5H1411_INVERSION_OFF,
215 .status_mode = S5H1411_DEMODLOCKING,
216 .mpeg_timing = S5H1411_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
217};
218
Michael Krufky19bc5792009-05-08 16:05:29 -0300219static struct s5h1411_config hcw_s5h1411_config = {
220 .output_mode = S5H1411_SERIAL_OUTPUT,
221 .gpio = S5H1411_GPIO_OFF,
222 .vsb_if = S5H1411_IF_44000,
223 .qam_if = S5H1411_IF_4000,
224 .inversion = S5H1411_INVERSION_ON,
225 .status_mode = S5H1411_DEMODLOCKING,
226 .mpeg_timing = S5H1411_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
227};
228
Steven Tothd1987d52007-12-18 01:57:06 -0300229static struct xc5000_config hauppauge_hvr1500q_tunerconfig = {
Steven Tothe12671cf2007-12-20 01:14:43 -0300230 .i2c_address = 0x61,
231 .if_khz = 5380,
Steven Tothd1987d52007-12-18 01:57:06 -0300232};
233
Michael Krufky335377b2008-05-07 01:43:10 -0300234static struct xc5000_config dvico_xc5000_tunerconfig = {
235 .i2c_address = 0x64,
236 .if_khz = 5380,
Michael Krufky335377b2008-05-07 01:43:10 -0300237};
238
Michael Krufky4041f1a2007-12-24 04:52:08 -0300239static struct tda829x_config tda829x_no_probe = {
240 .probe_tuner = TDA829X_DONT_PROBE,
241};
242
Michael Krufkyf21e0d72008-01-02 03:01:54 -0300243static struct tda18271_std_map hauppauge_tda18271_std_map = {
Michael Krufkyc0dc0c12008-04-22 14:46:22 -0300244 .atsc_6 = { .if_freq = 5380, .agc_mode = 3, .std = 3,
245 .if_lvl = 6, .rfagc_top = 0x37 },
246 .qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 0,
247 .if_lvl = 6, .rfagc_top = 0x37 },
Michael Krufkyf21e0d72008-01-02 03:01:54 -0300248};
249
Michael Krufkyb34cdc32009-05-21 12:49:28 -0300250static struct tda18271_std_map hauppauge_hvr1200_tda18271_std_map = {
251 .dvbt_6 = { .if_freq = 3300, .agc_mode = 3, .std = 4,
252 .if_lvl = 1, .rfagc_top = 0x37, },
253 .dvbt_7 = { .if_freq = 3800, .agc_mode = 3, .std = 5,
254 .if_lvl = 1, .rfagc_top = 0x37, },
255 .dvbt_8 = { .if_freq = 4300, .agc_mode = 3, .std = 6,
256 .if_lvl = 1, .rfagc_top = 0x37, },
257};
258
Michael Krufkyf21e0d72008-01-02 03:01:54 -0300259static struct tda18271_config hauppauge_tda18271_config = {
260 .std_map = &hauppauge_tda18271_std_map,
261 .gate = TDA18271_GATE_ANALOG,
Michael Krufky04a68ba2009-09-06 14:11:09 -0300262 .output_opt = TDA18271_OUTPUT_LT_OFF,
Michael Krufkyf21e0d72008-01-02 03:01:54 -0300263};
264
Steven Tothb3ea0162008-04-19 01:14:19 -0300265static struct tda18271_config hauppauge_hvr1200_tuner_config = {
Michael Krufkyb34cdc32009-05-21 12:49:28 -0300266 .std_map = &hauppauge_hvr1200_tda18271_std_map,
Steven Tothb3ea0162008-04-19 01:14:19 -0300267 .gate = TDA18271_GATE_ANALOG,
Michael Krufky04a68ba2009-09-06 14:11:09 -0300268 .output_opt = TDA18271_OUTPUT_LT_OFF,
Steven Tothb3ea0162008-04-19 01:14:19 -0300269};
270
Michael Krufky6b926ec2009-05-12 17:32:17 -0300271static struct tda18271_config hauppauge_hvr1210_tuner_config = {
272 .gate = TDA18271_GATE_DIGITAL,
Michael Krufky04a68ba2009-09-06 14:11:09 -0300273 .output_opt = TDA18271_OUTPUT_LT_OFF,
Michael Krufky6b926ec2009-05-12 17:32:17 -0300274};
275
Michael Krufky247bc542009-05-12 18:53:47 -0300276static struct tda18271_std_map hauppauge_hvr127x_std_map = {
Michael Krufkya5dbf452009-05-03 23:27:02 -0300277 .atsc_6 = { .if_freq = 3250, .agc_mode = 3, .std = 4,
278 .if_lvl = 1, .rfagc_top = 0x58 },
279 .qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 5,
280 .if_lvl = 1, .rfagc_top = 0x58 },
281};
282
Michael Krufky247bc542009-05-12 18:53:47 -0300283static struct tda18271_config hauppauge_hvr127x_config = {
284 .std_map = &hauppauge_hvr127x_std_map,
Michael Krufky04a68ba2009-09-06 14:11:09 -0300285 .output_opt = TDA18271_OUTPUT_LT_OFF,
Michael Krufkya5dbf452009-05-03 23:27:02 -0300286};
287
Michael Krufky247bc542009-05-12 18:53:47 -0300288static struct lgdt3305_config hauppauge_lgdt3305_config = {
Michael Krufkya5dbf452009-05-03 23:27:02 -0300289 .i2c_addr = 0x0e,
290 .mpeg_mode = LGDT3305_MPEG_SERIAL,
291 .tpclk_edge = LGDT3305_TPCLK_FALLING_EDGE,
292 .tpvalid_polarity = LGDT3305_TP_VALID_HIGH,
293 .deny_i2c_rptr = 1,
294 .spectral_inversion = 1,
295 .qam_if_khz = 4000,
296 .vsb_if_khz = 3250,
297};
298
Harvey Harrisonb1721d02008-04-25 19:03:08 -0700299static struct dibx000_agc_config xc3028_agc_config = {
Steven Toth66762372008-04-22 15:38:26 -0300300 BAND_VHF | BAND_UHF, /* band_caps */
301
302 /* P_agc_use_sd_mod1=0, P_agc_use_sd_mod2=0, P_agc_freq_pwm_div=0,
303 * P_agc_inv_pwm1=0, P_agc_inv_pwm2=0,
304 * P_agc_inh_dc_rv_est=0, P_agc_time_est=3, P_agc_freeze=0,
305 * P_agc_nb_est=2, P_agc_write=0
306 */
307 (0 << 15) | (0 << 14) | (0 << 11) | (0 << 10) | (0 << 9) | (0 << 8) |
308 (3 << 5) | (0 << 4) | (2 << 1) | (0 << 0), /* setup */
309
310 712, /* inv_gain */
311 21, /* time_stabiliz */
312
313 0, /* alpha_level */
314 118, /* thlock */
315
316 0, /* wbd_inv */
317 2867, /* wbd_ref */
318 0, /* wbd_sel */
319 2, /* wbd_alpha */
320
321 0, /* agc1_max */
322 0, /* agc1_min */
323 39718, /* agc2_max */
324 9930, /* agc2_min */
325 0, /* agc1_pt1 */
326 0, /* agc1_pt2 */
327 0, /* agc1_pt3 */
328 0, /* agc1_slope1 */
329 0, /* agc1_slope2 */
330 0, /* agc2_pt1 */
331 128, /* agc2_pt2 */
332 29, /* agc2_slope1 */
333 29, /* agc2_slope2 */
334
335 17, /* alpha_mant */
336 27, /* alpha_exp */
337 23, /* beta_mant */
338 51, /* beta_exp */
339
340 1, /* perform_agc_softsplit */
341};
342
343/* PLL Configuration for COFDM BW_MHz = 8.000000
344 * With external clock = 30.000000 */
Harvey Harrisonb1721d02008-04-25 19:03:08 -0700345static struct dibx000_bandwidth_config xc3028_bw_config = {
Steven Toth66762372008-04-22 15:38:26 -0300346 60000, /* internal */
347 30000, /* sampling */
348 1, /* pll_cfg: prediv */
349 8, /* pll_cfg: ratio */
350 3, /* pll_cfg: range */
351 1, /* pll_cfg: reset */
352 0, /* pll_cfg: bypass */
353 0, /* misc: refdiv */
354 0, /* misc: bypclk_div */
355 1, /* misc: IO_CLK_en_core */
356 1, /* misc: ADClkSrc */
357 0, /* misc: modulo */
358 (3 << 14) | (1 << 12) | (524 << 0), /* sad_cfg: refsel, sel, freq_15k */
359 (1 << 25) | 5816102, /* ifreq = 5.200000 MHz */
360 20452225, /* timf */
361 30000000 /* xtal_hz */
362};
363
364static struct dib7000p_config hauppauge_hvr1400_dib7000_config = {
365 .output_mpeg2_in_188_bytes = 1,
366 .hostbus_diversity = 1,
367 .tuner_is_baseband = 0,
368 .update_lna = NULL,
369
370 .agc_config_count = 1,
371 .agc = &xc3028_agc_config,
372 .bw = &xc3028_bw_config,
373
374 .gpio_dir = DIB7000P_GPIO_DEFAULT_DIRECTIONS,
375 .gpio_val = DIB7000P_GPIO_DEFAULT_VALUES,
376 .gpio_pwm_pos = DIB7000P_GPIO_DEFAULT_PWM_POS,
377
378 .pwm_freq_div = 0,
379 .agc_control = NULL,
380 .spur_protect = 0,
381
382 .output_mode = OUTMODE_MPEG2_SERIAL,
383};
384
Steven Tothaef2d182008-08-04 21:39:53 -0300385static struct zl10353_config dvico_fusionhdtv_xc3028 = {
386 .demod_address = 0x0f,
387 .if2 = 45600,
388 .no_tuner = 1,
Christopher Pascoed4dc6732009-04-27 11:27:04 -0300389 .disable_i2c_gate_ctrl = 1,
Steven Tothaef2d182008-08-04 21:39:53 -0300390};
391
Igor M. Liplianinf867c3f2009-06-19 05:45:23 -0300392static struct stv0900_reg stv0900_ts_regs[] = {
393 { R0900_TSGENERAL, 0x00 },
394 { R0900_P1_TSSPEED, 0x40 },
395 { R0900_P2_TSSPEED, 0x40 },
396 { R0900_P1_TSCFGM, 0xc0 },
397 { R0900_P2_TSCFGM, 0xc0 },
398 { R0900_P1_TSCFGH, 0xe0 },
399 { R0900_P2_TSCFGH, 0xe0 },
400 { R0900_P1_TSCFGL, 0x20 },
401 { R0900_P2_TSCFGL, 0x20 },
402 { 0xffff, 0xff }, /* terminate */
403};
404
Igor M. Liplianin5a23b072009-03-03 12:06:09 -0300405static struct stv0900_config netup_stv0900_config = {
406 .demod_address = 0x68,
Igor M. Liplianin29372a82009-10-17 08:58:26 -0300407 .demod_mode = 1, /* dual */
Abylay Ospan644c7ef02009-07-19 18:06:00 -0300408 .xtal = 8000000,
Igor M. Liplianin5a23b072009-03-03 12:06:09 -0300409 .clkmode = 3,/* 0-CLKI, 2-XTALI, else AUTO */
410 .diseqc_mode = 2,/* 2/3 PWM */
Igor M. Liplianinf867c3f2009-06-19 05:45:23 -0300411 .ts_config_regs = stv0900_ts_regs,
Igor M. Liplianin5a23b072009-03-03 12:06:09 -0300412 .tun1_maddress = 0,/* 0x60 */
413 .tun2_maddress = 3,/* 0x63 */
414 .tun1_adc = 1,/* 1 Vpp */
415 .tun2_adc = 1,/* 1 Vpp */
416};
417
418static struct stv6110_config netup_stv6110_tunerconfig_a = {
419 .i2c_address = 0x60,
Abylay Ospan644c7ef02009-07-19 18:06:00 -0300420 .mclk = 16000000,
421 .clk_div = 1,
Abylay Ospan873688c2009-10-17 08:23:00 -0300422 .gain = 8, /* +16 dB - maximum gain */
Igor M. Liplianin5a23b072009-03-03 12:06:09 -0300423};
424
425static struct stv6110_config netup_stv6110_tunerconfig_b = {
426 .i2c_address = 0x63,
Abylay Ospan644c7ef02009-07-19 18:06:00 -0300427 .mclk = 16000000,
428 .clk_div = 1,
Abylay Ospan873688c2009-10-17 08:23:00 -0300429 .gain = 8, /* +16 dB - maximum gain */
Igor M. Liplianin5a23b072009-03-03 12:06:09 -0300430};
431
Igor M. Liplianin96318d02009-01-17 12:11:20 -0300432static struct cx24116_config tbs_cx24116_config = {
Igor M. Liplianin09ea33e2009-11-24 20:16:04 -0300433 .demod_address = 0x55,
Igor M. Liplianin96318d02009-01-17 12:11:20 -0300434};
435
Igor M. Liplianin09ea33e2009-11-24 20:16:04 -0300436static struct ds3000_config tevii_ds3000_config = {
437 .demod_address = 0x68,
Igor M. Liplianin579943f2009-01-17 12:18:26 -0300438};
439
Igor M. Liplianinc9b8b042009-01-17 12:23:31 -0300440static struct cx24116_config dvbworld_cx24116_config = {
441 .demod_address = 0x05,
442};
443
David Wong493b7122009-05-18 05:25:49 -0300444static struct lgs8gxx_config mygica_x8506_lgs8gl5_config = {
445 .prod = LGS8GXX_PROD_LGS8GL5,
446 .demod_address = 0x19,
447 .serial_ts = 0,
448 .ts_clk_pol = 1,
449 .ts_clk_gated = 1,
450 .if_clk_freq = 30400, /* 30.4 MHz */
451 .if_freq = 5380, /* 5.38 MHz */
452 .if_neg_center = 1,
453 .ext_adc = 0,
454 .adc_signed = 0,
455 .if_neg_edge = 0,
456};
457
458static struct xc5000_config mygica_x8506_xc5000_config = {
459 .i2c_address = 0x61,
460 .if_khz = 5380,
461};
462
Michael Krufkyf35b9e82009-05-08 22:39:24 -0300463static int cx23885_dvb_set_frontend(struct dvb_frontend *fe,
464 struct dvb_frontend_parameters *param)
465{
466 struct cx23885_tsport *port = fe->dvb->priv;
467 struct cx23885_dev *dev = port->dev;
468
469 switch (dev->board) {
470 case CX23885_BOARD_HAUPPAUGE_HVR1275:
471 switch (param->u.vsb.modulation) {
472 case VSB_8:
473 cx23885_gpio_clear(dev, GPIO_5);
474 break;
475 case QAM_64:
476 case QAM_256:
477 default:
478 cx23885_gpio_set(dev, GPIO_5);
479 break;
480 }
481 break;
David T.L. Wong6f0d8c02009-10-21 13:15:30 -0300482 case CX23885_BOARD_MYGICA_X8506:
483 case CX23885_BOARD_MAGICPRO_PROHDTVE2:
484 /* Select Digital TV */
485 cx23885_gpio_set(dev, GPIO_0);
486 break;
Michael Krufkyf35b9e82009-05-08 22:39:24 -0300487 }
Michael Krufky5bdd3962009-05-08 22:39:24 -0300488 return 0;
Michael Krufkyf35b9e82009-05-08 22:39:24 -0300489}
490
Michael Krufky5bdd3962009-05-08 22:39:24 -0300491static int cx23885_dvb_fe_ioctl_override(struct dvb_frontend *fe,
492 unsigned int cmd, void *parg,
493 unsigned int stage)
494{
495 int err = 0;
496
497 switch (stage) {
498 case DVB_FE_IOCTL_PRE:
499
500 switch (cmd) {
501 case FE_SET_FRONTEND:
502 err = cx23885_dvb_set_frontend(fe,
503 (struct dvb_frontend_parameters *) parg);
504 break;
505 }
506 break;
507
508 case DVB_FE_IOCTL_POST:
509 /* no post-ioctl handling required */
510 break;
511 }
512 return err;
513};
514
515
David Wong2365b2d2009-06-17 01:38:12 -0300516static struct lgs8gxx_config magicpro_prohdtve2_lgs8g75_config = {
517 .prod = LGS8GXX_PROD_LGS8G75,
518 .demod_address = 0x19,
519 .serial_ts = 0,
520 .ts_clk_pol = 1,
521 .ts_clk_gated = 1,
522 .if_clk_freq = 30400, /* 30.4 MHz */
523 .if_freq = 6500, /* 6.50 MHz */
524 .if_neg_center = 1,
525 .ext_adc = 0,
526 .adc_signed = 1,
527 .adc_vpp = 2, /* 1.6 Vpp */
528 .if_neg_edge = 1,
529};
530
531static struct xc5000_config magicpro_prohdtve2_xc5000_config = {
532 .i2c_address = 0x61,
533 .if_khz = 6500,
534};
535
David T. L. Wongea5697f2009-10-26 08:54:04 -0300536static struct atbm8830_config mygica_x8558pro_atbm8830_cfg1 = {
537 .prod = ATBM8830_PROD_8830,
538 .demod_address = 0x44,
539 .serial_ts = 0,
540 .ts_sampling_edge = 1,
541 .ts_clk_gated = 0,
542 .osc_clk_freq = 30400, /* in kHz */
543 .if_freq = 0, /* zero IF */
544 .zif_swap_iq = 1,
545};
546
547static struct max2165_config mygic_x8558pro_max2165_cfg1 = {
548 .i2c_address = 0x60,
549 .osc_clk = 20
550};
551
552static struct atbm8830_config mygica_x8558pro_atbm8830_cfg2 = {
553 .prod = ATBM8830_PROD_8830,
554 .demod_address = 0x44,
555 .serial_ts = 1,
556 .ts_sampling_edge = 1,
557 .ts_clk_gated = 0,
558 .osc_clk_freq = 30400, /* in kHz */
559 .if_freq = 0, /* zero IF */
560 .zif_swap_iq = 1,
561};
562
563static struct max2165_config mygic_x8558pro_max2165_cfg2 = {
564 .i2c_address = 0x60,
565 .osc_clk = 20
566};
567
Steven Tothd19770e2007-03-11 20:44:05 -0300568static int dvb_register(struct cx23885_tsport *port)
569{
570 struct cx23885_dev *dev = port->dev;
David Wong493b7122009-05-18 05:25:49 -0300571 struct cx23885_i2c *i2c_bus = NULL, *i2c_bus2 = NULL;
Steven Toth363c35f2008-10-11 11:05:50 -0300572 struct videobuf_dvb_frontend *fe0;
Igor M. Liplianin5a23b072009-03-03 12:06:09 -0300573 int ret;
Steven Toth363c35f2008-10-11 11:05:50 -0300574
Darron Broadf972e0bd2008-10-11 11:24:30 -0300575 /* Get the first frontend */
Darron Broad92abe9e2008-10-11 11:18:53 -0300576 fe0 = videobuf_dvb_get_frontend(&port->frontends, 1);
Steven Toth363c35f2008-10-11 11:05:50 -0300577 if (!fe0)
578 return -EINVAL;
Steven Tothd19770e2007-03-11 20:44:05 -0300579
580 /* init struct videobuf_dvb */
Steven Toth363c35f2008-10-11 11:05:50 -0300581 fe0->dvb.name = dev->name;
Steven Tothd19770e2007-03-11 20:44:05 -0300582
583 /* init frontend */
584 switch (dev->board) {
Steven Totha77743b2007-08-22 21:01:20 -0300585 case CX23885_BOARD_HAUPPAUGE_HVR1250:
Michael Krufkyf139fa72007-09-09 03:55:34 -0300586 i2c_bus = &dev->i2c_bus[0];
Steven Toth363c35f2008-10-11 11:05:50 -0300587 fe0->dvb.frontend = dvb_attach(s5h1409_attach,
Steven Toth86184e02007-09-04 21:40:47 -0300588 &hauppauge_generic_config,
Michael Krufkyf139fa72007-09-09 03:55:34 -0300589 &i2c_bus->i2c_adap);
Steven Toth363c35f2008-10-11 11:05:50 -0300590 if (fe0->dvb.frontend != NULL) {
591 dvb_attach(mt2131_attach, fe0->dvb.frontend,
Michael Krufkyf139fa72007-09-09 03:55:34 -0300592 &i2c_bus->i2c_adap,
Steven Toth86184e02007-09-04 21:40:47 -0300593 &hauppauge_generic_tunerconfig, 0);
Steven Tothd19770e2007-03-11 20:44:05 -0300594 }
595 break;
Michael Krufkya5dbf452009-05-03 23:27:02 -0300596 case CX23885_BOARD_HAUPPAUGE_HVR1270:
Michael Krufkyd099bec2009-05-08 22:39:24 -0300597 case CX23885_BOARD_HAUPPAUGE_HVR1275:
Michael Krufkya5dbf452009-05-03 23:27:02 -0300598 i2c_bus = &dev->i2c_bus[0];
599 fe0->dvb.frontend = dvb_attach(lgdt3305_attach,
Michael Krufky247bc542009-05-12 18:53:47 -0300600 &hauppauge_lgdt3305_config,
Michael Krufkya5dbf452009-05-03 23:27:02 -0300601 &i2c_bus->i2c_adap);
602 if (fe0->dvb.frontend != NULL) {
603 dvb_attach(tda18271_attach, fe0->dvb.frontend,
604 0x60, &dev->i2c_bus[1].i2c_adap,
Michael Krufky247bc542009-05-12 18:53:47 -0300605 &hauppauge_hvr127x_config);
Michael Krufkya5dbf452009-05-03 23:27:02 -0300606 }
607 break;
Michael Krufky19bc5792009-05-08 16:05:29 -0300608 case CX23885_BOARD_HAUPPAUGE_HVR1255:
609 i2c_bus = &dev->i2c_bus[0];
610 fe0->dvb.frontend = dvb_attach(s5h1411_attach,
611 &hcw_s5h1411_config,
612 &i2c_bus->i2c_adap);
613 if (fe0->dvb.frontend != NULL) {
614 dvb_attach(tda18271_attach, fe0->dvb.frontend,
615 0x60, &dev->i2c_bus[1].i2c_adap,
616 &hauppauge_tda18271_config);
617 }
618 break;
Michael Krufky3ba71d22007-12-07 01:40:36 -0300619 case CX23885_BOARD_HAUPPAUGE_HVR1800:
620 i2c_bus = &dev->i2c_bus[0];
Darron Broad92abe9e2008-10-11 11:18:53 -0300621 switch (alt_tuner) {
Michael Krufky3ba71d22007-12-07 01:40:36 -0300622 case 1:
Steven Toth363c35f2008-10-11 11:05:50 -0300623 fe0->dvb.frontend =
Michael Krufky3ba71d22007-12-07 01:40:36 -0300624 dvb_attach(s5h1409_attach,
625 &hauppauge_ezqam_config,
626 &i2c_bus->i2c_adap);
Steven Toth363c35f2008-10-11 11:05:50 -0300627 if (fe0->dvb.frontend != NULL) {
628 dvb_attach(tda829x_attach, fe0->dvb.frontend,
Michael Krufky3ba71d22007-12-07 01:40:36 -0300629 &dev->i2c_bus[1].i2c_adap, 0x42,
Michael Krufky4041f1a2007-12-24 04:52:08 -0300630 &tda829x_no_probe);
Steven Toth363c35f2008-10-11 11:05:50 -0300631 dvb_attach(tda18271_attach, fe0->dvb.frontend,
Michael Krufky4041f1a2007-12-24 04:52:08 -0300632 0x60, &dev->i2c_bus[1].i2c_adap,
Michael Krufkyf21e0d72008-01-02 03:01:54 -0300633 &hauppauge_tda18271_config);
Michael Krufky3ba71d22007-12-07 01:40:36 -0300634 }
635 break;
636 case 0:
637 default:
Steven Toth363c35f2008-10-11 11:05:50 -0300638 fe0->dvb.frontend =
Michael Krufky3ba71d22007-12-07 01:40:36 -0300639 dvb_attach(s5h1409_attach,
640 &hauppauge_generic_config,
641 &i2c_bus->i2c_adap);
Steven Toth363c35f2008-10-11 11:05:50 -0300642 if (fe0->dvb.frontend != NULL)
643 dvb_attach(mt2131_attach, fe0->dvb.frontend,
Michael Krufky3ba71d22007-12-07 01:40:36 -0300644 &i2c_bus->i2c_adap,
645 &hauppauge_generic_tunerconfig, 0);
646 break;
647 }
648 break;
Steven Tothfc959be2007-09-08 19:08:17 -0300649 case CX23885_BOARD_HAUPPAUGE_HVR1800lp:
Michael Krufkyf139fa72007-09-09 03:55:34 -0300650 i2c_bus = &dev->i2c_bus[0];
Steven Toth363c35f2008-10-11 11:05:50 -0300651 fe0->dvb.frontend = dvb_attach(s5h1409_attach,
Steven Tothfc959be2007-09-08 19:08:17 -0300652 &hauppauge_hvr1800lp_config,
Michael Krufkyf139fa72007-09-09 03:55:34 -0300653 &i2c_bus->i2c_adap);
Steven Toth363c35f2008-10-11 11:05:50 -0300654 if (fe0->dvb.frontend != NULL) {
655 dvb_attach(mt2131_attach, fe0->dvb.frontend,
Michael Krufkyf139fa72007-09-09 03:55:34 -0300656 &i2c_bus->i2c_adap,
Steven Tothfc959be2007-09-08 19:08:17 -0300657 &hauppauge_generic_tunerconfig, 0);
658 }
659 break;
Michael Krufky9bc37ca2007-09-08 15:17:13 -0300660 case CX23885_BOARD_DVICO_FUSIONHDTV_5_EXP:
Michael Krufkyf139fa72007-09-09 03:55:34 -0300661 i2c_bus = &dev->i2c_bus[0];
Steven Toth363c35f2008-10-11 11:05:50 -0300662 fe0->dvb.frontend = dvb_attach(lgdt330x_attach,
Michael Krufky9bc37ca2007-09-08 15:17:13 -0300663 &fusionhdtv_5_express,
Michael Krufkyf139fa72007-09-09 03:55:34 -0300664 &i2c_bus->i2c_adap);
Steven Toth363c35f2008-10-11 11:05:50 -0300665 if (fe0->dvb.frontend != NULL) {
666 dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
Michael Krufky827855d2008-04-22 14:46:16 -0300667 &i2c_bus->i2c_adap, 0x61,
668 TUNER_LG_TDVS_H06XF);
Michael Krufky9bc37ca2007-09-08 15:17:13 -0300669 }
670 break;
Steven Tothd1987d52007-12-18 01:57:06 -0300671 case CX23885_BOARD_HAUPPAUGE_HVR1500Q:
672 i2c_bus = &dev->i2c_bus[1];
Steven Toth363c35f2008-10-11 11:05:50 -0300673 fe0->dvb.frontend = dvb_attach(s5h1409_attach,
Steven Tothd1987d52007-12-18 01:57:06 -0300674 &hauppauge_hvr1500q_config,
675 &dev->i2c_bus[0].i2c_adap);
Steven Toth363c35f2008-10-11 11:05:50 -0300676 if (fe0->dvb.frontend != NULL)
677 dvb_attach(xc5000_attach, fe0->dvb.frontend,
Michael Krufky30650962008-09-06 14:56:58 -0300678 &i2c_bus->i2c_adap,
679 &hauppauge_hvr1500q_tunerconfig);
Steven Tothd1987d52007-12-18 01:57:06 -0300680 break;
Michael Krufky07b4a832007-12-18 01:09:11 -0300681 case CX23885_BOARD_HAUPPAUGE_HVR1500:
682 i2c_bus = &dev->i2c_bus[1];
Steven Toth363c35f2008-10-11 11:05:50 -0300683 fe0->dvb.frontend = dvb_attach(s5h1409_attach,
Michael Krufky07b4a832007-12-18 01:09:11 -0300684 &hauppauge_hvr1500_config,
685 &dev->i2c_bus[0].i2c_adap);
Steven Toth363c35f2008-10-11 11:05:50 -0300686 if (fe0->dvb.frontend != NULL) {
Michael Krufky07b4a832007-12-18 01:09:11 -0300687 struct dvb_frontend *fe;
688 struct xc2028_config cfg = {
689 .i2c_adap = &i2c_bus->i2c_adap,
690 .i2c_addr = 0x61,
Michael Krufky07b4a832007-12-18 01:09:11 -0300691 };
692 static struct xc2028_ctrl ctl = {
Michael Krufkyef80bfeb2008-09-16 02:15:30 -0300693 .fname = XC2028_DEFAULT_FIRMWARE,
Michael Krufky07b4a832007-12-18 01:09:11 -0300694 .max_len = 64,
Steven Toth52c3d292009-04-20 22:42:00 -0300695 .demod = XC3028_FE_OREN538,
Michael Krufky07b4a832007-12-18 01:09:11 -0300696 };
697
698 fe = dvb_attach(xc2028_attach,
Steven Toth363c35f2008-10-11 11:05:50 -0300699 fe0->dvb.frontend, &cfg);
Michael Krufky07b4a832007-12-18 01:09:11 -0300700 if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
701 fe->ops.tuner_ops.set_config(fe, &ctl);
702 }
703 break;
Steven Tothb3ea0162008-04-19 01:14:19 -0300704 case CX23885_BOARD_HAUPPAUGE_HVR1200:
Steven Totha780a312008-04-19 01:25:52 -0300705 case CX23885_BOARD_HAUPPAUGE_HVR1700:
Steven Tothb3ea0162008-04-19 01:14:19 -0300706 i2c_bus = &dev->i2c_bus[0];
Steven Toth363c35f2008-10-11 11:05:50 -0300707 fe0->dvb.frontend = dvb_attach(tda10048_attach,
Steven Tothb3ea0162008-04-19 01:14:19 -0300708 &hauppauge_hvr1200_config,
709 &i2c_bus->i2c_adap);
Steven Toth363c35f2008-10-11 11:05:50 -0300710 if (fe0->dvb.frontend != NULL) {
711 dvb_attach(tda829x_attach, fe0->dvb.frontend,
Steven Tothb3ea0162008-04-19 01:14:19 -0300712 &dev->i2c_bus[1].i2c_adap, 0x42,
713 &tda829x_no_probe);
Steven Toth363c35f2008-10-11 11:05:50 -0300714 dvb_attach(tda18271_attach, fe0->dvb.frontend,
Steven Tothb3ea0162008-04-19 01:14:19 -0300715 0x60, &dev->i2c_bus[1].i2c_adap,
716 &hauppauge_hvr1200_tuner_config);
717 }
718 break;
Michael Krufky6b926ec2009-05-12 17:32:17 -0300719 case CX23885_BOARD_HAUPPAUGE_HVR1210:
720 i2c_bus = &dev->i2c_bus[0];
721 fe0->dvb.frontend = dvb_attach(tda10048_attach,
722 &hauppauge_hvr1210_config,
723 &i2c_bus->i2c_adap);
724 if (fe0->dvb.frontend != NULL) {
725 dvb_attach(tda18271_attach, fe0->dvb.frontend,
726 0x60, &dev->i2c_bus[1].i2c_adap,
727 &hauppauge_hvr1210_tuner_config);
728 }
729 break;
Steven Toth66762372008-04-22 15:38:26 -0300730 case CX23885_BOARD_HAUPPAUGE_HVR1400:
731 i2c_bus = &dev->i2c_bus[0];
Steven Toth363c35f2008-10-11 11:05:50 -0300732 fe0->dvb.frontend = dvb_attach(dib7000p_attach,
Steven Toth66762372008-04-22 15:38:26 -0300733 &i2c_bus->i2c_adap,
734 0x12, &hauppauge_hvr1400_dib7000_config);
Steven Toth363c35f2008-10-11 11:05:50 -0300735 if (fe0->dvb.frontend != NULL) {
Steven Toth66762372008-04-22 15:38:26 -0300736 struct dvb_frontend *fe;
737 struct xc2028_config cfg = {
738 .i2c_adap = &dev->i2c_bus[1].i2c_adap,
739 .i2c_addr = 0x64,
Steven Toth66762372008-04-22 15:38:26 -0300740 };
741 static struct xc2028_ctrl ctl = {
Michael Krufkyef80bfeb2008-09-16 02:15:30 -0300742 .fname = XC3028L_DEFAULT_FIRMWARE,
Steven Toth66762372008-04-22 15:38:26 -0300743 .max_len = 64,
744 .demod = 5000,
Steven Toth9c8ced52008-10-16 20:18:44 -0300745 /* This is true for all demods with
746 v36 firmware? */
Mauro Carvalho Chehab0975fc62008-09-28 02:24:44 -0300747 .type = XC2028_D2633,
Steven Toth66762372008-04-22 15:38:26 -0300748 };
749
750 fe = dvb_attach(xc2028_attach,
Steven Toth363c35f2008-10-11 11:05:50 -0300751 fe0->dvb.frontend, &cfg);
Steven Toth66762372008-04-22 15:38:26 -0300752 if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
753 fe->ops.tuner_ops.set_config(fe, &ctl);
754 }
755 break;
Michael Krufky335377b2008-05-07 01:43:10 -0300756 case CX23885_BOARD_DVICO_FUSIONHDTV_7_DUAL_EXP:
757 i2c_bus = &dev->i2c_bus[port->nr - 1];
758
Steven Toth363c35f2008-10-11 11:05:50 -0300759 fe0->dvb.frontend = dvb_attach(s5h1409_attach,
Michael Krufky335377b2008-05-07 01:43:10 -0300760 &dvico_s5h1409_config,
761 &i2c_bus->i2c_adap);
Steven Toth363c35f2008-10-11 11:05:50 -0300762 if (fe0->dvb.frontend == NULL)
763 fe0->dvb.frontend = dvb_attach(s5h1411_attach,
Michael Krufky52b50452008-07-09 02:18:49 -0300764 &dvico_s5h1411_config,
765 &i2c_bus->i2c_adap);
Steven Toth363c35f2008-10-11 11:05:50 -0300766 if (fe0->dvb.frontend != NULL)
767 dvb_attach(xc5000_attach, fe0->dvb.frontend,
Michael Krufky30650962008-09-06 14:56:58 -0300768 &i2c_bus->i2c_adap,
769 &dvico_xc5000_tunerconfig);
Michael Krufky335377b2008-05-07 01:43:10 -0300770 break;
Steven Tothaef2d182008-08-04 21:39:53 -0300771 case CX23885_BOARD_DVICO_FUSIONHDTV_DVB_T_DUAL_EXP: {
772 i2c_bus = &dev->i2c_bus[port->nr - 1];
773
Steven Toth363c35f2008-10-11 11:05:50 -0300774 fe0->dvb.frontend = dvb_attach(zl10353_attach,
Steven Tothaef2d182008-08-04 21:39:53 -0300775 &dvico_fusionhdtv_xc3028,
776 &i2c_bus->i2c_adap);
Steven Toth363c35f2008-10-11 11:05:50 -0300777 if (fe0->dvb.frontend != NULL) {
Steven Tothaef2d182008-08-04 21:39:53 -0300778 struct dvb_frontend *fe;
779 struct xc2028_config cfg = {
780 .i2c_adap = &i2c_bus->i2c_adap,
781 .i2c_addr = 0x61,
Steven Tothaef2d182008-08-04 21:39:53 -0300782 };
783 static struct xc2028_ctrl ctl = {
Michael Krufkyef80bfeb2008-09-16 02:15:30 -0300784 .fname = XC2028_DEFAULT_FIRMWARE,
Steven Tothaef2d182008-08-04 21:39:53 -0300785 .max_len = 64,
786 .demod = XC3028_FE_ZARLINK456,
787 };
788
Steven Toth363c35f2008-10-11 11:05:50 -0300789 fe = dvb_attach(xc2028_attach, fe0->dvb.frontend,
Steven Tothaef2d182008-08-04 21:39:53 -0300790 &cfg);
791 if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
792 fe->ops.tuner_ops.set_config(fe, &ctl);
793 }
794 break;
795 }
Steven Toth4c56b042008-08-12 13:30:03 -0300796 case CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H:
Igor M. Liplianin9bb1b7e2008-11-23 14:11:16 -0300797 case CX23885_BOARD_COMPRO_VIDEOMATE_E650F:
Vladimir Geroy34e383d2009-09-18 18:55:47 -0300798 case CX23885_BOARD_COMPRO_VIDEOMATE_E800:
Steven Toth4c56b042008-08-12 13:30:03 -0300799 i2c_bus = &dev->i2c_bus[0];
800
Steven Toth363c35f2008-10-11 11:05:50 -0300801 fe0->dvb.frontend = dvb_attach(zl10353_attach,
Steven Toth4c56b042008-08-12 13:30:03 -0300802 &dvico_fusionhdtv_xc3028,
803 &i2c_bus->i2c_adap);
Steven Toth363c35f2008-10-11 11:05:50 -0300804 if (fe0->dvb.frontend != NULL) {
Steven Toth4c56b042008-08-12 13:30:03 -0300805 struct dvb_frontend *fe;
806 struct xc2028_config cfg = {
807 .i2c_adap = &dev->i2c_bus[1].i2c_adap,
808 .i2c_addr = 0x61,
Steven Toth4c56b042008-08-12 13:30:03 -0300809 };
810 static struct xc2028_ctrl ctl = {
Michael Krufkyef80bfeb2008-09-16 02:15:30 -0300811 .fname = XC2028_DEFAULT_FIRMWARE,
Steven Toth4c56b042008-08-12 13:30:03 -0300812 .max_len = 64,
813 .demod = XC3028_FE_ZARLINK456,
814 };
815
Steven Toth363c35f2008-10-11 11:05:50 -0300816 fe = dvb_attach(xc2028_attach, fe0->dvb.frontend,
Steven Toth4c56b042008-08-12 13:30:03 -0300817 &cfg);
818 if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
819 fe->ops.tuner_ops.set_config(fe, &ctl);
820 }
821 break;
Igor M. Liplianin96318d02009-01-17 12:11:20 -0300822 case CX23885_BOARD_TBS_6920:
Igor M. Liplianin09ea33e2009-11-24 20:16:04 -0300823 i2c_bus = &dev->i2c_bus[1];
Igor M. Liplianin96318d02009-01-17 12:11:20 -0300824
825 fe0->dvb.frontend = dvb_attach(cx24116_attach,
Igor M. Liplianin09ea33e2009-11-24 20:16:04 -0300826 &tbs_cx24116_config,
827 &i2c_bus->i2c_adap);
Igor M. Liplianin96318d02009-01-17 12:11:20 -0300828 if (fe0->dvb.frontend != NULL)
Igor M. Liplianin09ea33e2009-11-24 20:16:04 -0300829 fe0->dvb.frontend->ops.set_voltage = f300_set_voltage;
Igor M. Liplianin96318d02009-01-17 12:11:20 -0300830
831 break;
Igor M. Liplianin579943f2009-01-17 12:18:26 -0300832 case CX23885_BOARD_TEVII_S470:
833 i2c_bus = &dev->i2c_bus[1];
834
Igor M. Liplianin09ea33e2009-11-24 20:16:04 -0300835 fe0->dvb.frontend = dvb_attach(ds3000_attach,
836 &tevii_ds3000_config,
837 &i2c_bus->i2c_adap);
Igor M. Liplianin579943f2009-01-17 12:18:26 -0300838 if (fe0->dvb.frontend != NULL)
Igor M. Liplianin09ea33e2009-11-24 20:16:04 -0300839 fe0->dvb.frontend->ops.set_voltage = f300_set_voltage;
Igor M. Liplianin579943f2009-01-17 12:18:26 -0300840
841 break;
Igor M. Liplianinc9b8b042009-01-17 12:23:31 -0300842 case CX23885_BOARD_DVBWORLD_2005:
843 i2c_bus = &dev->i2c_bus[1];
844
845 fe0->dvb.frontend = dvb_attach(cx24116_attach,
846 &dvbworld_cx24116_config,
847 &i2c_bus->i2c_adap);
848 break;
Igor M. Liplianin5a23b072009-03-03 12:06:09 -0300849 case CX23885_BOARD_NETUP_DUAL_DVBS2_CI:
850 i2c_bus = &dev->i2c_bus[0];
851 switch (port->nr) {
852 /* port B */
853 case 1:
854 fe0->dvb.frontend = dvb_attach(stv0900_attach,
855 &netup_stv0900_config,
856 &i2c_bus->i2c_adap, 0);
857 if (fe0->dvb.frontend != NULL) {
858 if (dvb_attach(stv6110_attach,
859 fe0->dvb.frontend,
860 &netup_stv6110_tunerconfig_a,
861 &i2c_bus->i2c_adap)) {
862 if (!dvb_attach(lnbh24_attach,
863 fe0->dvb.frontend,
864 &i2c_bus->i2c_adap,
Abylay Ospan9329fb52009-10-17 08:38:45 -0300865 LNBH24_PCL | LNBH24_TTX,
866 LNBH24_TEN, 0x09))
Igor M. Liplianin5a23b072009-03-03 12:06:09 -0300867 printk(KERN_ERR
868 "No LNBH24 found!\n");
869
870 }
871 }
872 break;
873 /* port C */
874 case 2:
875 fe0->dvb.frontend = dvb_attach(stv0900_attach,
876 &netup_stv0900_config,
877 &i2c_bus->i2c_adap, 1);
878 if (fe0->dvb.frontend != NULL) {
879 if (dvb_attach(stv6110_attach,
880 fe0->dvb.frontend,
881 &netup_stv6110_tunerconfig_b,
882 &i2c_bus->i2c_adap)) {
883 if (!dvb_attach(lnbh24_attach,
884 fe0->dvb.frontend,
885 &i2c_bus->i2c_adap,
Abylay Ospan9329fb52009-10-17 08:38:45 -0300886 LNBH24_PCL | LNBH24_TTX,
887 LNBH24_TEN, 0x0a))
Igor M. Liplianin5a23b072009-03-03 12:06:09 -0300888 printk(KERN_ERR
889 "No LNBH24 found!\n");
890
891 }
892 }
893 break;
894 }
895 break;
David Wong493b7122009-05-18 05:25:49 -0300896 case CX23885_BOARD_MYGICA_X8506:
897 i2c_bus = &dev->i2c_bus[0];
898 i2c_bus2 = &dev->i2c_bus[1];
899 fe0->dvb.frontend = dvb_attach(lgs8gxx_attach,
900 &mygica_x8506_lgs8gl5_config,
901 &i2c_bus->i2c_adap);
902 if (fe0->dvb.frontend != NULL) {
903 dvb_attach(xc5000_attach,
904 fe0->dvb.frontend,
905 &i2c_bus2->i2c_adap,
906 &mygica_x8506_xc5000_config);
907 }
908 break;
David Wong2365b2d2009-06-17 01:38:12 -0300909 case CX23885_BOARD_MAGICPRO_PROHDTVE2:
910 i2c_bus = &dev->i2c_bus[0];
911 i2c_bus2 = &dev->i2c_bus[1];
912 fe0->dvb.frontend = dvb_attach(lgs8gxx_attach,
913 &magicpro_prohdtve2_lgs8g75_config,
914 &i2c_bus->i2c_adap);
915 if (fe0->dvb.frontend != NULL) {
916 dvb_attach(xc5000_attach,
917 fe0->dvb.frontend,
918 &i2c_bus2->i2c_adap,
919 &magicpro_prohdtve2_xc5000_config);
920 }
921 break;
Steven Toth136973802009-07-20 15:37:25 -0300922 case CX23885_BOARD_HAUPPAUGE_HVR1850:
Michael Krufkyaee0b242009-11-11 01:52:45 -0300923 case CX23885_BOARD_HAUPPAUGE_HVR1290:
Steven Toth136973802009-07-20 15:37:25 -0300924 i2c_bus = &dev->i2c_bus[0];
925 fe0->dvb.frontend = dvb_attach(s5h1411_attach,
926 &hcw_s5h1411_config,
927 &i2c_bus->i2c_adap);
928 if (fe0->dvb.frontend != NULL)
929 dvb_attach(tda18271_attach, fe0->dvb.frontend,
930 0x60, &dev->i2c_bus[0].i2c_adap,
931 &hauppauge_tda18271_config);
932 break;
David T. L. Wongea5697f2009-10-26 08:54:04 -0300933 case CX23885_BOARD_MYGICA_X8558PRO:
934 switch (port->nr) {
935 /* port B */
936 case 1:
937 i2c_bus = &dev->i2c_bus[0];
938 fe0->dvb.frontend = dvb_attach(atbm8830_attach,
939 &mygica_x8558pro_atbm8830_cfg1,
940 &i2c_bus->i2c_adap);
941 if (fe0->dvb.frontend != NULL) {
942 dvb_attach(max2165_attach,
943 fe0->dvb.frontend,
944 &i2c_bus->i2c_adap,
945 &mygic_x8558pro_max2165_cfg1);
946 }
947 break;
948 /* port C */
949 case 2:
950 i2c_bus = &dev->i2c_bus[1];
951 fe0->dvb.frontend = dvb_attach(atbm8830_attach,
952 &mygica_x8558pro_atbm8830_cfg2,
953 &i2c_bus->i2c_adap);
954 if (fe0->dvb.frontend != NULL) {
955 dvb_attach(max2165_attach,
956 fe0->dvb.frontend,
957 &i2c_bus->i2c_adap,
958 &mygic_x8558pro_max2165_cfg2);
959 }
960 break;
961 }
962 break;
Steven Toth136973802009-07-20 15:37:25 -0300963
Steven Tothd19770e2007-03-11 20:44:05 -0300964 default:
Steven Toth9c8ced52008-10-16 20:18:44 -0300965 printk(KERN_INFO "%s: The frontend of your DVB/ATSC card "
966 " isn't supported yet\n",
Steven Tothd19770e2007-03-11 20:44:05 -0300967 dev->name);
968 break;
969 }
Steven Toth363c35f2008-10-11 11:05:50 -0300970 if (NULL == fe0->dvb.frontend) {
Steven Toth9c8ced52008-10-16 20:18:44 -0300971 printk(KERN_ERR "%s: frontend initialization failed\n",
972 dev->name);
Steven Tothd19770e2007-03-11 20:44:05 -0300973 return -1;
974 }
Michael Krufkyd7cba042008-09-12 13:31:45 -0300975 /* define general-purpose callback pointer */
Steven Toth363c35f2008-10-11 11:05:50 -0300976 fe0->dvb.frontend->callback = cx23885_tuner_callback;
Steven Tothd19770e2007-03-11 20:44:05 -0300977
978 /* Put the analog decoder in standby to keep it quiet */
Laurent Pinchart622b8282009-10-05 10:48:17 -0300979 call_all(dev, core, s_power, 0);
Steven Tothd19770e2007-03-11 20:44:05 -0300980
Steven Toth363c35f2008-10-11 11:05:50 -0300981 if (fe0->dvb.frontend->ops.analog_ops.standby)
982 fe0->dvb.frontend->ops.analog_ops.standby(fe0->dvb.frontend);
Michael Krufky3ba71d22007-12-07 01:40:36 -0300983
Steven Tothd19770e2007-03-11 20:44:05 -0300984 /* register everything */
Igor M. Liplianin5a23b072009-03-03 12:06:09 -0300985 ret = videobuf_dvb_register_bus(&port->frontends, THIS_MODULE, port,
Michael Krufky5bdd3962009-05-08 22:39:24 -0300986 &dev->pci->dev, adapter_nr, 0,
987 cx23885_dvb_fe_ioctl_override);
Steven Toth363c35f2008-10-11 11:05:50 -0300988
Igor M. Liplianin5a23b072009-03-03 12:06:09 -0300989 /* init CI & MAC */
990 switch (dev->board) {
991 case CX23885_BOARD_NETUP_DUAL_DVBS2_CI: {
992 static struct netup_card_info cinfo;
993
994 netup_get_card_info(&dev->i2c_bus[0].i2c_adap, &cinfo);
995 memcpy(port->frontends.adapter.proposed_mac,
996 cinfo.port[port->nr - 1].mac, 6);
997 printk(KERN_INFO "NetUP Dual DVB-S2 CI card port%d MAC="
998 "%02X:%02X:%02X:%02X:%02X:%02X\n",
999 port->nr,
1000 port->frontends.adapter.proposed_mac[0],
1001 port->frontends.adapter.proposed_mac[1],
1002 port->frontends.adapter.proposed_mac[2],
1003 port->frontends.adapter.proposed_mac[3],
1004 port->frontends.adapter.proposed_mac[4],
1005 port->frontends.adapter.proposed_mac[5]);
1006
1007 netup_ci_init(port);
1008 break;
1009 }
1010 }
1011
1012 return ret;
Steven Tothd19770e2007-03-11 20:44:05 -03001013}
1014
1015int cx23885_dvb_register(struct cx23885_tsport *port)
1016{
Steven Toth363c35f2008-10-11 11:05:50 -03001017
1018 struct videobuf_dvb_frontend *fe0;
Steven Tothd19770e2007-03-11 20:44:05 -03001019 struct cx23885_dev *dev = port->dev;
Steven Totheb0c58b2008-10-11 12:34:39 -03001020 int err, i;
Steven Tothd19770e2007-03-11 20:44:05 -03001021
Steven Totheb0c58b2008-10-11 12:34:39 -03001022 /* Here we need to allocate the correct number of frontends,
1023 * as reflected in the cards struct. The reality is that currrently
1024 * no cx23885 boards support this - yet. But, if we don't modify this
1025 * code then the second frontend would never be allocated (later)
1026 * and fail with error before the attach in dvb_register().
1027 * Without these changes we risk an OOPS later. The changes here
1028 * are for safety, and should provide a good foundation for the
1029 * future addition of any multi-frontend cx23885 based boards.
1030 */
1031 printk(KERN_INFO "%s() allocating %d frontend(s)\n", __func__,
1032 port->num_frontends);
Steven Toth363c35f2008-10-11 11:05:50 -03001033
Steven Totheb0c58b2008-10-11 12:34:39 -03001034 for (i = 1; i <= port->num_frontends; i++) {
Darron Broad96b7a1a2008-10-15 20:26:34 -03001035 if (videobuf_dvb_alloc_frontend(
Steven Toth9c8ced52008-10-16 20:18:44 -03001036 &port->frontends, i) == NULL) {
Steven Totheb0c58b2008-10-11 12:34:39 -03001037 printk(KERN_ERR "%s() failed to alloc\n", __func__);
1038 return -ENOMEM;
1039 }
Steven Tothd19770e2007-03-11 20:44:05 -03001040
Steven Totheb0c58b2008-10-11 12:34:39 -03001041 fe0 = videobuf_dvb_get_frontend(&port->frontends, i);
1042 if (!fe0)
1043 err = -EINVAL;
Steven Tothd19770e2007-03-11 20:44:05 -03001044
Steven Totheb0c58b2008-10-11 12:34:39 -03001045 dprintk(1, "%s\n", __func__);
Steven Toth9c8ced52008-10-16 20:18:44 -03001046 dprintk(1, " ->probed by Card=%d Name=%s, PCI %02x:%02x\n",
Steven Totheb0c58b2008-10-11 12:34:39 -03001047 dev->board,
1048 dev->name,
1049 dev->pci_bus,
1050 dev->pci_slot);
1051
1052 err = -ENODEV;
1053
1054 /* dvb stuff */
1055 /* We have to init the queue for each frontend on a port. */
Steven Toth9c8ced52008-10-16 20:18:44 -03001056 printk(KERN_INFO "%s: cx23885 based dvb card\n", dev->name);
1057 videobuf_queue_sg_init(&fe0->dvb.dvbq, &dvb_qops,
1058 &dev->pci->dev, &port->slock,
Michael Krufky44a64812007-03-20 23:00:18 -03001059 V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_TOP,
1060 sizeof(struct cx23885_buffer), port);
Steven Totheb0c58b2008-10-11 12:34:39 -03001061 }
Steven Tothd19770e2007-03-11 20:44:05 -03001062 err = dvb_register(port);
1063 if (err != 0)
Steven Toth9c8ced52008-10-16 20:18:44 -03001064 printk(KERN_ERR "%s() dvb_register failed err = %d\n",
1065 __func__, err);
Steven Tothd19770e2007-03-11 20:44:05 -03001066
Steven Tothd19770e2007-03-11 20:44:05 -03001067 return err;
1068}
1069
1070int cx23885_dvb_unregister(struct cx23885_tsport *port)
1071{
Steven Toth363c35f2008-10-11 11:05:50 -03001072 struct videobuf_dvb_frontend *fe0;
1073
Steven Totheb0c58b2008-10-11 12:34:39 -03001074 /* FIXME: in an error condition where the we have
1075 * an expected number of frontends (attach problem)
1076 * then this might not clean up correctly, if 1
1077 * is invalid.
1078 * This comment only applies to future boards IF they
1079 * implement MFE support.
1080 */
Darron Broad92abe9e2008-10-11 11:18:53 -03001081 fe0 = videobuf_dvb_get_frontend(&port->frontends, 1);
Steven Toth9c8ced52008-10-16 20:18:44 -03001082 if (fe0->dvb.frontend)
Steven Toth363c35f2008-10-11 11:05:50 -03001083 videobuf_dvb_unregister_bus(&port->frontends);
Steven Tothd19770e2007-03-11 20:44:05 -03001084
Hans Verkuilafd96662009-03-13 13:24:19 -03001085 switch (port->dev->board) {
1086 case CX23885_BOARD_NETUP_DUAL_DVBS2_CI:
1087 netup_ci_exit(port);
1088 break;
1089 }
Igor M. Liplianin5a23b072009-03-03 12:06:09 -03001090
Steven Tothd19770e2007-03-11 20:44:05 -03001091 return 0;
1092}
Michael Krufky44a64812007-03-20 23:00:18 -03001093