Commit | Line | Data |
---|---|---|
e0d3bafd SD |
1 | /* |
2 | DVB device driver for cx231xx | |
3 | ||
4 | Copyright (C) 2008 <srinivasa.deevi at conexant dot com> | |
b9255176 | 5 | Based on em28xx driver |
e0d3bafd SD |
6 | |
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 | 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/kernel.h> | |
5a0e3ad6 | 23 | #include <linux/slab.h> |
e0d3bafd SD |
24 | #include <linux/usb.h> |
25 | ||
26 | #include "cx231xx.h" | |
27 | #include <media/v4l2-common.h> | |
28 | #include <media/videobuf-vmalloc.h> | |
29 | ||
30 | #include "xc5000.h" | |
64fbf444 PB |
31 | #include "s5h1432.h" |
32 | #include "tda18271.h" | |
33 | #include "s5h1411.h" | |
1a50fdde | 34 | #include "lgdt3305.h" |
dd2e7dd2 | 35 | #include "si2165.h" |
ede676c7 | 36 | #include "mb86a20s.h" |
9e49f7c3 | 37 | #include "si2157.h" |
e0d3bafd | 38 | |
e0d3bafd SD |
39 | MODULE_DESCRIPTION("driver for cx231xx based DVB cards"); |
40 | MODULE_AUTHOR("Srinivasa Deevi <srinivasa.deevi@conexant.com>"); | |
41 | MODULE_LICENSE("GPL"); | |
42 | ||
43 | static unsigned int debug; | |
44 | module_param(debug, int, 0644); | |
45 | MODULE_PARM_DESC(debug, "enable debug messages [dvb]"); | |
46 | ||
47 | DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); | |
48 | ||
49 | #define dprintk(level, fmt, arg...) do { \ | |
50 | if (debug >= level) \ | |
51 | printk(KERN_DEBUG "%s/2-dvb: " fmt, dev->name, ## arg); \ | |
52 | } while (0) | |
53 | ||
54 | #define CX231XX_DVB_NUM_BUFS 5 | |
55 | #define CX231XX_DVB_MAX_PACKETSIZE 564 | |
56 | #define CX231XX_DVB_MAX_PACKETS 64 | |
57 | ||
58 | struct cx231xx_dvb { | |
84b5dbf3 | 59 | struct dvb_frontend *frontend; |
e0d3bafd SD |
60 | |
61 | /* feed count management */ | |
84b5dbf3 MCC |
62 | struct mutex lock; |
63 | int nfeeds; | |
e0d3bafd SD |
64 | |
65 | /* general boilerplate stuff */ | |
84b5dbf3 MCC |
66 | struct dvb_adapter adapter; |
67 | struct dvb_demux demux; | |
68 | struct dmxdev dmxdev; | |
69 | struct dmx_frontend fe_hw; | |
70 | struct dmx_frontend fe_mem; | |
71 | struct dvb_net net; | |
6d3debaf | 72 | struct i2c_client *i2c_client_tuner; |
e0d3bafd SD |
73 | }; |
74 | ||
64fbf444 PB |
75 | static struct s5h1432_config dvico_s5h1432_config = { |
76 | .output_mode = S5H1432_SERIAL_OUTPUT, | |
77 | .gpio = S5H1432_GPIO_ON, | |
78 | .qam_if = S5H1432_IF_4000, | |
79 | .vsb_if = S5H1432_IF_4000, | |
80 | .inversion = S5H1432_INVERSION_OFF, | |
81 | .status_mode = S5H1432_DEMODLOCKING, | |
82 | .mpeg_timing = S5H1432_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK, | |
83 | }; | |
84 | ||
85 | static struct tda18271_std_map cnxt_rde253s_tda18271_std_map = { | |
86 | .dvbt_6 = { .if_freq = 4000, .agc_mode = 3, .std = 4, | |
87 | .if_lvl = 1, .rfagc_top = 0x37, }, | |
88 | .dvbt_7 = { .if_freq = 4000, .agc_mode = 3, .std = 5, | |
89 | .if_lvl = 1, .rfagc_top = 0x37, }, | |
90 | .dvbt_8 = { .if_freq = 4000, .agc_mode = 3, .std = 6, | |
91 | .if_lvl = 1, .rfagc_top = 0x37, }, | |
92 | }; | |
93 | ||
ede676c7 | 94 | static struct tda18271_std_map mb86a20s_tda18271_config = { |
84c09d72 MCC |
95 | .dvbt_6 = { .if_freq = 4000, .agc_mode = 3, .std = 4, |
96 | .if_lvl = 0, .rfagc_top = 0x37, }, | |
ede676c7 MCC |
97 | }; |
98 | ||
64fbf444 PB |
99 | static struct tda18271_config cnxt_rde253s_tunerconfig = { |
100 | .std_map = &cnxt_rde253s_tda18271_std_map, | |
101 | .gate = TDA18271_GATE_ANALOG, | |
102 | }; | |
103 | ||
104 | static struct s5h1411_config tda18271_s5h1411_config = { | |
105 | .output_mode = S5H1411_SERIAL_OUTPUT, | |
106 | .gpio = S5H1411_GPIO_OFF, | |
107 | .vsb_if = S5H1411_IF_3250, | |
108 | .qam_if = S5H1411_IF_4000, | |
109 | .inversion = S5H1411_INVERSION_ON, | |
110 | .status_mode = S5H1411_DEMODLOCKING, | |
111 | .mpeg_timing = S5H1411_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK, | |
112 | }; | |
113 | static struct s5h1411_config xc5000_s5h1411_config = { | |
114 | .output_mode = S5H1411_SERIAL_OUTPUT, | |
115 | .gpio = S5H1411_GPIO_OFF, | |
116 | .vsb_if = S5H1411_IF_3250, | |
117 | .qam_if = S5H1411_IF_3250, | |
118 | .inversion = S5H1411_INVERSION_OFF, | |
119 | .status_mode = S5H1411_DEMODLOCKING, | |
120 | .mpeg_timing = S5H1411_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK, | |
121 | }; | |
1a50fdde MK |
122 | |
123 | static struct lgdt3305_config hcw_lgdt3305_config = { | |
124 | .i2c_addr = 0x0e, | |
125 | .mpeg_mode = LGDT3305_MPEG_SERIAL, | |
126 | .tpclk_edge = LGDT3305_TPCLK_FALLING_EDGE, | |
127 | .tpvalid_polarity = LGDT3305_TP_VALID_HIGH, | |
128 | .deny_i2c_rptr = 1, | |
129 | .spectral_inversion = 1, | |
130 | .qam_if_khz = 4000, | |
131 | .vsb_if_khz = 3250, | |
132 | }; | |
133 | ||
134 | static struct tda18271_std_map hauppauge_tda18271_std_map = { | |
135 | .atsc_6 = { .if_freq = 3250, .agc_mode = 3, .std = 4, | |
136 | .if_lvl = 1, .rfagc_top = 0x58, }, | |
137 | .qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 5, | |
138 | .if_lvl = 1, .rfagc_top = 0x58, }, | |
139 | }; | |
140 | ||
141 | static struct tda18271_config hcw_tda18271_config = { | |
142 | .std_map = &hauppauge_tda18271_std_map, | |
143 | .gate = TDA18271_GATE_DIGITAL, | |
144 | }; | |
145 | ||
ede676c7 MCC |
146 | static const struct mb86a20s_config pv_mb86a20s_config = { |
147 | .demod_address = 0x10, | |
7572f9c5 | 148 | .is_serial = true, |
ede676c7 MCC |
149 | }; |
150 | ||
151 | static struct tda18271_config pv_tda18271_config = { | |
152 | .std_map = &mb86a20s_tda18271_config, | |
153 | .gate = TDA18271_GATE_DIGITAL, | |
154 | .small_i2c = TDA18271_03_BYTE_CHUNK_INIT, | |
155 | }; | |
156 | ||
dd2e7dd2 MS |
157 | static const struct si2165_config hauppauge_930C_HD_1113xx_si2165_config = { |
158 | .i2c_addr = 0x64, | |
159 | .chip_mode = SI2165_MODE_PLL_XTAL, | |
160 | .ref_freq_Hz = 16000000, | |
161 | }; | |
162 | ||
9e49f7c3 MS |
163 | static const struct si2165_config pctv_quatro_stick_1114xx_si2165_config = { |
164 | .i2c_addr = 0x64, | |
165 | .chip_mode = SI2165_MODE_PLL_EXT, | |
166 | .ref_freq_Hz = 24000000, | |
167 | }; | |
168 | ||
84b5dbf3 | 169 | static inline void print_err_status(struct cx231xx *dev, int packet, int status) |
e0d3bafd SD |
170 | { |
171 | char *errmsg = "Unknown"; | |
172 | ||
173 | switch (status) { | |
174 | case -ENOENT: | |
175 | errmsg = "unlinked synchronuously"; | |
176 | break; | |
177 | case -ECONNRESET: | |
178 | errmsg = "unlinked asynchronuously"; | |
179 | break; | |
180 | case -ENOSR: | |
181 | errmsg = "Buffer error (overrun)"; | |
182 | break; | |
183 | case -EPIPE: | |
184 | errmsg = "Stalled (device not responding)"; | |
185 | break; | |
186 | case -EOVERFLOW: | |
187 | errmsg = "Babble (bad cable?)"; | |
188 | break; | |
189 | case -EPROTO: | |
190 | errmsg = "Bit-stuff error (bad cable?)"; | |
191 | break; | |
192 | case -EILSEQ: | |
193 | errmsg = "CRC/Timeout (could be anything)"; | |
194 | break; | |
195 | case -ETIME: | |
196 | errmsg = "Device does not respond"; | |
197 | break; | |
198 | } | |
199 | if (packet < 0) { | |
200 | dprintk(1, "URB status %d [%s].\n", status, errmsg); | |
201 | } else { | |
202 | dprintk(1, "URB packet %d, status %d [%s].\n", | |
203 | packet, status, errmsg); | |
204 | } | |
205 | } | |
206 | ||
207 | static inline int dvb_isoc_copy(struct cx231xx *dev, struct urb *urb) | |
208 | { | |
209 | int i; | |
210 | ||
211 | if (!dev) | |
212 | return 0; | |
213 | ||
990862a2 | 214 | if (dev->state & DEV_DISCONNECTED) |
e0d3bafd SD |
215 | return 0; |
216 | ||
217 | if (urb->status < 0) { | |
218 | print_err_status(dev, -1, urb->status); | |
219 | if (urb->status == -ENOENT) | |
220 | return 0; | |
221 | } | |
222 | ||
223 | for (i = 0; i < urb->number_of_packets; i++) { | |
224 | int status = urb->iso_frame_desc[i].status; | |
225 | ||
226 | if (status < 0) { | |
227 | print_err_status(dev, i, status); | |
228 | if (urb->iso_frame_desc[i].status != -EPROTO) | |
229 | continue; | |
230 | } | |
231 | ||
64fbf444 PB |
232 | dvb_dmx_swfilter(&dev->dvb->demux, |
233 | urb->transfer_buffer + | |
234 | urb->iso_frame_desc[i].offset, | |
235 | urb->iso_frame_desc[i].actual_length); | |
e0d3bafd SD |
236 | } |
237 | ||
238 | return 0; | |
239 | } | |
240 | ||
64fbf444 PB |
241 | static inline int dvb_bulk_copy(struct cx231xx *dev, struct urb *urb) |
242 | { | |
64fbf444 PB |
243 | if (!dev) |
244 | return 0; | |
245 | ||
990862a2 | 246 | if (dev->state & DEV_DISCONNECTED) |
64fbf444 PB |
247 | return 0; |
248 | ||
249 | if (urb->status < 0) { | |
250 | print_err_status(dev, -1, urb->status); | |
251 | if (urb->status == -ENOENT) | |
252 | return 0; | |
253 | } | |
254 | ||
255 | /* Feed the transport payload into the kernel demux */ | |
256 | dvb_dmx_swfilter(&dev->dvb->demux, | |
257 | urb->transfer_buffer, urb->actual_length); | |
258 | ||
259 | return 0; | |
260 | } | |
261 | ||
e0d3bafd SD |
262 | static int start_streaming(struct cx231xx_dvb *dvb) |
263 | { | |
264 | int rc; | |
265 | struct cx231xx *dev = dvb->adapter.priv; | |
266 | ||
64fbf444 PB |
267 | if (dev->USE_ISO) { |
268 | cx231xx_info("DVB transfer mode is ISO.\n"); | |
a6f6fb9c MCC |
269 | mutex_lock(&dev->i2c_lock); |
270 | cx231xx_enable_i2c_port_3(dev, false); | |
64fbf444 | 271 | cx231xx_set_alt_setting(dev, INDEX_TS1, 4); |
a6f6fb9c MCC |
272 | cx231xx_enable_i2c_port_3(dev, true); |
273 | mutex_unlock(&dev->i2c_lock); | |
64fbf444 PB |
274 | rc = cx231xx_set_mode(dev, CX231XX_DIGITAL_MODE); |
275 | if (rc < 0) | |
276 | return rc; | |
277 | dev->mode_tv = 1; | |
278 | return cx231xx_init_isoc(dev, CX231XX_DVB_MAX_PACKETS, | |
279 | CX231XX_DVB_NUM_BUFS, | |
280 | dev->ts1_mode.max_pkt_size, | |
281 | dvb_isoc_copy); | |
282 | } else { | |
283 | cx231xx_info("DVB transfer mode is BULK.\n"); | |
284 | cx231xx_set_alt_setting(dev, INDEX_TS1, 0); | |
285 | rc = cx231xx_set_mode(dev, CX231XX_DIGITAL_MODE); | |
286 | if (rc < 0) | |
287 | return rc; | |
288 | dev->mode_tv = 1; | |
289 | return cx231xx_init_bulk(dev, CX231XX_DVB_MAX_PACKETS, | |
290 | CX231XX_DVB_NUM_BUFS, | |
291 | dev->ts1_mode.max_pkt_size, | |
292 | dvb_bulk_copy); | |
293 | } | |
e0d3bafd | 294 | |
e0d3bafd SD |
295 | } |
296 | ||
297 | static int stop_streaming(struct cx231xx_dvb *dvb) | |
298 | { | |
299 | struct cx231xx *dev = dvb->adapter.priv; | |
300 | ||
64fbf444 PB |
301 | if (dev->USE_ISO) |
302 | cx231xx_uninit_isoc(dev); | |
303 | else | |
304 | cx231xx_uninit_bulk(dev); | |
e0d3bafd SD |
305 | |
306 | cx231xx_set_mode(dev, CX231XX_SUSPEND); | |
307 | ||
308 | return 0; | |
309 | } | |
310 | ||
311 | static int start_feed(struct dvb_demux_feed *feed) | |
312 | { | |
84b5dbf3 | 313 | struct dvb_demux *demux = feed->demux; |
e0d3bafd SD |
314 | struct cx231xx_dvb *dvb = demux->priv; |
315 | int rc, ret; | |
316 | ||
317 | if (!demux->dmx.frontend) | |
318 | return -EINVAL; | |
319 | ||
320 | mutex_lock(&dvb->lock); | |
321 | dvb->nfeeds++; | |
322 | rc = dvb->nfeeds; | |
323 | ||
324 | if (dvb->nfeeds == 1) { | |
325 | ret = start_streaming(dvb); | |
326 | if (ret < 0) | |
327 | rc = ret; | |
328 | } | |
329 | ||
330 | mutex_unlock(&dvb->lock); | |
331 | return rc; | |
332 | } | |
333 | ||
334 | static int stop_feed(struct dvb_demux_feed *feed) | |
335 | { | |
84b5dbf3 | 336 | struct dvb_demux *demux = feed->demux; |
e0d3bafd SD |
337 | struct cx231xx_dvb *dvb = demux->priv; |
338 | int err = 0; | |
339 | ||
340 | mutex_lock(&dvb->lock); | |
341 | dvb->nfeeds--; | |
342 | ||
343 | if (0 == dvb->nfeeds) | |
344 | err = stop_streaming(dvb); | |
345 | ||
346 | mutex_unlock(&dvb->lock); | |
347 | return err; | |
348 | } | |
349 | ||
e0d3bafd SD |
350 | /* ------------------------------------------------------------------ */ |
351 | static int cx231xx_dvb_bus_ctrl(struct dvb_frontend *fe, int acquire) | |
352 | { | |
353 | struct cx231xx *dev = fe->dvb->priv; | |
354 | ||
355 | if (acquire) | |
356 | return cx231xx_set_mode(dev, CX231XX_DIGITAL_MODE); | |
357 | else | |
358 | return cx231xx_set_mode(dev, CX231XX_SUSPEND); | |
359 | } | |
360 | ||
361 | /* ------------------------------------------------------------------ */ | |
362 | ||
e0d3bafd | 363 | static struct xc5000_config cnxt_rde250_tunerconfig = { |
84b5dbf3 | 364 | .i2c_address = 0x61, |
64fbf444 PB |
365 | .if_khz = 4000, |
366 | }; | |
367 | static struct xc5000_config cnxt_rdu250_tunerconfig = { | |
368 | .i2c_address = 0x61, | |
369 | .if_khz = 3250, | |
e0d3bafd SD |
370 | }; |
371 | ||
e0d3bafd SD |
372 | /* ------------------------------------------------------------------ */ |
373 | #if 0 | |
374 | static int attach_xc5000(u8 addr, struct cx231xx *dev) | |
375 | { | |
376 | ||
377 | struct dvb_frontend *fe; | |
378 | struct xc5000_config cfg; | |
379 | ||
380 | memset(&cfg, 0, sizeof(cfg)); | |
1a4aa920 | 381 | cfg.i2c_adap = &dev->i2c_bus[dev->board.tuner_i2c_master].i2c_adap; |
84b5dbf3 | 382 | cfg.i2c_addr = addr; |
e0d3bafd SD |
383 | |
384 | if (!dev->dvb->frontend) { | |
385 | printk(KERN_ERR "%s/2: dvb frontend not attached. " | |
84b5dbf3 | 386 | "Can't attach xc5000\n", dev->name); |
e0d3bafd SD |
387 | return -EINVAL; |
388 | } | |
389 | ||
390 | fe = dvb_attach(xc5000_attach, dev->dvb->frontend, &cfg); | |
391 | if (!fe) { | |
392 | printk(KERN_ERR "%s/2: xc5000 attach failed\n", dev->name); | |
393 | dvb_frontend_detach(dev->dvb->frontend); | |
394 | dev->dvb->frontend = NULL; | |
395 | return -EINVAL; | |
396 | } | |
397 | ||
398 | printk(KERN_INFO "%s/2: xc5000 attached\n", dev->name); | |
399 | ||
400 | return 0; | |
401 | } | |
402 | #endif | |
403 | ||
84b5dbf3 | 404 | int cx231xx_set_analog_freq(struct cx231xx *dev, u32 freq) |
e0d3bafd | 405 | { |
84b5dbf3 | 406 | if ((dev->dvb != NULL) && (dev->dvb->frontend != NULL)) { |
e0d3bafd | 407 | |
84b5dbf3 | 408 | struct dvb_tuner_ops *dops = &dev->dvb->frontend->ops.tuner_ops; |
e0d3bafd | 409 | |
84b5dbf3 MCC |
410 | if (dops->set_analog_params != NULL) { |
411 | struct analog_parameters params; | |
e0d3bafd | 412 | |
84b5dbf3 MCC |
413 | params.frequency = freq; |
414 | params.std = dev->norm; | |
415 | params.mode = 0; /* 0- Air; 1 - cable */ | |
416 | /*params.audmode = ; */ | |
e0d3bafd | 417 | |
84b5dbf3 | 418 | /* Set the analog parameters to set the frequency */ |
84b5dbf3 | 419 | dops->set_analog_params(dev->dvb->frontend, ¶ms); |
e0d3bafd SD |
420 | } |
421 | ||
84b5dbf3 MCC |
422 | } |
423 | ||
ea21f702 | 424 | return 0; |
e0d3bafd SD |
425 | } |
426 | ||
427 | int cx231xx_reset_analog_tuner(struct cx231xx *dev) | |
428 | { | |
84b5dbf3 | 429 | int status = 0; |
e0d3bafd | 430 | |
84b5dbf3 | 431 | if ((dev->dvb != NULL) && (dev->dvb->frontend != NULL)) { |
e0d3bafd | 432 | |
84b5dbf3 | 433 | struct dvb_tuner_ops *dops = &dev->dvb->frontend->ops.tuner_ops; |
e0d3bafd | 434 | |
84b5dbf3 | 435 | if (dops->init != NULL && !dev->xc_fw_load_done) { |
e0d3bafd | 436 | |
84b5dbf3 MCC |
437 | cx231xx_info("Reloading firmware for XC5000\n"); |
438 | status = dops->init(dev->dvb->frontend); | |
439 | if (status == 0) { | |
440 | dev->xc_fw_load_done = 1; | |
441 | cx231xx_info | |
442 | ("XC5000 firmware download completed\n"); | |
443 | } else { | |
444 | dev->xc_fw_load_done = 0; | |
445 | cx231xx_info | |
446 | ("XC5000 firmware download failed !!!\n"); | |
e0d3bafd | 447 | } |
e0d3bafd SD |
448 | } |
449 | ||
84b5dbf3 MCC |
450 | } |
451 | ||
e0d3bafd SD |
452 | return status; |
453 | } | |
454 | ||
e0d3bafd SD |
455 | /* ------------------------------------------------------------------ */ |
456 | ||
457 | static int register_dvb(struct cx231xx_dvb *dvb, | |
84b5dbf3 MCC |
458 | struct module *module, |
459 | struct cx231xx *dev, struct device *device) | |
e0d3bafd SD |
460 | { |
461 | int result; | |
462 | ||
463 | mutex_init(&dvb->lock); | |
464 | ||
465 | /* register adapter */ | |
466 | result = dvb_register_adapter(&dvb->adapter, dev->name, module, device, | |
467 | adapter_nr); | |
468 | if (result < 0) { | |
84b5dbf3 MCC |
469 | printk(KERN_WARNING |
470 | "%s: dvb_register_adapter failed (errno = %d)\n", | |
e0d3bafd SD |
471 | dev->name, result); |
472 | goto fail_adapter; | |
473 | } | |
474 | ||
475 | /* Ensure all frontends negotiate bus access */ | |
476 | dvb->frontend->ops.ts_bus_ctrl = cx231xx_dvb_bus_ctrl; | |
477 | ||
478 | dvb->adapter.priv = dev; | |
479 | ||
480 | /* register frontend */ | |
481 | result = dvb_register_frontend(&dvb->adapter, dvb->frontend); | |
482 | if (result < 0) { | |
84b5dbf3 MCC |
483 | printk(KERN_WARNING |
484 | "%s: dvb_register_frontend failed (errno = %d)\n", | |
e0d3bafd SD |
485 | dev->name, result); |
486 | goto fail_frontend; | |
487 | } | |
488 | ||
489 | /* register demux stuff */ | |
490 | dvb->demux.dmx.capabilities = | |
84b5dbf3 MCC |
491 | DMX_TS_FILTERING | DMX_SECTION_FILTERING | |
492 | DMX_MEMORY_BASED_FILTERING; | |
493 | dvb->demux.priv = dvb; | |
494 | dvb->demux.filternum = 256; | |
495 | dvb->demux.feednum = 256; | |
e0d3bafd | 496 | dvb->demux.start_feed = start_feed; |
84b5dbf3 | 497 | dvb->demux.stop_feed = stop_feed; |
e0d3bafd SD |
498 | |
499 | result = dvb_dmx_init(&dvb->demux); | |
500 | if (result < 0) { | |
501 | printk(KERN_WARNING "%s: dvb_dmx_init failed (errno = %d)\n", | |
502 | dev->name, result); | |
503 | goto fail_dmx; | |
504 | } | |
505 | ||
84b5dbf3 MCC |
506 | dvb->dmxdev.filternum = 256; |
507 | dvb->dmxdev.demux = &dvb->demux.dmx; | |
e0d3bafd SD |
508 | dvb->dmxdev.capabilities = 0; |
509 | result = dvb_dmxdev_init(&dvb->dmxdev, &dvb->adapter); | |
510 | if (result < 0) { | |
511 | printk(KERN_WARNING "%s: dvb_dmxdev_init failed (errno = %d)\n", | |
512 | dev->name, result); | |
513 | goto fail_dmxdev; | |
514 | } | |
515 | ||
516 | dvb->fe_hw.source = DMX_FRONTEND_0; | |
517 | result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_hw); | |
518 | if (result < 0) { | |
84b5dbf3 MCC |
519 | printk(KERN_WARNING |
520 | "%s: add_frontend failed (DMX_FRONTEND_0, errno = %d)\n", | |
e0d3bafd SD |
521 | dev->name, result); |
522 | goto fail_fe_hw; | |
523 | } | |
524 | ||
525 | dvb->fe_mem.source = DMX_MEMORY_FE; | |
526 | result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_mem); | |
527 | if (result < 0) { | |
84b5dbf3 MCC |
528 | printk(KERN_WARNING |
529 | "%s: add_frontend failed (DMX_MEMORY_FE, errno = %d)\n", | |
e0d3bafd SD |
530 | dev->name, result); |
531 | goto fail_fe_mem; | |
532 | } | |
533 | ||
534 | result = dvb->demux.dmx.connect_frontend(&dvb->demux.dmx, &dvb->fe_hw); | |
535 | if (result < 0) { | |
84b5dbf3 MCC |
536 | printk(KERN_WARNING |
537 | "%s: connect_frontend failed (errno = %d)\n", dev->name, | |
538 | result); | |
e0d3bafd SD |
539 | goto fail_fe_conn; |
540 | } | |
541 | ||
542 | /* register network adapter */ | |
543 | dvb_net_init(&dvb->adapter, &dvb->net, &dvb->demux.dmx); | |
544 | return 0; | |
545 | ||
b9255176 | 546 | fail_fe_conn: |
e0d3bafd | 547 | dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem); |
b9255176 | 548 | fail_fe_mem: |
e0d3bafd | 549 | dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw); |
b9255176 | 550 | fail_fe_hw: |
e0d3bafd | 551 | dvb_dmxdev_release(&dvb->dmxdev); |
b9255176 | 552 | fail_dmxdev: |
e0d3bafd | 553 | dvb_dmx_release(&dvb->demux); |
b9255176 | 554 | fail_dmx: |
e0d3bafd | 555 | dvb_unregister_frontend(dvb->frontend); |
b9255176 | 556 | fail_frontend: |
e0d3bafd SD |
557 | dvb_frontend_detach(dvb->frontend); |
558 | dvb_unregister_adapter(&dvb->adapter); | |
b9255176 | 559 | fail_adapter: |
e0d3bafd SD |
560 | return result; |
561 | } | |
562 | ||
563 | static void unregister_dvb(struct cx231xx_dvb *dvb) | |
564 | { | |
6d3debaf | 565 | struct i2c_client *client; |
e0d3bafd SD |
566 | dvb_net_release(&dvb->net); |
567 | dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem); | |
568 | dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw); | |
569 | dvb_dmxdev_release(&dvb->dmxdev); | |
570 | dvb_dmx_release(&dvb->demux); | |
6d3debaf MS |
571 | client = dvb->i2c_client_tuner; |
572 | /* remove I2C tuner */ | |
573 | if (client) { | |
574 | module_put(client->dev.driver->owner); | |
575 | i2c_unregister_device(client); | |
576 | } | |
e0d3bafd SD |
577 | dvb_unregister_frontend(dvb->frontend); |
578 | dvb_frontend_detach(dvb->frontend); | |
579 | dvb_unregister_adapter(&dvb->adapter); | |
580 | } | |
581 | ||
e0d3bafd SD |
582 | static int dvb_init(struct cx231xx *dev) |
583 | { | |
584 | int result = 0; | |
585 | struct cx231xx_dvb *dvb; | |
586 | ||
587 | if (!dev->board.has_dvb) { | |
588 | /* This device does not support the extension */ | |
589 | return 0; | |
590 | } | |
591 | ||
592 | dvb = kzalloc(sizeof(struct cx231xx_dvb), GFP_KERNEL); | |
593 | ||
594 | if (dvb == NULL) { | |
595 | printk(KERN_INFO "cx231xx_dvb: memory allocation failed\n"); | |
596 | return -ENOMEM; | |
597 | } | |
598 | dev->dvb = dvb; | |
599 | dev->cx231xx_set_analog_freq = cx231xx_set_analog_freq; | |
84b5dbf3 | 600 | dev->cx231xx_reset_analog_tuner = cx231xx_reset_analog_tuner; |
e0d3bafd | 601 | |
761f6cf6 | 602 | mutex_lock(&dev->lock); |
e0d3bafd | 603 | cx231xx_set_mode(dev, CX231XX_DIGITAL_MODE); |
64fbf444 | 604 | cx231xx_demod_reset(dev); |
e0d3bafd SD |
605 | /* init frontend */ |
606 | switch (dev->model) { | |
64fbf444 | 607 | case CX231XX_BOARD_CNXT_CARRAERA: |
84b5dbf3 MCC |
608 | case CX231XX_BOARD_CNXT_RDE_250: |
609 | ||
64fbf444 PB |
610 | dev->dvb->frontend = dvb_attach(s5h1432_attach, |
611 | &dvico_s5h1432_config, | |
1a4aa920 | 612 | &dev->i2c_bus[dev->board.demod_i2c_master].i2c_adap); |
84b5dbf3 MCC |
613 | |
614 | if (dev->dvb->frontend == NULL) { | |
615 | printk(DRIVER_NAME | |
64fbf444 | 616 | ": Failed to attach s5h1432 front end\n"); |
84b5dbf3 MCC |
617 | result = -EINVAL; |
618 | goto out_free; | |
619 | } | |
620 | ||
621 | /* define general-purpose callback pointer */ | |
622 | dvb->frontend->callback = cx231xx_tuner_callback; | |
623 | ||
d5abcc78 | 624 | if (!dvb_attach(xc5000_attach, dev->dvb->frontend, |
1a4aa920 | 625 | &dev->i2c_bus[dev->board.tuner_i2c_master].i2c_adap, |
d5abcc78 | 626 | &cnxt_rde250_tunerconfig)) { |
84b5dbf3 MCC |
627 | result = -EINVAL; |
628 | goto out_free; | |
629 | } | |
630 | ||
631 | break; | |
64fbf444 | 632 | case CX231XX_BOARD_CNXT_SHELBY: |
84b5dbf3 MCC |
633 | case CX231XX_BOARD_CNXT_RDU_250: |
634 | ||
64fbf444 PB |
635 | dev->dvb->frontend = dvb_attach(s5h1411_attach, |
636 | &xc5000_s5h1411_config, | |
1a4aa920 | 637 | &dev->i2c_bus[dev->board.demod_i2c_master].i2c_adap); |
84b5dbf3 MCC |
638 | |
639 | if (dev->dvb->frontend == NULL) { | |
640 | printk(DRIVER_NAME | |
e95342f1 | 641 | ": Failed to attach s5h1411 front end\n"); |
84b5dbf3 MCC |
642 | result = -EINVAL; |
643 | goto out_free; | |
644 | } | |
645 | ||
646 | /* define general-purpose callback pointer */ | |
647 | dvb->frontend->callback = cx231xx_tuner_callback; | |
648 | ||
d5abcc78 | 649 | if (!dvb_attach(xc5000_attach, dev->dvb->frontend, |
1a4aa920 | 650 | &dev->i2c_bus[dev->board.tuner_i2c_master].i2c_adap, |
64fbf444 PB |
651 | &cnxt_rdu250_tunerconfig)) { |
652 | result = -EINVAL; | |
653 | goto out_free; | |
654 | } | |
655 | break; | |
656 | case CX231XX_BOARD_CNXT_RDE_253S: | |
657 | ||
658 | dev->dvb->frontend = dvb_attach(s5h1432_attach, | |
659 | &dvico_s5h1432_config, | |
1a4aa920 | 660 | &dev->i2c_bus[dev->board.demod_i2c_master].i2c_adap); |
64fbf444 PB |
661 | |
662 | if (dev->dvb->frontend == NULL) { | |
663 | printk(DRIVER_NAME | |
664 | ": Failed to attach s5h1432 front end\n"); | |
665 | result = -EINVAL; | |
666 | goto out_free; | |
667 | } | |
668 | ||
669 | /* define general-purpose callback pointer */ | |
670 | dvb->frontend->callback = cx231xx_tuner_callback; | |
671 | ||
672 | if (!dvb_attach(tda18271_attach, dev->dvb->frontend, | |
1a4aa920 | 673 | 0x60, &dev->i2c_bus[dev->board.tuner_i2c_master].i2c_adap, |
64fbf444 PB |
674 | &cnxt_rde253s_tunerconfig)) { |
675 | result = -EINVAL; | |
676 | goto out_free; | |
677 | } | |
678 | break; | |
679 | case CX231XX_BOARD_CNXT_RDU_253S: | |
8b1255a2 | 680 | case CX231XX_BOARD_KWORLD_UB445_USB_HYBRID: |
64fbf444 PB |
681 | |
682 | dev->dvb->frontend = dvb_attach(s5h1411_attach, | |
683 | &tda18271_s5h1411_config, | |
1a4aa920 | 684 | &dev->i2c_bus[dev->board.demod_i2c_master].i2c_adap); |
64fbf444 PB |
685 | |
686 | if (dev->dvb->frontend == NULL) { | |
687 | printk(DRIVER_NAME | |
e95342f1 | 688 | ": Failed to attach s5h1411 front end\n"); |
64fbf444 PB |
689 | result = -EINVAL; |
690 | goto out_free; | |
691 | } | |
692 | ||
693 | /* define general-purpose callback pointer */ | |
694 | dvb->frontend->callback = cx231xx_tuner_callback; | |
695 | ||
696 | if (!dvb_attach(tda18271_attach, dev->dvb->frontend, | |
1a4aa920 | 697 | 0x60, &dev->i2c_bus[dev->board.tuner_i2c_master].i2c_adap, |
64fbf444 | 698 | &cnxt_rde253s_tunerconfig)) { |
84b5dbf3 MCC |
699 | result = -EINVAL; |
700 | goto out_free; | |
701 | } | |
702 | break; | |
1a50fdde MK |
703 | case CX231XX_BOARD_HAUPPAUGE_EXETER: |
704 | ||
705 | printk(KERN_INFO "%s: looking for tuner / demod on i2c bus: %d\n", | |
1a4aa920 | 706 | __func__, i2c_adapter_id(&dev->i2c_bus[dev->board.tuner_i2c_master].i2c_adap)); |
1a50fdde MK |
707 | |
708 | dev->dvb->frontend = dvb_attach(lgdt3305_attach, | |
709 | &hcw_lgdt3305_config, | |
1a4aa920 | 710 | &dev->i2c_bus[dev->board.tuner_i2c_master].i2c_adap); |
1a50fdde MK |
711 | |
712 | if (dev->dvb->frontend == NULL) { | |
713 | printk(DRIVER_NAME | |
714 | ": Failed to attach LG3305 front end\n"); | |
715 | result = -EINVAL; | |
716 | goto out_free; | |
717 | } | |
718 | ||
719 | /* define general-purpose callback pointer */ | |
720 | dvb->frontend->callback = cx231xx_tuner_callback; | |
721 | ||
722 | dvb_attach(tda18271_attach, dev->dvb->frontend, | |
1a4aa920 | 723 | 0x60, &dev->i2c_bus[dev->board.tuner_i2c_master].i2c_adap, |
1a50fdde MK |
724 | &hcw_tda18271_config); |
725 | break; | |
726 | ||
dd2e7dd2 MS |
727 | case CX231XX_BOARD_HAUPPAUGE_930C_HD_1113xx: |
728 | ||
729 | dev->dvb->frontend = dvb_attach(si2165_attach, | |
730 | &hauppauge_930C_HD_1113xx_si2165_config, | |
731 | &dev->i2c_bus[dev->board.tuner_i2c_master].i2c_adap | |
732 | ); | |
733 | ||
734 | if (dev->dvb->frontend == NULL) { | |
735 | printk(DRIVER_NAME | |
736 | ": Failed to attach SI2165 front end\n"); | |
737 | result = -EINVAL; | |
738 | goto out_free; | |
739 | } | |
740 | ||
3f9280a8 | 741 | dev->dvb->frontend->ops.i2c_gate_ctrl = NULL; |
dd2e7dd2 MS |
742 | |
743 | /* define general-purpose callback pointer */ | |
744 | dvb->frontend->callback = cx231xx_tuner_callback; | |
745 | ||
746 | dvb_attach(tda18271_attach, dev->dvb->frontend, | |
747 | 0x60, | |
748 | &dev->i2c_bus[dev->board.tuner_i2c_master].i2c_adap, | |
749 | &hcw_tda18271_config); | |
750 | ||
751 | dev->cx231xx_reset_analog_tuner = NULL; | |
752 | break; | |
753 | ||
9e49f7c3 MS |
754 | case CX231XX_BOARD_HAUPPAUGE_930C_HD_1114xx: |
755 | { | |
756 | struct i2c_client *client; | |
757 | struct i2c_board_info info; | |
758 | struct si2157_config si2157_config; | |
759 | ||
760 | memset(&info, 0, sizeof(struct i2c_board_info)); | |
761 | ||
762 | dev->dvb->frontend = dvb_attach(si2165_attach, | |
763 | &pctv_quatro_stick_1114xx_si2165_config, | |
764 | &dev->i2c_bus[dev->board.tuner_i2c_master].i2c_adap | |
765 | ); | |
766 | ||
767 | if (dev->dvb->frontend == NULL) { | |
768 | printk(DRIVER_NAME | |
769 | ": Failed to attach SI2165 front end\n"); | |
770 | result = -EINVAL; | |
771 | goto out_free; | |
772 | } | |
773 | ||
3f9280a8 | 774 | dev->dvb->frontend->ops.i2c_gate_ctrl = NULL; |
9e49f7c3 MS |
775 | |
776 | /* define general-purpose callback pointer */ | |
777 | dvb->frontend->callback = cx231xx_tuner_callback; | |
778 | ||
779 | /* attach tuner */ | |
780 | memset(&si2157_config, 0, sizeof(si2157_config)); | |
781 | si2157_config.fe = dev->dvb->frontend; | |
782 | si2157_config.inversion = true; | |
783 | strlcpy(info.type, "si2157", I2C_NAME_SIZE); | |
784 | info.addr = 0x60; | |
785 | info.platform_data = &si2157_config; | |
786 | request_module("si2157"); | |
787 | ||
788 | client = i2c_new_device( | |
789 | &dev->i2c_bus[dev->board.tuner_i2c_master].i2c_adap, | |
790 | &info); | |
791 | if (client == NULL || client->dev.driver == NULL) { | |
792 | dvb_frontend_detach(dev->dvb->frontend); | |
793 | result = -ENODEV; | |
794 | goto out_free; | |
795 | } | |
796 | ||
797 | if (!try_module_get(client->dev.driver->owner)) { | |
798 | i2c_unregister_device(client); | |
799 | dvb_frontend_detach(dev->dvb->frontend); | |
800 | result = -ENODEV; | |
801 | goto out_free; | |
802 | } | |
803 | ||
804 | dev->cx231xx_reset_analog_tuner = NULL; | |
805 | ||
806 | dev->dvb->i2c_client_tuner = client; | |
807 | break; | |
808 | } | |
809 | ||
ede676c7 | 810 | case CX231XX_BOARD_PV_PLAYTV_USB_HYBRID: |
eeaaf817 | 811 | case CX231XX_BOARD_KWORLD_UB430_USB_HYBRID: |
ede676c7 MCC |
812 | |
813 | printk(KERN_INFO "%s: looking for demod on i2c bus: %d\n", | |
814 | __func__, i2c_adapter_id(&dev->i2c_bus[dev->board.tuner_i2c_master].i2c_adap)); | |
815 | ||
816 | dev->dvb->frontend = dvb_attach(mb86a20s_attach, | |
817 | &pv_mb86a20s_config, | |
818 | &dev->i2c_bus[dev->board.demod_i2c_master].i2c_adap); | |
819 | ||
820 | if (dev->dvb->frontend == NULL) { | |
821 | printk(DRIVER_NAME | |
822 | ": Failed to attach mb86a20s demod\n"); | |
823 | result = -EINVAL; | |
824 | goto out_free; | |
825 | } | |
826 | ||
827 | /* define general-purpose callback pointer */ | |
828 | dvb->frontend->callback = cx231xx_tuner_callback; | |
829 | ||
830 | dvb_attach(tda18271_attach, dev->dvb->frontend, | |
831 | 0x60, &dev->i2c_bus[dev->board.tuner_i2c_master].i2c_adap, | |
832 | &pv_tda18271_config); | |
833 | break; | |
e0d3bafd SD |
834 | |
835 | default: | |
836 | printk(KERN_ERR "%s/2: The frontend of your DVB/ATSC card" | |
84b5dbf3 | 837 | " isn't supported yet\n", dev->name); |
e0d3bafd SD |
838 | break; |
839 | } | |
840 | if (NULL == dvb->frontend) { | |
841 | printk(KERN_ERR | |
84b5dbf3 | 842 | "%s/2: frontend initialization failed\n", dev->name); |
e0d3bafd SD |
843 | result = -EINVAL; |
844 | goto out_free; | |
845 | } | |
846 | ||
e0d3bafd SD |
847 | /* register everything */ |
848 | result = register_dvb(dvb, THIS_MODULE, dev, &dev->udev->dev); | |
849 | ||
850 | if (result < 0) | |
851 | goto out_free; | |
852 | ||
761f6cf6 | 853 | |
e0d3bafd | 854 | printk(KERN_INFO "Successfully loaded cx231xx-dvb\n"); |
e0d3bafd | 855 | |
761f6cf6 | 856 | ret: |
e0d3bafd | 857 | cx231xx_set_mode(dev, CX231XX_SUSPEND); |
761f6cf6 DH |
858 | mutex_unlock(&dev->lock); |
859 | return result; | |
860 | ||
861 | out_free: | |
e0d3bafd SD |
862 | kfree(dvb); |
863 | dev->dvb = NULL; | |
761f6cf6 | 864 | goto ret; |
e0d3bafd SD |
865 | } |
866 | ||
867 | static int dvb_fini(struct cx231xx *dev) | |
868 | { | |
869 | if (!dev->board.has_dvb) { | |
870 | /* This device does not support the extension */ | |
871 | return 0; | |
872 | } | |
873 | ||
874 | if (dev->dvb) { | |
875 | unregister_dvb(dev->dvb); | |
876 | dev->dvb = NULL; | |
877 | } | |
878 | ||
879 | return 0; | |
880 | } | |
881 | ||
882 | static struct cx231xx_ops dvb_ops = { | |
84b5dbf3 | 883 | .id = CX231XX_DVB, |
e0d3bafd SD |
884 | .name = "Cx231xx dvb Extension", |
885 | .init = dvb_init, | |
886 | .fini = dvb_fini, | |
887 | }; | |
888 | ||
889 | static int __init cx231xx_dvb_register(void) | |
890 | { | |
891 | return cx231xx_register_extension(&dvb_ops); | |
892 | } | |
893 | ||
894 | static void __exit cx231xx_dvb_unregister(void) | |
895 | { | |
896 | cx231xx_unregister_extension(&dvb_ops); | |
897 | } | |
898 | ||
899 | module_init(cx231xx_dvb_register); | |
900 | module_exit(cx231xx_dvb_unregister); |