2018-07-25 19:35:06 -07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2016-04-26 06:22:19 -07:00
|
|
|
/*
|
|
|
|
* Driver for Renesas R-Car VIN
|
|
|
|
*
|
|
|
|
* Copyright (C) 2016 Renesas Electronics Corp.
|
|
|
|
* Copyright (C) 2011-2013 Renesas Solutions Corp.
|
|
|
|
* Copyright (C) 2013 Cogent Embedded, Inc., <source@cogentembedded.com>
|
|
|
|
* Copyright (C) 2008 Magnus Damm
|
|
|
|
*
|
|
|
|
* Based on the soc-camera rcar_vin driver
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/pm_runtime.h>
|
|
|
|
|
|
|
|
#include <media/v4l2-event.h>
|
|
|
|
#include <media/v4l2-ioctl.h>
|
2018-04-14 04:57:15 -07:00
|
|
|
#include <media/v4l2-mc.h>
|
2016-04-26 06:22:19 -07:00
|
|
|
#include <media/v4l2-rect.h>
|
|
|
|
|
|
|
|
#include "rcar-vin.h"
|
|
|
|
|
|
|
|
#define RVIN_DEFAULT_FORMAT V4L2_PIX_FMT_YUYV
|
2018-04-14 04:57:15 -07:00
|
|
|
#define RVIN_DEFAULT_WIDTH 800
|
|
|
|
#define RVIN_DEFAULT_HEIGHT 600
|
2018-04-14 04:57:04 -07:00
|
|
|
#define RVIN_DEFAULT_FIELD V4L2_FIELD_NONE
|
2018-04-14 04:57:15 -07:00
|
|
|
#define RVIN_DEFAULT_COLORSPACE V4L2_COLORSPACE_SRGB
|
2016-04-26 06:22:19 -07:00
|
|
|
|
|
|
|
/* -----------------------------------------------------------------------------
|
|
|
|
* Format Conversions
|
|
|
|
*/
|
|
|
|
|
|
|
|
static const struct rvin_video_format rvin_formats[] = {
|
2019-10-13 17:16:15 -07:00
|
|
|
{
|
|
|
|
.fourcc = V4L2_PIX_FMT_NV12,
|
|
|
|
.bpp = 1,
|
|
|
|
},
|
2016-04-26 06:22:19 -07:00
|
|
|
{
|
|
|
|
.fourcc = V4L2_PIX_FMT_NV16,
|
|
|
|
.bpp = 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.fourcc = V4L2_PIX_FMT_YUYV,
|
|
|
|
.bpp = 2,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.fourcc = V4L2_PIX_FMT_UYVY,
|
|
|
|
.bpp = 2,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.fourcc = V4L2_PIX_FMT_RGB565,
|
|
|
|
.bpp = 2,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.fourcc = V4L2_PIX_FMT_XRGB555,
|
|
|
|
.bpp = 2,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.fourcc = V4L2_PIX_FMT_XBGR32,
|
|
|
|
.bpp = 4,
|
|
|
|
},
|
2019-07-04 10:16:01 -07:00
|
|
|
{
|
|
|
|
.fourcc = V4L2_PIX_FMT_ARGB555,
|
|
|
|
.bpp = 2,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.fourcc = V4L2_PIX_FMT_ABGR32,
|
|
|
|
.bpp = 4,
|
|
|
|
},
|
2020-09-15 16:01:40 -07:00
|
|
|
{
|
|
|
|
.fourcc = V4L2_PIX_FMT_SBGGR8,
|
|
|
|
.bpp = 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.fourcc = V4L2_PIX_FMT_SGBRG8,
|
|
|
|
.bpp = 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.fourcc = V4L2_PIX_FMT_SGRBG8,
|
|
|
|
.bpp = 1,
|
|
|
|
},
|
2020-05-27 05:16:49 -07:00
|
|
|
{
|
|
|
|
.fourcc = V4L2_PIX_FMT_SRGGB8,
|
|
|
|
.bpp = 1,
|
|
|
|
},
|
2021-09-24 05:43:17 -07:00
|
|
|
{
|
|
|
|
.fourcc = V4L2_PIX_FMT_GREY,
|
|
|
|
.bpp = 1,
|
|
|
|
},
|
2016-04-26 06:22:19 -07:00
|
|
|
};
|
|
|
|
|
2019-07-04 21:43:50 -07:00
|
|
|
const struct rvin_video_format *rvin_format_from_pixel(struct rvin_dev *vin,
|
|
|
|
u32 pixelformat)
|
2016-04-26 06:22:19 -07:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2019-12-06 09:39:31 -07:00
|
|
|
switch (pixelformat) {
|
|
|
|
case V4L2_PIX_FMT_XBGR32:
|
|
|
|
if (vin->info->model == RCAR_M1)
|
|
|
|
return NULL;
|
|
|
|
break;
|
|
|
|
case V4L2_PIX_FMT_NV12:
|
2019-12-06 09:39:32 -07:00
|
|
|
/*
|
|
|
|
* If NV12 is supported it's only supported on channels 0, 1, 4,
|
|
|
|
* 5, 8, 9, 12 and 13.
|
|
|
|
*/
|
|
|
|
if (!vin->info->nv12 || !(BIT(vin->id) & 0x3333))
|
2019-12-06 09:39:31 -07:00
|
|
|
return NULL;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2019-10-13 17:16:15 -07:00
|
|
|
|
2016-04-26 06:22:19 -07:00
|
|
|
for (i = 0; i < ARRAY_SIZE(rvin_formats); i++)
|
|
|
|
if (rvin_formats[i].fourcc == pixelformat)
|
|
|
|
return rvin_formats + i;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-07-04 21:43:50 -07:00
|
|
|
static u32 rvin_format_bytesperline(struct rvin_dev *vin,
|
|
|
|
struct v4l2_pix_format *pix)
|
2016-04-26 06:22:19 -07:00
|
|
|
{
|
|
|
|
const struct rvin_video_format *fmt;
|
2019-08-07 22:10:58 -07:00
|
|
|
u32 align;
|
2016-04-26 06:22:19 -07:00
|
|
|
|
2019-07-04 21:43:50 -07:00
|
|
|
fmt = rvin_format_from_pixel(vin, pix->pixelformat);
|
2016-04-26 06:22:19 -07:00
|
|
|
|
|
|
|
if (WARN_ON(!fmt))
|
|
|
|
return -EINVAL;
|
|
|
|
|
2019-10-13 17:16:15 -07:00
|
|
|
switch (pix->pixelformat) {
|
|
|
|
case V4L2_PIX_FMT_NV12:
|
|
|
|
case V4L2_PIX_FMT_NV16:
|
|
|
|
align = 0x20;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
align = 0x10;
|
|
|
|
break;
|
|
|
|
}
|
2019-08-07 22:10:58 -07:00
|
|
|
|
2019-12-09 19:05:59 -07:00
|
|
|
if (V4L2_FIELD_IS_SEQUENTIAL(pix->field))
|
|
|
|
align = 0x80;
|
|
|
|
|
2019-08-07 22:10:58 -07:00
|
|
|
return ALIGN(pix->width, align) * fmt->bpp;
|
2016-04-26 06:22:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static u32 rvin_format_sizeimage(struct v4l2_pix_format *pix)
|
|
|
|
{
|
2019-10-13 17:16:15 -07:00
|
|
|
switch (pix->pixelformat) {
|
|
|
|
case V4L2_PIX_FMT_NV12:
|
|
|
|
return pix->bytesperline * pix->height * 3 / 2;
|
|
|
|
case V4L2_PIX_FMT_NV16:
|
2016-04-26 06:22:19 -07:00
|
|
|
return pix->bytesperline * pix->height * 2;
|
2019-10-13 17:16:15 -07:00
|
|
|
default:
|
|
|
|
return pix->bytesperline * pix->height;
|
|
|
|
}
|
2016-04-26 06:22:19 -07:00
|
|
|
}
|
|
|
|
|
2018-04-14 04:57:09 -07:00
|
|
|
static void rvin_format_align(struct rvin_dev *vin, struct v4l2_pix_format *pix)
|
2018-04-14 04:57:08 -07:00
|
|
|
{
|
|
|
|
u32 walign;
|
|
|
|
|
2019-07-04 21:43:50 -07:00
|
|
|
if (!rvin_format_from_pixel(vin, pix->pixelformat))
|
2018-04-14 04:57:08 -07:00
|
|
|
pix->pixelformat = RVIN_DEFAULT_FORMAT;
|
|
|
|
|
|
|
|
switch (pix->field) {
|
|
|
|
case V4L2_FIELD_TOP:
|
|
|
|
case V4L2_FIELD_BOTTOM:
|
|
|
|
case V4L2_FIELD_NONE:
|
|
|
|
case V4L2_FIELD_INTERLACED_TB:
|
|
|
|
case V4L2_FIELD_INTERLACED_BT:
|
|
|
|
case V4L2_FIELD_INTERLACED:
|
|
|
|
case V4L2_FIELD_ALTERNATE:
|
2019-12-09 19:05:59 -07:00
|
|
|
case V4L2_FIELD_SEQ_TB:
|
|
|
|
case V4L2_FIELD_SEQ_BT:
|
2018-04-14 04:57:08 -07:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
pix->field = RVIN_DEFAULT_FIELD;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-11-25 16:02:57 -07:00
|
|
|
/* Hardware limits width alignment based on format. */
|
2019-12-04 10:57:59 -07:00
|
|
|
switch (pix->pixelformat) {
|
2021-11-25 16:02:57 -07:00
|
|
|
/* Multiple of 32 (2^5) for NV12/16. */
|
2019-10-13 17:16:15 -07:00
|
|
|
case V4L2_PIX_FMT_NV12:
|
|
|
|
case V4L2_PIX_FMT_NV16:
|
|
|
|
walign = 5;
|
|
|
|
break;
|
2021-11-25 16:02:57 -07:00
|
|
|
/* Multiple of 2 (2^1) for YUV. */
|
|
|
|
case V4L2_PIX_FMT_YUYV:
|
|
|
|
case V4L2_PIX_FMT_UYVY:
|
2019-10-13 17:16:15 -07:00
|
|
|
walign = 1;
|
|
|
|
break;
|
2021-11-25 16:02:57 -07:00
|
|
|
/* No multiple for RGB. */
|
|
|
|
default:
|
|
|
|
walign = 0;
|
|
|
|
break;
|
2019-10-13 17:16:15 -07:00
|
|
|
}
|
2018-04-14 04:57:08 -07:00
|
|
|
|
|
|
|
/* Limit to VIN capabilities */
|
2021-11-25 16:02:57 -07:00
|
|
|
v4l_bound_align_image(&pix->width, 5, vin->info->max_width, walign,
|
|
|
|
&pix->height, 2, vin->info->max_height, 0, 0);
|
2018-04-14 04:57:08 -07:00
|
|
|
|
2019-07-04 21:43:50 -07:00
|
|
|
pix->bytesperline = rvin_format_bytesperline(vin, pix);
|
2018-04-14 04:57:08 -07:00
|
|
|
pix->sizeimage = rvin_format_sizeimage(pix);
|
|
|
|
|
|
|
|
vin_dbg(vin, "Format %ux%u bpl: %u size: %u\n",
|
|
|
|
pix->width, pix->height, pix->bytesperline, pix->sizeimage);
|
|
|
|
}
|
|
|
|
|
2016-04-26 06:22:19 -07:00
|
|
|
/* -----------------------------------------------------------------------------
|
|
|
|
* V4L2
|
|
|
|
*/
|
|
|
|
|
2016-09-02 09:44:59 -07:00
|
|
|
static int rvin_reset_format(struct rvin_dev *vin)
|
|
|
|
{
|
|
|
|
struct v4l2_subdev_format fmt = {
|
|
|
|
.which = V4L2_SUBDEV_FORMAT_ACTIVE,
|
2020-11-25 09:44:46 -07:00
|
|
|
.pad = vin->parallel.source_pad,
|
2016-09-02 09:44:59 -07:00
|
|
|
};
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = v4l2_subdev_call(vin_to_source(vin), pad, get_fmt, NULL, &fmt);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2018-04-14 04:57:09 -07:00
|
|
|
v4l2_fill_pix_format(&vin->format, &fmt.format);
|
|
|
|
|
2022-10-09 11:35:49 -07:00
|
|
|
vin->crop.top = 0;
|
|
|
|
vin->crop.left = 0;
|
|
|
|
vin->crop.width = vin->format.width;
|
|
|
|
vin->crop.height = vin->format.height;
|
2016-09-02 09:44:59 -07:00
|
|
|
|
2019-09-04 14:54:08 -07:00
|
|
|
/* Make use of the hardware interlacer by default. */
|
|
|
|
if (vin->format.field == V4L2_FIELD_ALTERNATE) {
|
|
|
|
vin->format.field = V4L2_FIELD_INTERLACED;
|
|
|
|
vin->format.height *= 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
rvin_format_align(vin, &vin->format);
|
|
|
|
|
|
|
|
vin->compose.top = 0;
|
|
|
|
vin->compose.left = 0;
|
|
|
|
vin->compose.width = vin->format.width;
|
|
|
|
vin->compose.height = vin->format.height;
|
2017-05-23 17:15:24 -07:00
|
|
|
|
2016-09-02 09:44:59 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-04-14 04:57:09 -07:00
|
|
|
static int rvin_try_format(struct rvin_dev *vin, u32 which,
|
|
|
|
struct v4l2_pix_format *pix,
|
2019-10-08 16:22:01 -07:00
|
|
|
struct v4l2_rect *src_rect)
|
2016-04-26 06:22:19 -07:00
|
|
|
{
|
2018-04-14 04:57:09 -07:00
|
|
|
struct v4l2_subdev *sd = vin_to_source(vin);
|
media: v4l2-subdev: add subdev-wide state struct
We have 'struct v4l2_subdev_pad_config' which contains configuration for
a single pad used for the TRY functionality, and an array of those
structs is passed to various v4l2_subdev_pad_ops.
I was working on subdev internal routing between pads, and realized that
there's no way to add TRY functionality for routes, which is not pad
specific configuration. Adding a separate struct for try-route config
wouldn't work either, as e.g. set-fmt needs to know the try-route
configuration to propagate the settings.
This patch adds a new struct, 'struct v4l2_subdev_state' (which at the
moment only contains the v4l2_subdev_pad_config array) and the new
struct is used in most of the places where v4l2_subdev_pad_config was
used. All v4l2_subdev_pad_ops functions taking v4l2_subdev_pad_config
are changed to instead take v4l2_subdev_state.
The changes to drivers/media/v4l2-core/v4l2-subdev.c and
include/media/v4l2-subdev.h were written by hand, and all the driver
changes were done with the semantic patch below. The spatch needs to be
applied to a select list of directories. I used the following shell
commands to apply the spatch:
dirs="drivers/media/i2c drivers/media/platform drivers/media/usb drivers/media/test-drivers/vimc drivers/media/pci drivers/staging/media"
for dir in $dirs; do spatch -j8 --dir --include-headers --no-show-diff --in-place --sp-file v4l2-subdev-state.cocci $dir; done
Note that Coccinelle chokes on a few drivers (gcc extensions?). With
minor changes we can make Coccinelle run fine, and these changes can be
reverted after spatch. The diff for these changes is:
For drivers/media/i2c/s5k5baf.c:
@@ -1481,7 +1481,7 @@ static int s5k5baf_set_selection(struct v4l2_subdev *sd,
&s5k5baf_cis_rect,
v4l2_subdev_get_try_crop(sd, cfg, PAD_CIS),
v4l2_subdev_get_try_compose(sd, cfg, PAD_CIS),
- v4l2_subdev_get_try_crop(sd, cfg, PAD_OUT)
+ v4l2_subdev_get_try_crop(sd, cfg, PAD_OUT),
};
s5k5baf_set_rect_and_adjust(rects, rtype, &sel->r);
return 0;
For drivers/media/platform/s3c-camif/camif-capture.c:
@@ -1230,7 +1230,7 @@ static int s3c_camif_subdev_get_fmt(struct v4l2_subdev *sd,
*mf = camif->mbus_fmt;
break;
- case CAMIF_SD_PAD_SOURCE_C...CAMIF_SD_PAD_SOURCE_P:
+ case CAMIF_SD_PAD_SOURCE_C:
/* crop rectangle at camera interface input */
mf->width = camif->camif_crop.width;
mf->height = camif->camif_crop.height;
@@ -1332,7 +1332,7 @@ static int s3c_camif_subdev_set_fmt(struct v4l2_subdev *sd,
}
break;
- case CAMIF_SD_PAD_SOURCE_C...CAMIF_SD_PAD_SOURCE_P:
+ case CAMIF_SD_PAD_SOURCE_C:
/* Pixel format can be only changed on the sink pad. */
mf->code = camif->mbus_fmt.code;
mf->width = crop->width;
The semantic patch is:
// <smpl>
// Change function parameter
@@
identifier func;
identifier cfg;
@@
func(...,
- struct v4l2_subdev_pad_config *cfg
+ struct v4l2_subdev_state *sd_state
, ...)
{
<...
- cfg
+ sd_state
...>
}
// Change function declaration parameter
@@
identifier func;
identifier cfg;
type T;
@@
T func(...,
- struct v4l2_subdev_pad_config *cfg
+ struct v4l2_subdev_state *sd_state
, ...);
// Change function return value
@@
identifier func;
@@
- struct v4l2_subdev_pad_config
+ struct v4l2_subdev_state
*func(...)
{
...
}
// Change function declaration return value
@@
identifier func;
@@
- struct v4l2_subdev_pad_config
+ struct v4l2_subdev_state
*func(...);
// Some drivers pass a local pad_cfg for a single pad to a called function. Wrap it
// inside a pad_state.
@@
identifier func;
identifier pad_cfg;
@@
func(...)
{
...
struct v4l2_subdev_pad_config pad_cfg;
+ struct v4l2_subdev_state pad_state = { .pads = &pad_cfg };
<+...
(
v4l2_subdev_call
|
sensor_call
|
isi_try_fse
|
isc_try_fse
|
saa_call_all
)
(...,
- &pad_cfg
+ &pad_state
,...)
...+>
}
// If the function uses fields from pad_config, access via state->pads
@@
identifier func;
identifier state;
@@
func(...,
struct v4l2_subdev_state *state
, ...)
{
<...
(
- state->try_fmt
+ state->pads->try_fmt
|
- state->try_crop
+ state->pads->try_crop
|
- state->try_compose
+ state->pads->try_compose
)
...>
}
// If the function accesses the filehandle, use fh->state instead
@@
struct v4l2_subdev_fh *fh;
@@
- fh->pad
+ fh->state
@@
struct v4l2_subdev_fh fh;
@@
- fh.pad
+ fh.state
// Start of vsp1 specific
@@
@@
struct vsp1_entity {
...
- struct v4l2_subdev_pad_config *config;
+ struct v4l2_subdev_state *config;
...
};
@@
symbol entity;
@@
vsp1_entity_init(...)
{
...
entity->config =
- v4l2_subdev_alloc_pad_config
+ v4l2_subdev_alloc_state
(&entity->subdev);
...
}
@@
symbol entity;
@@
vsp1_entity_destroy(...)
{
...
- v4l2_subdev_free_pad_config
+ v4l2_subdev_free_state
(entity->config);
...
}
@exists@
identifier func =~ "(^vsp1.*)|(hsit_set_format)|(sru_enum_frame_size)|(sru_set_format)|(uif_get_selection)|(uif_set_selection)|(uds_enum_frame_size)|(uds_set_format)|(brx_set_format)|(brx_get_selection)|(histo_get_selection)|(histo_set_selection)|(brx_set_selection)";
symbol config;
@@
func(...) {
...
- struct v4l2_subdev_pad_config *config;
+ struct v4l2_subdev_state *config;
...
}
// End of vsp1 specific
// Start of rcar specific
@@
identifier sd;
identifier pad_cfg;
@@
rvin_try_format(...)
{
...
- struct v4l2_subdev_pad_config *pad_cfg;
+ struct v4l2_subdev_state *sd_state;
...
- pad_cfg = v4l2_subdev_alloc_pad_config(sd);
+ sd_state = v4l2_subdev_alloc_state(sd);
<...
- pad_cfg
+ sd_state
...>
- v4l2_subdev_free_pad_config(pad_cfg);
+ v4l2_subdev_free_state(sd_state);
...
}
// End of rcar specific
// Start of rockchip specific
@@
identifier func =~ "(rkisp1_rsz_get_pad_fmt)|(rkisp1_rsz_get_pad_crop)|(rkisp1_rsz_register)";
symbol rsz;
symbol pad_cfg;
@@
func(...)
{
+ struct v4l2_subdev_state state = { .pads = rsz->pad_cfg };
...
- rsz->pad_cfg
+ &state
...
}
@@
identifier func =~ "(rkisp1_isp_get_pad_fmt)|(rkisp1_isp_get_pad_crop)";
symbol isp;
symbol pad_cfg;
@@
func(...)
{
+ struct v4l2_subdev_state state = { .pads = isp->pad_cfg };
...
- isp->pad_cfg
+ &state
...
}
@@
symbol rkisp1;
symbol isp;
symbol pad_cfg;
@@
rkisp1_isp_register(...)
{
+ struct v4l2_subdev_state state = { .pads = rkisp1->isp.pad_cfg };
...
- rkisp1->isp.pad_cfg
+ &state
...
}
// End of rockchip specific
// Start of tegra-video specific
@@
identifier sd;
identifier pad_cfg;
@@
__tegra_channel_try_format(...)
{
...
- struct v4l2_subdev_pad_config *pad_cfg;
+ struct v4l2_subdev_state *sd_state;
...
- pad_cfg = v4l2_subdev_alloc_pad_config(sd);
+ sd_state = v4l2_subdev_alloc_state(sd);
<...
- pad_cfg
+ sd_state
...>
- v4l2_subdev_free_pad_config(pad_cfg);
+ v4l2_subdev_free_state(sd_state);
...
}
@@
identifier sd_state;
@@
__tegra_channel_try_format(...)
{
...
struct v4l2_subdev_state *sd_state;
<...
- sd_state->try_crop
+ sd_state->pads->try_crop
...>
}
// End of tegra-video specific
// </smpl>
Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
2021-06-10 07:55:58 -07:00
|
|
|
struct v4l2_subdev_state *sd_state;
|
media: subdev: add subdev state locking
The V4L2 subdevs have managed without centralized locking for the state
(previously pad_config), as the try-state is supposedly safe (although I
believe two TRY ioctls for the same fd would race), and the
active-state, and its locking, is managed by the drivers internally.
We now have active-state in a centralized position, and need locking.
Strictly speaking the locking is only needed for new drivers that use
the new state, as the current drivers continue behaving as they used to.
However, active-state locking is complicated by the fact that currently
the real active-state of a subdev is split into multiple parts: the new
v4l2_subdev_state, subdev control state, and subdev's internal state.
In the future all these three states should be combined into one state
(the v4l2_subdev_state), and then a single lock for the state should be
sufficient.
But to solve the current split-state situation we need to share locks
between the three states. This is accomplished by using the same lock
management as the control handler does: we use a pointer to a mutex,
allowing the driver to override the default mutex. Thus the driver can
do e.g.:
sd->state_lock = sd->ctrl_handler->lock;
before calling v4l2_subdev_init_finalize(), resulting in sharing the
same lock between the states and the controls.
The locking model for active-state is such that any subdev op that gets
the state as a parameter expects the state to be already locked by the
caller, and expects the caller to release the lock.
Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2022-04-12 02:42:46 -07:00
|
|
|
static struct lock_class_key key;
|
2016-04-26 06:22:19 -07:00
|
|
|
struct v4l2_subdev_format format = {
|
|
|
|
.which = which,
|
2020-11-25 09:44:46 -07:00
|
|
|
.pad = vin->parallel.source_pad,
|
2016-04-26 06:22:19 -07:00
|
|
|
};
|
2016-09-02 09:44:58 -07:00
|
|
|
enum v4l2_field field;
|
2018-04-14 04:57:03 -07:00
|
|
|
u32 width, height;
|
2016-04-26 06:22:19 -07:00
|
|
|
int ret;
|
|
|
|
|
2022-04-12 02:42:42 -07:00
|
|
|
/*
|
|
|
|
* FIXME: Drop this call, drivers are not supposed to use
|
|
|
|
* __v4l2_subdev_state_alloc().
|
|
|
|
*/
|
media: subdev: add subdev state locking
The V4L2 subdevs have managed without centralized locking for the state
(previously pad_config), as the try-state is supposedly safe (although I
believe two TRY ioctls for the same fd would race), and the
active-state, and its locking, is managed by the drivers internally.
We now have active-state in a centralized position, and need locking.
Strictly speaking the locking is only needed for new drivers that use
the new state, as the current drivers continue behaving as they used to.
However, active-state locking is complicated by the fact that currently
the real active-state of a subdev is split into multiple parts: the new
v4l2_subdev_state, subdev control state, and subdev's internal state.
In the future all these three states should be combined into one state
(the v4l2_subdev_state), and then a single lock for the state should be
sufficient.
But to solve the current split-state situation we need to share locks
between the three states. This is accomplished by using the same lock
management as the control handler does: we use a pointer to a mutex,
allowing the driver to override the default mutex. Thus the driver can
do e.g.:
sd->state_lock = sd->ctrl_handler->lock;
before calling v4l2_subdev_init_finalize(), resulting in sharing the
same lock between the states and the controls.
The locking model for active-state is such that any subdev op that gets
the state as a parameter expects the state to be already locked by the
caller, and expects the caller to release the lock.
Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2022-04-12 02:42:46 -07:00
|
|
|
sd_state = __v4l2_subdev_state_alloc(sd, "rvin:state->lock", &key);
|
2021-06-22 07:31:53 -07:00
|
|
|
if (IS_ERR(sd_state))
|
|
|
|
return PTR_ERR(sd_state);
|
2016-05-11 07:02:51 -07:00
|
|
|
|
2019-07-04 21:43:50 -07:00
|
|
|
if (!rvin_format_from_pixel(vin, pix->pixelformat))
|
2018-04-14 04:57:09 -07:00
|
|
|
pix->pixelformat = RVIN_DEFAULT_FORMAT;
|
|
|
|
|
2018-04-14 04:57:11 -07:00
|
|
|
v4l2_fill_mbus_format(&format.format, pix, vin->mbus_code);
|
2016-05-11 07:02:51 -07:00
|
|
|
|
2018-04-14 04:57:03 -07:00
|
|
|
/* Allow the video device to override field and to scale */
|
2016-09-02 09:44:58 -07:00
|
|
|
field = pix->field;
|
2018-04-14 04:57:03 -07:00
|
|
|
width = pix->width;
|
|
|
|
height = pix->height;
|
2016-09-02 09:44:58 -07:00
|
|
|
|
media: v4l2-subdev: add subdev-wide state struct
We have 'struct v4l2_subdev_pad_config' which contains configuration for
a single pad used for the TRY functionality, and an array of those
structs is passed to various v4l2_subdev_pad_ops.
I was working on subdev internal routing between pads, and realized that
there's no way to add TRY functionality for routes, which is not pad
specific configuration. Adding a separate struct for try-route config
wouldn't work either, as e.g. set-fmt needs to know the try-route
configuration to propagate the settings.
This patch adds a new struct, 'struct v4l2_subdev_state' (which at the
moment only contains the v4l2_subdev_pad_config array) and the new
struct is used in most of the places where v4l2_subdev_pad_config was
used. All v4l2_subdev_pad_ops functions taking v4l2_subdev_pad_config
are changed to instead take v4l2_subdev_state.
The changes to drivers/media/v4l2-core/v4l2-subdev.c and
include/media/v4l2-subdev.h were written by hand, and all the driver
changes were done with the semantic patch below. The spatch needs to be
applied to a select list of directories. I used the following shell
commands to apply the spatch:
dirs="drivers/media/i2c drivers/media/platform drivers/media/usb drivers/media/test-drivers/vimc drivers/media/pci drivers/staging/media"
for dir in $dirs; do spatch -j8 --dir --include-headers --no-show-diff --in-place --sp-file v4l2-subdev-state.cocci $dir; done
Note that Coccinelle chokes on a few drivers (gcc extensions?). With
minor changes we can make Coccinelle run fine, and these changes can be
reverted after spatch. The diff for these changes is:
For drivers/media/i2c/s5k5baf.c:
@@ -1481,7 +1481,7 @@ static int s5k5baf_set_selection(struct v4l2_subdev *sd,
&s5k5baf_cis_rect,
v4l2_subdev_get_try_crop(sd, cfg, PAD_CIS),
v4l2_subdev_get_try_compose(sd, cfg, PAD_CIS),
- v4l2_subdev_get_try_crop(sd, cfg, PAD_OUT)
+ v4l2_subdev_get_try_crop(sd, cfg, PAD_OUT),
};
s5k5baf_set_rect_and_adjust(rects, rtype, &sel->r);
return 0;
For drivers/media/platform/s3c-camif/camif-capture.c:
@@ -1230,7 +1230,7 @@ static int s3c_camif_subdev_get_fmt(struct v4l2_subdev *sd,
*mf = camif->mbus_fmt;
break;
- case CAMIF_SD_PAD_SOURCE_C...CAMIF_SD_PAD_SOURCE_P:
+ case CAMIF_SD_PAD_SOURCE_C:
/* crop rectangle at camera interface input */
mf->width = camif->camif_crop.width;
mf->height = camif->camif_crop.height;
@@ -1332,7 +1332,7 @@ static int s3c_camif_subdev_set_fmt(struct v4l2_subdev *sd,
}
break;
- case CAMIF_SD_PAD_SOURCE_C...CAMIF_SD_PAD_SOURCE_P:
+ case CAMIF_SD_PAD_SOURCE_C:
/* Pixel format can be only changed on the sink pad. */
mf->code = camif->mbus_fmt.code;
mf->width = crop->width;
The semantic patch is:
// <smpl>
// Change function parameter
@@
identifier func;
identifier cfg;
@@
func(...,
- struct v4l2_subdev_pad_config *cfg
+ struct v4l2_subdev_state *sd_state
, ...)
{
<...
- cfg
+ sd_state
...>
}
// Change function declaration parameter
@@
identifier func;
identifier cfg;
type T;
@@
T func(...,
- struct v4l2_subdev_pad_config *cfg
+ struct v4l2_subdev_state *sd_state
, ...);
// Change function return value
@@
identifier func;
@@
- struct v4l2_subdev_pad_config
+ struct v4l2_subdev_state
*func(...)
{
...
}
// Change function declaration return value
@@
identifier func;
@@
- struct v4l2_subdev_pad_config
+ struct v4l2_subdev_state
*func(...);
// Some drivers pass a local pad_cfg for a single pad to a called function. Wrap it
// inside a pad_state.
@@
identifier func;
identifier pad_cfg;
@@
func(...)
{
...
struct v4l2_subdev_pad_config pad_cfg;
+ struct v4l2_subdev_state pad_state = { .pads = &pad_cfg };
<+...
(
v4l2_subdev_call
|
sensor_call
|
isi_try_fse
|
isc_try_fse
|
saa_call_all
)
(...,
- &pad_cfg
+ &pad_state
,...)
...+>
}
// If the function uses fields from pad_config, access via state->pads
@@
identifier func;
identifier state;
@@
func(...,
struct v4l2_subdev_state *state
, ...)
{
<...
(
- state->try_fmt
+ state->pads->try_fmt
|
- state->try_crop
+ state->pads->try_crop
|
- state->try_compose
+ state->pads->try_compose
)
...>
}
// If the function accesses the filehandle, use fh->state instead
@@
struct v4l2_subdev_fh *fh;
@@
- fh->pad
+ fh->state
@@
struct v4l2_subdev_fh fh;
@@
- fh.pad
+ fh.state
// Start of vsp1 specific
@@
@@
struct vsp1_entity {
...
- struct v4l2_subdev_pad_config *config;
+ struct v4l2_subdev_state *config;
...
};
@@
symbol entity;
@@
vsp1_entity_init(...)
{
...
entity->config =
- v4l2_subdev_alloc_pad_config
+ v4l2_subdev_alloc_state
(&entity->subdev);
...
}
@@
symbol entity;
@@
vsp1_entity_destroy(...)
{
...
- v4l2_subdev_free_pad_config
+ v4l2_subdev_free_state
(entity->config);
...
}
@exists@
identifier func =~ "(^vsp1.*)|(hsit_set_format)|(sru_enum_frame_size)|(sru_set_format)|(uif_get_selection)|(uif_set_selection)|(uds_enum_frame_size)|(uds_set_format)|(brx_set_format)|(brx_get_selection)|(histo_get_selection)|(histo_set_selection)|(brx_set_selection)";
symbol config;
@@
func(...) {
...
- struct v4l2_subdev_pad_config *config;
+ struct v4l2_subdev_state *config;
...
}
// End of vsp1 specific
// Start of rcar specific
@@
identifier sd;
identifier pad_cfg;
@@
rvin_try_format(...)
{
...
- struct v4l2_subdev_pad_config *pad_cfg;
+ struct v4l2_subdev_state *sd_state;
...
- pad_cfg = v4l2_subdev_alloc_pad_config(sd);
+ sd_state = v4l2_subdev_alloc_state(sd);
<...
- pad_cfg
+ sd_state
...>
- v4l2_subdev_free_pad_config(pad_cfg);
+ v4l2_subdev_free_state(sd_state);
...
}
// End of rcar specific
// Start of rockchip specific
@@
identifier func =~ "(rkisp1_rsz_get_pad_fmt)|(rkisp1_rsz_get_pad_crop)|(rkisp1_rsz_register)";
symbol rsz;
symbol pad_cfg;
@@
func(...)
{
+ struct v4l2_subdev_state state = { .pads = rsz->pad_cfg };
...
- rsz->pad_cfg
+ &state
...
}
@@
identifier func =~ "(rkisp1_isp_get_pad_fmt)|(rkisp1_isp_get_pad_crop)";
symbol isp;
symbol pad_cfg;
@@
func(...)
{
+ struct v4l2_subdev_state state = { .pads = isp->pad_cfg };
...
- isp->pad_cfg
+ &state
...
}
@@
symbol rkisp1;
symbol isp;
symbol pad_cfg;
@@
rkisp1_isp_register(...)
{
+ struct v4l2_subdev_state state = { .pads = rkisp1->isp.pad_cfg };
...
- rkisp1->isp.pad_cfg
+ &state
...
}
// End of rockchip specific
// Start of tegra-video specific
@@
identifier sd;
identifier pad_cfg;
@@
__tegra_channel_try_format(...)
{
...
- struct v4l2_subdev_pad_config *pad_cfg;
+ struct v4l2_subdev_state *sd_state;
...
- pad_cfg = v4l2_subdev_alloc_pad_config(sd);
+ sd_state = v4l2_subdev_alloc_state(sd);
<...
- pad_cfg
+ sd_state
...>
- v4l2_subdev_free_pad_config(pad_cfg);
+ v4l2_subdev_free_state(sd_state);
...
}
@@
identifier sd_state;
@@
__tegra_channel_try_format(...)
{
...
struct v4l2_subdev_state *sd_state;
<...
- sd_state->try_crop
+ sd_state->pads->try_crop
...>
}
// End of tegra-video specific
// </smpl>
Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
2021-06-10 07:55:58 -07:00
|
|
|
ret = v4l2_subdev_call(sd, pad, set_fmt, sd_state, &format);
|
2016-08-15 08:06:31 -07:00
|
|
|
if (ret < 0 && ret != -ENOIOCTLCMD)
|
|
|
|
goto done;
|
2019-09-04 14:54:04 -07:00
|
|
|
ret = 0;
|
2016-04-26 06:22:19 -07:00
|
|
|
|
|
|
|
v4l2_fill_pix_format(pix, &format.format);
|
|
|
|
|
2019-10-08 16:22:00 -07:00
|
|
|
if (src_rect) {
|
|
|
|
src_rect->top = 0;
|
|
|
|
src_rect->left = 0;
|
|
|
|
src_rect->width = pix->width;
|
|
|
|
src_rect->height = pix->height;
|
2018-04-14 04:57:09 -07:00
|
|
|
}
|
2016-04-26 06:22:19 -07:00
|
|
|
|
2018-04-14 04:57:04 -07:00
|
|
|
if (field != V4L2_FIELD_ANY)
|
|
|
|
pix->field = field;
|
|
|
|
|
2018-04-14 04:57:03 -07:00
|
|
|
pix->width = width;
|
|
|
|
pix->height = height;
|
|
|
|
|
2018-04-14 04:57:09 -07:00
|
|
|
rvin_format_align(vin, pix);
|
2016-08-15 08:06:31 -07:00
|
|
|
done:
|
2022-04-12 02:42:42 -07:00
|
|
|
__v4l2_subdev_state_free(sd_state);
|
2016-04-26 06:22:19 -07:00
|
|
|
|
2019-09-04 14:54:04 -07:00
|
|
|
return ret;
|
2016-04-26 06:22:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int rvin_querycap(struct file *file, void *priv,
|
|
|
|
struct v4l2_capability *cap)
|
|
|
|
{
|
2018-09-10 05:19:14 -07:00
|
|
|
strscpy(cap->driver, KBUILD_MODNAME, sizeof(cap->driver));
|
|
|
|
strscpy(cap->card, "R_Car_VIN", sizeof(cap->card));
|
2016-04-26 06:22:19 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int rvin_try_fmt_vid_cap(struct file *file, void *priv,
|
|
|
|
struct v4l2_format *f)
|
|
|
|
{
|
|
|
|
struct rvin_dev *vin = video_drvdata(file);
|
|
|
|
|
2019-10-08 16:22:01 -07:00
|
|
|
return rvin_try_format(vin, V4L2_SUBDEV_FORMAT_TRY, &f->fmt.pix, NULL);
|
2016-04-26 06:22:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int rvin_s_fmt_vid_cap(struct file *file, void *priv,
|
|
|
|
struct v4l2_format *f)
|
|
|
|
{
|
|
|
|
struct rvin_dev *vin = video_drvdata(file);
|
2019-10-08 16:22:01 -07:00
|
|
|
struct v4l2_rect fmt_rect, src_rect;
|
2016-04-26 06:22:19 -07:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (vb2_is_busy(&vin->queue))
|
|
|
|
return -EBUSY;
|
|
|
|
|
2018-04-14 04:57:09 -07:00
|
|
|
ret = rvin_try_format(vin, V4L2_SUBDEV_FORMAT_ACTIVE, &f->fmt.pix,
|
2019-10-08 16:22:01 -07:00
|
|
|
&src_rect);
|
2016-04-26 06:22:19 -07:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
vin->format = f->fmt.pix;
|
2019-10-08 16:22:01 -07:00
|
|
|
|
|
|
|
fmt_rect.top = 0;
|
|
|
|
fmt_rect.left = 0;
|
|
|
|
fmt_rect.width = vin->format.width;
|
|
|
|
fmt_rect.height = vin->format.height;
|
|
|
|
|
2019-10-08 16:22:00 -07:00
|
|
|
v4l2_rect_map_inside(&vin->crop, &src_rect);
|
2019-10-08 16:22:01 -07:00
|
|
|
v4l2_rect_map_inside(&vin->compose, &fmt_rect);
|
2016-09-02 09:44:59 -07:00
|
|
|
|
2016-04-26 06:22:19 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int rvin_g_fmt_vid_cap(struct file *file, void *priv,
|
|
|
|
struct v4l2_format *f)
|
|
|
|
{
|
|
|
|
struct rvin_dev *vin = video_drvdata(file);
|
|
|
|
|
|
|
|
f->fmt.pix = vin->format;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int rvin_enum_fmt_vid_cap(struct file *file, void *priv,
|
|
|
|
struct v4l2_fmtdesc *f)
|
|
|
|
{
|
2019-10-13 17:07:50 -07:00
|
|
|
struct rvin_dev *vin = video_drvdata(file);
|
|
|
|
unsigned int i;
|
|
|
|
int matched;
|
|
|
|
|
2020-04-21 06:57:41 -07:00
|
|
|
/*
|
|
|
|
* If mbus_code is set only enumerate supported pixel formats for that
|
|
|
|
* bus code. Converting from YCbCr to RGB and RGB to YCbCr is possible
|
|
|
|
* with VIN, so all supported YCbCr and RGB media bus codes can produce
|
|
|
|
* all of the related pixel formats. If mbus_code is not set enumerate
|
|
|
|
* all possible pixelformats.
|
|
|
|
*
|
2020-05-27 05:16:48 -07:00
|
|
|
* TODO: Once raw MEDIA_BUS_FMT_SRGGB12_1X12 format is added to the
|
|
|
|
* driver this needs to be extended so raw media bus code only result in
|
|
|
|
* raw pixel format.
|
2020-04-21 06:57:41 -07:00
|
|
|
*/
|
|
|
|
switch (f->mbus_code) {
|
|
|
|
case 0:
|
|
|
|
case MEDIA_BUS_FMT_YUYV8_1X16:
|
|
|
|
case MEDIA_BUS_FMT_UYVY8_1X16:
|
|
|
|
case MEDIA_BUS_FMT_UYVY8_2X8:
|
|
|
|
case MEDIA_BUS_FMT_UYVY10_2X10:
|
|
|
|
case MEDIA_BUS_FMT_RGB888_1X24:
|
|
|
|
break;
|
2020-09-15 16:01:40 -07:00
|
|
|
case MEDIA_BUS_FMT_SBGGR8_1X8:
|
|
|
|
if (f->index)
|
|
|
|
return -EINVAL;
|
|
|
|
f->pixelformat = V4L2_PIX_FMT_SBGGR8;
|
|
|
|
return 0;
|
|
|
|
case MEDIA_BUS_FMT_SGBRG8_1X8:
|
|
|
|
if (f->index)
|
|
|
|
return -EINVAL;
|
|
|
|
f->pixelformat = V4L2_PIX_FMT_SGBRG8;
|
|
|
|
return 0;
|
|
|
|
case MEDIA_BUS_FMT_SGRBG8_1X8:
|
|
|
|
if (f->index)
|
|
|
|
return -EINVAL;
|
|
|
|
f->pixelformat = V4L2_PIX_FMT_SGRBG8;
|
|
|
|
return 0;
|
2020-05-27 05:16:48 -07:00
|
|
|
case MEDIA_BUS_FMT_SRGGB8_1X8:
|
|
|
|
if (f->index)
|
|
|
|
return -EINVAL;
|
|
|
|
f->pixelformat = V4L2_PIX_FMT_SRGGB8;
|
|
|
|
return 0;
|
2020-04-21 06:57:41 -07:00
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2019-10-13 17:07:50 -07:00
|
|
|
matched = -1;
|
|
|
|
for (i = 0; i < ARRAY_SIZE(rvin_formats); i++) {
|
|
|
|
if (rvin_format_from_pixel(vin, rvin_formats[i].fourcc))
|
|
|
|
matched++;
|
|
|
|
|
|
|
|
if (matched == f->index) {
|
|
|
|
f->pixelformat = rvin_formats[i].fourcc;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2016-04-26 06:22:19 -07:00
|
|
|
|
2019-10-13 17:07:50 -07:00
|
|
|
return -EINVAL;
|
2016-04-26 06:22:19 -07:00
|
|
|
}
|
|
|
|
|
2022-10-09 11:35:49 -07:00
|
|
|
static int rvin_remote_rectangle(struct rvin_dev *vin, struct v4l2_rect *rect)
|
|
|
|
{
|
|
|
|
struct v4l2_subdev_format fmt = {
|
|
|
|
.which = V4L2_SUBDEV_FORMAT_ACTIVE,
|
|
|
|
};
|
|
|
|
struct v4l2_subdev *sd;
|
|
|
|
unsigned int index;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (vin->info->use_mc) {
|
|
|
|
struct media_pad *pad = media_pad_remote_pad_first(&vin->pad);
|
|
|
|
|
|
|
|
if (!pad)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
sd = media_entity_to_v4l2_subdev(pad->entity);
|
|
|
|
index = pad->index;
|
|
|
|
} else {
|
|
|
|
sd = vin_to_source(vin);
|
|
|
|
index = vin->parallel.source_pad;
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.pad = index;
|
|
|
|
ret = v4l2_subdev_call(sd, pad, get_fmt, NULL, &fmt);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
rect->left = rect->top = 0;
|
|
|
|
rect->width = fmt.format.width;
|
|
|
|
rect->height = fmt.format.height;
|
|
|
|
|
|
|
|
if (fmt.format.field == V4L2_FIELD_ALTERNATE) {
|
|
|
|
switch (vin->format.field) {
|
|
|
|
case V4L2_FIELD_INTERLACED_TB:
|
|
|
|
case V4L2_FIELD_INTERLACED_BT:
|
|
|
|
case V4L2_FIELD_INTERLACED:
|
|
|
|
case V4L2_FIELD_SEQ_TB:
|
|
|
|
case V4L2_FIELD_SEQ_BT:
|
|
|
|
rect->height *= 2;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-04-26 06:22:19 -07:00
|
|
|
static int rvin_g_selection(struct file *file, void *fh,
|
|
|
|
struct v4l2_selection *s)
|
|
|
|
{
|
|
|
|
struct rvin_dev *vin = video_drvdata(file);
|
2022-10-09 11:35:49 -07:00
|
|
|
int ret;
|
2016-04-26 06:22:19 -07:00
|
|
|
|
2022-10-09 11:35:50 -07:00
|
|
|
if (!vin->scaler)
|
|
|
|
return -ENOIOCTLCMD;
|
|
|
|
|
2016-04-26 06:22:19 -07:00
|
|
|
if (s->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
switch (s->target) {
|
|
|
|
case V4L2_SEL_TGT_CROP_BOUNDS:
|
|
|
|
case V4L2_SEL_TGT_CROP_DEFAULT:
|
2022-10-09 11:35:49 -07:00
|
|
|
ret = rvin_remote_rectangle(vin, &s->r);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2016-04-26 06:22:19 -07:00
|
|
|
break;
|
|
|
|
case V4L2_SEL_TGT_CROP:
|
|
|
|
s->r = vin->crop;
|
|
|
|
break;
|
|
|
|
case V4L2_SEL_TGT_COMPOSE_BOUNDS:
|
|
|
|
case V4L2_SEL_TGT_COMPOSE_DEFAULT:
|
|
|
|
s->r.left = s->r.top = 0;
|
|
|
|
s->r.width = vin->format.width;
|
|
|
|
s->r.height = vin->format.height;
|
|
|
|
break;
|
|
|
|
case V4L2_SEL_TGT_COMPOSE:
|
|
|
|
s->r = vin->compose;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int rvin_s_selection(struct file *file, void *fh,
|
|
|
|
struct v4l2_selection *s)
|
|
|
|
{
|
|
|
|
struct rvin_dev *vin = video_drvdata(file);
|
|
|
|
const struct rvin_video_format *fmt;
|
|
|
|
struct v4l2_rect r = s->r;
|
|
|
|
struct v4l2_rect max_rect;
|
|
|
|
struct v4l2_rect min_rect = {
|
|
|
|
.width = 6,
|
|
|
|
.height = 2,
|
|
|
|
};
|
2022-10-09 11:35:49 -07:00
|
|
|
int ret;
|
2016-04-26 06:22:19 -07:00
|
|
|
|
2022-10-09 11:35:50 -07:00
|
|
|
if (!vin->scaler)
|
|
|
|
return -ENOIOCTLCMD;
|
|
|
|
|
2016-04-26 06:22:19 -07:00
|
|
|
if (s->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
v4l2_rect_set_min_size(&r, &min_rect);
|
|
|
|
|
|
|
|
switch (s->target) {
|
|
|
|
case V4L2_SEL_TGT_CROP:
|
|
|
|
/* Can't crop outside of source input */
|
2022-10-09 11:35:49 -07:00
|
|
|
ret = rvin_remote_rectangle(vin, &max_rect);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2016-04-26 06:22:19 -07:00
|
|
|
v4l2_rect_map_inside(&r, &max_rect);
|
|
|
|
|
2022-10-09 11:35:49 -07:00
|
|
|
v4l_bound_align_image(&r.width, 6, max_rect.width, 0,
|
|
|
|
&r.height, 2, max_rect.height, 0, 0);
|
2016-04-26 06:22:19 -07:00
|
|
|
|
2022-10-09 11:35:49 -07:00
|
|
|
r.top = clamp_t(s32, r.top, 0, max_rect.height - r.height);
|
|
|
|
r.left = clamp_t(s32, r.left, 0, max_rect.width - r.width);
|
2016-04-26 06:22:19 -07:00
|
|
|
|
|
|
|
vin->crop = s->r = r;
|
|
|
|
|
|
|
|
vin_dbg(vin, "Cropped %dx%d@%d:%d of %dx%d\n",
|
2016-08-15 08:06:26 -07:00
|
|
|
r.width, r.height, r.left, r.top,
|
2022-10-09 11:35:49 -07:00
|
|
|
max_rect.width, max_rect.height);
|
2016-04-26 06:22:19 -07:00
|
|
|
break;
|
|
|
|
case V4L2_SEL_TGT_COMPOSE:
|
|
|
|
/* Make sure compose rect fits inside output format */
|
|
|
|
max_rect.top = max_rect.left = 0;
|
|
|
|
max_rect.width = vin->format.width;
|
|
|
|
max_rect.height = vin->format.height;
|
|
|
|
v4l2_rect_map_inside(&r, &max_rect);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Composing is done by adding a offset to the buffer address,
|
|
|
|
* the HW wants this address to be aligned to HW_BUFFER_MASK.
|
|
|
|
* Make sure the top and left values meets this requirement.
|
|
|
|
*/
|
|
|
|
while ((r.top * vin->format.bytesperline) & HW_BUFFER_MASK)
|
|
|
|
r.top--;
|
|
|
|
|
2019-07-04 21:43:50 -07:00
|
|
|
fmt = rvin_format_from_pixel(vin, vin->format.pixelformat);
|
2016-04-26 06:22:19 -07:00
|
|
|
while ((r.left * fmt->bpp) & HW_BUFFER_MASK)
|
|
|
|
r.left--;
|
|
|
|
|
|
|
|
vin->compose = s->r = r;
|
|
|
|
|
|
|
|
vin_dbg(vin, "Compose %dx%d@%d:%d in %dx%d\n",
|
2016-08-15 08:06:26 -07:00
|
|
|
r.width, r.height, r.left, r.top,
|
|
|
|
vin->format.width, vin->format.height);
|
2016-04-26 06:22:19 -07:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* HW supports modifying configuration while running */
|
|
|
|
rvin_crop_scale_comp(vin);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-09-24 06:51:38 -07:00
|
|
|
static int rvin_g_parm(struct file *file, void *priv,
|
|
|
|
struct v4l2_streamparm *parm)
|
|
|
|
{
|
|
|
|
struct rvin_dev *vin = video_drvdata(file);
|
|
|
|
struct v4l2_subdev *sd = vin_to_source(vin);
|
|
|
|
|
|
|
|
return v4l2_g_parm_cap(&vin->vdev, sd, parm);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int rvin_s_parm(struct file *file, void *priv,
|
|
|
|
struct v4l2_streamparm *parm)
|
|
|
|
{
|
|
|
|
struct rvin_dev *vin = video_drvdata(file);
|
|
|
|
struct v4l2_subdev *sd = vin_to_source(vin);
|
|
|
|
|
|
|
|
return v4l2_s_parm_cap(&vin->vdev, sd, parm);
|
|
|
|
}
|
|
|
|
|
2018-10-04 14:38:15 -07:00
|
|
|
static int rvin_g_pixelaspect(struct file *file, void *priv,
|
|
|
|
int type, struct v4l2_fract *f)
|
2016-04-26 06:22:19 -07:00
|
|
|
{
|
|
|
|
struct rvin_dev *vin = video_drvdata(file);
|
|
|
|
struct v4l2_subdev *sd = vin_to_source(vin);
|
|
|
|
|
2018-10-04 14:38:15 -07:00
|
|
|
if (type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
|
2016-04-26 06:22:19 -07:00
|
|
|
return -EINVAL;
|
|
|
|
|
2018-10-04 14:38:15 -07:00
|
|
|
return v4l2_subdev_call(sd, video, g_pixelaspect, f);
|
2016-04-26 06:22:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int rvin_enum_input(struct file *file, void *priv,
|
|
|
|
struct v4l2_input *i)
|
|
|
|
{
|
|
|
|
struct rvin_dev *vin = video_drvdata(file);
|
|
|
|
struct v4l2_subdev *sd = vin_to_source(vin);
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (i->index != 0)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
ret = v4l2_subdev_call(sd, video, g_input_status, &i->status);
|
|
|
|
if (ret < 0 && ret != -ENOIOCTLCMD && ret != -ENODEV)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
i->type = V4L2_INPUT_TYPE_CAMERA;
|
2016-05-11 07:02:53 -07:00
|
|
|
|
2017-05-23 17:15:27 -07:00
|
|
|
if (v4l2_subdev_has_op(sd, pad, dv_timings_cap)) {
|
2016-05-11 07:02:53 -07:00
|
|
|
i->capabilities = V4L2_IN_CAP_DV_TIMINGS;
|
2017-05-23 17:15:27 -07:00
|
|
|
i->std = 0;
|
|
|
|
} else {
|
|
|
|
i->capabilities = V4L2_IN_CAP_STD;
|
|
|
|
i->std = vin->vdev.tvnorms;
|
|
|
|
}
|
2016-05-11 07:02:53 -07:00
|
|
|
|
2018-09-10 05:19:14 -07:00
|
|
|
strscpy(i->name, "Camera", sizeof(i->name));
|
2016-04-26 06:22:19 -07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int rvin_g_input(struct file *file, void *priv, unsigned int *i)
|
|
|
|
{
|
|
|
|
*i = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int rvin_s_input(struct file *file, void *priv, unsigned int i)
|
|
|
|
{
|
|
|
|
if (i > 0)
|
|
|
|
return -EINVAL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int rvin_querystd(struct file *file, void *priv, v4l2_std_id *a)
|
|
|
|
{
|
|
|
|
struct rvin_dev *vin = video_drvdata(file);
|
|
|
|
struct v4l2_subdev *sd = vin_to_source(vin);
|
|
|
|
|
|
|
|
return v4l2_subdev_call(sd, video, querystd, a);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int rvin_s_std(struct file *file, void *priv, v4l2_std_id a)
|
|
|
|
{
|
|
|
|
struct rvin_dev *vin = video_drvdata(file);
|
2016-09-02 09:44:59 -07:00
|
|
|
int ret;
|
2016-04-26 06:22:19 -07:00
|
|
|
|
2016-09-02 09:44:59 -07:00
|
|
|
ret = v4l2_subdev_call(vin_to_source(vin), video, s_std, a);
|
2016-04-26 06:22:19 -07:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
2018-04-14 04:57:10 -07:00
|
|
|
vin->std = a;
|
|
|
|
|
2016-04-26 06:22:19 -07:00
|
|
|
/* Changing the standard will change the width/height */
|
2016-09-02 09:44:59 -07:00
|
|
|
return rvin_reset_format(vin);
|
2016-04-26 06:22:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int rvin_g_std(struct file *file, void *priv, v4l2_std_id *a)
|
|
|
|
{
|
|
|
|
struct rvin_dev *vin = video_drvdata(file);
|
|
|
|
|
2018-04-14 04:57:10 -07:00
|
|
|
if (v4l2_subdev_has_op(vin_to_source(vin), pad, dv_timings_cap))
|
|
|
|
return -ENOIOCTLCMD;
|
|
|
|
|
|
|
|
*a = vin->std;
|
|
|
|
|
|
|
|
return 0;
|
2016-04-26 06:22:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int rvin_subscribe_event(struct v4l2_fh *fh,
|
|
|
|
const struct v4l2_event_subscription *sub)
|
|
|
|
{
|
|
|
|
switch (sub->type) {
|
|
|
|
case V4L2_EVENT_SOURCE_CHANGE:
|
|
|
|
return v4l2_event_subscribe(fh, sub, 4, NULL);
|
|
|
|
}
|
|
|
|
return v4l2_ctrl_subscribe_event(fh, sub);
|
|
|
|
}
|
|
|
|
|
2016-05-11 07:02:53 -07:00
|
|
|
static int rvin_enum_dv_timings(struct file *file, void *priv_fh,
|
2016-08-15 08:06:26 -07:00
|
|
|
struct v4l2_enum_dv_timings *timings)
|
2016-05-11 07:02:53 -07:00
|
|
|
{
|
|
|
|
struct rvin_dev *vin = video_drvdata(file);
|
|
|
|
struct v4l2_subdev *sd = vin_to_source(vin);
|
2017-05-23 17:15:26 -07:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (timings->pad)
|
|
|
|
return -EINVAL;
|
2016-05-11 07:02:53 -07:00
|
|
|
|
2020-11-25 09:44:46 -07:00
|
|
|
timings->pad = vin->parallel.sink_pad;
|
2016-05-11 07:02:53 -07:00
|
|
|
|
|
|
|
ret = v4l2_subdev_call(sd, pad, enum_dv_timings, timings);
|
|
|
|
|
2017-05-23 17:15:26 -07:00
|
|
|
timings->pad = 0;
|
2016-05-11 07:02:53 -07:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int rvin_s_dv_timings(struct file *file, void *priv_fh,
|
2016-08-15 08:06:26 -07:00
|
|
|
struct v4l2_dv_timings *timings)
|
2016-05-11 07:02:53 -07:00
|
|
|
{
|
|
|
|
struct rvin_dev *vin = video_drvdata(file);
|
|
|
|
struct v4l2_subdev *sd = vin_to_source(vin);
|
2016-08-15 08:06:27 -07:00
|
|
|
int ret;
|
|
|
|
|
2024-04-05 07:14:08 -07:00
|
|
|
ret = v4l2_subdev_call(sd, pad, s_dv_timings,
|
|
|
|
vin->parallel.sink_pad, timings);
|
2016-08-15 08:06:27 -07:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2017-05-23 17:15:25 -07:00
|
|
|
/* Changing the timings will change the width/height */
|
|
|
|
return rvin_reset_format(vin);
|
2016-05-11 07:02:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int rvin_g_dv_timings(struct file *file, void *priv_fh,
|
2016-08-15 08:06:26 -07:00
|
|
|
struct v4l2_dv_timings *timings)
|
2016-05-11 07:02:53 -07:00
|
|
|
{
|
|
|
|
struct rvin_dev *vin = video_drvdata(file);
|
|
|
|
struct v4l2_subdev *sd = vin_to_source(vin);
|
|
|
|
|
2024-04-05 07:14:08 -07:00
|
|
|
return v4l2_subdev_call(sd, pad, g_dv_timings,
|
|
|
|
vin->parallel.sink_pad, timings);
|
2016-05-11 07:02:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int rvin_query_dv_timings(struct file *file, void *priv_fh,
|
2016-08-15 08:06:26 -07:00
|
|
|
struct v4l2_dv_timings *timings)
|
2016-05-11 07:02:53 -07:00
|
|
|
{
|
|
|
|
struct rvin_dev *vin = video_drvdata(file);
|
|
|
|
struct v4l2_subdev *sd = vin_to_source(vin);
|
|
|
|
|
2024-04-05 07:14:08 -07:00
|
|
|
return v4l2_subdev_call(sd, pad, query_dv_timings,
|
|
|
|
vin->parallel.sink_pad, timings);
|
2016-05-11 07:02:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int rvin_dv_timings_cap(struct file *file, void *priv_fh,
|
2016-08-15 08:06:26 -07:00
|
|
|
struct v4l2_dv_timings_cap *cap)
|
2016-05-11 07:02:53 -07:00
|
|
|
{
|
|
|
|
struct rvin_dev *vin = video_drvdata(file);
|
|
|
|
struct v4l2_subdev *sd = vin_to_source(vin);
|
2017-05-23 17:15:26 -07:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (cap->pad)
|
|
|
|
return -EINVAL;
|
2016-05-11 07:02:53 -07:00
|
|
|
|
2020-11-25 09:44:46 -07:00
|
|
|
cap->pad = vin->parallel.sink_pad;
|
2016-05-11 07:02:53 -07:00
|
|
|
|
|
|
|
ret = v4l2_subdev_call(sd, pad, dv_timings_cap, cap);
|
|
|
|
|
2017-05-23 17:15:26 -07:00
|
|
|
cap->pad = 0;
|
2016-05-11 07:02:53 -07:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-09-15 10:33:23 -07:00
|
|
|
static int rvin_g_edid(struct file *file, void *fh, struct v4l2_edid *edid)
|
|
|
|
{
|
|
|
|
struct rvin_dev *vin = video_drvdata(file);
|
|
|
|
struct v4l2_subdev *sd = vin_to_source(vin);
|
2017-05-23 17:15:26 -07:00
|
|
|
int ret;
|
2016-09-15 10:33:23 -07:00
|
|
|
|
|
|
|
if (edid->pad)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2020-11-25 09:44:46 -07:00
|
|
|
edid->pad = vin->parallel.sink_pad;
|
2016-09-15 10:33:23 -07:00
|
|
|
|
|
|
|
ret = v4l2_subdev_call(sd, pad, get_edid, edid);
|
|
|
|
|
2017-05-23 17:15:26 -07:00
|
|
|
edid->pad = 0;
|
2016-09-15 10:33:23 -07:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int rvin_s_edid(struct file *file, void *fh, struct v4l2_edid *edid)
|
|
|
|
{
|
|
|
|
struct rvin_dev *vin = video_drvdata(file);
|
|
|
|
struct v4l2_subdev *sd = vin_to_source(vin);
|
2017-05-23 17:15:26 -07:00
|
|
|
int ret;
|
2016-09-15 10:33:23 -07:00
|
|
|
|
|
|
|
if (edid->pad)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2020-11-25 09:44:46 -07:00
|
|
|
edid->pad = vin->parallel.sink_pad;
|
2016-09-15 10:33:23 -07:00
|
|
|
|
|
|
|
ret = v4l2_subdev_call(sd, pad, set_edid, edid);
|
|
|
|
|
2017-05-23 17:15:26 -07:00
|
|
|
edid->pad = 0;
|
2016-09-15 10:33:23 -07:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-04-26 06:22:19 -07:00
|
|
|
static const struct v4l2_ioctl_ops rvin_ioctl_ops = {
|
|
|
|
.vidioc_querycap = rvin_querycap,
|
|
|
|
.vidioc_try_fmt_vid_cap = rvin_try_fmt_vid_cap,
|
|
|
|
.vidioc_g_fmt_vid_cap = rvin_g_fmt_vid_cap,
|
|
|
|
.vidioc_s_fmt_vid_cap = rvin_s_fmt_vid_cap,
|
|
|
|
.vidioc_enum_fmt_vid_cap = rvin_enum_fmt_vid_cap,
|
|
|
|
|
|
|
|
.vidioc_g_selection = rvin_g_selection,
|
|
|
|
.vidioc_s_selection = rvin_s_selection,
|
|
|
|
|
2021-09-24 06:51:38 -07:00
|
|
|
.vidioc_g_parm = rvin_g_parm,
|
|
|
|
.vidioc_s_parm = rvin_s_parm,
|
|
|
|
|
2018-10-04 14:38:15 -07:00
|
|
|
.vidioc_g_pixelaspect = rvin_g_pixelaspect,
|
2016-04-26 06:22:19 -07:00
|
|
|
|
|
|
|
.vidioc_enum_input = rvin_enum_input,
|
|
|
|
.vidioc_g_input = rvin_g_input,
|
|
|
|
.vidioc_s_input = rvin_s_input,
|
|
|
|
|
2016-05-11 07:02:53 -07:00
|
|
|
.vidioc_dv_timings_cap = rvin_dv_timings_cap,
|
|
|
|
.vidioc_enum_dv_timings = rvin_enum_dv_timings,
|
|
|
|
.vidioc_g_dv_timings = rvin_g_dv_timings,
|
|
|
|
.vidioc_s_dv_timings = rvin_s_dv_timings,
|
|
|
|
.vidioc_query_dv_timings = rvin_query_dv_timings,
|
|
|
|
|
2016-09-15 10:33:23 -07:00
|
|
|
.vidioc_g_edid = rvin_g_edid,
|
|
|
|
.vidioc_s_edid = rvin_s_edid,
|
|
|
|
|
2016-04-26 06:22:19 -07:00
|
|
|
.vidioc_querystd = rvin_querystd,
|
|
|
|
.vidioc_g_std = rvin_g_std,
|
|
|
|
.vidioc_s_std = rvin_s_std,
|
|
|
|
|
|
|
|
.vidioc_reqbufs = vb2_ioctl_reqbufs,
|
|
|
|
.vidioc_create_bufs = vb2_ioctl_create_bufs,
|
|
|
|
.vidioc_querybuf = vb2_ioctl_querybuf,
|
|
|
|
.vidioc_qbuf = vb2_ioctl_qbuf,
|
|
|
|
.vidioc_dqbuf = vb2_ioctl_dqbuf,
|
|
|
|
.vidioc_expbuf = vb2_ioctl_expbuf,
|
|
|
|
.vidioc_prepare_buf = vb2_ioctl_prepare_buf,
|
|
|
|
.vidioc_streamon = vb2_ioctl_streamon,
|
|
|
|
.vidioc_streamoff = vb2_ioctl_streamoff,
|
|
|
|
|
|
|
|
.vidioc_log_status = v4l2_ctrl_log_status,
|
|
|
|
.vidioc_subscribe_event = rvin_subscribe_event,
|
|
|
|
.vidioc_unsubscribe_event = v4l2_event_unsubscribe,
|
|
|
|
};
|
|
|
|
|
2018-04-14 04:57:15 -07:00
|
|
|
/* -----------------------------------------------------------------------------
|
|
|
|
* V4L2 Media Controller
|
|
|
|
*/
|
|
|
|
|
2018-04-14 04:57:16 -07:00
|
|
|
static void rvin_mc_try_format(struct rvin_dev *vin,
|
|
|
|
struct v4l2_pix_format *pix)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* The V4L2 specification clearly documents the colorspace fields
|
|
|
|
* as being set by drivers for capture devices. Using the values
|
|
|
|
* supplied by userspace thus wouldn't comply with the API. Until
|
2019-02-18 12:29:00 -07:00
|
|
|
* the API is updated force fixed values.
|
2018-04-14 04:57:16 -07:00
|
|
|
*/
|
|
|
|
pix->colorspace = RVIN_DEFAULT_COLORSPACE;
|
|
|
|
pix->xfer_func = V4L2_MAP_XFER_FUNC_DEFAULT(pix->colorspace);
|
|
|
|
pix->ycbcr_enc = V4L2_MAP_YCBCR_ENC_DEFAULT(pix->colorspace);
|
|
|
|
pix->quantization = V4L2_MAP_QUANTIZATION_DEFAULT(true, pix->colorspace,
|
|
|
|
pix->ycbcr_enc);
|
|
|
|
|
|
|
|
rvin_format_align(vin, pix);
|
|
|
|
}
|
|
|
|
|
2018-04-14 04:57:15 -07:00
|
|
|
static int rvin_mc_try_fmt_vid_cap(struct file *file, void *priv,
|
|
|
|
struct v4l2_format *f)
|
|
|
|
{
|
|
|
|
struct rvin_dev *vin = video_drvdata(file);
|
|
|
|
|
2018-04-14 04:57:16 -07:00
|
|
|
rvin_mc_try_format(vin, &f->fmt.pix);
|
2018-04-14 04:57:15 -07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int rvin_mc_s_fmt_vid_cap(struct file *file, void *priv,
|
|
|
|
struct v4l2_format *f)
|
|
|
|
{
|
|
|
|
struct rvin_dev *vin = video_drvdata(file);
|
|
|
|
|
|
|
|
if (vb2_is_busy(&vin->queue))
|
|
|
|
return -EBUSY;
|
|
|
|
|
2018-04-14 04:57:16 -07:00
|
|
|
rvin_mc_try_format(vin, &f->fmt.pix);
|
2018-04-14 04:57:15 -07:00
|
|
|
|
|
|
|
vin->format = f->fmt.pix;
|
|
|
|
|
2018-05-11 07:41:26 -07:00
|
|
|
vin->crop.top = 0;
|
|
|
|
vin->crop.left = 0;
|
|
|
|
vin->crop.width = vin->format.width;
|
|
|
|
vin->crop.height = vin->format.height;
|
|
|
|
vin->compose = vin->crop;
|
|
|
|
|
2018-04-14 04:57:15 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct v4l2_ioctl_ops rvin_mc_ioctl_ops = {
|
|
|
|
.vidioc_querycap = rvin_querycap,
|
|
|
|
.vidioc_try_fmt_vid_cap = rvin_mc_try_fmt_vid_cap,
|
|
|
|
.vidioc_g_fmt_vid_cap = rvin_g_fmt_vid_cap,
|
|
|
|
.vidioc_s_fmt_vid_cap = rvin_mc_s_fmt_vid_cap,
|
|
|
|
.vidioc_enum_fmt_vid_cap = rvin_enum_fmt_vid_cap,
|
|
|
|
|
2022-10-09 11:35:51 -07:00
|
|
|
.vidioc_g_selection = rvin_g_selection,
|
|
|
|
.vidioc_s_selection = rvin_s_selection,
|
|
|
|
|
2018-04-14 04:57:15 -07:00
|
|
|
.vidioc_reqbufs = vb2_ioctl_reqbufs,
|
|
|
|
.vidioc_create_bufs = vb2_ioctl_create_bufs,
|
|
|
|
.vidioc_querybuf = vb2_ioctl_querybuf,
|
|
|
|
.vidioc_qbuf = vb2_ioctl_qbuf,
|
|
|
|
.vidioc_dqbuf = vb2_ioctl_dqbuf,
|
|
|
|
.vidioc_expbuf = vb2_ioctl_expbuf,
|
|
|
|
.vidioc_prepare_buf = vb2_ioctl_prepare_buf,
|
|
|
|
.vidioc_streamon = vb2_ioctl_streamon,
|
|
|
|
.vidioc_streamoff = vb2_ioctl_streamoff,
|
|
|
|
|
|
|
|
.vidioc_log_status = v4l2_ctrl_log_status,
|
|
|
|
.vidioc_subscribe_event = rvin_subscribe_event,
|
|
|
|
.vidioc_unsubscribe_event = v4l2_event_unsubscribe,
|
|
|
|
};
|
|
|
|
|
2016-04-26 06:22:19 -07:00
|
|
|
/* -----------------------------------------------------------------------------
|
|
|
|
* File Operations
|
|
|
|
*/
|
|
|
|
|
2019-06-12 16:45:45 -07:00
|
|
|
static int rvin_power_parallel(struct rvin_dev *vin, bool on)
|
2016-04-26 06:22:19 -07:00
|
|
|
{
|
|
|
|
struct v4l2_subdev *sd = vin_to_source(vin);
|
2019-06-12 16:45:45 -07:00
|
|
|
int power = on ? 1 : 0;
|
2016-04-26 06:22:19 -07:00
|
|
|
int ret;
|
|
|
|
|
2019-06-12 16:45:45 -07:00
|
|
|
ret = v4l2_subdev_call(sd, core, s_power, power);
|
2016-04-26 06:22:19 -07:00
|
|
|
if (ret < 0 && ret != -ENOIOCTLCMD && ret != -ENODEV)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int rvin_open(struct file *file)
|
|
|
|
{
|
|
|
|
struct rvin_dev *vin = video_drvdata(file);
|
|
|
|
int ret;
|
|
|
|
|
2021-04-23 08:19:20 -07:00
|
|
|
ret = pm_runtime_resume_and_get(vin->dev);
|
|
|
|
if (ret < 0)
|
2019-06-12 16:45:44 -07:00
|
|
|
return ret;
|
|
|
|
|
2019-06-12 16:45:42 -07:00
|
|
|
ret = mutex_lock_interruptible(&vin->lock);
|
|
|
|
if (ret)
|
2019-06-12 16:45:44 -07:00
|
|
|
goto err_pm;
|
2016-04-26 06:22:19 -07:00
|
|
|
|
|
|
|
file->private_data = vin;
|
|
|
|
|
|
|
|
ret = v4l2_fh_open(file);
|
|
|
|
if (ret)
|
2019-06-12 16:45:44 -07:00
|
|
|
goto err_unlock;
|
2016-04-26 06:22:19 -07:00
|
|
|
|
2019-07-04 10:16:02 -07:00
|
|
|
if (vin->info->use_mc)
|
2020-01-24 13:35:43 -07:00
|
|
|
ret = v4l2_pipeline_pm_get(&vin->vdev.entity);
|
2019-07-04 10:16:02 -07:00
|
|
|
else if (v4l2_fh_is_singular_file(file))
|
|
|
|
ret = rvin_power_parallel(vin, true);
|
|
|
|
|
|
|
|
if (ret < 0)
|
|
|
|
goto err_open;
|
|
|
|
|
|
|
|
ret = v4l2_ctrl_handler_setup(&vin->ctrl_handler);
|
|
|
|
if (ret)
|
|
|
|
goto err_power;
|
|
|
|
|
2016-04-26 06:22:19 -07:00
|
|
|
mutex_unlock(&vin->lock);
|
2019-06-12 16:45:44 -07:00
|
|
|
|
|
|
|
return 0;
|
2019-07-04 10:16:02 -07:00
|
|
|
err_power:
|
|
|
|
if (vin->info->use_mc)
|
2020-01-24 13:35:43 -07:00
|
|
|
v4l2_pipeline_pm_put(&vin->vdev.entity);
|
2019-07-04 10:16:02 -07:00
|
|
|
else if (v4l2_fh_is_singular_file(file))
|
|
|
|
rvin_power_parallel(vin, false);
|
2019-06-12 16:45:44 -07:00
|
|
|
err_open:
|
|
|
|
v4l2_fh_release(file);
|
|
|
|
err_unlock:
|
|
|
|
mutex_unlock(&vin->lock);
|
|
|
|
err_pm:
|
|
|
|
pm_runtime_put(vin->dev);
|
|
|
|
|
2016-04-26 06:22:19 -07:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int rvin_release(struct file *file)
|
|
|
|
{
|
|
|
|
struct rvin_dev *vin = video_drvdata(file);
|
|
|
|
bool fh_singular;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
mutex_lock(&vin->lock);
|
|
|
|
|
|
|
|
/* Save the singular status before we call the clean-up helper */
|
|
|
|
fh_singular = v4l2_fh_is_singular_file(file);
|
|
|
|
|
|
|
|
/* the release helper will cleanup any on-going streaming */
|
|
|
|
ret = _vb2_fop_release(file, NULL);
|
|
|
|
|
2019-06-12 16:45:47 -07:00
|
|
|
if (vin->info->use_mc) {
|
2020-01-24 13:35:43 -07:00
|
|
|
v4l2_pipeline_pm_put(&vin->vdev.entity);
|
2019-06-12 16:45:47 -07:00
|
|
|
} else {
|
|
|
|
if (fh_singular)
|
|
|
|
rvin_power_parallel(vin, false);
|
|
|
|
}
|
2016-04-26 06:22:19 -07:00
|
|
|
|
|
|
|
mutex_unlock(&vin->lock);
|
|
|
|
|
2019-06-12 16:45:44 -07:00
|
|
|
pm_runtime_put(vin->dev);
|
|
|
|
|
2016-04-26 06:22:19 -07:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct v4l2_file_operations rvin_fops = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.unlocked_ioctl = video_ioctl2,
|
|
|
|
.open = rvin_open,
|
|
|
|
.release = rvin_release,
|
|
|
|
.poll = vb2_fop_poll,
|
|
|
|
.mmap = vb2_fop_mmap,
|
|
|
|
.read = vb2_fop_read,
|
|
|
|
};
|
|
|
|
|
2018-04-14 04:56:57 -07:00
|
|
|
void rvin_v4l2_unregister(struct rvin_dev *vin)
|
2016-04-26 06:22:19 -07:00
|
|
|
{
|
2018-04-14 04:56:58 -07:00
|
|
|
if (!video_is_registered(&vin->vdev))
|
|
|
|
return;
|
|
|
|
|
2016-04-26 06:22:19 -07:00
|
|
|
v4l2_info(&vin->v4l2_dev, "Removing %s\n",
|
|
|
|
video_device_node_name(&vin->vdev));
|
|
|
|
|
2019-02-18 12:29:00 -07:00
|
|
|
/* Checks internally if vdev have been init or not */
|
2016-04-26 06:22:19 -07:00
|
|
|
video_unregister_device(&vin->vdev);
|
|
|
|
}
|
|
|
|
|
2021-01-14 17:21:46 -07:00
|
|
|
static void rvin_notify_video_device(struct rvin_dev *vin,
|
|
|
|
unsigned int notification, void *arg)
|
2016-04-26 06:22:19 -07:00
|
|
|
{
|
|
|
|
switch (notification) {
|
|
|
|
case V4L2_DEVICE_NOTIFY_EVENT:
|
|
|
|
v4l2_event_queue(&vin->vdev, arg);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-14 17:21:46 -07:00
|
|
|
static void rvin_notify(struct v4l2_subdev *sd,
|
|
|
|
unsigned int notification, void *arg)
|
|
|
|
{
|
|
|
|
struct v4l2_subdev *remote;
|
|
|
|
struct rvin_group *group;
|
|
|
|
struct media_pad *pad;
|
|
|
|
struct rvin_dev *vin =
|
|
|
|
container_of(sd->v4l2_dev, struct rvin_dev, v4l2_dev);
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
/* If no media controller, no need to route the event. */
|
|
|
|
if (!vin->info->use_mc) {
|
|
|
|
rvin_notify_video_device(vin, notification, arg);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
group = vin->group;
|
|
|
|
|
|
|
|
for (i = 0; i < RCAR_VIN_NUM; i++) {
|
|
|
|
vin = group->vin[i];
|
|
|
|
if (!vin)
|
|
|
|
continue;
|
|
|
|
|
2022-06-25 10:02:24 -07:00
|
|
|
pad = media_pad_remote_pad_first(&vin->pad);
|
2021-01-14 17:21:46 -07:00
|
|
|
if (!pad)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
remote = media_entity_to_v4l2_subdev(pad->entity);
|
|
|
|
if (remote != sd)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
rvin_notify_video_device(vin, notification, arg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-14 04:56:57 -07:00
|
|
|
int rvin_v4l2_register(struct rvin_dev *vin)
|
2016-04-26 06:22:19 -07:00
|
|
|
{
|
|
|
|
struct video_device *vdev = &vin->vdev;
|
2017-05-23 17:15:29 -07:00
|
|
|
int ret;
|
2016-04-26 06:22:19 -07:00
|
|
|
|
|
|
|
vin->v4l2_dev.notify = rvin_notify;
|
|
|
|
|
|
|
|
/* video node */
|
|
|
|
vdev->v4l2_dev = &vin->v4l2_dev;
|
|
|
|
vdev->queue = &vin->queue;
|
2018-04-14 04:57:19 -07:00
|
|
|
snprintf(vdev->name, sizeof(vdev->name), "VIN%u output", vin->id);
|
2016-04-26 06:22:19 -07:00
|
|
|
vdev->release = video_device_release_empty;
|
|
|
|
vdev->lock = &vin->lock;
|
2019-06-12 16:45:47 -07:00
|
|
|
vdev->fops = &rvin_fops;
|
2016-04-26 06:22:19 -07:00
|
|
|
vdev->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING |
|
|
|
|
V4L2_CAP_READWRITE;
|
|
|
|
|
2018-04-14 04:57:15 -07:00
|
|
|
/* Set a default format */
|
2016-04-26 06:22:19 -07:00
|
|
|
vin->format.pixelformat = RVIN_DEFAULT_FORMAT;
|
2018-04-14 04:57:15 -07:00
|
|
|
vin->format.width = RVIN_DEFAULT_WIDTH;
|
|
|
|
vin->format.height = RVIN_DEFAULT_HEIGHT;
|
|
|
|
vin->format.field = RVIN_DEFAULT_FIELD;
|
|
|
|
vin->format.colorspace = RVIN_DEFAULT_COLORSPACE;
|
|
|
|
|
|
|
|
if (vin->info->use_mc) {
|
2020-04-21 06:57:41 -07:00
|
|
|
vdev->device_caps |= V4L2_CAP_IO_MC;
|
2018-04-14 04:57:15 -07:00
|
|
|
vdev->ioctl_ops = &rvin_mc_ioctl_ops;
|
|
|
|
} else {
|
|
|
|
vdev->ioctl_ops = &rvin_ioctl_ops;
|
|
|
|
rvin_reset_format(vin);
|
|
|
|
}
|
|
|
|
|
|
|
|
rvin_format_align(vin, &vin->format);
|
2016-04-26 06:22:19 -07:00
|
|
|
|
2020-02-03 04:41:18 -07:00
|
|
|
ret = video_register_device(&vin->vdev, VFL_TYPE_VIDEO, -1);
|
2016-04-26 06:22:19 -07:00
|
|
|
if (ret) {
|
|
|
|
vin_err(vin, "Failed to register video device\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
video_set_drvdata(&vin->vdev, vin);
|
|
|
|
|
|
|
|
v4l2_info(&vin->v4l2_dev, "Device registered as %s\n",
|
|
|
|
video_device_node_name(&vin->vdev));
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|