| Linux kernel & device driver programming |
| [ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] |
1 /* 1
2 * cx18 functions for DVB support
3 *
4 * Copyright (c) 2008 Steven Toth <stoth@linu
5 * Copyright (C) 2008 Andy Walls <awalls@rad
6 *
7 * This program is free software; you can red
8 * it under the terms of the GNU General Publ
9 * the Free Software Foundation; either versi
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope th
13 * but WITHOUT ANY WARRANTY; without even the
14 * MERCHANTABILITY or FITNESS FOR A PARTICULA
15 *
16 * GNU General Public License for more detail
17 *
18 * You should have received a copy of the GNU
19 * along with this program; if not, write to
20 * Foundation, Inc., 675 Mass Ave, Cambridge,
21 */
22
23 #include "cx18-version.h"
24 #include "cx18-dvb.h"
25 #include "cx18-io.h"
26 #include "cx18-queue.h"
27 #include "cx18-streams.h"
28 #include "cx18-cards.h"
29 #include "cx18-gpio.h"
30 #include "s5h1409.h"
31 #include "mxl5005s.h"
32 #include "zl10353.h"
33
34 #include <linux/firmware.h>
35 #include "mt352.h"
36 #include "mt352_priv.h"
37 #include "tuner-xc2028.h"
38
39 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
40
41 #define CX18_REG_DMUX_NUM_PORT_0_CONTROL 0xd5a
42 #define CX18_CLOCK_ENABLE2 0xc71
43 #define CX18_DMUX_CLK_MASK 0x008
44
45 /*
46 * CX18_CARD_HVR_1600_ESMT
47 * CX18_CARD_HVR_1600_SAMSUNG
48 */
49
50 static struct mxl5005s_config hauppauge_hvr160
51 .i2c_address = 0xC6 >> 1,
52 .if_freq = IF_FREQ_5380000HZ,
53 .xtal_freq = CRYSTAL_FREQ_160000
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_DISAB
60 .output_load = MXL5005S_IF_OUTPUT_
61 .top = MXL5005S_TOP_25P2,
62 .mod_mode = MXL_DIGITAL_MODE,
63 .if_mode = MXL_ZERO_IF,
64 .AgcMasterByte = 0x00,
65 };
66
67 static struct s5h1409_config hauppauge_hvr1600
68 .demod_address = 0x32 >> 1,
69 .output_mode = S5H1409_SERIAL_OUTPUT
70 .gpio = S5H1409_GPIO_ON,
71 .qam_if = 44000,
72 .inversion = S5H1409_INVERSION_OFF
73 .status_mode = S5H1409_DEMODLOCKING,
74 .mpeg_timing = S5H1409_MPEGTIMING_CO
75 };
76
77 /*
78 * CX18_CARD_LEADTEK_DVR3100H
79 */
80 /* Information/confirmation of proper config v
81 static struct zl10353_config leadtek_dvr3100h_
82 .demod_address = 0x1e >> 1, /*
83 .if2 = 45600, /*
84 .parallel_ts = 1, /*
85 .no_tuner = 1, /*
86 .disable_i2c_gate_ctrl = 1, /*
87 };
88
89 /*
90 * CX18_CARD_YUAN_MPC718
91 */
92 /*
93 * Due to
94 *
95 * 1. an absence of information on how to prgr
96 * 2. the Linux mt352 module pushing MT352 ini
97 *
98 * We have to use an init sequence that *you*
99 * driver (yuanrap.sys) and which we load as a
100 *
101 * If someone can provide me with a Zarlink MT
102 * with chip programming details, then I can r
103 */
104 static int yuan_mpc718_mt352_reqfw(struct cx18
105 const struc
106 {
107 struct cx18 *cx = stream->cx;
108 const char *fn = "dvb-cx18-mpc718-mt35
109 int ret;
110
111 ret = request_firmware(fw, fn, &cx->pc
112 if (ret)
113 CX18_ERR("Unable to open firmw
114 else {
115 size_t sz = (*fw)->size;
116 if (sz < 2 || sz > 64 || (sz %
117 CX18_ERR("Firmware %s
118 fn, (unsigned
119 ret = -EILSEQ;
120 release_firmware(*fw);
121 *fw = NULL;
122 }
123 }
124
125 if (ret) {
126 CX18_ERR("The MPC718 board var
127 "demodualtor will no
128 CX18_ERR("Run 'linux/Documenta
129 "mpc718' if you need
130 }
131 return ret;
132 }
133
134 static int yuan_mpc718_mt352_init(struct dvb_f
135 {
136 struct cx18_dvb *dvb = container_of(fe
137 st
138 struct cx18_stream *stream = container
139 const struct firmware *fw = NULL;
140 int ret;
141 int i;
142 u8 buf[3];
143
144 ret = yuan_mpc718_mt352_reqfw(stream,
145 if (ret)
146 return ret;
147
148 /* Loop through all the register-value
149 for (i = 0; i < fw->size; i += 2) {
150 buf[0] = fw->data[i];
151 /* Intercept a few registers w
152 switch (buf[0]) {
153 case TRL_NOMINAL_RATE_0:
154 /* Set our custom OFDM
155 break;
156 case TRL_NOMINAL_RATE_1:
157 /* 6 MHz: 64/7 * 6/8 /
158 /* 7 MHz: 64/7 * 7/8 /
159 /* 8 MHz: 64/7 * 8/8 /
160 buf[1] = 0x72;
161 buf[2] = 0x49;
162 mt352_write(fe, buf, 3
163 break;
164 case INPUT_FREQ_0:
165 /* Set our custom IF i
166 break;
167 case INPUT_FREQ_1:
168 /* 4.56 MHz IF: (20.48
169 buf[1] = 0x31;
170 buf[2] = 0xc0;
171 mt352_write(fe, buf, 3
172 break;
173 default:
174 /* Pass through the re
175 buf[1] = fw->data[i+1]
176 mt352_write(fe, buf, 2
177 break;
178 }
179 }
180
181 buf[0] = (u8) TUNER_GO;
182 buf[1] = 0x01; /* Go */
183 mt352_write(fe, buf, 2);
184 release_firmware(fw);
185 return 0;
186 }
187
188 static struct mt352_config yuan_mpc718_mt352_d
189 .demod_address = 0x1e >> 1,
190 .adc_clock = 20480, /* 20.480
191 .if2 = 4560, /* 4.560
192 .no_tuner = 1, /* XC3028
193 .demod_init = yuan_mpc718_mt352_ini
194 };
195
196 static struct zl10353_config yuan_mpc718_zl103
197 .demod_address = 0x1e >> 1, /*
198 .if2 = 45600, /*
199 .parallel_ts = 1, /*
200 .no_tuner = 1, /*
201 .disable_i2c_gate_ctrl = 1, /*
202 };
203
204 static int dvb_register(struct cx18_stream *st
205
206 /* Kernel DVB framework calls this when the fe
207 * The CX18 framework should enable the transp
208 * and queue processing.
209 */
210 static int cx18_dvb_start_feed(struct dvb_demu
211 {
212 struct dvb_demux *demux = feed->demux;
213 struct cx18_stream *stream = (struct c
214 struct cx18 *cx = stream->cx;
215 int ret;
216 u32 v;
217
218 CX18_DEBUG_INFO("Start feed: pid = 0x%
219 feed->pid, feed->index
220
221 mutex_lock(&cx->serialize_lock);
222 ret = cx18_init_on_first_open(cx);
223 mutex_unlock(&cx->serialize_lock);
224 if (ret) {
225 CX18_ERR("Failed to initialize
226 return ret;
227 }
228 ret = -EINVAL;
229
230 switch (cx->card->type) {
231 case CX18_CARD_HVR_1600_ESMT:
232 case CX18_CARD_HVR_1600_SAMSUNG:
233 v = cx18_read_reg(cx, CX18_REG
234 v |= 0x00400000; /* Serial Mod
235 v |= 0x00002000; /* Data Lengt
236 v |= 0x00010000; /* Error - Po
237 v |= 0x00020000; /* Error - Pa
238 v |= 0x000c0000; /* Error - Ig
239 cx18_write_reg(cx, v, CX18_REG
240 break;
241
242 case CX18_CARD_LEADTEK_DVR3100H:
243 case CX18_CARD_YUAN_MPC718:
244 default:
245 /* Assumption - Parallel trans
246 * undefined or default.
247 */
248 break;
249 }
250
251 if (!demux->dmx.frontend)
252 return -EINVAL;
253
254 if (!stream)
255 return -EINVAL;
256
257 mutex_lock(&stream->dvb.feedlock);
258 if (stream->dvb.feeding++ == 0) {
259 CX18_DEBUG_INFO("Starting Tran
260 set_bit(CX18_F_S_STREAMING, &s
261 ret = cx18_start_v4l2_encode_s
262 if (ret < 0) {
263 CX18_DEBUG_INFO("Faile
264 stream->dvb.feeding--;
265 if (stream->dvb.feedin
266 clear_bit(CX18
267 }
268 } else
269 ret = 0;
270 mutex_unlock(&stream->dvb.feedlock);
271
272 return ret;
273 }
274
275 /* Kernel DVB framework calls this when the fe
276 static int cx18_dvb_stop_feed(struct dvb_demux
277 {
278 struct dvb_demux *demux = feed->demux;
279 struct cx18_stream *stream = (struct c
280 struct cx18 *cx = stream->cx;
281 int ret = -EINVAL;
282
283 CX18_DEBUG_INFO("Stop feed: pid = 0x%x
284 feed->pid, feed->index
285
286 if (stream) {
287 mutex_lock(&stream->dvb.feedlo
288 if (--stream->dvb.feeding == 0
289 CX18_DEBUG_INFO("Stopp
290 ret = cx18_stop_v4l2_e
291 } else
292 ret = 0;
293 mutex_unlock(&stream->dvb.feed
294 }
295
296 return ret;
297 }
298
299 int cx18_dvb_register(struct cx18_stream *stre
300 {
301 struct cx18 *cx = stream->cx;
302 struct cx18_dvb *dvb = &stream->dvb;
303 struct dvb_adapter *dvb_adapter;
304 struct dvb_demux *dvbdemux;
305 struct dmx_demux *dmx;
306 int ret;
307
308 if (!dvb)
309 return -EINVAL;
310
311 ret = dvb_register_adapter(&dvb->dvb_a
312 CX18_DRIVER_NAME,
313 THIS_MODULE, &cx->pci_
314 if (ret < 0)
315 goto err_out;
316
317 dvb_adapter = &dvb->dvb_adapter;
318
319 dvbdemux = &dvb->demux;
320
321 dvbdemux->priv = (void *)stream;
322
323 dvbdemux->filternum = 256;
324 dvbdemux->feednum = 256;
325 dvbdemux->start_feed = cx18_dvb_start_
326 dvbdemux->stop_feed = cx18_dvb_stop_fe
327 dvbdemux->dmx.capabilities = (DMX_TS_F
328 DMX_SECTION_FILTERING | DMX_ME
329 ret = dvb_dmx_init(dvbdemux);
330 if (ret < 0)
331 goto err_dvb_unregister_adapte
332
333 dmx = &dvbdemux->dmx;
334
335 dvb->hw_frontend.source = DMX_FRONTEND
336 dvb->mem_frontend.source = DMX_MEMORY_
337 dvb->dmxdev.filternum = 256;
338 dvb->dmxdev.demux = dmx;
339
340 ret = dvb_dmxdev_init(&dvb->dmxdev, dv
341 if (ret < 0)
342 goto err_dvb_dmx_release;
343
344 ret = dmx->add_frontend(dmx, &dvb->hw_
345 if (ret < 0)
346 goto err_dvb_dmxdev_release;
347
348 ret = dmx->add_frontend(dmx, &dvb->mem
349 if (ret < 0)
350 goto err_remove_hw_frontend;
351
352 ret = dmx->connect_frontend(dmx, &dvb-
353 if (ret < 0)
354 goto err_remove_mem_frontend;
355
356 ret = dvb_register(stream);
357 if (ret < 0)
358 goto err_disconnect_frontend;
359
360 dvb_net_init(dvb_adapter, &dvb->dvbnet
361
362 CX18_INFO("DVB Frontend registered\n")
363 CX18_INFO("Registered DVB adapter%d fo
364 stream->dvb.dvb_adapter.num,
365 stream->buffers, stream->buf
366
367 mutex_init(&dvb->feedlock);
368 dvb->enabled = 1;
369 return ret;
370
371 err_disconnect_frontend:
372 dmx->disconnect_frontend(dmx);
373 err_remove_mem_frontend:
374 dmx->remove_frontend(dmx, &dvb->mem_fr
375 err_remove_hw_frontend:
376 dmx->remove_frontend(dmx, &dvb->hw_fro
377 err_dvb_dmxdev_release:
378 dvb_dmxdev_release(&dvb->dmxdev);
379 err_dvb_dmx_release:
380 dvb_dmx_release(dvbdemux);
381 err_dvb_unregister_adapter:
382 dvb_unregister_adapter(dvb_adapter);
383 err_out:
384 return ret;
385 }
386
387 void cx18_dvb_unregister(struct cx18_stream *s
388 {
389 struct cx18 *cx = stream->cx;
390 struct cx18_dvb *dvb = &stream->dvb;
391 struct dvb_adapter *dvb_adapter;
392 struct dvb_demux *dvbdemux;
393 struct dmx_demux *dmx;
394
395 CX18_INFO("unregister DVB\n");
396
397 dvb_adapter = &dvb->dvb_adapter;
398 dvbdemux = &dvb->demux;
399 dmx = &dvbdemux->dmx;
400
401 dmx->close(dmx);
402 dvb_net_release(&dvb->dvbnet);
403 dmx->remove_frontend(dmx, &dvb->mem_fr
404 dmx->remove_frontend(dmx, &dvb->hw_fro
405 dvb_dmxdev_release(&dvb->dmxdev);
406 dvb_dmx_release(dvbdemux);
407 dvb_unregister_frontend(dvb->fe);
408 dvb_frontend_detach(dvb->fe);
409 dvb_unregister_adapter(dvb_adapter);
410 }
411
412 /* All the DVB attach calls go here, this func
413 * for each new card. cx18_dvb_start_feed() wi
414 */
415 static int dvb_register(struct cx18_stream *st
416 {
417 struct cx18_dvb *dvb = &stream->dvb;
418 struct cx18 *cx = stream->cx;
419 int ret = 0;
420
421 switch (cx->card->type) {
422 case CX18_CARD_HVR_1600_ESMT:
423 case CX18_CARD_HVR_1600_SAMSUNG:
424 dvb->fe = dvb_attach(s5h1409_a
425 &hauppauge_hvr1600_con
426 &cx->i2c_adap[0]);
427 if (dvb->fe != NULL) {
428 dvb_attach(mxl5005s_at
429 &cx->i2c_adap[
430 &hauppauge_hvr
431 ret = 0;
432 }
433 break;
434 case CX18_CARD_LEADTEK_DVR3100H:
435 dvb->fe = dvb_attach(zl10353_a
436 &leadtek_
437 &cx->i2c_
438 if (dvb->fe != NULL) {
439 struct dvb_frontend *f
440 struct xc2028_config c
441 .i2c_adap = &c
442 .i2c_addr = 0x
443 .ctrl = NULL,
444 };
445 static struct xc2028_c
446 .fname = XC2
447 .max_len = 64,
448 .demod = XC3
449 .type = XC2
450 };
451
452 fe = dvb_attach(xc2028
453 if (fe != NULL && fe->
454 fe->ops.tuner_
455 }
456 break;
457 case CX18_CARD_YUAN_MPC718:
458 /*
459 * TODO
460 * Apparently, these cards als
461 * DiBcom demod supported by o
462 */
463 dvb->fe = dvb_attach(mt352_att
464 &yuan_mpc
465 &cx->i2c_
466 if (dvb->fe == NULL)
467 dvb->fe = dvb_attach(z
468 &
469 &
470 if (dvb->fe != NULL) {
471 struct dvb_frontend *f
472 struct xc2028_config c
473 .i2c_adap = &c
474 .i2c_addr = 0x
475 .ctrl = NULL,
476 };
477 static struct xc2028_c
478 .fname = XC2
479 .max_len = 64,
480 .demod = XC3
481 .type = XC2
482 };
483
484 fe = dvb_attach(xc2028
485 if (fe != NULL && fe->
486 fe->ops.tuner_
487 }
488 break;
489 default:
490 /* No Digital Tv Support */
491 break;
492 }
493
494 if (dvb->fe == NULL) {
495 CX18_ERR("frontend initializat
496 return -1;
497 }
498
499 dvb->fe->callback = cx18_reset_tuner_g
500
501 ret = dvb_register_frontend(&dvb->dvb_
502 if (ret < 0) {
503 if (dvb->fe->ops.release)
504 dvb->fe->ops.release(d
505 return ret;
506 }
507
508 /*
509 * The firmware seems to enable the TS
510 * under various circumstances. Howev
511 * might use it, let's just turn it on
512 */
513 cx18_write_reg_expect(cx,
514 (CX18_DMUX_CLK_M
515 CX18_CLOCK_ENABL
516 CX18_DMUX_CLK_MA
517 (CX18_DMUX_CLK_M
518
519 return ret;
520 }
521
| This page was automatically generated by the LXR engine. |