aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/videobuf-dvb.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/media/video/videobuf-dvb.c')
-rw-r--r--drivers/media/video/videobuf-dvb.c207
1 files changed, 172 insertions, 35 deletions
diff --git a/drivers/media/video/videobuf-dvb.c b/drivers/media/video/videobuf-dvb.c
index 6e4d73ec6855..0e7dcba8e4ae 100644
--- a/drivers/media/video/videobuf-dvb.c
+++ b/drivers/media/video/videobuf-dvb.c
@@ -13,7 +13,6 @@
13 * (at your option) any later version. 13 * (at your option) any later version.
14 */ 14 */
15 15
16
17#include <linux/module.h> 16#include <linux/module.h>
18#include <linux/init.h> 17#include <linux/init.h>
19#include <linux/device.h> 18#include <linux/device.h>
@@ -127,7 +126,6 @@ static int videobuf_dvb_stop_feed(struct dvb_demux_feed *feed)
127 mutex_lock(&dvb->lock); 126 mutex_lock(&dvb->lock);
128 dvb->nfeeds--; 127 dvb->nfeeds--;
129 if (0 == dvb->nfeeds && NULL != dvb->thread) { 128 if (0 == dvb->nfeeds && NULL != dvb->thread) {
130 // FIXME: cx8802_cancel_buffers(dev);
131 err = kthread_stop(dvb->thread); 129 err = kthread_stop(dvb->thread);
132 dvb->thread = NULL; 130 dvb->thread = NULL;
133 } 131 }
@@ -135,30 +133,38 @@ static int videobuf_dvb_stop_feed(struct dvb_demux_feed *feed)
135 return err; 133 return err;
136} 134}
137 135
138/* ------------------------------------------------------------------ */ 136static int videobuf_dvb_register_adapter(struct videobuf_dvb_frontends *fe,
139
140int videobuf_dvb_register(struct videobuf_dvb *dvb,
141 struct module *module, 137 struct module *module,
142 void *adapter_priv, 138 void *adapter_priv,
143 struct device *device, 139 struct device *device,
144 short *adapter_nr) 140 char *adapter_name,
141 short *adapter_nr,
142 int mfe_shared)
145{ 143{
146 int result; 144 int result;
147 145
148 mutex_init(&dvb->lock); 146 mutex_init(&fe->lock);
149 147
150 /* register adapter */ 148 /* register adapter */
151 result = dvb_register_adapter(&dvb->adapter, dvb->name, module, device, 149 result = dvb_register_adapter(&fe->adapter, adapter_name, module,
152 adapter_nr); 150 device, adapter_nr);
153 if (result < 0) { 151 if (result < 0) {
154 printk(KERN_WARNING "%s: dvb_register_adapter failed (errno = %d)\n", 152 printk(KERN_WARNING "%s: dvb_register_adapter failed (errno = %d)\n",
155 dvb->name, result); 153 adapter_name, result);
156 goto fail_adapter;
157 } 154 }
158 dvb->adapter.priv = adapter_priv; 155 fe->adapter.priv = adapter_priv;
156 fe->adapter.mfe_shared = mfe_shared;
157
158 return result;
159}
160
161static int videobuf_dvb_register_frontend(struct dvb_adapter *adapter,
162 struct videobuf_dvb *dvb)
163{
164 int result;
159 165
160 /* register frontend */ 166 /* register frontend */
161 result = dvb_register_frontend(&dvb->adapter, dvb->frontend); 167 result = dvb_register_frontend(adapter, dvb->frontend);
162 if (result < 0) { 168 if (result < 0) {
163 printk(KERN_WARNING "%s: dvb_register_frontend failed (errno = %d)\n", 169 printk(KERN_WARNING "%s: dvb_register_frontend failed (errno = %d)\n",
164 dvb->name, result); 170 dvb->name, result);
@@ -184,7 +190,8 @@ int videobuf_dvb_register(struct videobuf_dvb *dvb,
184 dvb->dmxdev.filternum = 256; 190 dvb->dmxdev.filternum = 256;
185 dvb->dmxdev.demux = &dvb->demux.dmx; 191 dvb->dmxdev.demux = &dvb->demux.dmx;
186 dvb->dmxdev.capabilities = 0; 192 dvb->dmxdev.capabilities = 0;
187 result = dvb_dmxdev_init(&dvb->dmxdev, &dvb->adapter); 193 result = dvb_dmxdev_init(&dvb->dmxdev, adapter);
194
188 if (result < 0) { 195 if (result < 0) {
189 printk(KERN_WARNING "%s: dvb_dmxdev_init failed (errno = %d)\n", 196 printk(KERN_WARNING "%s: dvb_dmxdev_init failed (errno = %d)\n",
190 dvb->name, result); 197 dvb->name, result);
@@ -215,7 +222,11 @@ int videobuf_dvb_register(struct videobuf_dvb *dvb,
215 } 222 }
216 223
217 /* register network adapter */ 224 /* register network adapter */
218 dvb_net_init(&dvb->adapter, &dvb->net, &dvb->demux.dmx); 225 dvb_net_init(adapter, &dvb->net, &dvb->demux.dmx);
226 if (dvb->net.dvbdev == NULL) {
227 result = -ENOMEM;
228 goto fail_fe_conn;
229 }
219 return 0; 230 return 0;
220 231
221fail_fe_conn: 232fail_fe_conn:
@@ -230,31 +241,157 @@ fail_dmx:
230 dvb_unregister_frontend(dvb->frontend); 241 dvb_unregister_frontend(dvb->frontend);
231fail_frontend: 242fail_frontend:
232 dvb_frontend_detach(dvb->frontend); 243 dvb_frontend_detach(dvb->frontend);
233 dvb_unregister_adapter(&dvb->adapter); 244 dvb->frontend = NULL;
234fail_adapter: 245
235 return result; 246 return result;
236} 247}
237 248
238void videobuf_dvb_unregister(struct videobuf_dvb *dvb) 249/* ------------------------------------------------------------------ */
250/* Register a single adapter and one or more frontends */
251int videobuf_dvb_register_bus(struct videobuf_dvb_frontends *f,
252 struct module *module,
253 void *adapter_priv,
254 struct device *device,
255 short *adapter_nr,
256 int mfe_shared)
239{ 257{
240 dvb_net_release(&dvb->net); 258 struct list_head *list, *q;
241 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem); 259 struct videobuf_dvb_frontend *fe;
242 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw); 260 int res;
243 dvb_dmxdev_release(&dvb->dmxdev); 261
244 dvb_dmx_release(&dvb->demux); 262 fe = videobuf_dvb_get_frontend(f, 1);
245 dvb_unregister_frontend(dvb->frontend); 263 if (!fe) {
246 dvb_frontend_detach(dvb->frontend); 264 printk(KERN_WARNING "Unable to register the adapter which has no frontends\n");
247 dvb_unregister_adapter(&dvb->adapter); 265 return -EINVAL;
266 }
267
268 /* Bring up the adapter */
269 res = videobuf_dvb_register_adapter(f, module, adapter_priv, device,
270 fe->dvb.name, adapter_nr, mfe_shared);
271 if (res < 0) {
272 printk(KERN_WARNING "videobuf_dvb_register_adapter failed (errno = %d)\n", res);
273 return res;
274 }
275
276 /* Attach all of the frontends to the adapter */
277 mutex_lock(&f->lock);
278 list_for_each_safe(list, q, &f->felist) {
279 fe = list_entry(list, struct videobuf_dvb_frontend, felist);
280 res = videobuf_dvb_register_frontend(&f->adapter, &fe->dvb);
281 if (res < 0) {
282 printk(KERN_WARNING "%s: videobuf_dvb_register_frontend failed (errno = %d)\n",
283 fe->dvb.name, res);
284 goto err;
285 }
286 }
287 mutex_unlock(&f->lock);
288 return 0;
289
290err:
291 mutex_unlock(&f->lock);
292 videobuf_dvb_unregister_bus(f);
293 return res;
248} 294}
295EXPORT_SYMBOL(videobuf_dvb_register_bus);
249 296
250EXPORT_SYMBOL(videobuf_dvb_register); 297void videobuf_dvb_unregister_bus(struct videobuf_dvb_frontends *f)
251EXPORT_SYMBOL(videobuf_dvb_unregister); 298{
299 videobuf_dvb_dealloc_frontends(f);
252 300
253/* ------------------------------------------------------------------ */ 301 dvb_unregister_adapter(&f->adapter);
254/* 302}
255 * Local variables: 303EXPORT_SYMBOL(videobuf_dvb_unregister_bus);
256 * c-basic-offset: 8 304
257 * compile-command: "make DVB=1" 305struct videobuf_dvb_frontend *videobuf_dvb_get_frontend(
258 * End: 306 struct videobuf_dvb_frontends *f, int id)
259 */ 307{
308 struct list_head *list, *q;
309 struct videobuf_dvb_frontend *fe, *ret = NULL;
310
311 mutex_lock(&f->lock);
312
313 list_for_each_safe(list, q, &f->felist) {
314 fe = list_entry(list, struct videobuf_dvb_frontend, felist);
315 if (fe->id == id) {
316 ret = fe;
317 break;
318 }
319 }
320
321 mutex_unlock(&f->lock);
322
323 return ret;
324}
325EXPORT_SYMBOL(videobuf_dvb_get_frontend);
326
327int videobuf_dvb_find_frontend(struct videobuf_dvb_frontends *f,
328 struct dvb_frontend *p)
329{
330 struct list_head *list, *q;
331 struct videobuf_dvb_frontend *fe = NULL;
332 int ret = 0;
333
334 mutex_lock(&f->lock);
260 335
336 list_for_each_safe(list, q, &f->felist) {
337 fe = list_entry(list, struct videobuf_dvb_frontend, felist);
338 if (fe->dvb.frontend == p) {
339 ret = fe->id;
340 break;
341 }
342 }
343
344 mutex_unlock(&f->lock);
345
346 return ret;
347}
348EXPORT_SYMBOL(videobuf_dvb_find_frontend);
349
350struct videobuf_dvb_frontend *videobuf_dvb_alloc_frontend(
351 struct videobuf_dvb_frontends *f, int id)
352{
353 struct videobuf_dvb_frontend *fe;
354
355 fe = kzalloc(sizeof(struct videobuf_dvb_frontend), GFP_KERNEL);
356 if (fe == NULL)
357 goto fail_alloc;
358
359 fe->id = id;
360 mutex_init(&fe->dvb.lock);
361
362 mutex_lock(&f->lock);
363 list_add_tail(&fe->felist, &f->felist);
364 mutex_unlock(&f->lock);
365
366fail_alloc:
367 return fe;
368}
369EXPORT_SYMBOL(videobuf_dvb_alloc_frontend);
370
371void videobuf_dvb_dealloc_frontends(struct videobuf_dvb_frontends *f)
372{
373 struct list_head *list, *q;
374 struct videobuf_dvb_frontend *fe;
375
376 mutex_lock(&f->lock);
377 list_for_each_safe(list, q, &f->felist) {
378 fe = list_entry(list, struct videobuf_dvb_frontend, felist);
379 if (fe->dvb.net.dvbdev) {
380 dvb_net_release(&fe->dvb.net);
381 fe->dvb.demux.dmx.remove_frontend(&fe->dvb.demux.dmx,
382 &fe->dvb.fe_mem);
383 fe->dvb.demux.dmx.remove_frontend(&fe->dvb.demux.dmx,
384 &fe->dvb.fe_hw);
385 dvb_dmxdev_release(&fe->dvb.dmxdev);
386 dvb_dmx_release(&fe->dvb.demux);
387 dvb_unregister_frontend(fe->dvb.frontend);
388 }
389 if (fe->dvb.frontend)
390 /* always allocated, may have been reset */
391 dvb_frontend_detach(fe->dvb.frontend);
392 list_del(list); /* remove list entry */
393 kfree(fe); /* free frontend allocation */
394 }
395 mutex_unlock(&f->lock);
396}
397EXPORT_SYMBOL(videobuf_dvb_dealloc_frontends);