blob: a3906225c49397f0d59b086c2a91124d8932c804 [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"
istvan_v@mailbox.hu0cf8af52011-07-11 10:58:35 -030040#include "xc4000.h"
Steven Tothd1987d52007-12-18 01:57:06 -030041#include "xc5000.h"
David T. L. Wongea5697f2009-10-26 08:54:04 -030042#include "max2165.h"
Steven Tothb3ea0162008-04-19 01:14:19 -030043#include "tda10048.h"
Michael Krufky07b4a832007-12-18 01:09:11 -030044#include "tuner-xc2028.h"
Michael Krufky827855d2008-04-22 14:46:16 -030045#include "tuner-simple.h"
Steven Toth66762372008-04-22 15:38:26 -030046#include "dib7000p.h"
47#include "dibx000_common.h"
Steven Tothaef2d182008-08-04 21:39:53 -030048#include "zl10353.h"
Igor M. Liplianin5a23b072009-03-03 12:06:09 -030049#include "stv0900.h"
Igor M. Liplianinf867c3f2009-06-19 05:45:23 -030050#include "stv0900_reg.h"
Igor M. Liplianin5a23b072009-03-03 12:06:09 -030051#include "stv6110.h"
52#include "lnbh24.h"
Igor M. Liplianin96318d02009-01-17 12:11:20 -030053#include "cx24116.h"
Igor M. Liplianin5a23b072009-03-03 12:06:09 -030054#include "cimax2.h"
David Wong493b7122009-05-18 05:25:49 -030055#include "lgs8gxx.h"
Igor M. Liplianin5a23b072009-03-03 12:06:09 -030056#include "netup-eeprom.h"
57#include "netup-init.h"
Michael Krufkya5dbf452009-05-03 23:27:02 -030058#include "lgdt3305.h"
David T. L. Wongea5697f2009-10-26 08:54:04 -030059#include "atbm8830.h"
Igor M. Liplianin09ea33e2009-11-24 20:16:04 -030060#include "ds3000.h"
61#include "cx23885-f300.h"
Igor M. Liplianin78db8542011-01-25 17:04:00 -030062#include "altera-ci.h"
63#include "stv0367.h"
Steven Tothd19770e2007-03-11 20:44:05 -030064
Steven Toth4513fc692008-01-12 11:36:36 -030065static unsigned int debug;
Steven Tothd19770e2007-03-11 20:44:05 -030066
Steven Toth4513fc692008-01-12 11:36:36 -030067#define dprintk(level, fmt, arg...)\
68 do { if (debug >= level)\
69 printk(KERN_DEBUG "%s/0: " fmt, dev->name, ## arg);\
70 } while (0)
Steven Tothd19770e2007-03-11 20:44:05 -030071
72/* ------------------------------------------------------------------ */
73
Michael Krufky3ba71d22007-12-07 01:40:36 -030074static unsigned int alt_tuner;
75module_param(alt_tuner, int, 0644);
76MODULE_PARM_DESC(alt_tuner, "Enable alternate tuner configuration");
77
Janne Grunau78e92002008-04-09 19:13:13 -030078DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
79
Michael Krufky3ba71d22007-12-07 01:40:36 -030080/* ------------------------------------------------------------------ */
81
Steven Tothd19770e2007-03-11 20:44:05 -030082static int dvb_buf_setup(struct videobuf_queue *q,
83 unsigned int *count, unsigned int *size)
84{
85 struct cx23885_tsport *port = q->priv_data;
86
87 port->ts_packet_size = 188 * 4;
88 port->ts_packet_count = 32;
89
90 *size = port->ts_packet_size * port->ts_packet_count;
91 *count = 32;
92 return 0;
93}
94
Michael Krufky44a64812007-03-20 23:00:18 -030095static int dvb_buf_prepare(struct videobuf_queue *q,
96 struct videobuf_buffer *vb, enum v4l2_field field)
Steven Tothd19770e2007-03-11 20:44:05 -030097{
98 struct cx23885_tsport *port = q->priv_data;
Steven Toth9c8ced52008-10-16 20:18:44 -030099 return cx23885_buf_prepare(q, port, (struct cx23885_buffer *)vb, field);
Steven Tothd19770e2007-03-11 20:44:05 -0300100}
101
102static void dvb_buf_queue(struct videobuf_queue *q, struct videobuf_buffer *vb)
103{
104 struct cx23885_tsport *port = q->priv_data;
Steven Toth9c8ced52008-10-16 20:18:44 -0300105 cx23885_buf_queue(port, (struct cx23885_buffer *)vb);
Steven Tothd19770e2007-03-11 20:44:05 -0300106}
107
Michael Krufky44a64812007-03-20 23:00:18 -0300108static void dvb_buf_release(struct videobuf_queue *q,
109 struct videobuf_buffer *vb)
Steven Tothd19770e2007-03-11 20:44:05 -0300110{
Steven Toth9c8ced52008-10-16 20:18:44 -0300111 cx23885_free_buffer(q, (struct cx23885_buffer *)vb);
Steven Tothd19770e2007-03-11 20:44:05 -0300112}
113
Mauro Carvalho Chehaba7d44ba2011-12-26 20:48:54 -0300114static int cx23885_dvb_set_frontend(struct dvb_frontend *fe);
115
Igor M. Liplianin78db8542011-01-25 17:04:00 -0300116static void cx23885_dvb_gate_ctrl(struct cx23885_tsport *port, int open)
117{
118 struct videobuf_dvb_frontends *f;
119 struct videobuf_dvb_frontend *fe;
120
121 f = &port->frontends;
122
123 if (f->gate <= 1) /* undefined or fe0 */
124 fe = videobuf_dvb_get_frontend(f, 1);
125 else
126 fe = videobuf_dvb_get_frontend(f, f->gate);
127
128 if (fe && fe->dvb.frontend && fe->dvb.frontend->ops.i2c_gate_ctrl)
129 fe->dvb.frontend->ops.i2c_gate_ctrl(fe->dvb.frontend, open);
Mauro Carvalho Chehaba7d44ba2011-12-26 20:48:54 -0300130
131 /*
132 * FIXME: Improve this path to avoid calling the
133 * cx23885_dvb_set_frontend() every time it passes here.
134 */
135 cx23885_dvb_set_frontend(fe->dvb.frontend);
Igor M. Liplianin78db8542011-01-25 17:04:00 -0300136}
137
Steven Tothd19770e2007-03-11 20:44:05 -0300138static struct videobuf_queue_ops dvb_qops = {
139 .buf_setup = dvb_buf_setup,
140 .buf_prepare = dvb_buf_prepare,
141 .buf_queue = dvb_buf_queue,
142 .buf_release = dvb_buf_release,
143};
144
Steven Toth86184e02007-09-04 21:40:47 -0300145static struct s5h1409_config hauppauge_generic_config = {
Steven Tothd19770e2007-03-11 20:44:05 -0300146 .demod_address = 0x32 >> 1,
147 .output_mode = S5H1409_SERIAL_OUTPUT,
Steven Tothfc959be2007-09-08 19:08:17 -0300148 .gpio = S5H1409_GPIO_ON,
Michael Krufky2b032382007-12-13 10:04:10 -0300149 .qam_if = 44000,
Steven Tothfc959be2007-09-08 19:08:17 -0300150 .inversion = S5H1409_INVERSION_OFF,
Steven Tothdfc1c082008-01-15 21:35:22 -0300151 .status_mode = S5H1409_DEMODLOCKING,
152 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
Steven Tothfc959be2007-09-08 19:08:17 -0300153};
154
Steven Tothb3ea0162008-04-19 01:14:19 -0300155static struct tda10048_config hauppauge_hvr1200_config = {
156 .demod_address = 0x10 >> 1,
157 .output_mode = TDA10048_SERIAL_OUTPUT,
158 .fwbulkwritelen = TDA10048_BULKWRITE_200,
Steven Toth484d9e02009-05-02 11:08:23 -0300159 .inversion = TDA10048_INVERSION_ON,
Steven Toth8816bef2009-05-15 21:04:18 -0300160 .dtv6_if_freq_khz = TDA10048_IF_3300,
161 .dtv7_if_freq_khz = TDA10048_IF_3800,
162 .dtv8_if_freq_khz = TDA10048_IF_4300,
Steven Toth484d9e02009-05-02 11:08:23 -0300163 .clk_freq_khz = TDA10048_CLK_16000,
Steven Tothb3ea0162008-04-19 01:14:19 -0300164};
165
Michael Krufky6b926ec2009-05-12 17:32:17 -0300166static struct tda10048_config hauppauge_hvr1210_config = {
167 .demod_address = 0x10 >> 1,
168 .output_mode = TDA10048_SERIAL_OUTPUT,
169 .fwbulkwritelen = TDA10048_BULKWRITE_200,
170 .inversion = TDA10048_INVERSION_ON,
Michael Krufkyc27586e2009-05-16 11:00:23 -0300171 .dtv6_if_freq_khz = TDA10048_IF_3300,
172 .dtv7_if_freq_khz = TDA10048_IF_3500,
173 .dtv8_if_freq_khz = TDA10048_IF_4000,
Michael Krufky6b926ec2009-05-12 17:32:17 -0300174 .clk_freq_khz = TDA10048_CLK_16000,
175};
176
Michael Krufky3ba71d22007-12-07 01:40:36 -0300177static struct s5h1409_config hauppauge_ezqam_config = {
178 .demod_address = 0x32 >> 1,
179 .output_mode = S5H1409_SERIAL_OUTPUT,
180 .gpio = S5H1409_GPIO_OFF,
181 .qam_if = 4000,
182 .inversion = S5H1409_INVERSION_ON,
Steven Tothdfc1c082008-01-15 21:35:22 -0300183 .status_mode = S5H1409_DEMODLOCKING,
184 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
Michael Krufky3ba71d22007-12-07 01:40:36 -0300185};
186
Steven Tothfc959be2007-09-08 19:08:17 -0300187static struct s5h1409_config hauppauge_hvr1800lp_config = {
188 .demod_address = 0x32 >> 1,
189 .output_mode = S5H1409_SERIAL_OUTPUT,
Steven Tothd19770e2007-03-11 20:44:05 -0300190 .gpio = S5H1409_GPIO_OFF,
Michael Krufky2b032382007-12-13 10:04:10 -0300191 .qam_if = 44000,
Steven Tothfe4751632007-03-20 15:27:53 -0300192 .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 Tothd19770e2007-03-11 20:44:05 -0300195};
196
Michael Krufky07b4a832007-12-18 01:09:11 -0300197static struct s5h1409_config hauppauge_hvr1500_config = {
198 .demod_address = 0x32 >> 1,
199 .output_mode = S5H1409_SERIAL_OUTPUT,
200 .gpio = S5H1409_GPIO_OFF,
201 .inversion = S5H1409_INVERSION_OFF,
Steven Tothdfc1c082008-01-15 21:35:22 -0300202 .status_mode = S5H1409_DEMODLOCKING,
203 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
Michael Krufky07b4a832007-12-18 01:09:11 -0300204};
205
Steven Toth86184e02007-09-04 21:40:47 -0300206static struct mt2131_config hauppauge_generic_tunerconfig = {
Steven Totha77743b2007-08-22 21:01:20 -0300207 0x61
208};
209
Michael Krufky9bc37ca2007-09-08 15:17:13 -0300210static struct lgdt330x_config fusionhdtv_5_express = {
211 .demod_address = 0x0e,
212 .demod_chip = LGDT3303,
213 .serial_mpeg = 0x40,
214};
215
Steven Tothd1987d52007-12-18 01:57:06 -0300216static struct s5h1409_config hauppauge_hvr1500q_config = {
217 .demod_address = 0x32 >> 1,
218 .output_mode = S5H1409_SERIAL_OUTPUT,
219 .gpio = S5H1409_GPIO_ON,
220 .qam_if = 44000,
221 .inversion = S5H1409_INVERSION_OFF,
Steven Tothdfc1c082008-01-15 21:35:22 -0300222 .status_mode = S5H1409_DEMODLOCKING,
223 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
Steven Tothd1987d52007-12-18 01:57:06 -0300224};
225
Michael Krufky335377b2008-05-07 01:43:10 -0300226static struct s5h1409_config dvico_s5h1409_config = {
227 .demod_address = 0x32 >> 1,
228 .output_mode = S5H1409_SERIAL_OUTPUT,
229 .gpio = S5H1409_GPIO_ON,
230 .qam_if = 44000,
231 .inversion = S5H1409_INVERSION_OFF,
232 .status_mode = S5H1409_DEMODLOCKING,
233 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
234};
235
Michael Krufky52b50452008-07-09 02:18:49 -0300236static struct s5h1411_config dvico_s5h1411_config = {
237 .output_mode = S5H1411_SERIAL_OUTPUT,
238 .gpio = S5H1411_GPIO_ON,
239 .qam_if = S5H1411_IF_44000,
240 .vsb_if = S5H1411_IF_44000,
241 .inversion = S5H1411_INVERSION_OFF,
242 .status_mode = S5H1411_DEMODLOCKING,
243 .mpeg_timing = S5H1411_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
244};
245
Michael Krufky19bc5792009-05-08 16:05:29 -0300246static struct s5h1411_config hcw_s5h1411_config = {
247 .output_mode = S5H1411_SERIAL_OUTPUT,
248 .gpio = S5H1411_GPIO_OFF,
249 .vsb_if = S5H1411_IF_44000,
250 .qam_if = S5H1411_IF_4000,
251 .inversion = S5H1411_INVERSION_ON,
252 .status_mode = S5H1411_DEMODLOCKING,
253 .mpeg_timing = S5H1411_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
254};
255
Steven Tothd1987d52007-12-18 01:57:06 -0300256static struct xc5000_config hauppauge_hvr1500q_tunerconfig = {
Steven Tothe12671cf2007-12-20 01:14:43 -0300257 .i2c_address = 0x61,
258 .if_khz = 5380,
Steven Tothd1987d52007-12-18 01:57:06 -0300259};
260
Michael Krufky335377b2008-05-07 01:43:10 -0300261static struct xc5000_config dvico_xc5000_tunerconfig = {
262 .i2c_address = 0x64,
263 .if_khz = 5380,
Michael Krufky335377b2008-05-07 01:43:10 -0300264};
265
Michael Krufky4041f1a2007-12-24 04:52:08 -0300266static struct tda829x_config tda829x_no_probe = {
267 .probe_tuner = TDA829X_DONT_PROBE,
268};
269
Michael Krufkyf21e0d72008-01-02 03:01:54 -0300270static struct tda18271_std_map hauppauge_tda18271_std_map = {
Michael Krufkyc0dc0c12008-04-22 14:46:22 -0300271 .atsc_6 = { .if_freq = 5380, .agc_mode = 3, .std = 3,
272 .if_lvl = 6, .rfagc_top = 0x37 },
273 .qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 0,
274 .if_lvl = 6, .rfagc_top = 0x37 },
Michael Krufkyf21e0d72008-01-02 03:01:54 -0300275};
276
Michael Krufkyb34cdc32009-05-21 12:49:28 -0300277static struct tda18271_std_map hauppauge_hvr1200_tda18271_std_map = {
278 .dvbt_6 = { .if_freq = 3300, .agc_mode = 3, .std = 4,
279 .if_lvl = 1, .rfagc_top = 0x37, },
280 .dvbt_7 = { .if_freq = 3800, .agc_mode = 3, .std = 5,
281 .if_lvl = 1, .rfagc_top = 0x37, },
282 .dvbt_8 = { .if_freq = 4300, .agc_mode = 3, .std = 6,
283 .if_lvl = 1, .rfagc_top = 0x37, },
284};
285
Michael Krufkyf21e0d72008-01-02 03:01:54 -0300286static struct tda18271_config hauppauge_tda18271_config = {
287 .std_map = &hauppauge_tda18271_std_map,
288 .gate = TDA18271_GATE_ANALOG,
Michael Krufky04a68ba2009-09-06 14:11:09 -0300289 .output_opt = TDA18271_OUTPUT_LT_OFF,
Michael Krufkyf21e0d72008-01-02 03:01:54 -0300290};
291
Steven Tothb3ea0162008-04-19 01:14:19 -0300292static struct tda18271_config hauppauge_hvr1200_tuner_config = {
Michael Krufkyb34cdc32009-05-21 12:49:28 -0300293 .std_map = &hauppauge_hvr1200_tda18271_std_map,
Steven Tothb3ea0162008-04-19 01:14:19 -0300294 .gate = TDA18271_GATE_ANALOG,
Michael Krufky04a68ba2009-09-06 14:11:09 -0300295 .output_opt = TDA18271_OUTPUT_LT_OFF,
Steven Tothb3ea0162008-04-19 01:14:19 -0300296};
297
Michael Krufky6b926ec2009-05-12 17:32:17 -0300298static struct tda18271_config hauppauge_hvr1210_tuner_config = {
299 .gate = TDA18271_GATE_DIGITAL,
Michael Krufky04a68ba2009-09-06 14:11:09 -0300300 .output_opt = TDA18271_OUTPUT_LT_OFF,
Michael Krufky6b926ec2009-05-12 17:32:17 -0300301};
302
Michael Krufky247bc542009-05-12 18:53:47 -0300303static struct tda18271_std_map hauppauge_hvr127x_std_map = {
Michael Krufkya5dbf452009-05-03 23:27:02 -0300304 .atsc_6 = { .if_freq = 3250, .agc_mode = 3, .std = 4,
305 .if_lvl = 1, .rfagc_top = 0x58 },
306 .qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 5,
307 .if_lvl = 1, .rfagc_top = 0x58 },
308};
309
Michael Krufky247bc542009-05-12 18:53:47 -0300310static struct tda18271_config hauppauge_hvr127x_config = {
311 .std_map = &hauppauge_hvr127x_std_map,
Michael Krufky04a68ba2009-09-06 14:11:09 -0300312 .output_opt = TDA18271_OUTPUT_LT_OFF,
Michael Krufkya5dbf452009-05-03 23:27:02 -0300313};
314
Michael Krufky247bc542009-05-12 18:53:47 -0300315static struct lgdt3305_config hauppauge_lgdt3305_config = {
Michael Krufkya5dbf452009-05-03 23:27:02 -0300316 .i2c_addr = 0x0e,
317 .mpeg_mode = LGDT3305_MPEG_SERIAL,
318 .tpclk_edge = LGDT3305_TPCLK_FALLING_EDGE,
319 .tpvalid_polarity = LGDT3305_TP_VALID_HIGH,
320 .deny_i2c_rptr = 1,
321 .spectral_inversion = 1,
322 .qam_if_khz = 4000,
323 .vsb_if_khz = 3250,
324};
325
Harvey Harrisonb1721d02008-04-25 19:03:08 -0700326static struct dibx000_agc_config xc3028_agc_config = {
Steven Toth66762372008-04-22 15:38:26 -0300327 BAND_VHF | BAND_UHF, /* band_caps */
328
329 /* P_agc_use_sd_mod1=0, P_agc_use_sd_mod2=0, P_agc_freq_pwm_div=0,
330 * P_agc_inv_pwm1=0, P_agc_inv_pwm2=0,
331 * P_agc_inh_dc_rv_est=0, P_agc_time_est=3, P_agc_freeze=0,
332 * P_agc_nb_est=2, P_agc_write=0
333 */
334 (0 << 15) | (0 << 14) | (0 << 11) | (0 << 10) | (0 << 9) | (0 << 8) |
335 (3 << 5) | (0 << 4) | (2 << 1) | (0 << 0), /* setup */
336
337 712, /* inv_gain */
338 21, /* time_stabiliz */
339
340 0, /* alpha_level */
341 118, /* thlock */
342
343 0, /* wbd_inv */
344 2867, /* wbd_ref */
345 0, /* wbd_sel */
346 2, /* wbd_alpha */
347
348 0, /* agc1_max */
349 0, /* agc1_min */
350 39718, /* agc2_max */
351 9930, /* agc2_min */
352 0, /* agc1_pt1 */
353 0, /* agc1_pt2 */
354 0, /* agc1_pt3 */
355 0, /* agc1_slope1 */
356 0, /* agc1_slope2 */
357 0, /* agc2_pt1 */
358 128, /* agc2_pt2 */
359 29, /* agc2_slope1 */
360 29, /* agc2_slope2 */
361
362 17, /* alpha_mant */
363 27, /* alpha_exp */
364 23, /* beta_mant */
365 51, /* beta_exp */
366
367 1, /* perform_agc_softsplit */
368};
369
370/* PLL Configuration for COFDM BW_MHz = 8.000000
371 * With external clock = 30.000000 */
Harvey Harrisonb1721d02008-04-25 19:03:08 -0700372static struct dibx000_bandwidth_config xc3028_bw_config = {
Steven Toth66762372008-04-22 15:38:26 -0300373 60000, /* internal */
374 30000, /* sampling */
375 1, /* pll_cfg: prediv */
376 8, /* pll_cfg: ratio */
377 3, /* pll_cfg: range */
378 1, /* pll_cfg: reset */
379 0, /* pll_cfg: bypass */
380 0, /* misc: refdiv */
381 0, /* misc: bypclk_div */
382 1, /* misc: IO_CLK_en_core */
383 1, /* misc: ADClkSrc */
384 0, /* misc: modulo */
385 (3 << 14) | (1 << 12) | (524 << 0), /* sad_cfg: refsel, sel, freq_15k */
386 (1 << 25) | 5816102, /* ifreq = 5.200000 MHz */
387 20452225, /* timf */
388 30000000 /* xtal_hz */
389};
390
391static struct dib7000p_config hauppauge_hvr1400_dib7000_config = {
392 .output_mpeg2_in_188_bytes = 1,
393 .hostbus_diversity = 1,
394 .tuner_is_baseband = 0,
395 .update_lna = NULL,
396
397 .agc_config_count = 1,
398 .agc = &xc3028_agc_config,
399 .bw = &xc3028_bw_config,
400
401 .gpio_dir = DIB7000P_GPIO_DEFAULT_DIRECTIONS,
402 .gpio_val = DIB7000P_GPIO_DEFAULT_VALUES,
403 .gpio_pwm_pos = DIB7000P_GPIO_DEFAULT_PWM_POS,
404
405 .pwm_freq_div = 0,
406 .agc_control = NULL,
407 .spur_protect = 0,
408
409 .output_mode = OUTMODE_MPEG2_SERIAL,
410};
411
Steven Tothaef2d182008-08-04 21:39:53 -0300412static struct zl10353_config dvico_fusionhdtv_xc3028 = {
413 .demod_address = 0x0f,
414 .if2 = 45600,
415 .no_tuner = 1,
Christopher Pascoed4dc6732009-04-27 11:27:04 -0300416 .disable_i2c_gate_ctrl = 1,
Steven Tothaef2d182008-08-04 21:39:53 -0300417};
418
Igor M. Liplianinf867c3f2009-06-19 05:45:23 -0300419static struct stv0900_reg stv0900_ts_regs[] = {
420 { R0900_TSGENERAL, 0x00 },
421 { R0900_P1_TSSPEED, 0x40 },
422 { R0900_P2_TSSPEED, 0x40 },
423 { R0900_P1_TSCFGM, 0xc0 },
424 { R0900_P2_TSCFGM, 0xc0 },
425 { R0900_P1_TSCFGH, 0xe0 },
426 { R0900_P2_TSCFGH, 0xe0 },
427 { R0900_P1_TSCFGL, 0x20 },
428 { R0900_P2_TSCFGL, 0x20 },
429 { 0xffff, 0xff }, /* terminate */
430};
431
Igor M. Liplianin5a23b072009-03-03 12:06:09 -0300432static struct stv0900_config netup_stv0900_config = {
433 .demod_address = 0x68,
Igor M. Liplianin29372a82009-10-17 08:58:26 -0300434 .demod_mode = 1, /* dual */
Abylay Ospan644c7ef02009-07-19 18:06:00 -0300435 .xtal = 8000000,
Igor M. Liplianin5a23b072009-03-03 12:06:09 -0300436 .clkmode = 3,/* 0-CLKI, 2-XTALI, else AUTO */
437 .diseqc_mode = 2,/* 2/3 PWM */
Igor M. Liplianinf867c3f2009-06-19 05:45:23 -0300438 .ts_config_regs = stv0900_ts_regs,
Igor M. Liplianin5a23b072009-03-03 12:06:09 -0300439 .tun1_maddress = 0,/* 0x60 */
440 .tun2_maddress = 3,/* 0x63 */
441 .tun1_adc = 1,/* 1 Vpp */
442 .tun2_adc = 1,/* 1 Vpp */
443};
444
445static struct stv6110_config netup_stv6110_tunerconfig_a = {
446 .i2c_address = 0x60,
Abylay Ospan644c7ef02009-07-19 18:06:00 -0300447 .mclk = 16000000,
448 .clk_div = 1,
Abylay Ospan873688c2009-10-17 08:23:00 -0300449 .gain = 8, /* +16 dB - maximum gain */
Igor M. Liplianin5a23b072009-03-03 12:06:09 -0300450};
451
452static struct stv6110_config netup_stv6110_tunerconfig_b = {
453 .i2c_address = 0x63,
Abylay Ospan644c7ef02009-07-19 18:06:00 -0300454 .mclk = 16000000,
455 .clk_div = 1,
Abylay Ospan873688c2009-10-17 08:23:00 -0300456 .gain = 8, /* +16 dB - maximum gain */
Igor M. Liplianin5a23b072009-03-03 12:06:09 -0300457};
458
Igor M. Liplianin96318d02009-01-17 12:11:20 -0300459static struct cx24116_config tbs_cx24116_config = {
Igor M. Liplianin09ea33e2009-11-24 20:16:04 -0300460 .demod_address = 0x55,
Igor M. Liplianin96318d02009-01-17 12:11:20 -0300461};
462
Igor M. Liplianin09ea33e2009-11-24 20:16:04 -0300463static struct ds3000_config tevii_ds3000_config = {
464 .demod_address = 0x68,
Igor M. Liplianin579943f2009-01-17 12:18:26 -0300465};
466
Igor M. Liplianinc9b8b042009-01-17 12:23:31 -0300467static struct cx24116_config dvbworld_cx24116_config = {
468 .demod_address = 0x05,
469};
470
David Wong493b7122009-05-18 05:25:49 -0300471static struct lgs8gxx_config mygica_x8506_lgs8gl5_config = {
472 .prod = LGS8GXX_PROD_LGS8GL5,
473 .demod_address = 0x19,
474 .serial_ts = 0,
475 .ts_clk_pol = 1,
476 .ts_clk_gated = 1,
477 .if_clk_freq = 30400, /* 30.4 MHz */
478 .if_freq = 5380, /* 5.38 MHz */
479 .if_neg_center = 1,
480 .ext_adc = 0,
481 .adc_signed = 0,
482 .if_neg_edge = 0,
483};
484
485static struct xc5000_config mygica_x8506_xc5000_config = {
486 .i2c_address = 0x61,
487 .if_khz = 5380,
488};
489
Mauro Carvalho Chehaba7d44ba2011-12-26 20:48:54 -0300490static int cx23885_dvb_set_frontend(struct dvb_frontend *fe)
Michael Krufkyf35b9e82009-05-08 22:39:24 -0300491{
Mauro Carvalho Chehaba7d44ba2011-12-26 20:48:54 -0300492 struct dtv_frontend_properties *p = &fe->dtv_property_cache;
Michael Krufkyf35b9e82009-05-08 22:39:24 -0300493 struct cx23885_tsport *port = fe->dvb->priv;
494 struct cx23885_dev *dev = port->dev;
495
496 switch (dev->board) {
497 case CX23885_BOARD_HAUPPAUGE_HVR1275:
Mauro Carvalho Chehaba7d44ba2011-12-26 20:48:54 -0300498 switch (p->modulation) {
Michael Krufkyf35b9e82009-05-08 22:39:24 -0300499 case VSB_8:
500 cx23885_gpio_clear(dev, GPIO_5);
501 break;
502 case QAM_64:
503 case QAM_256:
504 default:
505 cx23885_gpio_set(dev, GPIO_5);
506 break;
507 }
508 break;
David T.L. Wong6f0d8c02009-10-21 13:15:30 -0300509 case CX23885_BOARD_MYGICA_X8506:
510 case CX23885_BOARD_MAGICPRO_PROHDTVE2:
511 /* Select Digital TV */
512 cx23885_gpio_set(dev, GPIO_0);
513 break;
Michael Krufkyf35b9e82009-05-08 22:39:24 -0300514 }
Michael Krufky5bdd3962009-05-08 22:39:24 -0300515 return 0;
Michael Krufkyf35b9e82009-05-08 22:39:24 -0300516}
517
David Wong2365b2d2009-06-17 01:38:12 -0300518static struct lgs8gxx_config magicpro_prohdtve2_lgs8g75_config = {
519 .prod = LGS8GXX_PROD_LGS8G75,
520 .demod_address = 0x19,
521 .serial_ts = 0,
522 .ts_clk_pol = 1,
523 .ts_clk_gated = 1,
524 .if_clk_freq = 30400, /* 30.4 MHz */
525 .if_freq = 6500, /* 6.50 MHz */
526 .if_neg_center = 1,
527 .ext_adc = 0,
528 .adc_signed = 1,
529 .adc_vpp = 2, /* 1.6 Vpp */
530 .if_neg_edge = 1,
531};
532
533static struct xc5000_config magicpro_prohdtve2_xc5000_config = {
534 .i2c_address = 0x61,
535 .if_khz = 6500,
536};
537
David T. L. Wongea5697f2009-10-26 08:54:04 -0300538static struct atbm8830_config mygica_x8558pro_atbm8830_cfg1 = {
539 .prod = ATBM8830_PROD_8830,
540 .demod_address = 0x44,
541 .serial_ts = 0,
542 .ts_sampling_edge = 1,
543 .ts_clk_gated = 0,
544 .osc_clk_freq = 30400, /* in kHz */
545 .if_freq = 0, /* zero IF */
546 .zif_swap_iq = 1,
David Wongc245c752009-11-28 08:36:31 -0300547 .agc_min = 0x2E,
548 .agc_max = 0xFF,
549 .agc_hold_loop = 0,
David T. L. Wongea5697f2009-10-26 08:54:04 -0300550};
551
552static struct max2165_config mygic_x8558pro_max2165_cfg1 = {
553 .i2c_address = 0x60,
554 .osc_clk = 20
555};
556
557static struct atbm8830_config mygica_x8558pro_atbm8830_cfg2 = {
558 .prod = ATBM8830_PROD_8830,
559 .demod_address = 0x44,
560 .serial_ts = 1,
561 .ts_sampling_edge = 1,
562 .ts_clk_gated = 0,
563 .osc_clk_freq = 30400, /* in kHz */
564 .if_freq = 0, /* zero IF */
565 .zif_swap_iq = 1,
David Wongc245c752009-11-28 08:36:31 -0300566 .agc_min = 0x2E,
567 .agc_max = 0xFF,
568 .agc_hold_loop = 0,
David T. L. Wongea5697f2009-10-26 08:54:04 -0300569};
570
571static struct max2165_config mygic_x8558pro_max2165_cfg2 = {
572 .i2c_address = 0x60,
573 .osc_clk = 20
574};
Igor M. Liplianin78db8542011-01-25 17:04:00 -0300575static struct stv0367_config netup_stv0367_config[] = {
576 {
577 .demod_address = 0x1c,
578 .xtal = 27000000,
579 .if_khz = 4500,
580 .if_iq_mode = 0,
581 .ts_mode = 1,
582 .clk_pol = 0,
583 }, {
584 .demod_address = 0x1d,
585 .xtal = 27000000,
586 .if_khz = 4500,
587 .if_iq_mode = 0,
588 .ts_mode = 1,
589 .clk_pol = 0,
590 },
591};
592
593static struct xc5000_config netup_xc5000_config[] = {
594 {
595 .i2c_address = 0x61,
596 .if_khz = 4500,
597 }, {
598 .i2c_address = 0x64,
599 .if_khz = 4500,
600 },
601};
602
603int netup_altera_fpga_rw(void *device, int flag, int data, int read)
604{
605 struct cx23885_dev *dev = (struct cx23885_dev *)device;
606 unsigned long timeout = jiffies + msecs_to_jiffies(1);
Abylay Ospand1644602011-01-02 09:10:00 -0300607 uint32_t mem = 0;
Igor M. Liplianin78db8542011-01-25 17:04:00 -0300608
Abylay Ospand1644602011-01-02 09:10:00 -0300609 mem = cx_read(MC417_RWD);
Igor M. Liplianin78db8542011-01-25 17:04:00 -0300610 if (read)
611 cx_set(MC417_OEN, ALT_DATA);
612 else {
613 cx_clear(MC417_OEN, ALT_DATA);/* D0-D7 out */
Igor M. Liplianin78db8542011-01-25 17:04:00 -0300614 mem &= ~ALT_DATA;
615 mem |= (data & ALT_DATA);
Igor M. Liplianin78db8542011-01-25 17:04:00 -0300616 }
617
618 if (flag)
Abylay Ospand1644602011-01-02 09:10:00 -0300619 mem |= ALT_AD_RG;
Igor M. Liplianin78db8542011-01-25 17:04:00 -0300620 else
Abylay Ospand1644602011-01-02 09:10:00 -0300621 mem &= ~ALT_AD_RG;
Igor M. Liplianin78db8542011-01-25 17:04:00 -0300622
Abylay Ospand1644602011-01-02 09:10:00 -0300623 mem &= ~ALT_CS;
Igor M. Liplianin78db8542011-01-25 17:04:00 -0300624 if (read)
Abylay Ospand1644602011-01-02 09:10:00 -0300625 mem = (mem & ~ALT_RD) | ALT_WR;
Igor M. Liplianin78db8542011-01-25 17:04:00 -0300626 else
Abylay Ospand1644602011-01-02 09:10:00 -0300627 mem = (mem & ~ALT_WR) | ALT_RD;
628
629 cx_write(MC417_RWD, mem); /* start RW cycle */
Igor M. Liplianin78db8542011-01-25 17:04:00 -0300630
631 for (;;) {
632 mem = cx_read(MC417_RWD);
633 if ((mem & ALT_RDY) == 0)
634 break;
635 if (time_after(jiffies, timeout))
636 break;
637 udelay(1);
638 }
639
640 cx_set(MC417_RWD, ALT_RD | ALT_WR | ALT_CS);
641 if (read)
642 return mem & ALT_DATA;
643
644 return 0;
645};
David T. L. Wongea5697f2009-10-26 08:54:04 -0300646
Steven Tothd19770e2007-03-11 20:44:05 -0300647static int dvb_register(struct cx23885_tsport *port)
648{
649 struct cx23885_dev *dev = port->dev;
David Wong493b7122009-05-18 05:25:49 -0300650 struct cx23885_i2c *i2c_bus = NULL, *i2c_bus2 = NULL;
Igor M. Liplianin78db8542011-01-25 17:04:00 -0300651 struct videobuf_dvb_frontend *fe0, *fe1 = NULL;
652 int mfe_shared = 0; /* bus not shared by default */
Igor M. Liplianin5a23b072009-03-03 12:06:09 -0300653 int ret;
Steven Toth363c35f2008-10-11 11:05:50 -0300654
Darron Broadf972e0bd2008-10-11 11:24:30 -0300655 /* Get the first frontend */
Darron Broad92abe9e2008-10-11 11:18:53 -0300656 fe0 = videobuf_dvb_get_frontend(&port->frontends, 1);
Steven Toth363c35f2008-10-11 11:05:50 -0300657 if (!fe0)
658 return -EINVAL;
Steven Tothd19770e2007-03-11 20:44:05 -0300659
660 /* init struct videobuf_dvb */
Steven Toth363c35f2008-10-11 11:05:50 -0300661 fe0->dvb.name = dev->name;
Steven Tothd19770e2007-03-11 20:44:05 -0300662
Igor M. Liplianin78db8542011-01-25 17:04:00 -0300663 /* multi-frontend gate control is undefined or defaults to fe0 */
664 port->frontends.gate = 0;
665
666 /* Sets the gate control callback to be used by i2c command calls */
667 port->gate_ctrl = cx23885_dvb_gate_ctrl;
668
Steven Tothd19770e2007-03-11 20:44:05 -0300669 /* init frontend */
670 switch (dev->board) {
Steven Totha77743b2007-08-22 21:01:20 -0300671 case CX23885_BOARD_HAUPPAUGE_HVR1250:
Michael Krufkyf139fa72007-09-09 03:55:34 -0300672 i2c_bus = &dev->i2c_bus[0];
Steven Toth363c35f2008-10-11 11:05:50 -0300673 fe0->dvb.frontend = dvb_attach(s5h1409_attach,
Steven Toth86184e02007-09-04 21:40:47 -0300674 &hauppauge_generic_config,
Michael Krufkyf139fa72007-09-09 03:55:34 -0300675 &i2c_bus->i2c_adap);
Steven Toth363c35f2008-10-11 11:05:50 -0300676 if (fe0->dvb.frontend != NULL) {
677 dvb_attach(mt2131_attach, fe0->dvb.frontend,
Michael Krufkyf139fa72007-09-09 03:55:34 -0300678 &i2c_bus->i2c_adap,
Steven Toth86184e02007-09-04 21:40:47 -0300679 &hauppauge_generic_tunerconfig, 0);
Steven Tothd19770e2007-03-11 20:44:05 -0300680 }
681 break;
Michael Krufkya5dbf452009-05-03 23:27:02 -0300682 case CX23885_BOARD_HAUPPAUGE_HVR1270:
Michael Krufkyd099bec2009-05-08 22:39:24 -0300683 case CX23885_BOARD_HAUPPAUGE_HVR1275:
Michael Krufkya5dbf452009-05-03 23:27:02 -0300684 i2c_bus = &dev->i2c_bus[0];
685 fe0->dvb.frontend = dvb_attach(lgdt3305_attach,
Michael Krufky247bc542009-05-12 18:53:47 -0300686 &hauppauge_lgdt3305_config,
Michael Krufkya5dbf452009-05-03 23:27:02 -0300687 &i2c_bus->i2c_adap);
688 if (fe0->dvb.frontend != NULL) {
689 dvb_attach(tda18271_attach, fe0->dvb.frontend,
690 0x60, &dev->i2c_bus[1].i2c_adap,
Michael Krufky247bc542009-05-12 18:53:47 -0300691 &hauppauge_hvr127x_config);
Michael Krufkya5dbf452009-05-03 23:27:02 -0300692 }
693 break;
Michael Krufky19bc5792009-05-08 16:05:29 -0300694 case CX23885_BOARD_HAUPPAUGE_HVR1255:
695 i2c_bus = &dev->i2c_bus[0];
696 fe0->dvb.frontend = dvb_attach(s5h1411_attach,
697 &hcw_s5h1411_config,
698 &i2c_bus->i2c_adap);
699 if (fe0->dvb.frontend != NULL) {
700 dvb_attach(tda18271_attach, fe0->dvb.frontend,
701 0x60, &dev->i2c_bus[1].i2c_adap,
702 &hauppauge_tda18271_config);
703 }
704 break;
Michael Krufky3ba71d22007-12-07 01:40:36 -0300705 case CX23885_BOARD_HAUPPAUGE_HVR1800:
706 i2c_bus = &dev->i2c_bus[0];
Darron Broad92abe9e2008-10-11 11:18:53 -0300707 switch (alt_tuner) {
Michael Krufky3ba71d22007-12-07 01:40:36 -0300708 case 1:
Steven Toth363c35f2008-10-11 11:05:50 -0300709 fe0->dvb.frontend =
Michael Krufky3ba71d22007-12-07 01:40:36 -0300710 dvb_attach(s5h1409_attach,
711 &hauppauge_ezqam_config,
712 &i2c_bus->i2c_adap);
Steven Toth363c35f2008-10-11 11:05:50 -0300713 if (fe0->dvb.frontend != NULL) {
714 dvb_attach(tda829x_attach, fe0->dvb.frontend,
Michael Krufky3ba71d22007-12-07 01:40:36 -0300715 &dev->i2c_bus[1].i2c_adap, 0x42,
Michael Krufky4041f1a2007-12-24 04:52:08 -0300716 &tda829x_no_probe);
Steven Toth363c35f2008-10-11 11:05:50 -0300717 dvb_attach(tda18271_attach, fe0->dvb.frontend,
Michael Krufky4041f1a2007-12-24 04:52:08 -0300718 0x60, &dev->i2c_bus[1].i2c_adap,
Michael Krufkyf21e0d72008-01-02 03:01:54 -0300719 &hauppauge_tda18271_config);
Michael Krufky3ba71d22007-12-07 01:40:36 -0300720 }
721 break;
722 case 0:
723 default:
Steven Toth363c35f2008-10-11 11:05:50 -0300724 fe0->dvb.frontend =
Michael Krufky3ba71d22007-12-07 01:40:36 -0300725 dvb_attach(s5h1409_attach,
726 &hauppauge_generic_config,
727 &i2c_bus->i2c_adap);
Steven Toth363c35f2008-10-11 11:05:50 -0300728 if (fe0->dvb.frontend != NULL)
729 dvb_attach(mt2131_attach, fe0->dvb.frontend,
Michael Krufky3ba71d22007-12-07 01:40:36 -0300730 &i2c_bus->i2c_adap,
731 &hauppauge_generic_tunerconfig, 0);
732 break;
733 }
734 break;
Steven Tothfc959be2007-09-08 19:08:17 -0300735 case CX23885_BOARD_HAUPPAUGE_HVR1800lp:
Michael Krufkyf139fa72007-09-09 03:55:34 -0300736 i2c_bus = &dev->i2c_bus[0];
Steven Toth363c35f2008-10-11 11:05:50 -0300737 fe0->dvb.frontend = dvb_attach(s5h1409_attach,
Steven Tothfc959be2007-09-08 19:08:17 -0300738 &hauppauge_hvr1800lp_config,
Michael Krufkyf139fa72007-09-09 03:55:34 -0300739 &i2c_bus->i2c_adap);
Steven Toth363c35f2008-10-11 11:05:50 -0300740 if (fe0->dvb.frontend != NULL) {
741 dvb_attach(mt2131_attach, fe0->dvb.frontend,
Michael Krufkyf139fa72007-09-09 03:55:34 -0300742 &i2c_bus->i2c_adap,
Steven Tothfc959be2007-09-08 19:08:17 -0300743 &hauppauge_generic_tunerconfig, 0);
744 }
745 break;
Michael Krufky9bc37ca2007-09-08 15:17:13 -0300746 case CX23885_BOARD_DVICO_FUSIONHDTV_5_EXP:
Michael Krufkyf139fa72007-09-09 03:55:34 -0300747 i2c_bus = &dev->i2c_bus[0];
Steven Toth363c35f2008-10-11 11:05:50 -0300748 fe0->dvb.frontend = dvb_attach(lgdt330x_attach,
Michael Krufky9bc37ca2007-09-08 15:17:13 -0300749 &fusionhdtv_5_express,
Michael Krufkyf139fa72007-09-09 03:55:34 -0300750 &i2c_bus->i2c_adap);
Steven Toth363c35f2008-10-11 11:05:50 -0300751 if (fe0->dvb.frontend != NULL) {
752 dvb_attach(simple_tuner_attach, fe0->dvb.frontend,
Michael Krufky827855d2008-04-22 14:46:16 -0300753 &i2c_bus->i2c_adap, 0x61,
754 TUNER_LG_TDVS_H06XF);
Michael Krufky9bc37ca2007-09-08 15:17:13 -0300755 }
756 break;
Steven Tothd1987d52007-12-18 01:57:06 -0300757 case CX23885_BOARD_HAUPPAUGE_HVR1500Q:
758 i2c_bus = &dev->i2c_bus[1];
Steven Toth363c35f2008-10-11 11:05:50 -0300759 fe0->dvb.frontend = dvb_attach(s5h1409_attach,
Steven Tothd1987d52007-12-18 01:57:06 -0300760 &hauppauge_hvr1500q_config,
761 &dev->i2c_bus[0].i2c_adap);
Steven Toth363c35f2008-10-11 11:05:50 -0300762 if (fe0->dvb.frontend != NULL)
763 dvb_attach(xc5000_attach, fe0->dvb.frontend,
Michael Krufky30650962008-09-06 14:56:58 -0300764 &i2c_bus->i2c_adap,
765 &hauppauge_hvr1500q_tunerconfig);
Steven Tothd1987d52007-12-18 01:57:06 -0300766 break;
Michael Krufky07b4a832007-12-18 01:09:11 -0300767 case CX23885_BOARD_HAUPPAUGE_HVR1500:
768 i2c_bus = &dev->i2c_bus[1];
Steven Toth363c35f2008-10-11 11:05:50 -0300769 fe0->dvb.frontend = dvb_attach(s5h1409_attach,
Michael Krufky07b4a832007-12-18 01:09:11 -0300770 &hauppauge_hvr1500_config,
771 &dev->i2c_bus[0].i2c_adap);
Steven Toth363c35f2008-10-11 11:05:50 -0300772 if (fe0->dvb.frontend != NULL) {
Michael Krufky07b4a832007-12-18 01:09:11 -0300773 struct dvb_frontend *fe;
774 struct xc2028_config cfg = {
775 .i2c_adap = &i2c_bus->i2c_adap,
776 .i2c_addr = 0x61,
Michael Krufky07b4a832007-12-18 01:09:11 -0300777 };
778 static struct xc2028_ctrl ctl = {
Michael Krufkyef80bfeb2008-09-16 02:15:30 -0300779 .fname = XC2028_DEFAULT_FIRMWARE,
Michael Krufky07b4a832007-12-18 01:09:11 -0300780 .max_len = 64,
Steven Toth52c3d292009-04-20 22:42:00 -0300781 .demod = XC3028_FE_OREN538,
Michael Krufky07b4a832007-12-18 01:09:11 -0300782 };
783
784 fe = dvb_attach(xc2028_attach,
Steven Toth363c35f2008-10-11 11:05:50 -0300785 fe0->dvb.frontend, &cfg);
Michael Krufky07b4a832007-12-18 01:09:11 -0300786 if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
787 fe->ops.tuner_ops.set_config(fe, &ctl);
788 }
789 break;
Steven Tothb3ea0162008-04-19 01:14:19 -0300790 case CX23885_BOARD_HAUPPAUGE_HVR1200:
Steven Totha780a312008-04-19 01:25:52 -0300791 case CX23885_BOARD_HAUPPAUGE_HVR1700:
Steven Tothb3ea0162008-04-19 01:14:19 -0300792 i2c_bus = &dev->i2c_bus[0];
Steven Toth363c35f2008-10-11 11:05:50 -0300793 fe0->dvb.frontend = dvb_attach(tda10048_attach,
Steven Tothb3ea0162008-04-19 01:14:19 -0300794 &hauppauge_hvr1200_config,
795 &i2c_bus->i2c_adap);
Steven Toth363c35f2008-10-11 11:05:50 -0300796 if (fe0->dvb.frontend != NULL) {
797 dvb_attach(tda829x_attach, fe0->dvb.frontend,
Steven Tothb3ea0162008-04-19 01:14:19 -0300798 &dev->i2c_bus[1].i2c_adap, 0x42,
799 &tda829x_no_probe);
Steven Toth363c35f2008-10-11 11:05:50 -0300800 dvb_attach(tda18271_attach, fe0->dvb.frontend,
Steven Tothb3ea0162008-04-19 01:14:19 -0300801 0x60, &dev->i2c_bus[1].i2c_adap,
802 &hauppauge_hvr1200_tuner_config);
803 }
804 break;
Michael Krufky6b926ec2009-05-12 17:32:17 -0300805 case CX23885_BOARD_HAUPPAUGE_HVR1210:
806 i2c_bus = &dev->i2c_bus[0];
807 fe0->dvb.frontend = dvb_attach(tda10048_attach,
808 &hauppauge_hvr1210_config,
809 &i2c_bus->i2c_adap);
810 if (fe0->dvb.frontend != NULL) {
811 dvb_attach(tda18271_attach, fe0->dvb.frontend,
812 0x60, &dev->i2c_bus[1].i2c_adap,
813 &hauppauge_hvr1210_tuner_config);
814 }
815 break;
Steven Toth66762372008-04-22 15:38:26 -0300816 case CX23885_BOARD_HAUPPAUGE_HVR1400:
817 i2c_bus = &dev->i2c_bus[0];
Steven Toth363c35f2008-10-11 11:05:50 -0300818 fe0->dvb.frontend = dvb_attach(dib7000p_attach,
Steven Toth66762372008-04-22 15:38:26 -0300819 &i2c_bus->i2c_adap,
820 0x12, &hauppauge_hvr1400_dib7000_config);
Steven Toth363c35f2008-10-11 11:05:50 -0300821 if (fe0->dvb.frontend != NULL) {
Steven Toth66762372008-04-22 15:38:26 -0300822 struct dvb_frontend *fe;
823 struct xc2028_config cfg = {
824 .i2c_adap = &dev->i2c_bus[1].i2c_adap,
825 .i2c_addr = 0x64,
Steven Toth66762372008-04-22 15:38:26 -0300826 };
827 static struct xc2028_ctrl ctl = {
Michael Krufkyef80bfeb2008-09-16 02:15:30 -0300828 .fname = XC3028L_DEFAULT_FIRMWARE,
Steven Toth66762372008-04-22 15:38:26 -0300829 .max_len = 64,
Mauro Carvalho Chehab9bed77e2011-07-28 16:38:54 -0300830 .demod = XC3028_FE_DIBCOM52,
Steven Toth9c8ced52008-10-16 20:18:44 -0300831 /* This is true for all demods with
832 v36 firmware? */
Mauro Carvalho Chehab0975fc62008-09-28 02:24:44 -0300833 .type = XC2028_D2633,
Steven Toth66762372008-04-22 15:38:26 -0300834 };
835
836 fe = dvb_attach(xc2028_attach,
Steven Toth363c35f2008-10-11 11:05:50 -0300837 fe0->dvb.frontend, &cfg);
Steven Toth66762372008-04-22 15:38:26 -0300838 if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
839 fe->ops.tuner_ops.set_config(fe, &ctl);
840 }
841 break;
Michael Krufky335377b2008-05-07 01:43:10 -0300842 case CX23885_BOARD_DVICO_FUSIONHDTV_7_DUAL_EXP:
843 i2c_bus = &dev->i2c_bus[port->nr - 1];
844
Steven Toth363c35f2008-10-11 11:05:50 -0300845 fe0->dvb.frontend = dvb_attach(s5h1409_attach,
Michael Krufky335377b2008-05-07 01:43:10 -0300846 &dvico_s5h1409_config,
847 &i2c_bus->i2c_adap);
Steven Toth363c35f2008-10-11 11:05:50 -0300848 if (fe0->dvb.frontend == NULL)
849 fe0->dvb.frontend = dvb_attach(s5h1411_attach,
Michael Krufky52b50452008-07-09 02:18:49 -0300850 &dvico_s5h1411_config,
851 &i2c_bus->i2c_adap);
Steven Toth363c35f2008-10-11 11:05:50 -0300852 if (fe0->dvb.frontend != NULL)
853 dvb_attach(xc5000_attach, fe0->dvb.frontend,
Michael Krufky30650962008-09-06 14:56:58 -0300854 &i2c_bus->i2c_adap,
855 &dvico_xc5000_tunerconfig);
Michael Krufky335377b2008-05-07 01:43:10 -0300856 break;
Steven Tothaef2d182008-08-04 21:39:53 -0300857 case CX23885_BOARD_DVICO_FUSIONHDTV_DVB_T_DUAL_EXP: {
858 i2c_bus = &dev->i2c_bus[port->nr - 1];
859
Steven Toth363c35f2008-10-11 11:05:50 -0300860 fe0->dvb.frontend = dvb_attach(zl10353_attach,
Steven Tothaef2d182008-08-04 21:39:53 -0300861 &dvico_fusionhdtv_xc3028,
862 &i2c_bus->i2c_adap);
Steven Toth363c35f2008-10-11 11:05:50 -0300863 if (fe0->dvb.frontend != NULL) {
Steven Tothaef2d182008-08-04 21:39:53 -0300864 struct dvb_frontend *fe;
865 struct xc2028_config cfg = {
866 .i2c_adap = &i2c_bus->i2c_adap,
867 .i2c_addr = 0x61,
Steven Tothaef2d182008-08-04 21:39:53 -0300868 };
869 static struct xc2028_ctrl ctl = {
Michael Krufkyef80bfeb2008-09-16 02:15:30 -0300870 .fname = XC2028_DEFAULT_FIRMWARE,
Steven Tothaef2d182008-08-04 21:39:53 -0300871 .max_len = 64,
872 .demod = XC3028_FE_ZARLINK456,
873 };
874
Steven Toth363c35f2008-10-11 11:05:50 -0300875 fe = dvb_attach(xc2028_attach, fe0->dvb.frontend,
Steven Tothaef2d182008-08-04 21:39:53 -0300876 &cfg);
877 if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
878 fe->ops.tuner_ops.set_config(fe, &ctl);
879 }
880 break;
881 }
Steven Toth4c56b042008-08-12 13:30:03 -0300882 case CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H:
Igor M. Liplianin9bb1b7e2008-11-23 14:11:16 -0300883 case CX23885_BOARD_COMPRO_VIDEOMATE_E650F:
Vladimir Geroy34e383d2009-09-18 18:55:47 -0300884 case CX23885_BOARD_COMPRO_VIDEOMATE_E800:
Steven Toth4c56b042008-08-12 13:30:03 -0300885 i2c_bus = &dev->i2c_bus[0];
886
Steven Toth363c35f2008-10-11 11:05:50 -0300887 fe0->dvb.frontend = dvb_attach(zl10353_attach,
Steven Toth4c56b042008-08-12 13:30:03 -0300888 &dvico_fusionhdtv_xc3028,
889 &i2c_bus->i2c_adap);
Steven Toth363c35f2008-10-11 11:05:50 -0300890 if (fe0->dvb.frontend != NULL) {
Steven Toth4c56b042008-08-12 13:30:03 -0300891 struct dvb_frontend *fe;
892 struct xc2028_config cfg = {
893 .i2c_adap = &dev->i2c_bus[1].i2c_adap,
894 .i2c_addr = 0x61,
Steven Toth4c56b042008-08-12 13:30:03 -0300895 };
896 static struct xc2028_ctrl ctl = {
Michael Krufkyef80bfeb2008-09-16 02:15:30 -0300897 .fname = XC2028_DEFAULT_FIRMWARE,
Steven Toth4c56b042008-08-12 13:30:03 -0300898 .max_len = 64,
899 .demod = XC3028_FE_ZARLINK456,
900 };
901
Steven Toth363c35f2008-10-11 11:05:50 -0300902 fe = dvb_attach(xc2028_attach, fe0->dvb.frontend,
Steven Toth4c56b042008-08-12 13:30:03 -0300903 &cfg);
904 if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
905 fe->ops.tuner_ops.set_config(fe, &ctl);
906 }
907 break;
istvan_v@mailbox.hu0cf8af52011-07-11 10:58:35 -0300908 case CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H_XC4000:
909 i2c_bus = &dev->i2c_bus[0];
910
911 fe0->dvb.frontend = dvb_attach(zl10353_attach,
912 &dvico_fusionhdtv_xc3028,
913 &i2c_bus->i2c_adap);
914 if (fe0->dvb.frontend != NULL) {
915 struct dvb_frontend *fe;
916 struct xc4000_config cfg = {
917 .i2c_address = 0x61,
918 .default_pm = 0,
919 .dvb_amplitude = 134,
920 .set_smoothedcvbs = 1,
921 .if_khz = 4560
922 };
923
924 fe = dvb_attach(xc4000_attach, fe0->dvb.frontend,
925 &dev->i2c_bus[1].i2c_adap, &cfg);
926 }
927 break;
Igor M. Liplianin96318d02009-01-17 12:11:20 -0300928 case CX23885_BOARD_TBS_6920:
Igor M. Liplianin09ea33e2009-11-24 20:16:04 -0300929 i2c_bus = &dev->i2c_bus[1];
Igor M. Liplianin96318d02009-01-17 12:11:20 -0300930
931 fe0->dvb.frontend = dvb_attach(cx24116_attach,
Igor M. Liplianin09ea33e2009-11-24 20:16:04 -0300932 &tbs_cx24116_config,
933 &i2c_bus->i2c_adap);
Igor M. Liplianin96318d02009-01-17 12:11:20 -0300934 if (fe0->dvb.frontend != NULL)
Igor M. Liplianin09ea33e2009-11-24 20:16:04 -0300935 fe0->dvb.frontend->ops.set_voltage = f300_set_voltage;
Igor M. Liplianin96318d02009-01-17 12:11:20 -0300936
937 break;
Igor M. Liplianin579943f2009-01-17 12:18:26 -0300938 case CX23885_BOARD_TEVII_S470:
939 i2c_bus = &dev->i2c_bus[1];
940
Igor M. Liplianin09ea33e2009-11-24 20:16:04 -0300941 fe0->dvb.frontend = dvb_attach(ds3000_attach,
942 &tevii_ds3000_config,
943 &i2c_bus->i2c_adap);
Igor M. Liplianin579943f2009-01-17 12:18:26 -0300944 if (fe0->dvb.frontend != NULL)
Igor M. Liplianin09ea33e2009-11-24 20:16:04 -0300945 fe0->dvb.frontend->ops.set_voltage = f300_set_voltage;
Igor M. Liplianin579943f2009-01-17 12:18:26 -0300946
947 break;
Igor M. Liplianinc9b8b042009-01-17 12:23:31 -0300948 case CX23885_BOARD_DVBWORLD_2005:
949 i2c_bus = &dev->i2c_bus[1];
950
951 fe0->dvb.frontend = dvb_attach(cx24116_attach,
952 &dvbworld_cx24116_config,
953 &i2c_bus->i2c_adap);
954 break;
Igor M. Liplianin5a23b072009-03-03 12:06:09 -0300955 case CX23885_BOARD_NETUP_DUAL_DVBS2_CI:
956 i2c_bus = &dev->i2c_bus[0];
957 switch (port->nr) {
958 /* port B */
959 case 1:
960 fe0->dvb.frontend = dvb_attach(stv0900_attach,
961 &netup_stv0900_config,
962 &i2c_bus->i2c_adap, 0);
963 if (fe0->dvb.frontend != NULL) {
964 if (dvb_attach(stv6110_attach,
965 fe0->dvb.frontend,
966 &netup_stv6110_tunerconfig_a,
967 &i2c_bus->i2c_adap)) {
968 if (!dvb_attach(lnbh24_attach,
969 fe0->dvb.frontend,
970 &i2c_bus->i2c_adap,
Abylay Ospan9329fb52009-10-17 08:38:45 -0300971 LNBH24_PCL | LNBH24_TTX,
972 LNBH24_TEN, 0x09))
Igor M. Liplianin5a23b072009-03-03 12:06:09 -0300973 printk(KERN_ERR
974 "No LNBH24 found!\n");
975
976 }
977 }
978 break;
979 /* port C */
980 case 2:
981 fe0->dvb.frontend = dvb_attach(stv0900_attach,
982 &netup_stv0900_config,
983 &i2c_bus->i2c_adap, 1);
984 if (fe0->dvb.frontend != NULL) {
985 if (dvb_attach(stv6110_attach,
986 fe0->dvb.frontend,
987 &netup_stv6110_tunerconfig_b,
988 &i2c_bus->i2c_adap)) {
989 if (!dvb_attach(lnbh24_attach,
990 fe0->dvb.frontend,
991 &i2c_bus->i2c_adap,
Abylay Ospan9329fb52009-10-17 08:38:45 -0300992 LNBH24_PCL | LNBH24_TTX,
993 LNBH24_TEN, 0x0a))
Igor M. Liplianin5a23b072009-03-03 12:06:09 -0300994 printk(KERN_ERR
995 "No LNBH24 found!\n");
996
997 }
998 }
999 break;
1000 }
1001 break;
David Wong493b7122009-05-18 05:25:49 -03001002 case CX23885_BOARD_MYGICA_X8506:
1003 i2c_bus = &dev->i2c_bus[0];
1004 i2c_bus2 = &dev->i2c_bus[1];
1005 fe0->dvb.frontend = dvb_attach(lgs8gxx_attach,
1006 &mygica_x8506_lgs8gl5_config,
1007 &i2c_bus->i2c_adap);
1008 if (fe0->dvb.frontend != NULL) {
1009 dvb_attach(xc5000_attach,
1010 fe0->dvb.frontend,
1011 &i2c_bus2->i2c_adap,
1012 &mygica_x8506_xc5000_config);
1013 }
1014 break;
David Wong2365b2d2009-06-17 01:38:12 -03001015 case CX23885_BOARD_MAGICPRO_PROHDTVE2:
1016 i2c_bus = &dev->i2c_bus[0];
1017 i2c_bus2 = &dev->i2c_bus[1];
1018 fe0->dvb.frontend = dvb_attach(lgs8gxx_attach,
1019 &magicpro_prohdtve2_lgs8g75_config,
1020 &i2c_bus->i2c_adap);
1021 if (fe0->dvb.frontend != NULL) {
1022 dvb_attach(xc5000_attach,
1023 fe0->dvb.frontend,
1024 &i2c_bus2->i2c_adap,
1025 &magicpro_prohdtve2_xc5000_config);
1026 }
1027 break;
Steven Toth136973802009-07-20 15:37:25 -03001028 case CX23885_BOARD_HAUPPAUGE_HVR1850:
Steven Toth35045132012-01-04 21:08:35 -03001029 i2c_bus = &dev->i2c_bus[0];
1030 fe0->dvb.frontend = dvb_attach(s5h1411_attach,
1031 &hcw_s5h1411_config,
1032 &i2c_bus->i2c_adap);
1033 if (fe0->dvb.frontend != NULL)
1034 dvb_attach(tda18271_attach, fe0->dvb.frontend,
1035 0x60, &dev->i2c_bus[0].i2c_adap,
1036 &hauppauge_tda18271_config);
1037
1038 tda18271_attach(&dev->ts1.analog_fe,
1039 0x60, &dev->i2c_bus[1].i2c_adap,
1040 &hauppauge_tda18271_config);
1041
1042 break;
Michael Krufkyaee0b242009-11-11 01:52:45 -03001043 case CX23885_BOARD_HAUPPAUGE_HVR1290:
Steven Toth136973802009-07-20 15:37:25 -03001044 i2c_bus = &dev->i2c_bus[0];
1045 fe0->dvb.frontend = dvb_attach(s5h1411_attach,
1046 &hcw_s5h1411_config,
1047 &i2c_bus->i2c_adap);
1048 if (fe0->dvb.frontend != NULL)
1049 dvb_attach(tda18271_attach, fe0->dvb.frontend,
1050 0x60, &dev->i2c_bus[0].i2c_adap,
1051 &hauppauge_tda18271_config);
1052 break;
David T. L. Wongea5697f2009-10-26 08:54:04 -03001053 case CX23885_BOARD_MYGICA_X8558PRO:
1054 switch (port->nr) {
1055 /* port B */
1056 case 1:
1057 i2c_bus = &dev->i2c_bus[0];
1058 fe0->dvb.frontend = dvb_attach(atbm8830_attach,
1059 &mygica_x8558pro_atbm8830_cfg1,
1060 &i2c_bus->i2c_adap);
1061 if (fe0->dvb.frontend != NULL) {
1062 dvb_attach(max2165_attach,
1063 fe0->dvb.frontend,
1064 &i2c_bus->i2c_adap,
1065 &mygic_x8558pro_max2165_cfg1);
1066 }
1067 break;
1068 /* port C */
1069 case 2:
1070 i2c_bus = &dev->i2c_bus[1];
1071 fe0->dvb.frontend = dvb_attach(atbm8830_attach,
1072 &mygica_x8558pro_atbm8830_cfg2,
1073 &i2c_bus->i2c_adap);
1074 if (fe0->dvb.frontend != NULL) {
1075 dvb_attach(max2165_attach,
1076 fe0->dvb.frontend,
1077 &i2c_bus->i2c_adap,
1078 &mygic_x8558pro_max2165_cfg2);
1079 }
1080 break;
1081 }
1082 break;
Igor M. Liplianin78db8542011-01-25 17:04:00 -03001083 case CX23885_BOARD_NETUP_DUAL_DVB_T_C_CI_RF:
1084 i2c_bus = &dev->i2c_bus[0];
1085 mfe_shared = 1;/* MFE */
1086 port->frontends.gate = 0;/* not clear for me yet */
1087 /* ports B, C */
1088 /* MFE frontend 1 DVB-T */
1089 fe0->dvb.frontend = dvb_attach(stv0367ter_attach,
1090 &netup_stv0367_config[port->nr - 1],
1091 &i2c_bus->i2c_adap);
Abylay Ospan4174ebf52011-01-02 09:15:00 -03001092 if (fe0->dvb.frontend != NULL) {
Igor M. Liplianin78db8542011-01-25 17:04:00 -03001093 if (NULL == dvb_attach(xc5000_attach,
1094 fe0->dvb.frontend,
1095 &i2c_bus->i2c_adap,
1096 &netup_xc5000_config[port->nr - 1]))
1097 goto frontend_detach;
Abylay Ospan4174ebf52011-01-02 09:15:00 -03001098 /* load xc5000 firmware */
1099 fe0->dvb.frontend->ops.tuner_ops.init(fe0->dvb.frontend);
1100 }
Igor M. Liplianin78db8542011-01-25 17:04:00 -03001101 /* MFE frontend 2 */
1102 fe1 = videobuf_dvb_get_frontend(&port->frontends, 2);
1103 if (fe1 == NULL)
1104 goto frontend_detach;
1105 /* DVB-C init */
1106 fe1->dvb.frontend = dvb_attach(stv0367cab_attach,
1107 &netup_stv0367_config[port->nr - 1],
1108 &i2c_bus->i2c_adap);
1109 if (fe1->dvb.frontend != NULL) {
1110 fe1->dvb.frontend->id = 1;
1111 if (NULL == dvb_attach(xc5000_attach,
1112 fe1->dvb.frontend,
1113 &i2c_bus->i2c_adap,
1114 &netup_xc5000_config[port->nr - 1]))
1115 goto frontend_detach;
1116 }
1117 break;
Steven Tothd19770e2007-03-11 20:44:05 -03001118 default:
Steven Toth9c8ced52008-10-16 20:18:44 -03001119 printk(KERN_INFO "%s: The frontend of your DVB/ATSC card "
1120 " isn't supported yet\n",
Steven Tothd19770e2007-03-11 20:44:05 -03001121 dev->name);
1122 break;
1123 }
Igor M. Liplianin78db8542011-01-25 17:04:00 -03001124
1125 if ((NULL == fe0->dvb.frontend) || (fe1 && NULL == fe1->dvb.frontend)) {
Steven Toth9c8ced52008-10-16 20:18:44 -03001126 printk(KERN_ERR "%s: frontend initialization failed\n",
Igor M. Liplianin78db8542011-01-25 17:04:00 -03001127 dev->name);
1128 goto frontend_detach;
Steven Tothd19770e2007-03-11 20:44:05 -03001129 }
Igor M. Liplianin78db8542011-01-25 17:04:00 -03001130
Michael Krufkyd7cba042008-09-12 13:31:45 -03001131 /* define general-purpose callback pointer */
Steven Toth363c35f2008-10-11 11:05:50 -03001132 fe0->dvb.frontend->callback = cx23885_tuner_callback;
Igor M. Liplianin78db8542011-01-25 17:04:00 -03001133 if (fe1)
1134 fe1->dvb.frontend->callback = cx23885_tuner_callback;
1135#if 0
1136 /* Ensure all frontends negotiate bus access */
1137 fe0->dvb.frontend->ops.ts_bus_ctrl = cx23885_dvb_bus_ctrl;
1138 if (fe1)
1139 fe1->dvb.frontend->ops.ts_bus_ctrl = cx23885_dvb_bus_ctrl;
1140#endif
Steven Tothd19770e2007-03-11 20:44:05 -03001141
1142 /* Put the analog decoder in standby to keep it quiet */
Laurent Pinchart622b8282009-10-05 10:48:17 -03001143 call_all(dev, core, s_power, 0);
Steven Tothd19770e2007-03-11 20:44:05 -03001144
Steven Toth363c35f2008-10-11 11:05:50 -03001145 if (fe0->dvb.frontend->ops.analog_ops.standby)
1146 fe0->dvb.frontend->ops.analog_ops.standby(fe0->dvb.frontend);
Michael Krufky3ba71d22007-12-07 01:40:36 -03001147
Steven Tothd19770e2007-03-11 20:44:05 -03001148 /* register everything */
Igor M. Liplianin5a23b072009-03-03 12:06:09 -03001149 ret = videobuf_dvb_register_bus(&port->frontends, THIS_MODULE, port,
Igor M. Liplianin78db8542011-01-25 17:04:00 -03001150 &dev->pci->dev, adapter_nr, mfe_shared,
Mauro Carvalho Chehaba7d44ba2011-12-26 20:48:54 -03001151 NULL);
Abylay Ospanbee30192010-06-25 08:01:28 -03001152 if (ret)
Igor M. Liplianin78db8542011-01-25 17:04:00 -03001153 goto frontend_detach;
Steven Toth363c35f2008-10-11 11:05:50 -03001154
Igor M. Liplianin5a23b072009-03-03 12:06:09 -03001155 /* init CI & MAC */
1156 switch (dev->board) {
1157 case CX23885_BOARD_NETUP_DUAL_DVBS2_CI: {
1158 static struct netup_card_info cinfo;
1159
1160 netup_get_card_info(&dev->i2c_bus[0].i2c_adap, &cinfo);
1161 memcpy(port->frontends.adapter.proposed_mac,
1162 cinfo.port[port->nr - 1].mac, 6);
hartleysbe395152009-12-30 16:08:57 -03001163 printk(KERN_INFO "NetUP Dual DVB-S2 CI card port%d MAC=%pM\n",
1164 port->nr, port->frontends.adapter.proposed_mac);
Igor M. Liplianin5a23b072009-03-03 12:06:09 -03001165
1166 netup_ci_init(port);
1167 break;
1168 }
Igor M. Liplianin78db8542011-01-25 17:04:00 -03001169 case CX23885_BOARD_NETUP_DUAL_DVB_T_C_CI_RF: {
1170 struct altera_ci_config netup_ci_cfg = {
1171 .dev = dev,/* magic number to identify*/
1172 .adapter = &port->frontends.adapter,/* for CI */
1173 .demux = &fe0->dvb.demux,/* for hw pid filter */
1174 .fpga_rw = netup_altera_fpga_rw,
1175 };
1176
1177 altera_ci_init(&netup_ci_cfg, port->nr);
1178 break;
1179 }
Pierre Gronlier16bfdaa42010-04-26 13:26:29 -03001180 case CX23885_BOARD_TEVII_S470: {
1181 u8 eeprom[256]; /* 24C02 i2c eeprom */
1182
1183 if (port->nr != 1)
1184 break;
1185
1186 /* Read entire EEPROM */
1187 dev->i2c_bus[0].i2c_client.addr = 0xa0 >> 1;
1188 tveeprom_read(&dev->i2c_bus[0].i2c_client, eeprom, sizeof(eeprom));
Andy Shevchenko5cac1f662010-09-11 14:33:28 -03001189 printk(KERN_INFO "TeVii S470 MAC= %pM\n", eeprom + 0xa0);
Pierre Gronlier16bfdaa42010-04-26 13:26:29 -03001190 memcpy(port->frontends.adapter.proposed_mac, eeprom + 0xa0, 6);
1191 break;
1192 }
Igor M. Liplianin5a23b072009-03-03 12:06:09 -03001193 }
1194
1195 return ret;
Igor M. Liplianin78db8542011-01-25 17:04:00 -03001196
1197frontend_detach:
1198 port->gate_ctrl = NULL;
1199 videobuf_dvb_dealloc_frontends(&port->frontends);
1200 return -EINVAL;
Steven Tothd19770e2007-03-11 20:44:05 -03001201}
1202
1203int cx23885_dvb_register(struct cx23885_tsport *port)
1204{
Steven Toth363c35f2008-10-11 11:05:50 -03001205
1206 struct videobuf_dvb_frontend *fe0;
Steven Tothd19770e2007-03-11 20:44:05 -03001207 struct cx23885_dev *dev = port->dev;
Steven Totheb0c58b2008-10-11 12:34:39 -03001208 int err, i;
Steven Tothd19770e2007-03-11 20:44:05 -03001209
Steven Totheb0c58b2008-10-11 12:34:39 -03001210 /* Here we need to allocate the correct number of frontends,
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001211 * as reflected in the cards struct. The reality is that currently
Steven Totheb0c58b2008-10-11 12:34:39 -03001212 * no cx23885 boards support this - yet. But, if we don't modify this
1213 * code then the second frontend would never be allocated (later)
1214 * and fail with error before the attach in dvb_register().
1215 * Without these changes we risk an OOPS later. The changes here
1216 * are for safety, and should provide a good foundation for the
1217 * future addition of any multi-frontend cx23885 based boards.
1218 */
1219 printk(KERN_INFO "%s() allocating %d frontend(s)\n", __func__,
1220 port->num_frontends);
Steven Toth363c35f2008-10-11 11:05:50 -03001221
Steven Totheb0c58b2008-10-11 12:34:39 -03001222 for (i = 1; i <= port->num_frontends; i++) {
Darron Broad96b7a1a2008-10-15 20:26:34 -03001223 if (videobuf_dvb_alloc_frontend(
Steven Toth9c8ced52008-10-16 20:18:44 -03001224 &port->frontends, i) == NULL) {
Steven Totheb0c58b2008-10-11 12:34:39 -03001225 printk(KERN_ERR "%s() failed to alloc\n", __func__);
1226 return -ENOMEM;
1227 }
Steven Tothd19770e2007-03-11 20:44:05 -03001228
Steven Totheb0c58b2008-10-11 12:34:39 -03001229 fe0 = videobuf_dvb_get_frontend(&port->frontends, i);
1230 if (!fe0)
1231 err = -EINVAL;
Steven Tothd19770e2007-03-11 20:44:05 -03001232
Steven Totheb0c58b2008-10-11 12:34:39 -03001233 dprintk(1, "%s\n", __func__);
Steven Toth9c8ced52008-10-16 20:18:44 -03001234 dprintk(1, " ->probed by Card=%d Name=%s, PCI %02x:%02x\n",
Steven Totheb0c58b2008-10-11 12:34:39 -03001235 dev->board,
1236 dev->name,
1237 dev->pci_bus,
1238 dev->pci_slot);
1239
1240 err = -ENODEV;
1241
1242 /* dvb stuff */
1243 /* We have to init the queue for each frontend on a port. */
Steven Toth9c8ced52008-10-16 20:18:44 -03001244 printk(KERN_INFO "%s: cx23885 based dvb card\n", dev->name);
1245 videobuf_queue_sg_init(&fe0->dvb.dvbq, &dvb_qops,
1246 &dev->pci->dev, &port->slock,
Michael Krufky44a64812007-03-20 23:00:18 -03001247 V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_TOP,
Hans Verkuil08bff032010-09-20 17:39:46 -03001248 sizeof(struct cx23885_buffer), port, NULL);
Steven Totheb0c58b2008-10-11 12:34:39 -03001249 }
Steven Tothd19770e2007-03-11 20:44:05 -03001250 err = dvb_register(port);
1251 if (err != 0)
Steven Toth9c8ced52008-10-16 20:18:44 -03001252 printk(KERN_ERR "%s() dvb_register failed err = %d\n",
1253 __func__, err);
Steven Tothd19770e2007-03-11 20:44:05 -03001254
Steven Tothd19770e2007-03-11 20:44:05 -03001255 return err;
1256}
1257
1258int cx23885_dvb_unregister(struct cx23885_tsport *port)
1259{
Steven Toth363c35f2008-10-11 11:05:50 -03001260 struct videobuf_dvb_frontend *fe0;
1261
Steven Totheb0c58b2008-10-11 12:34:39 -03001262 /* FIXME: in an error condition where the we have
1263 * an expected number of frontends (attach problem)
1264 * then this might not clean up correctly, if 1
1265 * is invalid.
1266 * This comment only applies to future boards IF they
1267 * implement MFE support.
1268 */
Darron Broad92abe9e2008-10-11 11:18:53 -03001269 fe0 = videobuf_dvb_get_frontend(&port->frontends, 1);
Abylay Ospane66131c2011-07-15 15:01:07 -03001270 if (fe0 && fe0->dvb.frontend)
Steven Toth363c35f2008-10-11 11:05:50 -03001271 videobuf_dvb_unregister_bus(&port->frontends);
Steven Tothd19770e2007-03-11 20:44:05 -03001272
Hans Verkuilafd96662009-03-13 13:24:19 -03001273 switch (port->dev->board) {
1274 case CX23885_BOARD_NETUP_DUAL_DVBS2_CI:
1275 netup_ci_exit(port);
1276 break;
Igor M. Liplianin78db8542011-01-25 17:04:00 -03001277 case CX23885_BOARD_NETUP_DUAL_DVB_T_C_CI_RF:
1278 altera_ci_release(port->dev, port->nr);
1279 break;
Hans Verkuilafd96662009-03-13 13:24:19 -03001280 }
Igor M. Liplianin5a23b072009-03-03 12:06:09 -03001281
Igor M. Liplianin78db8542011-01-25 17:04:00 -03001282 port->gate_ctrl = NULL;
1283
Steven Tothd19770e2007-03-11 20:44:05 -03001284 return 0;
1285}
Michael Krufky44a64812007-03-20 23:00:18 -03001286