blob: ee88ae83230c26ca7df038e288ad800d47e45582 [file] [log] [blame]
Michel Ludwig3169c9b2007-08-21 17:37:22 -03001/*
Ruslan Pisarevd0058642010-10-20 06:35:54 -03002 * tm6000-dvb.c - dvb-t support for TM5600/TM6000/TM6010 USB video capture devices
3 *
4 * Copyright (C) 2007 Michel Ludwig <michel.ludwig@gmail.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation version 2
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Michel Ludwig3169c9b2007-08-21 17:37:22 -030018 */
19
Stefan Ringel08e60ba2010-02-05 20:06:52 -030020#include <linux/kernel.h>
Tejun Heo4ef09882010-03-30 02:52:33 +090021#include <linux/slab.h>
Michel Ludwig3169c9b2007-08-21 17:37:22 -030022#include <linux/usb.h>
23
24#include "tm6000.h"
25#include "tm6000-regs.h"
26
Michel Ludwig3169c9b2007-08-21 17:37:22 -030027#include "zl10353.h"
28
29#include <media/tuner.h>
30
Michel Ludwig5b74c2c2007-11-16 13:16:59 -030031#include "tuner-xc2028.h"
Stefan Ringel7e2d9822010-05-23 15:31:44 -030032#include "xc5000.h"
Michel Ludwig5b74c2c2007-11-16 13:16:59 -030033
Stefan Ringelcee39262010-05-30 09:19:04 -030034MODULE_DESCRIPTION("DVB driver extension module for tm5600/6000/6010 based TV cards");
Mauro Carvalho Chehab37e59f82014-02-07 08:03:07 -020035MODULE_AUTHOR("Mauro Carvalho Chehab");
Stefan Ringelcee39262010-05-30 09:19:04 -030036MODULE_LICENSE("GPL");
37
38MODULE_SUPPORTED_DEVICE("{{Trident, tm5600},"
39 "{{Trident, tm6000},"
40 "{{Trident, tm6010}");
41
42static int debug;
43
44module_param(debug, int, 0644);
45MODULE_PARM_DESC(debug, "enable debug message");
46
Timofey Trofimov52e0a722010-05-29 13:52:46 -030047static inline void print_err_status(struct tm6000_core *dev,
48 int packet, int status)
Stefan Ringel08e60ba2010-02-05 20:06:52 -030049{
50 char *errmsg = "Unknown";
51
Timofey Trofimov52e0a722010-05-29 13:52:46 -030052 switch (status) {
Stefan Ringel08e60ba2010-02-05 20:06:52 -030053 case -ENOENT:
54 errmsg = "unlinked synchronuously";
55 break;
56 case -ECONNRESET:
57 errmsg = "unlinked asynchronuously";
58 break;
59 case -ENOSR:
60 errmsg = "Buffer error (overrun)";
61 break;
62 case -EPIPE:
63 errmsg = "Stalled (device not responding)";
64 break;
65 case -EOVERFLOW:
66 errmsg = "Babble (bad cable?)";
67 break;
68 case -EPROTO:
69 errmsg = "Bit-stuff error (bad cable?)";
70 break;
71 case -EILSEQ:
72 errmsg = "CRC/Timeout (could be anything)";
73 break;
74 case -ETIME:
75 errmsg = "Device does not respond";
76 break;
77 }
Timofey Trofimov52e0a722010-05-29 13:52:46 -030078 if (packet < 0) {
Stefan Ringel08e60ba2010-02-05 20:06:52 -030079 dprintk(dev, 1, "URB status %d [%s].\n",
80 status, errmsg);
81 } else {
82 dprintk(dev, 1, "URB packet %d, status %d [%s].\n",
83 packet, status, errmsg);
84 }
85}
86
Michel Ludwig3169c9b2007-08-21 17:37:22 -030087static void tm6000_urb_received(struct urb *urb)
88{
89 int ret;
Timofey Trofimov52e0a722010-05-29 13:52:46 -030090 struct tm6000_core *dev = urb->context;
Michel Ludwig3169c9b2007-08-21 17:37:22 -030091
Stefan Ringelde2a20b2011-11-28 15:46:19 -030092 switch (urb->status) {
93 case 0:
94 case -ETIMEDOUT:
95 break;
96 case -ENOENT:
97 case -ECONNRESET:
98 case -ESHUTDOWN:
99 return;
100 default:
Timofey Trofimov52e0a722010-05-29 13:52:46 -0300101 print_err_status(dev, 0, urb->status);
Stefan Ringelde2a20b2011-11-28 15:46:19 -0300102 }
103
104 if (urb->actual_length > 0)
Michel Ludwig3169c9b2007-08-21 17:37:22 -0300105 dvb_dmx_swfilter(&dev->dvb->demux, urb->transfer_buffer,
106 urb->actual_length);
Michel Ludwig3169c9b2007-08-21 17:37:22 -0300107
Timofey Trofimov52e0a722010-05-29 13:52:46 -0300108 if (dev->dvb->streams > 0) {
Michel Ludwig3169c9b2007-08-21 17:37:22 -0300109 ret = usb_submit_urb(urb, GFP_ATOMIC);
Timofey Trofimov52e0a722010-05-29 13:52:46 -0300110 if (ret < 0) {
Curtis McEnroe94b27662011-06-02 20:33:31 -0400111 printk(KERN_ERR "tm6000: error %s\n", __func__);
Michel Ludwig3169c9b2007-08-21 17:37:22 -0300112 kfree(urb->transfer_buffer);
113 usb_free_urb(urb);
114 }
115 }
116}
117
Thierry Reding3d1a51d2011-08-04 04:14:01 -0300118static int tm6000_start_stream(struct tm6000_core *dev)
Michel Ludwig3169c9b2007-08-21 17:37:22 -0300119{
120 int ret;
Stefan Ringel08e60ba2010-02-05 20:06:52 -0300121 unsigned int pipe, size;
Michel Ludwig3169c9b2007-08-21 17:37:22 -0300122 struct tm6000_dvb *dvb = dev->dvb;
123
Curtis McEnroe94b27662011-06-02 20:33:31 -0400124 printk(KERN_INFO "tm6000: got start stream request %s\n", __func__);
Michel Ludwig3169c9b2007-08-21 17:37:22 -0300125
Stefan Ringeldcf5d3a2010-05-23 15:29:26 -0300126 if (dev->mode != TM6000_MODE_DIGITAL) {
127 tm6000_init_digital_mode(dev);
128 dev->mode = TM6000_MODE_DIGITAL;
129 }
Michel Ludwig3169c9b2007-08-21 17:37:22 -0300130
Michel Ludwig3169c9b2007-08-21 17:37:22 -0300131 dvb->bulk_urb = usb_alloc_urb(0, GFP_KERNEL);
Wolfram Sang5d54a422016-08-11 23:04:01 +0200132 if (dvb->bulk_urb == NULL)
Michel Ludwig3169c9b2007-08-21 17:37:22 -0300133 return -ENOMEM;
Michel Ludwig3169c9b2007-08-21 17:37:22 -0300134
Mauro Carvalho Chehab6ae635c2010-04-26 11:24:18 -0300135 pipe = usb_rcvbulkpipe(dev->udev, dev->bulk_in.endp->desc.bEndpointAddress
Stefan Ringel08e60ba2010-02-05 20:06:52 -0300136 & USB_ENDPOINT_NUMBER_MASK);
Michel Ludwig3169c9b2007-08-21 17:37:22 -0300137
Stefan Ringel08e60ba2010-02-05 20:06:52 -0300138 size = usb_maxpacket(dev->udev, pipe, usb_pipeout(pipe));
139 size = size * 15; /* 512 x 8 or 12 or 15 */
140
141 dvb->bulk_urb->transfer_buffer = kzalloc(size, GFP_KERNEL);
Timofey Trofimov52e0a722010-05-29 13:52:46 -0300142 if (dvb->bulk_urb->transfer_buffer == NULL) {
Michel Ludwig3169c9b2007-08-21 17:37:22 -0300143 usb_free_urb(dvb->bulk_urb);
144 printk(KERN_ERR "tm6000: couldn't allocate transfer buffer!\n");
145 return -ENOMEM;
146 }
147
Michel Ludwig3169c9b2007-08-21 17:37:22 -0300148 usb_fill_bulk_urb(dvb->bulk_urb, dev->udev, pipe,
149 dvb->bulk_urb->transfer_buffer,
Stefan Ringel08e60ba2010-02-05 20:06:52 -0300150 size,
Michel Ludwig3169c9b2007-08-21 17:37:22 -0300151 tm6000_urb_received, dev);
Michel Ludwig43861362007-09-24 17:01:49 -0300152
Michel Ludwig3169c9b2007-08-21 17:37:22 -0300153 ret = usb_clear_halt(dev->udev, pipe);
Timofey Trofimov52e0a722010-05-29 13:52:46 -0300154 if (ret < 0) {
155 printk(KERN_ERR "tm6000: error %i in %s during pipe reset\n",
Curtis McEnroe94b27662011-06-02 20:33:31 -0400156 ret, __func__);
Michel Ludwig43861362007-09-24 17:01:49 -0300157 return ret;
Timofey Trofimov52e0a722010-05-29 13:52:46 -0300158 } else
Michel Ludwig3169c9b2007-08-21 17:37:22 -0300159 printk(KERN_ERR "tm6000: pipe resetted\n");
Michel Ludwig3169c9b2007-08-21 17:37:22 -0300160
Stefan Ringel08e60ba2010-02-05 20:06:52 -0300161/* mutex_lock(&tm6000_driver.open_close_mutex); */
Stefan Ringelde2a20b2011-11-28 15:46:19 -0300162 ret = usb_submit_urb(dvb->bulk_urb, GFP_ATOMIC);
Michel Ludwig3169c9b2007-08-21 17:37:22 -0300163
Stefan Ringel08e60ba2010-02-05 20:06:52 -0300164/* mutex_unlock(&tm6000_driver.open_close_mutex); */
Michel Ludwig3169c9b2007-08-21 17:37:22 -0300165 if (ret) {
Timofey Trofimov52e0a722010-05-29 13:52:46 -0300166 printk(KERN_ERR "tm6000: submit of urb failed (error=%i)\n",
167 ret);
Michel Ludwig3169c9b2007-08-21 17:37:22 -0300168
169 kfree(dvb->bulk_urb->transfer_buffer);
170 usb_free_urb(dvb->bulk_urb);
171 return ret;
172 }
173
174 return 0;
175}
176
Thierry Reding3d1a51d2011-08-04 04:14:01 -0300177static void tm6000_stop_stream(struct tm6000_core *dev)
Michel Ludwig3169c9b2007-08-21 17:37:22 -0300178{
179 struct tm6000_dvb *dvb = dev->dvb;
180
Timofey Trofimov52e0a722010-05-29 13:52:46 -0300181 if (dvb->bulk_urb) {
182 printk(KERN_INFO "urb killing\n");
Michel Ludwig3169c9b2007-08-21 17:37:22 -0300183 usb_kill_urb(dvb->bulk_urb);
Timofey Trofimov52e0a722010-05-29 13:52:46 -0300184 printk(KERN_INFO "urb buffer free\n");
Michel Ludwig3169c9b2007-08-21 17:37:22 -0300185 kfree(dvb->bulk_urb->transfer_buffer);
186 usb_free_urb(dvb->bulk_urb);
187 dvb->bulk_urb = NULL;
188 }
189}
190
Thierry Reding3d1a51d2011-08-04 04:14:01 -0300191static int tm6000_start_feed(struct dvb_demux_feed *feed)
Michel Ludwig3169c9b2007-08-21 17:37:22 -0300192{
193 struct dvb_demux *demux = feed->demux;
194 struct tm6000_core *dev = demux->priv;
195 struct tm6000_dvb *dvb = dev->dvb;
Curtis McEnroe94b27662011-06-02 20:33:31 -0400196 printk(KERN_INFO "tm6000: got start feed request %s\n", __func__);
Michel Ludwig3169c9b2007-08-21 17:37:22 -0300197
198 mutex_lock(&dvb->mutex);
Timofey Trofimov52e0a722010-05-29 13:52:46 -0300199 if (dvb->streams == 0) {
Michel Ludwig3169c9b2007-08-21 17:37:22 -0300200 dvb->streams = 1;
Stefan Ringel08e60ba2010-02-05 20:06:52 -0300201/* mutex_init(&tm6000_dev->streming_mutex); */
Michel Ludwig3169c9b2007-08-21 17:37:22 -0300202 tm6000_start_stream(dev);
Timofey Trofimov52e0a722010-05-29 13:52:46 -0300203 } else
Michel Ludwig3169c9b2007-08-21 17:37:22 -0300204 ++(dvb->streams);
Michel Ludwig3169c9b2007-08-21 17:37:22 -0300205 mutex_unlock(&dvb->mutex);
206
207 return 0;
208}
209
Thierry Reding3d1a51d2011-08-04 04:14:01 -0300210static int tm6000_stop_feed(struct dvb_demux_feed *feed)
Timofey Trofimov52e0a722010-05-29 13:52:46 -0300211{
Michel Ludwig3169c9b2007-08-21 17:37:22 -0300212 struct dvb_demux *demux = feed->demux;
213 struct tm6000_core *dev = demux->priv;
214 struct tm6000_dvb *dvb = dev->dvb;
215
Curtis McEnroe94b27662011-06-02 20:33:31 -0400216 printk(KERN_INFO "tm6000: got stop feed request %s\n", __func__);
Michel Ludwig3169c9b2007-08-21 17:37:22 -0300217
218 mutex_lock(&dvb->mutex);
Michel Ludwig3169c9b2007-08-21 17:37:22 -0300219
Timofey Trofimov52e0a722010-05-29 13:52:46 -0300220 printk(KERN_INFO "stream %#x\n", dvb->streams);
Stefan Ringel08e60ba2010-02-05 20:06:52 -0300221 --(dvb->streams);
Timofey Trofimov52e0a722010-05-29 13:52:46 -0300222 if (dvb->streams == 0) {
223 printk(KERN_INFO "stop stream\n");
Michel Ludwig3169c9b2007-08-21 17:37:22 -0300224 tm6000_stop_stream(dev);
Stefan Ringel08e60ba2010-02-05 20:06:52 -0300225/* mutex_destroy(&tm6000_dev->streaming_mutex); */
Michel Ludwig3169c9b2007-08-21 17:37:22 -0300226 }
227 mutex_unlock(&dvb->mutex);
Stefan Ringel08e60ba2010-02-05 20:06:52 -0300228/* mutex_destroy(&tm6000_dev->streaming_mutex); */
Michel Ludwig3169c9b2007-08-21 17:37:22 -0300229
230 return 0;
231}
232
Thierry Reding3d1a51d2011-08-04 04:14:01 -0300233static int tm6000_dvb_attach_frontend(struct tm6000_core *dev)
Michel Ludwig3169c9b2007-08-21 17:37:22 -0300234{
235 struct tm6000_dvb *dvb = dev->dvb;
236
Timofey Trofimov52e0a722010-05-29 13:52:46 -0300237 if (dev->caps.has_zl10353) {
238 struct zl10353_config config = {
239 .demod_address = dev->demod_addr,
Michel Ludwig3169c9b2007-08-21 17:37:22 -0300240 .no_tuner = 1,
Stefan Ringel08e60ba2010-02-05 20:06:52 -0300241 .parallel_ts = 1,
242 .if2 = 45700,
243 .disable_i2c_gate_ctrl = 1,
Michel Ludwig3169c9b2007-08-21 17:37:22 -0300244 };
245
Stefan Ringel89eeda62010-02-15 14:37:23 -0300246 dvb->frontend = dvb_attach(zl10353_attach, &config,
Michel Ludwig3169c9b2007-08-21 17:37:22 -0300247 &dev->i2c_adap);
Timofey Trofimov52e0a722010-05-29 13:52:46 -0300248 } else {
Michel Ludwig3169c9b2007-08-21 17:37:22 -0300249 printk(KERN_ERR "tm6000: no frontend defined for the device!\n");
250 return -1;
251 }
252
Michel Ludwig70bfae52007-11-19 06:10:54 -0300253 return (!dvb->frontend) ? -1 : 0;
Michel Ludwig3169c9b2007-08-21 17:37:22 -0300254}
255
Maykel Moya1b4c5b12008-04-28 19:20:26 -0300256DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
257
Thierry Reding3d1a51d2011-08-04 04:14:01 -0300258static int register_dvb(struct tm6000_core *dev)
Michel Ludwig3169c9b2007-08-21 17:37:22 -0300259{
260 int ret = -1;
261 struct tm6000_dvb *dvb = dev->dvb;
262
263 mutex_init(&dvb->mutex);
264
265 dvb->streams = 0;
266
267 /* attach the frontend */
268 ret = tm6000_dvb_attach_frontend(dev);
Timofey Trofimov52e0a722010-05-29 13:52:46 -0300269 if (ret < 0) {
Michel Ludwig3169c9b2007-08-21 17:37:22 -0300270 printk(KERN_ERR "tm6000: couldn't attach the frontend!\n");
Michel Ludwig70bfae52007-11-19 06:10:54 -0300271 goto err;
Michel Ludwig3169c9b2007-08-21 17:37:22 -0300272 }
273
274 ret = dvb_register_adapter(&dvb->adapter, "Trident TVMaster 6000 DVB-T",
Timofey Trofimov52e0a722010-05-29 13:52:46 -0300275 THIS_MODULE, &dev->udev->dev, adapter_nr);
Zhouyang Jia68fc1242018-06-11 00:39:20 -0400276 if (ret < 0) {
277 pr_err("tm6000: couldn't register the adapter!\n");
278 goto err;
279 }
280
Michel Ludwig3169c9b2007-08-21 17:37:22 -0300281 dvb->adapter.priv = dev;
282
Michel Ludwig5b74c2c2007-11-16 13:16:59 -0300283 if (dvb->frontend) {
Stefan Ringel7e2d9822010-05-23 15:31:44 -0300284 switch (dev->tuner_type) {
285 case TUNER_XC2028: {
286 struct xc2028_config cfg = {
287 .i2c_adap = &dev->i2c_adap,
288 .i2c_addr = dev->tuner_addr,
289 };
Michel Ludwig5b74c2c2007-11-16 13:16:59 -0300290
Stefan Ringel7e2d9822010-05-23 15:31:44 -0300291 dvb->frontend->callback = tm6000_tuner_callback;
292 ret = dvb_register_frontend(&dvb->adapter, dvb->frontend);
293 if (ret < 0) {
294 printk(KERN_ERR
295 "tm6000: couldn't register frontend\n");
296 goto adapter_err;
297 }
Michel Ludwig3169c9b2007-08-21 17:37:22 -0300298
Stefan Ringel7e2d9822010-05-23 15:31:44 -0300299 if (!dvb_attach(xc2028_attach, dvb->frontend, &cfg)) {
300 printk(KERN_ERR "tm6000: couldn't register "
301 "frontend (xc3028)\n");
302 ret = -EINVAL;
303 goto frontend_err;
304 }
305 printk(KERN_INFO "tm6000: XC2028/3028 asked to be "
306 "attached to frontend!\n");
307 break;
308 }
309 case TUNER_XC5000: {
310 struct xc5000_config cfg = {
311 .i2c_address = dev->tuner_addr,
312 };
313
314 dvb->frontend->callback = tm6000_xc5000_callback;
315 ret = dvb_register_frontend(&dvb->adapter, dvb->frontend);
316 if (ret < 0) {
317 printk(KERN_ERR
318 "tm6000: couldn't register frontend\n");
319 goto adapter_err;
320 }
321
322 if (!dvb_attach(xc5000_attach, dvb->frontend, &dev->i2c_adap, &cfg)) {
323 printk(KERN_ERR "tm6000: couldn't register "
324 "frontend (xc5000)\n");
325 ret = -EINVAL;
326 goto frontend_err;
327 }
328 printk(KERN_INFO "tm6000: XC5000 asked to be "
329 "attached to frontend!\n");
330 break;
331 }
Michel Ludwig5b74c2c2007-11-16 13:16:59 -0300332 }
Timofey Trofimov52e0a722010-05-29 13:52:46 -0300333 } else
Michel Ludwig5b74c2c2007-11-16 13:16:59 -0300334 printk(KERN_ERR "tm6000: no frontend found\n");
Michel Ludwig3169c9b2007-08-21 17:37:22 -0300335
336 dvb->demux.dmx.capabilities = DMX_TS_FILTERING | DMX_SECTION_FILTERING
337 | DMX_MEMORY_BASED_FILTERING;
338 dvb->demux.priv = dev;
Stefan Ringel38d75a72010-02-15 14:37:19 -0300339 dvb->demux.filternum = 8;
340 dvb->demux.feednum = 8;
Michel Ludwig3169c9b2007-08-21 17:37:22 -0300341 dvb->demux.start_feed = tm6000_start_feed;
342 dvb->demux.stop_feed = tm6000_stop_feed;
343 dvb->demux.write_to_decoder = NULL;
344 ret = dvb_dmx_init(&dvb->demux);
Timofey Trofimov52e0a722010-05-29 13:52:46 -0300345 if (ret < 0) {
Mauro Carvalho Chehab45dbf0d2011-09-23 09:26:22 -0300346 printk(KERN_ERR "tm6000: dvb_dmx_init failed (errno = %d)\n", ret);
Michel Ludwig3169c9b2007-08-21 17:37:22 -0300347 goto frontend_err;
348 }
349
350 dvb->dmxdev.filternum = dev->dvb->demux.filternum;
351 dvb->dmxdev.demux = &dev->dvb->demux.dmx;
352 dvb->dmxdev.capabilities = 0;
353
354 ret = dvb_dmxdev_init(&dvb->dmxdev, &dvb->adapter);
Timofey Trofimov52e0a722010-05-29 13:52:46 -0300355 if (ret < 0) {
Mauro Carvalho Chehab45dbf0d2011-09-23 09:26:22 -0300356 printk(KERN_ERR "tm6000: dvb_dmxdev_init failed (errno = %d)\n", ret);
Michel Ludwig3169c9b2007-08-21 17:37:22 -0300357 goto dvb_dmx_err;
358 }
359
360 return 0;
361
362dvb_dmx_err:
363 dvb_dmx_release(&dvb->demux);
364frontend_err:
Timofey Trofimov52e0a722010-05-29 13:52:46 -0300365 if (dvb->frontend) {
Michel Ludwig3169c9b2007-08-21 17:37:22 -0300366 dvb_unregister_frontend(dvb->frontend);
Julian Scheelafca99a2012-11-05 11:51:05 -0300367 dvb_frontend_detach(dvb->frontend);
Michel Ludwig3169c9b2007-08-21 17:37:22 -0300368 }
369adapter_err:
370 dvb_unregister_adapter(&dvb->adapter);
371err:
372 return ret;
373}
374
Thierry Reding3d1a51d2011-08-04 04:14:01 -0300375static void unregister_dvb(struct tm6000_core *dev)
Michel Ludwig3169c9b2007-08-21 17:37:22 -0300376{
377 struct tm6000_dvb *dvb = dev->dvb;
378
Timofey Trofimov52e0a722010-05-29 13:52:46 -0300379 if (dvb->bulk_urb != NULL) {
Michel Ludwig3169c9b2007-08-21 17:37:22 -0300380 struct urb *bulk_urb = dvb->bulk_urb;
381
382 kfree(bulk_urb->transfer_buffer);
383 bulk_urb->transfer_buffer = NULL;
384 usb_unlink_urb(bulk_urb);
385 usb_free_urb(bulk_urb);
386 }
387
Stefan Ringel08e60ba2010-02-05 20:06:52 -0300388/* mutex_lock(&tm6000_driver.open_close_mutex); */
Timofey Trofimov52e0a722010-05-29 13:52:46 -0300389 if (dvb->frontend) {
Michel Ludwig3169c9b2007-08-21 17:37:22 -0300390 dvb_unregister_frontend(dvb->frontend);
Julian Scheelafca99a2012-11-05 11:51:05 -0300391 dvb_frontend_detach(dvb->frontend);
Michel Ludwig3169c9b2007-08-21 17:37:22 -0300392 }
393
394 dvb_dmxdev_release(&dvb->dmxdev);
395 dvb_dmx_release(&dvb->demux);
396 dvb_unregister_adapter(&dvb->adapter);
397 mutex_destroy(&dvb->mutex);
Stefan Ringel08e60ba2010-02-05 20:06:52 -0300398/* mutex_unlock(&tm6000_driver.open_close_mutex); */
Michel Ludwig3169c9b2007-08-21 17:37:22 -0300399}
Stefan Ringelcee39262010-05-30 09:19:04 -0300400
401static int dvb_init(struct tm6000_core *dev)
402{
403 struct tm6000_dvb *dvb;
404 int rc;
405
406 if (!dev)
407 return 0;
408
409 if (!dev->caps.has_dvb)
410 return 0;
411
matthieu castetc81c0062011-12-16 15:34:12 -0300412 if (dev->udev->speed == USB_SPEED_FULL) {
413 printk(KERN_INFO "This USB2.0 device cannot be run on a USB1.1 port. (it lacks a hardware PID filter)\n");
414 return 0;
415 }
416
Stefan Ringelcee39262010-05-30 09:19:04 -0300417 dvb = kzalloc(sizeof(struct tm6000_dvb), GFP_KERNEL);
418 if (!dvb) {
419 printk(KERN_INFO "Cannot allocate memory\n");
420 return -ENOMEM;
421 }
422
423 dev->dvb = dvb;
424
425 rc = register_dvb(dev);
426 if (rc < 0) {
427 kfree(dvb);
428 dev->dvb = NULL;
429 return 0;
430 }
431
432 return 0;
433}
434
435static int dvb_fini(struct tm6000_core *dev)
436{
437 if (!dev)
438 return 0;
439
440 if (!dev->caps.has_dvb)
441 return 0;
442
443 if (dev->dvb) {
444 unregister_dvb(dev);
445 kfree(dev->dvb);
446 dev->dvb = NULL;
447 }
448
449 return 0;
450}
451
452static struct tm6000_ops dvb_ops = {
Mauro Carvalho Chehab39e12562010-06-03 16:31:20 -0300453 .type = TM6000_DVB,
Stefan Ringelcee39262010-05-30 09:19:04 -0300454 .name = "TM6000 dvb Extension",
455 .init = dvb_init,
456 .fini = dvb_fini,
457};
458
459static int __init tm6000_dvb_register(void)
460{
461 return tm6000_register_extension(&dvb_ops);
462}
463
464static void __exit tm6000_dvb_unregister(void)
465{
466 tm6000_unregister_extension(&dvb_ops);
467}
468
469module_init(tm6000_dvb_register);
470module_exit(tm6000_dvb_unregister);