blob: bf24e86293c69ba5d3293fcbe02dbf4392537834 [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"
Steven Tothd19770e2007-03-11 20:44:05 -030059
Steven Toth4513fc692008-01-12 11:36:36 -030060static unsigned int debug;
Steven Tothd19770e2007-03-11 20:44:05 -030061
Steven Toth4513fc692008-01-12 11:36:36 -030062#define dprintk(level, fmt, arg...)\
63 do { if (debug >= level)\
64 printk(KERN_DEBUG "%s/0: " fmt, dev->name, ## arg);\
65 } while (0)
Steven Tothd19770e2007-03-11 20:44:05 -030066
67/* ------------------------------------------------------------------ */
68
Michael Krufky3ba71d22007-12-07 01:40:36 -030069static unsigned int alt_tuner;
70module_param(alt_tuner, int, 0644);
71MODULE_PARM_DESC(alt_tuner, "Enable alternate tuner configuration");
72
Janne Grunau78e92002008-04-09 19:13:13 -030073DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
74
Michael Krufky3ba71d22007-12-07 01:40:36 -030075/* ------------------------------------------------------------------ */
76
Steven Tothd19770e2007-03-11 20:44:05 -030077static int dvb_buf_setup(struct videobuf_queue *q,
78 unsigned int *count, unsigned int *size)
79{
80 struct cx23885_tsport *port = q->priv_data;
81
82 port->ts_packet_size = 188 * 4;
83 port->ts_packet_count = 32;
84
85 *size = port->ts_packet_size * port->ts_packet_count;
86 *count = 32;
87 return 0;
88}
89
Michael Krufky44a64812007-03-20 23:00:18 -030090static int dvb_buf_prepare(struct videobuf_queue *q,
91 struct videobuf_buffer *vb, enum v4l2_field field)
Steven Tothd19770e2007-03-11 20:44:05 -030092{
93 struct cx23885_tsport *port = q->priv_data;
Steven Toth9c8ced52008-10-16 20:18:44 -030094 return cx23885_buf_prepare(q, port, (struct cx23885_buffer *)vb, field);
Steven Tothd19770e2007-03-11 20:44:05 -030095}
96
97static void dvb_buf_queue(struct videobuf_queue *q, struct videobuf_buffer *vb)
98{
99 struct cx23885_tsport *port = q->priv_data;
Steven Toth9c8ced52008-10-16 20:18:44 -0300100 cx23885_buf_queue(port, (struct cx23885_buffer *)vb);
Steven Tothd19770e2007-03-11 20:44:05 -0300101}
102
Michael Krufky44a64812007-03-20 23:00:18 -0300103static void dvb_buf_release(struct videobuf_queue *q,
104 struct videobuf_buffer *vb)
Steven Tothd19770e2007-03-11 20:44:05 -0300105{
Steven Toth9c8ced52008-10-16 20:18:44 -0300106 cx23885_free_buffer(q, (struct cx23885_buffer *)vb);
Steven Tothd19770e2007-03-11 20:44:05 -0300107}
108
109static struct videobuf_queue_ops dvb_qops = {
110 .buf_setup = dvb_buf_setup,
111 .buf_prepare = dvb_buf_prepare,
112 .buf_queue = dvb_buf_queue,
113 .buf_release = dvb_buf_release,
114};
115
Steven Toth86184e02007-09-04 21:40:47 -0300116static struct s5h1409_config hauppauge_generic_config = {
Steven Tothd19770e2007-03-11 20:44:05 -0300117 .demod_address = 0x32 >> 1,
118 .output_mode = S5H1409_SERIAL_OUTPUT,
Steven Tothfc959be2007-09-08 19:08:17 -0300119 .gpio = S5H1409_GPIO_ON,
Michael Krufky2b032382007-12-13 10:04:10 -0300120 .qam_if = 44000,
Steven Tothfc959be2007-09-08 19:08:17 -0300121 .inversion = S5H1409_INVERSION_OFF,
Steven Tothdfc1c082008-01-15 21:35:22 -0300122 .status_mode = S5H1409_DEMODLOCKING,
123 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
Steven Tothfc959be2007-09-08 19:08:17 -0300124};
125
Steven Tothb3ea0162008-04-19 01:14:19 -0300126static struct tda10048_config hauppauge_hvr1200_config = {
127 .demod_address = 0x10 >> 1,
128 .output_mode = TDA10048_SERIAL_OUTPUT,
129 .fwbulkwritelen = TDA10048_BULKWRITE_200,
Steven Toth484d9e02009-05-02 11:08:23 -0300130 .inversion = TDA10048_INVERSION_ON,
Steven Toth8816bef2009-05-15 21:04:18 -0300131 .dtv6_if_freq_khz = TDA10048_IF_3300,
132 .dtv7_if_freq_khz = TDA10048_IF_3800,
133 .dtv8_if_freq_khz = TDA10048_IF_4300,
Steven Toth484d9e02009-05-02 11:08:23 -0300134 .clk_freq_khz = TDA10048_CLK_16000,
Steven Tothb3ea0162008-04-19 01:14:19 -0300135};
136
Michael Krufky6b926ec2009-05-12 17:32:17 -0300137static struct tda10048_config hauppauge_hvr1210_config = {
138 .demod_address = 0x10 >> 1,
139 .output_mode = TDA10048_SERIAL_OUTPUT,
140 .fwbulkwritelen = TDA10048_BULKWRITE_200,
141 .inversion = TDA10048_INVERSION_ON,
Michael Krufkyc27586e2009-05-16 11:00:23 -0300142 .dtv6_if_freq_khz = TDA10048_IF_3300,
143 .dtv7_if_freq_khz = TDA10048_IF_3500,
144 .dtv8_if_freq_khz = TDA10048_IF_4000,
Michael Krufky6b926ec2009-05-12 17:32:17 -0300145 .clk_freq_khz = TDA10048_CLK_16000,
146};
147
Michael Krufky3ba71d22007-12-07 01:40:36 -0300148static struct s5h1409_config hauppauge_ezqam_config = {
149 .demod_address = 0x32 >> 1,
150 .output_mode = S5H1409_SERIAL_OUTPUT,
151 .gpio = S5H1409_GPIO_OFF,
152 .qam_if = 4000,
153 .inversion = S5H1409_INVERSION_ON,
Steven Tothdfc1c082008-01-15 21:35:22 -0300154 .status_mode = S5H1409_DEMODLOCKING,
155 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
Michael Krufky3ba71d22007-12-07 01:40:36 -0300156};
157
Steven Tothfc959be2007-09-08 19:08:17 -0300158static struct s5h1409_config hauppauge_hvr1800lp_config = {
159 .demod_address = 0x32 >> 1,
160 .output_mode = S5H1409_SERIAL_OUTPUT,
Steven Tothd19770e2007-03-11 20:44:05 -0300161 .gpio = S5H1409_GPIO_OFF,
Michael Krufky2b032382007-12-13 10:04:10 -0300162 .qam_if = 44000,
Steven Tothfe4751632007-03-20 15:27:53 -0300163 .inversion = S5H1409_INVERSION_OFF,
Steven Tothdfc1c082008-01-15 21:35:22 -0300164 .status_mode = S5H1409_DEMODLOCKING,
165 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
Steven Tothd19770e2007-03-11 20:44:05 -0300166};
167
Michael Krufky07b4a832007-12-18 01:09:11 -0300168static struct s5h1409_config hauppauge_hvr1500_config = {
169 .demod_address = 0x32 >> 1,
170 .output_mode = S5H1409_SERIAL_OUTPUT,
171 .gpio = S5H1409_GPIO_OFF,
172 .inversion = S5H1409_INVERSION_OFF,
Steven Tothdfc1c082008-01-15 21:35:22 -0300173 .status_mode = S5H1409_DEMODLOCKING,
174 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
Michael Krufky07b4a832007-12-18 01:09:11 -0300175};
176
Steven Toth86184e02007-09-04 21:40:47 -0300177static struct mt2131_config hauppauge_generic_tunerconfig = {
Steven Totha77743b2007-08-22 21:01:20 -0300178 0x61
179};
180
Michael Krufky9bc37ca2007-09-08 15:17:13 -0300181static struct lgdt330x_config fusionhdtv_5_express = {
182 .demod_address = 0x0e,
183 .demod_chip = LGDT3303,
184 .serial_mpeg = 0x40,
185};
186
Steven Tothd1987d52007-12-18 01:57:06 -0300187static struct s5h1409_config hauppauge_hvr1500q_config = {
188 .demod_address = 0x32 >> 1,
189 .output_mode = S5H1409_SERIAL_OUTPUT,
190 .gpio = S5H1409_GPIO_ON,
191 .qam_if = 44000,
192 .inversion = S5H1409_INVERSION_OFF,
Steven Tothdfc1c082008-01-15 21:35:22 -0300193 .status_mode = S5H1409_DEMODLOCKING,
194 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
Steven Tothd1987d52007-12-18 01:57:06 -0300195};
196
Michael Krufky335377b2008-05-07 01:43:10 -0300197static struct s5h1409_config dvico_s5h1409_config = {
198 .demod_address = 0x32 >> 1,
199 .output_mode = S5H1409_SERIAL_OUTPUT,
200 .gpio = S5H1409_GPIO_ON,
201 .qam_if = 44000,
202 .inversion = S5H1409_INVERSION_OFF,
203 .status_mode = S5H1409_DEMODLOCKING,
204 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
205};
206
Michael Krufky52b50452008-07-09 02:18:49 -0300207static struct s5h1411_config dvico_s5h1411_config = {
208 .output_mode = S5H1411_SERIAL_OUTPUT,
209 .gpio = S5H1411_GPIO_ON,
210 .qam_if = S5H1411_IF_44000,
211 .vsb_if = S5H1411_IF_44000,
212 .inversion = S5H1411_INVERSION_OFF,
213 .status_mode = S5H1411_DEMODLOCKING,
214 .mpeg_timing = S5H1411_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
215};
216
Michael Krufky19bc5792009-05-08 16:05:29 -0300217static struct s5h1411_config hcw_s5h1411_config = {
218 .output_mode = S5H1411_SERIAL_OUTPUT,
219 .gpio = S5H1411_GPIO_OFF,
220 .vsb_if = S5H1411_IF_44000,
221 .qam_if = S5H1411_IF_4000,
222 .inversion = S5H1411_INVERSION_ON,
223 .status_mode = S5H1411_DEMODLOCKING,
224 .mpeg_timing = S5H1411_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
225};
226
Steven Tothd1987d52007-12-18 01:57:06 -0300227static struct xc5000_config hauppauge_hvr1500q_tunerconfig = {
Steven Tothe12671cf2007-12-20 01:14:43 -0300228 .i2c_address = 0x61,
229 .if_khz = 5380,
Steven Tothd1987d52007-12-18 01:57:06 -0300230};
231
Michael Krufky335377b2008-05-07 01:43:10 -0300232static struct xc5000_config dvico_xc5000_tunerconfig = {
233 .i2c_address = 0x64,
234 .if_khz = 5380,
Michael Krufky335377b2008-05-07 01:43:10 -0300235};
236
Michael Krufky4041f1a2007-12-24 04:52:08 -0300237static struct tda829x_config tda829x_no_probe = {
238 .probe_tuner = TDA829X_DONT_PROBE,
239};
240
Michael Krufkyf21e0d72008-01-02 03:01:54 -0300241static struct tda18271_std_map hauppauge_tda18271_std_map = {
Michael Krufkyc0dc0c12008-04-22 14:46:22 -0300242 .atsc_6 = { .if_freq = 5380, .agc_mode = 3, .std = 3,
243 .if_lvl = 6, .rfagc_top = 0x37 },
244 .qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 0,
245 .if_lvl = 6, .rfagc_top = 0x37 },
Michael Krufkyf21e0d72008-01-02 03:01:54 -0300246};
247
Michael Krufkyb34cdc32009-05-21 12:49:28 -0300248static struct tda18271_std_map hauppauge_hvr1200_tda18271_std_map = {
249 .dvbt_6 = { .if_freq = 3300, .agc_mode = 3, .std = 4,
250 .if_lvl = 1, .rfagc_top = 0x37, },
251 .dvbt_7 = { .if_freq = 3800, .agc_mode = 3, .std = 5,
252 .if_lvl = 1, .rfagc_top = 0x37, },
253 .dvbt_8 = { .if_freq = 4300, .agc_mode = 3, .std = 6,
254 .if_lvl = 1, .rfagc_top = 0x37, },
255};
256
Michael Krufkyf21e0d72008-01-02 03:01:54 -0300257static struct tda18271_config hauppauge_tda18271_config = {
258 .std_map = &hauppauge_tda18271_std_map,
259 .gate = TDA18271_GATE_ANALOG,
Michael Krufky04a68ba2009-09-06 14:11:09 -0300260 .output_opt = TDA18271_OUTPUT_LT_OFF,
Michael Krufkyf21e0d72008-01-02 03:01:54 -0300261};
262
Steven Tothb3ea0162008-04-19 01:14:19 -0300263static struct tda18271_config hauppauge_hvr1200_tuner_config = {
Michael Krufkyb34cdc32009-05-21 12:49:28 -0300264 .std_map = &hauppauge_hvr1200_tda18271_std_map,
Steven Tothb3ea0162008-04-19 01:14:19 -0300265 .gate = TDA18271_GATE_ANALOG,
Michael Krufky04a68ba2009-09-06 14:11:09 -0300266 .output_opt = TDA18271_OUTPUT_LT_OFF,
Steven Tothb3ea0162008-04-19 01:14:19 -0300267};
268
Michael Krufky6b926ec2009-05-12 17:32:17 -0300269static struct tda18271_config hauppauge_hvr1210_tuner_config = {
270 .gate = TDA18271_GATE_DIGITAL,
Michael Krufky04a68ba2009-09-06 14:11:09 -0300271 .output_opt = TDA18271_OUTPUT_LT_OFF,
Michael Krufky6b926ec2009-05-12 17:32:17 -0300272};
273
Michael Krufky247bc542009-05-12 18:53:47 -0300274static struct tda18271_std_map hauppauge_hvr127x_std_map = {
Michael Krufkya5dbf452009-05-03 23:27:02 -0300275 .atsc_6 = { .if_freq = 3250, .agc_mode = 3, .std = 4,
276 .if_lvl = 1, .rfagc_top = 0x58 },
277 .qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 5,
278 .if_lvl = 1, .rfagc_top = 0x58 },
279};
280
Michael Krufky247bc542009-05-12 18:53:47 -0300281static struct tda18271_config hauppauge_hvr127x_config = {
282 .std_map = &hauppauge_hvr127x_std_map,
Michael Krufky04a68ba2009-09-06 14:11:09 -0300283 .output_opt = TDA18271_OUTPUT_LT_OFF,
Michael Krufkya5dbf452009-05-03 23:27:02 -0300284};
285
Michael Krufky247bc542009-05-12 18:53:47 -0300286static struct lgdt3305_config hauppauge_lgdt3305_config = {
Michael Krufkya5dbf452009-05-03 23:27:02 -0300287 .i2c_addr = 0x0e,
288 .mpeg_mode = LGDT3305_MPEG_SERIAL,
289 .tpclk_edge = LGDT3305_TPCLK_FALLING_EDGE,
290 .tpvalid_polarity = LGDT3305_TP_VALID_HIGH,
291 .deny_i2c_rptr = 1,
292 .spectral_inversion = 1,
293 .qam_if_khz = 4000,
294 .vsb_if_khz = 3250,
295};
296
Harvey Harrisonb1721d02008-04-25 19:03:08 -0700297static struct dibx000_agc_config xc3028_agc_config = {
Steven Toth66762372008-04-22 15:38:26 -0300298 BAND_VHF | BAND_UHF, /* band_caps */
299
300 /* P_agc_use_sd_mod1=0, P_agc_use_sd_mod2=0, P_agc_freq_pwm_div=0,
301 * P_agc_inv_pwm1=0, P_agc_inv_pwm2=0,
302 * P_agc_inh_dc_rv_est=0, P_agc_time_est=3, P_agc_freeze=0,
303 * P_agc_nb_est=2, P_agc_write=0
304 */
305 (0 << 15) | (0 << 14) | (0 << 11) | (0 << 10) | (0 << 9) | (0 << 8) |
306 (3 << 5) | (0 << 4) | (2 << 1) | (0 << 0), /* setup */
307
308 712, /* inv_gain */
309 21, /* time_stabiliz */
310
311 0, /* alpha_level */
312 118, /* thlock */
313
314 0, /* wbd_inv */
315 2867, /* wbd_ref */
316 0, /* wbd_sel */
317 2, /* wbd_alpha */
318
319 0, /* agc1_max */
320 0, /* agc1_min */
321 39718, /* agc2_max */
322 9930, /* agc2_min */
323 0, /* agc1_pt1 */
324 0, /* agc1_pt2 */
325 0, /* agc1_pt3 */
326 0, /* agc1_slope1 */
327 0, /* agc1_slope2 */
328 0, /* agc2_pt1 */
329 128, /* agc2_pt2 */
330 29, /* agc2_slope1 */
331 29, /* agc2_slope2 */
332
333 17, /* alpha_mant */
334 27, /* alpha_exp */
335 23, /* beta_mant */
336 51, /* beta_exp */
337
338 1, /* perform_agc_softsplit */
339};
340
341/* PLL Configuration for COFDM BW_MHz = 8.000000
342 * With external clock = 30.000000 */
Harvey Harrisonb1721d02008-04-25 19:03:08 -0700343static struct dibx000_bandwidth_config xc3028_bw_config = {
Steven Toth66762372008-04-22 15:38:26 -0300344 60000, /* internal */
345 30000, /* sampling */
346 1, /* pll_cfg: prediv */
347 8, /* pll_cfg: ratio */
348 3, /* pll_cfg: range */
349 1, /* pll_cfg: reset */
350 0, /* pll_cfg: bypass */
351 0, /* misc: refdiv */
352 0, /* misc: bypclk_div */
353 1, /* misc: IO_CLK_en_core */
354 1, /* misc: ADClkSrc */
355 0, /* misc: modulo */
356 (3 << 14) | (1 << 12) | (524 << 0), /* sad_cfg: refsel, sel, freq_15k */
357 (1 << 25) | 5816102, /* ifreq = 5.200000 MHz */
358 20452225, /* timf */
359 30000000 /* xtal_hz */
360};
361
362static struct dib7000p_config hauppauge_hvr1400_dib7000_config = {
363 .output_mpeg2_in_188_bytes = 1,
364 .hostbus_diversity = 1,
365 .tuner_is_baseband = 0,
366 .update_lna = NULL,
367
368 .agc_config_count = 1,
369 .agc = &xc3028_agc_config,
370 .bw = &xc3028_bw_config,
371
372 .gpio_dir = DIB7000P_GPIO_DEFAULT_DIRECTIONS,
373 .gpio_val = DIB7000P_GPIO_DEFAULT_VALUES,
374 .gpio_pwm_pos = DIB7000P_GPIO_DEFAULT_PWM_POS,
375
376 .pwm_freq_div = 0,
377 .agc_control = NULL,
378 .spur_protect = 0,
379
380 .output_mode = OUTMODE_MPEG2_SERIAL,
381};
382
Steven Tothaef2d182008-08-04 21:39:53 -0300383static struct zl10353_config dvico_fusionhdtv_xc3028 = {
384 .demod_address = 0x0f,
385 .if2 = 45600,
386 .no_tuner = 1,
Christopher Pascoed4dc6732009-04-27 11:27:04 -0300387 .disable_i2c_gate_ctrl = 1,
Steven Tothaef2d182008-08-04 21:39:53 -0300388};
389
Igor M. Liplianinf867c3f2009-06-19 05:45:23 -0300390static struct stv0900_reg stv0900_ts_regs[] = {
391 { R0900_TSGENERAL, 0x00 },
392 { R0900_P1_TSSPEED, 0x40 },
393 { R0900_P2_TSSPEED, 0x40 },
394 { R0900_P1_TSCFGM, 0xc0 },
395 { R0900_P2_TSCFGM, 0xc0 },
396 { R0900_P1_TSCFGH, 0xe0 },
397 { R0900_P2_TSCFGH, 0xe0 },
398 { R0900_P1_TSCFGL, 0x20 },
399 { R0900_P2_TSCFGL, 0x20 },
400 { 0xffff, 0xff }, /* terminate */
401};
402
Igor M. Liplianin5a23b072009-03-03 12:06:09 -0300403static struct stv0900_config netup_stv0900_config = {
404 .demod_address = 0x68,
Igor M. Liplianin29372a82009-10-17 08:58:26 -0300405 .demod_mode = 1, /* dual */
Abylay Ospan644c7ef02009-07-19 18:06:00 -0300406 .xtal = 8000000,
Igor M. Liplianin5a23b072009-03-03 12:06:09 -0300407 .clkmode = 3,/* 0-CLKI, 2-XTALI, else AUTO */
408 .diseqc_mode = 2,/* 2/3 PWM */
Igor M. Liplianinf867c3f2009-06-19 05:45:23 -0300409 .ts_config_regs = stv0900_ts_regs,
Igor M. Liplianin5a23b072009-03-03 12:06:09 -0300410 .tun1_maddress = 0,/* 0x60 */
411 .tun2_maddress = 3,/* 0x63 */
412 .tun1_adc = 1,/* 1 Vpp */
413 .tun2_adc = 1,/* 1 Vpp */
414};
415
416static struct stv6110_config netup_stv6110_tunerconfig_a = {
417 .i2c_address = 0x60,
Abylay Ospan644c7ef02009-07-19 18:06:00 -0300418 .mclk = 16000000,
419 .clk_div = 1,
Abylay Ospan873688c2009-10-17 08:23:00 -0300420 .gain = 8, /* +16 dB - maximum gain */
Igor M. Liplianin5a23b072009-03-03 12:06:09 -0300421};
422
423static struct stv6110_config netup_stv6110_tunerconfig_b = {
424 .i2c_address = 0x63,
Abylay Ospan644c7ef02009-07-19 18:06:00 -0300425 .mclk = 16000000,
426 .clk_div = 1,
Abylay Ospan873688c2009-10-17 08:23:00 -0300427 .gain = 8, /* +16 dB - maximum gain */
Igor M. Liplianin5a23b072009-03-03 12:06:09 -0300428};
429
Igor M. Liplianin96318d02009-01-17 12:11:20 -0300430static int tbs_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
431{
432 struct cx23885_tsport *port = fe->dvb->priv;
433 struct cx23885_dev *dev = port->dev;
434
435 if (voltage == SEC_VOLTAGE_18)
436 cx_write(MC417_RWD, 0x00001e00);/* GPIO-13 high */
437 else if (voltage == SEC_VOLTAGE_13)
438 cx_write(MC417_RWD, 0x00001a00);/* GPIO-13 low */
439 else
440 cx_write(MC417_RWD, 0x00001800);/* GPIO-12 low */
441 return 0;
442}
443
444static struct cx24116_config tbs_cx24116_config = {
445 .demod_address = 0x05,
446};
447
Igor M. Liplianin579943f2009-01-17 12:18:26 -0300448static struct cx24116_config tevii_cx24116_config = {
449 .demod_address = 0x55,
450};
451
Igor M. Liplianinc9b8b042009-01-17 12:23:31 -0300452static struct cx24116_config dvbworld_cx24116_config = {
453 .demod_address = 0x05,
454};
455
David Wong493b7122009-05-18 05:25:49 -0300456static struct lgs8gxx_config mygica_x8506_lgs8gl5_config = {
457 .prod = LGS8GXX_PROD_LGS8GL5,
458 .demod_address = 0x19,
459 .serial_ts = 0,
460 .ts_clk_pol = 1,
461 .ts_clk_gated = 1,
462 .if_clk_freq = 30400, /* 30.4 MHz */
463 .if_freq = 5380, /* 5.38 MHz */
464 .if_neg_center = 1,
465 .ext_adc = 0,
466 .adc_signed = 0,
467 .if_neg_edge = 0,
468};
469
470static struct xc5000_config mygica_x8506_xc5000_config = {
471 .i2c_address = 0x61,
472 .if_khz = 5380,
473};
474
Michael Krufkyf35b9e82009-05-08 22:39:24 -0300475static int cx23885_dvb_set_frontend(struct dvb_frontend *fe,
476 struct dvb_frontend_parameters *param)
477{
478 struct cx23885_tsport *port = fe->dvb->priv;
479 struct cx23885_dev *dev = port->dev;
480
481 switch (dev->board) {
482 case CX23885_BOARD_HAUPPAUGE_HVR1275:
483 switch (param->u.vsb.modulation) {
484 case VSB_8:
485 cx23885_gpio_clear(dev, GPIO_5);
486 break;
487 case QAM_64:
488 case QAM_256:
489 default:
490 cx23885_gpio_set(dev, GPIO_5);
491 break;
492 }
493 break;
David T.L. Wong6f0d8c02009-10-21 13:15:30 -0300494 case CX23885_BOARD_MYGICA_X8506:
495 case CX23885_BOARD_MAGICPRO_PROHDTVE2:
496 /* Select Digital TV */
497 cx23885_gpio_set(dev, GPIO_0);
498 break;
Michael Krufkyf35b9e82009-05-08 22:39:24 -0300499 }
Michael Krufky5bdd3962009-05-08 22:39:24 -0300500 return 0;
Michael Krufkyf35b9e82009-05-08 22:39:24 -0300501}
502
Michael Krufky5bdd3962009-05-08 22:39:24 -0300503static int cx23885_dvb_fe_ioctl_override(struct dvb_frontend *fe,
504 unsigned int cmd, void *parg,
505 unsigned int stage)
506{
507 int err = 0;
508
509 switch (stage) {
510 case DVB_FE_IOCTL_PRE:
511
512 switch (cmd) {
513 case FE_SET_FRONTEND:
514 err = cx23885_dvb_set_frontend(fe,
515 (struct dvb_frontend_parameters *) parg);
516 break;
517 }
518 break;
519
520 case DVB_FE_IOCTL_POST:
521 /* no post-ioctl handling required */
522 break;
523 }
524 return err;
525};
526
527
David Wong2365b2d2009-06-17 01:38:12 -0300528static struct lgs8gxx_config magicpro_prohdtve2_lgs8g75_config = {
529 .prod = LGS8GXX_PROD_LGS8G75,
530 .demod_address = 0x19,
531 .serial_ts = 0,
532 .ts_clk_pol = 1,
533 .ts_clk_gated = 1,
534 .if_clk_freq = 30400, /* 30.4 MHz */
535 .if_freq = 6500, /* 6.50 MHz */
536 .if_neg_center = 1,
537 .ext_adc = 0,
538 .adc_signed = 1,
539 .adc_vpp = 2, /* 1.6 Vpp */
540 .if_neg_edge = 1,
541};
542
543static struct xc5000_config magicpro_prohdtve2_xc5000_config = {
544 .i2c_address = 0x61,
545 .if_khz = 6500,
546};
547
David T. L. Wongea5697f2009-10-26 08:54:04 -0300548static struct atbm8830_config mygica_x8558pro_atbm8830_cfg1 = {
549 .prod = ATBM8830_PROD_8830,
550 .demod_address = 0x44,
551 .serial_ts = 0,
552 .ts_sampling_edge = 1,
553 .ts_clk_gated = 0,
554 .osc_clk_freq = 30400, /* in kHz */
555 .if_freq = 0, /* zero IF */
556 .zif_swap_iq = 1,
557};
558
559static struct max2165_config mygic_x8558pro_max2165_cfg1 = {
560 .i2c_address = 0x60,
561 .osc_clk = 20
562};
563
564static struct atbm8830_config mygica_x8558pro_atbm8830_cfg2 = {
565 .prod = ATBM8830_PROD_8830,
566 .demod_address = 0x44,
567 .serial_ts = 1,
568 .ts_sampling_edge = 1,
569 .ts_clk_gated = 0,
570 .osc_clk_freq = 30400, /* in kHz */
571 .if_freq = 0, /* zero IF */
572 .zif_swap_iq = 1,
573};
574
575static struct max2165_config mygic_x8558pro_max2165_cfg2 = {
576 .i2c_address = 0x60,
577 .osc_clk = 20
578};
579
Steven Tothd19770e2007-03-11 20:44:05 -0300580static int dvb_register(struct cx23885_tsport *port)
581{
582 struct cx23885_dev *dev = port->dev;
David Wong493b7122009-05-18 05:25:49 -0300583 struct cx23885_i2c *i2c_bus = NULL, *i2c_bus2 = NULL;
Steven Toth363c35f2008-10-11 11:05:50 -0300584 struct videobuf_dvb_frontend *fe0;
Igor M. Liplianin5a23b072009-03-03 12:06:09 -0300585 int ret;
Steven Toth363c35f2008-10-11 11:05:50 -0300586
Darron Broadf972e0bd2008-10-11 11:24:30 -0300587 /* Get the first frontend */
Darron Broad92abe9e2008-10-11 11:18:53 -0300588 fe0 = videobuf_dvb_get_frontend(&port->frontends, 1);
Steven Toth363c35f2008-10-11 11:05:50 -0300589 if (!fe0)
590 return -EINVAL;
Steven Tothd19770e2007-03-11 20:44:05 -0300591
592 /* init struct videobuf_dvb */
Steven Toth363c35f2008-10-11 11:05:50 -0300593 fe0->dvb.name = dev->name;
Steven Tothd19770e2007-03-11 20:44:05 -0300594
595 /* init frontend */
596 switch (dev->board) {
Steven Totha77743b2007-08-22 21:01:20 -0300597 case CX23885_BOARD_HAUPPAUGE_HVR1250:
Michael Krufkyf139fa72007-09-09 03:55:34 -0300598 i2c_bus = &dev->i2c_bus[0];
Steven Toth363c35f2008-10-11 11:05:50 -0300599 fe0->dvb.frontend = dvb_attach(s5h1409_attach,
Steven Toth86184e02007-09-04 21:40:47 -0300600 &hauppauge_generic_config,
Michael Krufkyf139fa72007-09-09 03:55:34 -0300601 &i2c_bus->i2c_adap);
Steven Toth363c35f2008-10-11 11:05:50 -0300602 if (fe0->dvb.frontend != NULL) {
603 dvb_attach(mt2131_attach, fe0->dvb.frontend,
Michael Krufkyf139fa72007-09-09 03:55:34 -0300604 &i2c_bus->i2c_adap,
Steven Toth86184e02007-09-04 21:40:47 -0300605 &hauppauge_generic_tunerconfig, 0);
Steven Tothd19770e2007-03-11 20:44:05 -0300606 }
607 break;
Michael Krufkya5dbf452009-05-03 23:27:02 -0300608 case CX23885_BOARD_HAUPPAUGE_HVR1270:
Michael Krufkyd099bec2009-05-08 22:39:24 -0300609 case CX23885_BOARD_HAUPPAUGE_HVR1275:
Michael Krufkya5dbf452009-05-03 23:27:02 -0300610 i2c_bus = &dev->i2c_bus[0];
611 fe0->dvb.frontend = dvb_attach(lgdt3305_attach,
Michael Krufky247bc542009-05-12 18:53:47 -0300612 &hauppauge_lgdt3305_config,
Michael Krufkya5dbf452009-05-03 23:27:02 -0300613 &i2c_bus->i2c_adap);
614 if (fe0->dvb.frontend != NULL) {
615 dvb_attach(tda18271_attach, fe0->dvb.frontend,
616 0x60, &dev->i2c_bus[1].i2c_adap,
Michael Krufky247bc542009-05-12 18:53:47 -0300617 &hauppauge_hvr127x_config);
Michael Krufkya5dbf452009-05-03 23:27:02 -0300618 }
619 break;
Michael Krufky19bc5792009-05-08 16:05:29 -0300620 case CX23885_BOARD_HAUPPAUGE_HVR1255:
621 i2c_bus = &dev->i2c_bus[0];
622 fe0->dvb.frontend = dvb_attach(s5h1411_attach,
623 &hcw_s5h1411_config,
624 &i2c_bus->i2c_adap);
625 if (fe0->dvb.frontend != NULL) {
626 dvb_attach(tda18271_attach, fe0->dvb.frontend,
627 0x60, &dev->i2c_bus[1].i2c_adap,
628 &hauppauge_tda18271_config);
629 }
630 break;
Michael Krufky3ba71d22007-12-07 01:40:36 -0300631 case CX23885_BOARD_HAUPPAUGE_HVR1800:
632 i2c_bus = &dev->i2c_bus[0];
Darron Broad92abe9e2008-10-11 11:18:53 -0300633 switch (alt_tuner) {
Michael Krufky3ba71d22007-12-07 01:40:36 -0300634 case 1:
Steven Toth363c35f2008-10-11 11:05:50 -0300635 fe0->dvb.frontend =
Michael Krufky3ba71d22007-12-07 01:40:36 -0300636 dvb_attach(s5h1409_attach,
637 &hauppauge_ezqam_config,
638 &i2c_bus->i2c_adap);
Steven Toth363c35f2008-10-11 11:05:50 -0300639 if (fe0->dvb.frontend != NULL) {
640 dvb_attach(tda829x_attach, fe0->dvb.frontend,
Michael Krufky3ba71d22007-12-07 01:40:36 -0300641 &dev->i2c_bus[1].i2c_adap, 0x42,
Michael Krufky4041f1a2007-12-24 04:52:08 -0300642 &tda829x_no_probe);
Steven Toth363c35f2008-10-11 11:05:50 -0300643 dvb_attach(tda18271_attach, fe0->dvb.frontend,
Michael Krufky4041f1a2007-12-24 04:52:08 -0300644 0x60, &dev->i2c_bus[1].i2c_adap,
Michael Krufkyf21e0d72008-01-02 03:01:54 -0300645 &hauppauge_tda18271_config);
Michael Krufky3ba71d22007-12-07 01:40:36 -0300646 }
647 break;
648 case 0:
649 default:
Steven Toth363c35f2008-10-11 11:05:50 -0300650 fe0->dvb.frontend =
Michael Krufky3ba71d22007-12-07 01:40:36 -0300651 dvb_attach(s5h1409_attach,
652 &hauppauge_generic_config,
653 &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 Krufky3ba71d22007-12-07 01:40:36 -0300656 &i2c_bus->i2c_adap,
657 &hauppauge_generic_tunerconfig, 0);
658 break;
659 }
660 break;
Steven Tothfc959be2007-09-08 19:08:17 -0300661 case CX23885_BOARD_HAUPPAUGE_HVR1800lp:
Michael Krufkyf139fa72007-09-09 03:55:34 -0300662 i2c_bus = &dev->i2c_bus[0];
Steven Toth363c35f2008-10-11 11:05:50 -0300663 fe0->dvb.frontend = dvb_attach(s5h1409_attach,
Steven Tothfc959be2007-09-08 19:08:17 -0300664 &hauppauge_hvr1800lp_config,
Michael Krufkyf139fa72007-09-09 03:55:34 -0300665 &i2c_bus->i2c_adap);
Steven Toth363c35f2008-10-11 11:05:50 -0300666 if (fe0->dvb.frontend != NULL) {
667 dvb_attach(mt2131_attach, fe0->dvb.frontend,
Michael Krufkyf139fa72007-09-09 03:55:34 -0300668 &i2c_bus->i2c_adap,
Steven Tothfc959be2007-09-08 19:08:17 -0300669 &hauppauge_generic_tunerconfig, 0);
670 }
671 break;
Michael Krufky9bc37ca2007-09-08 15:17:13 -0300672 case CX23885_BOARD_DVICO_FUSIONHDTV_5_EXP:
Michael Krufkyf139fa72007-09-09 03:55:34 -0300673 i2c_bus = &dev->i2c_bus[0];
Steven Toth363c35f2008-10-11 11:05:50 -0300674 fe0->dvb.frontend = dvb_attach(lgdt330x_attach,
Michael Krufky9bc37ca2007-09-08 15:17:13 -0300675 &fusionhdtv_5_express,
Michael Krufkyf139fa72007-09-09 03:55:34 -0300676 &i2c_bus->i2c_adap);
Steven Toth363c35f2008-10-11 11:05:50 -0300677 if (fe0->dvb.frontend != NULL) {
678 dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
Michael Krufky827855d2008-04-22 14:46:16 -0300679 &i2c_bus->i2c_adap, 0x61,
680 TUNER_LG_TDVS_H06XF);
Michael Krufky9bc37ca2007-09-08 15:17:13 -0300681 }
682 break;
Steven Tothd1987d52007-12-18 01:57:06 -0300683 case CX23885_BOARD_HAUPPAUGE_HVR1500Q:
684 i2c_bus = &dev->i2c_bus[1];
Steven Toth363c35f2008-10-11 11:05:50 -0300685 fe0->dvb.frontend = dvb_attach(s5h1409_attach,
Steven Tothd1987d52007-12-18 01:57:06 -0300686 &hauppauge_hvr1500q_config,
687 &dev->i2c_bus[0].i2c_adap);
Steven Toth363c35f2008-10-11 11:05:50 -0300688 if (fe0->dvb.frontend != NULL)
689 dvb_attach(xc5000_attach, fe0->dvb.frontend,
Michael Krufky30650962008-09-06 14:56:58 -0300690 &i2c_bus->i2c_adap,
691 &hauppauge_hvr1500q_tunerconfig);
Steven Tothd1987d52007-12-18 01:57:06 -0300692 break;
Michael Krufky07b4a832007-12-18 01:09:11 -0300693 case CX23885_BOARD_HAUPPAUGE_HVR1500:
694 i2c_bus = &dev->i2c_bus[1];
Steven Toth363c35f2008-10-11 11:05:50 -0300695 fe0->dvb.frontend = dvb_attach(s5h1409_attach,
Michael Krufky07b4a832007-12-18 01:09:11 -0300696 &hauppauge_hvr1500_config,
697 &dev->i2c_bus[0].i2c_adap);
Steven Toth363c35f2008-10-11 11:05:50 -0300698 if (fe0->dvb.frontend != NULL) {
Michael Krufky07b4a832007-12-18 01:09:11 -0300699 struct dvb_frontend *fe;
700 struct xc2028_config cfg = {
701 .i2c_adap = &i2c_bus->i2c_adap,
702 .i2c_addr = 0x61,
Michael Krufky07b4a832007-12-18 01:09:11 -0300703 };
704 static struct xc2028_ctrl ctl = {
Michael Krufkyef80bfeb2008-09-16 02:15:30 -0300705 .fname = XC2028_DEFAULT_FIRMWARE,
Michael Krufky07b4a832007-12-18 01:09:11 -0300706 .max_len = 64,
Steven Toth52c3d292009-04-20 22:42:00 -0300707 .demod = XC3028_FE_OREN538,
Michael Krufky07b4a832007-12-18 01:09:11 -0300708 };
709
710 fe = dvb_attach(xc2028_attach,
Steven Toth363c35f2008-10-11 11:05:50 -0300711 fe0->dvb.frontend, &cfg);
Michael Krufky07b4a832007-12-18 01:09:11 -0300712 if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
713 fe->ops.tuner_ops.set_config(fe, &ctl);
714 }
715 break;
Steven Tothb3ea0162008-04-19 01:14:19 -0300716 case CX23885_BOARD_HAUPPAUGE_HVR1200:
Steven Totha780a312008-04-19 01:25:52 -0300717 case CX23885_BOARD_HAUPPAUGE_HVR1700:
Steven Tothb3ea0162008-04-19 01:14:19 -0300718 i2c_bus = &dev->i2c_bus[0];
Steven Toth363c35f2008-10-11 11:05:50 -0300719 fe0->dvb.frontend = dvb_attach(tda10048_attach,
Steven Tothb3ea0162008-04-19 01:14:19 -0300720 &hauppauge_hvr1200_config,
721 &i2c_bus->i2c_adap);
Steven Toth363c35f2008-10-11 11:05:50 -0300722 if (fe0->dvb.frontend != NULL) {
723 dvb_attach(tda829x_attach, fe0->dvb.frontend,
Steven Tothb3ea0162008-04-19 01:14:19 -0300724 &dev->i2c_bus[1].i2c_adap, 0x42,
725 &tda829x_no_probe);
Steven Toth363c35f2008-10-11 11:05:50 -0300726 dvb_attach(tda18271_attach, fe0->dvb.frontend,
Steven Tothb3ea0162008-04-19 01:14:19 -0300727 0x60, &dev->i2c_bus[1].i2c_adap,
728 &hauppauge_hvr1200_tuner_config);
729 }
730 break;
Michael Krufky6b926ec2009-05-12 17:32:17 -0300731 case CX23885_BOARD_HAUPPAUGE_HVR1210:
732 i2c_bus = &dev->i2c_bus[0];
733 fe0->dvb.frontend = dvb_attach(tda10048_attach,
734 &hauppauge_hvr1210_config,
735 &i2c_bus->i2c_adap);
736 if (fe0->dvb.frontend != NULL) {
737 dvb_attach(tda18271_attach, fe0->dvb.frontend,
738 0x60, &dev->i2c_bus[1].i2c_adap,
739 &hauppauge_hvr1210_tuner_config);
740 }
741 break;
Steven Toth66762372008-04-22 15:38:26 -0300742 case CX23885_BOARD_HAUPPAUGE_HVR1400:
743 i2c_bus = &dev->i2c_bus[0];
Steven Toth363c35f2008-10-11 11:05:50 -0300744 fe0->dvb.frontend = dvb_attach(dib7000p_attach,
Steven Toth66762372008-04-22 15:38:26 -0300745 &i2c_bus->i2c_adap,
746 0x12, &hauppauge_hvr1400_dib7000_config);
Steven Toth363c35f2008-10-11 11:05:50 -0300747 if (fe0->dvb.frontend != NULL) {
Steven Toth66762372008-04-22 15:38:26 -0300748 struct dvb_frontend *fe;
749 struct xc2028_config cfg = {
750 .i2c_adap = &dev->i2c_bus[1].i2c_adap,
751 .i2c_addr = 0x64,
Steven Toth66762372008-04-22 15:38:26 -0300752 };
753 static struct xc2028_ctrl ctl = {
Michael Krufkyef80bfeb2008-09-16 02:15:30 -0300754 .fname = XC3028L_DEFAULT_FIRMWARE,
Steven Toth66762372008-04-22 15:38:26 -0300755 .max_len = 64,
756 .demod = 5000,
Steven Toth9c8ced52008-10-16 20:18:44 -0300757 /* This is true for all demods with
758 v36 firmware? */
Mauro Carvalho Chehab0975fc62008-09-28 02:24:44 -0300759 .type = XC2028_D2633,
Steven Toth66762372008-04-22 15:38:26 -0300760 };
761
762 fe = dvb_attach(xc2028_attach,
Steven Toth363c35f2008-10-11 11:05:50 -0300763 fe0->dvb.frontend, &cfg);
Steven Toth66762372008-04-22 15:38:26 -0300764 if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
765 fe->ops.tuner_ops.set_config(fe, &ctl);
766 }
767 break;
Michael Krufky335377b2008-05-07 01:43:10 -0300768 case CX23885_BOARD_DVICO_FUSIONHDTV_7_DUAL_EXP:
769 i2c_bus = &dev->i2c_bus[port->nr - 1];
770
Steven Toth363c35f2008-10-11 11:05:50 -0300771 fe0->dvb.frontend = dvb_attach(s5h1409_attach,
Michael Krufky335377b2008-05-07 01:43:10 -0300772 &dvico_s5h1409_config,
773 &i2c_bus->i2c_adap);
Steven Toth363c35f2008-10-11 11:05:50 -0300774 if (fe0->dvb.frontend == NULL)
775 fe0->dvb.frontend = dvb_attach(s5h1411_attach,
Michael Krufky52b50452008-07-09 02:18:49 -0300776 &dvico_s5h1411_config,
777 &i2c_bus->i2c_adap);
Steven Toth363c35f2008-10-11 11:05:50 -0300778 if (fe0->dvb.frontend != NULL)
779 dvb_attach(xc5000_attach, fe0->dvb.frontend,
Michael Krufky30650962008-09-06 14:56:58 -0300780 &i2c_bus->i2c_adap,
781 &dvico_xc5000_tunerconfig);
Michael Krufky335377b2008-05-07 01:43:10 -0300782 break;
Steven Tothaef2d182008-08-04 21:39:53 -0300783 case CX23885_BOARD_DVICO_FUSIONHDTV_DVB_T_DUAL_EXP: {
784 i2c_bus = &dev->i2c_bus[port->nr - 1];
785
Steven Toth363c35f2008-10-11 11:05:50 -0300786 fe0->dvb.frontend = dvb_attach(zl10353_attach,
Steven Tothaef2d182008-08-04 21:39:53 -0300787 &dvico_fusionhdtv_xc3028,
788 &i2c_bus->i2c_adap);
Steven Toth363c35f2008-10-11 11:05:50 -0300789 if (fe0->dvb.frontend != NULL) {
Steven Tothaef2d182008-08-04 21:39:53 -0300790 struct dvb_frontend *fe;
791 struct xc2028_config cfg = {
792 .i2c_adap = &i2c_bus->i2c_adap,
793 .i2c_addr = 0x61,
Steven Tothaef2d182008-08-04 21:39:53 -0300794 };
795 static struct xc2028_ctrl ctl = {
Michael Krufkyef80bfeb2008-09-16 02:15:30 -0300796 .fname = XC2028_DEFAULT_FIRMWARE,
Steven Tothaef2d182008-08-04 21:39:53 -0300797 .max_len = 64,
798 .demod = XC3028_FE_ZARLINK456,
799 };
800
Steven Toth363c35f2008-10-11 11:05:50 -0300801 fe = dvb_attach(xc2028_attach, fe0->dvb.frontend,
Steven Tothaef2d182008-08-04 21:39:53 -0300802 &cfg);
803 if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
804 fe->ops.tuner_ops.set_config(fe, &ctl);
805 }
806 break;
807 }
Steven Toth4c56b042008-08-12 13:30:03 -0300808 case CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H:
Igor M. Liplianin9bb1b7e2008-11-23 14:11:16 -0300809 case CX23885_BOARD_COMPRO_VIDEOMATE_E650F:
Vladimir Geroy34e383d2009-09-18 18:55:47 -0300810 case CX23885_BOARD_COMPRO_VIDEOMATE_E800:
Steven Toth4c56b042008-08-12 13:30:03 -0300811 i2c_bus = &dev->i2c_bus[0];
812
Steven Toth363c35f2008-10-11 11:05:50 -0300813 fe0->dvb.frontend = dvb_attach(zl10353_attach,
Steven Toth4c56b042008-08-12 13:30:03 -0300814 &dvico_fusionhdtv_xc3028,
815 &i2c_bus->i2c_adap);
Steven Toth363c35f2008-10-11 11:05:50 -0300816 if (fe0->dvb.frontend != NULL) {
Steven Toth4c56b042008-08-12 13:30:03 -0300817 struct dvb_frontend *fe;
818 struct xc2028_config cfg = {
819 .i2c_adap = &dev->i2c_bus[1].i2c_adap,
820 .i2c_addr = 0x61,
Steven Toth4c56b042008-08-12 13:30:03 -0300821 };
822 static struct xc2028_ctrl ctl = {
Michael Krufkyef80bfeb2008-09-16 02:15:30 -0300823 .fname = XC2028_DEFAULT_FIRMWARE,
Steven Toth4c56b042008-08-12 13:30:03 -0300824 .max_len = 64,
825 .demod = XC3028_FE_ZARLINK456,
826 };
827
Steven Toth363c35f2008-10-11 11:05:50 -0300828 fe = dvb_attach(xc2028_attach, fe0->dvb.frontend,
Steven Toth4c56b042008-08-12 13:30:03 -0300829 &cfg);
830 if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
831 fe->ops.tuner_ops.set_config(fe, &ctl);
832 }
833 break;
Igor M. Liplianin96318d02009-01-17 12:11:20 -0300834 case CX23885_BOARD_TBS_6920:
835 i2c_bus = &dev->i2c_bus[0];
836
837 fe0->dvb.frontend = dvb_attach(cx24116_attach,
838 &tbs_cx24116_config,
839 &i2c_bus->i2c_adap);
840 if (fe0->dvb.frontend != NULL)
841 fe0->dvb.frontend->ops.set_voltage = tbs_set_voltage;
842
843 break;
Igor M. Liplianin579943f2009-01-17 12:18:26 -0300844 case CX23885_BOARD_TEVII_S470:
845 i2c_bus = &dev->i2c_bus[1];
846
847 fe0->dvb.frontend = dvb_attach(cx24116_attach,
848 &tevii_cx24116_config,
849 &i2c_bus->i2c_adap);
850 if (fe0->dvb.frontend != NULL)
851 fe0->dvb.frontend->ops.set_voltage = tbs_set_voltage;
852
853 break;
Igor M. Liplianinc9b8b042009-01-17 12:23:31 -0300854 case CX23885_BOARD_DVBWORLD_2005:
855 i2c_bus = &dev->i2c_bus[1];
856
857 fe0->dvb.frontend = dvb_attach(cx24116_attach,
858 &dvbworld_cx24116_config,
859 &i2c_bus->i2c_adap);
860 break;
Igor M. Liplianin5a23b072009-03-03 12:06:09 -0300861 case CX23885_BOARD_NETUP_DUAL_DVBS2_CI:
862 i2c_bus = &dev->i2c_bus[0];
863 switch (port->nr) {
864 /* port B */
865 case 1:
866 fe0->dvb.frontend = dvb_attach(stv0900_attach,
867 &netup_stv0900_config,
868 &i2c_bus->i2c_adap, 0);
869 if (fe0->dvb.frontend != NULL) {
870 if (dvb_attach(stv6110_attach,
871 fe0->dvb.frontend,
872 &netup_stv6110_tunerconfig_a,
873 &i2c_bus->i2c_adap)) {
874 if (!dvb_attach(lnbh24_attach,
875 fe0->dvb.frontend,
876 &i2c_bus->i2c_adap,
Abylay Ospan9329fb52009-10-17 08:38:45 -0300877 LNBH24_PCL | LNBH24_TTX,
878 LNBH24_TEN, 0x09))
Igor M. Liplianin5a23b072009-03-03 12:06:09 -0300879 printk(KERN_ERR
880 "No LNBH24 found!\n");
881
882 }
883 }
884 break;
885 /* port C */
886 case 2:
887 fe0->dvb.frontend = dvb_attach(stv0900_attach,
888 &netup_stv0900_config,
889 &i2c_bus->i2c_adap, 1);
890 if (fe0->dvb.frontend != NULL) {
891 if (dvb_attach(stv6110_attach,
892 fe0->dvb.frontend,
893 &netup_stv6110_tunerconfig_b,
894 &i2c_bus->i2c_adap)) {
895 if (!dvb_attach(lnbh24_attach,
896 fe0->dvb.frontend,
897 &i2c_bus->i2c_adap,
Abylay Ospan9329fb52009-10-17 08:38:45 -0300898 LNBH24_PCL | LNBH24_TTX,
899 LNBH24_TEN, 0x0a))
Igor M. Liplianin5a23b072009-03-03 12:06:09 -0300900 printk(KERN_ERR
901 "No LNBH24 found!\n");
902
903 }
904 }
905 break;
906 }
907 break;
David Wong493b7122009-05-18 05:25:49 -0300908 case CX23885_BOARD_MYGICA_X8506:
909 i2c_bus = &dev->i2c_bus[0];
910 i2c_bus2 = &dev->i2c_bus[1];
911 fe0->dvb.frontend = dvb_attach(lgs8gxx_attach,
912 &mygica_x8506_lgs8gl5_config,
913 &i2c_bus->i2c_adap);
914 if (fe0->dvb.frontend != NULL) {
915 dvb_attach(xc5000_attach,
916 fe0->dvb.frontend,
917 &i2c_bus2->i2c_adap,
918 &mygica_x8506_xc5000_config);
919 }
920 break;
David Wong2365b2d2009-06-17 01:38:12 -0300921 case CX23885_BOARD_MAGICPRO_PROHDTVE2:
922 i2c_bus = &dev->i2c_bus[0];
923 i2c_bus2 = &dev->i2c_bus[1];
924 fe0->dvb.frontend = dvb_attach(lgs8gxx_attach,
925 &magicpro_prohdtve2_lgs8g75_config,
926 &i2c_bus->i2c_adap);
927 if (fe0->dvb.frontend != NULL) {
928 dvb_attach(xc5000_attach,
929 fe0->dvb.frontend,
930 &i2c_bus2->i2c_adap,
931 &magicpro_prohdtve2_xc5000_config);
932 }
933 break;
Steven Toth136973802009-07-20 15:37:25 -0300934 case CX23885_BOARD_HAUPPAUGE_HVR1850:
Michael Krufkyaee0b242009-11-11 01:52:45 -0300935 case CX23885_BOARD_HAUPPAUGE_HVR1290:
Steven Toth136973802009-07-20 15:37:25 -0300936 i2c_bus = &dev->i2c_bus[0];
937 fe0->dvb.frontend = dvb_attach(s5h1411_attach,
938 &hcw_s5h1411_config,
939 &i2c_bus->i2c_adap);
940 if (fe0->dvb.frontend != NULL)
941 dvb_attach(tda18271_attach, fe0->dvb.frontend,
942 0x60, &dev->i2c_bus[0].i2c_adap,
943 &hauppauge_tda18271_config);
944 break;
David T. L. Wongea5697f2009-10-26 08:54:04 -0300945 case CX23885_BOARD_MYGICA_X8558PRO:
946 switch (port->nr) {
947 /* port B */
948 case 1:
949 i2c_bus = &dev->i2c_bus[0];
950 fe0->dvb.frontend = dvb_attach(atbm8830_attach,
951 &mygica_x8558pro_atbm8830_cfg1,
952 &i2c_bus->i2c_adap);
953 if (fe0->dvb.frontend != NULL) {
954 dvb_attach(max2165_attach,
955 fe0->dvb.frontend,
956 &i2c_bus->i2c_adap,
957 &mygic_x8558pro_max2165_cfg1);
958 }
959 break;
960 /* port C */
961 case 2:
962 i2c_bus = &dev->i2c_bus[1];
963 fe0->dvb.frontend = dvb_attach(atbm8830_attach,
964 &mygica_x8558pro_atbm8830_cfg2,
965 &i2c_bus->i2c_adap);
966 if (fe0->dvb.frontend != NULL) {
967 dvb_attach(max2165_attach,
968 fe0->dvb.frontend,
969 &i2c_bus->i2c_adap,
970 &mygic_x8558pro_max2165_cfg2);
971 }
972 break;
973 }
974 break;
Steven Toth136973802009-07-20 15:37:25 -0300975
Steven Tothd19770e2007-03-11 20:44:05 -0300976 default:
Steven Toth9c8ced52008-10-16 20:18:44 -0300977 printk(KERN_INFO "%s: The frontend of your DVB/ATSC card "
978 " isn't supported yet\n",
Steven Tothd19770e2007-03-11 20:44:05 -0300979 dev->name);
980 break;
981 }
Steven Toth363c35f2008-10-11 11:05:50 -0300982 if (NULL == fe0->dvb.frontend) {
Steven Toth9c8ced52008-10-16 20:18:44 -0300983 printk(KERN_ERR "%s: frontend initialization failed\n",
984 dev->name);
Steven Tothd19770e2007-03-11 20:44:05 -0300985 return -1;
986 }
Michael Krufkyd7cba042008-09-12 13:31:45 -0300987 /* define general-purpose callback pointer */
Steven Toth363c35f2008-10-11 11:05:50 -0300988 fe0->dvb.frontend->callback = cx23885_tuner_callback;
Steven Tothd19770e2007-03-11 20:44:05 -0300989
990 /* Put the analog decoder in standby to keep it quiet */
Laurent Pinchart622b8282009-10-05 10:48:17 -0300991 call_all(dev, core, s_power, 0);
Steven Tothd19770e2007-03-11 20:44:05 -0300992
Steven Toth363c35f2008-10-11 11:05:50 -0300993 if (fe0->dvb.frontend->ops.analog_ops.standby)
994 fe0->dvb.frontend->ops.analog_ops.standby(fe0->dvb.frontend);
Michael Krufky3ba71d22007-12-07 01:40:36 -0300995
Steven Tothd19770e2007-03-11 20:44:05 -0300996 /* register everything */
Igor M. Liplianin5a23b072009-03-03 12:06:09 -0300997 ret = videobuf_dvb_register_bus(&port->frontends, THIS_MODULE, port,
Michael Krufky5bdd3962009-05-08 22:39:24 -0300998 &dev->pci->dev, adapter_nr, 0,
999 cx23885_dvb_fe_ioctl_override);
Steven Toth363c35f2008-10-11 11:05:50 -03001000
Igor M. Liplianin5a23b072009-03-03 12:06:09 -03001001 /* init CI & MAC */
1002 switch (dev->board) {
1003 case CX23885_BOARD_NETUP_DUAL_DVBS2_CI: {
1004 static struct netup_card_info cinfo;
1005
1006 netup_get_card_info(&dev->i2c_bus[0].i2c_adap, &cinfo);
1007 memcpy(port->frontends.adapter.proposed_mac,
1008 cinfo.port[port->nr - 1].mac, 6);
1009 printk(KERN_INFO "NetUP Dual DVB-S2 CI card port%d MAC="
1010 "%02X:%02X:%02X:%02X:%02X:%02X\n",
1011 port->nr,
1012 port->frontends.adapter.proposed_mac[0],
1013 port->frontends.adapter.proposed_mac[1],
1014 port->frontends.adapter.proposed_mac[2],
1015 port->frontends.adapter.proposed_mac[3],
1016 port->frontends.adapter.proposed_mac[4],
1017 port->frontends.adapter.proposed_mac[5]);
1018
1019 netup_ci_init(port);
1020 break;
1021 }
1022 }
1023
1024 return ret;
Steven Tothd19770e2007-03-11 20:44:05 -03001025}
1026
1027int cx23885_dvb_register(struct cx23885_tsport *port)
1028{
Steven Toth363c35f2008-10-11 11:05:50 -03001029
1030 struct videobuf_dvb_frontend *fe0;
Steven Tothd19770e2007-03-11 20:44:05 -03001031 struct cx23885_dev *dev = port->dev;
Steven Totheb0c58b2008-10-11 12:34:39 -03001032 int err, i;
Steven Tothd19770e2007-03-11 20:44:05 -03001033
Steven Totheb0c58b2008-10-11 12:34:39 -03001034 /* Here we need to allocate the correct number of frontends,
1035 * as reflected in the cards struct. The reality is that currrently
1036 * no cx23885 boards support this - yet. But, if we don't modify this
1037 * code then the second frontend would never be allocated (later)
1038 * and fail with error before the attach in dvb_register().
1039 * Without these changes we risk an OOPS later. The changes here
1040 * are for safety, and should provide a good foundation for the
1041 * future addition of any multi-frontend cx23885 based boards.
1042 */
1043 printk(KERN_INFO "%s() allocating %d frontend(s)\n", __func__,
1044 port->num_frontends);
Steven Toth363c35f2008-10-11 11:05:50 -03001045
Steven Totheb0c58b2008-10-11 12:34:39 -03001046 for (i = 1; i <= port->num_frontends; i++) {
Darron Broad96b7a1a2008-10-15 20:26:34 -03001047 if (videobuf_dvb_alloc_frontend(
Steven Toth9c8ced52008-10-16 20:18:44 -03001048 &port->frontends, i) == NULL) {
Steven Totheb0c58b2008-10-11 12:34:39 -03001049 printk(KERN_ERR "%s() failed to alloc\n", __func__);
1050 return -ENOMEM;
1051 }
Steven Tothd19770e2007-03-11 20:44:05 -03001052
Steven Totheb0c58b2008-10-11 12:34:39 -03001053 fe0 = videobuf_dvb_get_frontend(&port->frontends, i);
1054 if (!fe0)
1055 err = -EINVAL;
Steven Tothd19770e2007-03-11 20:44:05 -03001056
Steven Totheb0c58b2008-10-11 12:34:39 -03001057 dprintk(1, "%s\n", __func__);
Steven Toth9c8ced52008-10-16 20:18:44 -03001058 dprintk(1, " ->probed by Card=%d Name=%s, PCI %02x:%02x\n",
Steven Totheb0c58b2008-10-11 12:34:39 -03001059 dev->board,
1060 dev->name,
1061 dev->pci_bus,
1062 dev->pci_slot);
1063
1064 err = -ENODEV;
1065
1066 /* dvb stuff */
1067 /* We have to init the queue for each frontend on a port. */
Steven Toth9c8ced52008-10-16 20:18:44 -03001068 printk(KERN_INFO "%s: cx23885 based dvb card\n", dev->name);
1069 videobuf_queue_sg_init(&fe0->dvb.dvbq, &dvb_qops,
1070 &dev->pci->dev, &port->slock,
Michael Krufky44a64812007-03-20 23:00:18 -03001071 V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_TOP,
1072 sizeof(struct cx23885_buffer), port);
Steven Totheb0c58b2008-10-11 12:34:39 -03001073 }
Steven Tothd19770e2007-03-11 20:44:05 -03001074 err = dvb_register(port);
1075 if (err != 0)
Steven Toth9c8ced52008-10-16 20:18:44 -03001076 printk(KERN_ERR "%s() dvb_register failed err = %d\n",
1077 __func__, err);
Steven Tothd19770e2007-03-11 20:44:05 -03001078
Steven Tothd19770e2007-03-11 20:44:05 -03001079 return err;
1080}
1081
1082int cx23885_dvb_unregister(struct cx23885_tsport *port)
1083{
Steven Toth363c35f2008-10-11 11:05:50 -03001084 struct videobuf_dvb_frontend *fe0;
1085
Steven Totheb0c58b2008-10-11 12:34:39 -03001086 /* FIXME: in an error condition where the we have
1087 * an expected number of frontends (attach problem)
1088 * then this might not clean up correctly, if 1
1089 * is invalid.
1090 * This comment only applies to future boards IF they
1091 * implement MFE support.
1092 */
Darron Broad92abe9e2008-10-11 11:18:53 -03001093 fe0 = videobuf_dvb_get_frontend(&port->frontends, 1);
Steven Toth9c8ced52008-10-16 20:18:44 -03001094 if (fe0->dvb.frontend)
Steven Toth363c35f2008-10-11 11:05:50 -03001095 videobuf_dvb_unregister_bus(&port->frontends);
Steven Tothd19770e2007-03-11 20:44:05 -03001096
Hans Verkuilafd96662009-03-13 13:24:19 -03001097 switch (port->dev->board) {
1098 case CX23885_BOARD_NETUP_DUAL_DVBS2_CI:
1099 netup_ci_exit(port);
1100 break;
1101 }
Igor M. Liplianin5a23b072009-03-03 12:06:09 -03001102
Steven Tothd19770e2007-03-11 20:44:05 -03001103 return 0;
1104}
Michael Krufky44a64812007-03-20 23:00:18 -03001105