2013-06-04 18:22:30 +04:00
|
|
|
/*
|
|
|
|
* vsp1_rpf.c -- R-Car VSP1 Read Pixel Formatter
|
|
|
|
*
|
2014-02-06 21:42:31 +04:00
|
|
|
* Copyright (C) 2013-2014 Renesas Electronics Corporation
|
2013-06-04 18:22:30 +04:00
|
|
|
*
|
|
|
|
* Contact: Laurent Pinchart (laurent.pinchart@ideasonboard.com)
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/device.h>
|
|
|
|
|
|
|
|
#include <media/v4l2-subdev.h>
|
|
|
|
|
|
|
|
#include "vsp1.h"
|
2015-11-23 01:29:25 +03:00
|
|
|
#include "vsp1_dl.h"
|
2013-06-04 18:22:30 +04:00
|
|
|
#include "vsp1_rwpf.h"
|
|
|
|
#include "vsp1_video.h"
|
|
|
|
|
|
|
|
#define RPF_MAX_WIDTH 8190
|
|
|
|
#define RPF_MAX_HEIGHT 8190
|
|
|
|
|
|
|
|
/* -----------------------------------------------------------------------------
|
|
|
|
* Device Access
|
|
|
|
*/
|
|
|
|
|
2015-11-23 01:29:25 +03:00
|
|
|
static inline void vsp1_rpf_write(struct vsp1_rwpf *rpf,
|
|
|
|
struct vsp1_dl_list *dl, u32 reg, u32 data)
|
2013-06-04 18:22:30 +04:00
|
|
|
{
|
2015-11-23 01:29:25 +03:00
|
|
|
vsp1_dl_list_write(dl, reg + rpf->entity.index * VI6_RPF_OFFSET, data);
|
2013-06-04 18:22:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -----------------------------------------------------------------------------
|
2015-11-17 18:10:26 +03:00
|
|
|
* V4L2 Subdevice Operations
|
2013-06-04 18:22:30 +04:00
|
|
|
*/
|
|
|
|
|
2015-11-17 18:10:26 +03:00
|
|
|
static struct v4l2_subdev_ops rpf_ops = {
|
2015-11-22 18:37:45 +03:00
|
|
|
.pad = &vsp1_rwpf_pad_ops,
|
2015-11-17 18:10:26 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/* -----------------------------------------------------------------------------
|
|
|
|
* VSP1 Entity Operations
|
|
|
|
*/
|
|
|
|
|
2015-11-23 01:29:25 +03:00
|
|
|
static void rpf_set_memory(struct vsp1_entity *entity, struct vsp1_dl_list *dl)
|
2013-06-04 18:22:30 +04:00
|
|
|
{
|
2015-11-17 18:10:26 +03:00
|
|
|
struct vsp1_rwpf *rpf = entity_to_rwpf(entity);
|
|
|
|
|
2015-11-23 01:29:25 +03:00
|
|
|
vsp1_rpf_write(rpf, dl, VI6_RPF_SRCM_ADDR_Y,
|
2015-11-17 18:10:26 +03:00
|
|
|
rpf->mem.addr[0] + rpf->offsets[0]);
|
2015-11-23 01:29:25 +03:00
|
|
|
vsp1_rpf_write(rpf, dl, VI6_RPF_SRCM_ADDR_C0,
|
2015-11-17 18:10:26 +03:00
|
|
|
rpf->mem.addr[1] + rpf->offsets[1]);
|
2015-11-23 01:29:25 +03:00
|
|
|
vsp1_rpf_write(rpf, dl, VI6_RPF_SRCM_ADDR_C1,
|
2015-11-17 18:10:26 +03:00
|
|
|
rpf->mem.addr[2] + rpf->offsets[1]);
|
|
|
|
}
|
|
|
|
|
2016-01-14 19:17:32 +03:00
|
|
|
static void rpf_configure(struct vsp1_entity *entity,
|
|
|
|
struct vsp1_pipeline *pipe,
|
|
|
|
struct vsp1_dl_list *dl)
|
2015-11-17 18:10:26 +03:00
|
|
|
{
|
|
|
|
struct vsp1_rwpf *rpf = to_rwpf(&entity->subdev);
|
2015-07-28 20:00:43 +03:00
|
|
|
const struct vsp1_format_info *fmtinfo = rpf->fmtinfo;
|
|
|
|
const struct v4l2_pix_format_mplane *format = &rpf->format;
|
2015-11-16 00:14:22 +03:00
|
|
|
const struct v4l2_mbus_framefmt *source_format;
|
|
|
|
const struct v4l2_mbus_framefmt *sink_format;
|
2015-11-16 00:14:22 +03:00
|
|
|
const struct v4l2_rect *crop;
|
|
|
|
unsigned int left = 0;
|
|
|
|
unsigned int top = 0;
|
2013-06-04 18:22:30 +04:00
|
|
|
u32 pstride;
|
|
|
|
u32 infmt;
|
2014-05-22 02:00:05 +04:00
|
|
|
|
2013-08-25 03:49:58 +04:00
|
|
|
/* Source size, stride and crop offsets.
|
|
|
|
*
|
|
|
|
* The crop offsets correspond to the location of the crop rectangle top
|
|
|
|
* left corner in the plane buffer. Only two offsets are needed, as
|
|
|
|
* planes 2 and 3 always have identical strides.
|
|
|
|
*/
|
2015-11-16 00:14:22 +03:00
|
|
|
crop = vsp1_rwpf_get_crop(rpf, rpf->entity.config);
|
|
|
|
|
2015-11-23 01:29:25 +03:00
|
|
|
vsp1_rpf_write(rpf, dl, VI6_RPF_SRC_BSIZE,
|
2013-08-25 03:49:58 +04:00
|
|
|
(crop->width << VI6_RPF_SRC_BSIZE_BHSIZE_SHIFT) |
|
|
|
|
(crop->height << VI6_RPF_SRC_BSIZE_BVSIZE_SHIFT));
|
2015-11-23 01:29:25 +03:00
|
|
|
vsp1_rpf_write(rpf, dl, VI6_RPF_SRC_ESIZE,
|
2013-08-25 03:49:58 +04:00
|
|
|
(crop->width << VI6_RPF_SRC_ESIZE_EHSIZE_SHIFT) |
|
|
|
|
(crop->height << VI6_RPF_SRC_ESIZE_EVSIZE_SHIFT));
|
2013-06-04 18:22:30 +04:00
|
|
|
|
2013-08-25 03:49:58 +04:00
|
|
|
rpf->offsets[0] = crop->top * format->plane_fmt[0].bytesperline
|
|
|
|
+ crop->left * fmtinfo->bpp[0] / 8;
|
2013-06-04 18:22:30 +04:00
|
|
|
pstride = format->plane_fmt[0].bytesperline
|
|
|
|
<< VI6_RPF_SRCM_PSTRIDE_Y_SHIFT;
|
2014-11-27 04:25:01 +03:00
|
|
|
|
2013-08-25 03:49:58 +04:00
|
|
|
if (format->num_planes > 1) {
|
|
|
|
rpf->offsets[1] = crop->top * format->plane_fmt[1].bytesperline
|
|
|
|
+ crop->left * fmtinfo->bpp[1] / 8;
|
2013-06-04 18:22:30 +04:00
|
|
|
pstride |= format->plane_fmt[1].bytesperline
|
|
|
|
<< VI6_RPF_SRCM_PSTRIDE_C_SHIFT;
|
2015-11-01 18:48:11 +03:00
|
|
|
} else {
|
|
|
|
rpf->offsets[1] = 0;
|
2013-08-25 03:49:58 +04:00
|
|
|
}
|
2013-06-04 18:22:30 +04:00
|
|
|
|
2015-11-23 01:29:25 +03:00
|
|
|
vsp1_rpf_write(rpf, dl, VI6_RPF_SRCM_PSTRIDE, pstride);
|
2013-06-04 18:22:30 +04:00
|
|
|
|
|
|
|
/* Format */
|
2015-11-16 00:14:22 +03:00
|
|
|
sink_format = vsp1_entity_get_pad_format(&rpf->entity,
|
|
|
|
rpf->entity.config,
|
|
|
|
RWPF_PAD_SINK);
|
|
|
|
source_format = vsp1_entity_get_pad_format(&rpf->entity,
|
|
|
|
rpf->entity.config,
|
|
|
|
RWPF_PAD_SOURCE);
|
|
|
|
|
2013-06-04 18:22:30 +04:00
|
|
|
infmt = VI6_RPF_INFMT_CIPM
|
|
|
|
| (fmtinfo->hwfmt << VI6_RPF_INFMT_RDFMT_SHIFT);
|
|
|
|
|
|
|
|
if (fmtinfo->swap_yc)
|
|
|
|
infmt |= VI6_RPF_INFMT_SPYCS;
|
|
|
|
if (fmtinfo->swap_uv)
|
|
|
|
infmt |= VI6_RPF_INFMT_SPUVS;
|
|
|
|
|
2015-11-16 00:14:22 +03:00
|
|
|
if (sink_format->code != source_format->code)
|
2013-06-04 18:22:30 +04:00
|
|
|
infmt |= VI6_RPF_INFMT_CSC;
|
|
|
|
|
2015-11-23 01:29:25 +03:00
|
|
|
vsp1_rpf_write(rpf, dl, VI6_RPF_INFMT, infmt);
|
|
|
|
vsp1_rpf_write(rpf, dl, VI6_RPF_DSWAP, fmtinfo->swap);
|
2013-06-04 18:22:30 +04:00
|
|
|
|
2013-07-11 01:03:46 +04:00
|
|
|
/* Output location */
|
2015-11-16 00:14:22 +03:00
|
|
|
if (pipe->bru) {
|
|
|
|
const struct v4l2_rect *compose;
|
|
|
|
|
|
|
|
compose = vsp1_entity_get_pad_compose(pipe->bru,
|
|
|
|
pipe->bru->config,
|
|
|
|
rpf->bru_input);
|
|
|
|
left = compose->left;
|
|
|
|
top = compose->top;
|
|
|
|
}
|
|
|
|
|
2015-11-23 01:29:25 +03:00
|
|
|
vsp1_rpf_write(rpf, dl, VI6_RPF_LOC,
|
2015-11-16 00:14:22 +03:00
|
|
|
(left << VI6_RPF_LOC_HCOORD_SHIFT) |
|
|
|
|
(top << VI6_RPF_LOC_VCOORD_SHIFT));
|
2013-06-04 18:22:30 +04:00
|
|
|
|
2014-05-22 02:00:05 +04:00
|
|
|
/* Use the alpha channel (extended to 8 bits) when available or an
|
|
|
|
* alpha value set through the V4L2_CID_ALPHA_COMPONENT control
|
|
|
|
* otherwise. Disable color keying.
|
2013-06-04 18:22:30 +04:00
|
|
|
*/
|
2015-11-23 01:29:25 +03:00
|
|
|
vsp1_rpf_write(rpf, dl, VI6_RPF_ALPH_SEL, VI6_RPF_ALPH_SEL_AEXT_EXT |
|
2014-05-27 03:12:53 +04:00
|
|
|
(fmtinfo->alpha ? VI6_RPF_ALPH_SEL_ASEL_PACKED
|
|
|
|
: VI6_RPF_ALPH_SEL_ASEL_FIXED));
|
2015-08-05 22:57:35 +03:00
|
|
|
|
2015-11-23 01:29:25 +03:00
|
|
|
vsp1_rpf_write(rpf, dl, VI6_RPF_VRTCOL_SET,
|
2015-11-01 17:19:42 +03:00
|
|
|
rpf->alpha << VI6_RPF_VRTCOL_SET_LAYA_SHIFT);
|
|
|
|
|
2015-11-23 01:29:25 +03:00
|
|
|
vsp1_pipeline_propagate_alpha(pipe, &rpf->entity, dl, rpf->alpha);
|
2015-08-05 22:57:35 +03:00
|
|
|
|
2015-11-23 01:29:25 +03:00
|
|
|
vsp1_rpf_write(rpf, dl, VI6_RPF_MSK_CTRL, 0);
|
|
|
|
vsp1_rpf_write(rpf, dl, VI6_RPF_CKEY_CTRL, 0);
|
2013-06-04 18:22:30 +04:00
|
|
|
}
|
|
|
|
|
2015-11-17 17:23:23 +03:00
|
|
|
static const struct vsp1_entity_operations rpf_entity_ops = {
|
2015-07-28 22:04:47 +03:00
|
|
|
.set_memory = rpf_set_memory,
|
2015-11-17 18:10:26 +03:00
|
|
|
.configure = rpf_configure,
|
2013-06-04 18:22:30 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/* -----------------------------------------------------------------------------
|
|
|
|
* Initialization and Cleanup
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct vsp1_rwpf *vsp1_rpf_create(struct vsp1_device *vsp1, unsigned int index)
|
|
|
|
{
|
|
|
|
struct vsp1_rwpf *rpf;
|
2015-11-16 00:42:01 +03:00
|
|
|
char name[6];
|
2013-06-04 18:22:30 +04:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
rpf = devm_kzalloc(vsp1->dev, sizeof(*rpf), GFP_KERNEL);
|
|
|
|
if (rpf == NULL)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
|
|
|
rpf->max_width = RPF_MAX_WIDTH;
|
|
|
|
rpf->max_height = RPF_MAX_HEIGHT;
|
|
|
|
|
2015-11-17 17:23:23 +03:00
|
|
|
rpf->entity.ops = &rpf_entity_ops;
|
2013-06-04 18:22:30 +04:00
|
|
|
rpf->entity.type = VSP1_ENTITY_RPF;
|
|
|
|
rpf->entity.index = index;
|
|
|
|
|
2015-11-16 00:42:01 +03:00
|
|
|
sprintf(name, "rpf.%u", index);
|
|
|
|
ret = vsp1_entity_init(vsp1, &rpf->entity, name, 2, &rpf_ops);
|
2013-06-04 18:22:30 +04:00
|
|
|
if (ret < 0)
|
|
|
|
return ERR_PTR(ret);
|
|
|
|
|
2014-05-22 02:00:05 +04:00
|
|
|
/* Initialize the control handler. */
|
2015-11-01 17:19:42 +03:00
|
|
|
ret = vsp1_rwpf_init_ctrls(rpf);
|
|
|
|
if (ret < 0) {
|
2014-05-22 02:00:05 +04:00
|
|
|
dev_err(vsp1->dev, "rpf%u: failed to initialize controls\n",
|
|
|
|
index);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2013-06-04 18:22:30 +04:00
|
|
|
return rpf;
|
|
|
|
|
2014-05-28 19:49:13 +04:00
|
|
|
error:
|
|
|
|
vsp1_entity_destroy(&rpf->entity);
|
2013-06-04 18:22:30 +04:00
|
|
|
return ERR_PTR(ret);
|
|
|
|
}
|