Re: [PATCH 3/3] media: imx-pxp: add i.MX Pixel Pipeline driver

2018-09-04 Thread Philipp Zabel
Hi Jacopo,

thank you for the review!

On Tue, 2018-09-04 at 10:04 +0200, jacopo mondi wrote:
> Hi Philipp,
> 
> On Fri, Aug 10, 2018 at 05:18:22PM +0200, Philipp Zabel wrote:
[...]
> > +static struct pxp_fmt formats[] = {
> > +   {
> > +   .fourcc = V4L2_PIX_FMT_XBGR32,
> > +   .depth  = 32,
> > +   /* Both capture and output format */
> > +   .types  = MEM2MEM_CAPTURE | MEM2MEM_OUTPUT,
[...]
> > +   }, {
> > +   .fourcc = V4L2_PIX_FMT_YUV32,
> > +   .depth  = 16,
> 
> According to:
> https://www.linuxtv.org/downloads/v4l-dvb-apis-old/packed-yuv.html
> shouldn't this be 32?

Yes, I'll change depth to 32.

[...]
> > +}
> > +
> 
> Multiple blank lines (in a few other places too)
> 
> > +

Found them, will fix them.

[...]
> > +   /* Enable clocks and dump registers */
> > +   clk_prepare_enable(dev->clk);
> > +   pxp_soft_reset(dev);
> > +
> > +   spin_lock_init(>irqlock);
> > +
> > +   ret = v4l2_device_register(>dev, >v4l2_dev);
> > +   if (ret)
> > +   return ret;
> > +
> > +   atomic_set(>num_inst, 0);
> > +   mutex_init(>dev_mutex);
> > +
> > +   dev->vfd = pxp_videodev;
> 
> The name of the video device is the same for all instances of this
> driver. Is this ok?

I expect that there is only ever going to be one instance on the SoC.

[...]
> > +   v4l2_device_unregister(>v4l2_dev);
> 
> Disable clock?

Yes, I'll fix the clock handling.

[...]
> > +MODULE_DESCRIPTION("i.MX PXP mem2mem scaler/CSC/rotator");
> > +MODULE_AUTHOR("Philipp Zabel ");
> > +MODULE_LICENSE("GPL");
> 
> SPDX header says GPL2.0+

See include/linux/module.h:

/*
 * The following license idents are currently accepted as indicating free
 * software modules
 *
 *  "GPL"   [GNU Public License v2 or later]
 * [...]
 */

This already seems to be the right choice.

regards
Philipp


Re: [PATCH 3/3] media: imx-pxp: add i.MX Pixel Pipeline driver

2018-09-04 Thread jacopo mondi
Hi Philipp,

On Fri, Aug 10, 2018 at 05:18:22PM +0200, Philipp Zabel wrote:
> Add a V4L2 mem-to-mem scaler/CSC driver for the Pixel Pipeline (PXP)
> version found on i.MX6ULL SoCs. A similar variant is used on i.MX7D.
>
> Since this driver only uses the legacy pipeline, it should be reasonably
> easy to extend it to work with the older PXP versions found on i.MX6UL,
> i.MX6SX, i.MX6SL, i.MX28, and i.MX23.
>
> The driver supports scaling and colorspace conversion. There is
> currently no support for rotation, alpha-blending, and the LUTs.
>
> Signed-off-by: Philipp Zabel 
> ---
>  drivers/media/platform/Kconfig   |9 +
>  drivers/media/platform/Makefile  |2 +
>  drivers/media/platform/imx-pxp.c | 1455 ++
>  drivers/media/platform/imx-pxp.h | 1685 ++
>  4 files changed, 3151 insertions(+)
>  create mode 100644 drivers/media/platform/imx-pxp.c
>  create mode 100644 drivers/media/platform/imx-pxp.h
>
> diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig
> index b25c8d3c1c31..ae1c025c14de 100644
> --- a/drivers/media/platform/Kconfig
> +++ b/drivers/media/platform/Kconfig
> @@ -181,6 +181,15 @@ config VIDEO_CODA
>  config VIDEO_IMX_VDOA
>   def_tristate VIDEO_CODA if SOC_IMX6Q || COMPILE_TEST
>
> +config VIDEO_IMX_PXP
> + tristate "i.MX Pixel Pipeline (PXP)"
> + depends on VIDEO_DEV && VIDEO_V4L2 && (ARCH_MXC || COMPILE_TEST)
> + select VIDEOBUF2_DMA_CONTIG
> + select V4L2_MEM2MEM_DEV
> + help
> +   The i.MX Pixel Pipeline is a memory-to-memory engine for scaling,
> +  color space conversion, and rotation.
> +
>  config VIDEO_MEDIATEK_JPEG
>   tristate "Mediatek JPEG Codec driver"
>   depends on MTK_IOMMU_V1 || COMPILE_TEST
> diff --git a/drivers/media/platform/Makefile b/drivers/media/platform/Makefile
> index 08640ba87fc2..0c2714c2bb05 100644
> --- a/drivers/media/platform/Makefile
> +++ b/drivers/media/platform/Makefile
> @@ -25,6 +25,8 @@ obj-$(CONFIG_VIDEO_TI_CAL)  += ti-vpe/
>  obj-$(CONFIG_VIDEO_MX2_EMMAPRP)  += mx2_emmaprp.o
>  obj-$(CONFIG_VIDEO_CODA) += coda/
>
> +obj-$(CONFIG_VIDEO_IMX_PXP)  += imx-pxp.o
> +
>  obj-$(CONFIG_VIDEO_SH_VEU)   += sh_veu.o
>
>  obj-$(CONFIG_CEC_GPIO)   += cec-gpio/
> diff --git a/drivers/media/platform/imx-pxp.c 
> b/drivers/media/platform/imx-pxp.c
> new file mode 100644
> index ..c9e3ef0f92b4
> --- /dev/null
> +++ b/drivers/media/platform/imx-pxp.c
> @@ -0,0 +1,1455 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * i.MX Pixel Pipeline (PXP) mem-to-mem scaler/CSC/rotator driver
> + *
> + * Copyright (c) 2018 Pengutronix, Philipp Zabel
> + *
> + * based on vim2m
> + *
> + * Copyright (c) 2009-2010 Samsung Electronics Co., Ltd.
> + * Pawel Osciak, 
> + * Marek Szyprowski, 
> + */
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include "imx-pxp.h"
> +
> +static unsigned int debug;
> +module_param(debug, uint, 0644);
> +MODULE_PARM_DESC(debug, "activates debug info");
> +
> +#define MIN_W 8
> +#define MIN_H 8
> +#define MAX_W 4096
> +#define MAX_H 4096
> +#define ALIGN_W 3 /* 8x8 pixel blocks */
> +#define ALIGN_H 3
> +
> +/* Flags that indicate a format can be used for capture/output */
> +#define MEM2MEM_CAPTURE  (1 << 0)
> +#define MEM2MEM_OUTPUT   (1 << 1)
> +
> +#define MEM2MEM_NAME "pxp"
> +
> +/* Per queue */
> +#define MEM2MEM_DEF_NUM_BUFS VIDEO_MAX_FRAME
> +/* In bytes, per queue */
> +#define MEM2MEM_VID_MEM_LIMIT(16 * 1024 * 1024)
> +
> +/* Flags that indicate processing mode */
> +#define MEM2MEM_HFLIP(1 << 0)
> +#define MEM2MEM_VFLIP(1 << 1)
> +
> +#define dprintk(dev, fmt, arg...) \
> + v4l2_dbg(1, debug, >v4l2_dev, "%s: " fmt, __func__, ## arg)
> +
> +struct pxp_fmt {
> + u32 fourcc;
> + int depth;
> + /* Types the format can be used for */
> + u32 types;
> +};
> +
> +static struct pxp_fmt formats[] = {
> + {
> + .fourcc = V4L2_PIX_FMT_XBGR32,
> + .depth  = 32,
> + /* Both capture and output format */
> + .types  = MEM2MEM_CAPTURE | MEM2MEM_OUTPUT,
> + }, {
> + .fourcc = V4L2_PIX_FMT_ABGR32,
> + .depth  = 32,
> + /* Capture-only format */
> + .types  = MEM2MEM_CAPTURE,
> + }, {
> + .fourcc = V4L2_PIX_FMT_BGR24,
> + .depth  = 24,
> + .types  = MEM2MEM_CAPTURE,
> + }, {
> + .fourcc = V4L2_PIX_FMT_RGB565,
> + .depth  = 16,
> + .types  = MEM2MEM_CAPTURE | MEM2MEM_OUTPUT,
> + }, {
> + .fourcc = V4L2_PIX_FMT_RGB555,
> + .depth  = 16,
> + .types  = MEM2MEM_CAPTURE | MEM2MEM_OUTPUT,
> + 

Re: [PATCH 3/3] media: imx-pxp: add i.MX Pixel Pipeline driver

2018-09-03 Thread Philipp Zabel
Hi Hans,

On Mon, 2018-09-03 at 14:55 +0200, Hans Verkuil wrote:
> Hi Philipp,
> 
> Apologies for the delay, but the Request API took most of my time.

Understandable. Also, I expect I'll profit from that work when adding
CODA960 JPEG support. So I have no reason to complain.

> But I finally got around to it:
>
> On 08/10/2018 05:18 PM, Philipp Zabel wrote:
> > Add a V4L2 mem-to-mem scaler/CSC driver for the Pixel Pipeline (PXP)
> > version found on i.MX6ULL SoCs. A similar variant is used on i.MX7D.
> > 
> > Since this driver only uses the legacy pipeline, it should be reasonably
> > easy to extend it to work with the older PXP versions found on i.MX6UL,
> > i.MX6SX, i.MX6SL, i.MX28, and i.MX23.
> > 
> > The driver supports scaling and colorspace conversion. There is
> > currently no support for rotation, alpha-blending, and the LUTs.
> > 
> > Signed-off-by: Philipp Zabel 
> > ---
> >  drivers/media/platform/Kconfig   |9 +
> >  drivers/media/platform/Makefile  |2 +
> >  drivers/media/platform/imx-pxp.c | 1455 ++
> >  drivers/media/platform/imx-pxp.h | 1685 ++
> 
> Missing MAINTAINERS entry.

I'll add one for v2.

[...]
> > +static void pxp_setup_csc(struct pxp_ctx *ctx)
> > +{
> > +   struct pxp_dev *dev = ctx->dev;
> > +
> > +   if (pxp_v4l2_pix_fmt_is_yuv(ctx->q_data[V4L2_M2M_SRC].fmt->fourcc) &&
> > +   !pxp_v4l2_pix_fmt_is_yuv(ctx->q_data[V4L2_M2M_DST].fmt->fourcc)) {
[...]
> > +   if (ctx->ycbcr_enc == V4L2_YCBCR_ENC_601 &&
> > +   ctx->quant == V4L2_QUANTIZATION_FULL_RANGE)
> > +   csc1_coef = csc1_coef_bt601_full;
> > +   else
> > +   csc1_coef = csc1_coef_bt601_lim;
> 
> This is weird: setting ycbcr_enc to V4L2_YCBCR_ENC_709 would result in
> limited range BT601.
> 
> > +
> > +   writel(csc1_coef[0], dev->mmio + HW_PXP_CSC1_COEF0);
> > +   writel(csc1_coef[1], dev->mmio + HW_PXP_CSC1_COEF1);
> > +   writel(csc1_coef[2], dev->mmio + HW_PXP_CSC1_COEF2);
> 
> No support for Rec. 709?

Will add coefficients for Rec. 709.

> > +   } else {
> > +   writel(BM_PXP_CSC1_COEF0_BYPASS, dev->mmio + HW_PXP_CSC1_COEF0);
> > +   }
> > +
> > +   if (!pxp_v4l2_pix_fmt_is_yuv(ctx->q_data[V4L2_M2M_SRC].fmt->fourcc) &&
> > +   pxp_v4l2_pix_fmt_is_yuv(ctx->q_data[V4L2_M2M_DST].fmt->fourcc)) {
[...]
> > +   if (ctx->ycbcr_enc == V4L2_YCBCR_ENC_601 &&
> > +   ctx->quant == V4L2_QUANTIZATION_FULL_RANGE) {
> 
> This makes no sense. ctx->ycbcr_enc and ctx->quant refer to the output queue,
> i.e. the RGB side. ycbcr_enc is ignored for RGB and quant is in practice 
> always
> full range. While you can have limited range RGB as well, that's not however
> what you are trying to implement here.
>
> The problem is that you cannot at the moment specify what ycbcr_enc etc.
> format you want for the capture queue. See below for a link to an RFC to add
> support for this.

Right. I'll split ycbcr_enc and quantization into per-queue settings for
v2 and revive your RFC to allow configuring capture queue colorimetry.

[...]
> > +/*
> > + * video ioctls
> > + */
> > +static int vidioc_querycap(struct file *file, void *priv,
> > +  struct v4l2_capability *cap)
> > +{
> > +   strncpy(cap->driver, MEM2MEM_NAME, sizeof(cap->driver) - 1);
> > +   strncpy(cap->card, MEM2MEM_NAME, sizeof(cap->card) - 1);
> 
> Use strlcpy.

Ok.

> > +   snprintf(cap->bus_info, sizeof(cap->bus_info),
> > +   "platform:%s", MEM2MEM_NAME);
> > +   cap->device_caps = V4L2_CAP_VIDEO_M2M | V4L2_CAP_STREAMING;
> > +   cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
> 
> Please set the device_caps field of video_device, and then you can drop
> these two lines since the core will fill this in for you.

Ok.

[...]
> > +static int vidioc_g_fmt(struct pxp_ctx *ctx, struct v4l2_format *f)
> > +{
> > +   struct vb2_queue *vq;
> > +   struct pxp_q_data *q_data;
> > +
> > +   vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type);
> > +   if (!vq)
> > +   return -EINVAL;
> > +
> > +   q_data = get_q_data(ctx, f->type);
> > +
> > +   f->fmt.pix.width= q_data->width;
> > +   f->fmt.pix.height   = q_data->height;
> > +   f->fmt.pix.field= V4L2_FIELD_NONE;
> > +   f->fmt.pix.pixelformat  = q_data->fmt->fourcc;
> > +   f->fmt.pix.bytesperline = q_data->bytesperline;
> > +   f->fmt.pix.sizeimage= q_data->sizeimage;
> > +   f->fmt.pix.colorspace   = ctx->colorspace;
> > +   f->fmt.pix.xfer_func= ctx->xfer_func;
> > +   f->fmt.pix.ycbcr_enc= ctx->ycbcr_enc;
> > +   f->fmt.pix.quantization = ctx->quant;
> 
> Since you do colorspace conversion, these can't be the same for
> both output and capture.
> 
> colorspace and xfer_func will be the same (those are not converted),
> but ycbcr_enc should be set to 0 for RGB and quantization range
> will be different as well (either set to 0 for capture, or set
> to FULL for RGB capture and 

Re: [PATCH 3/3] media: imx-pxp: add i.MX Pixel Pipeline driver

2018-09-03 Thread Hans Verkuil
Hi Philipp,

Apologies for the delay, but the Request API took most of my time.

But I finally got around to it:

On 08/10/2018 05:18 PM, Philipp Zabel wrote:
> Add a V4L2 mem-to-mem scaler/CSC driver for the Pixel Pipeline (PXP)
> version found on i.MX6ULL SoCs. A similar variant is used on i.MX7D.
> 
> Since this driver only uses the legacy pipeline, it should be reasonably
> easy to extend it to work with the older PXP versions found on i.MX6UL,
> i.MX6SX, i.MX6SL, i.MX28, and i.MX23.
> 
> The driver supports scaling and colorspace conversion. There is
> currently no support for rotation, alpha-blending, and the LUTs.
> 
> Signed-off-by: Philipp Zabel 
> ---
>  drivers/media/platform/Kconfig   |9 +
>  drivers/media/platform/Makefile  |2 +
>  drivers/media/platform/imx-pxp.c | 1455 ++
>  drivers/media/platform/imx-pxp.h | 1685 ++

Missing MAINTAINERS entry.

>  4 files changed, 3151 insertions(+)
>  create mode 100644 drivers/media/platform/imx-pxp.c
>  create mode 100644 drivers/media/platform/imx-pxp.h
> 
> diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig
> index b25c8d3c1c31..ae1c025c14de 100644
> --- a/drivers/media/platform/Kconfig
> +++ b/drivers/media/platform/Kconfig
> @@ -181,6 +181,15 @@ config VIDEO_CODA
>  config VIDEO_IMX_VDOA
>   def_tristate VIDEO_CODA if SOC_IMX6Q || COMPILE_TEST
>  
> +config VIDEO_IMX_PXP
> + tristate "i.MX Pixel Pipeline (PXP)"
> + depends on VIDEO_DEV && VIDEO_V4L2 && (ARCH_MXC || COMPILE_TEST)
> + select VIDEOBUF2_DMA_CONTIG
> + select V4L2_MEM2MEM_DEV
> + help
> +   The i.MX Pixel Pipeline is a memory-to-memory engine for scaling,
> +  color space conversion, and rotation.
> +
>  config VIDEO_MEDIATEK_JPEG
>   tristate "Mediatek JPEG Codec driver"
>   depends on MTK_IOMMU_V1 || COMPILE_TEST
> diff --git a/drivers/media/platform/Makefile b/drivers/media/platform/Makefile
> index 08640ba87fc2..0c2714c2bb05 100644
> --- a/drivers/media/platform/Makefile
> +++ b/drivers/media/platform/Makefile
> @@ -25,6 +25,8 @@ obj-$(CONFIG_VIDEO_TI_CAL)  += ti-vpe/
>  obj-$(CONFIG_VIDEO_MX2_EMMAPRP)  += mx2_emmaprp.o
>  obj-$(CONFIG_VIDEO_CODA) += coda/
>  
> +obj-$(CONFIG_VIDEO_IMX_PXP)  += imx-pxp.o
> +
>  obj-$(CONFIG_VIDEO_SH_VEU)   += sh_veu.o
>  
>  obj-$(CONFIG_CEC_GPIO)   += cec-gpio/
> diff --git a/drivers/media/platform/imx-pxp.c 
> b/drivers/media/platform/imx-pxp.c
> new file mode 100644
> index ..c9e3ef0f92b4
> --- /dev/null
> +++ b/drivers/media/platform/imx-pxp.c
> @@ -0,0 +1,1455 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * i.MX Pixel Pipeline (PXP) mem-to-mem scaler/CSC/rotator driver
> + *
> + * Copyright (c) 2018 Pengutronix, Philipp Zabel
> + *
> + * based on vim2m
> + *
> + * Copyright (c) 2009-2010 Samsung Electronics Co., Ltd.
> + * Pawel Osciak, 
> + * Marek Szyprowski, 
> + */
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include "imx-pxp.h"
> +
> +static unsigned int debug;
> +module_param(debug, uint, 0644);
> +MODULE_PARM_DESC(debug, "activates debug info");
> +
> +#define MIN_W 8
> +#define MIN_H 8
> +#define MAX_W 4096
> +#define MAX_H 4096
> +#define ALIGN_W 3 /* 8x8 pixel blocks */
> +#define ALIGN_H 3
> +
> +/* Flags that indicate a format can be used for capture/output */
> +#define MEM2MEM_CAPTURE  (1 << 0)
> +#define MEM2MEM_OUTPUT   (1 << 1)
> +
> +#define MEM2MEM_NAME "pxp"
> +
> +/* Per queue */
> +#define MEM2MEM_DEF_NUM_BUFS VIDEO_MAX_FRAME
> +/* In bytes, per queue */
> +#define MEM2MEM_VID_MEM_LIMIT(16 * 1024 * 1024)
> +
> +/* Flags that indicate processing mode */
> +#define MEM2MEM_HFLIP(1 << 0)
> +#define MEM2MEM_VFLIP(1 << 1)
> +
> +#define dprintk(dev, fmt, arg...) \
> + v4l2_dbg(1, debug, >v4l2_dev, "%s: " fmt, __func__, ## arg)
> +
> +struct pxp_fmt {
> + u32 fourcc;
> + int depth;
> + /* Types the format can be used for */
> + u32 types;
> +};
> +
> +static struct pxp_fmt formats[] = {
> + {
> + .fourcc = V4L2_PIX_FMT_XBGR32,
> + .depth  = 32,
> + /* Both capture and output format */
> + .types  = MEM2MEM_CAPTURE | MEM2MEM_OUTPUT,
> + }, {
> + .fourcc = V4L2_PIX_FMT_ABGR32,
> + .depth  = 32,
> + /* Capture-only format */
> + .types  = MEM2MEM_CAPTURE,
> + }, {
> + .fourcc = V4L2_PIX_FMT_BGR24,
> + .depth  = 24,
> + .types  = MEM2MEM_CAPTURE,
> + }, {
> + .fourcc = V4L2_PIX_FMT_RGB565,
> + .depth  = 16,
> + .types  = MEM2MEM_CAPTURE | MEM2MEM_OUTPUT,
> + }, {
> + .fourcc 

Re: [PATCH 3/3] media: imx-pxp: add i.MX Pixel Pipeline driver

2018-08-10 Thread Philipp Zabel
On Fri, 2018-08-10 at 17:18 +0200, Philipp Zabel wrote:
> Add a V4L2 mem-to-mem scaler/CSC driver for the Pixel Pipeline (PXP)
> version found on i.MX6ULL SoCs. A similar variant is used on i.MX7D.
> 
> Since this driver only uses the legacy pipeline, it should be reasonably
> easy to extend it to work with the older PXP versions found on i.MX6UL,
> i.MX6SX, i.MX6SL, i.MX28, and i.MX23.
> 
> The driver supports scaling and colorspace conversion. There is
> currently no support for rotation, alpha-blending, and the LUTs.
> 
> Signed-off-by: Philipp Zabel 

FWIW for mem2mem devices, here is the output of v4l2-compliance, built
from v4l-utils-1.14.0-249-g70b13df426d3:

--8<--
v4l2-compliance SHA: not available, 32 bits

Compliance test for device /dev/video0:

Driver Info:
Driver name  : pxp
Card type: pxp
Bus info : platform:pxp
Driver version   : 4.18.0
Capabilities : 0x84208000
Video Memory-to-Memory
Streaming
Extended Pix Format
Device Capabilities
Device Caps  : 0x04208000
Video Memory-to-Memory
Streaming
Extended Pix Format

Required ioctls:
test VIDIOC_QUERYCAP: OK

Allow for multiple opens:
test second /dev/video0 open: OK
test VIDIOC_QUERYCAP: OK
test VIDIOC_G/S_PRIORITY: OK
test for unlimited opens: OK

Debug ioctls:
test VIDIOC_DBG_G/S_REGISTER: OK
test VIDIOC_LOG_STATUS: OK (Not Supported)

Input ioctls:
test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported)
test VIDIOC_G/S_FREQUENCY: OK (Not Supported)
test VIDIOC_S_HW_FREQ_SEEK: OK (Not Supported)
test VIDIOC_ENUMAUDIO: OK (Not Supported)
test VIDIOC_G/S/ENUMINPUT: OK (Not Supported)
test VIDIOC_G/S_AUDIO: OK (Not Supported)
Inputs: 0 Audio Inputs: 0 Tuners: 0

Output ioctls:
test VIDIOC_G/S_MODULATOR: OK (Not Supported)
test VIDIOC_G/S_FREQUENCY: OK (Not Supported)
test VIDIOC_ENUMAUDOUT: OK (Not Supported)
test VIDIOC_G/S/ENUMOUTPUT: OK (Not Supported)
test VIDIOC_G/S_AUDOUT: OK (Not Supported)
Outputs: 0 Audio Outputs: 0 Modulators: 0

Input/Output configuration ioctls:
test VIDIOC_ENUM/G/S/QUERY_STD: OK (Not Supported)
test VIDIOC_ENUM/G/S/QUERY_DV_TIMINGS: OK (Not Supported)
test VIDIOC_DV_TIMINGS_CAP: OK (Not Supported)
test VIDIOC_G/S_EDID: OK (Not Supported)

Control ioctls:
test VIDIOC_QUERY_EXT_CTRL/QUERYMENU: OK
test VIDIOC_QUERYCTRL: OK
test VIDIOC_G/S_CTRL: OK
test VIDIOC_G/S/TRY_EXT_CTRLS: OK
test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: OK
test VIDIOC_G/S_JPEGCOMP: OK (Not Supported)
Standard Controls: 4 Private Controls: 0

Format ioctls:
test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK
test VIDIOC_G/S_PARM: OK (Not Supported)
test VIDIOC_G_FBUF: OK (Not Supported)
test VIDIOC_G_FMT: OK
test VIDIOC_TRY_FMT: OK
test VIDIOC_S_FMT: OK
test VIDIOC_G_SLICED_VBI_CAP: OK (Not Supported)
test Cropping: OK (Not Supported)
test Composing: OK (Not Supported)
test Scaling: OK

Codec ioctls:
test VIDIOC_(TRY_)ENCODER_CMD: OK (Not Supported)
test VIDIOC_G_ENC_INDEX: OK (Not Supported)
test VIDIOC_(TRY_)DECODER_CMD: OK (Not Supported)

Buffer ioctls:
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK
test VIDIOC_EXPBUF: OK

Total: 43, Succeeded: 43, Failed: 0, Warnings: 0
-->8--

regards
Philipp


[PATCH 3/3] media: imx-pxp: add i.MX Pixel Pipeline driver

2018-08-10 Thread Philipp Zabel
Add a V4L2 mem-to-mem scaler/CSC driver for the Pixel Pipeline (PXP)
version found on i.MX6ULL SoCs. A similar variant is used on i.MX7D.

Since this driver only uses the legacy pipeline, it should be reasonably
easy to extend it to work with the older PXP versions found on i.MX6UL,
i.MX6SX, i.MX6SL, i.MX28, and i.MX23.

The driver supports scaling and colorspace conversion. There is
currently no support for rotation, alpha-blending, and the LUTs.

Signed-off-by: Philipp Zabel 
---
 drivers/media/platform/Kconfig   |9 +
 drivers/media/platform/Makefile  |2 +
 drivers/media/platform/imx-pxp.c | 1455 ++
 drivers/media/platform/imx-pxp.h | 1685 ++
 4 files changed, 3151 insertions(+)
 create mode 100644 drivers/media/platform/imx-pxp.c
 create mode 100644 drivers/media/platform/imx-pxp.h

diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig
index b25c8d3c1c31..ae1c025c14de 100644
--- a/drivers/media/platform/Kconfig
+++ b/drivers/media/platform/Kconfig
@@ -181,6 +181,15 @@ config VIDEO_CODA
 config VIDEO_IMX_VDOA
def_tristate VIDEO_CODA if SOC_IMX6Q || COMPILE_TEST
 
+config VIDEO_IMX_PXP
+   tristate "i.MX Pixel Pipeline (PXP)"
+   depends on VIDEO_DEV && VIDEO_V4L2 && (ARCH_MXC || COMPILE_TEST)
+   select VIDEOBUF2_DMA_CONTIG
+   select V4L2_MEM2MEM_DEV
+   help
+ The i.MX Pixel Pipeline is a memory-to-memory engine for scaling,
+  color space conversion, and rotation.
+
 config VIDEO_MEDIATEK_JPEG
tristate "Mediatek JPEG Codec driver"
depends on MTK_IOMMU_V1 || COMPILE_TEST
diff --git a/drivers/media/platform/Makefile b/drivers/media/platform/Makefile
index 08640ba87fc2..0c2714c2bb05 100644
--- a/drivers/media/platform/Makefile
+++ b/drivers/media/platform/Makefile
@@ -25,6 +25,8 @@ obj-$(CONFIG_VIDEO_TI_CAL)+= ti-vpe/
 obj-$(CONFIG_VIDEO_MX2_EMMAPRP)+= mx2_emmaprp.o
 obj-$(CONFIG_VIDEO_CODA)   += coda/
 
+obj-$(CONFIG_VIDEO_IMX_PXP)+= imx-pxp.o
+
 obj-$(CONFIG_VIDEO_SH_VEU) += sh_veu.o
 
 obj-$(CONFIG_CEC_GPIO) += cec-gpio/
diff --git a/drivers/media/platform/imx-pxp.c b/drivers/media/platform/imx-pxp.c
new file mode 100644
index ..c9e3ef0f92b4
--- /dev/null
+++ b/drivers/media/platform/imx-pxp.c
@@ -0,0 +1,1455 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * i.MX Pixel Pipeline (PXP) mem-to-mem scaler/CSC/rotator driver
+ *
+ * Copyright (c) 2018 Pengutronix, Philipp Zabel
+ *
+ * based on vim2m
+ *
+ * Copyright (c) 2009-2010 Samsung Electronics Co., Ltd.
+ * Pawel Osciak, 
+ * Marek Szyprowski, 
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "imx-pxp.h"
+
+static unsigned int debug;
+module_param(debug, uint, 0644);
+MODULE_PARM_DESC(debug, "activates debug info");
+
+#define MIN_W 8
+#define MIN_H 8
+#define MAX_W 4096
+#define MAX_H 4096
+#define ALIGN_W 3 /* 8x8 pixel blocks */
+#define ALIGN_H 3
+
+/* Flags that indicate a format can be used for capture/output */
+#define MEM2MEM_CAPTURE(1 << 0)
+#define MEM2MEM_OUTPUT (1 << 1)
+
+#define MEM2MEM_NAME   "pxp"
+
+/* Per queue */
+#define MEM2MEM_DEF_NUM_BUFS   VIDEO_MAX_FRAME
+/* In bytes, per queue */
+#define MEM2MEM_VID_MEM_LIMIT  (16 * 1024 * 1024)
+
+/* Flags that indicate processing mode */
+#define MEM2MEM_HFLIP  (1 << 0)
+#define MEM2MEM_VFLIP  (1 << 1)
+
+#define dprintk(dev, fmt, arg...) \
+   v4l2_dbg(1, debug, >v4l2_dev, "%s: " fmt, __func__, ## arg)
+
+struct pxp_fmt {
+   u32 fourcc;
+   int depth;
+   /* Types the format can be used for */
+   u32 types;
+};
+
+static struct pxp_fmt formats[] = {
+   {
+   .fourcc = V4L2_PIX_FMT_XBGR32,
+   .depth  = 32,
+   /* Both capture and output format */
+   .types  = MEM2MEM_CAPTURE | MEM2MEM_OUTPUT,
+   }, {
+   .fourcc = V4L2_PIX_FMT_ABGR32,
+   .depth  = 32,
+   /* Capture-only format */
+   .types  = MEM2MEM_CAPTURE,
+   }, {
+   .fourcc = V4L2_PIX_FMT_BGR24,
+   .depth  = 24,
+   .types  = MEM2MEM_CAPTURE,
+   }, {
+   .fourcc = V4L2_PIX_FMT_RGB565,
+   .depth  = 16,
+   .types  = MEM2MEM_CAPTURE | MEM2MEM_OUTPUT,
+   }, {
+   .fourcc = V4L2_PIX_FMT_RGB555,
+   .depth  = 16,
+   .types  = MEM2MEM_CAPTURE | MEM2MEM_OUTPUT,
+   }, {
+   .fourcc = V4L2_PIX_FMT_RGB444,
+   .depth  = 16,
+   .types  = MEM2MEM_CAPTURE | MEM2MEM_OUTPUT,
+   }, {
+   .fourcc = V4L2_PIX_FMT_YUV32,
+   .depth  = 16,
+   .types  = MEM2MEM_CAPTURE | MEM2MEM_OUTPUT,
+   }, {
+