3 * some helper function for simple DVB cards which simply DMA the
4 * complete transport stream and let the computer sort everything else
5 * (i.e. we are using the software demux, ...). Also uses the
6 * video-buf to manage DMA buffers.
8 * (c) 2004 Gerd Knorr <kraxel@bytesex.org> [SUSE Labs]
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
16 #include <linux/module.h>
17 #include <linux/init.h>
18 #include <linux/device.h>
20 #include <linux/kthread.h>
21 #include <linux/file.h>
22 #include <linux/suspend.h>
24 #include <media/video-buf.h>
25 #include <media/video-buf-dvb.h>
27 /* ------------------------------------------------------------------ */
29 MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
30 MODULE_LICENSE("GPL");
32 static unsigned int debug = 0;
33 module_param(debug, int, 0644);
34 MODULE_PARM_DESC(debug,"enable debug messages");
36 #define dprintk(fmt, arg...) if (debug) \
37 printk(KERN_DEBUG "%s/dvb: " fmt, dvb->name , ## arg)
39 /* ------------------------------------------------------------------ */
41 static int videobuf_dvb_thread(void *data)
43 struct videobuf_dvb *dvb = data;
44 struct videobuf_buffer *buf;
48 dprintk("dvb thread started\n");
49 videobuf_read_start(&dvb->dvbq);
52 /* fetch next buffer */
53 buf = list_entry(dvb->dvbq.stream.next,
54 struct videobuf_buffer, stream);
55 list_del(&buf->stream);
56 err = videobuf_waiton(buf,0,1);
59 /* no more feeds left or stop_feed() asked us to quit */
62 if (kthread_should_stop())
66 /* feed buffer data to demux */
67 if (buf->state == STATE_DONE)
68 dvb_dmx_swfilter(&dvb->demux, buf->dma.vmalloc,
72 list_add_tail(&buf->stream,&dvb->dvbq.stream);
73 spin_lock_irqsave(dvb->dvbq.irqlock,flags);
74 dvb->dvbq.ops->buf_queue(&dvb->dvbq,buf);
75 spin_unlock_irqrestore(dvb->dvbq.irqlock,flags);
78 videobuf_read_stop(&dvb->dvbq);
79 dprintk("dvb thread stopped\n");
81 /* Hmm, linux becomes *very* unhappy without this ... */
82 while (!kthread_should_stop()) {
83 set_current_state(TASK_INTERRUPTIBLE);
89 static int videobuf_dvb_start_feed(struct dvb_demux_feed *feed)
91 struct dvb_demux *demux = feed->demux;
92 struct videobuf_dvb *dvb = demux->priv;
95 if (!demux->dmx.frontend)
102 if (NULL != dvb->thread)
104 dvb->thread = kthread_run(videobuf_dvb_thread,
105 dvb, "%s dvb", dvb->name);
106 if (IS_ERR(dvb->thread)) {
107 rc = PTR_ERR(dvb->thread);
116 static int videobuf_dvb_stop_feed(struct dvb_demux_feed *feed)
118 struct dvb_demux *demux = feed->demux;
119 struct videobuf_dvb *dvb = demux->priv;
124 if (0 == dvb->nfeeds && NULL != dvb->thread) {
125 // FIXME: cx8802_cancel_buffers(dev);
126 err = kthread_stop(dvb->thread);
133 /* ------------------------------------------------------------------ */
135 int videobuf_dvb_register(struct videobuf_dvb *dvb,
136 struct module *module,
141 init_MUTEX(&dvb->lock);
143 /* register adapter */
144 result = dvb_register_adapter(&dvb->adapter, dvb->name, module);
146 printk(KERN_WARNING "%s: dvb_register_adapter failed (errno = %d)\n",
150 dvb->adapter.priv = adapter_priv;
152 /* register frontend */
153 result = dvb_register_frontend(&dvb->adapter, dvb->frontend);
155 printk(KERN_WARNING "%s: dvb_register_frontend failed (errno = %d)\n",
160 /* register demux stuff */
161 dvb->demux.dmx.capabilities =
162 DMX_TS_FILTERING | DMX_SECTION_FILTERING |
163 DMX_MEMORY_BASED_FILTERING;
164 dvb->demux.priv = dvb;
165 dvb->demux.filternum = 256;
166 dvb->demux.feednum = 256;
167 dvb->demux.start_feed = videobuf_dvb_start_feed;
168 dvb->demux.stop_feed = videobuf_dvb_stop_feed;
169 result = dvb_dmx_init(&dvb->demux);
171 printk(KERN_WARNING "%s: dvb_dmx_init failed (errno = %d)\n",
176 dvb->dmxdev.filternum = 256;
177 dvb->dmxdev.demux = &dvb->demux.dmx;
178 dvb->dmxdev.capabilities = 0;
179 result = dvb_dmxdev_init(&dvb->dmxdev, &dvb->adapter);
181 printk(KERN_WARNING "%s: dvb_dmxdev_init failed (errno = %d)\n",
186 dvb->fe_hw.source = DMX_FRONTEND_0;
187 result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_hw);
189 printk(KERN_WARNING "%s: add_frontend failed (DMX_FRONTEND_0, errno = %d)\n",
194 dvb->fe_mem.source = DMX_MEMORY_FE;
195 result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_mem);
197 printk(KERN_WARNING "%s: add_frontend failed (DMX_MEMORY_FE, errno = %d)\n",
202 result = dvb->demux.dmx.connect_frontend(&dvb->demux.dmx, &dvb->fe_hw);
204 printk(KERN_WARNING "%s: connect_frontend failed (errno = %d)\n",
209 /* register network adapter */
210 dvb_net_init(&dvb->adapter, &dvb->net, &dvb->demux.dmx);
214 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
216 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
218 dvb_dmxdev_release(&dvb->dmxdev);
220 dvb_dmx_release(&dvb->demux);
222 dvb_unregister_frontend(dvb->frontend);
224 dvb_unregister_adapter(&dvb->adapter);
229 void videobuf_dvb_unregister(struct videobuf_dvb *dvb)
231 dvb_net_release(&dvb->net);
232 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
233 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
234 dvb_dmxdev_release(&dvb->dmxdev);
235 dvb_dmx_release(&dvb->demux);
236 dvb_unregister_frontend(dvb->frontend);
237 dvb_unregister_adapter(&dvb->adapter);
240 EXPORT_SYMBOL(videobuf_dvb_register);
241 EXPORT_SYMBOL(videobuf_dvb_unregister);
243 /* ------------------------------------------------------------------ */
247 * compile-command: "make DVB=1"