mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-08-26 02:39:48 +00:00
[media] v4l: vsp1: wpf: Implement rotation support
Some WPF instances, on Gen3 devices, can perform 90° rotation when writing frames to memory. Implement support for this using the V4L2_CID_ROTATE control. Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
This commit is contained in:
parent
99bb078eee
commit
3e9a0e0bfa
5 changed files with 177 additions and 54 deletions
|
@ -106,7 +106,7 @@ static void rpf_configure(struct vsp1_entity *entity,
|
||||||
* of the pipeline.
|
* of the pipeline.
|
||||||
*/
|
*/
|
||||||
output = vsp1_entity_get_pad_format(wpf, wpf->config,
|
output = vsp1_entity_get_pad_format(wpf, wpf->config,
|
||||||
RWPF_PAD_SOURCE);
|
RWPF_PAD_SINK);
|
||||||
|
|
||||||
crop.width = pipe->partition.width * input_width
|
crop.width = pipe->partition.width * input_width
|
||||||
/ output->width;
|
/ output->width;
|
||||||
|
|
|
@ -121,6 +121,11 @@ static int vsp1_rwpf_set_format(struct v4l2_subdev *subdev,
|
||||||
RWPF_PAD_SOURCE);
|
RWPF_PAD_SOURCE);
|
||||||
*format = fmt->format;
|
*format = fmt->format;
|
||||||
|
|
||||||
|
if (rwpf->flip.rotate) {
|
||||||
|
format->width = fmt->format.height;
|
||||||
|
format->height = fmt->format.width;
|
||||||
|
}
|
||||||
|
|
||||||
done:
|
done:
|
||||||
mutex_unlock(&rwpf->entity.lock);
|
mutex_unlock(&rwpf->entity.lock);
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -56,9 +56,14 @@ struct vsp1_rwpf {
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
spinlock_t lock;
|
spinlock_t lock;
|
||||||
struct v4l2_ctrl *ctrls[2];
|
struct {
|
||||||
|
struct v4l2_ctrl *vflip;
|
||||||
|
struct v4l2_ctrl *hflip;
|
||||||
|
struct v4l2_ctrl *rotate;
|
||||||
|
} ctrls;
|
||||||
unsigned int pending;
|
unsigned int pending;
|
||||||
unsigned int active;
|
unsigned int active;
|
||||||
|
bool rotate;
|
||||||
} flip;
|
} flip;
|
||||||
|
|
||||||
struct vsp1_rwpf_memory mem;
|
struct vsp1_rwpf_memory mem;
|
||||||
|
|
|
@ -187,9 +187,13 @@ static void vsp1_video_pipeline_setup_partitions(struct vsp1_pipeline *pipe)
|
||||||
struct vsp1_entity *entity;
|
struct vsp1_entity *entity;
|
||||||
unsigned int div_size;
|
unsigned int div_size;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Partitions are computed on the size before rotation, use the format
|
||||||
|
* at the WPF sink.
|
||||||
|
*/
|
||||||
format = vsp1_entity_get_pad_format(&pipe->output->entity,
|
format = vsp1_entity_get_pad_format(&pipe->output->entity,
|
||||||
pipe->output->entity.config,
|
pipe->output->entity.config,
|
||||||
RWPF_PAD_SOURCE);
|
RWPF_PAD_SINK);
|
||||||
div_size = format->width;
|
div_size = format->width;
|
||||||
|
|
||||||
/* Gen2 hardware doesn't require image partitioning. */
|
/* Gen2 hardware doesn't require image partitioning. */
|
||||||
|
@ -229,9 +233,13 @@ static struct v4l2_rect vsp1_video_partition(struct vsp1_pipeline *pipe,
|
||||||
struct v4l2_rect partition;
|
struct v4l2_rect partition;
|
||||||
unsigned int modulus;
|
unsigned int modulus;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Partitions are computed on the size before rotation, use the format
|
||||||
|
* at the WPF sink.
|
||||||
|
*/
|
||||||
format = vsp1_entity_get_pad_format(&pipe->output->entity,
|
format = vsp1_entity_get_pad_format(&pipe->output->entity,
|
||||||
pipe->output->entity.config,
|
pipe->output->entity.config,
|
||||||
RWPF_PAD_SOURCE);
|
RWPF_PAD_SINK);
|
||||||
|
|
||||||
/* A single partition simply processes the output size in full. */
|
/* A single partition simply processes the output size in full. */
|
||||||
if (pipe->partitions <= 1) {
|
if (pipe->partitions <= 1) {
|
||||||
|
|
|
@ -43,32 +43,90 @@ static inline void vsp1_wpf_write(struct vsp1_rwpf *wpf,
|
||||||
enum wpf_flip_ctrl {
|
enum wpf_flip_ctrl {
|
||||||
WPF_CTRL_VFLIP = 0,
|
WPF_CTRL_VFLIP = 0,
|
||||||
WPF_CTRL_HFLIP = 1,
|
WPF_CTRL_HFLIP = 1,
|
||||||
WPF_CTRL_MAX,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static int vsp1_wpf_set_rotation(struct vsp1_rwpf *wpf, unsigned int rotation)
|
||||||
|
{
|
||||||
|
struct vsp1_video *video = wpf->video;
|
||||||
|
struct v4l2_mbus_framefmt *sink_format;
|
||||||
|
struct v4l2_mbus_framefmt *source_format;
|
||||||
|
bool rotate;
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Only consider the 0°/180° from/to 90°/270° modifications, the rest
|
||||||
|
* is taken care of by the flipping configuration.
|
||||||
|
*/
|
||||||
|
rotate = rotation == 90 || rotation == 270;
|
||||||
|
if (rotate == wpf->flip.rotate)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
/* Changing rotation isn't allowed when buffers are allocated. */
|
||||||
|
mutex_lock(&video->lock);
|
||||||
|
|
||||||
|
if (vb2_is_busy(&video->queue)) {
|
||||||
|
ret = -EBUSY;
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
|
||||||
|
sink_format = vsp1_entity_get_pad_format(&wpf->entity,
|
||||||
|
wpf->entity.config,
|
||||||
|
RWPF_PAD_SINK);
|
||||||
|
source_format = vsp1_entity_get_pad_format(&wpf->entity,
|
||||||
|
wpf->entity.config,
|
||||||
|
RWPF_PAD_SOURCE);
|
||||||
|
|
||||||
|
mutex_lock(&wpf->entity.lock);
|
||||||
|
|
||||||
|
if (rotate) {
|
||||||
|
source_format->width = sink_format->height;
|
||||||
|
source_format->height = sink_format->width;
|
||||||
|
} else {
|
||||||
|
source_format->width = sink_format->width;
|
||||||
|
source_format->height = sink_format->height;
|
||||||
|
}
|
||||||
|
|
||||||
|
wpf->flip.rotate = rotate;
|
||||||
|
|
||||||
|
mutex_unlock(&wpf->entity.lock);
|
||||||
|
|
||||||
|
done:
|
||||||
|
mutex_unlock(&video->lock);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
static int vsp1_wpf_s_ctrl(struct v4l2_ctrl *ctrl)
|
static int vsp1_wpf_s_ctrl(struct v4l2_ctrl *ctrl)
|
||||||
{
|
{
|
||||||
struct vsp1_rwpf *wpf =
|
struct vsp1_rwpf *wpf =
|
||||||
container_of(ctrl->handler, struct vsp1_rwpf, ctrls);
|
container_of(ctrl->handler, struct vsp1_rwpf, ctrls);
|
||||||
unsigned int i;
|
unsigned int rotation;
|
||||||
u32 flip = 0;
|
u32 flip = 0;
|
||||||
|
int ret;
|
||||||
|
|
||||||
switch (ctrl->id) {
|
/* Update the rotation. */
|
||||||
case V4L2_CID_HFLIP:
|
rotation = wpf->flip.ctrls.rotate ? wpf->flip.ctrls.rotate->val : 0;
|
||||||
case V4L2_CID_VFLIP:
|
ret = vsp1_wpf_set_rotation(wpf, rotation);
|
||||||
for (i = 0; i < WPF_CTRL_MAX; ++i) {
|
if (ret < 0)
|
||||||
if (wpf->flip.ctrls[i])
|
return ret;
|
||||||
flip |= wpf->flip.ctrls[i]->val ? BIT(i) : 0;
|
|
||||||
}
|
/*
|
||||||
|
* Compute the flip value resulting from all three controls, with
|
||||||
|
* rotation by 180° flipping the image in both directions. Store the
|
||||||
|
* result in the pending flip field for the next frame that will be
|
||||||
|
* processed.
|
||||||
|
*/
|
||||||
|
if (wpf->flip.ctrls.vflip->val)
|
||||||
|
flip |= BIT(WPF_CTRL_VFLIP);
|
||||||
|
|
||||||
|
if (wpf->flip.ctrls.hflip && wpf->flip.ctrls.hflip->val)
|
||||||
|
flip |= BIT(WPF_CTRL_HFLIP);
|
||||||
|
|
||||||
|
if (rotation == 180 || rotation == 270)
|
||||||
|
flip ^= BIT(WPF_CTRL_VFLIP) | BIT(WPF_CTRL_HFLIP);
|
||||||
|
|
||||||
spin_lock_irq(&wpf->flip.lock);
|
spin_lock_irq(&wpf->flip.lock);
|
||||||
wpf->flip.pending = flip;
|
wpf->flip.pending = flip;
|
||||||
spin_unlock_irq(&wpf->flip.lock);
|
spin_unlock_irq(&wpf->flip.lock);
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -89,10 +147,10 @@ static int wpf_init_controls(struct vsp1_rwpf *wpf)
|
||||||
num_flip_ctrls = 0;
|
num_flip_ctrls = 0;
|
||||||
} else if (vsp1->info->features & VSP1_HAS_WPF_HFLIP) {
|
} else if (vsp1->info->features & VSP1_HAS_WPF_HFLIP) {
|
||||||
/*
|
/*
|
||||||
* When horizontal flip is supported the WPF implements two
|
* When horizontal flip is supported the WPF implements three
|
||||||
* controls (horizontal flip and vertical flip).
|
* controls (horizontal flip, vertical flip and rotation).
|
||||||
*/
|
*/
|
||||||
num_flip_ctrls = 2;
|
num_flip_ctrls = 3;
|
||||||
} else if (vsp1->info->features & VSP1_HAS_WPF_VFLIP) {
|
} else if (vsp1->info->features & VSP1_HAS_WPF_VFLIP) {
|
||||||
/*
|
/*
|
||||||
* When only vertical flip is supported the WPF implements a
|
* When only vertical flip is supported the WPF implements a
|
||||||
|
@ -107,17 +165,19 @@ static int wpf_init_controls(struct vsp1_rwpf *wpf)
|
||||||
vsp1_rwpf_init_ctrls(wpf, num_flip_ctrls);
|
vsp1_rwpf_init_ctrls(wpf, num_flip_ctrls);
|
||||||
|
|
||||||
if (num_flip_ctrls >= 1) {
|
if (num_flip_ctrls >= 1) {
|
||||||
wpf->flip.ctrls[WPF_CTRL_VFLIP] =
|
wpf->flip.ctrls.vflip =
|
||||||
v4l2_ctrl_new_std(&wpf->ctrls, &vsp1_wpf_ctrl_ops,
|
v4l2_ctrl_new_std(&wpf->ctrls, &vsp1_wpf_ctrl_ops,
|
||||||
V4L2_CID_VFLIP, 0, 1, 1, 0);
|
V4L2_CID_VFLIP, 0, 1, 1, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (num_flip_ctrls == 2) {
|
if (num_flip_ctrls == 3) {
|
||||||
wpf->flip.ctrls[WPF_CTRL_HFLIP] =
|
wpf->flip.ctrls.hflip =
|
||||||
v4l2_ctrl_new_std(&wpf->ctrls, &vsp1_wpf_ctrl_ops,
|
v4l2_ctrl_new_std(&wpf->ctrls, &vsp1_wpf_ctrl_ops,
|
||||||
V4L2_CID_HFLIP, 0, 1, 1, 0);
|
V4L2_CID_HFLIP, 0, 1, 1, 0);
|
||||||
|
wpf->flip.ctrls.rotate =
|
||||||
v4l2_ctrl_cluster(2, wpf->flip.ctrls);
|
v4l2_ctrl_new_std(&wpf->ctrls, &vsp1_wpf_ctrl_ops,
|
||||||
|
V4L2_CID_ROTATE, 0, 270, 90, 0);
|
||||||
|
v4l2_ctrl_cluster(3, &wpf->flip.ctrls.vflip);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wpf->ctrls.error) {
|
if (wpf->ctrls.error) {
|
||||||
|
@ -222,8 +282,8 @@ static void wpf_configure(struct vsp1_entity *entity,
|
||||||
const struct vsp1_format_info *fmtinfo = wpf->fmtinfo;
|
const struct vsp1_format_info *fmtinfo = wpf->fmtinfo;
|
||||||
struct vsp1_rwpf_memory mem = wpf->mem;
|
struct vsp1_rwpf_memory mem = wpf->mem;
|
||||||
unsigned int flip = wpf->flip.active;
|
unsigned int flip = wpf->flip.active;
|
||||||
unsigned int width = source_format->width;
|
unsigned int width = sink_format->width;
|
||||||
unsigned int height = source_format->height;
|
unsigned int height = sink_format->height;
|
||||||
unsigned int offset;
|
unsigned int offset;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -246,45 +306,78 @@ static void wpf_configure(struct vsp1_entity *entity,
|
||||||
/*
|
/*
|
||||||
* Update the memory offsets based on flipping configuration.
|
* Update the memory offsets based on flipping configuration.
|
||||||
* The destination addresses point to the locations where the
|
* The destination addresses point to the locations where the
|
||||||
* VSP starts writing to memory, which can be different corners
|
* VSP starts writing to memory, which can be any corner of the
|
||||||
* of the image depending on vertical flipping.
|
* image depending on the combination of flipping and rotation.
|
||||||
*/
|
*/
|
||||||
if (pipe->partitions > 1) {
|
|
||||||
const struct vsp1_format_info *fmtinfo = wpf->fmtinfo;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Horizontal flipping is handled through a line buffer
|
* First take the partition left coordinate into account.
|
||||||
* and doesn't modify the start address, but still needs
|
* Compute the offset to order the partitions correctly on the
|
||||||
* to be handled when image partitioning is in effect to
|
* output based on whether flipping is enabled. Consider
|
||||||
* order the partitions correctly.
|
* horizontal flipping when rotation is disabled but vertical
|
||||||
|
* flipping when rotation is enabled, as rotating the image
|
||||||
|
* switches the horizontal and vertical directions. The offset
|
||||||
|
* is applied horizontally or vertically accordingly.
|
||||||
*/
|
*/
|
||||||
if (flip & BIT(WPF_CTRL_HFLIP))
|
if (flip & BIT(WPF_CTRL_HFLIP) && !wpf->flip.rotate)
|
||||||
offset = format->width - pipe->partition.left
|
offset = format->width - pipe->partition.left
|
||||||
- pipe->partition.width;
|
- pipe->partition.width;
|
||||||
|
else if (flip & BIT(WPF_CTRL_VFLIP) && wpf->flip.rotate)
|
||||||
|
offset = format->height - pipe->partition.left
|
||||||
|
- pipe->partition.width;
|
||||||
else
|
else
|
||||||
offset = pipe->partition.left;
|
offset = pipe->partition.left;
|
||||||
|
|
||||||
mem.addr[0] += offset * fmtinfo->bpp[0] / 8;
|
for (i = 0; i < format->num_planes; ++i) {
|
||||||
if (format->num_planes > 1) {
|
unsigned int hsub = i > 0 ? fmtinfo->hsub : 1;
|
||||||
mem.addr[1] += offset / fmtinfo->hsub
|
unsigned int vsub = i > 0 ? fmtinfo->vsub : 1;
|
||||||
* fmtinfo->bpp[1] / 8;
|
|
||||||
mem.addr[2] += offset / fmtinfo->hsub
|
if (wpf->flip.rotate)
|
||||||
* fmtinfo->bpp[2] / 8;
|
mem.addr[i] += offset / vsub
|
||||||
}
|
* format->plane_fmt[i].bytesperline;
|
||||||
|
else
|
||||||
|
mem.addr[i] += offset / hsub
|
||||||
|
* fmtinfo->bpp[i] / 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flip & BIT(WPF_CTRL_VFLIP)) {
|
if (flip & BIT(WPF_CTRL_VFLIP)) {
|
||||||
mem.addr[0] += (format->height - 1)
|
/*
|
||||||
|
* When rotating the output (after rotation) image
|
||||||
|
* height is equal to the partition width (before
|
||||||
|
* rotation). Otherwise it is equal to the output
|
||||||
|
* image height.
|
||||||
|
*/
|
||||||
|
if (wpf->flip.rotate)
|
||||||
|
height = pipe->partition.width;
|
||||||
|
else
|
||||||
|
height = format->height;
|
||||||
|
|
||||||
|
mem.addr[0] += (height - 1)
|
||||||
* format->plane_fmt[0].bytesperline;
|
* format->plane_fmt[0].bytesperline;
|
||||||
|
|
||||||
if (format->num_planes > 1) {
|
if (format->num_planes > 1) {
|
||||||
offset = (format->height / wpf->fmtinfo->vsub - 1)
|
offset = (height / fmtinfo->vsub - 1)
|
||||||
* format->plane_fmt[1].bytesperline;
|
* format->plane_fmt[1].bytesperline;
|
||||||
mem.addr[1] += offset;
|
mem.addr[1] += offset;
|
||||||
mem.addr[2] += offset;
|
mem.addr[2] += offset;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (wpf->flip.rotate && !(flip & BIT(WPF_CTRL_HFLIP))) {
|
||||||
|
unsigned int hoffset = max(0, (int)format->width - 16);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Compute the output coordinate. The partition
|
||||||
|
* horizontal (left) offset becomes a vertical offset.
|
||||||
|
*/
|
||||||
|
for (i = 0; i < format->num_planes; ++i) {
|
||||||
|
unsigned int hsub = i > 0 ? fmtinfo->hsub : 1;
|
||||||
|
|
||||||
|
mem.addr[i] += hoffset / hsub
|
||||||
|
* fmtinfo->bpp[i] / 8;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* On Gen3 hardware the SPUVS bit has no effect on 3-planar
|
* On Gen3 hardware the SPUVS bit has no effect on 3-planar
|
||||||
* formats. Swap the U and V planes manually in that case.
|
* formats. Swap the U and V planes manually in that case.
|
||||||
|
@ -306,6 +399,9 @@ static void wpf_configure(struct vsp1_entity *entity,
|
||||||
|
|
||||||
outfmt = fmtinfo->hwfmt << VI6_WPF_OUTFMT_WRFMT_SHIFT;
|
outfmt = fmtinfo->hwfmt << VI6_WPF_OUTFMT_WRFMT_SHIFT;
|
||||||
|
|
||||||
|
if (wpf->flip.rotate)
|
||||||
|
outfmt |= VI6_WPF_OUTFMT_ROT;
|
||||||
|
|
||||||
if (fmtinfo->alpha)
|
if (fmtinfo->alpha)
|
||||||
outfmt |= VI6_WPF_OUTFMT_PXA;
|
outfmt |= VI6_WPF_OUTFMT_PXA;
|
||||||
if (fmtinfo->swap_yc)
|
if (fmtinfo->swap_yc)
|
||||||
|
@ -367,9 +463,18 @@ static void wpf_configure(struct vsp1_entity *entity,
|
||||||
VI6_WFP_IRQ_ENB_DFEE);
|
VI6_WFP_IRQ_ENB_DFEE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static unsigned int wpf_max_width(struct vsp1_entity *entity,
|
||||||
|
struct vsp1_pipeline *pipe)
|
||||||
|
{
|
||||||
|
struct vsp1_rwpf *wpf = to_rwpf(&entity->subdev);
|
||||||
|
|
||||||
|
return wpf->flip.rotate ? 256 : wpf->max_width;
|
||||||
|
}
|
||||||
|
|
||||||
static const struct vsp1_entity_operations wpf_entity_ops = {
|
static const struct vsp1_entity_operations wpf_entity_ops = {
|
||||||
.destroy = vsp1_wpf_destroy,
|
.destroy = vsp1_wpf_destroy,
|
||||||
.configure = wpf_configure,
|
.configure = wpf_configure,
|
||||||
|
.max_width = wpf_max_width,
|
||||||
};
|
};
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
|
|
Loading…
Reference in a new issue