Linux 4.19.133
[linux/fpc-iii.git] / drivers / media / usb / cx231xx / cx231xx-dvb.c
blob89357cb08b1abf88353f01efbdc730a0af9afe17
1 /*
2 DVB device driver for cx231xx
4 Copyright (C) 2008 <srinivasa.deevi at conexant dot com>
5 Based on em28xx driver
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.
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 GNU General Public License for more details.
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.
22 #include "cx231xx.h"
23 #include <linux/kernel.h>
24 #include <linux/slab.h>
26 #include <media/dvbdev.h>
27 #include <media/dmxdev.h>
28 #include <media/dvb_demux.h>
29 #include <media/dvb_net.h>
30 #include <media/dvb_frontend.h>
31 #include <media/v4l2-common.h>
32 #include <media/tuner.h>
34 #include "xc5000.h"
35 #include "s5h1432.h"
36 #include "tda18271.h"
37 #include "s5h1411.h"
38 #include "lgdt3305.h"
39 #include "si2165.h"
40 #include "si2168.h"
41 #include "mb86a20s.h"
42 #include "si2157.h"
43 #include "lgdt3306a.h"
44 #include "r820t.h"
45 #include "mn88473.h"
47 MODULE_DESCRIPTION("driver for cx231xx based DVB cards");
48 MODULE_AUTHOR("Srinivasa Deevi <srinivasa.deevi@conexant.com>");
49 MODULE_LICENSE("GPL");
51 static unsigned int debug;
52 module_param(debug, int, 0644);
53 MODULE_PARM_DESC(debug, "enable debug messages [dvb]");
55 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
57 #define CX231XX_DVB_NUM_BUFS 5
58 #define CX231XX_DVB_MAX_PACKETSIZE 564
59 #define CX231XX_DVB_MAX_PACKETS 64
60 #define CX231XX_DVB_MAX_FRONTENDS 2
62 struct cx231xx_dvb {
63 struct dvb_frontend *frontend[CX231XX_DVB_MAX_FRONTENDS];
65 /* feed count management */
66 struct mutex lock;
67 int nfeeds;
69 /* general boilerplate stuff */
70 struct dvb_adapter adapter;
71 struct dvb_demux demux;
72 struct dmxdev dmxdev;
73 struct dmx_frontend fe_hw;
74 struct dmx_frontend fe_mem;
75 struct dvb_net net;
76 struct i2c_client *i2c_client_demod[2];
77 struct i2c_client *i2c_client_tuner;
80 static struct s5h1432_config dvico_s5h1432_config = {
81 .output_mode = S5H1432_SERIAL_OUTPUT,
82 .gpio = S5H1432_GPIO_ON,
83 .qam_if = S5H1432_IF_4000,
84 .vsb_if = S5H1432_IF_4000,
85 .inversion = S5H1432_INVERSION_OFF,
86 .status_mode = S5H1432_DEMODLOCKING,
87 .mpeg_timing = S5H1432_MPEGTIMING_CONTINUOUS_NONINVERTING_CLOCK,
90 static struct tda18271_std_map cnxt_rde253s_tda18271_std_map = {
91 .dvbt_6 = { .if_freq = 4000, .agc_mode = 3, .std = 4,
92 .if_lvl = 1, .rfagc_top = 0x37, },
93 .dvbt_7 = { .if_freq = 4000, .agc_mode = 3, .std = 5,
94 .if_lvl = 1, .rfagc_top = 0x37, },
95 .dvbt_8 = { .if_freq = 4000, .agc_mode = 3, .std = 6,
96 .if_lvl = 1, .rfagc_top = 0x37, },
99 static struct tda18271_std_map mb86a20s_tda18271_config = {
100 .dvbt_6 = { .if_freq = 4000, .agc_mode = 3, .std = 4,
101 .if_lvl = 0, .rfagc_top = 0x37, },
104 static struct tda18271_config cnxt_rde253s_tunerconfig = {
105 .std_map = &cnxt_rde253s_tda18271_std_map,
106 .gate = TDA18271_GATE_ANALOG,
109 static struct s5h1411_config tda18271_s5h1411_config = {
110 .output_mode = S5H1411_SERIAL_OUTPUT,
111 .gpio = S5H1411_GPIO_OFF,
112 .vsb_if = S5H1411_IF_3250,
113 .qam_if = S5H1411_IF_4000,
114 .inversion = S5H1411_INVERSION_ON,
115 .status_mode = S5H1411_DEMODLOCKING,
116 .mpeg_timing = S5H1411_MPEGTIMING_CONTINUOUS_NONINVERTING_CLOCK,
118 static struct s5h1411_config xc5000_s5h1411_config = {
119 .output_mode = S5H1411_SERIAL_OUTPUT,
120 .gpio = S5H1411_GPIO_OFF,
121 .vsb_if = S5H1411_IF_3250,
122 .qam_if = S5H1411_IF_3250,
123 .inversion = S5H1411_INVERSION_OFF,
124 .status_mode = S5H1411_DEMODLOCKING,
125 .mpeg_timing = S5H1411_MPEGTIMING_CONTINUOUS_NONINVERTING_CLOCK,
128 static struct lgdt3305_config hcw_lgdt3305_config = {
129 .i2c_addr = 0x0e,
130 .mpeg_mode = LGDT3305_MPEG_SERIAL,
131 .tpclk_edge = LGDT3305_TPCLK_FALLING_EDGE,
132 .tpvalid_polarity = LGDT3305_TP_VALID_HIGH,
133 .deny_i2c_rptr = 1,
134 .spectral_inversion = 1,
135 .qam_if_khz = 4000,
136 .vsb_if_khz = 3250,
139 static struct tda18271_std_map hauppauge_tda18271_std_map = {
140 .atsc_6 = { .if_freq = 3250, .agc_mode = 3, .std = 4,
141 .if_lvl = 1, .rfagc_top = 0x58, },
142 .qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 5,
143 .if_lvl = 1, .rfagc_top = 0x58, },
146 static struct tda18271_config hcw_tda18271_config = {
147 .std_map = &hauppauge_tda18271_std_map,
148 .gate = TDA18271_GATE_DIGITAL,
151 static const struct mb86a20s_config pv_mb86a20s_config = {
152 .demod_address = 0x10,
153 .is_serial = true,
156 static struct tda18271_config pv_tda18271_config = {
157 .std_map = &mb86a20s_tda18271_config,
158 .gate = TDA18271_GATE_DIGITAL,
159 .small_i2c = TDA18271_03_BYTE_CHUNK_INIT,
162 static struct lgdt3306a_config hauppauge_955q_lgdt3306a_config = {
163 .qam_if_khz = 4000,
164 .vsb_if_khz = 3250,
165 .spectral_inversion = 1,
166 .mpeg_mode = LGDT3306A_MPEG_SERIAL,
167 .tpclk_edge = LGDT3306A_TPCLK_RISING_EDGE,
168 .tpvalid_polarity = LGDT3306A_TP_VALID_HIGH,
169 .xtalMHz = 25,
172 static struct r820t_config astrometa_t2hybrid_r820t_config = {
173 .i2c_addr = 0x3a, /* 0x74 >> 1 */
174 .xtal = 16000000,
175 .rafael_chip = CHIP_R828D,
176 .max_i2c_msg_len = 2,
179 static inline void print_err_status(struct cx231xx *dev, int packet, int status)
181 char *errmsg = "Unknown";
183 switch (status) {
184 case -ENOENT:
185 errmsg = "unlinked synchronously";
186 break;
187 case -ECONNRESET:
188 errmsg = "unlinked asynchronously";
189 break;
190 case -ENOSR:
191 errmsg = "Buffer error (overrun)";
192 break;
193 case -EPIPE:
194 errmsg = "Stalled (device not responding)";
195 break;
196 case -EOVERFLOW:
197 errmsg = "Babble (bad cable?)";
198 break;
199 case -EPROTO:
200 errmsg = "Bit-stuff error (bad cable?)";
201 break;
202 case -EILSEQ:
203 errmsg = "CRC/Timeout (could be anything)";
204 break;
205 case -ETIME:
206 errmsg = "Device does not respond";
207 break;
209 if (packet < 0) {
210 dev_dbg(dev->dev,
211 "URB status %d [%s].\n", status, errmsg);
212 } else {
213 dev_dbg(dev->dev,
214 "URB packet %d, status %d [%s].\n",
215 packet, status, errmsg);
219 static inline int dvb_isoc_copy(struct cx231xx *dev, struct urb *urb)
221 int i;
223 if (!dev)
224 return 0;
226 if (dev->state & DEV_DISCONNECTED)
227 return 0;
229 if (urb->status < 0) {
230 print_err_status(dev, -1, urb->status);
231 if (urb->status == -ENOENT)
232 return 0;
235 for (i = 0; i < urb->number_of_packets; i++) {
236 int status = urb->iso_frame_desc[i].status;
238 if (status < 0) {
239 print_err_status(dev, i, status);
240 if (urb->iso_frame_desc[i].status != -EPROTO)
241 continue;
244 dvb_dmx_swfilter(&dev->dvb->demux,
245 urb->transfer_buffer +
246 urb->iso_frame_desc[i].offset,
247 urb->iso_frame_desc[i].actual_length);
250 return 0;
253 static inline int dvb_bulk_copy(struct cx231xx *dev, struct urb *urb)
255 if (!dev)
256 return 0;
258 if (dev->state & DEV_DISCONNECTED)
259 return 0;
261 if (urb->status < 0) {
262 print_err_status(dev, -1, urb->status);
263 if (urb->status == -ENOENT)
264 return 0;
267 /* Feed the transport payload into the kernel demux */
268 dvb_dmx_swfilter(&dev->dvb->demux,
269 urb->transfer_buffer, urb->actual_length);
271 return 0;
274 static int start_streaming(struct cx231xx_dvb *dvb)
276 int rc;
277 struct cx231xx *dev = dvb->adapter.priv;
279 if (dev->USE_ISO) {
280 dev_dbg(dev->dev, "DVB transfer mode is ISO.\n");
281 cx231xx_set_alt_setting(dev, INDEX_TS1, 5);
282 rc = cx231xx_set_mode(dev, CX231XX_DIGITAL_MODE);
283 if (rc < 0)
284 return rc;
285 dev->mode_tv = 1;
286 return cx231xx_init_isoc(dev, CX231XX_DVB_MAX_PACKETS,
287 CX231XX_DVB_NUM_BUFS,
288 dev->ts1_mode.max_pkt_size,
289 dvb_isoc_copy);
290 } else {
291 dev_dbg(dev->dev, "DVB transfer mode is BULK.\n");
292 cx231xx_set_alt_setting(dev, INDEX_TS1, 0);
293 rc = cx231xx_set_mode(dev, CX231XX_DIGITAL_MODE);
294 if (rc < 0)
295 return rc;
296 dev->mode_tv = 1;
297 return cx231xx_init_bulk(dev, CX231XX_DVB_MAX_PACKETS,
298 CX231XX_DVB_NUM_BUFS,
299 dev->ts1_mode.max_pkt_size,
300 dvb_bulk_copy);
305 static int stop_streaming(struct cx231xx_dvb *dvb)
307 struct cx231xx *dev = dvb->adapter.priv;
309 if (dev->USE_ISO)
310 cx231xx_uninit_isoc(dev);
311 else
312 cx231xx_uninit_bulk(dev);
314 cx231xx_set_mode(dev, CX231XX_SUSPEND);
316 return 0;
319 static int start_feed(struct dvb_demux_feed *feed)
321 struct dvb_demux *demux = feed->demux;
322 struct cx231xx_dvb *dvb = demux->priv;
323 int rc, ret;
325 if (!demux->dmx.frontend)
326 return -EINVAL;
328 mutex_lock(&dvb->lock);
329 dvb->nfeeds++;
330 rc = dvb->nfeeds;
332 if (dvb->nfeeds == 1) {
333 ret = start_streaming(dvb);
334 if (ret < 0)
335 rc = ret;
338 mutex_unlock(&dvb->lock);
339 return rc;
342 static int stop_feed(struct dvb_demux_feed *feed)
344 struct dvb_demux *demux = feed->demux;
345 struct cx231xx_dvb *dvb = demux->priv;
346 int err = 0;
348 mutex_lock(&dvb->lock);
349 dvb->nfeeds--;
351 if (0 == dvb->nfeeds)
352 err = stop_streaming(dvb);
354 mutex_unlock(&dvb->lock);
355 return err;
358 /* ------------------------------------------------------------------ */
359 static int cx231xx_dvb_bus_ctrl(struct dvb_frontend *fe, int acquire)
361 struct cx231xx *dev = fe->dvb->priv;
363 if (acquire)
364 return cx231xx_set_mode(dev, CX231XX_DIGITAL_MODE);
365 else
366 return cx231xx_set_mode(dev, CX231XX_SUSPEND);
369 /* ------------------------------------------------------------------ */
371 static struct xc5000_config cnxt_rde250_tunerconfig = {
372 .i2c_address = 0x61,
373 .if_khz = 4000,
375 static struct xc5000_config cnxt_rdu250_tunerconfig = {
376 .i2c_address = 0x61,
377 .if_khz = 3250,
380 /* ------------------------------------------------------------------ */
381 #if 0
382 static int attach_xc5000(u8 addr, struct cx231xx *dev)
385 struct dvb_frontend *fe;
386 struct xc5000_config cfg;
388 memset(&cfg, 0, sizeof(cfg));
389 cfg.i2c_adap = cx231xx_get_i2c_adap(dev, dev->board.tuner_i2c_master);
390 cfg.i2c_addr = addr;
392 if (!dev->dvb->frontend[0]) {
393 dev_err(dev->dev, "%s/2: dvb frontend not attached. Can't attach xc5000\n",
394 dev->name);
395 return -EINVAL;
398 fe = dvb_attach(xc5000_attach, dev->dvb->frontend[0], &cfg);
399 if (!fe) {
400 dev_err(dev->dev, "%s/2: xc5000 attach failed\n", dev->name);
401 dvb_frontend_detach(dev->dvb->frontend[0]);
402 dev->dvb->frontend[0] = NULL;
403 return -EINVAL;
406 dev_info(dev->dev, "%s/2: xc5000 attached\n", dev->name);
408 return 0;
410 #endif
412 int cx231xx_set_analog_freq(struct cx231xx *dev, u32 freq)
414 if (dev->dvb && dev->dvb->frontend[0]) {
416 struct dvb_tuner_ops *dops = &dev->dvb->frontend[0]->ops.tuner_ops;
418 if (dops->set_analog_params != NULL) {
419 struct analog_parameters params;
421 params.frequency = freq;
422 params.std = dev->norm;
423 params.mode = 0; /* 0- Air; 1 - cable */
424 /*params.audmode = ; */
426 /* Set the analog parameters to set the frequency */
427 dops->set_analog_params(dev->dvb->frontend[0], &params);
432 return 0;
435 int cx231xx_reset_analog_tuner(struct cx231xx *dev)
437 int status = 0;
439 if (dev->dvb && dev->dvb->frontend[0]) {
441 struct dvb_tuner_ops *dops = &dev->dvb->frontend[0]->ops.tuner_ops;
443 if (dops->init != NULL && !dev->xc_fw_load_done) {
445 dev_dbg(dev->dev,
446 "Reloading firmware for XC5000\n");
447 status = dops->init(dev->dvb->frontend[0]);
448 if (status == 0) {
449 dev->xc_fw_load_done = 1;
450 dev_dbg(dev->dev,
451 "XC5000 firmware download completed\n");
452 } else {
453 dev->xc_fw_load_done = 0;
454 dev_dbg(dev->dev,
455 "XC5000 firmware download failed !!!\n");
461 return status;
464 /* ------------------------------------------------------------------ */
466 static int register_dvb(struct cx231xx_dvb *dvb,
467 struct module *module,
468 struct cx231xx *dev, struct device *device)
470 int result;
472 mutex_init(&dvb->lock);
475 /* register adapter */
476 result = dvb_register_adapter(&dvb->adapter, dev->name, module, device,
477 adapter_nr);
478 if (result < 0) {
479 dev_warn(dev->dev,
480 "%s: dvb_register_adapter failed (errno = %d)\n",
481 dev->name, result);
482 goto fail_adapter;
484 dvb_register_media_controller(&dvb->adapter, dev->media_dev);
486 /* Ensure all frontends negotiate bus access */
487 dvb->frontend[0]->ops.ts_bus_ctrl = cx231xx_dvb_bus_ctrl;
488 if (dvb->frontend[1])
489 dvb->frontend[1]->ops.ts_bus_ctrl = cx231xx_dvb_bus_ctrl;
491 dvb->adapter.priv = dev;
493 /* register frontend */
494 result = dvb_register_frontend(&dvb->adapter, dvb->frontend[0]);
495 if (result < 0) {
496 dev_warn(dev->dev,
497 "%s: dvb_register_frontend failed (errno = %d)\n",
498 dev->name, result);
499 goto fail_frontend0;
502 if (dvb->frontend[1]) {
503 result = dvb_register_frontend(&dvb->adapter, dvb->frontend[1]);
504 if (result < 0) {
505 dev_warn(dev->dev,
506 "%s: 2nd dvb_register_frontend failed (errno = %d)\n",
507 dev->name, result);
508 goto fail_frontend1;
511 /* MFE lock */
512 dvb->adapter.mfe_shared = 1;
515 /* register demux stuff */
516 dvb->demux.dmx.capabilities =
517 DMX_TS_FILTERING | DMX_SECTION_FILTERING |
518 DMX_MEMORY_BASED_FILTERING;
519 dvb->demux.priv = dvb;
520 dvb->demux.filternum = 256;
521 dvb->demux.feednum = 256;
522 dvb->demux.start_feed = start_feed;
523 dvb->demux.stop_feed = stop_feed;
525 result = dvb_dmx_init(&dvb->demux);
526 if (result < 0) {
527 dev_warn(dev->dev,
528 "%s: dvb_dmx_init failed (errno = %d)\n",
529 dev->name, result);
530 goto fail_dmx;
533 dvb->dmxdev.filternum = 256;
534 dvb->dmxdev.demux = &dvb->demux.dmx;
535 dvb->dmxdev.capabilities = 0;
536 result = dvb_dmxdev_init(&dvb->dmxdev, &dvb->adapter);
537 if (result < 0) {
538 dev_warn(dev->dev,
539 "%s: dvb_dmxdev_init failed (errno = %d)\n",
540 dev->name, result);
541 goto fail_dmxdev;
544 dvb->fe_hw.source = DMX_FRONTEND_0;
545 result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_hw);
546 if (result < 0) {
547 dev_warn(dev->dev,
548 "%s: add_frontend failed (DMX_FRONTEND_0, errno = %d)\n",
549 dev->name, result);
550 goto fail_fe_hw;
553 dvb->fe_mem.source = DMX_MEMORY_FE;
554 result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_mem);
555 if (result < 0) {
556 dev_warn(dev->dev,
557 "%s: add_frontend failed (DMX_MEMORY_FE, errno = %d)\n",
558 dev->name, result);
559 goto fail_fe_mem;
562 result = dvb->demux.dmx.connect_frontend(&dvb->demux.dmx, &dvb->fe_hw);
563 if (result < 0) {
564 dev_warn(dev->dev,
565 "%s: connect_frontend failed (errno = %d)\n",
566 dev->name, result);
567 goto fail_fe_conn;
570 /* register network adapter */
571 dvb_net_init(&dvb->adapter, &dvb->net, &dvb->demux.dmx);
572 result = dvb_create_media_graph(&dvb->adapter,
573 dev->tuner_type == TUNER_ABSENT);
574 if (result < 0)
575 goto fail_create_graph;
577 return 0;
579 fail_create_graph:
580 dvb_net_release(&dvb->net);
581 fail_fe_conn:
582 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
583 fail_fe_mem:
584 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
585 fail_fe_hw:
586 dvb_dmxdev_release(&dvb->dmxdev);
587 fail_dmxdev:
588 dvb_dmx_release(&dvb->demux);
589 fail_dmx:
590 if (dvb->frontend[1])
591 dvb_unregister_frontend(dvb->frontend[1]);
592 dvb_unregister_frontend(dvb->frontend[0]);
593 fail_frontend1:
594 if (dvb->frontend[1])
595 dvb_frontend_detach(dvb->frontend[1]);
596 fail_frontend0:
597 dvb_frontend_detach(dvb->frontend[0]);
598 dvb_unregister_adapter(&dvb->adapter);
599 fail_adapter:
600 return result;
603 static void unregister_dvb(struct cx231xx_dvb *dvb)
605 dvb_net_release(&dvb->net);
606 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
607 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
608 dvb_dmxdev_release(&dvb->dmxdev);
609 dvb_dmx_release(&dvb->demux);
610 if (dvb->frontend[1])
611 dvb_unregister_frontend(dvb->frontend[1]);
612 dvb_unregister_frontend(dvb->frontend[0]);
613 if (dvb->frontend[1])
614 dvb_frontend_detach(dvb->frontend[1]);
615 dvb_frontend_detach(dvb->frontend[0]);
616 dvb_unregister_adapter(&dvb->adapter);
618 /* remove I2C tuner */
619 dvb_module_release(dvb->i2c_client_tuner);
620 dvb->i2c_client_tuner = NULL;
621 /* remove I2C demod(s) */
622 dvb_module_release(dvb->i2c_client_demod[1]);
623 dvb->i2c_client_demod[1] = NULL;
624 dvb_module_release(dvb->i2c_client_demod[0]);
625 dvb->i2c_client_demod[0] = NULL;
628 static int dvb_init(struct cx231xx *dev)
630 int result;
631 struct cx231xx_dvb *dvb;
632 struct i2c_adapter *tuner_i2c;
633 struct i2c_adapter *demod_i2c;
634 struct i2c_client *client;
635 struct i2c_adapter *adapter;
637 if (!dev->board.has_dvb) {
638 /* This device does not support the extension */
639 return 0;
642 dvb = kzalloc(sizeof(struct cx231xx_dvb), GFP_KERNEL);
644 if (dvb == NULL) {
645 dev_info(dev->dev,
646 "cx231xx_dvb: memory allocation failed\n");
647 return -ENOMEM;
649 dev->dvb = dvb;
650 dev->cx231xx_set_analog_freq = cx231xx_set_analog_freq;
651 dev->cx231xx_reset_analog_tuner = cx231xx_reset_analog_tuner;
653 tuner_i2c = cx231xx_get_i2c_adap(dev, dev->board.tuner_i2c_master);
654 demod_i2c = cx231xx_get_i2c_adap(dev, dev->board.demod_i2c_master);
655 mutex_lock(&dev->lock);
656 cx231xx_set_mode(dev, CX231XX_DIGITAL_MODE);
657 cx231xx_demod_reset(dev);
658 /* init frontend */
659 switch (dev->model) {
660 case CX231XX_BOARD_CNXT_CARRAERA:
661 case CX231XX_BOARD_CNXT_RDE_250:
663 dev->dvb->frontend[0] = dvb_attach(s5h1432_attach,
664 &dvico_s5h1432_config,
665 demod_i2c);
667 if (!dev->dvb->frontend[0]) {
668 dev_err(dev->dev,
669 "Failed to attach s5h1432 front end\n");
670 result = -EINVAL;
671 goto out_free;
674 /* define general-purpose callback pointer */
675 dvb->frontend[0]->callback = cx231xx_tuner_callback;
677 if (!dvb_attach(xc5000_attach, dev->dvb->frontend[0],
678 tuner_i2c,
679 &cnxt_rde250_tunerconfig)) {
680 result = -EINVAL;
681 goto out_free;
684 break;
685 case CX231XX_BOARD_CNXT_SHELBY:
686 case CX231XX_BOARD_CNXT_RDU_250:
688 dev->dvb->frontend[0] = dvb_attach(s5h1411_attach,
689 &xc5000_s5h1411_config,
690 demod_i2c);
692 if (!dev->dvb->frontend[0]) {
693 dev_err(dev->dev,
694 "Failed to attach s5h1411 front end\n");
695 result = -EINVAL;
696 goto out_free;
699 /* define general-purpose callback pointer */
700 dvb->frontend[0]->callback = cx231xx_tuner_callback;
702 if (!dvb_attach(xc5000_attach, dev->dvb->frontend[0],
703 tuner_i2c,
704 &cnxt_rdu250_tunerconfig)) {
705 result = -EINVAL;
706 goto out_free;
708 break;
709 case CX231XX_BOARD_CNXT_RDE_253S:
711 dev->dvb->frontend[0] = dvb_attach(s5h1432_attach,
712 &dvico_s5h1432_config,
713 demod_i2c);
715 if (!dev->dvb->frontend[0]) {
716 dev_err(dev->dev,
717 "Failed to attach s5h1432 front end\n");
718 result = -EINVAL;
719 goto out_free;
722 /* define general-purpose callback pointer */
723 dvb->frontend[0]->callback = cx231xx_tuner_callback;
725 if (!dvb_attach(tda18271_attach, dev->dvb->frontend[0],
726 dev->board.tuner_addr, tuner_i2c,
727 &cnxt_rde253s_tunerconfig)) {
728 result = -EINVAL;
729 goto out_free;
731 break;
732 case CX231XX_BOARD_CNXT_RDU_253S:
733 case CX231XX_BOARD_KWORLD_UB445_USB_HYBRID:
735 dev->dvb->frontend[0] = dvb_attach(s5h1411_attach,
736 &tda18271_s5h1411_config,
737 demod_i2c);
739 if (!dev->dvb->frontend[0]) {
740 dev_err(dev->dev,
741 "Failed to attach s5h1411 front end\n");
742 result = -EINVAL;
743 goto out_free;
746 /* define general-purpose callback pointer */
747 dvb->frontend[0]->callback = cx231xx_tuner_callback;
749 if (!dvb_attach(tda18271_attach, dev->dvb->frontend[0],
750 dev->board.tuner_addr, tuner_i2c,
751 &cnxt_rde253s_tunerconfig)) {
752 result = -EINVAL;
753 goto out_free;
755 break;
756 case CX231XX_BOARD_HAUPPAUGE_EXETER:
758 dev_info(dev->dev,
759 "%s: looking for tuner / demod on i2c bus: %d\n",
760 __func__, i2c_adapter_id(tuner_i2c));
762 dev->dvb->frontend[0] = dvb_attach(lgdt3305_attach,
763 &hcw_lgdt3305_config,
764 demod_i2c);
766 if (!dev->dvb->frontend[0]) {
767 dev_err(dev->dev,
768 "Failed to attach LG3305 front end\n");
769 result = -EINVAL;
770 goto out_free;
773 /* define general-purpose callback pointer */
774 dvb->frontend[0]->callback = cx231xx_tuner_callback;
776 dvb_attach(tda18271_attach, dev->dvb->frontend[0],
777 dev->board.tuner_addr, tuner_i2c,
778 &hcw_tda18271_config);
779 break;
781 case CX231XX_BOARD_HAUPPAUGE_930C_HD_1113xx:
783 struct si2165_platform_data si2165_pdata = {};
785 /* attach demod */
786 si2165_pdata.fe = &dev->dvb->frontend[0];
787 si2165_pdata.chip_mode = SI2165_MODE_PLL_XTAL;
788 si2165_pdata.ref_freq_hz = 16000000;
790 /* perform probe/init/attach */
791 client = dvb_module_probe("si2165", NULL, demod_i2c,
792 dev->board.demod_addr,
793 &si2165_pdata);
794 if (!client) {
795 result = -ENODEV;
796 goto out_free;
798 dvb->i2c_client_demod[0] = client;
800 dev->dvb->frontend[0]->ops.i2c_gate_ctrl = NULL;
802 /* define general-purpose callback pointer */
803 dvb->frontend[0]->callback = cx231xx_tuner_callback;
805 dvb_attach(tda18271_attach, dev->dvb->frontend[0],
806 dev->board.tuner_addr, tuner_i2c,
807 &hcw_tda18271_config);
809 dev->cx231xx_reset_analog_tuner = NULL;
810 break;
812 case CX231XX_BOARD_HAUPPAUGE_930C_HD_1114xx:
814 struct si2165_platform_data si2165_pdata = {};
815 struct si2157_config si2157_config = {};
817 /* attach demod */
818 si2165_pdata.fe = &dev->dvb->frontend[0];
819 si2165_pdata.chip_mode = SI2165_MODE_PLL_EXT;
820 si2165_pdata.ref_freq_hz = 24000000;
822 /* perform probe/init/attach */
823 client = dvb_module_probe("si2165", NULL, demod_i2c,
824 dev->board.demod_addr,
825 &si2165_pdata);
826 if (!client) {
827 result = -ENODEV;
828 goto out_free;
830 dvb->i2c_client_demod[0] = client;
832 dev->dvb->frontend[0]->ops.i2c_gate_ctrl = NULL;
834 /* define general-purpose callback pointer */
835 dvb->frontend[0]->callback = cx231xx_tuner_callback;
837 /* attach tuner */
838 si2157_config.fe = dev->dvb->frontend[0];
839 #ifdef CONFIG_MEDIA_CONTROLLER_DVB
840 si2157_config.mdev = dev->media_dev;
841 #endif
842 si2157_config.if_port = 1;
843 si2157_config.inversion = true;
845 /* perform probe/init/attach */
846 client = dvb_module_probe("si2157", NULL, tuner_i2c,
847 dev->board.tuner_addr,
848 &si2157_config);
849 if (!client) {
850 result = -ENODEV;
851 goto out_free;
853 dev->cx231xx_reset_analog_tuner = NULL;
855 dev->dvb->i2c_client_tuner = client;
856 break;
858 case CX231XX_BOARD_HAUPPAUGE_955Q:
860 struct si2157_config si2157_config = {};
861 struct lgdt3306a_config lgdt3306a_config = {};
863 lgdt3306a_config = hauppauge_955q_lgdt3306a_config;
864 lgdt3306a_config.fe = &dev->dvb->frontend[0];
865 lgdt3306a_config.i2c_adapter = &adapter;
867 /* perform probe/init/attach */
868 client = dvb_module_probe("lgdt3306a", NULL, demod_i2c,
869 dev->board.demod_addr,
870 &lgdt3306a_config);
871 if (!client) {
872 result = -ENODEV;
873 goto out_free;
875 dvb->i2c_client_demod[0] = client;
877 dev->dvb->frontend[0]->ops.i2c_gate_ctrl = NULL;
879 /* define general-purpose callback pointer */
880 dvb->frontend[0]->callback = cx231xx_tuner_callback;
882 /* attach tuner */
883 si2157_config.fe = dev->dvb->frontend[0];
884 #ifdef CONFIG_MEDIA_CONTROLLER_DVB
885 si2157_config.mdev = dev->media_dev;
886 #endif
887 si2157_config.if_port = 1;
888 si2157_config.inversion = true;
890 /* perform probe/init/attach */
891 client = dvb_module_probe("si2157", NULL, tuner_i2c,
892 dev->board.tuner_addr,
893 &si2157_config);
894 if (!client) {
895 result = -ENODEV;
896 goto out_free;
898 dev->cx231xx_reset_analog_tuner = NULL;
900 dev->dvb->i2c_client_tuner = client;
901 break;
903 case CX231XX_BOARD_PV_PLAYTV_USB_HYBRID:
904 case CX231XX_BOARD_KWORLD_UB430_USB_HYBRID:
906 dev_info(dev->dev,
907 "%s: looking for demod on i2c bus: %d\n",
908 __func__, i2c_adapter_id(tuner_i2c));
910 dev->dvb->frontend[0] = dvb_attach(mb86a20s_attach,
911 &pv_mb86a20s_config,
912 demod_i2c);
914 if (!dev->dvb->frontend[0]) {
915 dev_err(dev->dev,
916 "Failed to attach mb86a20s demod\n");
917 result = -EINVAL;
918 goto out_free;
921 /* define general-purpose callback pointer */
922 dvb->frontend[0]->callback = cx231xx_tuner_callback;
924 dvb_attach(tda18271_attach, dev->dvb->frontend[0],
925 dev->board.tuner_addr, tuner_i2c,
926 &pv_tda18271_config);
927 break;
929 case CX231XX_BOARD_EVROMEDIA_FULL_HYBRID_FULLHD:
931 struct si2157_config si2157_config = {};
932 struct si2168_config si2168_config = {};
934 /* attach demodulator chip */
935 si2168_config.ts_mode = SI2168_TS_SERIAL; /* from *.inf file */
936 si2168_config.fe = &dev->dvb->frontend[0];
937 si2168_config.i2c_adapter = &adapter;
938 si2168_config.ts_clock_inv = true;
940 /* perform probe/init/attach */
941 client = dvb_module_probe("si2168", NULL, demod_i2c,
942 dev->board.demod_addr,
943 &si2168_config);
944 if (!client) {
945 result = -ENODEV;
946 goto out_free;
948 dvb->i2c_client_demod[0] = client;
950 /* attach tuner chip */
951 si2157_config.fe = dev->dvb->frontend[0];
952 #ifdef CONFIG_MEDIA_CONTROLLER_DVB
953 si2157_config.mdev = dev->media_dev;
954 #endif
955 si2157_config.if_port = 1;
956 si2157_config.inversion = false;
958 /* perform probe/init/attach */
959 client = dvb_module_probe("si2157", NULL, tuner_i2c,
960 dev->board.tuner_addr,
961 &si2157_config);
962 if (!client) {
963 result = -ENODEV;
964 goto out_free;
966 dev->cx231xx_reset_analog_tuner = NULL;
967 dev->dvb->i2c_client_tuner = client;
968 break;
970 case CX231XX_BOARD_ASTROMETA_T2HYBRID:
972 struct mn88473_config mn88473_config = {};
974 /* attach demodulator chip */
975 mn88473_config.i2c_wr_max = 16;
976 mn88473_config.xtal = 25000000;
977 mn88473_config.fe = &dev->dvb->frontend[0];
979 /* perform probe/init/attach */
980 client = dvb_module_probe("mn88473", NULL, demod_i2c,
981 dev->board.demod_addr,
982 &mn88473_config);
983 if (!client) {
984 result = -ENODEV;
985 goto out_free;
987 dvb->i2c_client_demod[0] = client;
989 /* define general-purpose callback pointer */
990 dvb->frontend[0]->callback = cx231xx_tuner_callback;
992 /* attach tuner chip */
993 dvb_attach(r820t_attach, dev->dvb->frontend[0],
994 tuner_i2c,
995 &astrometa_t2hybrid_r820t_config);
996 break;
998 case CX231XX_BOARD_HAUPPAUGE_935C:
1000 struct si2157_config si2157_config = {};
1001 struct si2168_config si2168_config = {};
1003 /* attach demodulator chip */
1004 si2168_config.ts_mode = SI2168_TS_SERIAL;
1005 si2168_config.fe = &dev->dvb->frontend[0];
1006 si2168_config.i2c_adapter = &adapter;
1007 si2168_config.ts_clock_inv = true;
1009 /* perform probe/init/attach */
1010 client = dvb_module_probe("si2168", NULL, demod_i2c,
1011 dev->board.demod_addr,
1012 &si2168_config);
1013 if (!client) {
1014 result = -ENODEV;
1015 goto out_free;
1017 dvb->i2c_client_demod[0] = client;
1018 dev->dvb->frontend[0]->ops.i2c_gate_ctrl = NULL;
1020 /* define general-purpose callback pointer */
1021 dvb->frontend[0]->callback = cx231xx_tuner_callback;
1023 /* attach tuner */
1024 si2157_config.fe = dev->dvb->frontend[0];
1025 #ifdef CONFIG_MEDIA_CONTROLLER_DVB
1026 si2157_config.mdev = dev->media_dev;
1027 #endif
1028 si2157_config.if_port = 1;
1029 si2157_config.inversion = true;
1031 /* perform probe/init/attach */
1032 client = dvb_module_probe("si2157", NULL, tuner_i2c,
1033 dev->board.tuner_addr,
1034 &si2157_config);
1035 if (!client) {
1036 result = -ENODEV;
1037 goto out_free;
1039 dev->cx231xx_reset_analog_tuner = NULL;
1040 dev->dvb->i2c_client_tuner = client;
1041 break;
1043 case CX231XX_BOARD_HAUPPAUGE_975:
1045 struct i2c_adapter *adapter2;
1046 struct si2157_config si2157_config = {};
1047 struct lgdt3306a_config lgdt3306a_config = {};
1048 struct si2168_config si2168_config = {};
1050 /* attach first demodulator chip */
1051 lgdt3306a_config = hauppauge_955q_lgdt3306a_config;
1052 lgdt3306a_config.fe = &dev->dvb->frontend[0];
1053 lgdt3306a_config.i2c_adapter = &adapter;
1055 /* perform probe/init/attach */
1056 client = dvb_module_probe("lgdt3306a", NULL, demod_i2c,
1057 dev->board.demod_addr,
1058 &lgdt3306a_config);
1059 if (!client) {
1060 result = -ENODEV;
1061 goto out_free;
1063 dvb->i2c_client_demod[0] = client;
1065 /* attach second demodulator chip */
1066 si2168_config.ts_mode = SI2168_TS_SERIAL;
1067 si2168_config.fe = &dev->dvb->frontend[1];
1068 si2168_config.i2c_adapter = &adapter2;
1069 si2168_config.ts_clock_inv = true;
1071 /* perform probe/init/attach */
1072 client = dvb_module_probe("si2168", NULL, adapter,
1073 dev->board.demod_addr2,
1074 &si2168_config);
1075 if (!client) {
1076 result = -ENODEV;
1077 goto out_free;
1079 dvb->i2c_client_demod[1] = client;
1080 dvb->frontend[1]->id = 1;
1082 /* define general-purpose callback pointer */
1083 dvb->frontend[0]->callback = cx231xx_tuner_callback;
1084 dvb->frontend[1]->callback = cx231xx_tuner_callback;
1086 /* attach tuner */
1087 si2157_config.fe = dev->dvb->frontend[0];
1088 #ifdef CONFIG_MEDIA_CONTROLLER_DVB
1089 si2157_config.mdev = dev->media_dev;
1090 #endif
1091 si2157_config.if_port = 1;
1092 si2157_config.inversion = true;
1094 /* perform probe/init/attach */
1095 client = dvb_module_probe("si2157", NULL, adapter,
1096 dev->board.tuner_addr,
1097 &si2157_config);
1098 if (!client) {
1099 result = -ENODEV;
1100 goto out_free;
1102 dev->cx231xx_reset_analog_tuner = NULL;
1103 dvb->i2c_client_tuner = client;
1105 dvb->frontend[1]->tuner_priv = dvb->frontend[0]->tuner_priv;
1107 memcpy(&dvb->frontend[1]->ops.tuner_ops,
1108 &dvb->frontend[0]->ops.tuner_ops,
1109 sizeof(struct dvb_tuner_ops));
1110 break;
1112 default:
1113 dev_err(dev->dev,
1114 "%s/2: The frontend of your DVB/ATSC card isn't supported yet\n",
1115 dev->name);
1116 break;
1118 if (!dvb->frontend[0]) {
1119 dev_err(dev->dev,
1120 "%s/2: frontend initialization failed\n", dev->name);
1121 result = -EINVAL;
1122 goto out_free;
1125 /* register everything */
1126 result = register_dvb(dvb, THIS_MODULE, dev, dev->dev);
1128 if (result < 0)
1129 goto out_free;
1132 dev_info(dev->dev, "Successfully loaded cx231xx-dvb\n");
1134 ret:
1135 cx231xx_set_mode(dev, CX231XX_SUSPEND);
1136 mutex_unlock(&dev->lock);
1137 return result;
1139 out_free:
1140 /* remove I2C tuner */
1141 dvb_module_release(dvb->i2c_client_tuner);
1142 dvb->i2c_client_tuner = NULL;
1143 /* remove I2C demod(s) */
1144 dvb_module_release(dvb->i2c_client_demod[1]);
1145 dvb->i2c_client_demod[1] = NULL;
1146 dvb_module_release(dvb->i2c_client_demod[0]);
1147 dvb->i2c_client_demod[0] = NULL;
1148 kfree(dvb);
1149 dev->dvb = NULL;
1150 goto ret;
1153 static int dvb_fini(struct cx231xx *dev)
1155 if (!dev->board.has_dvb) {
1156 /* This device does not support the extension */
1157 return 0;
1160 if (dev->dvb) {
1161 unregister_dvb(dev->dvb);
1162 dev->dvb = NULL;
1165 return 0;
1168 static struct cx231xx_ops dvb_ops = {
1169 .id = CX231XX_DVB,
1170 .name = "Cx231xx dvb Extension",
1171 .init = dvb_init,
1172 .fini = dvb_fini,
1175 static int __init cx231xx_dvb_register(void)
1177 return cx231xx_register_extension(&dvb_ops);
1180 static void __exit cx231xx_dvb_unregister(void)
1182 cx231xx_unregister_extension(&dvb_ops);
1185 module_init(cx231xx_dvb_register);
1186 module_exit(cx231xx_dvb_unregister);