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
,
80 struct media_device
*mdev
,
87 mutex_init(&fe
->lock
);
89 /* register adapter */
90 result
= dvb_register_adapter(&fe
->adapter
, adapter_name
, module
,
93 pr_warn("%s: dvb_register_adapter failed (errno = %d)\n",
94 adapter_name
, result
);
96 fe
->adapter
.priv
= adapter_priv
;
97 fe
->adapter
.mfe_shared
= mfe_shared
;
98 #ifdef CONFIG_MEDIA_CONTROLLER_DVB
100 fe
->adapter
.mdev
= mdev
;
105 static int vb2_dvb_register_frontend(struct dvb_adapter
*adapter
,
110 /* register frontend */
111 result
= dvb_register_frontend(adapter
, dvb
->frontend
);
113 pr_warn("%s: dvb_register_frontend failed (errno = %d)\n",
118 /* register demux stuff */
119 dvb
->demux
.dmx
.capabilities
=
120 DMX_TS_FILTERING
| DMX_SECTION_FILTERING
|
121 DMX_MEMORY_BASED_FILTERING
;
122 dvb
->demux
.priv
= dvb
;
123 dvb
->demux
.filternum
= 256;
124 dvb
->demux
.feednum
= 256;
125 dvb
->demux
.start_feed
= vb2_dvb_start_feed
;
126 dvb
->demux
.stop_feed
= vb2_dvb_stop_feed
;
127 result
= dvb_dmx_init(&dvb
->demux
);
129 pr_warn("%s: dvb_dmx_init failed (errno = %d)\n",
134 dvb
->dmxdev
.filternum
= 256;
135 dvb
->dmxdev
.demux
= &dvb
->demux
.dmx
;
136 dvb
->dmxdev
.capabilities
= 0;
137 result
= dvb_dmxdev_init(&dvb
->dmxdev
, adapter
);
140 pr_warn("%s: dvb_dmxdev_init failed (errno = %d)\n",
145 dvb
->fe_hw
.source
= DMX_FRONTEND_0
;
146 result
= dvb
->demux
.dmx
.add_frontend(&dvb
->demux
.dmx
, &dvb
->fe_hw
);
148 pr_warn("%s: add_frontend failed (DMX_FRONTEND_0, errno = %d)\n",
153 dvb
->fe_mem
.source
= DMX_MEMORY_FE
;
154 result
= dvb
->demux
.dmx
.add_frontend(&dvb
->demux
.dmx
, &dvb
->fe_mem
);
156 pr_warn("%s: add_frontend failed (DMX_MEMORY_FE, errno = %d)\n",
161 result
= dvb
->demux
.dmx
.connect_frontend(&dvb
->demux
.dmx
, &dvb
->fe_hw
);
163 pr_warn("%s: connect_frontend failed (errno = %d)\n",
168 /* register network adapter */
169 result
= dvb_net_init(adapter
, &dvb
->net
, &dvb
->demux
.dmx
);
171 pr_warn("%s: dvb_net_init failed (errno = %d)\n",
178 dvb
->demux
.dmx
.remove_frontend(&dvb
->demux
.dmx
, &dvb
->fe_mem
);
180 dvb
->demux
.dmx
.remove_frontend(&dvb
->demux
.dmx
, &dvb
->fe_hw
);
182 dvb_dmxdev_release(&dvb
->dmxdev
);
184 dvb_dmx_release(&dvb
->demux
);
186 dvb_unregister_frontend(dvb
->frontend
);
188 dvb_frontend_detach(dvb
->frontend
);
189 dvb
->frontend
= NULL
;
194 /* ------------------------------------------------------------------ */
195 /* Register a single adapter and one or more frontends */
196 int vb2_dvb_register_bus(struct vb2_dvb_frontends
*f
,
197 struct module
*module
,
199 struct device
*device
,
200 struct media_device
*mdev
,
204 struct list_head
*list
, *q
;
205 struct vb2_dvb_frontend
*fe
;
208 fe
= vb2_dvb_get_frontend(f
, 1);
210 pr_warn("Unable to register the adapter which has no frontends\n");
214 /* Bring up the adapter */
215 res
= vb2_dvb_register_adapter(f
, module
, adapter_priv
, device
, mdev
,
216 fe
->dvb
.name
, adapter_nr
, mfe_shared
);
218 pr_warn("vb2_dvb_register_adapter failed (errno = %d)\n", res
);
222 /* Attach all of the frontends to the adapter */
223 mutex_lock(&f
->lock
);
224 list_for_each_safe(list
, q
, &f
->felist
) {
225 fe
= list_entry(list
, struct vb2_dvb_frontend
, felist
);
226 res
= vb2_dvb_register_frontend(&f
->adapter
, &fe
->dvb
);
228 pr_warn("%s: vb2_dvb_register_frontend failed (errno = %d)\n",
232 res
= dvb_create_media_graph(&f
->adapter
, false);
237 mutex_unlock(&f
->lock
);
241 mutex_unlock(&f
->lock
);
242 vb2_dvb_unregister_bus(f
);
245 EXPORT_SYMBOL(vb2_dvb_register_bus
);
247 void vb2_dvb_unregister_bus(struct vb2_dvb_frontends
*f
)
249 vb2_dvb_dealloc_frontends(f
);
251 dvb_unregister_adapter(&f
->adapter
);
253 EXPORT_SYMBOL(vb2_dvb_unregister_bus
);
255 struct vb2_dvb_frontend
*vb2_dvb_get_frontend(
256 struct vb2_dvb_frontends
*f
, int id
)
258 struct list_head
*list
, *q
;
259 struct vb2_dvb_frontend
*fe
, *ret
= NULL
;
261 mutex_lock(&f
->lock
);
263 list_for_each_safe(list
, q
, &f
->felist
) {
264 fe
= list_entry(list
, struct vb2_dvb_frontend
, felist
);
271 mutex_unlock(&f
->lock
);
275 EXPORT_SYMBOL(vb2_dvb_get_frontend
);
277 int vb2_dvb_find_frontend(struct vb2_dvb_frontends
*f
,
278 struct dvb_frontend
*p
)
280 struct list_head
*list
, *q
;
281 struct vb2_dvb_frontend
*fe
= NULL
;
284 mutex_lock(&f
->lock
);
286 list_for_each_safe(list
, q
, &f
->felist
) {
287 fe
= list_entry(list
, struct vb2_dvb_frontend
, felist
);
288 if (fe
->dvb
.frontend
== p
) {
294 mutex_unlock(&f
->lock
);
298 EXPORT_SYMBOL(vb2_dvb_find_frontend
);
300 struct vb2_dvb_frontend
*vb2_dvb_alloc_frontend(
301 struct vb2_dvb_frontends
*f
, int id
)
303 struct vb2_dvb_frontend
*fe
;
305 fe
= kzalloc(sizeof(struct vb2_dvb_frontend
), GFP_KERNEL
);
310 mutex_init(&fe
->dvb
.lock
);
312 mutex_lock(&f
->lock
);
313 list_add_tail(&fe
->felist
, &f
->felist
);
314 mutex_unlock(&f
->lock
);
317 EXPORT_SYMBOL(vb2_dvb_alloc_frontend
);
319 void vb2_dvb_dealloc_frontends(struct vb2_dvb_frontends
*f
)
321 struct list_head
*list
, *q
;
322 struct vb2_dvb_frontend
*fe
;
324 mutex_lock(&f
->lock
);
325 list_for_each_safe(list
, q
, &f
->felist
) {
326 fe
= list_entry(list
, struct vb2_dvb_frontend
, felist
);
327 if (fe
->dvb
.net
.dvbdev
) {
328 dvb_net_release(&fe
->dvb
.net
);
329 fe
->dvb
.demux
.dmx
.remove_frontend(&fe
->dvb
.demux
.dmx
,
331 fe
->dvb
.demux
.dmx
.remove_frontend(&fe
->dvb
.demux
.dmx
,
333 dvb_dmxdev_release(&fe
->dvb
.dmxdev
);
334 dvb_dmx_release(&fe
->dvb
.demux
);
335 dvb_unregister_frontend(fe
->dvb
.frontend
);
337 if (fe
->dvb
.frontend
)
338 /* always allocated, may have been reset */
339 dvb_frontend_detach(fe
->dvb
.frontend
);
340 list_del(list
); /* remove list entry */
341 kfree(fe
); /* free frontend allocation */
343 mutex_unlock(&f
->lock
);
345 EXPORT_SYMBOL(vb2_dvb_dealloc_frontends
);