aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/v4l2-core/v4l2-common.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2018-04-03 20:16:59 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2018-04-03 20:16:59 -0400
commitef1c4a6fa91bbbe9b09f770d28eba31a9edf770c (patch)
tree52f5d175031c553160d14890e876ffc5432d2467 /drivers/media/v4l2-core/v4l2-common.c
parent147a89bc71e7db40f011454a40add7ff2d10f8d8 (diff)
parentf8a695c4b43d02c89b8bba9ba6058fd5db1bc71d (diff)
Merge tag 'media/v4.17-1' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media
Pull media updates from Mauro Carvalho Chehab: - new CEC pin injection code for testing purposes - DVB frontend cxd2099 promoted from staging - new platform driver for Sony cxd2880 DVB devices - new sensor drivers: mt9t112, ov2685, ov5695, ov772x, tda1997x, tw9910.c - removal of unused cx18 and ivtv alsa mixers - the reneseas-ceu driver doesn't depend on soc_camera anymore and moved from staging - removed the mantis_vp3028 driver, unused since 2009 - s5p-mfc: add support for version 10 of the MSP - added a decoder for imon protocol - atomisp: lots of cleanups - imx074 and mt9t031: don't depend on soc_camera anymore, being promoted from staging - added helper functions to better support DVB I2C binding - lots of driver improvements and cleanups * tag 'media/v4.17-1' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media: (438 commits) media: v4l2-ioctl: rename a temp var that stores _IOC_SIZE(cmd) media: fimc-capture: get rid of two warnings media: dvb-usb-v2: fix a missing dependency of I2C_MUX media: uvc: to the right check at uvc_ioctl_enum_framesizes() media: cec-core: fix a bug at cec_error_inj_write() media: tda9840: cleanup a warning media: tm6000: avoid casting just to print pointer address media: em28xx-input: improve error handling code media: zr364xx: avoid casting just to print pointer address media: vivid-radio-rx: add a cast to avoid a warning media: saa7134-alsa: don't use casts to print a buffer address media: solo6x10: get rid of an address space warning media: zoran: don't cast pointers to print them media: ir-kbd-i2c: change the if logic to avoid a warning media: ir-kbd-i2c: improve error handling code media: saa7134-input: improve error handling media: s2255drv: fix a casting warning media: ivtvfb: Cleanup some warnings media: videobuf-dma-sg: Fix a weird cast soc_camera: fix a weird cast on printk ...
Diffstat (limited to 'drivers/media/v4l2-core/v4l2-common.c')
-rw-r--r--drivers/media/v4l2-core/v4l2-common.c82
1 files changed, 67 insertions, 15 deletions
diff --git a/drivers/media/v4l2-core/v4l2-common.c b/drivers/media/v4l2-core/v4l2-common.c
index 8650ad92b64d..b518b92d6d96 100644
--- a/drivers/media/v4l2-core/v4l2-common.c
+++ b/drivers/media/v4l2-core/v4l2-common.c
@@ -357,31 +357,35 @@ void v4l_bound_align_image(u32 *w, unsigned int wmin, unsigned int wmax,
357} 357}
358EXPORT_SYMBOL_GPL(v4l_bound_align_image); 358EXPORT_SYMBOL_GPL(v4l_bound_align_image);
359 359
360const struct v4l2_frmsize_discrete * 360const void *
361v4l2_find_nearest_format(const struct v4l2_frmsize_discrete *sizes, 361__v4l2_find_nearest_size(const void *array, size_t array_size,
362 size_t num_sizes, 362 size_t entry_size, size_t width_offset,
363 s32 width, s32 height) 363 size_t height_offset, s32 width, s32 height)
364{ 364{
365 int i; 365 u32 error, min_error = U32_MAX;
366 u32 error, min_error = UINT_MAX; 366 const void *best = NULL;
367 const struct v4l2_frmsize_discrete *size, *best = NULL; 367 unsigned int i;
368 368
369 if (!sizes) 369 if (!array)
370 return NULL; 370 return NULL;
371 371
372 for (i = 0, size = sizes; i < num_sizes; i++, size++) { 372 for (i = 0; i < array_size; i++, array += entry_size) {
373 error = abs(size->width - width) + abs(size->height - height); 373 const u32 *entry_width = array + width_offset;
374 if (error < min_error) { 374 const u32 *entry_height = array + height_offset;
375 min_error = error; 375
376 best = size; 376 error = abs(*entry_width - width) + abs(*entry_height - height);
377 } 377 if (error > min_error)
378 continue;
379
380 min_error = error;
381 best = array;
378 if (!error) 382 if (!error)
379 break; 383 break;
380 } 384 }
381 385
382 return best; 386 return best;
383} 387}
384EXPORT_SYMBOL_GPL(v4l2_find_nearest_format); 388EXPORT_SYMBOL_GPL(__v4l2_find_nearest_size);
385 389
386void v4l2_get_timestamp(struct timeval *tv) 390void v4l2_get_timestamp(struct timeval *tv)
387{ 391{
@@ -392,3 +396,51 @@ void v4l2_get_timestamp(struct timeval *tv)
392 tv->tv_usec = ts.tv_nsec / NSEC_PER_USEC; 396 tv->tv_usec = ts.tv_nsec / NSEC_PER_USEC;
393} 397}
394EXPORT_SYMBOL_GPL(v4l2_get_timestamp); 398EXPORT_SYMBOL_GPL(v4l2_get_timestamp);
399
400int v4l2_g_parm_cap(struct video_device *vdev,
401 struct v4l2_subdev *sd, struct v4l2_streamparm *a)
402{
403 struct v4l2_subdev_frame_interval ival = { 0 };
404 int ret;
405
406 if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE &&
407 a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
408 return -EINVAL;
409
410 if (vdev->device_caps & V4L2_CAP_READWRITE)
411 a->parm.capture.readbuffers = 2;
412 if (v4l2_subdev_has_op(sd, video, g_frame_interval))
413 a->parm.capture.capability = V4L2_CAP_TIMEPERFRAME;
414 ret = v4l2_subdev_call(sd, video, g_frame_interval, &ival);
415 if (!ret)
416 a->parm.capture.timeperframe = ival.interval;
417 return ret;
418}
419EXPORT_SYMBOL_GPL(v4l2_g_parm_cap);
420
421int v4l2_s_parm_cap(struct video_device *vdev,
422 struct v4l2_subdev *sd, struct v4l2_streamparm *a)
423{
424 struct v4l2_subdev_frame_interval ival = {
425 .interval = a->parm.capture.timeperframe
426 };
427 int ret;
428
429 if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE &&
430 a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
431 return -EINVAL;
432
433 memset(&a->parm, 0, sizeof(a->parm));
434 if (vdev->device_caps & V4L2_CAP_READWRITE)
435 a->parm.capture.readbuffers = 2;
436 else
437 a->parm.capture.readbuffers = 0;
438
439 if (v4l2_subdev_has_op(sd, video, g_frame_interval))
440 a->parm.capture.capability = V4L2_CAP_TIMEPERFRAME;
441 ret = v4l2_subdev_call(sd, video, s_frame_interval, &ival);
442 if (!ret)
443 a->parm.capture.timeperframe = ival.interval;
444 return ret;
445}
446EXPORT_SYMBOL_GPL(v4l2_s_parm_cap);