diff options
author | Hans Verkuil <hans.verkuil@cisco.com> | 2015-03-09 12:34:03 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@osg.samsung.com> | 2015-04-02 23:05:36 -0400 |
commit | 08569d6477d76e2fc8fdd41cfb0ce02f59333c69 (patch) | |
tree | ec115d8b99b8f2b3cf632cd8b74b29acc204fed3 /drivers/media | |
parent | 38a1421ddd68edecb53e6dd16bae3a4b089fa1cf (diff) |
[media] cx18: embed video_device
Embed the video_device struct to simplify the error handling and in
order to (eventually) get rid of video_device_alloc/release.
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Cc: Andy Walls <awalls@md.metrocast.net>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Diffstat (limited to 'drivers/media')
-rw-r--r-- | drivers/media/pci/cx18/cx18-alsa-main.c | 2 | ||||
-rw-r--r-- | drivers/media/pci/cx18/cx18-driver.h | 2 | ||||
-rw-r--r-- | drivers/media/pci/cx18/cx18-fileops.c | 2 | ||||
-rw-r--r-- | drivers/media/pci/cx18/cx18-ioctl.c | 2 | ||||
-rw-r--r-- | drivers/media/pci/cx18/cx18-streams.c | 62 | ||||
-rw-r--r-- | drivers/media/pci/cx18/cx18-streams.h | 2 |
6 files changed, 28 insertions, 44 deletions
diff --git a/drivers/media/pci/cx18/cx18-alsa-main.c b/drivers/media/pci/cx18/cx18-alsa-main.c index ea272bcb38df..0b0e8015ad34 100644 --- a/drivers/media/pci/cx18/cx18-alsa-main.c +++ b/drivers/media/pci/cx18/cx18-alsa-main.c | |||
@@ -216,7 +216,7 @@ static int cx18_alsa_load(struct cx18 *cx) | |||
216 | } | 216 | } |
217 | 217 | ||
218 | s = &cx->streams[CX18_ENC_STREAM_TYPE_PCM]; | 218 | s = &cx->streams[CX18_ENC_STREAM_TYPE_PCM]; |
219 | if (s->video_dev == NULL) { | 219 | if (s->video_dev.v4l2_dev == NULL) { |
220 | CX18_DEBUG_ALSA_INFO("%s: PCM stream for card is disabled - " | 220 | CX18_DEBUG_ALSA_INFO("%s: PCM stream for card is disabled - " |
221 | "skipping\n", __func__); | 221 | "skipping\n", __func__); |
222 | return 0; | 222 | return 0; |
diff --git a/drivers/media/pci/cx18/cx18-driver.h b/drivers/media/pci/cx18/cx18-driver.h index ec40f2db4e39..b15beed2dc14 100644 --- a/drivers/media/pci/cx18/cx18-driver.h +++ b/drivers/media/pci/cx18/cx18-driver.h | |||
@@ -373,7 +373,7 @@ struct cx18_in_work_order { | |||
373 | struct cx18_stream { | 373 | struct cx18_stream { |
374 | /* These first five fields are always set, even if the stream | 374 | /* These first five fields are always set, even if the stream |
375 | is not actually created. */ | 375 | is not actually created. */ |
376 | struct video_device *video_dev; /* NULL when stream not created */ | 376 | struct video_device video_dev; /* v4l2_dev is NULL when stream not created */ |
377 | struct cx18_dvb *dvb; /* DVB / Digital Transport */ | 377 | struct cx18_dvb *dvb; /* DVB / Digital Transport */ |
378 | struct cx18 *cx; /* for ease of use */ | 378 | struct cx18 *cx; /* for ease of use */ |
379 | const char *name; /* name of the stream */ | 379 | const char *name; /* name of the stream */ |
diff --git a/drivers/media/pci/cx18/cx18-fileops.c b/drivers/media/pci/cx18/cx18-fileops.c index 76a3b4ac541e..d245445eea2d 100644 --- a/drivers/media/pci/cx18/cx18-fileops.c +++ b/drivers/media/pci/cx18/cx18-fileops.c | |||
@@ -797,7 +797,7 @@ static int cx18_serialized_open(struct cx18_stream *s, struct file *filp) | |||
797 | CX18_DEBUG_WARN("nomem on v4l2 open\n"); | 797 | CX18_DEBUG_WARN("nomem on v4l2 open\n"); |
798 | return -ENOMEM; | 798 | return -ENOMEM; |
799 | } | 799 | } |
800 | v4l2_fh_init(&item->fh, s->video_dev); | 800 | v4l2_fh_init(&item->fh, &s->video_dev); |
801 | 801 | ||
802 | item->cx = cx; | 802 | item->cx = cx; |
803 | item->type = s->type; | 803 | item->type = s->type; |
diff --git a/drivers/media/pci/cx18/cx18-ioctl.c b/drivers/media/pci/cx18/cx18-ioctl.c index c2e0093a5f6a..0230b0f3c25b 100644 --- a/drivers/media/pci/cx18/cx18-ioctl.c +++ b/drivers/media/pci/cx18/cx18-ioctl.c | |||
@@ -1039,7 +1039,7 @@ static int cx18_log_status(struct file *file, void *fh) | |||
1039 | for (i = 0; i < CX18_MAX_STREAMS; i++) { | 1039 | for (i = 0; i < CX18_MAX_STREAMS; i++) { |
1040 | struct cx18_stream *s = &cx->streams[i]; | 1040 | struct cx18_stream *s = &cx->streams[i]; |
1041 | 1041 | ||
1042 | if (s->video_dev == NULL || s->buffers == 0) | 1042 | if (s->video_dev.v4l2_dev == NULL || s->buffers == 0) |
1043 | continue; | 1043 | continue; |
1044 | CX18_INFO("Stream %s: status 0x%04lx, %d%% of %d KiB (%d buffers) in use\n", | 1044 | CX18_INFO("Stream %s: status 0x%04lx, %d%% of %d KiB (%d buffers) in use\n", |
1045 | s->name, s->s_flags, | 1045 | s->name, s->s_flags, |
diff --git a/drivers/media/pci/cx18/cx18-streams.c b/drivers/media/pci/cx18/cx18-streams.c index 369445fcf3e5..cf7ddaf0a704 100644 --- a/drivers/media/pci/cx18/cx18-streams.c +++ b/drivers/media/pci/cx18/cx18-streams.c | |||
@@ -254,11 +254,8 @@ static struct videobuf_queue_ops cx18_videobuf_qops = { | |||
254 | static void cx18_stream_init(struct cx18 *cx, int type) | 254 | static void cx18_stream_init(struct cx18 *cx, int type) |
255 | { | 255 | { |
256 | struct cx18_stream *s = &cx->streams[type]; | 256 | struct cx18_stream *s = &cx->streams[type]; |
257 | struct video_device *video_dev = s->video_dev; | ||
258 | 257 | ||
259 | /* we need to keep video_dev, so restore it afterwards */ | ||
260 | memset(s, 0, sizeof(*s)); | 258 | memset(s, 0, sizeof(*s)); |
261 | s->video_dev = video_dev; | ||
262 | 259 | ||
263 | /* initialize cx18_stream fields */ | 260 | /* initialize cx18_stream fields */ |
264 | s->dvb = NULL; | 261 | s->dvb = NULL; |
@@ -319,12 +316,12 @@ static int cx18_prep_dev(struct cx18 *cx, int type) | |||
319 | 316 | ||
320 | /* | 317 | /* |
321 | * These five fields are always initialized. | 318 | * These five fields are always initialized. |
322 | * For analog capture related streams, if video_dev == NULL then the | 319 | * For analog capture related streams, if video_dev.v4l2_dev == NULL then the |
323 | * stream is not in use. | 320 | * stream is not in use. |
324 | * For the TS stream, if dvb == NULL then the stream is not in use. | 321 | * For the TS stream, if dvb == NULL then the stream is not in use. |
325 | * In those cases no other fields but these four can be used. | 322 | * In those cases no other fields but these four can be used. |
326 | */ | 323 | */ |
327 | s->video_dev = NULL; | 324 | s->video_dev.v4l2_dev = NULL; |
328 | s->dvb = NULL; | 325 | s->dvb = NULL; |
329 | s->cx = cx; | 326 | s->cx = cx; |
330 | s->type = type; | 327 | s->type = type; |
@@ -367,24 +364,17 @@ static int cx18_prep_dev(struct cx18 *cx, int type) | |||
367 | if (num_offset == -1) | 364 | if (num_offset == -1) |
368 | return 0; | 365 | return 0; |
369 | 366 | ||
370 | /* allocate and initialize the v4l2 video device structure */ | 367 | /* initialize the v4l2 video device structure */ |
371 | s->video_dev = video_device_alloc(); | 368 | snprintf(s->video_dev.name, sizeof(s->video_dev.name), "%s %s", |
372 | if (s->video_dev == NULL) { | ||
373 | CX18_ERR("Couldn't allocate v4l2 video_device for %s\n", | ||
374 | s->name); | ||
375 | return -ENOMEM; | ||
376 | } | ||
377 | |||
378 | snprintf(s->video_dev->name, sizeof(s->video_dev->name), "%s %s", | ||
379 | cx->v4l2_dev.name, s->name); | 369 | cx->v4l2_dev.name, s->name); |
380 | 370 | ||
381 | s->video_dev->num = num; | 371 | s->video_dev.num = num; |
382 | s->video_dev->v4l2_dev = &cx->v4l2_dev; | 372 | s->video_dev.v4l2_dev = &cx->v4l2_dev; |
383 | s->video_dev->fops = &cx18_v4l2_enc_fops; | 373 | s->video_dev.fops = &cx18_v4l2_enc_fops; |
384 | s->video_dev->release = video_device_release; | 374 | s->video_dev.release = video_device_release_empty; |
385 | s->video_dev->tvnorms = V4L2_STD_ALL; | 375 | s->video_dev.tvnorms = V4L2_STD_ALL; |
386 | s->video_dev->lock = &cx->serialize_lock; | 376 | s->video_dev.lock = &cx->serialize_lock; |
387 | cx18_set_funcs(s->video_dev); | 377 | cx18_set_funcs(&s->video_dev); |
388 | return 0; | 378 | return 0; |
389 | } | 379 | } |
390 | 380 | ||
@@ -428,31 +418,30 @@ static int cx18_reg_dev(struct cx18 *cx, int type) | |||
428 | } | 418 | } |
429 | } | 419 | } |
430 | 420 | ||
431 | if (s->video_dev == NULL) | 421 | if (s->video_dev.v4l2_dev == NULL) |
432 | return 0; | 422 | return 0; |
433 | 423 | ||
434 | num = s->video_dev->num; | 424 | num = s->video_dev.num; |
435 | /* card number + user defined offset + device offset */ | 425 | /* card number + user defined offset + device offset */ |
436 | if (type != CX18_ENC_STREAM_TYPE_MPG) { | 426 | if (type != CX18_ENC_STREAM_TYPE_MPG) { |
437 | struct cx18_stream *s_mpg = &cx->streams[CX18_ENC_STREAM_TYPE_MPG]; | 427 | struct cx18_stream *s_mpg = &cx->streams[CX18_ENC_STREAM_TYPE_MPG]; |
438 | 428 | ||
439 | if (s_mpg->video_dev) | 429 | if (s_mpg->video_dev.v4l2_dev) |
440 | num = s_mpg->video_dev->num | 430 | num = s_mpg->video_dev.num |
441 | + cx18_stream_info[type].num_offset; | 431 | + cx18_stream_info[type].num_offset; |
442 | } | 432 | } |
443 | video_set_drvdata(s->video_dev, s); | 433 | video_set_drvdata(&s->video_dev, s); |
444 | 434 | ||
445 | /* Register device. First try the desired minor, then any free one. */ | 435 | /* Register device. First try the desired minor, then any free one. */ |
446 | ret = video_register_device_no_warn(s->video_dev, vfl_type, num); | 436 | ret = video_register_device_no_warn(&s->video_dev, vfl_type, num); |
447 | if (ret < 0) { | 437 | if (ret < 0) { |
448 | CX18_ERR("Couldn't register v4l2 device for %s (device node number %d)\n", | 438 | CX18_ERR("Couldn't register v4l2 device for %s (device node number %d)\n", |
449 | s->name, num); | 439 | s->name, num); |
450 | video_device_release(s->video_dev); | 440 | s->video_dev.v4l2_dev = NULL; |
451 | s->video_dev = NULL; | ||
452 | return ret; | 441 | return ret; |
453 | } | 442 | } |
454 | 443 | ||
455 | name = video_device_node_name(s->video_dev); | 444 | name = video_device_node_name(&s->video_dev); |
456 | 445 | ||
457 | switch (vfl_type) { | 446 | switch (vfl_type) { |
458 | case VFL_TYPE_GRABBER: | 447 | case VFL_TYPE_GRABBER: |
@@ -542,10 +531,9 @@ void cx18_streams_cleanup(struct cx18 *cx, int unregister) | |||
542 | } | 531 | } |
543 | 532 | ||
544 | /* If struct video_device exists, can have buffers allocated */ | 533 | /* If struct video_device exists, can have buffers allocated */ |
545 | vdev = cx->streams[type].video_dev; | 534 | vdev = &cx->streams[type].video_dev; |
546 | 535 | ||
547 | cx->streams[type].video_dev = NULL; | 536 | if (vdev->v4l2_dev == NULL) |
548 | if (vdev == NULL) | ||
549 | continue; | 537 | continue; |
550 | 538 | ||
551 | if (type == CX18_ENC_STREAM_TYPE_YUV) | 539 | if (type == CX18_ENC_STREAM_TYPE_YUV) |
@@ -553,11 +541,7 @@ void cx18_streams_cleanup(struct cx18 *cx, int unregister) | |||
553 | 541 | ||
554 | cx18_stream_free(&cx->streams[type]); | 542 | cx18_stream_free(&cx->streams[type]); |
555 | 543 | ||
556 | /* Unregister or release device */ | 544 | video_unregister_device(vdev); |
557 | if (unregister) | ||
558 | video_unregister_device(vdev); | ||
559 | else | ||
560 | video_device_release(vdev); | ||
561 | } | 545 | } |
562 | } | 546 | } |
563 | 547 | ||
@@ -1042,7 +1026,7 @@ u32 cx18_find_handle(struct cx18 *cx) | |||
1042 | for (i = 0; i < CX18_MAX_STREAMS; i++) { | 1026 | for (i = 0; i < CX18_MAX_STREAMS; i++) { |
1043 | struct cx18_stream *s = &cx->streams[i]; | 1027 | struct cx18_stream *s = &cx->streams[i]; |
1044 | 1028 | ||
1045 | if (s->video_dev && (s->handle != CX18_INVALID_TASK_HANDLE)) | 1029 | if (s->video_dev.v4l2_dev && (s->handle != CX18_INVALID_TASK_HANDLE)) |
1046 | return s->handle; | 1030 | return s->handle; |
1047 | } | 1031 | } |
1048 | return CX18_INVALID_TASK_HANDLE; | 1032 | return CX18_INVALID_TASK_HANDLE; |
diff --git a/drivers/media/pci/cx18/cx18-streams.h b/drivers/media/pci/cx18/cx18-streams.h index 713b0e61536d..27f8af9b11cd 100644 --- a/drivers/media/pci/cx18/cx18-streams.h +++ b/drivers/media/pci/cx18/cx18-streams.h | |||
@@ -33,7 +33,7 @@ void cx18_stream_rotate_idx_mdls(struct cx18 *cx); | |||
33 | 33 | ||
34 | static inline bool cx18_stream_enabled(struct cx18_stream *s) | 34 | static inline bool cx18_stream_enabled(struct cx18_stream *s) |
35 | { | 35 | { |
36 | return s->video_dev || | 36 | return s->video_dev.v4l2_dev || |
37 | (s->dvb && s->dvb->enabled) || | 37 | (s->dvb && s->dvb->enabled) || |
38 | (s->type == CX18_ENC_STREAM_TYPE_IDX && | 38 | (s->type == CX18_ENC_STREAM_TYPE_IDX && |
39 | s->cx->stream_buffers[CX18_ENC_STREAM_TYPE_IDX] != 0); | 39 | s->cx->stream_buffers[CX18_ENC_STREAM_TYPE_IDX] != 0); |