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>
19 #include <linux/slab.h>
21 #include <media/videobuf2-dvb.h>
23 /* ------------------------------------------------------------------ */
25 MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
26 MODULE_LICENSE("GPL");
28 /* ------------------------------------------------------------------ */
30 static int dvb_fnc(struct vb2_buffer
*vb
, void *priv
)
32 struct vb2_dvb
*dvb
= priv
;
34 dvb_dmx_swfilter(&dvb
->demux
, vb2_plane_vaddr(vb
, 0),
35 vb2_get_plane_payload(vb
, 0));
39 static int vb2_dvb_start_feed(struct dvb_demux_feed
*feed
)
41 struct dvb_demux
*demux
= feed
->demux
;
42 struct vb2_dvb
*dvb
= demux
->priv
;
45 if (!demux
->dmx
.frontend
)
48 mutex_lock(&dvb
->lock
);
51 if (!dvb
->dvbq
.threadio
) {
52 rc
= vb2_thread_start(&dvb
->dvbq
, dvb_fnc
, dvb
, dvb
->name
);
58 mutex_unlock(&dvb
->lock
);
62 static int vb2_dvb_stop_feed(struct dvb_demux_feed
*feed
)
64 struct dvb_demux
*demux
= feed
->demux
;
65 struct vb2_dvb
*dvb
= demux
->priv
;
68 mutex_lock(&dvb
->lock
);
71 err
= vb2_thread_stop(&dvb
->dvbq
);
72 mutex_unlock(&dvb
->lock
);
76 static int vb2_dvb_register_adapter(struct vb2_dvb_frontends
*fe
,
77 struct module
*module
,
79 struct device
*device
,
86 mutex_init(&fe
->lock
);
88 /* register adapter */
89 result
= dvb_register_adapter(&fe
->adapter
, adapter_name
, module
,
92 pr_warn("%s: dvb_register_adapter failed (errno = %d)\n",
93 adapter_name
, result
);
95 fe
->adapter
.priv
= adapter_priv
;
96 fe
->adapter
.mfe_shared
= mfe_shared
;
101 static int vb2_dvb_register_frontend(struct dvb_adapter
*adapter
,
106 /* register frontend */
107 result
= dvb_register_frontend(adapter
, dvb
->frontend
);
109 pr_warn("%s: dvb_register_frontend failed (errno = %d)\n",
114 /* register demux stuff */
115 dvb
->demux
.dmx
.capabilities
=
116 DMX_TS_FILTERING
| DMX_SECTION_FILTERING
|
117 DMX_MEMORY_BASED_FILTERING
;
118 dvb
->demux
.priv
= dvb
;
119 dvb
->demux
.filternum
= 256;
120 dvb
->demux
.feednum
= 256;
121 dvb
->demux
.start_feed
= vb2_dvb_start_feed
;
122 dvb
->demux
.stop_feed
= vb2_dvb_stop_feed
;
123 result
= dvb_dmx_init(&dvb
->demux
);
125 pr_warn("%s: dvb_dmx_init failed (errno = %d)\n",
130 dvb
->dmxdev
.filternum
= 256;
131 dvb
->dmxdev
.demux
= &dvb
->demux
.dmx
;
132 dvb
->dmxdev
.capabilities
= 0;
133 result
= dvb_dmxdev_init(&dvb
->dmxdev
, adapter
);
136 pr_warn("%s: dvb_dmxdev_init failed (errno = %d)\n",
141 dvb
->fe_hw
.source
= DMX_FRONTEND_0
;
142 result
= dvb
->demux
.dmx
.add_frontend(&dvb
->demux
.dmx
, &dvb
->fe_hw
);
144 pr_warn("%s: add_frontend failed (DMX_FRONTEND_0, errno = %d)\n",
149 dvb
->fe_mem
.source
= DMX_MEMORY_FE
;
150 result
= dvb
->demux
.dmx
.add_frontend(&dvb
->demux
.dmx
, &dvb
->fe_mem
);
152 pr_warn("%s: add_frontend failed (DMX_MEMORY_FE, errno = %d)\n",
157 result
= dvb
->demux
.dmx
.connect_frontend(&dvb
->demux
.dmx
, &dvb
->fe_hw
);
159 pr_warn("%s: connect_frontend failed (errno = %d)\n",
164 /* register network adapter */
165 result
= dvb_net_init(adapter
, &dvb
->net
, &dvb
->demux
.dmx
);
167 pr_warn("%s: dvb_net_init failed (errno = %d)\n",
174 dvb
->demux
.dmx
.remove_frontend(&dvb
->demux
.dmx
, &dvb
->fe_mem
);
176 dvb
->demux
.dmx
.remove_frontend(&dvb
->demux
.dmx
, &dvb
->fe_hw
);
178 dvb_dmxdev_release(&dvb
->dmxdev
);
180 dvb_dmx_release(&dvb
->demux
);
182 dvb_unregister_frontend(dvb
->frontend
);
184 dvb_frontend_detach(dvb
->frontend
);
185 dvb
->frontend
= NULL
;
190 /* ------------------------------------------------------------------ */
191 /* Register a single adapter and one or more frontends */
192 int vb2_dvb_register_bus(struct vb2_dvb_frontends
*f
,
193 struct module
*module
,
195 struct device
*device
,
199 struct list_head
*list
, *q
;
200 struct vb2_dvb_frontend
*fe
;
203 fe
= vb2_dvb_get_frontend(f
, 1);
205 pr_warn("Unable to register the adapter which has no frontends\n");
209 /* Bring up the adapter */
210 res
= vb2_dvb_register_adapter(f
, module
, adapter_priv
, device
,
211 fe
->dvb
.name
, adapter_nr
, mfe_shared
);
213 pr_warn("vb2_dvb_register_adapter failed (errno = %d)\n", res
);
217 /* Attach all of the frontends to the adapter */
218 mutex_lock(&f
->lock
);
219 list_for_each_safe(list
, q
, &f
->felist
) {
220 fe
= list_entry(list
, struct vb2_dvb_frontend
, felist
);
221 res
= vb2_dvb_register_frontend(&f
->adapter
, &fe
->dvb
);
223 pr_warn("%s: vb2_dvb_register_frontend failed (errno = %d)\n",
228 mutex_unlock(&f
->lock
);
232 mutex_unlock(&f
->lock
);
233 vb2_dvb_unregister_bus(f
);
236 EXPORT_SYMBOL(vb2_dvb_register_bus
);
238 void vb2_dvb_unregister_bus(struct vb2_dvb_frontends
*f
)
240 vb2_dvb_dealloc_frontends(f
);
242 dvb_unregister_adapter(&f
->adapter
);
244 EXPORT_SYMBOL(vb2_dvb_unregister_bus
);
246 struct vb2_dvb_frontend
*vb2_dvb_get_frontend(
247 struct vb2_dvb_frontends
*f
, int id
)
249 struct list_head
*list
, *q
;
250 struct vb2_dvb_frontend
*fe
, *ret
= NULL
;
252 mutex_lock(&f
->lock
);
254 list_for_each_safe(list
, q
, &f
->felist
) {
255 fe
= list_entry(list
, struct vb2_dvb_frontend
, felist
);
262 mutex_unlock(&f
->lock
);
266 EXPORT_SYMBOL(vb2_dvb_get_frontend
);
268 int vb2_dvb_find_frontend(struct vb2_dvb_frontends
*f
,
269 struct dvb_frontend
*p
)
271 struct list_head
*list
, *q
;
272 struct vb2_dvb_frontend
*fe
= NULL
;
275 mutex_lock(&f
->lock
);
277 list_for_each_safe(list
, q
, &f
->felist
) {
278 fe
= list_entry(list
, struct vb2_dvb_frontend
, felist
);
279 if (fe
->dvb
.frontend
== p
) {
285 mutex_unlock(&f
->lock
);
289 EXPORT_SYMBOL(vb2_dvb_find_frontend
);
291 struct vb2_dvb_frontend
*vb2_dvb_alloc_frontend(
292 struct vb2_dvb_frontends
*f
, int id
)
294 struct vb2_dvb_frontend
*fe
;
296 fe
= kzalloc(sizeof(struct vb2_dvb_frontend
), GFP_KERNEL
);
301 mutex_init(&fe
->dvb
.lock
);
303 mutex_lock(&f
->lock
);
304 list_add_tail(&fe
->felist
, &f
->felist
);
305 mutex_unlock(&f
->lock
);
308 EXPORT_SYMBOL(vb2_dvb_alloc_frontend
);
310 void vb2_dvb_dealloc_frontends(struct vb2_dvb_frontends
*f
)
312 struct list_head
*list
, *q
;
313 struct vb2_dvb_frontend
*fe
;
315 mutex_lock(&f
->lock
);
316 list_for_each_safe(list
, q
, &f
->felist
) {
317 fe
= list_entry(list
, struct vb2_dvb_frontend
, felist
);
318 if (fe
->dvb
.net
.dvbdev
) {
319 dvb_net_release(&fe
->dvb
.net
);
320 fe
->dvb
.demux
.dmx
.remove_frontend(&fe
->dvb
.demux
.dmx
,
322 fe
->dvb
.demux
.dmx
.remove_frontend(&fe
->dvb
.demux
.dmx
,
324 dvb_dmxdev_release(&fe
->dvb
.dmxdev
);
325 dvb_dmx_release(&fe
->dvb
.demux
);
326 dvb_unregister_frontend(fe
->dvb
.frontend
);
328 if (fe
->dvb
.frontend
)
329 /* always allocated, may have been reset */
330 dvb_frontend_detach(fe
->dvb
.frontend
);
331 list_del(list
); /* remove list entry */
332 kfree(fe
); /* free frontend allocation */
334 mutex_unlock(&f
->lock
);
336 EXPORT_SYMBOL(vb2_dvb_dealloc_frontends
);