blob: f0381d62518d52b1e491795a3ba53a7d7bbca6a3 [file] [log] [blame]
Hans Verkuil1c1e45d2008-04-28 20:24:33 -03001/*
2 * cx18 functions for DVB support
3 *
Steven Toth6d897612008-09-03 17:12:12 -03004 * Copyright (c) 2008 Steven Toth <stoth@linuxtv.org>
Andy Walls6afdeaf2010-05-23 18:53:35 -03005 * Copyright (C) 2008 Andy Walls <awalls@md.metrocast.net>
Hans Verkuil1c1e45d2008-04-28 20:24:33 -03006 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 *
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23#include "cx18-version.h"
24#include "cx18-dvb.h"
Andy Wallsb1526422008-08-30 16:03:44 -030025#include "cx18-io.h"
Andy Walls21a278b2009-04-15 20:45:10 -030026#include "cx18-queue.h"
Hans Verkuil1c1e45d2008-04-28 20:24:33 -030027#include "cx18-streams.h"
28#include "cx18-cards.h"
Andy Walls8bb09db2009-06-09 20:47:21 -030029#include "cx18-gpio.h"
Hans Verkuil1c1e45d2008-04-28 20:24:33 -030030#include "s5h1409.h"
Steven Toth67129472008-05-01 07:23:23 -030031#include "mxl5005s.h"
Andy Walls8bb09db2009-06-09 20:47:21 -030032#include "zl10353.h"
Andy Wallsff861fb2009-07-03 11:54:40 -030033
34#include <linux/firmware.h>
35#include "mt352.h"
36#include "mt352_priv.h"
Andy Walls8bb09db2009-06-09 20:47:21 -030037#include "tuner-xc2028.h"
Hans Verkuil1c1e45d2008-04-28 20:24:33 -030038
39DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
40
41#define CX18_REG_DMUX_NUM_PORT_0_CONTROL 0xd5a000
Andy Walls8bb09db2009-06-09 20:47:21 -030042#define CX18_CLOCK_ENABLE2 0xc71024
43#define CX18_DMUX_CLK_MASK 0x0080
Hans Verkuil1c1e45d2008-04-28 20:24:33 -030044
Andy Wallsff861fb2009-07-03 11:54:40 -030045/*
46 * CX18_CARD_HVR_1600_ESMT
47 * CX18_CARD_HVR_1600_SAMSUNG
48 */
49
Steven Toth67129472008-05-01 07:23:23 -030050static struct mxl5005s_config hauppauge_hvr1600_tuner = {
51 .i2c_address = 0xC6 >> 1,
52 .if_freq = IF_FREQ_5380000HZ,
53 .xtal_freq = CRYSTAL_FREQ_16000000HZ,
54 .agc_mode = MXL_SINGLE_AGC,
55 .tracking_filter = MXL_TF_C_H,
56 .rssi_enable = MXL_RSSI_ENABLE,
57 .cap_select = MXL_CAP_SEL_ENABLE,
58 .div_out = MXL_DIV_OUT_4,
59 .clock_out = MXL_CLOCK_OUT_DISABLE,
60 .output_load = MXL5005S_IF_OUTPUT_LOAD_200_OHM,
61 .top = MXL5005S_TOP_25P2,
62 .mod_mode = MXL_DIGITAL_MODE,
63 .if_mode = MXL_ZERO_IF,
Devin Heitmueller48c511e2009-10-28 23:10:16 -030064 .qam_gain = 0x02,
Steven Toth67129472008-05-01 07:23:23 -030065 .AgcMasterByte = 0x00,
Hans Verkuil1c1e45d2008-04-28 20:24:33 -030066};
67
68static struct s5h1409_config hauppauge_hvr1600_config = {
69 .demod_address = 0x32 >> 1,
70 .output_mode = S5H1409_SERIAL_OUTPUT,
71 .gpio = S5H1409_GPIO_ON,
72 .qam_if = 44000,
73 .inversion = S5H1409_INVERSION_OFF,
74 .status_mode = S5H1409_DEMODLOCKING,
Devin Heitmuelleraf5c8e12009-10-27 23:33:21 -030075 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
76 .hvr1600_opt = S5H1409_HVR1600_OPTIMIZE
Andy Walls8bb09db2009-06-09 20:47:21 -030077};
Hans Verkuil1c1e45d2008-04-28 20:24:33 -030078
Andy Wallsff861fb2009-07-03 11:54:40 -030079/*
80 * CX18_CARD_LEADTEK_DVR3100H
81 */
Andy Walls8bb09db2009-06-09 20:47:21 -030082/* Information/confirmation of proper config values provided by Terry Wu */
83static struct zl10353_config leadtek_dvr3100h_demod = {
84 .demod_address = 0x1e >> 1, /* Datasheet suggested straps */
85 .if2 = 45600, /* 4.560 MHz IF from the XC3028 */
86 .parallel_ts = 1, /* Not a serial TS */
87 .no_tuner = 1, /* XC3028 is not behind the gate */
88 .disable_i2c_gate_ctrl = 1, /* Disable the I2C gate */
Hans Verkuil1c1e45d2008-04-28 20:24:33 -030089};
Hans Verkuil1c1e45d2008-04-28 20:24:33 -030090
Andy Wallsff861fb2009-07-03 11:54:40 -030091/*
92 * CX18_CARD_YUAN_MPC718
93 */
94/*
95 * Due to
96 *
97 * 1. an absence of information on how to prgram the MT352
98 * 2. the Linux mt352 module pushing MT352 initialzation off onto us here
99 *
100 * We have to use an init sequence that *you* must extract from the Windows
101 * driver (yuanrap.sys) and which we load as a firmware.
102 *
103 * If someone can provide me with a Zarlink MT352 (Intel CE6352?) Design Manual
104 * with chip programming details, then I can remove this annoyance.
105 */
106static int yuan_mpc718_mt352_reqfw(struct cx18_stream *stream,
107 const struct firmware **fw)
108{
109 struct cx18 *cx = stream->cx;
110 const char *fn = "dvb-cx18-mpc718-mt352.fw";
111 int ret;
112
113 ret = request_firmware(fw, fn, &cx->pci_dev->dev);
114 if (ret)
115 CX18_ERR("Unable to open firmware file %s\n", fn);
116 else {
117 size_t sz = (*fw)->size;
118 if (sz < 2 || sz > 64 || (sz % 2) != 0) {
119 CX18_ERR("Firmware %s has a bad size: %lu bytes\n",
120 fn, (unsigned long) sz);
121 ret = -EILSEQ;
122 release_firmware(*fw);
123 *fw = NULL;
124 }
125 }
126
127 if (ret) {
128 CX18_ERR("The MPC718 board variant with the MT352 DVB-T"
129 "demodualtor will not work without it\n");
130 CX18_ERR("Run 'linux/Documentation/dvb/get_dvb_firmware "
131 "mpc718' if you need the firmware\n");
132 }
133 return ret;
134}
135
136static int yuan_mpc718_mt352_init(struct dvb_frontend *fe)
137{
138 struct cx18_dvb *dvb = container_of(fe->dvb,
139 struct cx18_dvb, dvb_adapter);
Andy Walls754f9962010-12-11 20:38:20 -0300140 struct cx18_stream *stream = dvb->stream;
Andy Wallsff861fb2009-07-03 11:54:40 -0300141 const struct firmware *fw = NULL;
142 int ret;
143 int i;
144 u8 buf[3];
145
146 ret = yuan_mpc718_mt352_reqfw(stream, &fw);
147 if (ret)
148 return ret;
149
150 /* Loop through all the register-value pairs in the firmware file */
151 for (i = 0; i < fw->size; i += 2) {
152 buf[0] = fw->data[i];
153 /* Intercept a few registers we want to set ourselves */
154 switch (buf[0]) {
155 case TRL_NOMINAL_RATE_0:
156 /* Set our custom OFDM bandwidth in the case below */
157 break;
158 case TRL_NOMINAL_RATE_1:
159 /* 6 MHz: 64/7 * 6/8 / 20.48 * 2^16 = 0x55b6.db6 */
160 /* 7 MHz: 64/7 * 7/8 / 20.48 * 2^16 = 0x6400 */
161 /* 8 MHz: 64/7 * 8/8 / 20.48 * 2^16 = 0x7249.249 */
162 buf[1] = 0x72;
163 buf[2] = 0x49;
164 mt352_write(fe, buf, 3);
165 break;
166 case INPUT_FREQ_0:
167 /* Set our custom IF in the case below */
168 break;
169 case INPUT_FREQ_1:
170 /* 4.56 MHz IF: (20.48 - 4.56)/20.48 * 2^14 = 0x31c0 */
171 buf[1] = 0x31;
172 buf[2] = 0xc0;
173 mt352_write(fe, buf, 3);
174 break;
175 default:
176 /* Pass through the register-value pair from the fw */
177 buf[1] = fw->data[i+1];
178 mt352_write(fe, buf, 2);
179 break;
180 }
181 }
182
183 buf[0] = (u8) TUNER_GO;
184 buf[1] = 0x01; /* Go */
185 mt352_write(fe, buf, 2);
186 release_firmware(fw);
187 return 0;
188}
189
190static struct mt352_config yuan_mpc718_mt352_demod = {
191 .demod_address = 0x1e >> 1,
192 .adc_clock = 20480, /* 20.480 MHz */
193 .if2 = 4560, /* 4.560 MHz */
194 .no_tuner = 1, /* XC3028 is not behind the gate */
195 .demod_init = yuan_mpc718_mt352_init,
196};
197
198static struct zl10353_config yuan_mpc718_zl10353_demod = {
199 .demod_address = 0x1e >> 1, /* Datasheet suggested straps */
200 .if2 = 45600, /* 4.560 MHz IF from the XC3028 */
201 .parallel_ts = 1, /* Not a serial TS */
202 .no_tuner = 1, /* XC3028 is not behind the gate */
203 .disable_i2c_gate_ctrl = 1, /* Disable the I2C gate */
204};
205
Alexey Chernova3634362010-10-28 18:12:02 -0300206static struct zl10353_config gotview_dvd3_zl10353_demod = {
207 .demod_address = 0x1e >> 1, /* Datasheet suggested straps */
208 .if2 = 45600, /* 4.560 MHz IF from the XC3028 */
209 .parallel_ts = 1, /* Not a serial TS */
210 .no_tuner = 1, /* XC3028 is not behind the gate */
211 .disable_i2c_gate_ctrl = 1, /* Disable the I2C gate */
212};
213
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300214static int dvb_register(struct cx18_stream *stream);
215
216/* Kernel DVB framework calls this when the feed needs to start.
217 * The CX18 framework should enable the transport DMA handling
218 * and queue processing.
219 */
220static int cx18_dvb_start_feed(struct dvb_demux_feed *feed)
221{
222 struct dvb_demux *demux = feed->demux;
223 struct cx18_stream *stream = (struct cx18_stream *) demux->priv;
Jiri Slabye34d3752010-01-10 05:56:46 -0300224 struct cx18 *cx;
Andy Walls08cf7b22008-06-22 00:04:21 -0300225 int ret;
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300226 u32 v;
227
Jiri Slabye34d3752010-01-10 05:56:46 -0300228 if (!stream)
229 return -EINVAL;
230
231 cx = stream->cx;
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300232 CX18_DEBUG_INFO("Start feed: pid = 0x%x index = %d\n",
233 feed->pid, feed->index);
Andy Walls08cf7b22008-06-22 00:04:21 -0300234
235 mutex_lock(&cx->serialize_lock);
236 ret = cx18_init_on_first_open(cx);
237 mutex_unlock(&cx->serialize_lock);
238 if (ret) {
239 CX18_ERR("Failed to initialize firmware starting DVB feed\n");
240 return ret;
241 }
242 ret = -EINVAL;
243
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300244 switch (cx->card->type) {
245 case CX18_CARD_HVR_1600_ESMT:
246 case CX18_CARD_HVR_1600_SAMSUNG:
Andy Wallsb1526422008-08-30 16:03:44 -0300247 v = cx18_read_reg(cx, CX18_REG_DMUX_NUM_PORT_0_CONTROL);
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300248 v |= 0x00400000; /* Serial Mode */
249 v |= 0x00002000; /* Data Length - Byte */
250 v |= 0x00010000; /* Error - Polarity */
251 v |= 0x00020000; /* Error - Passthru */
252 v |= 0x000c0000; /* Error - Ignore */
Andy Wallsb1526422008-08-30 16:03:44 -0300253 cx18_write_reg(cx, v, CX18_REG_DMUX_NUM_PORT_0_CONTROL);
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300254 break;
255
Andy Walls8bb09db2009-06-09 20:47:21 -0300256 case CX18_CARD_LEADTEK_DVR3100H:
Andy Wallsff861fb2009-07-03 11:54:40 -0300257 case CX18_CARD_YUAN_MPC718:
Alexey Chernova3634362010-10-28 18:12:02 -0300258 case CX18_CARD_GOTVIEW_PCI_DVD3:
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300259 default:
260 /* Assumption - Parallel transport - Signalling
261 * undefined or default.
262 */
263 break;
264 }
265
266 if (!demux->dmx.frontend)
267 return -EINVAL;
268
Andy Walls754f9962010-12-11 20:38:20 -0300269 mutex_lock(&stream->dvb->feedlock);
270 if (stream->dvb->feeding++ == 0) {
Andy Wallsf68d0cf2008-11-05 21:19:15 -0300271 CX18_DEBUG_INFO("Starting Transport DMA\n");
Andy Walls6adb21c2010-01-30 16:20:27 -0300272 mutex_lock(&cx->serialize_lock);
Andy Wallsf68d0cf2008-11-05 21:19:15 -0300273 set_bit(CX18_F_S_STREAMING, &stream->s_flags);
274 ret = cx18_start_v4l2_encode_stream(stream);
275 if (ret < 0) {
276 CX18_DEBUG_INFO("Failed to start Transport DMA\n");
Andy Walls754f9962010-12-11 20:38:20 -0300277 stream->dvb->feeding--;
278 if (stream->dvb->feeding == 0)
Andy Wallsf68d0cf2008-11-05 21:19:15 -0300279 clear_bit(CX18_F_S_STREAMING, &stream->s_flags);
280 }
Andy Walls6adb21c2010-01-30 16:20:27 -0300281 mutex_unlock(&cx->serialize_lock);
Andy Wallsf68d0cf2008-11-05 21:19:15 -0300282 } else
283 ret = 0;
Andy Walls754f9962010-12-11 20:38:20 -0300284 mutex_unlock(&stream->dvb->feedlock);
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300285
286 return ret;
287}
288
289/* Kernel DVB framework calls this when the feed needs to stop. */
290static int cx18_dvb_stop_feed(struct dvb_demux_feed *feed)
291{
292 struct dvb_demux *demux = feed->demux;
293 struct cx18_stream *stream = (struct cx18_stream *)demux->priv;
Jiri Slabye34d3752010-01-10 05:56:46 -0300294 struct cx18 *cx;
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300295 int ret = -EINVAL;
296
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300297 if (stream) {
Jiri Slabye34d3752010-01-10 05:56:46 -0300298 cx = stream->cx;
299 CX18_DEBUG_INFO("Stop feed: pid = 0x%x index = %d\n",
300 feed->pid, feed->index);
301
Andy Walls754f9962010-12-11 20:38:20 -0300302 mutex_lock(&stream->dvb->feedlock);
303 if (--stream->dvb->feeding == 0) {
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300304 CX18_DEBUG_INFO("Stopping Transport DMA\n");
Andy Walls6adb21c2010-01-30 16:20:27 -0300305 mutex_lock(&cx->serialize_lock);
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300306 ret = cx18_stop_v4l2_encode_stream(stream, 0);
Andy Walls6adb21c2010-01-30 16:20:27 -0300307 mutex_unlock(&cx->serialize_lock);
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300308 } else
309 ret = 0;
Andy Walls754f9962010-12-11 20:38:20 -0300310 mutex_unlock(&stream->dvb->feedlock);
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300311 }
312
313 return ret;
314}
315
316int cx18_dvb_register(struct cx18_stream *stream)
317{
318 struct cx18 *cx = stream->cx;
Andy Walls754f9962010-12-11 20:38:20 -0300319 struct cx18_dvb *dvb = stream->dvb;
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300320 struct dvb_adapter *dvb_adapter;
321 struct dvb_demux *dvbdemux;
322 struct dmx_demux *dmx;
323 int ret;
324
325 if (!dvb)
326 return -EINVAL;
327
Andy Walls754f9962010-12-11 20:38:20 -0300328 dvb->enabled = 0;
329 dvb->stream = stream;
330
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300331 ret = dvb_register_adapter(&dvb->dvb_adapter,
332 CX18_DRIVER_NAME,
Andy Walls3d059132009-01-10 21:54:39 -0300333 THIS_MODULE, &cx->pci_dev->dev, adapter_nr);
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300334 if (ret < 0)
335 goto err_out;
336
337 dvb_adapter = &dvb->dvb_adapter;
338
339 dvbdemux = &dvb->demux;
340
341 dvbdemux->priv = (void *)stream;
342
343 dvbdemux->filternum = 256;
344 dvbdemux->feednum = 256;
345 dvbdemux->start_feed = cx18_dvb_start_feed;
346 dvbdemux->stop_feed = cx18_dvb_stop_feed;
347 dvbdemux->dmx.capabilities = (DMX_TS_FILTERING |
348 DMX_SECTION_FILTERING | DMX_MEMORY_BASED_FILTERING);
349 ret = dvb_dmx_init(dvbdemux);
350 if (ret < 0)
351 goto err_dvb_unregister_adapter;
352
353 dmx = &dvbdemux->dmx;
354
355 dvb->hw_frontend.source = DMX_FRONTEND_0;
356 dvb->mem_frontend.source = DMX_MEMORY_FE;
357 dvb->dmxdev.filternum = 256;
358 dvb->dmxdev.demux = dmx;
359
360 ret = dvb_dmxdev_init(&dvb->dmxdev, dvb_adapter);
361 if (ret < 0)
362 goto err_dvb_dmx_release;
363
364 ret = dmx->add_frontend(dmx, &dvb->hw_frontend);
365 if (ret < 0)
366 goto err_dvb_dmxdev_release;
367
368 ret = dmx->add_frontend(dmx, &dvb->mem_frontend);
369 if (ret < 0)
370 goto err_remove_hw_frontend;
371
372 ret = dmx->connect_frontend(dmx, &dvb->hw_frontend);
373 if (ret < 0)
374 goto err_remove_mem_frontend;
375
376 ret = dvb_register(stream);
377 if (ret < 0)
378 goto err_disconnect_frontend;
379
380 dvb_net_init(dvb_adapter, &dvb->dvbnet, dmx);
381
382 CX18_INFO("DVB Frontend registered\n");
Andy Walls22dce182009-11-09 23:55:30 -0300383 CX18_INFO("Registered DVB adapter%d for %s (%d x %d.%02d kB)\n",
Andy Walls754f9962010-12-11 20:38:20 -0300384 stream->dvb->dvb_adapter.num, stream->name,
Andy Walls22dce182009-11-09 23:55:30 -0300385 stream->buffers, stream->buf_size/1024,
386 (stream->buf_size * 100 / 1024) % 100);
Andy Walls6ecd86d2008-12-07 23:30:17 -0300387
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300388 mutex_init(&dvb->feedlock);
389 dvb->enabled = 1;
390 return ret;
391
392err_disconnect_frontend:
393 dmx->disconnect_frontend(dmx);
394err_remove_mem_frontend:
395 dmx->remove_frontend(dmx, &dvb->mem_frontend);
396err_remove_hw_frontend:
397 dmx->remove_frontend(dmx, &dvb->hw_frontend);
398err_dvb_dmxdev_release:
399 dvb_dmxdev_release(&dvb->dmxdev);
400err_dvb_dmx_release:
401 dvb_dmx_release(dvbdemux);
402err_dvb_unregister_adapter:
403 dvb_unregister_adapter(dvb_adapter);
404err_out:
405 return ret;
406}
407
408void cx18_dvb_unregister(struct cx18_stream *stream)
409{
410 struct cx18 *cx = stream->cx;
Andy Walls754f9962010-12-11 20:38:20 -0300411 struct cx18_dvb *dvb = stream->dvb;
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300412 struct dvb_adapter *dvb_adapter;
413 struct dvb_demux *dvbdemux;
414 struct dmx_demux *dmx;
415
416 CX18_INFO("unregister DVB\n");
417
Andy Walls754f9962010-12-11 20:38:20 -0300418 if (dvb == NULL || !dvb->enabled)
419 return;
420
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300421 dvb_adapter = &dvb->dvb_adapter;
422 dvbdemux = &dvb->demux;
423 dmx = &dvbdemux->dmx;
424
425 dmx->close(dmx);
426 dvb_net_release(&dvb->dvbnet);
427 dmx->remove_frontend(dmx, &dvb->mem_frontend);
428 dmx->remove_frontend(dmx, &dvb->hw_frontend);
429 dvb_dmxdev_release(&dvb->dmxdev);
430 dvb_dmx_release(dvbdemux);
431 dvb_unregister_frontend(dvb->fe);
432 dvb_frontend_detach(dvb->fe);
433 dvb_unregister_adapter(dvb_adapter);
434}
435
436/* All the DVB attach calls go here, this function get's modified
Andy Walls8bb09db2009-06-09 20:47:21 -0300437 * for each new card. cx18_dvb_start_feed() will also need changes.
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300438 */
439static int dvb_register(struct cx18_stream *stream)
440{
Andy Walls754f9962010-12-11 20:38:20 -0300441 struct cx18_dvb *dvb = stream->dvb;
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300442 struct cx18 *cx = stream->cx;
443 int ret = 0;
444
445 switch (cx->card->type) {
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300446 case CX18_CARD_HVR_1600_ESMT:
447 case CX18_CARD_HVR_1600_SAMSUNG:
448 dvb->fe = dvb_attach(s5h1409_attach,
449 &hauppauge_hvr1600_config,
450 &cx->i2c_adap[0]);
451 if (dvb->fe != NULL) {
Steven Toth67129472008-05-01 07:23:23 -0300452 dvb_attach(mxl5005s_attach, dvb->fe,
453 &cx->i2c_adap[0],
454 &hauppauge_hvr1600_tuner);
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300455 ret = 0;
456 }
457 break;
Andy Walls8bb09db2009-06-09 20:47:21 -0300458 case CX18_CARD_LEADTEK_DVR3100H:
459 dvb->fe = dvb_attach(zl10353_attach,
460 &leadtek_dvr3100h_demod,
461 &cx->i2c_adap[1]);
462 if (dvb->fe != NULL) {
463 struct dvb_frontend *fe;
464 struct xc2028_config cfg = {
465 .i2c_adap = &cx->i2c_adap[1],
466 .i2c_addr = 0xc2 >> 1,
467 .ctrl = NULL,
468 };
469 static struct xc2028_ctrl ctrl = {
470 .fname = XC2028_DEFAULT_FIRMWARE,
471 .max_len = 64,
472 .demod = XC3028_FE_ZARLINK456,
473 .type = XC2028_AUTO,
474 };
475
476 fe = dvb_attach(xc2028_attach, dvb->fe, &cfg);
477 if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
478 fe->ops.tuner_ops.set_config(fe, &ctrl);
479 }
480 break;
Andy Wallsff861fb2009-07-03 11:54:40 -0300481 case CX18_CARD_YUAN_MPC718:
482 /*
483 * TODO
484 * Apparently, these cards also could instead have a
485 * DiBcom demod supported by one of the db7000 drivers
486 */
487 dvb->fe = dvb_attach(mt352_attach,
488 &yuan_mpc718_mt352_demod,
489 &cx->i2c_adap[1]);
490 if (dvb->fe == NULL)
491 dvb->fe = dvb_attach(zl10353_attach,
492 &yuan_mpc718_zl10353_demod,
493 &cx->i2c_adap[1]);
494 if (dvb->fe != NULL) {
495 struct dvb_frontend *fe;
496 struct xc2028_config cfg = {
497 .i2c_adap = &cx->i2c_adap[1],
498 .i2c_addr = 0xc2 >> 1,
499 .ctrl = NULL,
500 };
501 static struct xc2028_ctrl ctrl = {
502 .fname = XC2028_DEFAULT_FIRMWARE,
503 .max_len = 64,
504 .demod = XC3028_FE_ZARLINK456,
505 .type = XC2028_AUTO,
506 };
507
508 fe = dvb_attach(xc2028_attach, dvb->fe, &cfg);
509 if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
510 fe->ops.tuner_ops.set_config(fe, &ctrl);
511 }
512 break;
Alexey Chernova3634362010-10-28 18:12:02 -0300513 case CX18_CARD_GOTVIEW_PCI_DVD3:
514 dvb->fe = dvb_attach(zl10353_attach,
515 &gotview_dvd3_zl10353_demod,
516 &cx->i2c_adap[1]);
517 if (dvb->fe != NULL) {
518 struct dvb_frontend *fe;
519 struct xc2028_config cfg = {
520 .i2c_adap = &cx->i2c_adap[1],
521 .i2c_addr = 0xc2 >> 1,
522 .ctrl = NULL,
523 };
524 static struct xc2028_ctrl ctrl = {
525 .fname = XC2028_DEFAULT_FIRMWARE,
526 .max_len = 64,
527 .demod = XC3028_FE_ZARLINK456,
528 .type = XC2028_AUTO,
529 };
530
531 fe = dvb_attach(xc2028_attach, dvb->fe, &cfg);
532 if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
533 fe->ops.tuner_ops.set_config(fe, &ctrl);
534 }
535 break;
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300536 default:
537 /* No Digital Tv Support */
538 break;
539 }
540
541 if (dvb->fe == NULL) {
542 CX18_ERR("frontend initialization failed\n");
543 return -1;
544 }
545
Andy Walls8bb09db2009-06-09 20:47:21 -0300546 dvb->fe->callback = cx18_reset_tuner_gpio;
547
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300548 ret = dvb_register_frontend(&dvb->dvb_adapter, dvb->fe);
549 if (ret < 0) {
550 if (dvb->fe->ops.release)
551 dvb->fe->ops.release(dvb->fe);
552 return ret;
553 }
554
Andy Walls8bb09db2009-06-09 20:47:21 -0300555 /*
556 * The firmware seems to enable the TS DMUX clock
557 * under various circumstances. However, since we know we
558 * might use it, let's just turn it on ourselves here.
559 */
560 cx18_write_reg_expect(cx,
561 (CX18_DMUX_CLK_MASK << 16) | CX18_DMUX_CLK_MASK,
562 CX18_CLOCK_ENABLE2,
563 CX18_DMUX_CLK_MASK,
564 (CX18_DMUX_CLK_MASK << 16) | CX18_DMUX_CLK_MASK);
565
Hans Verkuil1c1e45d2008-04-28 20:24:33 -0300566 return ret;
567}