Re: [PATCH -next] media: ti-vpe: sc: remove redundant dev_err call in sc_create()

2021-04-02 Thread Benoit Parrot
Yang,

Thank you for the patch.

Yang Yingliang  wrote on Thu [2021-Apr-01 18:30:15 
+0800]:
> There is an error message within devm_ioremap_resource
> already, so remove the dev_err call to avoid redundant
> error message.
> 
> Reported-by: Hulk Robot 
> Signed-off-by: Yang Yingliang 
> ---
>  drivers/media/platform/ti-vpe/sc.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/drivers/media/platform/ti-vpe/sc.c 
> b/drivers/media/platform/ti-vpe/sc.c
> index 98f95082a6fd..0202d278523f 100644
> --- a/drivers/media/platform/ti-vpe/sc.c
> +++ b/drivers/media/platform/ti-vpe/sc.c
> @@ -294,10 +294,8 @@ struct sc_data *sc_create(struct platform_device *pdev, 
> const char *res_name)
>   }
>  
>   sc->base = devm_ioremap_resource(&pdev->dev, sc->res);
> - if (IS_ERR(sc->base)) {
> - dev_err(&pdev->dev, "failed to ioremap\n");
> + if (IS_ERR(sc->base))
>   return ERR_CAST(sc->base);
> - }

Reviewed-by: Benoit Parrot 

>  
>   return sc;
>  }
> -- 
> 2.25.1
> 


Re: [PATCH -next] media: ti-vpe: csc: remove redundant dev_err call in csc_create()

2021-04-02 Thread Benoit Parrot
Yang,

Thank you for the patch.

Yang Yingliang  wrote on Thu [2021-Apr-01 18:28:50 
+0800]:
> There is an error message within devm_ioremap_resource
> already, so remove the dev_err call to avoid redundant
> error message.
> 
> Reported-by: Hulk Robot 
> Signed-off-by: Yang Yingliang 
> ---
>  drivers/media/platform/ti-vpe/csc.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/drivers/media/platform/ti-vpe/csc.c 
> b/drivers/media/platform/ti-vpe/csc.c
> index f4e0cf72d1cf..ff15bc589f1b 100644
> --- a/drivers/media/platform/ti-vpe/csc.c
> +++ b/drivers/media/platform/ti-vpe/csc.c
> @@ -267,10 +267,8 @@ struct csc_data *csc_create(struct platform_device 
> *pdev, const char *res_name)
>   }
>  
>   csc->base = devm_ioremap_resource(&pdev->dev, csc->res);
> - if (IS_ERR(csc->base)) {
> - dev_err(&pdev->dev, "failed to ioremap\n");
> + if (IS_ERR(csc->base))
>   return ERR_CAST(csc->base);
> - }

Reviewed-by: Benoit Parrot 

>  
>   return csc;
>  }
> -- 
> 2.25.1
> 


Re: [PATCH 13/16] media: ti-vpe: csi2rx: Add CSI2RX support

2021-03-31 Thread Benoit Parrot
Pratyush,

Tomi Valkeinen  wrote on Wed [2021-Mar-31 
09:06:35 +0300]:
> Hi,
> 
> On 30/03/2021 20:33, Pratyush Yadav wrote:
> > TI's J721E uses the Cadence CSI2RX and DPHY peripherals to facilitate
> > capture over a CSI-2 bus.
> > 
> > The Cadence CSI2RX IP acts as a bridge between the TI specific parts and
> > the CSI-2 protocol parts. TI then has a wrapper on top of this bridge
> > called the SHIM layer. It takes in data from stream 0, repacks it, and
> > sends it to memory over PSI-L DMA.
> > 
> > This driver acts as the "front end" to V4L2 client applications. It
> > implements the required ioctls and buffer operations, passes the
> > necessary calls on to the bridge, programs the SHIM layer, and performs
> > DMA via the dmaengine API to finally return the data to a buffer
> > supplied by the application.
> > 
> > Signed-off-by: Pratyush Yadav 
> > ---
> >   MAINTAINERS   |   7 +
> >   drivers/media/platform/Kconfig|  11 +
> >   drivers/media/platform/ti-vpe/Makefile|   1 +
> >   drivers/media/platform/ti-vpe/ti-csi2rx.c | 964 ++
> >   4 files changed, 983 insertions(+)
> >   create mode 100644 drivers/media/platform/ti-vpe/ti-csi2rx.c
> 
> Some quick comments:
> 
> "ti-vpe" directory is not correct, this has nothing to do with VPE. That
> said, the directory has already been abused by having CAL driver there,
> perhaps we should rename the directory just to "ti". But if we do that,
> I think we should have subdirs for cal, vpe and this new one.

I agree with Tomi here. This should create a ti directory under
media/platform and then add a directory under that specifically for this
driver/IP as a first step. Not sure what the correct name for that
directory should be but it should meaningful. As a follow on step then the
other drivers can be relocated to a proper directory structure.
> 
> "ti-csi2rx" is rather generic name. TI has had CSI-2 RX IPs before (CAL)
> and probably will also have new ones in the future. If there's no clear
> model name for the IP, as I think is the case here, it's probably best
> to just use the SoC model in the name. E.g. the DSS on J7 is
> "ti,j721e-dss".
> 
> This driver implements the legacy video API. I think it would be better
> (and easier to maintain) to only implement the media-controller API,
> unless you specifically need to support the legacy API for existing
> userspace.

We just went through a major rework with CAL to make it media controller
compatible in order to be able to handle CSI2 virtual channels.
I think as this is a new driver/IP which perform the same type of service
it makes sense to make use the more current API instead of the legacy one.

> 
>  Tomi

Benoit


Re: [PATCH 19/20] media: platform: vpdma.c: fix comparison to bool

2020-08-11 Thread Benoit Parrot
Daniel W. S. Almeida  wrote on Fri [2020-Aug-07 05:35:46 
-0300]:
> From: "Daniel W. S. Almeida" 
> 
> Fix the following coccinelle report:
> 
> drivers/media/platform/ti-vpe/vpdma.c:946:5-26: WARNING:
> Comparison to bool
> 
> Found using - Coccinelle (http://coccinelle.lip6.fr)
> 
> Signed-off-by: Daniel W. S. Almeida 

Reviewed-by: Benoit Parrot 

> ---
>  drivers/media/platform/ti-vpe/vpdma.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/media/platform/ti-vpe/vpdma.c 
> b/drivers/media/platform/ti-vpe/vpdma.c
> index 2e5148ae7a0f..de600bbc 100644
> --- a/drivers/media/platform/ti-vpe/vpdma.c
> +++ b/drivers/media/platform/ti-vpe/vpdma.c
> @@ -943,7 +943,7 @@ int vpdma_hwlist_alloc(struct vpdma_data *vpdma, void 
> *priv)
>  
>   spin_lock_irqsave(&vpdma->lock, flags);
>   for (i = 0; i < VPDMA_MAX_NUM_LIST &&
> - vpdma->hwlist_used[i] == true; i++)
> + vpdma->hwlist_used[i]; i++)
>   ;
>  
>   if (i < VPDMA_MAX_NUM_LIST) {
> -- 
> 2.28.0
> 


Re: [Patch 1/2] dt-binbings: media: ti-vpe: Document the VIP driver

2020-05-29 Thread Benoit Parrot
Hi Rob,

Thanks for the review.

Rob Herring  wrote on Thu [2020-May-28 17:39:33 -0600]:
> On Fri, May 22, 2020 at 05:54:11PM -0500, Benoit Parrot wrote:
> > Device Tree bindings for the Video Input Port (VIP) driver.
> 
> Bindings document h/w, not drivers.

I'll fix that.

> 
> > 
> > Signed-off-by: Benoit Parrot 
> > ---
> >  .../devicetree/bindings/media/ti,vip.yaml | 394 ++
> >  MAINTAINERS   |   1 +
> >  2 files changed, 395 insertions(+)
> >  create mode 100644 Documentation/devicetree/bindings/media/ti,vip.yaml
> > 
> > diff --git a/Documentation/devicetree/bindings/media/ti,vip.yaml 
> > b/Documentation/devicetree/bindings/media/ti,vip.yaml
> > new file mode 100644
> > index ..8a9084e42329
> > --- /dev/null
> > +++ b/Documentation/devicetree/bindings/media/ti,vip.yaml
> > @@ -0,0 +1,394 @@
> > +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
> > +%YAML 1.2
> > +---
> > +$id: http://devicetree.org/schemas/media/ti,vip.yaml#
> > +$schema: http://devicetree.org/meta-schemas/core.yaml#
> > +
> > +title: Texas Instruments DRA7x VIDEO INPUT PORT (VIP) Device Tree Bindings
> > +
> > +maintainers:
> > +  - Benoit Parrot 
> > +
> > +description: |-
> > +  The Video Input Port (VIP) is a key component for image capture
> > +  applications. The capture module provides the system interface and the
> > +  processing capability to connect parallel image-sensor as well as
> > +  BT.656/1120 capable encoder chip to DRA7x device.
> > +
> > +  Each VIP instance supports 2 independently configurable external video
> > +  input capture slices (Slice 0 and Slice 1) each providing up to two video
> > +  input ports (Port A and Port B) where Port A can be configured as
> > +  24/16/8-bit port and Port B is fixed as 8-bit port.
> > +  Here these ports a represented as follows
> > +port@0 -> Slice 0 Port A
> > +port@1 -> Slice 0 Port B
> > +port@2 -> Slice 1 Port A
> > +port@3 -> Slice 1 Port B
> > +
> > +  Each camera port nodes should contain a 'port' child node with child
> > +  'endpoint' node. Please refer to the bindings defined in
> > +  Documentation/devicetree/bindings/media/video-interfaces.txt.
> > +
> > +properties:
> > +  compatible:
> > +const: ti,dra7-vip
> > +
> > +  label:
> > +description: Instance name
> 
> Kind of odd for this type of binding. Are there a define set or pattern 
> of values.

The label here are used to 'name' each H/W instance. And so far there can
be a up to 3 instances with the currently available devices, but that
doesn't mean there couldn't be more in the future. So I did not want to
limit it here.

> 
> > +
> > +  reg:
> > +items:
> > +  - description: The VIP main register region
> > +  - description: Video Data Parser (PARSER) register region for Slice0
> > +  - description: Color Space Conversion (CSC) register region for 
> > Slice0
> > +  - description: Scaler (SC) register region for Slice0
> > +  - description: Video Data Parser (PARSER) register region for Slice1
> > +  - description: Color Space Conversion (CSC) register region for 
> > Slice1
> > +  - description: Scaler (SC) register region for Slice1
> > +  - description: Video Port Direct Memory Access (VPDMA) register 
> > region
> > +
> > +  reg-names:
> > +items:
> > +  - const: vip
> > +  - const: parser0
> > +  - const: csc0
> > +  - const: sc0
> > +  - const: parser1
> > +  - const: csc1
> > +  - const: sc1
> > +  - const: vpdma
> > +
> > +  interrupts:
> > +minItems: 2
> > +description:
> > +  IRQ index 0 is used for Slice0 interrupts
> > +  IRQ index 1 is used for Slice1 interrupts
> > +
> > +  ti,vip-clk-polarity:
> > +$ref: "/schemas/types.yaml#/definitions/phandle-array"
> > +description:
> > +  phandle to the device control module. The 1st argument should
> > +  contain the register offset to the CTRL_CORE_SMA_SW_1 register.
> > +  2nd argument contains the bit field to slice 0 port A,
> > +  3rd argument contains the bit field to slice 0 port B,
> > +  4th argument contains the bit field to slice 1 port A,
> > +  5th argument contains the bit field to slice 1 port B.
> > +
> > +  # See ./video-interfaces.t

[Patch 2/2] media: use v4l2_rect_enclosed helper

2020-05-28 Thread Benoit Parrot
Several drivers implement the same enclosed_rectangle() function to
check if a rectangle is enclosed into another. Replace this with the
newly added v4l2_rect_enclosed() helper function.

Signed-off-by: Benoit Parrot 
---
 drivers/media/platform/am437x/am437x-vpfe.c   | 19 +++
 .../media/platform/exynos4-is/fimc-capture.c  | 18 +++---
 drivers/media/platform/exynos4-is/fimc-lite.c | 18 +++---
 drivers/media/platform/s5p-jpeg/jpeg-core.c   | 16 ++--
 4 files changed, 11 insertions(+), 60 deletions(-)

diff --git a/drivers/media/platform/am437x/am437x-vpfe.c 
b/drivers/media/platform/am437x/am437x-vpfe.c
index 66079cc41f38..0fb9f9ba1219 100644
--- a/drivers/media/platform/am437x/am437x-vpfe.c
+++ b/drivers/media/platform/am437x/am437x-vpfe.c
@@ -26,6 +26,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "am437x-vpfe.h"
 
@@ -1987,20 +1988,6 @@ vpfe_g_selection(struct file *file, void *fh, struct 
v4l2_selection *s)
return 0;
 }
 
-static int enclosed_rectangle(struct v4l2_rect *a, struct v4l2_rect *b)
-{
-   if (a->left < b->left || a->top < b->top)
-   return 0;
-
-   if (a->left + a->width > b->left + b->width)
-   return 0;
-
-   if (a->top + a->height > b->top + b->height)
-   return 0;
-
-   return 1;
-}
-
 static int
 vpfe_s_selection(struct file *file, void *fh, struct v4l2_selection *s)
 {
@@ -2025,10 +2012,10 @@ vpfe_s_selection(struct file *file, void *fh, struct 
v4l2_selection *s)
r.left = clamp_t(unsigned int, r.left, 0, cr.width - r.width);
r.top  = clamp_t(unsigned int, r.top, 0, cr.height - r.height);
 
-   if (s->flags & V4L2_SEL_FLAG_LE && !enclosed_rectangle(&r, &s->r))
+   if (s->flags & V4L2_SEL_FLAG_LE && !v4l2_rect_enclosed(&r, &s->r))
return -ERANGE;
 
-   if (s->flags & V4L2_SEL_FLAG_GE && !enclosed_rectangle(&s->r, &r))
+   if (s->flags & V4L2_SEL_FLAG_GE && !v4l2_rect_enclosed(&s->r, &r))
return -ERANGE;
 
s->r = vpfe->crop = r;
diff --git a/drivers/media/platform/exynos4-is/fimc-capture.c 
b/drivers/media/platform/exynos4-is/fimc-capture.c
index 705f182330ca..8b10741a847a 100644
--- a/drivers/media/platform/exynos4-is/fimc-capture.c
+++ b/drivers/media/platform/exynos4-is/fimc-capture.c
@@ -21,6 +21,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -1299,19 +1300,6 @@ static int fimc_cap_g_selection(struct file *file, void 
*fh,
return -EINVAL;
 }
 
-/* Return 1 if rectangle a is enclosed in rectangle b, or 0 otherwise. */
-static int enclosed_rectangle(struct v4l2_rect *a, struct v4l2_rect *b)
-{
-   if (a->left < b->left || a->top < b->top)
-   return 0;
-   if (a->left + a->width > b->left + b->width)
-   return 0;
-   if (a->top + a->height > b->top + b->height)
-   return 0;
-
-   return 1;
-}
-
 static int fimc_cap_s_selection(struct file *file, void *fh,
struct v4l2_selection *s)
 {
@@ -1334,11 +1322,11 @@ static int fimc_cap_s_selection(struct file *file, void 
*fh,
fimc_capture_try_selection(ctx, &rect, s->target);
 
if (s->flags & V4L2_SEL_FLAG_LE &&
-   !enclosed_rectangle(&rect, &s->r))
+   !v4l2_rect_enclosed(&rect, &s->r))
return -ERANGE;
 
if (s->flags & V4L2_SEL_FLAG_GE &&
-   !enclosed_rectangle(&s->r, &rect))
+   !v4l2_rect_enclosed(&s->r, &rect))
return -ERANGE;
 
s->r = rect;
diff --git a/drivers/media/platform/exynos4-is/fimc-lite.c 
b/drivers/media/platform/exynos4-is/fimc-lite.c
index 394e0818f2d5..9c666f663ab4 100644
--- a/drivers/media/platform/exynos4-is/fimc-lite.c
+++ b/drivers/media/platform/exynos4-is/fimc-lite.c
@@ -25,6 +25,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -868,19 +869,6 @@ static int fimc_lite_reqbufs(struct file *file, void *priv,
return ret;
 }
 
-/* Return 1 if rectangle a is enclosed in rectangle b, or 0 otherwise. */
-static int enclosed_rectangle(struct v4l2_rect *a, struct v4l2_rect *b)
-{
-   if (a->left < b->left || a->top < b->top)
-   return 0;
-   if (a->left + a->width > b->left + b->width)
-   return 0;
-   if (a->top + a->height > b->top + b->height)
-   return 0;
-
-   return 1;
-}
-
 static int fimc_lite_g_selection(struct file *file, void *fh,
 struct v4l2_selection *sel)
 {
@@ -922,11 +910,11 @@ static int fimc_lite_s_selection(

[Patch 1/2] media: v4l2-rect.h: add enclosed rectangle helper

2020-05-28 Thread Benoit Parrot
Add a helper function to check if one rectangle is enclosed inside
another.

Signed-off-by: Benoit Parrot 
---
 include/media/v4l2-rect.h | 20 
 1 file changed, 20 insertions(+)

diff --git a/include/media/v4l2-rect.h b/include/media/v4l2-rect.h
index 8800a640c224..bd587d0c0dc3 100644
--- a/include/media/v4l2-rect.h
+++ b/include/media/v4l2-rect.h
@@ -184,4 +184,24 @@ static inline bool v4l2_rect_overlap(const struct 
v4l2_rect *r1,
return true;
 }
 
+/**
+ * v4l2_rect_enclosed() - is r1 enclosed in r2?
+ * @r1: rectangle.
+ * @r2: rectangle.
+ *
+ * Returns true if @r1 is enclosed in @r2.
+ */
+static inline bool v4l2_rect_enclosed(struct v4l2_rect *r1,
+ struct v4l2_rect *r2)
+{
+   if (r1->left < r2->left || r1->top < r2->top)
+   return false;
+   if (r1->left + r1->width > r2->left + r2->width)
+   return false;
+   if (r1->top + r1->height > r2->top + r2->height)
+   return false;
+
+   return true;
+}
+
 #endif
-- 
2.17.1



[Patch 0/2] media: v4l2-rect.h: add enclosed rectangle helper

2020-05-28 Thread Benoit Parrot
This series introduces a new v4l2_rect_enclosed helper function which
already exist in some form in several drivers. It then proceed to
update those drivers to use the new helper function.

Benoit Parrot (2):
  media: v4l2-rect.h: add enclosed rectangle helper
  media: use v4l2_rect_enclosed helper

 drivers/media/platform/am437x/am437x-vpfe.c   | 19 +++---
 .../media/platform/exynos4-is/fimc-capture.c  | 18 +++--
 drivers/media/platform/exynos4-is/fimc-lite.c | 18 +++--
 drivers/media/platform/s5p-jpeg/jpeg-core.c   | 16 ++-
 include/media/v4l2-rect.h | 20 +++
 5 files changed, 31 insertions(+), 60 deletions(-)

-- 
2.17.1



[Patch 2/2] media: ti-vpe: Add the VIP driver

2020-05-22 Thread Benoit Parrot
VIP stands for Video Input Port, it can be found on devices such as
DRA7xx and provides a parallel interface to a video source such as
a sensor or TV decoder.  Each VIP can support two inputs (slices) and
a SoC can be configured with a variable number of VIP's.
Each slice can supports two ports each connected to its own
sub-device.

Signed-off-by: Benoit Parrot 
Signed-off-by: Nikhil Devshatwar 
---
 drivers/media/platform/Kconfig |   13 +
 drivers/media/platform/ti-vpe/Makefile |2 +
 drivers/media/platform/ti-vpe/vip.c| 4158 
 drivers/media/platform/ti-vpe/vip.h|  724 +
 4 files changed, 4897 insertions(+)
 create mode 100644 drivers/media/platform/ti-vpe/vip.c
 create mode 100644 drivers/media/platform/ti-vpe/vip.h

diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig
index c57ee78fa99d..f4100a1aad58 100644
--- a/drivers/media/platform/Kconfig
+++ b/drivers/media/platform/Kconfig
@@ -168,6 +168,19 @@ config VIDEO_TI_CAL
  In TI Technical Reference Manual this module is referred as
  Camera Interface Subsystem (CAMSS).
 
+config VIDEO_TI_VIP
+   tristate "TI Video Input Port"
+   default n
+   depends on VIDEO_DEV && VIDEO_V4L2 && SOC_DRA7XX
+   depends on HAS_DMA
+   select VIDEOBUF2_DMA_CONTIG
+   select VIDEO_TI_VPDMA
+   select VIDEO_TI_SC
+   select VIDEO_TI_CSC
+   help
+   Driver support for VIP module on certain TI SoC's
+   VIP = Video Input Port.
+
 endif # V4L_PLATFORM_DRIVERS
 
 menuconfig V4L_MEM2MEM_DRIVERS
diff --git a/drivers/media/platform/ti-vpe/Makefile 
b/drivers/media/platform/ti-vpe/Makefile
index 886ac5ec073f..cdbecadf7191 100644
--- a/drivers/media/platform/ti-vpe/Makefile
+++ b/drivers/media/platform/ti-vpe/Makefile
@@ -3,11 +3,13 @@ obj-$(CONFIG_VIDEO_TI_VPE) += ti-vpe.o
 obj-$(CONFIG_VIDEO_TI_VPDMA) += ti-vpdma.o
 obj-$(CONFIG_VIDEO_TI_SC) += ti-sc.o
 obj-$(CONFIG_VIDEO_TI_CSC) += ti-csc.o
+obj-$(CONFIG_VIDEO_TI_VIP) += ti-vip.o
 
 ti-vpe-y := vpe.o
 ti-vpdma-y := vpdma.o
 ti-sc-y := sc.o
 ti-csc-y := csc.o
+ti-vip-y := vip.o
 
 ccflags-$(CONFIG_VIDEO_TI_VPE_DEBUG) += -DDEBUG
 
diff --git a/drivers/media/platform/ti-vpe/vip.c 
b/drivers/media/platform/ti-vpe/vip.c
new file mode 100644
index ..307b01851a14
--- /dev/null
+++ b/drivers/media/platform/ti-vpe/vip.c
@@ -0,0 +1,4158 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * TI VIP capture driver
+ *
+ * Copyright (C) 2018 Texas Instruments Incorporated -  http://www.ti.com/
+ * David Griego, 
+ * Dale Farnsworth, 
+ * Nikhil Devshatwar, 
+ * Benoit Parrot, 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+
+#include "vip.h"
+
+#define VIP_MODULE_NAME "vip"
+
+static int debug;
+module_param(debug, int, 0644);
+MODULE_PARM_DESC(debug, "debug level (0-8)");
+
+/*
+ * Minimum and maximum frame sizes
+ */
+#define MIN_W  128
+#define MIN_H  128
+#define MAX_W  2048
+#define MAX_H  1536
+
+/*
+ * Required alignments
+ */
+#define S_ALIGN0 /* multiple of 1 */
+#define H_ALIGN1 /* multiple of 2 */
+#define W_ALIGN1 /* multiple of 2 */
+#define L_ALIGN7 /* multiple of 128, line stride, 16 bytes */
+
+/*
+ * Need a descriptor entry for each of up to 15 outputs,
+ * and up to 2 control transfers.
+ */
+#define VIP_DESC_LIST_SIZE (17 * sizeof(struct vpdma_dtd))
+
+#define vip_dbg(level, dev, fmt, arg...)   \
+   v4l2_dbg(level, debug, dev, fmt, ##arg)
+#define vip_err(dev, fmt, arg...)  \
+   v4l2_err(dev, fmt, ##arg)
+#define vip_warn(dev, fmt, arg...) \
+   v4l2_err(dev, fmt, ##arg)
+#define vip_info(dev, fmt, arg...) \
+   v4l2_info(dev, fmt, ##arg)
+
+#define CTRL_CORE_SMA_SW_1  0x534
+/*
+ * The srce_info structure contains per-srce data.
+ */
+struct vip_srce_info {
+   u8  base_channel;   /* the VPDMA channel nummber */
+   u8  vb_index;   /* input frame f, f-1, f-2 index */
+   u8  vb_part;/* identifies section of co-planar formats */
+};
+
+#define VIP_VPDMA_FIFO_SIZE2
+#define VIP_DROPQ_SIZE 3
+
+/*
+ * Define indices into the srce_info tables
+ */
+
+#define VIP_SRCE_MULT_PORT 0
+#define VIP_SRCE_MULT_ANC  1
+#define VIP_SRCE_LUMA  2
+#define VIP_SRCE_CHROMA3
+#define VIP_SRCE_RGB   4
+
+static struct vip_srce_info srce_info[5] = {
+   [VIP_SRCE_MULT_PORT] = {
+   .base_channel   = VIP1_CHAN_NUM_MULT_PORT_A_SRC0,
+   .vb_index   = 0,
+   .vb_part= VIP_CHROMA,
+   },
+   [VIP_SRCE_MULT_ANC] = {
+   .base_channel   = VIP1_CHAN_NUM_MULT_ANC_A_SRC0,
+

[Patch 0/2] media: ti-vpe: Add the VIP driver

2020-05-22 Thread Benoit Parrot
ed 51
Video Capture: Frame #041 (epoll)   warn: 
v4l2-test-buffers.cpp(446): got sequence number 56, expected 55
Video Capture: Frame #044 (epoll)   warn: 
v4l2-test-buffers.cpp(446): got sequence number 60, expected 59
Video Capture: Frame #047 (epoll)   warn: 
v4l2-test-buffers.cpp(446): got sequence number 64, expected 63
Video Capture: Frame #050 (epoll)   warn: 
v4l2-test-buffers.cpp(446): got sequence number 68, expected 67
Video Capture: Frame #053 (epoll)   warn: 
v4l2-test-buffers.cpp(446): got sequence number 72, expected 71
Video Capture: Frame #056 (epoll)   warn: 
v4l2-test-buffers.cpp(446): got sequence number 76, expected 75
test MMAP (epoll): OK 
test USERPTR (no poll): OK (Not Supported)
test USERPTR (select): OK (Not Supported)
test DMABUF: Cannot test, specify --expbuf-device

Total for vip device /dev/video1: 51, Succeeded: 51, Failed: 0, Warnings: 57

Benoit Parrot (2):
  dt-binbings: media: ti-vpe: Document the VIP driver
  media: ti-vpe: Add the VIP driver

 .../devicetree/bindings/media/ti,vip.yaml |  394 ++
 MAINTAINERS   |1 +
 drivers/media/platform/Kconfig|   13 +
 drivers/media/platform/ti-vpe/Makefile|2 +
 drivers/media/platform/ti-vpe/vip.c   | 4158 +
 drivers/media/platform/ti-vpe/vip.h   |  724 +++
 6 files changed, 5292 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/ti,vip.yaml
 create mode 100644 drivers/media/platform/ti-vpe/vip.c
 create mode 100644 drivers/media/platform/ti-vpe/vip.h

-- 
2.17.1



[Patch 1/2] dt-binbings: media: ti-vpe: Document the VIP driver

2020-05-22 Thread Benoit Parrot
Device Tree bindings for the Video Input Port (VIP) driver.

Signed-off-by: Benoit Parrot 
---
 .../devicetree/bindings/media/ti,vip.yaml | 394 ++
 MAINTAINERS   |   1 +
 2 files changed, 395 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/ti,vip.yaml

diff --git a/Documentation/devicetree/bindings/media/ti,vip.yaml 
b/Documentation/devicetree/bindings/media/ti,vip.yaml
new file mode 100644
index ..8a9084e42329
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/ti,vip.yaml
@@ -0,0 +1,394 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/media/ti,vip.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Texas Instruments DRA7x VIDEO INPUT PORT (VIP) Device Tree Bindings
+
+maintainers:
+  - Benoit Parrot 
+
+description: |-
+  The Video Input Port (VIP) is a key component for image capture
+  applications. The capture module provides the system interface and the
+  processing capability to connect parallel image-sensor as well as
+  BT.656/1120 capable encoder chip to DRA7x device.
+
+  Each VIP instance supports 2 independently configurable external video
+  input capture slices (Slice 0 and Slice 1) each providing up to two video
+  input ports (Port A and Port B) where Port A can be configured as
+  24/16/8-bit port and Port B is fixed as 8-bit port.
+  Here these ports a represented as follows
+port@0 -> Slice 0 Port A
+port@1 -> Slice 0 Port B
+port@2 -> Slice 1 Port A
+port@3 -> Slice 1 Port B
+
+  Each camera port nodes should contain a 'port' child node with child
+  'endpoint' node. Please refer to the bindings defined in
+  Documentation/devicetree/bindings/media/video-interfaces.txt.
+
+properties:
+  compatible:
+const: ti,dra7-vip
+
+  label:
+description: Instance name
+
+  reg:
+items:
+  - description: The VIP main register region
+  - description: Video Data Parser (PARSER) register region for Slice0
+  - description: Color Space Conversion (CSC) register region for Slice0
+  - description: Scaler (SC) register region for Slice0
+  - description: Video Data Parser (PARSER) register region for Slice1
+  - description: Color Space Conversion (CSC) register region for Slice1
+  - description: Scaler (SC) register region for Slice1
+  - description: Video Port Direct Memory Access (VPDMA) register region
+
+  reg-names:
+items:
+  - const: vip
+  - const: parser0
+  - const: csc0
+  - const: sc0
+  - const: parser1
+  - const: csc1
+  - const: sc1
+  - const: vpdma
+
+  interrupts:
+minItems: 2
+description:
+  IRQ index 0 is used for Slice0 interrupts
+  IRQ index 1 is used for Slice1 interrupts
+
+  ti,vip-clk-polarity:
+$ref: "/schemas/types.yaml#/definitions/phandle-array"
+description:
+  phandle to the device control module. The 1st argument should
+  contain the register offset to the CTRL_CORE_SMA_SW_1 register.
+  2nd argument contains the bit field to slice 0 port A,
+  3rd argument contains the bit field to slice 0 port B,
+  4th argument contains the bit field to slice 1 port A,
+  5th argument contains the bit field to slice 1 port B.
+
+  # See ./video-interfaces.txt for details
+  ports:
+type: object
+additionalProperties: false
+
+properties:
+  "#address-cells":
+const: 1
+
+  "#size-cells":
+const: 0
+
+  port@0:
+type: object
+additionalProperties: false
+
+properties:
+  reg:
+const: 0
+description: Slice 0 Port A
+
+  label:
+description: Port name. Usually the pin group name
+
+patternProperties:
+  endpoint:
+type: object
+additionalProperties: false
+
+properties:
+  hsync-active:
+maxItems: 1
+
+  vsync-active:
+maxItems: 1
+
+  pclk-sample:
+maxItems: 1
+
+  bus-width:
+maxItems: 1
+
+  ti,vip-pixel-mux:
+type: boolean
+description:
+  In BT656/1120 mode, this enable pixel-muxing if
+  the number of channels is either 1, 2 or 4. If this
+  property is present then pixel-muxing is enabled
+  otherwise it will use line-muxing.
+
+  ti,vip-channels:
+$ref: "/schemas/types.yaml#definitions/uint8-array"
+minItems: 1
+maxItems: 16
+description: |-
+  In BT656/1120 mode, list of channel ids to be captured.
+  If the property is not present then 1 channel is assumed.
+
+  remote

Re: [PATCH] media: ti-vpe: avoid gcc-9 warning

2020-04-28 Thread Benoit Parrot
Reviewed-by: Benoit Parrot 

Arnd Bergmann  wrote on Tue [2020-Apr-28 23:34:19 +0200]:
> gcc warns about empty array declarations, which we get in this driver
> when compile-testing without CONFIG_OF:
> 
> drivers/media/platform/ti-vpe/cal.c:2194:34: warning: array 'cal_of_match' 
> assumed to have one element
>  2194 | static const struct of_device_id cal_of_match[];
> 
> Since all users of this driver do need CONFIG_OF anyway, there is no
> point in making the array definition conditional to save space, so
> just remove the #ifdef and move the array up a little.
> 
> Fixes: 343e89a792a5 ("[media] media: ti-vpe: Add CAL v4l2 camera capture 
> driver")
> Signed-off-by: Arnd Bergmann 
> ---
>  drivers/media/platform/ti-vpe/cal.c | 46 +
>  1 file changed, 21 insertions(+), 25 deletions(-)
> 
> diff --git a/drivers/media/platform/ti-vpe/cal.c 
> b/drivers/media/platform/ti-vpe/cal.c
> index 49204872e711..9b18db7af6c3 100644
> --- a/drivers/media/platform/ti-vpe/cal.c
> +++ b/drivers/media/platform/ti-vpe/cal.c
> @@ -2237,7 +2237,26 @@ static struct cal_ctx *cal_create_instance(struct 
> cal_dev *dev, int inst)
>   return NULL;
>  }
>  
> -static const struct of_device_id cal_of_match[];
> +static const struct of_device_id cal_of_match[] = {
> + {
> + .compatible = "ti,dra72-cal",
> + .data = (void *)&dra72x_cal_data,
> + },
> + {
> + .compatible = "ti,dra72-pre-es2-cal",
> + .data = (void *)&dra72x_es1_cal_data,
> + },
> + {
> + .compatible = "ti,dra76-cal",
> + .data = (void *)&dra76x_cal_data,
> + },
> + {
> + .compatible = "ti,am654-cal",
> + .data = (void *)&am654_cal_data,
> + },
> + {},
> +};
> +MODULE_DEVICE_TABLE(of, cal_of_match);
>  
>  static int cal_probe(struct platform_device *pdev)
>  {
> @@ -2413,29 +2432,6 @@ static int cal_remove(struct platform_device *pdev)
>   return 0;
>  }
>  
> -#if defined(CONFIG_OF)
> -static const struct of_device_id cal_of_match[] = {
> - {
> - .compatible = "ti,dra72-cal",
> - .data = (void *)&dra72x_cal_data,
> - },
> - {
> - .compatible = "ti,dra72-pre-es2-cal",
> - .data = (void *)&dra72x_es1_cal_data,
> - },
> - {
> - .compatible = "ti,dra76-cal",
> - .data = (void *)&dra76x_cal_data,
> - },
> - {
> - .compatible = "ti,am654-cal",
> - .data = (void *)&am654_cal_data,
> - },
> - {},
> -};
> -MODULE_DEVICE_TABLE(of, cal_of_match);
> -#endif
> -
>  static int cal_runtime_resume(struct device *dev)
>  {
>   struct cal_dev *caldev = dev_get_drvdata(dev);
> @@ -2462,7 +2458,7 @@ static struct platform_driver cal_pdrv = {
>   .driver = {
>   .name   = CAL_MODULE_NAME,
>   .pm = &cal_pm_ops,
> - .of_match_table = of_match_ptr(cal_of_match),
> + .of_match_table = cal_of_match,
>   },
>  };
>  
> -- 
> 2.26.0
> 


Re: [Patch 19/19] dt-bindings: media: cal: convert binding to yaml

2019-10-23 Thread Benoit Parrot
Sakari Ailus  wrote on Tue [2019-Oct-22 10:46:23 +0300]:
> Hi Benoit,
> 
> Thanks for the patch.
> 
> On Fri, Oct 18, 2019 at 10:34:37AM -0500, Benoit Parrot wrote:
> > Convert ti-cal.txt to ti,cal.yaml.
> > 
> > Signed-off-by: Benoit Parrot 
> > ---
> >  .../devicetree/bindings/media/ti,cal.yaml | 186 ++
> >  .../devicetree/bindings/media/ti-cal.txt  |  82 
> >  2 files changed, 186 insertions(+), 82 deletions(-)
> >  create mode 100644 Documentation/devicetree/bindings/media/ti,cal.yaml
> >  delete mode 100644 Documentation/devicetree/bindings/media/ti-cal.txt
> > 
> > diff --git a/Documentation/devicetree/bindings/media/ti,cal.yaml 
> > b/Documentation/devicetree/bindings/media/ti,cal.yaml
> > new file mode 100644
> > index ..c3fbb22b4571
> > --- /dev/null
> > +++ b/Documentation/devicetree/bindings/media/ti,cal.yaml
> > @@ -0,0 +1,186 @@
> > +# SPDX-License-Identifier: (GPL-2.0)
> > +%YAML 1.2
> > +---
> > +$id: http://devicetree.org/schemas/media/ti,cal.yaml#
> > +$schema: http://devicetree.org/meta-schemas/core.yaml#
> > +
> > +title: Texas Instruments DRA72x CAMERA ADAPTATION LAYER (CAL) Device Tree 
> > Bindings
> > +
> > +maintainers:
> > +  - Benoit Parrot 
> > +
> > +description: |-
> > +  The Camera Adaptation Layer (CAL) is a key component for image capture
> > +  applications. The capture module provides the system interface and the
> > +  processing capability to connect CSI2 image-sensor modules to the
> > +  DRA72x device.
> > +
> > +  CAL supports 2 camera port nodes on MIPI bus. Each CSI2 camera port nodes
> > +  should contain a 'port' child node with child 'endpoint' node. Please
> > +  refer to the bindings defined in
> > +  Documentation/devicetree/bindings/media/video-interfaces.txt.
> > +
> > +  compatible should be
> > + "ti,dra72-cal", for DRA72 controllers
> > + "ti,dra72-pre-es2-cal", for DRA72 controllers pre ES2.0
> > + "ti,dra76-cal", for DRA76 controllers
> > + "ti,am654-cal", for AM654 controllers
> > +
> > +properties:
> > +  compatible:
> > +  items:
> > +- enum:
> > +- ti,dra72-cal
> > +- ti,dra72-pre-es2-cal
> > +- ti,dra76-cal
> > +- ti,am654-cal
> > +
> > +  reg:
> > +minItems: 2
> > +items:
> > +  - description: The CAL main register region
> > +  - description: The RX Core0 (DPHY0) register region
> > +  - description: The RX Core1 (DPHY1) register region
> > +
> > +  reg-names:
> > +minItems: 2
> > +items:
> > +  - const: cal_top
> > +  - const: cal_rx_core0
> > +  - const: cal_rx_core1
> > +
> > +  interrupts:
> > +maxItems: 1
> > +
> > +  syscon-camerrx:
> > +maxItems: 1
> > +items:
> > +  - description:
> > +   phandle to the device control module and offset to the
> > +   control_camerarx_core register
> > +
> > +  clocks:
> > +maxItems: 1
> > +description: functional clock
> > +
> > +  clock-names:
> > +items:
> > +  - const: fck
> > +
> > +  power-domains:
> > +description:
> > +  List of phandle and PM domain specifier as documented in
> > +  Documentation/devicetree/bindings/power/power_domain.txt
> > +maxItems: 1
> > +
> > +  # See ./video-interfaces.txt for details
> > +  ports:
> > +maxItems: 1
> > +type: object
> > +additionalProperties: false
> > +
> > +properties:
> > +  "#address-cells":
> > +const: 1
> > +
> > +  "#size-cells":
> > +const: 0
> > +
> > +patternProperties:
> > +  '^port@[0-9a-fA-F]+$':
> > +minItems: 1
> > +maxItems: 2
> 
> Obviously you need a port node to connect a sensor. But can the device do
> something useful without one? I guess it may be a matter of taste whether
> you require one.

In an ideal world all of these would be covered by a video-interfaces.yaml
file I would just need to include... :)

But I'll try and add some more "required" and see how much trouble it gets
me.
> 
> > +type: object
> > +additionalProperties: false
> > +
> > +properties:
> > +  reg:
> > +minItems: 1
> &

Re: [Patch 19/19] dt-bindings: media: cal: convert binding to yaml

2019-10-23 Thread Benoit Parrot
Hans Verkuil  wrote on Mon [2019-Oct-21 12:49:00 +0200]:
> On 10/18/19 5:34 PM, Benoit Parrot wrote:
> > Convert ti-cal.txt to ti,cal.yaml.
> > 
> > Signed-off-by: Benoit Parrot 
> 
> Can you add this bindings file to MAINTAINERS as well in a separate patch?

Yes I can do that, no problem.

Benoit

> 
> Thanks!
> 
>   Hans
> 
> > ---
> >  .../devicetree/bindings/media/ti,cal.yaml | 186 ++
> >  .../devicetree/bindings/media/ti-cal.txt  |  82 
> >  2 files changed, 186 insertions(+), 82 deletions(-)
> >  create mode 100644 Documentation/devicetree/bindings/media/ti,cal.yaml
> >  delete mode 100644 Documentation/devicetree/bindings/media/ti-cal.txt
> > 
> > diff --git a/Documentation/devicetree/bindings/media/ti,cal.yaml 
> > b/Documentation/devicetree/bindings/media/ti,cal.yaml
> > new file mode 100644
> > index ..c3fbb22b4571
> > --- /dev/null
> > +++ b/Documentation/devicetree/bindings/media/ti,cal.yaml
> > @@ -0,0 +1,186 @@
> > +# SPDX-License-Identifier: (GPL-2.0)
> > +%YAML 1.2
> > +---
> > +$id: http://devicetree.org/schemas/media/ti,cal.yaml#
> > +$schema: http://devicetree.org/meta-schemas/core.yaml#
> > +
> > +title: Texas Instruments DRA72x CAMERA ADAPTATION LAYER (CAL) Device Tree 
> > Bindings
> > +
> > +maintainers:
> > +  - Benoit Parrot 
> > +
> > +description: |-
> > +  The Camera Adaptation Layer (CAL) is a key component for image capture
> > +  applications. The capture module provides the system interface and the
> > +  processing capability to connect CSI2 image-sensor modules to the
> > +  DRA72x device.
> > +
> > +  CAL supports 2 camera port nodes on MIPI bus. Each CSI2 camera port nodes
> > +  should contain a 'port' child node with child 'endpoint' node. Please
> > +  refer to the bindings defined in
> > +  Documentation/devicetree/bindings/media/video-interfaces.txt.
> > +
> > +  compatible should be
> > + "ti,dra72-cal", for DRA72 controllers
> > + "ti,dra72-pre-es2-cal", for DRA72 controllers pre ES2.0
> > + "ti,dra76-cal", for DRA76 controllers
> > + "ti,am654-cal", for AM654 controllers
> > +
> > +properties:
> > +  compatible:
> > +  items:
> > +- enum:
> > +- ti,dra72-cal
> > +- ti,dra72-pre-es2-cal
> > +- ti,dra76-cal
> > +- ti,am654-cal
> > +
> > +  reg:
> > +minItems: 2
> > +items:
> > +  - description: The CAL main register region
> > +  - description: The RX Core0 (DPHY0) register region
> > +  - description: The RX Core1 (DPHY1) register region
> > +
> > +  reg-names:
> > +minItems: 2
> > +items:
> > +  - const: cal_top
> > +  - const: cal_rx_core0
> > +  - const: cal_rx_core1
> > +
> > +  interrupts:
> > +maxItems: 1
> > +
> > +  syscon-camerrx:
> > +maxItems: 1
> > +items:
> > +  - description:
> > +   phandle to the device control module and offset to the
> > +   control_camerarx_core register
> > +
> > +  clocks:
> > +maxItems: 1
> > +description: functional clock
> > +
> > +  clock-names:
> > +items:
> > +  - const: fck
> > +
> > +  power-domains:
> > +description:
> > +  List of phandle and PM domain specifier as documented in
> > +  Documentation/devicetree/bindings/power/power_domain.txt
> > +maxItems: 1
> > +
> > +  # See ./video-interfaces.txt for details
> > +  ports:
> > +maxItems: 1
> > +type: object
> > +additionalProperties: false
> > +
> > +properties:
> > +  "#address-cells":
> > +const: 1
> > +
> > +  "#size-cells":
> > +const: 0
> > +
> > +patternProperties:
> > +  '^port@[0-9a-fA-F]+$':
> > +minItems: 1
> > +maxItems: 2
> > +type: object
> > +additionalProperties: false
> > +
> > +properties:
> > +  reg:
> > +minItems: 1
> > +items:
> > +  - description: The port id
> > +
> > +patternProperties:
> > +  '^endpoint@[0-9a-fA-F]+$':
> > +minItems: 1
> > +type: object
> > +add

Re: [Patch 00/19] media: ti-vpe: cal: maintenance

2019-10-23 Thread Benoit Parrot
Hans Verkuil  wrote on Mon [2019-Oct-21 12:50:02 +0200]:
> Hi Benoit,
> 
> This series looks good to me. I had just one small comment on patch 7
> and a comment on patch 19.
> 
> Just post a v2 for just patch 7/19 and post a patch 20/19 for the requested
> MAINTAINERS change.
> 
> Once I have Rob's Acks I can merge this.

Ok, thanks.
I'll send a v2 probably later this week or early next.

Benoit

> 
> Regards,
> 
>   Hans
> 
> On 10/18/19 5:34 PM, Benoit Parrot wrote:


Re: [Patch 07/19] media: ti-vpe: cal: add CSI2 PHY LDO errata support

2019-10-23 Thread Benoit Parrot
Hans Verkuil  wrote on Mon [2019-Oct-21 12:38:03 +0200]:
> On 10/18/19 5:34 PM, Benoit Parrot wrote:
> > Apply Errata i913 every time the functional clock is enabled.
> > This should take care of suspend/resume case as well.
> > 
> > Signed-off-by: Benoit Parrot 
> > Signed-off-by: Jyri Sarha 
> > ---
> >  drivers/media/platform/ti-vpe/cal.c  | 56 +++-
> >  drivers/media/platform/ti-vpe/cal_regs.h | 27 
> >  2 files changed, 82 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/media/platform/ti-vpe/cal.c 
> > b/drivers/media/platform/ti-vpe/cal.c
> > index 62aeedb705e9..3cbc4dca6de8 100644
> > --- a/drivers/media/platform/ti-vpe/cal.c
> > +++ b/drivers/media/platform/ti-vpe/cal.c
> > @@ -284,6 +284,13 @@ static struct cal_data dra72x_cal_data = {
> > .flags = 0,
> >  };
> >  
> > +static struct cal_data dra72x_es1_cal_data = {
> > +   .csi2_phy_core = dra72x_cal_csi_phy,
> > +   .num_csi2_phy = ARRAY_SIZE(dra72x_cal_csi_phy),
> > +
> > +   .flags = DRA72_CAL_PRE_ES2_LDO_DISABLE,
> > +};
> > +
> >  /*
> >   * there is one cal_dev structure in the driver, it is shared by
> >   * all instances.
> > @@ -569,9 +576,52 @@ static void cal_get_hwinfo(struct cal_dev *dev)
> > hwinfo);
> >  }
> >  
> > +/*
> > + *   Errata i913: CSI2 LDO Needs to be disabled when module is powered on
> > + *
> > + *   Enabling CSI2 LDO shorts it to core supply. It is crucial the 2 CSI2
> > + *   LDOs on the device are disabled if CSI-2 module is powered on
> > + *   (0x4845 B304 | 0x4845 B384 [28:27] = 0x1) or in ULPS (0x4845 B304
> > + *   | 0x4845 B384 [28:27] = 0x2) mode. Common concerns include: high
> > + *   current draw on the module supply in active mode.
> > + *
> > + *   Errata does not apply when CSI-2 module is powered off
> > + *   (0x4845 B304 | 0x4845 B384 [28:27] = 0x0).
> > + *
> > + * SW Workaround:
> > + * Set the following register bits to disable the LDO,
> > + * which is essentially CSI2 REG10 bit 6:
> > + *
> > + * Core 0:  0x4845 B828 = 0x 0040
> > + * Core 1:  0x4845 B928 = 0x 0040
> > + */
> > +static void i913_errata(struct cal_dev *dev, unsigned int port)
> > +{
> > +   u32 reg10 = reg_read(dev->cc[port], CAL_CSI2_PHY_REG10);
> > +
> > +   set_field(®10, CAL_CSI2_PHY_REG0_HSCLOCKCONFIG_DISABLE,
> > + CAL_CSI2_PHY_REG10_I933_LDO_DISABLE_MASK);
> > +
> > +   cal_dbg(1, dev, "CSI2_%d_REG10 = 0x%08x\n", port, reg10);
> > +   reg_write(dev->cc[port], CAL_CSI2_PHY_REG10, reg10);
> > +}
> > +
> >  static inline int cal_runtime_get(struct cal_dev *dev)
> 
> I'd drop the 'inline' here. It doesn't seem appropriate anymore since this
> function is now more complex.

Ok I'll fix that

Benoit

> 
> Regards,
> 
>   Hans
> 
> >  {
> > -   return pm_runtime_get_sync(&dev->pdev->dev);
> > +   int r;
> > +
> > +   r = pm_runtime_get_sync(&dev->pdev->dev);
> > +
> > +   if (dev->flags & DRA72_CAL_PRE_ES2_LDO_DISABLE) {
> > +   /*
> > +* Apply errata on both port eveytime we (re-)enable
> > +* the clock
> > +*/
> > +   i913_errata(dev, 0);
> > +   i913_errata(dev, 1);
> > +   }
> > +
> > +   return r;
> >  }
> >  
> >  static inline void cal_runtime_put(struct cal_dev *dev)
> > @@ -2071,6 +2121,10 @@ static const struct of_device_id cal_of_match[] = {
> > .compatible = "ti,dra72-cal",
> > .data = (void *)&dra72x_cal_data,
> > },
> > +   {
> > +   .compatible = "ti,dra72-pre-es2-cal",
> > +   .data = (void *)&dra72x_es1_cal_data,
> > +   },
> > {},
> >  };
> >  MODULE_DEVICE_TABLE(of, cal_of_match);
> > diff --git a/drivers/media/platform/ti-vpe/cal_regs.h 
> > b/drivers/media/platform/ti-vpe/cal_regs.h
> > index 68cfc922b422..78d6f015c9ea 100644
> > --- a/drivers/media/platform/ti-vpe/cal_regs.h
> > +++ b/drivers/media/platform/ti-vpe/cal_regs.h
> > @@ -10,6 +10,30 @@
> >  #ifndef __TI_CAL_REGS_H
> >  #define __TI_CAL_REGS_H
> >  
> > +/*
> > + * struct cal_dev.flags possibilities
> > + *
> > + * DRA72_CAL_PRE_ES2_LDO_DISABLE:
> > + *   Errata i913: CSI2 LDO Needs to be disabled when module is powered on
> > + *
> > + *   Enabling CSI2 LDO sh

Re: [Patch 0/3] ARM: dts: dra7: add vpe nodes

2019-10-22 Thread Benoit Parrot
Tony Lindgren  wrote on Tue [2019-Oct-22 09:37:54 -0700]:
> * Benoit Parrot  [191022 16:34]:
> > Tony Lindgren  wrote on Tue [2019-Oct-22 09:30:48 -0700]:
> > > * Benoit Parrot  [191022 16:28]:
> > > > Tony,
> > > > 
> > > > Ping,
> > > > 
> > > > I already had comments from Rob but i would like your feedback before
> > > > sending a v2.
> > > 
> > > Looks good to me in general other than what Rob commented
> > > on. Did not spot any node naming issues here :)
> > 
> > Would I need to split off the clk*.c/.h as well here though?
> 
> Yeah please do patches with just drivers/clk/ti and
> include/dt-bindings/clock changes in them. then Tero
> can queue them into an immutable branch that I can merge
> in too and use as a base for the dts changes.

Although the .h is in include/dt-binding. Does it still belong in the same
patch as drivers/clk/ti/clk-7xx.c then?

Just making sure

> 
> Regards,
> 
> Tony


Re: [Patch 0/3] ARM: dts: dra7: add vpe nodes

2019-10-22 Thread Benoit Parrot
Tony Lindgren  wrote on Tue [2019-Oct-22 09:30:48 -0700]:
> * Benoit Parrot  [191022 16:28]:
> > Tony,
> > 
> > Ping,
> > 
> > I already had comments from Rob but i would like your feedback before
> > sending a v2.
> 
> Looks good to me in general other than what Rob commented
> on. Did not spot any node naming issues here :)

Would I need to split off the clk*.c/.h as well here though?

Benoit

> 
> Regards,
> 
> Tony


Re: [Patch 0/3] ARM: dts: dra7: add vpe nodes

2019-10-22 Thread Benoit Parrot
Tony,

Ping,

I already had comments from Rob but i would like your feedback before
sending a v2.

Regards,
Benoit

Benoit Parrot  wrote on Wed [2019-Oct-09 12:56:25 -0500]:
> This patch series adds the needed clkctrl and ty-sysc nodes for VPE module.
> We also document the VPE DT bindings.
> 
> Benoit Parrot (3):
>   dt-bindings: media: ti-vpe: Document VPE driver
>   ARM: dts: dra7: add vpe clkctrl node
>   ARM: dts: dra7: Add ti-sysc node for VPE
> 
>  .../devicetree/bindings/media/ti-vpe.txt  | 48 +++
>  MAINTAINERS   |  1 +
>  arch/arm/boot/dts/dra7-l4.dtsi| 30 ++--
>  arch/arm/boot/dts/dra7xx-clocks.dtsi  | 18 ++-
>  drivers/clk/ti/clk-7xx.c  |  6 +++
>  include/dt-bindings/clock/dra7.h  | 10 
>  6 files changed, 108 insertions(+), 5 deletions(-)
>  create mode 100644 Documentation/devicetree/bindings/media/ti-vpe.txt
> 
> -- 
> 2.17.1
> 


Re: [Patch 1/3] ARM: dts: am43xx: add support for clkout1 clock

2019-10-22 Thread Benoit Parrot
Tony Lindgren  wrote on Tue [2019-Oct-22 08:48:16 -0700]:
> * Benoit Parrot  [191016 18:47]:
> > --- a/arch/arm/boot/dts/am43xx-clocks.dtsi
> > +++ b/arch/arm/boot/dts/am43xx-clocks.dtsi
> > @@ -704,6 +704,60 @@
> > ti,bit-shift = <8>;
> > reg = <0x2a48>;
> > };
> > +
> > +   clkout1_osc_div_ck: clkout1_osc_div_ck {
> > +   #clock-cells = <0>;
> > +   compatible = "ti,divider-clock";
> > +   clocks = <&sys_clkin_ck>;
> > +   ti,bit-shift = <20>;
> > +   ti,max-div = <4>;
> > +   reg = <0x4100>;
> > +   };
> 
> Here too please describe why the clock names are not generic.

Tero originally had this patch in the kernel so this is somewhat of a
revert. Since these "clock" were removed. If the name syntax is no longer
valid for some reason, then I will need a little more informations to
proceed.

Tero, can you assist here?

Benoit

> 
> Regards,
> 
> Tony


Re: [Patch 5/9] arm: dts: dra72-evm-common: Add entries for the CSI2 cameras

2019-10-22 Thread Benoit Parrot
Tony Lindgren  wrote on Tue [2019-Oct-22 08:44:46 -0700]:
> * Benoit Parrot  [191018 15:46]:
> > Add device nodes for CSI2 camera board OV5640.
> > Add the CAL port nodes with the necessary linkage to the ov5640 nodes.
> > 
> > Signed-off-by: Benoit Parrot 
> > ---
> >  arch/arm/boot/dts/dra72-evm-common.dtsi | 35 +
> >  1 file changed, 35 insertions(+)
> > 
> > diff --git a/arch/arm/boot/dts/dra72-evm-common.dtsi 
> > b/arch/arm/boot/dts/dra72-evm-common.dtsi
> > index 8641a3d7d8ad..e4c01a67f6de 100644
> > --- a/arch/arm/boot/dts/dra72-evm-common.dtsi
> > +++ b/arch/arm/boot/dts/dra72-evm-common.dtsi
> > @@ -187,6 +187,12 @@
> > gpio = <&gpio5 8 GPIO_ACTIVE_HIGH>;
> > enable-active-high;
> > };
> > +
> > +   clk_ov5640_fixed: clk_ov5640_fixed {
> > +   compatible = "fixed-clock";
> > +   #clock-cells = <0>;
> > +   clock-frequency = <2400>;
> > +   };
> >  };
> 
> The clock node name should be generic and not use
> undescores. If there is a hidden dependency to the
> clock node name here, it should be mentioned in the
> patch for the non-standard use.

Not sure what you mean by generic, here.
This is just to provide a "clock" node which gives the "value" of the fixed
oscillator frequency so driver can get to it, the actual name does not
matter.

Benoit

> 
> Regards,
> 
> Tony


Re: [Patch 1/9] ARM: dts: dra7: add cam clkctrl node

2019-10-22 Thread Benoit Parrot
Tony Lindgren  wrote on Tue [2019-Oct-22 08:40:12 -0700]:
> * Benoit Parrot  [191018 15:46]:
> > Add clkctrl nodes for CAM domain.
> 
> You're missing the Linux clk folks and list from Cc, can
> you please resend?

Sure.

> 
> I need an ack for the clk-7xx.c changes if I'm to apply
> this patch.
> 
> Probably the best way would be for tero to collect
> all the drivers/clk/ti clock data changes and provide
> an immutable branch with those that I can merge too.

So I assume then that the clk*.c and header file changes should be split in
a separate patch?

Tero,
Let me know how youo would like to proceed.

Benoit

> 
> That way the related dts changes can be applied on
> top of it with things working.
> 
> Regards,
> 
> Tony


[Patch 9/9] arm64: dts: k3-am654-base-board: Add CSI2 OV5640 camera

2019-10-18 Thread Benoit Parrot
Add support for the OV5640 CSI camera:
- add the OV5640 nodes
- add the CAL node linkage
- enable CAL node

Signed-off-by: Benoit Parrot 
---
 .../arm64/boot/dts/ti/k3-am654-base-board.dts | 36 +++
 1 file changed, 36 insertions(+)

diff --git a/arch/arm64/boot/dts/ti/k3-am654-base-board.dts 
b/arch/arm64/boot/dts/ti/k3-am654-base-board.dts
index 1102b84f853d..918601c18f85 100644
--- a/arch/arm64/boot/dts/ti/k3-am654-base-board.dts
+++ b/arch/arm64/boot/dts/ti/k3-am654-base-board.dts
@@ -53,6 +53,12 @@
gpios = <&wkup_gpio0 27 GPIO_ACTIVE_LOW>;
};
};
+
+   clk_ov5640_fixed: clk_ov5640_fixed {
+   compatible = "fixed-clock";
+   #clock-cells = <0>;
+   clock-frequency = <2400>;
+   };
 };
 
 &wkup_pmx0 {
@@ -184,6 +190,23 @@
pinctrl-names = "default";
pinctrl-0 = <&main_i2c1_pins_default>;
clock-frequency = <40>;
+
+   ov5640@3c {
+   compatible = "ovti,ov5640";
+   reg = <0x3c>;
+
+   clocks = <&clk_ov5640_fixed>;
+   clock-names = "xclk";
+
+   port {
+   csi2_cam0: endpoint {
+   remote-endpoint = <&csi2_phy0>;
+   clock-lanes = <0>;
+   data-lanes = <1 2>;
+   };
+   };
+   };
+
 };
 
 &main_i2c2 {
@@ -280,3 +303,16 @@
 &pcie1_ep {
status = "disabled";
 };
+
+&cal {
+   status = "okay";
+};
+
+&csi2_0 {
+   csi2_phy0: endpoint@0 {
+   remote-endpoint = <&csi2_cam0>;
+   clock-lanes = <0>;
+   data-lanes = <1 2>;
+   };
+};
+
-- 
2.17.1



[Patch 5/9] arm: dts: dra72-evm-common: Add entries for the CSI2 cameras

2019-10-18 Thread Benoit Parrot
Add device nodes for CSI2 camera board OV5640.
Add the CAL port nodes with the necessary linkage to the ov5640 nodes.

Signed-off-by: Benoit Parrot 
---
 arch/arm/boot/dts/dra72-evm-common.dtsi | 35 +
 1 file changed, 35 insertions(+)

diff --git a/arch/arm/boot/dts/dra72-evm-common.dtsi 
b/arch/arm/boot/dts/dra72-evm-common.dtsi
index 8641a3d7d8ad..e4c01a67f6de 100644
--- a/arch/arm/boot/dts/dra72-evm-common.dtsi
+++ b/arch/arm/boot/dts/dra72-evm-common.dtsi
@@ -187,6 +187,12 @@
gpio = <&gpio5 8 GPIO_ACTIVE_HIGH>;
enable-active-high;
};
+
+   clk_ov5640_fixed: clk_ov5640_fixed {
+   compatible = "fixed-clock";
+   #clock-cells = <0>;
+   clock-frequency = <2400>;
+   };
 };
 
 &dra7_pmx_core {
@@ -269,6 +275,23 @@
line-name = "vin6_sel_s0";
};
};
+
+   ov5640@3c {
+   compatible = "ovti,ov5640";
+   reg = <0x3c>;
+
+   clocks = <&clk_ov5640_fixed>;
+   clock-names = "xclk";
+
+   port {
+   csi2_cam0: endpoint {
+   remote-endpoint = <&csi2_phy0>;
+   clock-lanes = <0>;
+   data-lanes = <1 2>;
+   };
+   };
+   };
+
 };
 
 &uart1 {
@@ -580,3 +603,15 @@
 &pcie1_rc {
status = "okay";
 };
+
+&cal {
+   status = "okay";
+};
+
+&csi2_0 {
+   csi2_phy0: endpoint@0 {
+   remote-endpoint = <&csi2_cam0>;
+   clock-lanes = <0>;
+   data-lanes = <1 2>;
+   };
+};
-- 
2.17.1



[Patch 8/9] arm64: dts: k3-am65-main Add CAL node

2019-10-18 Thread Benoit Parrot
Add CAL dtsi node for AM654 device. Including proper power-domains and
clock properties.

Signed-off-by: Benoit Parrot 
---
 arch/arm64/boot/dts/ti/k3-am65-main.dtsi | 23 +++
 1 file changed, 23 insertions(+)

diff --git a/arch/arm64/boot/dts/ti/k3-am65-main.dtsi 
b/arch/arm64/boot/dts/ti/k3-am65-main.dtsi
index 799c75fa7981..9bd9a74d5e33 100644
--- a/arch/arm64/boot/dts/ti/k3-am65-main.dtsi
+++ b/arch/arm64/boot/dts/ti/k3-am65-main.dtsi
@@ -516,4 +516,27 @@
dma-coherent;
interrupts = ;
};
+
+   cal: cal@6f03000 {
+   compatible = "ti,am654-cal";
+   reg = <0x0 0x06f03000 0x0 0x400>,
+ <0x0 0x06f03800 0x0 0x40>;
+   reg-names = "cal_top",
+   "cal_rx_core0";
+   interrupts = ;
+   syscon-camerrx = <&scm_conf 0x40c0>;
+   clock-names = "fck";
+   clocks = <&k3_clks 2 0>;
+   power-domains = <&k3_pds 2 TI_SCI_PD_EXCLUSIVE>;
+   status = "disabled";
+
+   ports {
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   csi2_0: port@0 {
+   reg = <0>;
+   };
+   };
+   };
 };
-- 
2.17.1



[Patch 6/9] arm: dtsi: dra76x: Add CAL dtsi node

2019-10-18 Thread Benoit Parrot
Add the required dtsi node to support the Camera
Adaptation Layer (CAL) for the DRA76 family of devices.

Signed-off-by: Benoit Parrot 
---
 arch/arm/boot/dts/dra76x.dtsi | 43 +++
 1 file changed, 43 insertions(+)

diff --git a/arch/arm/boot/dts/dra76x.dtsi b/arch/arm/boot/dts/dra76x.dtsi
index cdcba3f561c4..b6f7591bc590 100644
--- a/arch/arm/boot/dts/dra76x.dtsi
+++ b/arch/arm/boot/dts/dra76x.dtsi
@@ -41,6 +41,49 @@
 
 };
 
+&l4_per3 {
+   target-module@1b {  /* 0x489b, ap 25 34.0 */
+   compatible = "ti,sysc-omap4", "ti,sysc";
+   reg = <0x1b 0x4>,
+ <0x1b0010 0x4>;
+   reg-names = "rev", "sysc";
+   ti,sysc-midle = ,
+   ;
+   ti,sysc-sidle = ,
+   ;
+   clocks = <&cam_clkctrl DRA7_CAM_VIP3_CLKCTRL 0>;
+   clock-names = "fck";
+   #address-cells = <1>;
+   #size-cells = <1>;
+   ranges = <0x0 0x1b 0x1>;
+
+   cal: cal@0 {
+   compatible = "ti,dra76-cal";
+   reg = <0x 0x400>,
+ <0x0800 0x40>,
+ <0x0900 0x40>;
+   reg-names = "cal_top",
+   "cal_rx_core0",
+   "cal_rx_core1";
+   interrupts = ;
+   syscon-camerrx = <&scm_conf 0x6dc>;
+   status = "disabled";
+
+   ports {
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   csi2_0: port@0 {
+   reg = <0>;
+   };
+   csi2_1: port@1 {
+   reg = <1>;
+   };
+   };
+   };
+   };
+};
+
 /* MCAN interrupts are hard-wired to irqs 67, 68 */
 &crossbar_mpu {
ti,irqs-skip = <10 67 68 133 139 140>;
-- 
2.17.1



[Patch 2/9] ARM: OMAP: DRA7xx: Make CAM clock domain SWSUP only

2019-10-18 Thread Benoit Parrot
Both CAL and VIP rely on this clock domain. But CAL DPHY require
LVDSRX_96M_GFCLK to be active. When this domain is set to HWSUP the
LVDSRX_96M_GFCLK is on;y active when VIP1 clock is also active.  If only
CAL on DRA72x (which uses the VIP2 clkctrl) probes the CAM domain is
enabled but the LVDSRX_96M_GFCLK is left gated. Since LVDSRX_96M_GFCLK
is sourcing the input clock to the DPHY then actual frame capture cannot
start as the phy are inactive.

So we either have to also enabled VIP1 even if we don't intend on using
it or we need to set the CAM domain to use SWSUP only.

This patch implements the latter.

Signed-off-by: Benoit Parrot 
---
 arch/arm/mach-omap2/clockdomains7xx_data.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/mach-omap2/clockdomains7xx_data.c 
b/arch/arm/mach-omap2/clockdomains7xx_data.c
index 3068802824b7..27835c4d1aa9 100644
--- a/arch/arm/mach-omap2/clockdomains7xx_data.c
+++ b/arch/arm/mach-omap2/clockdomains7xx_data.c
@@ -606,7 +606,7 @@ static struct clockdomain cam_7xx_clkdm = {
.dep_bit  = DRA7XX_CAM_STATDEP_SHIFT,
.wkdep_srcs   = cam_wkup_sleep_deps,
.sleepdep_srcs= cam_wkup_sleep_deps,
-   .flags= CLKDM_CAN_HWSUP_SWSUP,
+   .flags= CLKDM_CAN_SWSUP,
 };
 
 static struct clockdomain l4per_7xx_clkdm = {
-- 
2.17.1



[Patch 4/9] ARM: dts: DRA72: Add CAL dtsi node

2019-10-18 Thread Benoit Parrot
This patch adds the required dtsi node to support the Camera
Adaptation Layer (CAL) for the DRA72 family of devices.

Signed-off-by: Benoit Parrot 
---
 arch/arm/boot/dts/dra72x.dtsi | 43 +++
 1 file changed, 43 insertions(+)

diff --git a/arch/arm/boot/dts/dra72x.dtsi b/arch/arm/boot/dts/dra72x.dtsi
index f5762709c853..29d4c7664e90 100644
--- a/arch/arm/boot/dts/dra72x.dtsi
+++ b/arch/arm/boot/dts/dra72x.dtsi
@@ -17,6 +17,49 @@
};
 };
 
+&l4_per2 {
+   target-module@5b000 {   /* 0x4845b000, ap 59 46.0 */
+   compatible = "ti,sysc-omap4", "ti,sysc";
+   reg = <0x5b000 0x4>,
+ <0x5b010 0x4>;
+   reg-names = "rev", "sysc";
+   ti,sysc-midle = ,
+   ;
+   ti,sysc-sidle = ,
+   ;
+   clocks = <&cam_clkctrl DRA7_CAM_VIP2_CLKCTRL 0>;
+   clock-names = "fck";
+   #address-cells = <1>;
+   #size-cells = <1>;
+   ranges = <0x0 0x5b000 0x1000>;
+
+   cal: cal@0 {
+   compatible = "ti,dra72-cal";
+   reg = <0x 0x400>,
+ <0x0800 0x40>,
+ <0x0900 0x40>;
+   reg-names = "cal_top",
+   "cal_rx_core0",
+   "cal_rx_core1";
+   interrupts = ;
+   syscon-camerrx = <&scm_conf 0xE94>;
+   status = "disabled";
+
+   ports {
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   csi2_0: port@0 {
+   reg = <0>;
+   };
+   csi2_1: port@1 {
+   reg = <1>;
+   };
+   };
+   };
+   };
+};
+
 &dss {
reg = <0x5800 0x80>,
  <0x58004054 0x4>,
-- 
2.17.1



[Patch 1/9] ARM: dts: dra7: add cam clkctrl node

2019-10-18 Thread Benoit Parrot
Add clkctrl nodes for CAM domain.

Signed-off-by: Benoit Parrot 
---
 arch/arm/boot/dts/dra7xx-clocks.dtsi | 14 ++
 drivers/clk/ti/clk-7xx.c | 19 +++
 include/dt-bindings/clock/dra7.h | 10 ++
 3 files changed, 43 insertions(+)

diff --git a/arch/arm/boot/dts/dra7xx-clocks.dtsi 
b/arch/arm/boot/dts/dra7xx-clocks.dtsi
index d1c2406ec71c..199f8d483f75 100644
--- a/arch/arm/boot/dts/dra7xx-clocks.dtsi
+++ b/arch/arm/boot/dts/dra7xx-clocks.dtsi
@@ -1734,6 +1734,20 @@
};
};
 
+   cam_cm: cam-cm@1000 {
+   compatible = "ti,omap4-cm";
+   reg = <0x1000 0x100>;
+   #address-cells = <1>;
+   #size-cells = <1>;
+   ranges = <0 0x1000 0x100>;
+
+   cam_clkctrl: cam-clkctrl@20 {
+   compatible = "ti,clkctrl";
+   reg = <0x20 0x2c>;
+   #clock-cells = <2>;
+   };
+   };
+
dss_cm: dss-cm@1100 {
compatible = "ti,omap4-cm";
reg = <0x1100 0x100>;
diff --git a/drivers/clk/ti/clk-7xx.c b/drivers/clk/ti/clk-7xx.c
index 5dd9cad07542..8f2204a36b51 100644
--- a/drivers/clk/ti/clk-7xx.c
+++ b/drivers/clk/ti/clk-7xx.c
@@ -151,6 +151,24 @@ static const struct omap_clkctrl_reg_data 
dra7_vpe_clkctrl_regs[] __initconst =
{ 0 },
 };
 
+static const char * const dra7_cam_gfclk_mux_parents[] __initconst = {
+   "l3_iclk_div",
+   "core_iss_main_clk",
+   NULL,
+};
+
+static const struct omap_clkctrl_bit_data dra7_cam_bit_data[] __initconst = {
+   { 24, TI_CLK_MUX, dra7_cam_gfclk_mux_parents, NULL },
+   { 0 },
+};
+
+static const struct omap_clkctrl_reg_data dra7_cam_clkctrl_regs[] __initconst 
= {
+   { DRA7_CAM_VIP1_CLKCTRL, dra7_cam_bit_data, CLKF_HW_SUP, "l3_iclk_div" 
},
+   { DRA7_CAM_VIP2_CLKCTRL, dra7_cam_bit_data, CLKF_HW_SUP, "l3_iclk_div" 
},
+   { DRA7_CAM_VIP3_CLKCTRL, dra7_cam_bit_data, CLKF_HW_SUP, "l3_iclk_div" 
},
+   { 0 },
+};
+
 static const struct omap_clkctrl_reg_data dra7_coreaon_clkctrl_regs[] 
__initconst = {
{ DRA7_COREAON_SMARTREFLEX_MPU_CLKCTRL, NULL, CLKF_SW_SUP, 
"wkupaon_iclk_mux" },
{ DRA7_COREAON_SMARTREFLEX_CORE_CLKCTRL, NULL, CLKF_SW_SUP, 
"wkupaon_iclk_mux" },
@@ -783,6 +801,7 @@ const struct omap_clkctrl_data dra7_clkctrl_data[] 
__initconst = {
{ 0x4a008c00, dra7_atl_clkctrl_regs },
{ 0x4a008d20, dra7_l4cfg_clkctrl_regs },
{ 0x4a008e20, dra7_l3instr_clkctrl_regs },
+   { 0x4a009020, dra7_cam_clkctrl_regs },
{ 0x4a009120, dra7_dss_clkctrl_regs },
{ 0x4a009320, dra7_l3init_clkctrl_regs },
{ 0x4a0093b0, dra7_pcie_clkctrl_regs },
diff --git a/include/dt-bindings/clock/dra7.h b/include/dt-bindings/clock/dra7.h
index 2b765e579b2a..2c058a534bab 100644
--- a/include/dt-bindings/clock/dra7.h
+++ b/include/dt-bindings/clock/dra7.h
@@ -34,6 +34,11 @@
 #define DRA7_VPE_CLKCTRL_INDEX(offset) ((offset) - DRA7_VPE_CLKCTRL_OFFSET)
 #define DRA7_VPE_CLKCTRL   DRA7_VPE_CLKCTRL_INDEX(0x64)
 
+/* vip clocks */
+#define DRA7_VIP1_CLKCTRL  DRA7_CLKCTRL_INDEX(0x20)
+#define DRA7_VIP2_CLKCTRL  DRA7_CLKCTRL_INDEX(0x28)
+#define DRA7_VIP3_CLKCTRL  DRA7_CLKCTRL_INDEX(0x30)
+
 /* coreaon clocks */
 #define DRA7_SMARTREFLEX_MPU_CLKCTRL   DRA7_CLKCTRL_INDEX(0x28)
 #define DRA7_SMARTREFLEX_CORE_CLKCTRL  DRA7_CLKCTRL_INDEX(0x38)
@@ -202,6 +207,11 @@
 #define DRA7_VPE_CLKCTRL_INDEX(offset) ((offset) - DRA7_VPE_CLKCTRL_OFFSET)
 #define DRA7_VPE_VPE_CLKCTRL   DRA7_VPE_CLKCTRL_INDEX(0x64)
 
+/* vip clocks */
+#define DRA7_CAM_VIP1_CLKCTRL  DRA7_CLKCTRL_INDEX(0x20)
+#define DRA7_CAM_VIP2_CLKCTRL  DRA7_CLKCTRL_INDEX(0x28)
+#define DRA7_CAM_VIP3_CLKCTRL  DRA7_CLKCTRL_INDEX(0x30)
+
 /* coreaon clocks */
 #define DRA7_COREAON_SMARTREFLEX_MPU_CLKCTRL   DRA7_CLKCTRL_INDEX(0x28)
 #define DRA7_COREAON_SMARTREFLEX_CORE_CLKCTRL  DRA7_CLKCTRL_INDEX(0x38)
-- 
2.17.1



[Patch 7/9] arm: dts: dra76-evm: Add CAL and OV5640 nodes

2019-10-18 Thread Benoit Parrot
Add device nodes for CSI2 camera board OV5640.
Add the CAL port nodes with the necessary linkage to the ov5640 nodes.

Signed-off-by: Benoit Parrot 
---
 arch/arm/boot/dts/dra76-evm.dts | 39 +
 1 file changed, 39 insertions(+)

diff --git a/arch/arm/boot/dts/dra76-evm.dts b/arch/arm/boot/dts/dra76-evm.dts
index 1fb6f13fb5e2..c9fdf62c68e9 100644
--- a/arch/arm/boot/dts/dra76-evm.dts
+++ b/arch/arm/boot/dts/dra76-evm.dts
@@ -116,6 +116,12 @@
regulator-min-microvolt = <180>;
regulator-max-microvolt = <180>;
};
+
+   clk_ov5640_fixed: clk_ov5640_fixed {
+   compatible = "fixed-clock";
+   #clock-cells = <0>;
+   clock-frequency = <2400>;
+   };
 };
 
 &i2c1 {
@@ -317,6 +323,27 @@
};
 };
 
+&i2c5 {
+   status = "okay";
+   clock-frequency = <40>;
+
+   ov5640@3c {
+   compatible = "ovti,ov5640";
+   reg = <0x3c>;
+
+   clocks = <&clk_ov5640_fixed>;
+   clock-names = "xclk";
+
+   port {
+   csi2_cam0: endpoint {
+   remote-endpoint = <&csi2_phy0>;
+   clock-lanes = <0>;
+   data-lanes = <1 2>;
+   };
+   };
+   };
+};
+
 &cpu0 {
vdd-supply = <&buck10_reg>;
 };
@@ -447,3 +474,15 @@
max-bitrate = <500>;
};
 };
+
+&cal {
+   status = "okay";
+};
+
+&csi2_0 {
+   csi2_phy0: endpoint@0 {
+   remote-endpoint = <&csi2_cam0>;
+   clock-lanes = <0>;
+   data-lanes = <1 2>;
+   };
+};
-- 
2.17.1



[Patch 0/9] ARM: dts: dra7: add cal nodes

2019-10-18 Thread Benoit Parrot
This patch series adds the needed clkctrl and ty-sysc nodes for CAL module.
It also adds support for the module in related dtsi and dts for DRA72,
DRA76 and AM654 SoC.

Benoit Parrot (9):
  ARM: dts: dra7: add cam clkctrl node
  ARM: OMAP: DRA7xx: Make CAM clock domain SWSUP only
  ARM: dts: dra7-l4: Add ti-sysc node for CAM
  ARM: dts: DRA72: Add CAL dtsi node
  arm: dts: dra72-evm-common: Add entries for the CSI2 cameras
  arm: dtsi: dra76x: Add CAL dtsi node
  arm: dts: dra76-evm: Add CAL and OV5640 nodes
  arm64: dts: k3-am65-main Add CAL node
  arm64: dts: k3-am654-base-board: Add CSI2 OV5640 camera

 arch/arm/boot/dts/dra7-l4.dtsi| 43 ---
 arch/arm/boot/dts/dra72-evm-common.dtsi   | 35 +++
 arch/arm/boot/dts/dra72x.dtsi | 43 +++
 arch/arm/boot/dts/dra76-evm.dts   | 39 +
 arch/arm/boot/dts/dra76x.dtsi | 43 +++
 arch/arm/boot/dts/dra7xx-clocks.dtsi  | 14 ++
 arch/arm/mach-omap2/clockdomains7xx_data.c|  2 +-
 arch/arm64/boot/dts/ti/k3-am65-main.dtsi  | 23 ++
 .../arm64/boot/dts/ti/k3-am654-base-board.dts | 36 
 drivers/clk/ti/clk-7xx.c  | 19 
 include/dt-bindings/clock/dra7.h  | 10 +
 11 files changed, 300 insertions(+), 7 deletions(-)

-- 
2.17.1



[Patch 3/9] ARM: dts: dra7-l4: Add ti-sysc node for CAM

2019-10-18 Thread Benoit Parrot
Add CAM nodes as a child of l4 interconnect in order for it to probe
using ti-sysc.

Signed-off-by: Benoit Parrot 
---
 arch/arm/boot/dts/dra7-l4.dtsi | 43 +-
 1 file changed, 37 insertions(+), 6 deletions(-)

diff --git a/arch/arm/boot/dts/dra7-l4.dtsi b/arch/arm/boot/dts/dra7-l4.dtsi
index 0917231a20e2..8f5c26a4f7c8 100644
--- a/arch/arm/boot/dts/dra7-l4.dtsi
+++ b/arch/arm/boot/dts/dra7-l4.dtsi
@@ -4135,27 +4135,58 @@
};
 
target-module@17 {  /* 0x4897, ap 21 
0a.0 */
-   compatible = "ti,sysc";
-   status = "disabled";
+   compatible = "ti,sysc-omap4", "ti,sysc";
+   reg = <0x170010 0x4>;
+   reg-names = "sysc";
+   ti,sysc-midle = ,
+   ,
+   ;
+   ti,sysc-sidle = ,
+   ,
+   ;
+   clocks = <&cam_clkctrl DRA7_CAM_VIP1_CLKCTRL 0>;
+   clock-names = "fck";
#address-cells = <1>;
#size-cells = <1>;
ranges = <0x0 0x17 0x1>;
+   status = "disabled";
};
 
target-module@19 {  /* 0x4899, ap 23 
2e.0 */
-   compatible = "ti,sysc";
-   status = "disabled";
+   compatible = "ti,sysc-omap4", "ti,sysc";
+   reg = <0x190010 0x4>;
+   reg-names = "sysc";
+   ti,sysc-midle = ,
+   ,
+   ;
+   ti,sysc-sidle = ,
+   ,
+   ;
+   clocks = <&cam_clkctrl DRA7_CAM_VIP2_CLKCTRL 0>;
+   clock-names = "fck";
#address-cells = <1>;
#size-cells = <1>;
ranges = <0x0 0x19 0x1>;
+   status = "disabled";
};
 
target-module@1b {  /* 0x489b, ap 25 
34.0 */
-   compatible = "ti,sysc";
-   status = "disabled";
+   compatible = "ti,sysc-omap4", "ti,sysc";
+   reg = <0x1b 0x4>,
+ <0x1b0010 0x4>;
+   reg-names = "rev", "sysc";
+   ti,sysc-midle = ,
+   ,
+   ;
+   ti,sysc-sidle = ,
+   ,
+   ;
+   clocks = <&cam_clkctrl DRA7_CAM_VIP3_CLKCTRL 0>;
+   clock-names = "fck";
#address-cells = <1>;
#size-cells = <1>;
ranges = <0x0 0x1b 0x1>;
+   status = "disabled";
};
 
target-module@1d0010 {  /* 0x489d, ap 27 
30.0 */
-- 
2.17.1



[Patch 09/19] media: ti-vpe: cal: Fix pixel processing parameters

2019-10-18 Thread Benoit Parrot
The pixel processing unit was hard coded to only handle 8 bits per pixel
from input to output.

We now add handling for 10, 12 and 16 bits per pixel at the source and
setting the in-memory size (i.e. container size) to 16 bits for these 3
cases.

Signed-off-by: Benoit Parrot 
---
 drivers/media/platform/ti-vpe/cal.c | 41 ++---
 1 file changed, 38 insertions(+), 3 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/cal.c 
b/drivers/media/platform/ti-vpe/cal.c
index 5cc44c5b0ad8..3c293e263397 100644
--- a/drivers/media/platform/ti-vpe/cal.c
+++ b/drivers/media/platform/ti-vpe/cal.c
@@ -803,13 +803,48 @@ static void csi2_ctx_config(struct cal_ctx *ctx)
 
 static void pix_proc_config(struct cal_ctx *ctx)
 {
-   u32 val;
+   u32 val, extract, pack;
+
+   switch (ctx->fmt->bpp) {
+   case 8:
+   extract = CAL_PIX_PROC_EXTRACT_B8;
+   pack = CAL_PIX_PROC_PACK_B8;
+   break;
+   case 10:
+   extract = CAL_PIX_PROC_EXTRACT_B10_MIPI;
+   pack = CAL_PIX_PROC_PACK_B16;
+   break;
+   case 12:
+   extract = CAL_PIX_PROC_EXTRACT_B12_MIPI;
+   pack = CAL_PIX_PROC_PACK_B16;
+   break;
+   case 16:
+   extract = CAL_PIX_PROC_EXTRACT_B16_LE;
+   pack = CAL_PIX_PROC_PACK_B16;
+   break;
+   default:
+   /*
+* If you see this warning then it means that you added
+* some new entry in the cal_formats[] array with a different
+* bit per pixel values then the one supported below.
+* Either add support for the new bpp value below or adjust
+* the new entry to use one of the value below.
+*
+* Instead of failing here just use 8 bpp as a default.
+*/
+   dev_warn_once(&ctx->dev->pdev->dev,
+ "%s:%d:%s: bpp:%d unsupported! Overwritten with 
8.\n",
+ __FILE__, __LINE__, __func__, ctx->fmt->bpp);
+   extract = CAL_PIX_PROC_EXTRACT_B8;
+   pack = CAL_PIX_PROC_PACK_B8;
+   break;
+   }
 
val = reg_read(ctx->dev, CAL_PIX_PROC(ctx->csi2_port));
-   set_field(&val, CAL_PIX_PROC_EXTRACT_B8, CAL_PIX_PROC_EXTRACT_MASK);
+   set_field(&val, extract, CAL_PIX_PROC_EXTRACT_MASK);
set_field(&val, CAL_PIX_PROC_DPCMD_BYPASS, CAL_PIX_PROC_DPCMD_MASK);
set_field(&val, CAL_PIX_PROC_DPCME_BYPASS, CAL_PIX_PROC_DPCME_MASK);
-   set_field(&val, CAL_PIX_PROC_PACK_B8, CAL_PIX_PROC_PACK_MASK);
+   set_field(&val, pack, CAL_PIX_PROC_PACK_MASK);
set_field(&val, ctx->csi2_port, CAL_PIX_PROC_CPORT_MASK);
set_field(&val, CAL_GEN_ENABLE, CAL_PIX_PROC_EN_MASK);
reg_write(ctx->dev, CAL_PIX_PROC(ctx->csi2_port), val);
-- 
2.17.1



[Patch 04/19] media: ti-vpe: cal: Enable DMABUF export

2019-10-18 Thread Benoit Parrot
Allow CAL to be able to export DMA buffer.

Signed-off-by: Benoit Parrot 
Signed-off-by: Jyri Sarha 
---
 drivers/media/platform/ti-vpe/cal.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/media/platform/ti-vpe/cal.c 
b/drivers/media/platform/ti-vpe/cal.c
index 26f95a81e4ed..78fe2da61d77 100644
--- a/drivers/media/platform/ti-vpe/cal.c
+++ b/drivers/media/platform/ti-vpe/cal.c
@@ -1488,6 +1488,7 @@ static const struct v4l2_ioctl_ops cal_ioctl_ops = {
.vidioc_querybuf  = vb2_ioctl_querybuf,
.vidioc_qbuf  = vb2_ioctl_qbuf,
.vidioc_dqbuf = vb2_ioctl_dqbuf,
+   .vidioc_expbuf= vb2_ioctl_expbuf,
.vidioc_enum_input= cal_enum_input,
.vidioc_g_input   = cal_g_input,
.vidioc_s_input   = cal_s_input,
-- 
2.17.1



[Patch 07/19] media: ti-vpe: cal: add CSI2 PHY LDO errata support

2019-10-18 Thread Benoit Parrot
Apply Errata i913 every time the functional clock is enabled.
This should take care of suspend/resume case as well.

Signed-off-by: Benoit Parrot 
Signed-off-by: Jyri Sarha 
---
 drivers/media/platform/ti-vpe/cal.c  | 56 +++-
 drivers/media/platform/ti-vpe/cal_regs.h | 27 
 2 files changed, 82 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/ti-vpe/cal.c 
b/drivers/media/platform/ti-vpe/cal.c
index 62aeedb705e9..3cbc4dca6de8 100644
--- a/drivers/media/platform/ti-vpe/cal.c
+++ b/drivers/media/platform/ti-vpe/cal.c
@@ -284,6 +284,13 @@ static struct cal_data dra72x_cal_data = {
.flags = 0,
 };
 
+static struct cal_data dra72x_es1_cal_data = {
+   .csi2_phy_core = dra72x_cal_csi_phy,
+   .num_csi2_phy = ARRAY_SIZE(dra72x_cal_csi_phy),
+
+   .flags = DRA72_CAL_PRE_ES2_LDO_DISABLE,
+};
+
 /*
  * there is one cal_dev structure in the driver, it is shared by
  * all instances.
@@ -569,9 +576,52 @@ static void cal_get_hwinfo(struct cal_dev *dev)
hwinfo);
 }
 
+/*
+ *   Errata i913: CSI2 LDO Needs to be disabled when module is powered on
+ *
+ *   Enabling CSI2 LDO shorts it to core supply. It is crucial the 2 CSI2
+ *   LDOs on the device are disabled if CSI-2 module is powered on
+ *   (0x4845 B304 | 0x4845 B384 [28:27] = 0x1) or in ULPS (0x4845 B304
+ *   | 0x4845 B384 [28:27] = 0x2) mode. Common concerns include: high
+ *   current draw on the module supply in active mode.
+ *
+ *   Errata does not apply when CSI-2 module is powered off
+ *   (0x4845 B304 | 0x4845 B384 [28:27] = 0x0).
+ *
+ * SW Workaround:
+ * Set the following register bits to disable the LDO,
+ * which is essentially CSI2 REG10 bit 6:
+ *
+ * Core 0:  0x4845 B828 = 0x 0040
+ * Core 1:  0x4845 B928 = 0x 0040
+ */
+static void i913_errata(struct cal_dev *dev, unsigned int port)
+{
+   u32 reg10 = reg_read(dev->cc[port], CAL_CSI2_PHY_REG10);
+
+   set_field(®10, CAL_CSI2_PHY_REG0_HSCLOCKCONFIG_DISABLE,
+ CAL_CSI2_PHY_REG10_I933_LDO_DISABLE_MASK);
+
+   cal_dbg(1, dev, "CSI2_%d_REG10 = 0x%08x\n", port, reg10);
+   reg_write(dev->cc[port], CAL_CSI2_PHY_REG10, reg10);
+}
+
 static inline int cal_runtime_get(struct cal_dev *dev)
 {
-   return pm_runtime_get_sync(&dev->pdev->dev);
+   int r;
+
+   r = pm_runtime_get_sync(&dev->pdev->dev);
+
+   if (dev->flags & DRA72_CAL_PRE_ES2_LDO_DISABLE) {
+   /*
+* Apply errata on both port eveytime we (re-)enable
+* the clock
+*/
+   i913_errata(dev, 0);
+   i913_errata(dev, 1);
+   }
+
+   return r;
 }
 
 static inline void cal_runtime_put(struct cal_dev *dev)
@@ -2071,6 +2121,10 @@ static const struct of_device_id cal_of_match[] = {
.compatible = "ti,dra72-cal",
.data = (void *)&dra72x_cal_data,
},
+   {
+   .compatible = "ti,dra72-pre-es2-cal",
+   .data = (void *)&dra72x_es1_cal_data,
+   },
{},
 };
 MODULE_DEVICE_TABLE(of, cal_of_match);
diff --git a/drivers/media/platform/ti-vpe/cal_regs.h 
b/drivers/media/platform/ti-vpe/cal_regs.h
index 68cfc922b422..78d6f015c9ea 100644
--- a/drivers/media/platform/ti-vpe/cal_regs.h
+++ b/drivers/media/platform/ti-vpe/cal_regs.h
@@ -10,6 +10,30 @@
 #ifndef __TI_CAL_REGS_H
 #define __TI_CAL_REGS_H
 
+/*
+ * struct cal_dev.flags possibilities
+ *
+ * DRA72_CAL_PRE_ES2_LDO_DISABLE:
+ *   Errata i913: CSI2 LDO Needs to be disabled when module is powered on
+ *
+ *   Enabling CSI2 LDO shorts it to core supply. It is crucial the 2 CSI2
+ *   LDOs on the device are disabled if CSI-2 module is powered on
+ *   (0x4845 B304 | 0x4845 B384 [28:27] = 0x1) or in ULPS (0x4845 B304
+ *   | 0x4845 B384 [28:27] = 0x2) mode. Common concerns include: high
+ *   current draw on the module supply in active mode.
+ *
+ *   Errata does not apply when CSI-2 module is powered off
+ *   (0x4845 B304 | 0x4845 B384 [28:27] = 0x0).
+ *
+ * SW Workaround:
+ * Set the following register bits to disable the LDO,
+ * which is essentially CSI2 REG10 bit 6:
+ *
+ * Core 0:  0x4845 B828 = 0x 0040
+ * Core 1:  0x4845 B928 = 0x 0040
+ */
+#define DRA72_CAL_PRE_ES2_LDO_DISABLE BIT(0)
+
 #define CAL_NUM_CSI2_PORTS 2
 
 /* CAL register offsets */
@@ -71,6 +95,7 @@
 #define CAL_CSI2_PHY_REG0  0x000
 #define CAL_CSI2_PHY_REG1  0x004
 #define CAL_CSI2_PHY_REG2  0x008
+#define CAL_CSI2_PHY_REG10 0x028
 
 /* CAL Control Module Core Camerrx Control register offsets */
 #define CM_CTRL_CORE_CAMERRX_CONTROL   0x000
@@ -458,6 +483,8 @@
 #define CAL_CSI2_PHY_REG1_CLOCK_MISS_DETECTOR_STATUS_SUCCESS   0
 #define CAL_CSI2_PHY_REG1_RESET_DONE_STATUS_MASK   GENMASK(29, 28)
 
+#define CAL_CS

[Patch 05/19] media: ti-vpe: cal: Restrict DMA to avoid memory corruption

2019-10-18 Thread Benoit Parrot
From: Nikhil Devshatwar 

When setting DMA for video capture from CSI channel, if the DMA size
is not given, it ends up writing as much data as sent by the camera.

This may lead to overwriting the buffers causing memory corruption.
Observed green lines on the default framebuffer.

Restrict the DMA to maximum height as specified in the S_FMT ioctl.

Signed-off-by: Nikhil Devshatwar 
Signed-off-by: Benoit Parrot 
---
 drivers/media/platform/ti-vpe/cal.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/cal.c 
b/drivers/media/platform/ti-vpe/cal.c
index 78fe2da61d77..62aeedb705e9 100644
--- a/drivers/media/platform/ti-vpe/cal.c
+++ b/drivers/media/platform/ti-vpe/cal.c
@@ -769,12 +769,13 @@ static void pix_proc_config(struct cal_ctx *ctx)
 }
 
 static void cal_wr_dma_config(struct cal_ctx *ctx,
- unsigned int width)
+ unsigned int width, unsigned int height)
 {
u32 val;
 
val = reg_read(ctx->dev, CAL_WR_DMA_CTRL(ctx->csi2_port));
set_field(&val, ctx->csi2_port, CAL_WR_DMA_CTRL_CPORT_MASK);
+   set_field(&val, height, CAL_WR_DMA_CTRL_YSIZE_MASK);
set_field(&val, CAL_WR_DMA_CTRL_DTAG_PIX_DAT,
  CAL_WR_DMA_CTRL_DTAG_MASK);
set_field(&val, CAL_WR_DMA_CTRL_MODE_CONST,
@@ -1397,7 +1398,8 @@ static int cal_start_streaming(struct vb2_queue *vq, 
unsigned int count)
csi2_lane_config(ctx);
csi2_ctx_config(ctx);
pix_proc_config(ctx);
-   cal_wr_dma_config(ctx, ctx->v_fmt.fmt.pix.bytesperline);
+   cal_wr_dma_config(ctx, ctx->v_fmt.fmt.pix.bytesperline,
+ ctx->v_fmt.fmt.pix.height);
cal_wr_dma_addr(ctx, addr);
csi2_ppi_enable(ctx);
 
-- 
2.17.1



[Patch 03/19] media: ti-vpe: cal: Add per platform data support

2019-10-18 Thread Benoit Parrot
First this patch adds a method to access the CTRL_CORE_CAMERRX_CONTROL
register to use the syscon mechanism. For backward compatibility we also
handle using the existing camerrx_control "reg" entry if a syscon node
is not found.

In addition the register bit layout for the CTRL_CORE_CAMERRX_CONTROL
changes depending on the device. In order to support this we need to use
a register access scheme based on data configuration instead of using
static macro.

In this case we make use of the regmap facility and create data set
based on the various device and phy available.

Signed-off-by: Benoit Parrot 
---
 drivers/media/platform/ti-vpe/cal.c | 281 +---
 1 file changed, 212 insertions(+), 69 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/cal.c 
b/drivers/media/platform/ti-vpe/cal.c
index 223161f9c403..26f95a81e4ed 100644
--- a/drivers/media/platform/ti-vpe/cal.c
+++ b/drivers/media/platform/ti-vpe/cal.c
@@ -14,6 +14,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 #include 
 #include 
 #include 
@@ -220,20 +222,66 @@ struct cal_dmaqueue {
int ini_jiffies;
 };
 
-struct cm_data {
+struct cc_data {
void __iomem*base;
struct resource *res;
 
-   unsigned intcamerrx_control;
-
struct platform_device *pdev;
 };
 
-struct cc_data {
-   void __iomem*base;
-   struct resource *res;
+/* CTRL_CORE_CAMERRX_CONTROL register field id */
+enum cal_camerarx_field {
+   F_CTRLCLKEN,
+   F_CAMMODE,
+   F_LANEENABLE,
+   F_CSI_MODE,
 
-   struct platform_device *pdev;
+   F_MAX_FIELDS,
+};
+
+struct cal_csi2_phy {
+   struct regmap_field *fields[F_MAX_FIELDS];
+   struct reg_field *base_fields;
+   const int num_lanes;
+};
+
+struct cal_data {
+   const int num_csi2_phy;
+   struct cal_csi2_phy *csi2_phy_core;
+
+   const unsigned int flags;
+};
+
+static struct reg_field dra72x_ctrl_core_csi0_reg_fields[F_MAX_FIELDS] = {
+   [F_CTRLCLKEN] = REG_FIELD(0, 10, 10),
+   [F_CAMMODE] = REG_FIELD(0, 11, 12),
+   [F_LANEENABLE] = REG_FIELD(0, 13, 16),
+   [F_CSI_MODE] = REG_FIELD(0, 17, 17),
+};
+
+static struct reg_field dra72x_ctrl_core_csi1_reg_fields[F_MAX_FIELDS] = {
+   [F_CTRLCLKEN] = REG_FIELD(0, 0, 0),
+   [F_CAMMODE] = REG_FIELD(0, 1, 2),
+   [F_LANEENABLE] = REG_FIELD(0, 3, 4),
+   [F_CSI_MODE] = REG_FIELD(0, 5, 5),
+};
+
+static struct cal_csi2_phy dra72x_cal_csi_phy[] = {
+   {
+   .base_fields = dra72x_ctrl_core_csi0_reg_fields,
+   .num_lanes = 4,
+   },
+   {
+   .base_fields = dra72x_ctrl_core_csi1_reg_fields,
+   .num_lanes = 2,
+   },
+};
+
+static struct cal_data dra72x_cal_data = {
+   .csi2_phy_core = dra72x_cal_csi_phy,
+   .num_csi2_phy = ARRAY_SIZE(dra72x_cal_csi_phy),
+
+   .flags = 0,
 };
 
 /*
@@ -247,8 +295,15 @@ struct cal_dev {
struct platform_device  *pdev;
struct v4l2_device  v4l2_dev;
 
+   /* Controller flags for special cases */
+   unsigned intflags;
+
+   struct cal_data *data;
+
/* Control Module handle */
-   struct cm_data  *cm;
+   struct regmap   *syscon_camerrx;
+   u32 syscon_camerrx_offset;
+
/* Camera Core Module handle */
struct cc_data  *cc[CAL_NUM_CSI2_PORTS];
 
@@ -359,73 +414,113 @@ static inline void set_field(u32 *valp, u32 field, u32 
mask)
*valp = val;
 }
 
-/*
- * Control Module block access
- */
-static struct cm_data *cm_create(struct cal_dev *dev)
+static u32 cal_data_get_phy_max_lanes(struct cal_ctx *ctx)
 {
-   struct platform_device *pdev = dev->pdev;
-   struct cm_data *cm;
+   struct cal_dev *dev = ctx->dev;
+   u32 phy_id = ctx->csi2_port - 1;
 
-   cm = devm_kzalloc(&pdev->dev, sizeof(*cm), GFP_KERNEL);
-   if (!cm)
-   return ERR_PTR(-ENOMEM);
+   return dev->data->csi2_phy_core[phy_id].num_lanes;
+}
+
+static u32 cal_data_get_num_csi2_phy(struct cal_dev *dev)
+{
+   return dev->data->num_csi2_phy;
+}
+
+static int cal_camerarx_regmap_init(struct cal_dev *dev)
+{
+   struct reg_field *field;
+   struct cal_csi2_phy *phy;
+   int i, j;
+
+   if (!dev->data)
+   return -EINVAL;
 
-   cm->res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
-   "camerrx_control");
-   cm->base = devm_ioremap_resource(&pdev->dev, cm->res);
-   if (IS_ERR(cm->base)) {
+   for (i = 0; i < cal_data_get_num_csi2_phy(dev); i++) {
+   phy = &dev->data->csi2_phy_core[i];
+   for (j = 0; j < F_MAX_FIELDS; j++) {
+   field = &phy->base_fields[j];
+   /*
+

[Patch 08/19] media: ti-vpe: cal: Fix ths_term/ths_settle parameters

2019-10-18 Thread Benoit Parrot
The current method to calculate the ddr clk period is wrong.
Therefore the ths_term calculation is incorrect.
Also it was wrongly assumed that the ths_settle parameter
was based on the control clock instead of the pixel clock.

Since the DPHY can tolerate quite a bit a of variation,
capture was still mostly working with the 2 tested modes
when the pixel clock was close to the control clock
(i.e. 96 Mhz). But it would quickly stops working when
using different modes or when customers used different
sensors altogether.

Calculating the DDRClk period needs to take into account
the pixel bit width and the number of active data lanes.

Based on the latest technical reference manual these
parameters should now be calculated as follows:

THS_TERM: Programmed value = floor(20 ns/DDRClk period)
THS_SETTLE: Programmed value = floor(105 ns/DDRClk period) + 4

Also originally 'depth' was used to represent the number of
bits a pixel would use once stored in memory (i.e. the
container size). To accurately calculate the THS_* parameters
we need to use the actual number of bits per pixels coming
in from the sensor. So we are renaming 'depth' to 'bpp' (bits
per pixels) and update the format table to show the actual
number of bits per pixel being received.

The "container" size will be derived from the "bpp" value.

Signed-off-by: Benoit Parrot 
---
 drivers/media/platform/ti-vpe/cal.c | 98 +
 1 file changed, 44 insertions(+), 54 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/cal.c 
b/drivers/media/platform/ti-vpe/cal.c
index 3cbc4dca6de8..5cc44c5b0ad8 100644
--- a/drivers/media/platform/ti-vpe/cal.c
+++ b/drivers/media/platform/ti-vpe/cal.c
@@ -73,8 +73,6 @@ static const struct v4l2_fract
 #define CAL_NUM_INPUT 1
 #define CAL_NUM_CONTEXT 2
 
-#define bytes_per_line(pixel, bpp) (ALIGN(pixel * bpp, 16))
-
 #define reg_read(dev, offset) ioread32(dev->base + offset)
 #define reg_write(dev, offset, val) iowrite32(val, dev->base + offset)
 
@@ -93,102 +91,103 @@ static const struct v4l2_fract
 struct cal_fmt {
u32 fourcc;
u32 code;
-   u8  depth;
+   /* Bits per pixel */
+   u8  bpp;
 };
 
 static struct cal_fmt cal_formats[] = {
{
.fourcc = V4L2_PIX_FMT_YUYV,
.code   = MEDIA_BUS_FMT_YUYV8_2X8,
-   .depth  = 16,
+   .bpp= 16,
}, {
.fourcc = V4L2_PIX_FMT_UYVY,
.code   = MEDIA_BUS_FMT_UYVY8_2X8,
-   .depth  = 16,
+   .bpp= 16,
}, {
.fourcc = V4L2_PIX_FMT_YVYU,
.code   = MEDIA_BUS_FMT_YVYU8_2X8,
-   .depth  = 16,
+   .bpp= 16,
}, {
.fourcc = V4L2_PIX_FMT_VYUY,
.code   = MEDIA_BUS_FMT_VYUY8_2X8,
-   .depth  = 16,
+   .bpp= 16,
}, {
.fourcc = V4L2_PIX_FMT_RGB565, /* gggb rggg */
.code   = MEDIA_BUS_FMT_RGB565_2X8_LE,
-   .depth  = 16,
+   .bpp= 16,
}, {
.fourcc = V4L2_PIX_FMT_RGB565X, /* rggg gggb */
.code   = MEDIA_BUS_FMT_RGB565_2X8_BE,
-   .depth  = 16,
+   .bpp= 16,
}, {
.fourcc = V4L2_PIX_FMT_RGB555, /* gggb argg */
.code   = MEDIA_BUS_FMT_RGB555_2X8_PADHI_LE,
-   .depth  = 16,
+   .bpp= 16,
}, {
.fourcc = V4L2_PIX_FMT_RGB555X, /* argg gggb */
.code   = MEDIA_BUS_FMT_RGB555_2X8_PADHI_BE,
-   .depth  = 16,
+   .bpp= 16,
}, {
.fourcc = V4L2_PIX_FMT_RGB24, /* rgb */
.code   = MEDIA_BUS_FMT_RGB888_2X12_LE,
-   .depth  = 24,
+   .bpp= 24,
}, {
.fourcc = V4L2_PIX_FMT_BGR24, /* bgr */
.code   = MEDIA_BUS_FMT_RGB888_2X12_BE,
-   .depth  = 24,
+   .bpp= 24,
}, {
.fourcc = V4L2_PIX_FMT_RGB32, /* argb */
.code   = MEDIA_BUS_FMT_ARGB_1X32,
-   .depth  = 32,
+   .bpp= 32,
}, {
.fourcc = V4L2_PIX_FMT_SBGGR8,
.code   = MEDIA_BUS_FMT_SBGGR8_1X8,
-   .depth  = 8,
+   .bpp= 8,
}, {
.fourcc = V4L2_PIX_FMT_SGBRG8,
.code   = MEDIA

[Patch 18/19] media: ti-vpe: cal: fix enum_mbus_code/frame_size subdev arguments

2019-10-18 Thread Benoit Parrot
Make sure that both enum_mbus_code() and enum_framesize() properly
populate the .which parameter member, otherwise -EINVAL is return
causing the subdev asynchronous registration handshake to fail.

Signed-off-by: Benoit Parrot 
---
 drivers/media/platform/ti-vpe/cal.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/media/platform/ti-vpe/cal.c 
b/drivers/media/platform/ti-vpe/cal.c
index b55987ee70dd..6a404350edb3 100644
--- a/drivers/media/platform/ti-vpe/cal.c
+++ b/drivers/media/platform/ti-vpe/cal.c
@@ -1500,6 +1500,7 @@ static int cal_enum_framesizes(struct file *file, void 
*fh,
fse.index = fsize->index;
fse.pad = 0;
fse.code = fmt->code;
+   fse.which = V4L2_SUBDEV_FORMAT_ACTIVE;
 
ret = v4l2_subdev_call(ctx->sensor, pad, enum_frame_size, NULL, &fse);
if (ret)
@@ -1840,6 +1841,7 @@ static int cal_async_bound(struct v4l2_async_notifier 
*notifier,
 
memset(&mbus_code, 0, sizeof(mbus_code));
mbus_code.index = j;
+   mbus_code.which = V4L2_SUBDEV_FORMAT_ACTIVE;
ret = v4l2_subdev_call(subdev, pad, enum_mbus_code,
   NULL, &mbus_code);
if (ret)
-- 
2.17.1



[Patch 13/19] dt-bindings: media: cal: update binding to add AM654 support

2019-10-18 Thread Benoit Parrot
Update Device Tree bindings for the CAL driver to add AM654 support.

Signed-off-by: Benoit Parrot 
---
 Documentation/devicetree/bindings/media/ti-cal.txt | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Documentation/devicetree/bindings/media/ti-cal.txt 
b/Documentation/devicetree/bindings/media/ti-cal.txt
index 29fbbfb8be0d..b7bf8492dc2a 100644
--- a/Documentation/devicetree/bindings/media/ti-cal.txt
+++ b/Documentation/devicetree/bindings/media/ti-cal.txt
@@ -11,6 +11,7 @@ Required properties:
  Should be "ti,dra72-cal", for DRA72 controllers
  Should be "ti,dra72-pre-es2-cal", for DRA72 controllers pre ES2.0
  Should be "ti,dra76-cal", for DRA76 controllers
+ Should be "ti,am654-cal", for AM654 controllers
 - reg: CAL Top level, Receiver Core #0, Receiver Core #1 and Camera RX
control address space
 - reg-names: cal_top, cal_rx_core0, cal_rx_core1 and camerrx_control
-- 
2.17.1



[Patch 02/19] dt-bindings: media: cal: update binding example

2019-10-18 Thread Benoit Parrot
Update binding example to show proper endpoint properties and linkage.

Signed-off-by: Benoit Parrot 
---
 .../devicetree/bindings/media/ti-cal.txt  | 32 ++-
 1 file changed, 17 insertions(+), 15 deletions(-)

diff --git a/Documentation/devicetree/bindings/media/ti-cal.txt 
b/Documentation/devicetree/bindings/media/ti-cal.txt
index 782f801b12a9..6b56fddcfc4a 100644
--- a/Documentation/devicetree/bindings/media/ti-cal.txt
+++ b/Documentation/devicetree/bindings/media/ti-cal.txt
@@ -27,7 +27,6 @@ Documentation/devicetree/bindings/media/video-interfaces.txt.
 Example:
cal: cal@4845b000 {
compatible = "ti,dra72-cal";
-   ti,hwmods = "cal";
reg = <0x4845B000 0x400>,
  <0x4845B800 0x40>,
  <0x4845B900 0x40>;
@@ -45,9 +44,10 @@ Example:
 
csi2_0: port@0 {
reg = <0>;
-   endpoint {
-   slave-mode;
-   remote-endpoint = <&ar0330_1>;
+   csi2_phy0: endpoint@0 {
+   remote-endpoint = <&csi2_cam0>;
+   clock-lanes = <0>;
+   data-lanes = <1 2>;
};
};
csi2_1: port@1 {
@@ -57,19 +57,21 @@ Example:
};
 
i2c5: i2c@4807c000 {
-   ar0330@10 {
-   compatible = "ti,ar0330";
-   reg = <0x10>;
+   status = "okay";
+   clock-frequency = <40>;
 
-   port {
-   #address-cells = <1>;
-   #size-cells = <0>;
+   ov5640@3c {
+   compatible = "ovti,ov5640";
+   reg = <0x3c>;
+
+   clocks = <&clk_ov5640_fixed>;
+   clock-names = "xclk";
 
-   ar0330_1: endpoint {
-   reg = <0>;
-   clock-lanes = <1>;
-   data-lanes = <0 2 3 4>;
-   remote-endpoint = <&csi2_0>;
+   port {
+   csi2_cam0: endpoint {
+   remote-endpoint = <&csi2_phy0>;
+   clock-lanes = <0>;
+   data-lanes = <1 2>;
};
};
};
-- 
2.17.1



[Patch 01/19] dt-bindings: media: cal: update binding to use syscon

2019-10-18 Thread Benoit Parrot
Update Device Tree bindings for the CAL driver to use syscon to access
the phy config register instead of trying to map it directly.

Signed-off-by: Benoit Parrot 
---
 Documentation/devicetree/bindings/media/ti-cal.txt | 14 +-
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/Documentation/devicetree/bindings/media/ti-cal.txt 
b/Documentation/devicetree/bindings/media/ti-cal.txt
index ae9b52f37576..782f801b12a9 100644
--- a/Documentation/devicetree/bindings/media/ti-cal.txt
+++ b/Documentation/devicetree/bindings/media/ti-cal.txt
@@ -10,9 +10,14 @@ Required properties:
 - compatible: must be "ti,dra72-cal"
 - reg: CAL Top level, Receiver Core #0, Receiver Core #1 and Camera RX
control address space
-- reg-names: cal_top, cal_rx_core0, cal_rx_core1, and camerrx_control
+- reg-names: cal_top, cal_rx_core0, cal_rx_core1 and camerrx_control
 registers
 - interrupts: should contain IRQ line for the CAL;
+- syscon-camerrx: phandle to the device control module and offset to the
+ control_camerarx_core register
+ This node is meant to replace the "camerrx_control" reg
+ entry above but "camerrx_control" is still handled
+ for backward compatibility.
 
 CAL supports 2 camera port nodes on MIPI bus. Each CSI2 camera port nodes
 should contain a 'port' child node with child 'endpoint' node. Please
@@ -25,13 +30,12 @@ Example:
ti,hwmods = "cal";
reg = <0x4845B000 0x400>,
  <0x4845B800 0x40>,
- <0x4845B900 0x40>,
- <0x4A002e94 0x4>;
+ <0x4845B900 0x40>;
reg-names = "cal_top",
"cal_rx_core0",
-   "cal_rx_core1",
-   "camerrx_control";
+   "cal_rx_core1";
interrupts = ;
+   syscon-camerrx = <&scm_conf 0xE94>;
#address-cells = <1>;
#size-cells = <0>;
 
-- 
2.17.1



[Patch 00/19] media: ti-vpe: cal: maintenance

2019-10-18 Thread Benoit Parrot
This a collection of backlog patches I have been carrying for the CAL
driver.

- Add support for SoC variants.

- Switches to syscon/regmap to access a system controller register for
the DPHY configuration. This register has different bit layout depending
on the SoC version.

- It adds supports for pre ES2.0 silicon errata.

- Reworked the DPHY initialization sequence to match the technical
reference manual and provide a more robust restartability.

- Adds the missing ability to power subdevice.

- Update the devicetree binding and then converts it to dt-schema 

Benoit Parrot (18):
  dt-bindings: media: cal: update binding to use syscon
  dt-bindings: media: cal: update binding example
  media: ti-vpe: cal: Add per platform data support
  media: ti-vpe: cal: Enable DMABUF export
  dt-bindings: media: cal: update binding to add PHY LDO errata support
  media: ti-vpe: cal: add CSI2 PHY LDO errata support
  media: ti-vpe: cal: Fix ths_term/ths_settle parameters
  media: ti-vpe: cal: Fix pixel processing parameters
  media: ti-vpe: cal: Align DPHY init sequence with docs
  dt-bindings: media: cal: update binding to add DRA76x support
  media: ti-vpe: cal: Add DRA76x support
  dt-bindings: media: cal: update binding to add AM654 support
  media: ti-vpe: cal: Add AM654 support
  media: ti-vpe: cal: Add subdev s_power hooks
  media: ti-vpe: cal: Properly calculate max resolution boundary
  media: ti-vpe: cal: Fix a WARN issued when start streaming fails
  media: ti-vpe: cal: fix enum_mbus_code/frame_size subdev arguments
  dt-bindings: media: cal: convert binding to yaml

Nikhil Devshatwar (1):
  media: ti-vpe: cal: Restrict DMA to avoid memory corruption

 .../devicetree/bindings/media/ti,cal.yaml | 186 +
 .../devicetree/bindings/media/ti-cal.txt  |  72 --
 drivers/media/platform/Kconfig|   2 +-
 drivers/media/platform/ti-vpe/cal.c   | 775 ++
 drivers/media/platform/ti-vpe/cal_regs.h  |  27 +
 5 files changed, 830 insertions(+), 232 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/media/ti,cal.yaml
 delete mode 100644 Documentation/devicetree/bindings/media/ti-cal.txt

-- 
2.17.1



[Patch 19/19] dt-bindings: media: cal: convert binding to yaml

2019-10-18 Thread Benoit Parrot
Convert ti-cal.txt to ti,cal.yaml.

Signed-off-by: Benoit Parrot 
---
 .../devicetree/bindings/media/ti,cal.yaml | 186 ++
 .../devicetree/bindings/media/ti-cal.txt  |  82 
 2 files changed, 186 insertions(+), 82 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/media/ti,cal.yaml
 delete mode 100644 Documentation/devicetree/bindings/media/ti-cal.txt

diff --git a/Documentation/devicetree/bindings/media/ti,cal.yaml 
b/Documentation/devicetree/bindings/media/ti,cal.yaml
new file mode 100644
index ..c3fbb22b4571
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/ti,cal.yaml
@@ -0,0 +1,186 @@
+# SPDX-License-Identifier: (GPL-2.0)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/media/ti,cal.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Texas Instruments DRA72x CAMERA ADAPTATION LAYER (CAL) Device Tree 
Bindings
+
+maintainers:
+  - Benoit Parrot 
+
+description: |-
+  The Camera Adaptation Layer (CAL) is a key component for image capture
+  applications. The capture module provides the system interface and the
+  processing capability to connect CSI2 image-sensor modules to the
+  DRA72x device.
+
+  CAL supports 2 camera port nodes on MIPI bus. Each CSI2 camera port nodes
+  should contain a 'port' child node with child 'endpoint' node. Please
+  refer to the bindings defined in
+  Documentation/devicetree/bindings/media/video-interfaces.txt.
+
+  compatible should be
+ "ti,dra72-cal", for DRA72 controllers
+ "ti,dra72-pre-es2-cal", for DRA72 controllers pre ES2.0
+ "ti,dra76-cal", for DRA76 controllers
+ "ti,am654-cal", for AM654 controllers
+
+properties:
+  compatible:
+  items:
+- enum:
+- ti,dra72-cal
+- ti,dra72-pre-es2-cal
+- ti,dra76-cal
+- ti,am654-cal
+
+  reg:
+minItems: 2
+items:
+  - description: The CAL main register region
+  - description: The RX Core0 (DPHY0) register region
+  - description: The RX Core1 (DPHY1) register region
+
+  reg-names:
+minItems: 2
+items:
+  - const: cal_top
+  - const: cal_rx_core0
+  - const: cal_rx_core1
+
+  interrupts:
+maxItems: 1
+
+  syscon-camerrx:
+maxItems: 1
+items:
+  - description:
+   phandle to the device control module and offset to the
+   control_camerarx_core register
+
+  clocks:
+maxItems: 1
+description: functional clock
+
+  clock-names:
+items:
+  - const: fck
+
+  power-domains:
+description:
+  List of phandle and PM domain specifier as documented in
+  Documentation/devicetree/bindings/power/power_domain.txt
+maxItems: 1
+
+  # See ./video-interfaces.txt for details
+  ports:
+maxItems: 1
+type: object
+additionalProperties: false
+
+properties:
+  "#address-cells":
+const: 1
+
+  "#size-cells":
+const: 0
+
+patternProperties:
+  '^port@[0-9a-fA-F]+$':
+minItems: 1
+maxItems: 2
+type: object
+additionalProperties: false
+
+properties:
+  reg:
+minItems: 1
+items:
+  - description: The port id
+
+patternProperties:
+  '^endpoint@[0-9a-fA-F]+$':
+minItems: 1
+type: object
+additionalProperties: false
+
+properties:
+  clock-lanes:
+maxItems: 1
+
+  data-lanes:
+minItems: 1
+maxItems: 4
+
+  remote-endpoint: true
+
+required:
+  - remote-endpoint
+
+required:
+  - reg
+
+required:
+  - compatible
+  - reg
+  - reg-names
+  - interrupts
+  - syscon-camerrx
+
+additionalProperties: false
+
+examples:
+  - |
+#include 
+
+cal: cal@4845b000 {
+compatible = "ti,dra72-cal";
+reg = <0x4845B000 0x400>,
+  <0x4845B800 0x40>,
+  <0x4845B900 0x40>;
+reg-names = "cal_top",
+"cal_rx_core0",
+"cal_rx_core1";
+interrupts = ;
+syscon-camerrx = <&scm_conf 0xE94>;
+
+ports {
+  #address-cells = <1>;
+  #size-cells = <0>;
+
+  csi2_0: port@0 {
+reg = <0>;
+csi2_phy0: endpoint@0 {
+   remote-endpoint = <&csi2_cam0>;
+   clock-lanes = <0>;
+   data-lanes = <1 2>;
+};
+  };
+};
+};
+
+i2c5: i2c@4807c000 {
+status = "okay";
+clock-frequency = <40>;
+#address-cells = <1>;
+#size-cells = <0>;
+

[Patch 06/19] dt-bindings: media: cal: update binding to add PHY LDO errata support

2019-10-18 Thread Benoit Parrot
Update Device Tree bindings for the CAL driver to add support for
the CSI2 PHY LDO errata workaround for pre-es2 devices.

Signed-off-by: Benoit Parrot 
Signed-off-by: Jyri Sarha 
---
 Documentation/devicetree/bindings/media/ti-cal.txt | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/media/ti-cal.txt 
b/Documentation/devicetree/bindings/media/ti-cal.txt
index 6b56fddcfc4a..d43870a2324b 100644
--- a/Documentation/devicetree/bindings/media/ti-cal.txt
+++ b/Documentation/devicetree/bindings/media/ti-cal.txt
@@ -7,7 +7,9 @@ processing capability to connect CSI2 image-sensor modules to 
the
 DRA72x device.
 
 Required properties:
-- compatible: must be "ti,dra72-cal"
+- compatible:
+ Should be "ti,dra72-cal", for DRA72 controllers
+ Should be "ti,dra72-pre-es2-cal", for DRA72 controllers pre ES2.0
 - reg: CAL Top level, Receiver Core #0, Receiver Core #1 and Camera RX
control address space
 - reg-names: cal_top, cal_rx_core0, cal_rx_core1 and camerrx_control
-- 
2.17.1



[Patch 17/19] media: ti-vpe: cal: Fix a WARN issued when start streaming fails

2019-10-18 Thread Benoit Parrot
When start_streaming fails after the buffers have been queued we have to
make sure all buffers are returned to user-space properly otherwise a
v4l2 level WARN is generated.

Signed-off-by: Benoit Parrot 
---
 drivers/media/platform/ti-vpe/cal.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/drivers/media/platform/ti-vpe/cal.c 
b/drivers/media/platform/ti-vpe/cal.c
index a0ff67412410..b55987ee70dd 100644
--- a/drivers/media/platform/ti-vpe/cal.c
+++ b/drivers/media/platform/ti-vpe/cal.c
@@ -1702,10 +1702,15 @@ static int cal_start_streaming(struct vb2_queue *vq, 
unsigned int count)
return 0;
 
 err:
+   spin_lock_irqsave(&ctx->slock, flags);
+   vb2_buffer_done(&ctx->cur_frm->vb.vb2_buf, VB2_BUF_STATE_QUEUED);
+   ctx->cur_frm = NULL;
+   ctx->next_frm = NULL;
list_for_each_entry_safe(buf, tmp, &dma_q->active, list) {
list_del(&buf->list);
vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_QUEUED);
}
+   spin_unlock_irqrestore(&ctx->slock, flags);
return ret;
 }
 
-- 
2.17.1



[Patch 15/19] media: ti-vpe: cal: Add subdev s_power hooks

2019-10-18 Thread Benoit Parrot
Based on V4L2 documentations bridge driver must power on and off sub
device explicitly if media-controller mode is not used.

Signed-off-by: Benoit Parrot 
---
 drivers/media/platform/ti-vpe/cal.c | 12 
 1 file changed, 12 insertions(+)

diff --git a/drivers/media/platform/ti-vpe/cal.c 
b/drivers/media/platform/ti-vpe/cal.c
index 42b0063b610e..e61d2f3fd1da 100644
--- a/drivers/media/platform/ti-vpe/cal.c
+++ b/drivers/media/platform/ti-vpe/cal.c
@@ -1661,6 +1661,12 @@ static int cal_start_streaming(struct vb2_queue *vq, 
unsigned int count)
if (ret < 0)
goto err;
 
+   ret = v4l2_subdev_call(ctx->sensor, core, s_power, 1);
+   if (ret < 0 && ret != -ENOIOCTLCMD && ret != -ENODEV) {
+   ctx_err(ctx, "power on failed in subdev\n");
+   goto err;
+   }
+
cal_runtime_get(ctx->dev);
 
csi2_ctx_config(ctx);
@@ -1674,6 +1680,7 @@ static int cal_start_streaming(struct vb2_queue *vq, 
unsigned int count)
 
ret = v4l2_subdev_call(ctx->sensor, video, s_stream, 1);
if (ret) {
+   v4l2_subdev_call(ctx->sensor, core, s_power, 0);
ctx_err(ctx, "stream on failed in subdev\n");
cal_runtime_put(ctx->dev);
goto err;
@@ -1702,6 +1709,7 @@ static void cal_stop_streaming(struct vb2_queue *vq)
struct cal_dmaqueue *dma_q = &ctx->vidq;
struct cal_buffer *buf, *tmp;
unsigned long flags;
+   int ret;
 
csi2_ppi_disable(ctx);
disable_irqs(ctx);
@@ -1710,6 +1718,10 @@ static void cal_stop_streaming(struct vb2_queue *vq)
if (v4l2_subdev_call(ctx->sensor, video, s_stream, 0))
ctx_err(ctx, "stream off failed in subdev\n");
 
+   ret = v4l2_subdev_call(ctx->sensor, core, s_power, 0);
+   if (ret < 0 && ret != -ENOIOCTLCMD && ret != -ENODEV)
+   ctx_err(ctx, "power off failed in subdev\n");
+
/* Release all active buffers */
spin_lock_irqsave(&ctx->slock, flags);
list_for_each_entry_safe(buf, tmp, &dma_q->active, list) {
-- 
2.17.1



[Patch 16/19] media: ti-vpe: cal: Properly calculate max resolution boundary

2019-10-18 Thread Benoit Parrot
Currently we were using an arbitrarily small maximum resolution mostly
based on available sensor capabilities. However the hardware DMA limits
are much higher than the statically define maximum resolution we were
using.

There we rework the boundary check code to handle the maximum width and
height based on the maximum line width in bytes and re-calculating the
pixel width based on the given pixel format.

Signed-off-by: Benoit Parrot 
---
 drivers/media/platform/ti-vpe/cal.c | 16 +++-
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/cal.c 
b/drivers/media/platform/ti-vpe/cal.c
index e61d2f3fd1da..a0ff67412410 100644
--- a/drivers/media/platform/ti-vpe/cal.c
+++ b/drivers/media/platform/ti-vpe/cal.c
@@ -34,8 +34,8 @@
 
 #define CAL_MODULE_NAME "cal"
 
-#define MAX_WIDTH 1920
-#define MAX_HEIGHT 1200
+#define MAX_WIDTH_BYTES (8192 * 8)
+#define MAX_HEIGHT_LINES 16383
 
 #define CAL_VERSION "0.1.0"
 
@@ -1337,15 +1337,21 @@ static int cal_calc_format_size(struct cal_ctx *ctx,
const struct cal_fmt *fmt,
struct v4l2_format *f)
 {
-   u32 bpl;
+   u32 bpl, max_width;
 
if (!fmt) {
ctx_dbg(3, ctx, "No cal_fmt provided!\n");
return -EINVAL;
}
 
-   v4l_bound_align_image(&f->fmt.pix.width, 48, MAX_WIDTH, 2,
- &f->fmt.pix.height, 32, MAX_HEIGHT, 0, 0);
+   /*
+* Maximum width is bound by the DMA max width in bytes.
+* We need to recalculate the actual maxi width depending on the
+* number of bytes per pixels required.
+*/
+   max_width = MAX_WIDTH_BYTES / (ALIGN(fmt->bpp, 8) >> 3);
+   v4l_bound_align_image(&f->fmt.pix.width, 48, max_width, 2,
+ &f->fmt.pix.height, 32, MAX_HEIGHT_LINES, 0, 0);
 
bpl = (f->fmt.pix.width * ALIGN(fmt->bpp, 8)) >> 3;
f->fmt.pix.bytesperline = ALIGN(bpl, 16);
-- 
2.17.1



[Patch 11/19] dt-bindings: media: cal: update binding to add DRA76x support

2019-10-18 Thread Benoit Parrot
Update Device Tree bindings for the CAL driver to add DRA76x support.

Signed-off-by: Benoit Parrot 
---
 Documentation/devicetree/bindings/media/ti-cal.txt | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Documentation/devicetree/bindings/media/ti-cal.txt 
b/Documentation/devicetree/bindings/media/ti-cal.txt
index d43870a2324b..29fbbfb8be0d 100644
--- a/Documentation/devicetree/bindings/media/ti-cal.txt
+++ b/Documentation/devicetree/bindings/media/ti-cal.txt
@@ -10,6 +10,7 @@ Required properties:
 - compatible:
  Should be "ti,dra72-cal", for DRA72 controllers
  Should be "ti,dra72-pre-es2-cal", for DRA72 controllers pre ES2.0
+ Should be "ti,dra76-cal", for DRA76 controllers
 - reg: CAL Top level, Receiver Core #0, Receiver Core #1 and Camera RX
control address space
 - reg-names: cal_top, cal_rx_core0, cal_rx_core1 and camerrx_control
-- 
2.17.1



[Patch 14/19] media: ti-vpe: cal: Add AM654 support

2019-10-18 Thread Benoit Parrot
Add the needed control module register bit layout to support the AM654
family of devices.

Signed-off-by: Benoit Parrot 
---
 drivers/media/platform/Kconfig  |  2 +-
 drivers/media/platform/ti-vpe/cal.c | 28 +++-
 2 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig
index 997de1a83ff9..24713e79c1ec 100644
--- a/drivers/media/platform/Kconfig
+++ b/drivers/media/platform/Kconfig
@@ -151,7 +151,7 @@ source "drivers/media/platform/sunxi/Kconfig"
 config VIDEO_TI_CAL
tristate "TI CAL (Camera Adaptation Layer) driver"
depends on VIDEO_DEV && VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API
-   depends on SOC_DRA7XX || COMPILE_TEST
+   depends on SOC_DRA7XX || ARCH_K3 || COMPILE_TEST
select VIDEOBUF2_DMA_CONTIG
select V4L2_FWNODE
help
diff --git a/drivers/media/platform/ti-vpe/cal.c 
b/drivers/media/platform/ti-vpe/cal.c
index f590fe712d3d..42b0063b610e 100644
--- a/drivers/media/platform/ti-vpe/cal.c
+++ b/drivers/media/platform/ti-vpe/cal.c
@@ -322,6 +322,26 @@ static struct cal_data dra76x_cal_data = {
.flags = 0,
 };
 
+static struct reg_field am654_ctrl_core_csi0_reg_fields[F_MAX_FIELDS] = {
+   [F_CTRLCLKEN] = REG_FIELD(0, 15, 15),
+   [F_CAMMODE] = REG_FIELD(0, 24, 25),
+   [F_LANEENABLE] = REG_FIELD(0, 0, 4),
+};
+
+static struct cal_csi2_phy am654_cal_csi_phy[] = {
+   {
+   .base_fields = am654_ctrl_core_csi0_reg_fields,
+   .num_lanes = 5,
+   },
+};
+
+static struct cal_data am654_cal_data = {
+   .csi2_phy_core = am654_cal_csi_phy,
+   .num_csi2_phy = ARRAY_SIZE(am654_cal_csi_phy),
+
+   .flags = 0,
+};
+
 /*
  * there is one cal_dev structure in the driver, it is shared by
  * all instances.
@@ -548,7 +568,9 @@ static void camerarx_phy_enable(struct cal_ctx *ctx)
/* Always enable all lanes at the phy control level */
max_lanes = (1 << cal_data_get_phy_max_lanes(ctx)) - 1;
regmap_field_write(phy->fields[F_LANEENABLE], max_lanes);
-   regmap_field_write(phy->fields[F_CSI_MODE], 1);
+   /* F_CSI_MODE is not present on every architecture */
+   if (phy->fields[F_CSI_MODE])
+   regmap_field_write(phy->fields[F_CSI_MODE], 1);
regmap_field_write(phy->fields[F_CTRLCLKEN], 1);
 }
 
@@ -2331,6 +2353,10 @@ static const struct of_device_id cal_of_match[] = {
.compatible = "ti,dra76-cal",
.data = (void *)&dra76x_cal_data,
},
+   {
+   .compatible = "ti,am654-cal",
+   .data = (void *)&am654_cal_data,
+   },
{},
 };
 MODULE_DEVICE_TABLE(of, cal_of_match);
-- 
2.17.1



[Patch 10/19] media: ti-vpe: cal: Align DPHY init sequence with docs

2019-10-18 Thread Benoit Parrot
The current CSI2 DPHY initialization sequence although
functional does not match with the documented sequence
in the Technical Reference Manual.

This may affect capture re-startability in stop/start
situations.

Signed-off-by: Benoit Parrot 
---
 drivers/media/platform/ti-vpe/cal.c | 199 
 1 file changed, 172 insertions(+), 27 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/cal.c 
b/drivers/media/platform/ti-vpe/cal.c
index 3c293e263397..c912ea82b534 100644
--- a/drivers/media/platform/ti-vpe/cal.c
+++ b/drivers/media/platform/ti-vpe/cal.c
@@ -689,29 +689,76 @@ static void disable_irqs(struct cal_ctx *ctx)
reg_write(ctx->dev, CAL_CSI2_VC_IRQENABLE(1), 0);
 }
 
-static void csi2_init(struct cal_ctx *ctx)
+static void csi2_phy_config(struct cal_ctx *ctx);
+
+static void csi2_phy_init(struct cal_ctx *ctx)
 {
int i;
u32 val;
 
+   /* Steps
+*  1. Configure D-PHY mode and enable required lanes
+*  2. Reset complex IO - Wait for completion of reset
+*  Note if the external sensor is not sending byte clock,
+*  the reset will timeout
+*  3 Program Stop States
+*  A. Program THS_TERM, THS_SETTLE, etc... Timings parameters
+*  in terms of DDR clock periods
+*  B. Enable stop state transition timeouts
+*  4.Force FORCERXMODE
+*  D. Enable pull down using pad control
+*  E. Power up PHY
+*  F. Wait for power up completion
+*  G. Wait for all enabled lane to reach stop state
+*  H. Disable pull down using pad control
+*/
+
+   /* 1. Configure D-PHY mode and enable required lanes */
+   camerarx_phy_enable(ctx);
+
+   /* 2. Reset complex IO - Do not wait for reset completion */
+   val = reg_read(ctx->dev, CAL_CSI2_COMPLEXIO_CFG(ctx->csi2_port));
+   set_field(&val, CAL_CSI2_COMPLEXIO_CFG_RESET_CTRL_OPERATIONAL,
+ CAL_CSI2_COMPLEXIO_CFG_RESET_CTRL_MASK);
+   reg_write(ctx->dev, CAL_CSI2_COMPLEXIO_CFG(ctx->csi2_port), val);
+   ctx_dbg(3, ctx, "CAL_CSI2_COMPLEXIO_CFG(%d) = 0x%08x De-assert Complex 
IO Reset\n",
+   ctx->csi2_port,
+   reg_read(ctx->dev, CAL_CSI2_COMPLEXIO_CFG(ctx->csi2_port)));
+
+   /* Dummy read to allow SCP to complete */
+   val = reg_read(ctx->dev, CAL_CSI2_COMPLEXIO_CFG(ctx->csi2_port));
+
+   /* 3.A. Program Phy Timing Parameters */
+   csi2_phy_config(ctx);
+
+   /* 3.B. Program Stop States */
val = reg_read(ctx->dev, CAL_CSI2_TIMING(ctx->csi2_port));
-   set_field(&val, CAL_GEN_ENABLE,
- CAL_CSI2_TIMING_FORCE_RX_MODE_IO1_MASK);
set_field(&val, CAL_GEN_ENABLE,
  CAL_CSI2_TIMING_STOP_STATE_X16_IO1_MASK);
set_field(&val, CAL_GEN_DISABLE,
  CAL_CSI2_TIMING_STOP_STATE_X4_IO1_MASK);
set_field(&val, 407, CAL_CSI2_TIMING_STOP_STATE_COUNTER_IO1_MASK);
reg_write(ctx->dev, CAL_CSI2_TIMING(ctx->csi2_port), val);
-   ctx_dbg(3, ctx, "CAL_CSI2_TIMING(%d) = 0x%08x\n", ctx->csi2_port,
+   ctx_dbg(3, ctx, "CAL_CSI2_TIMING(%d) = 0x%08x Stop States\n",
+   ctx->csi2_port,
+   reg_read(ctx->dev, CAL_CSI2_TIMING(ctx->csi2_port)));
+
+   /* 4. Force FORCERXMODE */
+   val = reg_read(ctx->dev, CAL_CSI2_TIMING(ctx->csi2_port));
+   set_field(&val, CAL_GEN_ENABLE,
+ CAL_CSI2_TIMING_FORCE_RX_MODE_IO1_MASK);
+   reg_write(ctx->dev, CAL_CSI2_TIMING(ctx->csi2_port), val);
+   ctx_dbg(3, ctx, "CAL_CSI2_TIMING(%d) = 0x%08x Force RXMODE\n",
+   ctx->csi2_port,
reg_read(ctx->dev, CAL_CSI2_TIMING(ctx->csi2_port)));
 
+   /* E. Power up the PHY using the complex IO */
val = reg_read(ctx->dev, CAL_CSI2_COMPLEXIO_CFG(ctx->csi2_port));
-   set_field(&val, CAL_CSI2_COMPLEXIO_CFG_RESET_CTRL_OPERATIONAL,
- CAL_CSI2_COMPLEXIO_CFG_RESET_CTRL_MASK);
set_field(&val, CAL_CSI2_COMPLEXIO_CFG_PWR_CMD_STATE_ON,
  CAL_CSI2_COMPLEXIO_CFG_PWR_CMD_MASK);
reg_write(ctx->dev, CAL_CSI2_COMPLEXIO_CFG(ctx->csi2_port), val);
+
+   /* F. Wait for power up completion */
for (i = 0; i < 10; i++) {
if (reg_read_field(ctx->dev,
   CAL_CSI2_COMPLEXIO_CFG(ctx->csi2_port),
@@ -720,18 +767,104 @@ static void csi2_init(struct cal_ctx *ctx)
break;
usleep_range(1000, 1100);
}
-   ctx_dbg(3, ctx, "CAL_CSI2_COMPLEXIO_CFG(%d) = 0x%08x\n", ctx->csi2_port,
-   reg_read(ctx->dev, CAL_CSI2_COMPLEXIO_CFG(ctx->csi2_port)));
+   ctx_dbg(3, ctx, "CAL_CSI2_COMPLEXIO_CFG(%d) = 0x%08x Powered 

[Patch 12/19] media: ti-vpe: cal: Add DRA76x support

2019-10-18 Thread Benoit Parrot
Add the needed control module register bit layout to support
the DRA76x family of devices.

Signed-off-by: Benoit Parrot 
---
 drivers/media/platform/ti-vpe/cal.c | 36 +
 1 file changed, 36 insertions(+)

diff --git a/drivers/media/platform/ti-vpe/cal.c 
b/drivers/media/platform/ti-vpe/cal.c
index c912ea82b534..f590fe712d3d 100644
--- a/drivers/media/platform/ti-vpe/cal.c
+++ b/drivers/media/platform/ti-vpe/cal.c
@@ -290,6 +290,38 @@ static struct cal_data dra72x_es1_cal_data = {
.flags = DRA72_CAL_PRE_ES2_LDO_DISABLE,
 };
 
+static struct reg_field dra76x_ctrl_core_csi0_reg_fields[F_MAX_FIELDS] = {
+   [F_CTRLCLKEN] = REG_FIELD(0, 8, 8),
+   [F_CAMMODE] = REG_FIELD(0, 9, 10),
+   [F_CSI_MODE] = REG_FIELD(0, 11, 11),
+   [F_LANEENABLE] = REG_FIELD(0, 27, 31),
+};
+
+static struct reg_field dra76x_ctrl_core_csi1_reg_fields[F_MAX_FIELDS] = {
+   [F_CTRLCLKEN] = REG_FIELD(0, 0, 0),
+   [F_CAMMODE] = REG_FIELD(0, 1, 2),
+   [F_CSI_MODE] = REG_FIELD(0, 3, 3),
+   [F_LANEENABLE] = REG_FIELD(0, 24, 26),
+};
+
+static struct cal_csi2_phy dra76x_cal_csi_phy[] = {
+   {
+   .base_fields = dra76x_ctrl_core_csi0_reg_fields,
+   .num_lanes = 5,
+   },
+   {
+   .base_fields = dra76x_ctrl_core_csi1_reg_fields,
+   .num_lanes = 3,
+   },
+};
+
+static struct cal_data dra76x_cal_data = {
+   .csi2_phy_core = dra76x_cal_csi_phy,
+   .num_csi2_phy = ARRAY_SIZE(dra76x_cal_csi_phy),
+
+   .flags = 0,
+};
+
 /*
  * there is one cal_dev structure in the driver, it is shared by
  * all instances.
@@ -2295,6 +2327,10 @@ static const struct of_device_id cal_of_match[] = {
.compatible = "ti,dra72-pre-es2-cal",
.data = (void *)&dra72x_es1_cal_data,
},
+   {
+   .compatible = "ti,dra76-cal",
+   .data = (void *)&dra76x_cal_data,
+   },
{},
 };
 MODULE_DEVICE_TABLE(of, cal_of_match);
-- 
2.17.1



[Patch 2/3] ARM: dts: am437x-sk-evm: Add VPFE and OV2659 entries

2019-10-16 Thread Benoit Parrot
Add VPFE device nodes entries.
Add OmniVision OV2659 sensor device nodes and linkage.

The sensor clock (xvclk) is sourced from clkout1.
Add clock entries to properly select clkout1 and set its parent
clock to sys_clkin_ck.

Signed-off-by: Benoit Parrot 
---
 arch/arm/boot/dts/am437x-sk-evm.dts | 27 ++-
 1 file changed, 26 insertions(+), 1 deletion(-)

diff --git a/arch/arm/boot/dts/am437x-sk-evm.dts 
b/arch/arm/boot/dts/am437x-sk-evm.dts
index 74eaa6a3b258..25222497f828 100644
--- a/arch/arm/boot/dts/am437x-sk-evm.dts
+++ b/arch/arm/boot/dts/am437x-sk-evm.dts
@@ -272,6 +272,12 @@
>;
};
 
+   clkout1_pin: pinmux_clkout1_pin {
+   pinctrl-single,pins = <
+   0x270 (PIN_OUTPUT_PULLDOWN | MUX_MODE3) /* 
XDMA_EVENT_INTR0/CLKOUT1 */
+   >;
+   };
+
cpsw_default: cpsw_default {
pinctrl-single,pins = <
/* Slave 1 */
@@ -593,6 +599,25 @@
pinctrl-0 = <&i2c1_pins>;
clock-frequency = <40>;
 
+   ov2659@30 {
+   compatible = "ovti,ov2659";
+   reg = <0x30>;
+   pinctrl-names = "default";
+   pinctrl-0 = <&clkout1_pin>;
+
+   clocks = <&clkout1_mux_ck>;
+   clock-names = "xvclk";
+   assigned-clocks = <&clkout1_mux_ck>;
+   assigned-clock-parents = <&clkout1_osc_div_ck>;
+
+   port {
+   ov2659_1: endpoint {
+   remote-endpoint = <&vpfe0_ep>;
+   link-frequencies = /bits/ 64 <7000>;
+   };
+   };
+   };
+
edt-ft5306@38 {
status = "okay";
compatible = "edt,edt-ft5306", "edt,edt-ft5x06";
@@ -877,7 +902,7 @@
/* Camera port */
port {
vpfe0_ep: endpoint {
-   /* remote-endpoint = <&sensor>; add once we have it */
+   remote-endpoint = <&ov2659_1>;
ti,am437x-vpfe-interface = <0>;
bus-width = <8>;
hsync-active = <0>;
-- 
2.17.1



[Patch 0/3] ARM: dts: am43x-vpfe/ov2659.patch

2019-10-16 Thread Benoit Parrot
This patch series adds the missing camera endpoint (ov2659) as well as
the required source clocks nodes for the sensor.

On the am437x-sk-evm the camera sensor is sourced from clkout1 but that
clock nodes/tree was removed as it was unsed at the time, we are
re-adding the needed clock nodes here.

Benoit Parrot (2):
  ARM: dts: am437x-sk-evm: Add VPFE and OV2659 entries
  ARM: dts: am43x-epos-evm: Add VPFE and OV2659 entries

Tero Kristo (1):
  ARM: dts: am43xx: add support for clkout1 clock

 arch/arm/boot/dts/am437x-sk-evm.dts  | 27 +-
 arch/arm/boot/dts/am43x-epos-evm.dts | 23 +++-
 arch/arm/boot/dts/am43xx-clocks.dtsi | 54 
 3 files changed, 102 insertions(+), 2 deletions(-)

-- 
2.17.1



[Patch 3/3] ARM: dts: am43x-epos-evm: Add VPFE and OV2659 entries

2019-10-16 Thread Benoit Parrot
Add VPFE device nodes entries.
Add OmniVision OV2659 sensor device nodes and linkage.

Since Rev1.2a on this board the sensor source clock (xvclk) has a
dedicated 12Mhz oscillator instead of using clkout1.
Add 'audio_mstrclk' fixed clock object to represent it.

Signed-off-by: Benoit Parrot 
---
 arch/arm/boot/dts/am43x-epos-evm.dts | 23 ++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/arch/arm/boot/dts/am43x-epos-evm.dts 
b/arch/arm/boot/dts/am43x-epos-evm.dts
index 95314121d111..1958d0985f76 100644
--- a/arch/arm/boot/dts/am43x-epos-evm.dts
+++ b/arch/arm/boot/dts/am43x-epos-evm.dts
@@ -145,6 +145,12 @@
system-clock-frequency = <1200>;
};
};
+
+   audio_mstrclk: mclk_osc {
+   compatible = "fixed-clock";
+   #clock-cells = <0>;
+   clock-frequency = <1200>;
+   };
 };
 
 &am43xx_pinmux {
@@ -696,6 +702,21 @@
IOVDD-supply = <&dcdc4>; /* V3_3D -> DCDC4 */
DVDD-supply = <&ldo1>; /* V1_8AUD -> V1_8D -> LDO1 */
};
+
+   ov2659@30 {
+   compatible = "ovti,ov2659";
+   reg = <0x30>;
+
+   clocks = <&audio_mstrclk>;
+   clock-names = "xvclk";
+
+   port {
+   ov2659_1: endpoint {
+   remote-endpoint = <&vpfe1_ep>;
+   link-frequencies = /bits/ 64 <7000>;
+   };
+   };
+   };
 };
 
 &i2c2 {
@@ -962,7 +983,7 @@
 
port {
vpfe1_ep: endpoint {
-   /* remote-endpoint = <&sensor>; add once we have it */
+   remote-endpoint = <&ov2659_1>;
ti,am437x-vpfe-interface = <0>;
bus-width = <8>;
hsync-active = <0>;
-- 
2.17.1



[Patch 1/3] ARM: dts: am43xx: add support for clkout1 clock

2019-10-16 Thread Benoit Parrot
From: Tero Kristo 

clkout1 clock node and its generation tree was missing. Add this based
on the data on TRM and PRCM functional spec.

commit 664ae1ab2536 ("ARM: dts: am43xx: add clkctrl nodes") effectively
reverted this commit 8010f13a40d3 ("ARM: dts: am43xx: add support for
clkout1 clock") which is needed for the ov2659 camera sensor clock
definition hence it is being re-applied here.

Fixes: 664ae1ab2536 ("ARM: dts: am43xx: add clkctrl nodes")
Signed-off-by: Tero Kristo 
Tested-by: Benoit Parrot 
Signed-off-by: Tony Lindgren 
Signed-off-by: Benoit Parrot 
---
 arch/arm/boot/dts/am43xx-clocks.dtsi | 54 
 1 file changed, 54 insertions(+)

diff --git a/arch/arm/boot/dts/am43xx-clocks.dtsi 
b/arch/arm/boot/dts/am43xx-clocks.dtsi
index 091356f2a8c1..944b142dafd2 100644
--- a/arch/arm/boot/dts/am43xx-clocks.dtsi
+++ b/arch/arm/boot/dts/am43xx-clocks.dtsi
@@ -704,6 +704,60 @@
ti,bit-shift = <8>;
reg = <0x2a48>;
};
+
+   clkout1_osc_div_ck: clkout1_osc_div_ck {
+   #clock-cells = <0>;
+   compatible = "ti,divider-clock";
+   clocks = <&sys_clkin_ck>;
+   ti,bit-shift = <20>;
+   ti,max-div = <4>;
+   reg = <0x4100>;
+   };
+
+   clkout1_src2_mux_ck: clkout1_src2_mux_ck {
+   #clock-cells = <0>;
+   compatible = "ti,mux-clock";
+   clocks = <&clk_rc32k_ck>, <&sysclk_div>, <&dpll_ddr_m2_ck>,
+<&dpll_per_m2_ck>, <&dpll_disp_m2_ck>,
+<&dpll_mpu_m2_ck>;
+   reg = <0x4100>;
+   };
+
+   clkout1_src2_pre_div_ck: clkout1_src2_pre_div_ck {
+   #clock-cells = <0>;
+   compatible = "ti,divider-clock";
+   clocks = <&clkout1_src2_mux_ck>;
+   ti,bit-shift = <4>;
+   ti,max-div = <8>;
+   reg = <0x4100>;
+   };
+
+   clkout1_src2_post_div_ck: clkout1_src2_post_div_ck {
+   #clock-cells = <0>;
+   compatible = "ti,divider-clock";
+   clocks = <&clkout1_src2_pre_div_ck>;
+   ti,bit-shift = <8>;
+   ti,max-div = <32>;
+   ti,index-power-of-two;
+   reg = <0x4100>;
+   };
+
+   clkout1_mux_ck: clkout1_mux_ck {
+   #clock-cells = <0>;
+   compatible = "ti,mux-clock";
+   clocks = <&clkout1_osc_div_ck>, <&clk_rc32k_ck>,
+<&clkout1_src2_post_div_ck>, <&dpll_extdev_m2_ck>;
+   ti,bit-shift = <16>;
+   reg = <0x4100>;
+   };
+
+   clkout1_ck: clkout1_ck {
+   #clock-cells = <0>;
+   compatible = "ti,gate-clock";
+   clocks = <&clkout1_mux_ck>;
+   ti,bit-shift = <23>;
+   reg = <0x4100>;
+   };
 };
 
 &prcm {
-- 
2.17.1



Re: [Patch 1/3] dt-bindings: media: ti-vpe: Document VPE driver

2019-10-16 Thread Benoit Parrot
Rob Herring  wrote on Tue [2019-Oct-15 17:29:47 -0500]:
> On Wed, Oct 09, 2019 at 12:56:26PM -0500, Benoit Parrot wrote:
> > Device Tree bindings for the Video Processing Engine (VPE) driver.
> > 
> > Signed-off-by: Benoit Parrot 
> > ---
> >  .../devicetree/bindings/media/ti-vpe.txt  | 48 +++
> >  MAINTAINERS   |  1 +
> >  2 files changed, 49 insertions(+)
> >  create mode 100644 Documentation/devicetree/bindings/media/ti-vpe.txt
> 
> Please convert to DT schema format.

I can do that.
Before posting/merging a .yaml, are we supposed to be able to pass these?
# make dt_binding_check
# make dtbs_check

Because currently with 5.4-rc3 these fails.

Is there a way to run these "test command" target a specific .yaml and not
the whole set?

> 
> > 
> > diff --git a/Documentation/devicetree/bindings/media/ti-vpe.txt 
> > b/Documentation/devicetree/bindings/media/ti-vpe.txt
> > new file mode 100644
> > index ..b2942fa8c3ea
> > --- /dev/null
> > +++ b/Documentation/devicetree/bindings/media/ti-vpe.txt
> > @@ -0,0 +1,48 @@
> > +Texas Instruments DRA7x VIDEO PROCESSING ENGINE (VPE)
> > +--
> > +
> > +The Video Processing Engine (VPE) is a key component for image post
> > +processing applications. VPE consist of a single memory to memory
> > +path which can perform chroma up/down sampling, deinterlacing,
> > +scaling and color space conversion.
> > +
> > +Required properties:
> > +- compatible: must be "ti,vpe"
> 
> Needs to have SoC specific compatibles.

Yes, I'll fix that.

> 
> > +- reg: physical base address and length of the registers set for the 4
> > +   memory regions required;
> > +- reg-names: name associated with the memory regions described is ;
> 
> The names need to be documented.

Ok.

> 
> > +- interrupts: should contain IRQ line for VPE;
> > +
> > +Example:
> > +
> > +   target-module@1d0010 {  /* 0x489d, ap 27 30.0 */
> > +   compatible = "ti,sysc-omap4", "ti,sysc";
> > +   reg = <0x1d0010 0x4>;
> > +   reg-names = "sysc";
> > +   ti,sysc-midle = ,
> > +   ,
> > +   ;
> > +   ti,sysc-sidle = ,
> > +   ,
> > +   ;
> > +   clocks = <&vpe_clkctrl DRA7_VPE_VPE_CLKCTRL 0>;
> > +   clock-names = "fck";
> > +   #address-cells = <1>;
> > +   #size-cells = <1>;
> > +   ranges = <0x0 0x1d 0x1>;
> 
> All this is outside the scope of this binding.

OK I was not sure if the whole interconnect thing was needed in the example
or not.

> 
> > +
> > +   vpe: vpe@0 {
> > +   compatible = "ti,vpe";
> > +   reg = <0x 0x120>,
> > + <0x0700 0x80>,
> > + <0x5700 0x18>,
> > + <0xd000 0x400>;
> > +   reg-names = "vpe_top",
> > +   "sc",
> > +   "csc",
> > +   "vpdma";
> > +   interrupts = ;
> 
> > +   #address-cells = <1>;
> > +   #size-cells = <0>;
> 
> Not documented, nor needed as there are no child nodes.

Yeah, I'll remove that.

> 
> > +   };
> > +   };
> > diff --git a/MAINTAINERS b/MAINTAINERS
> > index 8598f49fa2c8..63dcda51f8ae 100644
> > --- a/MAINTAINERS
> > +++ b/MAINTAINERS
> > @@ -16299,6 +16299,7 @@ W:  http://linuxtv.org/
> >  Q: http://patchwork.linuxtv.org/project/linux-media/list/
> >  S: Maintained
> >  F: drivers/media/platform/ti-vpe/
> > +F: Documentation/devicetree/bindings/media/ti-vpe.txt

Now with the dt_schemas, I noticed that the maintainer's name is part of
the yaml file. Do we still need to add this to the MAINTAINERS file as
well?

Benoit


> >  
> >  TI WILINK WIRELESS DRIVERS
> >  L: linux-wirel...@vger.kernel.org
> > -- 
> > 2.17.1
> > 


Re: [PATCH][next] media: ti-vpe: vpe: use r2y instead of y2r, copy-paste error

2019-10-11 Thread Benoit Parrot
Colin King  wrote on Fri [2019-Oct-11 14:29:40 +0100]:
> From: Colin Ian King 
> 
> There appears to be a copy-paste error on the access of
> csc_coeffs.y2r.r601.full.coeff, I believe csc_coeffs.2yr.r601.full.coeff
> should be used instead. This is a moot point as the code is never
> reached, but at least use the correct structure element.
> 
> Addresses-Coverity: ("Copy-paste error")
> Fixes: 3ff3a712a9ea ("media: ti-vpe: vpe: don't rely on colorspace member for 
> conversion")
> Signed-off-by: Colin Ian King 
> ---
>  drivers/media/platform/ti-vpe/csc.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/media/platform/ti-vpe/csc.c 
> b/drivers/media/platform/ti-vpe/csc.c
> index bd923bee4a31..834114a4eebe 100644
> --- a/drivers/media/platform/ti-vpe/csc.c
> +++ b/drivers/media/platform/ti-vpe/csc.c
> @@ -238,7 +238,7 @@ void csc_set_coeff(struct csc_data *csc, u32 *csc_reg0,
>   coeff = csc_coeffs.r2y.r709.limited.coeff;
>   } else {
>   /* Should never reach this, but it keeps gcc happy */
> - coeff = csc_coeffs.y2r.r601.full.coeff;
> + coeff = csc_coeffs.r2y.r601.full.coeff;
>   }
>   } else {
>   *csc_reg5 |= CSC_BYPASS;

Reviewed-by: Benoit Parrot 

> -- 
> 2.20.1
> 


Re: linux-next: Fixes tag needs some work in the v4l-dvb tree

2019-10-11 Thread Benoit Parrot
Stephen Rothwell  wrote on Fri [2019-Oct-11 07:47:02 
+1100]:
> Hi all,
> 
> In commit
> 
>   e20b248051ca ("media: ti-vpe: vpe: Make sure YUYV is set as default format")
> 
> Fixes tag
> 
>   Fixes: 40cc823f7005 ("media: ti-vpe: Add support for NV21 format")
> 
> has these problem(s):
> 
>   - Target SHA1 does not exist
> 
> Did you mean
> 
> Fixes: b2bb3d822f2c ("media: ti-vpe: Add support for NV21 format")

Ah, yes.
This was obviously missed through the rebase, sorry.

Benoit

> 
> -- 
> Cheers,
> Stephen Rothwell




[Patch 1/3] dt-bindings: media: ti-vpe: Document VPE driver

2019-10-09 Thread Benoit Parrot
Device Tree bindings for the Video Processing Engine (VPE) driver.

Signed-off-by: Benoit Parrot 
---
 .../devicetree/bindings/media/ti-vpe.txt  | 48 +++
 MAINTAINERS   |  1 +
 2 files changed, 49 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/ti-vpe.txt

diff --git a/Documentation/devicetree/bindings/media/ti-vpe.txt 
b/Documentation/devicetree/bindings/media/ti-vpe.txt
new file mode 100644
index ..b2942fa8c3ea
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/ti-vpe.txt
@@ -0,0 +1,48 @@
+Texas Instruments DRA7x VIDEO PROCESSING ENGINE (VPE)
+--
+
+The Video Processing Engine (VPE) is a key component for image post
+processing applications. VPE consist of a single memory to memory
+path which can perform chroma up/down sampling, deinterlacing,
+scaling and color space conversion.
+
+Required properties:
+- compatible: must be "ti,vpe"
+- reg: physical base address and length of the registers set for the 4
+   memory regions required;
+- reg-names: name associated with the memory regions described is ;
+- interrupts: should contain IRQ line for VPE;
+
+Example:
+
+   target-module@1d0010 {  /* 0x489d, ap 27 30.0 */
+   compatible = "ti,sysc-omap4", "ti,sysc";
+   reg = <0x1d0010 0x4>;
+   reg-names = "sysc";
+   ti,sysc-midle = ,
+   ,
+   ;
+   ti,sysc-sidle = ,
+   ,
+   ;
+   clocks = <&vpe_clkctrl DRA7_VPE_VPE_CLKCTRL 0>;
+   clock-names = "fck";
+   #address-cells = <1>;
+   #size-cells = <1>;
+   ranges = <0x0 0x1d 0x1>;
+
+   vpe: vpe@0 {
+   compatible = "ti,vpe";
+   reg = <0x 0x120>,
+ <0x0700 0x80>,
+ <0x5700 0x18>,
+ <0xd000 0x400>;
+   reg-names = "vpe_top",
+   "sc",
+   "csc",
+   "vpdma";
+   interrupts = ;
+   #address-cells = <1>;
+   #size-cells = <0>;
+   };
+   };
diff --git a/MAINTAINERS b/MAINTAINERS
index 8598f49fa2c8..63dcda51f8ae 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -16299,6 +16299,7 @@ W:  http://linuxtv.org/
 Q: http://patchwork.linuxtv.org/project/linux-media/list/
 S: Maintained
 F: drivers/media/platform/ti-vpe/
+F: Documentation/devicetree/bindings/media/ti-vpe.txt
 
 TI WILINK WIRELESS DRIVERS
 L: linux-wirel...@vger.kernel.org
-- 
2.17.1



[Patch 0/3] ARM: dts: dra7: add vpe nodes

2019-10-09 Thread Benoit Parrot
This patch series adds the needed clkctrl and ty-sysc nodes for VPE module.
We also document the VPE DT bindings.

Benoit Parrot (3):
  dt-bindings: media: ti-vpe: Document VPE driver
  ARM: dts: dra7: add vpe clkctrl node
  ARM: dts: dra7: Add ti-sysc node for VPE

 .../devicetree/bindings/media/ti-vpe.txt  | 48 +++
 MAINTAINERS   |  1 +
 arch/arm/boot/dts/dra7-l4.dtsi| 30 ++--
 arch/arm/boot/dts/dra7xx-clocks.dtsi  | 18 ++-
 drivers/clk/ti/clk-7xx.c  |  6 +++
 include/dt-bindings/clock/dra7.h  | 10 
 6 files changed, 108 insertions(+), 5 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/media/ti-vpe.txt

-- 
2.17.1



[Patch 2/3] ARM: dts: dra7: add vpe clkctrl node

2019-10-09 Thread Benoit Parrot
Add clkctrl nodes for VPE module.

Signed-off-by: Benoit Parrot 
---
 arch/arm/boot/dts/dra7xx-clocks.dtsi | 18 --
 drivers/clk/ti/clk-7xx.c |  6 ++
 include/dt-bindings/clock/dra7.h | 10 ++
 3 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/arch/arm/boot/dts/dra7xx-clocks.dtsi 
b/arch/arm/boot/dts/dra7xx-clocks.dtsi
index 93e1eb83bed9..d1c2406ec71c 100644
--- a/arch/arm/boot/dts/dra7xx-clocks.dtsi
+++ b/arch/arm/boot/dts/dra7xx-clocks.dtsi
@@ -1591,10 +1591,10 @@
 
rtc_cm: rtc-cm@700 {
compatible = "ti,omap4-cm";
-   reg = <0x700 0x100>;
+   reg = <0x700 0x60>;
#address-cells = <1>;
#size-cells = <1>;
-   ranges = <0 0x700 0x100>;
+   ranges = <0 0x700 0x60>;
 
rtc_clkctrl: rtc-clkctrl@20 {
compatible = "ti,clkctrl";
@@ -1603,6 +1603,20 @@
};
};
 
+   vpe_cm: vpe-cm@760 {
+   compatible = "ti,omap4-cm";
+   reg = <0x760 0xc>;
+   #address-cells = <1>;
+   #size-cells = <1>;
+   ranges = <0 0x760 0xc>;
+
+   vpe_clkctrl: vpe-clkctrl@0 {
+   compatible = "ti,clkctrl";
+   reg = <0x0 0xc>;
+   #clock-cells = <2>;
+   };
+   };
+
 };
 
 &cm_core {
diff --git a/drivers/clk/ti/clk-7xx.c b/drivers/clk/ti/clk-7xx.c
index b57fe09b428b..5dd9cad07542 100644
--- a/drivers/clk/ti/clk-7xx.c
+++ b/drivers/clk/ti/clk-7xx.c
@@ -146,6 +146,11 @@ static const struct omap_clkctrl_reg_data 
dra7_rtc_clkctrl_regs[] __initconst =
{ 0 },
 };
 
+static const struct omap_clkctrl_reg_data dra7_vpe_clkctrl_regs[] __initconst 
= {
+   { DRA7_VPE_VPE_CLKCTRL, NULL, CLKF_HW_SUP, "dpll_core_h23x2_ck" },
+   { 0 },
+};
+
 static const struct omap_clkctrl_reg_data dra7_coreaon_clkctrl_regs[] 
__initconst = {
{ DRA7_COREAON_SMARTREFLEX_MPU_CLKCTRL, NULL, CLKF_SW_SUP, 
"wkupaon_iclk_mux" },
{ DRA7_COREAON_SMARTREFLEX_CORE_CLKCTRL, NULL, CLKF_SW_SUP, 
"wkupaon_iclk_mux" },
@@ -769,6 +774,7 @@ const struct omap_clkctrl_data dra7_clkctrl_data[] 
__initconst = {
{ 0x4a005550, dra7_ipu_clkctrl_regs },
{ 0x4a005620, dra7_dsp2_clkctrl_regs },
{ 0x4a005720, dra7_rtc_clkctrl_regs },
+   { 0x4a005760, dra7_vpe_clkctrl_regs },
{ 0x4a008620, dra7_coreaon_clkctrl_regs },
{ 0x4a008720, dra7_l3main1_clkctrl_regs },
{ 0x4a008920, dra7_ipu2_clkctrl_regs },
diff --git a/include/dt-bindings/clock/dra7.h b/include/dt-bindings/clock/dra7.h
index 72f2e8411523..2b765e579b2a 100644
--- a/include/dt-bindings/clock/dra7.h
+++ b/include/dt-bindings/clock/dra7.h
@@ -29,6 +29,11 @@
 #define DRA7_RTC_CLKCTRL_INDEX(offset) ((offset) - DRA7_RTC_CLKCTRL_OFFSET)
 #define DRA7_RTCSS_CLKCTRL DRA7_RTC_CLKCTRL_INDEX(0x44)
 
+/* vpe clocks */
+#define DRA7_VPE_CLKCTRL_OFFSET0x60
+#define DRA7_VPE_CLKCTRL_INDEX(offset) ((offset) - DRA7_VPE_CLKCTRL_OFFSET)
+#define DRA7_VPE_CLKCTRL   DRA7_VPE_CLKCTRL_INDEX(0x64)
+
 /* coreaon clocks */
 #define DRA7_SMARTREFLEX_MPU_CLKCTRL   DRA7_CLKCTRL_INDEX(0x28)
 #define DRA7_SMARTREFLEX_CORE_CLKCTRL  DRA7_CLKCTRL_INDEX(0x38)
@@ -192,6 +197,11 @@
 /* rtc clocks */
 #define DRA7_RTC_RTCSS_CLKCTRL DRA7_CLKCTRL_INDEX(0x44)
 
+/* vpe clocks */
+#define DRA7_VPE_CLKCTRL_OFFSET0x60
+#define DRA7_VPE_CLKCTRL_INDEX(offset) ((offset) - DRA7_VPE_CLKCTRL_OFFSET)
+#define DRA7_VPE_VPE_CLKCTRL   DRA7_VPE_CLKCTRL_INDEX(0x64)
+
 /* coreaon clocks */
 #define DRA7_COREAON_SMARTREFLEX_MPU_CLKCTRL   DRA7_CLKCTRL_INDEX(0x28)
 #define DRA7_COREAON_SMARTREFLEX_CORE_CLKCTRL  DRA7_CLKCTRL_INDEX(0x38)
-- 
2.17.1



[Patch 3/3] ARM: dts: dra7: Add ti-sysc node for VPE

2019-10-09 Thread Benoit Parrot
Add VPE node as a child of l4 interconnect in order for it to probe
using ti-sysc.

Signed-off-by: Benoit Parrot 
---
 arch/arm/boot/dts/dra7-l4.dtsi | 30 +++---
 1 file changed, 27 insertions(+), 3 deletions(-)

diff --git a/arch/arm/boot/dts/dra7-l4.dtsi b/arch/arm/boot/dts/dra7-l4.dtsi
index ea0e7c19eb4e..d876c1754f33 100644
--- a/arch/arm/boot/dts/dra7-l4.dtsi
+++ b/arch/arm/boot/dts/dra7-l4.dtsi
@@ -4158,12 +4158,36 @@
ranges = <0x0 0x1b 0x1>;
};
 
-   target-module@1d {  /* 0x489d, ap 27 
30.0 */
-   compatible = "ti,sysc";
-   status = "disabled";
+   target-module@1d0010 {  /* 0x489d, ap 27 
30.0 */
+   compatible = "ti,sysc-omap4", "ti,sysc";
+   reg = <0x1d0010 0x4>;
+   reg-names = "sysc";
+   ti,sysc-midle = ,
+   ,
+   ;
+   ti,sysc-sidle = ,
+   ,
+   ;
+   clocks = <&vpe_clkctrl DRA7_VPE_VPE_CLKCTRL 0>;
+   clock-names = "fck";
#address-cells = <1>;
#size-cells = <1>;
ranges = <0x0 0x1d 0x1>;
+
+   vpe: vpe@0 {
+   compatible = "ti,vpe";
+   reg = <0x 0x120>,
+ <0x0700 0x80>,
+ <0x5700 0x18>,
+ <0xd000 0x400>;
+   reg-names = "vpe_top",
+   "sc",
+   "csc",
+   "vpdma";
+   interrupts = ;
+   #address-cells = <1>;
+   #size-cells = <0>;
+   };
};
};
 };
-- 
2.17.1



[Patch v4 2/3] media: ov5640: Fix 1920x1080 mode to remove extra enable/disable

2019-10-09 Thread Benoit Parrot
In the 1920x1080 register array an extra pair of reset ctrl disable
re-enable was causing unwanted init delays.

Signed-off-by: Benoit Parrot 
Reviewed-by: Jacopo Mondi 
---
 drivers/media/i2c/ov5640.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/media/i2c/ov5640.c b/drivers/media/i2c/ov5640.c
index b93b61baace5..065c9b61ecbd 100644
--- a/drivers/media/i2c/ov5640.c
+++ b/drivers/media/i2c/ov5640.c
@@ -490,7 +490,6 @@ static const struct reg_value 
ov5640_setting_720P_1280_720[] = {
 };
 
 static const struct reg_value ov5640_setting_1080P_1920_1080[] = {
-   {0x3008, 0x42, 0, 0},
{0x3c07, 0x08, 0, 0},
{0x3c09, 0x1c, 0, 0}, {0x3c0a, 0x9c, 0, 0}, {0x3c0b, 0x40, 0, 0},
{0x3814, 0x11, 0, 0},
@@ -518,7 +517,7 @@ static const struct reg_value 
ov5640_setting_1080P_1920_1080[] = {
{0x3a0e, 0x03, 0, 0}, {0x3a0d, 0x04, 0, 0}, {0x3a14, 0x04, 0, 0},
{0x3a15, 0x60, 0, 0}, {0x4407, 0x04, 0, 0},
{0x460b, 0x37, 0, 0}, {0x460c, 0x20, 0, 0}, {0x3824, 0x04, 0, 0},
-   {0x4005, 0x1a, 0, 0}, {0x3008, 0x02, 0, 0},
+   {0x4005, 0x1a, 0, 0},
 };
 
 static const struct reg_value ov5640_setting_QSXGA_2592_1944[] = {
-- 
2.17.1



[Patch v4 3/3] media: ov5640: Make 2592x1944 mode only available at 15 fps

2019-10-09 Thread Benoit Parrot
The sensor data sheet clearly state that 2592x1944 only works at 15 fps
make sure we don't try to miss configure the pll out of acceptable
range.

Signed-off-by: Benoit Parrot 
Reviewed-by: Jacopo Mondi 
---
 drivers/media/i2c/ov5640.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/drivers/media/i2c/ov5640.c b/drivers/media/i2c/ov5640.c
index 065c9b61ecbd..5e495c833d32 100644
--- a/drivers/media/i2c/ov5640.c
+++ b/drivers/media/i2c/ov5640.c
@@ -1611,6 +1611,11 @@ ov5640_find_mode(struct ov5640_dev *sensor, enum 
ov5640_frame_rate fr,
!(mode->hact == 640 && mode->vact == 480))
return NULL;
 
+   /* 2592x1944 only works at 15fps max */
+   if ((mode->hact == 2592 && mode->vact == 1944) &&
+   fr > OV5640_15_FPS)
+   return NULL;
+
return mode;
 }
 
-- 
2.17.1



[Patch v4 1/3] media: ov5640: add PIXEL_RATE control

2019-10-09 Thread Benoit Parrot
Add v4l2 controls to report the pixel rates of each mode. This is
needed by some CSI2 receiver in order to perform proper DPHY
configuration.

Signed-off-by: Benoit Parrot 
---
 drivers/media/i2c/ov5640.c | 25 +++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/drivers/media/i2c/ov5640.c b/drivers/media/i2c/ov5640.c
index 500d9bbff10b..b93b61baace5 100644
--- a/drivers/media/i2c/ov5640.c
+++ b/drivers/media/i2c/ov5640.c
@@ -193,6 +193,7 @@ struct ov5640_mode_info {
 
 struct ov5640_ctrls {
struct v4l2_ctrl_handler handler;
+   struct v4l2_ctrl *pixel_rate;
struct {
struct v4l2_ctrl *auto_exp;
struct v4l2_ctrl *exposure;
@@ -1614,6 +1615,16 @@ ov5640_find_mode(struct ov5640_dev *sensor, enum 
ov5640_frame_rate fr,
return mode;
 }
 
+static u64 ov5640_calc_pixel_rate(struct ov5640_dev *sensor)
+{
+   u64 rate;
+
+   rate = sensor->current_mode->vtot * sensor->current_mode->htot;
+   rate *= ov5640_framerates[sensor->current_fr];
+
+   return rate;
+}
+
 /*
  * sensor changes between scaling and subsampling, go through
  * exposure calculation
@@ -1818,8 +1829,7 @@ static int ov5640_set_mode(struct ov5640_dev *sensor)
 * All the formats we support have 16 bits per pixel, seems to require
 * the same rate than YUV, so we can just use 16 bpp all the time.
 */
-   rate = mode->vtot * mode->htot * 16;
-   rate *= ov5640_framerates[sensor->current_fr];
+   rate = ov5640_calc_pixel_rate(sensor) * 16;
if (sensor->ep.bus_type == V4L2_MBUS_CSI2_DPHY) {
rate = rate / sensor->ep.bus.mipi_csi2.num_data_lanes;
ret = ov5640_set_mipi_pclk(sensor, rate);
@@ -2233,6 +2243,8 @@ static int ov5640_set_fmt(struct v4l2_subdev *sd,
if (mbus_fmt->code != sensor->fmt.code)
sensor->pending_fmt_change = true;
 
+   __v4l2_ctrl_s_ctrl_int64(sensor->ctrls.pixel_rate,
+ov5640_calc_pixel_rate(sensor));
 out:
mutex_unlock(&sensor->lock);
return ret;
@@ -2657,6 +2669,11 @@ static int ov5640_init_controls(struct ov5640_dev 
*sensor)
/* we can use our own mutex for the ctrl lock */
hdl->lock = &sensor->lock;
 
+   /* Clock related controls */
+   ctrls->pixel_rate = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_PIXEL_RATE,
+ 0, INT_MAX, 1,
+ ov5640_calc_pixel_rate(sensor));
+
/* Auto/manual white balance */
ctrls->auto_wb = v4l2_ctrl_new_std(hdl, ops,
   V4L2_CID_AUTO_WHITE_BALANCE,
@@ -2704,6 +2721,7 @@ static int ov5640_init_controls(struct ov5640_dev *sensor)
goto free_ctrls;
}
 
+   ctrls->pixel_rate->flags |= V4L2_CTRL_FLAG_READ_ONLY;
ctrls->gain->flags |= V4L2_CTRL_FLAG_VOLATILE;
ctrls->exposure->flags |= V4L2_CTRL_FLAG_VOLATILE;
 
@@ -2816,6 +2834,9 @@ static int ov5640_s_frame_interval(struct v4l2_subdev *sd,
sensor->frame_interval = fi->interval;
sensor->current_mode = mode;
sensor->pending_mode_change = true;
+
+   __v4l2_ctrl_s_ctrl_int64(sensor->ctrls.pixel_rate,
+ov5640_calc_pixel_rate(sensor));
}
 out:
mutex_unlock(&sensor->lock);
-- 
2.17.1



[Patch v4 0/3] media: ov5640: updates

2019-10-09 Thread Benoit Parrot
This patch series is a collection of patches we have been carrying for a
while.

First, it adds support for PIXEL_RATE control which is used by some
CSI2 receiver driver to properly set-up their DPHY.

Then we fix an issue related to having extra sensor enable/disable in
the register array for the 1920x1080 mode.

Finally we restrict the largest resolution which should only be
available at the lowest FPS.

Changes since v3:
- Fix a potential early pointer dereference in init_controls.
  Reported by Sakari.

Changes since v2:
- Addressed comment from Sakari and Jacopo.
- Make use of the calc_pixel_rate in set_mode also
- Cleaned up the pixel_rate ctrl struct
- Fix the fps condition checking for the max resolution case

Changes since v1:
- Addressed comment from Sakari.
  added a function to calculate the pixel rate and remove the need to
  cache its value


Benoit Parrot (3):
  media: ov5640: add PIXEL_RATE control
  media: ov5640: Fix 1920x1080 mode to remove extra enable/disable
  media: ov5640: Make 2592x1944 mode only available at 15 fps

 drivers/media/i2c/ov5640.c | 33 +
 1 file changed, 29 insertions(+), 4 deletions(-)

-- 
2.17.1



Re: [Patch v3 1/3] media: ov5640: add PIXEL_RATE control

2019-10-07 Thread Benoit Parrot
Sakari Ailus  wrote on Mon [2019-Oct-07 11:03:20 
+0300]:
> On Fri, Oct 04, 2019 at 12:24:16PM -0500, Benoit Parrot wrote:
> > @@ -2657,6 +2669,12 @@ static int ov5640_init_controls(struct ov5640_dev 
> > *sensor)
> > /* we can use our own mutex for the ctrl lock */
> > hdl->lock = &sensor->lock;
> >  
> > +   /* Clock related controls */
> > +   ctrls->pixel_rate = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_PIXEL_RATE,
> > + 0, INT_MAX, 1,
> > + ov5640_calc_pixel_rate(sensor));
> > +   ctrls->pixel_rate->flags |= V4L2_CTRL_FLAG_READ_ONLY;
> 
> Please check ctrls->pixel_rate first; it may be NULL here.

How about I just move this line below "if (hdl->error)" instead?

Benoit
> 
> > +
> > /* Auto/manual white balance */
> > ctrls->auto_wb = v4l2_ctrl_new_std(hdl, ops,
> >V4L2_CID_AUTO_WHITE_BALANCE,
> 
> -- 
> Sakari Ailus
> sakari.ai...@linux.intel.com


[Patch v3 01/21] media: ti-vpe: Fix a parallel build issue

2019-10-07 Thread Benoit Parrot
When TI CAL was introduce as another driver under platform/ti-vpe
adding a second entry into the ti-vpe directory in the platform
Makefile caused issues during parallel build.

Signed-off-by: Benoit Parrot 
Signed-off-by: Jyri Sarha 
---
 drivers/media/platform/Makefile | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/media/platform/Makefile b/drivers/media/platform/Makefile
index 6ee7eb0d36f4..d13db96e3015 100644
--- a/drivers/media/platform/Makefile
+++ b/drivers/media/platform/Makefile
@@ -19,9 +19,7 @@ obj-$(CONFIG_VIDEO_VIVID) += vivid/
 obj-$(CONFIG_VIDEO_VIM2M)  += vim2m.o
 obj-$(CONFIG_VIDEO_VICODEC)+= vicodec/
 
-obj-$(CONFIG_VIDEO_TI_VPE) += ti-vpe/
-
-obj-$(CONFIG_VIDEO_TI_CAL) += ti-vpe/
+obj-y  += ti-vpe/
 
 obj-$(CONFIG_VIDEO_MX2_EMMAPRP)+= mx2_emmaprp.o
 obj-$(CONFIG_VIDEO_CODA)   += coda/
-- 
2.17.1



[Patch v3 04/21] media: ti-vpe: vpe: Remove unnecessary use of container_of

2019-10-07 Thread Benoit Parrot
Instead of saving a pointer to the 'fh' member of struct vpe_ctx to
later have to use container_of to retrieve the actual pointer to the
context structure, which seems to confuse static code analysis tool
anyways, just save the pointer to the actual structure and then retrieve
it directly.

Signed-off-by: Benoit Parrot 
---
 drivers/media/platform/ti-vpe/vpe.c | 22 +++---
 1 file changed, 7 insertions(+), 15 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/vpe.c 
b/drivers/media/platform/ti-vpe/vpe.c
index 56f60dbea15c..0e9cb0319a92 100644
--- a/drivers/media/platform/ti-vpe/vpe.c
+++ b/drivers/media/platform/ti-vpe/vpe.c
@@ -900,14 +900,6 @@ static int set_srcdst_params(struct vpe_ctx *ctx)
return 0;
 }
 
-/*
- * Return the vpe_ctx structure for a given struct file
- */
-static struct vpe_ctx *file2ctx(struct file *file)
-{
-   return container_of(file->private_data, struct vpe_ctx, fh);
-}
-
 /*
  * mem2mem callbacks
  */
@@ -1527,7 +1519,7 @@ static int vpe_enum_fmt(struct file *file, void *priv,
 static int vpe_g_fmt(struct file *file, void *priv, struct v4l2_format *f)
 {
struct v4l2_pix_format_mplane *pix = &f->fmt.pix_mp;
-   struct vpe_ctx *ctx = file2ctx(file);
+   struct vpe_ctx *ctx = file->private_data;
struct vb2_queue *vq;
struct vpe_q_data *q_data;
int i;
@@ -1689,7 +1681,7 @@ static int __vpe_try_fmt(struct vpe_ctx *ctx, struct 
v4l2_format *f,
 
 static int vpe_try_fmt(struct file *file, void *priv, struct v4l2_format *f)
 {
-   struct vpe_ctx *ctx = file2ctx(file);
+   struct vpe_ctx *ctx = file->private_data;
struct vpe_fmt *fmt = find_format(f);
 
if (V4L2_TYPE_IS_OUTPUT(f->type))
@@ -1762,7 +1754,7 @@ static int __vpe_s_fmt(struct vpe_ctx *ctx, struct 
v4l2_format *f)
 static int vpe_s_fmt(struct file *file, void *priv, struct v4l2_format *f)
 {
int ret;
-   struct vpe_ctx *ctx = file2ctx(file);
+   struct vpe_ctx *ctx = file->private_data;
 
ret = vpe_try_fmt(file, priv, f);
if (ret)
@@ -1847,7 +1839,7 @@ static int __vpe_try_selection(struct vpe_ctx *ctx, 
struct v4l2_selection *s)
 static int vpe_g_selection(struct file *file, void *fh,
struct v4l2_selection *s)
 {
-   struct vpe_ctx *ctx = file2ctx(file);
+   struct vpe_ctx *ctx = file->private_data;
struct vpe_q_data *q_data;
bool use_c_rect = false;
 
@@ -1908,7 +1900,7 @@ static int vpe_g_selection(struct file *file, void *fh,
 static int vpe_s_selection(struct file *file, void *fh,
struct v4l2_selection *s)
 {
-   struct vpe_ctx *ctx = file2ctx(file);
+   struct vpe_ctx *ctx = file->private_data;
struct vpe_q_data *q_data;
struct v4l2_selection sel = *s;
int ret;
@@ -2275,7 +2267,7 @@ static int vpe_open(struct file *file)
init_adb_hdrs(ctx);
 
v4l2_fh_init(&ctx->fh, video_devdata(file));
-   file->private_data = &ctx->fh;
+   file->private_data = ctx;
 
hdl = &ctx->hdl;
v4l2_ctrl_handler_init(hdl, 1);
@@ -2360,7 +2352,7 @@ static int vpe_open(struct file *file)
 static int vpe_release(struct file *file)
 {
struct vpe_dev *dev = video_drvdata(file);
-   struct vpe_ctx *ctx = file2ctx(file);
+   struct vpe_ctx *ctx = file->private_data;
 
vpe_dbg(dev, "releasing instance %p\n", ctx);
 
-- 
2.17.1



[Patch v3 05/21] media: ti-vpe: Add support for SEQ_BT

2019-10-07 Thread Benoit Parrot
From: Nikhil Devshatwar 

SEQ_BT indicates the buffer for bottom field needs to be processed
before the top field.

Simplify the field selection logic to support SEQ_BT as well.

Modify the interlace flags to include any of alternate, SEQ_TB, SEQ_BT.
Update other format error checking to consider SEQ_BT.
Replace SEQ_TB with SEQ_XX wherever applicable.

Signed-off-by: Nikhil Devshatwar 
Signed-off-by: Benoit Parrot 
---
 drivers/media/platform/ti-vpe/vpe.c | 73 ++---
 1 file changed, 46 insertions(+), 27 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/vpe.c 
b/drivers/media/platform/ti-vpe/vpe.c
index 0e9cb0319a92..5d0ec5f7ca25 100644
--- a/drivers/media/platform/ti-vpe/vpe.c
+++ b/drivers/media/platform/ti-vpe/vpe.c
@@ -328,9 +328,14 @@ struct vpe_q_data {
 #defineQ_DATA_MODE_TILED   BIT(1)
 #defineQ_DATA_INTERLACED_ALTERNATE BIT(2)
 #defineQ_DATA_INTERLACED_SEQ_TBBIT(3)
+#defineQ_DATA_INTERLACED_SEQ_BTBIT(4)
+
+#define Q_IS_SEQ_XX(Q_DATA_INTERLACED_SEQ_TB | \
+   Q_DATA_INTERLACED_SEQ_BT)
 
 #define Q_IS_INTERLACED(Q_DATA_INTERLACED_ALTERNATE | \
-   Q_DATA_INTERLACED_SEQ_TB)
+   Q_DATA_INTERLACED_SEQ_TB | \
+   Q_DATA_INTERLACED_SEQ_BT)
 
 enum {
Q_DATA_SRC = 0,
@@ -1105,24 +1110,31 @@ static void add_in_dtd(struct vpe_ctx *ctx, int port)
dma_addr += offset;
stride = q_data->bytesperline[VPE_LUMA];
 
-   if (q_data->flags & Q_DATA_INTERLACED_SEQ_TB) {
-   /*
-* Use top or bottom field from same vb alternately
-* f,f-1,f-2 = TBT when seq is even
-* f,f-1,f-2 = BTB when seq is odd
-*/
-   field = (p_data->vb_index + (ctx->sequence % 2)) % 2;
+   /*
+* field used in VPDMA desc  = 0 (top) / 1 (bottom)
+* Use top or bottom field from same vb alternately
+* For each de-interlacing operation, f,f-1,f-2 should be one
+* of TBT or BTB
+*/
+   if (q_data->flags & Q_DATA_INTERLACED_SEQ_TB ||
+   q_data->flags & Q_DATA_INTERLACED_SEQ_BT) {
+   /* Select initial value based on format */
+   if (q_data->flags & Q_DATA_INTERLACED_SEQ_BT)
+   field = 1;
+   else
+   field = 0;
+
+   /* Toggle for each vb_index and each operation */
+   field = (field + p_data->vb_index + ctx->sequence) % 2;
 
if (field) {
-   /*
-* bottom field of a SEQ_TB buffer
-* Skip the top field data by
-*/
int height = q_data->height / 2;
int bpp = fmt->fourcc == V4L2_PIX_FMT_NV12 ?
1 : (vpdma_fmt->depth >> 3);
+
if (plane)
height /= 2;
+
dma_addr += q_data->width * height * bpp;
}
}
@@ -1177,12 +1189,14 @@ static void device_run(void *priv)
struct vpe_q_data *d_q_data = &ctx->q_data[Q_DATA_DST];
struct vpe_q_data *s_q_data = &ctx->q_data[Q_DATA_SRC];
 
-   if (ctx->deinterlacing && s_q_data->flags & Q_DATA_INTERLACED_SEQ_TB &&
-   ctx->sequence % 2 == 0) {
-   /* When using SEQ_TB buffers, When using it first time,
-* No need to remove the buffer as the next field is present
-* in the same buffer. (so that job_ready won't fail)
-* It will be removed when using bottom field
+   if (ctx->deinterlacing && s_q_data->flags & Q_IS_SEQ_XX &&
+   ctx->sequence % 2 == 0) {
+   /* When using SEQ_XX type buffers, each buffer has two fields
+* each buffer has two fields (top & bottom)
+* Removing one buffer is actually getting two fields
+* Alternate between two operations:-
+* Even : consume one field but DO NOT REMOVE from queue
+* Odd : consume other field and REMOVE from queue
 */
ctx->src_vbs[0] = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx);
WARN_ON(ctx->src_vbs[0] == NULL);
@@ -1573,8 +1587,10 @@ static int __vpe_try_fmt(struct vpe_ctx *ctx, struct 
v4l2_format *f,
  

[Patch v3 00/21] media: vpe: maintenance

2019-10-07 Thread Benoit Parrot
This a collection of backlog patches I have been carrying for the VPE
driver.

It adds supports for SEQ_BT as well as NV21.
And fixes a number of issues both through v4l2-compliance and normal
usage.

Changes since v2:
- Fix a type causing a compile error
- Address Hans' comment on the v4l2_common patches
- Rework patch 16 a bit to limit the expanded use of fmt.pix_mp and use
  a local pointer whenever possible.
- Reworked csc_set_coeff() to use the updated format_info helper and
  also to properly handle the v4l2_format type passed as arguments

Changes since v1:
- Added a missing from my first set fixing a Makefile issue
- Added a csc table fix to match the technical specification
- Base on Hans' comment I reworked the last two patches which
  yielded one more patch
- This also led me to create additional patches to the
  v4l2_format_info table to simplify pixel encoding lookup

==
v4l2-compliance SHA: 5b168dc8473911227890526bad26553d9e8ff81b, 32 bits

Compliance test for vpe device /dev/video0:

Driver Info:
Driver name  : vpe
Card type: vpe
Bus info : platform:vpe
Driver version   : 5.4.0
Capabilities : 0x84204000
Video Memory-to-Memory Multiplanar
Streaming
Extended Pix Format
Device Capabilities
Device Caps  : 0x04204000
Video Memory-to-Memory Multiplanar
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 (Not Supported)
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: 1 Private Controls: 1

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
test Composing: OK
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:
warn: v4l2-test-buffers.cpp(683): VIDIOC_CREATE_BUFS not 
supported
warn: v4l2-test-buffers.cpp(683): VIDIOC_CREATE_BUFS not 
supported
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK
test VIDIOC_EXPBUF: OK
test Requests: OK (Not Supported)

Test input 0:

Streaming ioctls:
test read/write: OK (Not Supported)
test blocking wait: OK
Video Capture Multiplanar: Captured 58 buffers
test MMAP (no poll): OK
Video Capture Multiplanar: Captured 58 buffers
test MMAP (select): OK
Video Capture Multiplanar: Captured 58 buffers
test MMAP (epoll): OK
test USERPTR (no poll): OK (Not Supported)
test USERPTR (select): OK (Not Supported)
test DMABUF: Cannot test, specify --expbuf-device

Total for vpe device /dev/video0: 51, Succeeded: 51, Failed: 0, Warnings: 2
======

Benoit Parrot (18):
  media: ti-vpe: Fix a parallel build issue
  media: ti-vpe: vpe: Fix Motion Vector vpdma stride
  media: ti-vpe: vpe: Add missing null pointer checks
  media: ti-vpe: vpe: Remove unnecessary use of container_of
  media: t

[Patch v3 10/21] media: ti-vpe: vpe: Make sure YUYV is set as default format

2019-10-07 Thread Benoit Parrot
v4l2-compliance fails with this message:

   fail: v4l2-test-formats.cpp(672): \
Video Capture Multiplanar: TRY_FMT(G_FMT) != G_FMT
   fail: v4l2-test-formats.cpp(672): \
Video Output Multiplanar: TRY_FMT(G_FMT) != G_FMT
...
   test VIDIOC_TRY_FMT: FAIL

Fixes: 94ed726e8e01 ("media: ti-vpe: Add support for NV21 format")

The default pixel format was setup as pointing to a specific offset in
the vpe_formats table assuming it was pointing to the V4L2_PIX_FMT_YUYV
entry. This became false after the addition on the NV21 format (see
above commid-id)

So instead of hard-coding an offset which might change over time we need
to use a lookup helper instead so we know the default will always be what
we intended.

Signed-off-by: Benoit Parrot 
Reviewed-by: Tomi Valkeinen 
---
 drivers/media/platform/ti-vpe/vpe.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/platform/ti-vpe/vpe.c 
b/drivers/media/platform/ti-vpe/vpe.c
index d3f1ae8b72fa..7aa83026fb6c 100644
--- a/drivers/media/platform/ti-vpe/vpe.c
+++ b/drivers/media/platform/ti-vpe/vpe.c
@@ -2321,7 +2321,7 @@ static int vpe_open(struct file *file)
v4l2_ctrl_handler_setup(hdl);
 
s_q_data = &ctx->q_data[Q_DATA_SRC];
-   s_q_data->fmt = &vpe_formats[2];
+   s_q_data->fmt = __find_format(V4L2_PIX_FMT_YUYV);
s_q_data->width = 1920;
s_q_data->height = 1080;
s_q_data->nplanes = 1;
-- 
2.17.1



[Patch v3 09/21] media: ti-vpe: vpe: fix a v4l2-compliance warning about invalid pixel format

2019-10-07 Thread Benoit Parrot
v4l2-compliance warns with this message:

   warn: v4l2-test-formats.cpp(717): \
TRY_FMT cannot handle an invalid pixelformat.
   warn: v4l2-test-formats.cpp(718): \
This may or may not be a problem. For more information see:
   warn: v4l2-test-formats.cpp(719): \
http://www.mail-archive.com/linux-media@vger.kernel.org/msg56550.html
...
   test VIDIOC_TRY_FMT: FAIL

We need to make sure that the returns a valid pixel format in all
instance. Based on the v4l2 framework convention drivers must return a
valid pixel format when the requested pixel format is either invalid or
not supported.

Signed-off-by: Benoit Parrot 
Reviewed-by: Tomi Valkeinen 
---
 drivers/media/platform/ti-vpe/vpe.c | 13 +
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/vpe.c 
b/drivers/media/platform/ti-vpe/vpe.c
index 1278d457f753..d3f1ae8b72fa 100644
--- a/drivers/media/platform/ti-vpe/vpe.c
+++ b/drivers/media/platform/ti-vpe/vpe.c
@@ -351,20 +351,25 @@ enum {
 };
 
 /* find our format description corresponding to the passed v4l2_format */
-static struct vpe_fmt *find_format(struct v4l2_format *f)
+static struct vpe_fmt *__find_format(u32 fourcc)
 {
struct vpe_fmt *fmt;
unsigned int k;
 
for (k = 0; k < ARRAY_SIZE(vpe_formats); k++) {
fmt = &vpe_formats[k];
-   if (fmt->fourcc == f->fmt.pix.pixelformat)
+   if (fmt->fourcc == fourcc)
return fmt;
}
 
return NULL;
 }
 
+static struct vpe_fmt *find_format(struct v4l2_format *f)
+{
+   return __find_format(f->fmt.pix.pixelformat);
+}
+
 /*
  * there is one vpe_dev structure in the driver, it is shared by
  * all instances.
@@ -1599,9 +1604,9 @@ static int __vpe_try_fmt(struct vpe_ctx *ctx, struct 
v4l2_format *f,
unsigned int stride = 0;
 
if (!fmt || !(fmt->types & type)) {
-   vpe_err(ctx->dev, "Fourcc format (0x%08x) invalid.\n",
+   vpe_dbg(ctx->dev, "Fourcc format (0x%08x) invalid.\n",
pix->pixelformat);
-   return -EINVAL;
+   fmt = __find_format(V4L2_PIX_FMT_YUYV);
}
 
if (pix->field != V4L2_FIELD_NONE &&
-- 
2.17.1



[Patch v3 17/21] media: ti-vpe: vpe: fix v4l2_compliance issue related to xfer_func

2019-10-07 Thread Benoit Parrot
All 4 of the "colorspace" components were not originally handled.
Causing issue related to xfer_func not being initialized properly.

This was found with v4l2-compliance test.

Signed-off-by: Benoit Parrot 
---
 drivers/media/platform/ti-vpe/vpe.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/ti-vpe/vpe.c 
b/drivers/media/platform/ti-vpe/vpe.c
index 295cbcef3a0e..7c74b21e0164 100644
--- a/drivers/media/platform/ti-vpe/vpe.c
+++ b/drivers/media/platform/ti-vpe/vpe.c
@@ -1582,11 +1582,14 @@ static int vpe_g_fmt(struct file *file, void *priv, 
struct v4l2_format *f)
struct vpe_q_data *s_q_data;
struct v4l2_pix_format_mplane *spix;
 
-   /* get colorspace from the source queue */
+   /* get colorimetry from the source queue */
s_q_data = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE);
spix = &s_q_data->format.fmt.pix_mp;
 
pix->colorspace = spix->colorspace;
+   pix->xfer_func = spix->xfer_func;
+   pix->ycbcr_enc = spix->ycbcr_enc;
+   pix->quantization = spix->quantization;
}
 
return 0;
-- 
2.17.1



[Patch v3 16/21] media: ti-vpe: vpe: use standard struct instead of duplicating fields

2019-10-07 Thread Benoit Parrot
For each queue we need to maintain resolutions, pixel format,
bytesperline, sizeimage, colorspace, etc.

Instead of manually adding more entries in the vpe_q_data struct, it is
better to just add a "struct v4l2_format" member and use that to store
all needed information.

Signed-off-by: Benoit Parrot 
---
 drivers/media/platform/ti-vpe/vpe.c | 196 ++--
 1 file changed, 101 insertions(+), 95 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/vpe.c 
b/drivers/media/platform/ti-vpe/vpe.c
index d7f8eb901475..295cbcef3a0e 100644
--- a/drivers/media/platform/ti-vpe/vpe.c
+++ b/drivers/media/platform/ti-vpe/vpe.c
@@ -319,14 +319,9 @@ static struct vpe_fmt vpe_formats[] = {
  * there is one source queue and one destination queue for each m2m context.
  */
 struct vpe_q_data {
-   unsigned intwidth;  /* frame width 
*/
-   unsigned intheight; /* frame height 
*/
-   unsigned intnplanes;/* Current 
number of planes */
-   unsigned intbytesperline[VPE_MAX_PLANES];   /* bytes per 
line in memory */
-   enum v4l2_colorspacecolorspace;
-   enum v4l2_field field;  /* supported 
field value */
+   /* current v4l2 format info */
+   struct v4l2_format  format;
unsigned intflags;
-   unsigned intsizeimage[VPE_MAX_PLANES];  /* image size 
in memory */
struct v4l2_rectc_rect; /* crop/compose 
rectangle */
struct vpe_fmt  *fmt;   /* format info 
*/
 };
@@ -761,11 +756,12 @@ static void set_src_registers(struct vpe_ctx *ctx)
 static void set_dst_registers(struct vpe_ctx *ctx)
 {
struct vpe_mmr_adb *mmr_adb = ctx->mmr_adb.addr;
-   enum v4l2_colorspace clrspc = ctx->q_data[Q_DATA_DST].colorspace;
+   struct v4l2_pix_format_mplane *pix;
struct vpe_fmt *fmt = ctx->q_data[Q_DATA_DST].fmt;
u32 val = 0;
 
-   if (clrspc == V4L2_COLORSPACE_SRGB) {
+   pix = &ctx->q_data[Q_DATA_DST].format.fmt.pix_mp;
+   if (pix->colorspace == V4L2_COLORSPACE_SRGB) {
val |= VPE_RGB_OUT_SELECT;
vpdma_set_bg_color(ctx->dev->vpdma,
(struct vpdma_data_format *)fmt->vpdma_fmt[0], 0xff);
@@ -868,11 +864,15 @@ static int set_srcdst_params(struct vpe_ctx *ctx)
unsigned int src_h = s_q_data->c_rect.height;
unsigned int dst_w = d_q_data->c_rect.width;
unsigned int dst_h = d_q_data->c_rect.height;
+   struct v4l2_pix_format_mplane *spix;
+   struct v4l2_pix_format_mplane *dpix;
size_t mv_buf_size;
int ret;
 
ctx->sequence = 0;
ctx->field = V4L2_FIELD_TOP;
+   spix = &s_q_data->format.fmt.pix_mp;
+   dpix = &d_q_data->format.fmt.pix_mp;
 
if ((s_q_data->flags & Q_IS_INTERLACED) &&
!(d_q_data->flags & Q_IS_INTERLACED)) {
@@ -887,9 +887,9 @@ static int set_srcdst_params(struct vpe_ctx *ctx)
 * extra space will not be used by the de-interlacer, but will
 * ensure that vpdma operates correctly
 */
-   bytes_per_line = ALIGN((s_q_data->width * mv->depth) >> 3,
-   VPDMA_STRIDE_ALIGN);
-   mv_buf_size = bytes_per_line * s_q_data->height;
+   bytes_per_line = ALIGN((spix->width * mv->depth) >> 3,
+  VPDMA_STRIDE_ALIGN);
+   mv_buf_size = bytes_per_line * spix->height;
 
ctx->deinterlacing = true;
src_h <<= 1;
@@ -909,7 +909,7 @@ static int set_srcdst_params(struct vpe_ctx *ctx)
set_dei_regs(ctx);
 
csc_set_coeff(ctx->dev->csc, &mmr_adb->csc_regs[0],
-   s_q_data->colorspace, d_q_data->colorspace);
+ spix->colorspace, dpix->colorspace);
 
sc_set_hs_coeffs(ctx->dev->sc, ctx->sc_coeff_h.addr, src_w, dst_w);
sc_set_vs_coeffs(ctx->dev->sc, ctx->sc_coeff_v.addr, src_h, dst_h);
@@ -1023,6 +1023,7 @@ static void add_out_dtd(struct vpe_ctx *ctx, int port)
struct vpe_fmt *fmt = q_data->fmt;
const struct vpdma_data_format *vpdma_fmt;
int mv_buf_selector = !ctx->src_mv_buf_selector;
+   struct v4l2_pix_format_mplane *pix;
dma_addr_t dma_addr;
u32 flags = 0;
u32 offset = 0;
@@ -1032,21 +1033,23 @@ static void add_out_dtd(struct vpe_ctx *ctx, int port)
vpdma_fmt = &vpdma_misc_fmts[VPDMA_DATA_FMT_MV];
dma_addr = ctx->mv_buf_dma[mv_buf_selector];
q_data = &ctx->q_data[Q_DATA_SRC]

[Patch v3 21/21] media: ti-vpe: vpe: don't rely on colorspace member for conversion

2019-10-07 Thread Benoit Parrot
Up to now VPE was relying on the colorspace value of struct v4l2_format
as an indication to perform color space conversion from YUV to RGB or
not.

Instead we should used the source/destination fourcc codes as a more
reliable indication to perform color space conversion or not.

To do so, we rework the csc module to use "struct v4l2_format *" as
parameters, and reorganize the coefficients tables in a more logical
way.

Signed-off-by: Benoit Parrot 
---
 drivers/media/platform/ti-vpe/csc.c | 254 +++-
 drivers/media/platform/ti-vpe/csc.h |   4 +-
 drivers/media/platform/ti-vpe/vpe.c |  25 ++-
 3 files changed, 184 insertions(+), 99 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/csc.c 
b/drivers/media/platform/ti-vpe/csc.c
index f0c45d187b5f..bd923bee4a31 100644
--- a/drivers/media/platform/ti-vpe/csc.c
+++ b/drivers/media/platform/ti-vpe/csc.c
@@ -15,76 +15,96 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "csc.h"
 
 /*
- * 16 coefficients in the order:
+ * 12 coefficients in the order:
  * a0, b0, c0, a1, b1, c1, a2, b2, c2, d0, d1, d2
- * (we may need to pass non-default values from user space later on, we might
- * need to make the coefficient struct more easy to populate)
  */
-struct colorspace_coeffs {
-   u16 sd[12];
-   u16 hd[12];
+struct quantization {
+   u16 coeff[12];
 };
 
-/* VIDEO_RANGE: limited range, GRAPHICS_RANGE: full range */
-#defineCSC_COEFFS_VIDEO_RANGE_Y2R  0
-#defineCSC_COEFFS_GRAPHICS_RANGE_Y2R   1
-#defineCSC_COEFFS_VIDEO_RANGE_R2Y  2
-#defineCSC_COEFFS_GRAPHICS_RANGE_R2Y   3
+struct colorspace {
+   struct quantization limited;
+   struct quantization full;
+};
+
+struct encoding_direction {
+   struct colorspace r601;
+   struct colorspace r709;
+};
+
+struct csc_coeffs {
+   struct encoding_direction y2r;
+   struct encoding_direction r2y;
+};
 
 /* default colorspace coefficients */
-static struct colorspace_coeffs colorspace_coeffs[4] = {
-   [CSC_COEFFS_VIDEO_RANGE_Y2R] = {
-   {
-   /* SDTV */
-   0x0400, 0x, 0x057D, 0x0400, 0x1EA7, 0x1D35,
-   0x0400, 0x06EF, 0x1FFE, 0x0D40, 0x0210, 0x0C88,
+static struct csc_coeffs csc_coeffs = {
+   .y2r = {
+   .r601 = {
+   .limited = {
+   {   /* SDTV */
+   0x0400, 0x, 0x057D, 0x0400, 0x1EA7, 0x1D35,
+   0x0400, 0x06EF, 0x1FFE, 0x0D40, 0x0210, 0x0C88,
+   }
+   },
+   .full = {
+   {   /* SDTV */
+   0x04A8, 0x1FFE, 0x0662, 0x04A8, 0x1E6F, 0x1CBF,
+   0x04A8, 0x0812, 0x1FFF, 0x0C84, 0x0220, 0x0BAC,
+   }
+   },
},
-   {
-   /* HDTV */
-   0x0400, 0x, 0x0629, 0x0400, 0x1F45, 0x1E2B,
-   0x0400, 0x0742, 0x, 0x0CEC, 0x0148, 0x0C60,
+   .r709 = {
+   .limited = {
+   {   /* HDTV */
+   0x0400, 0x, 0x0629, 0x0400, 0x1F45, 0x1E2B,
+   0x0400, 0x0742, 0x, 0x0CEC, 0x0148, 0x0C60,
+   }
+   },
+   .full = {
+   {   /* HDTV */
+   0x04A8, 0x, 0x072C, 0x04A8, 0x1F26, 0x1DDE,
+   0x04A8, 0x0873, 0x, 0x0C20, 0x0134, 0x0B7C,
+   }
+   },
},
},
-   [CSC_COEFFS_GRAPHICS_RANGE_Y2R] = {
-   {
-   /* SDTV */
-   0x04A8, 0x1FFE, 0x0662, 0x04A8, 0x1E6F, 0x1CBF,
-   0x04A8, 0x0812, 0x1FFF, 0x0C84, 0x0220, 0x0BAC,
+   .r2y = {
+   .r601 = {
+   .limited = {
+   {   /* SDTV */
+   0x0132, 0x0259, 0x0075, 0x1F50, 0x1EA5, 0x020B,
+   0x020B, 0x1E4A, 0x1FAB, 0x, 0x0200, 0x0200,
+   }
+   },
+   .full = {
+   {   /* SDTV */
+   0x0107, 0x0204, 0x0064, 0x1F68, 0x1ED6, 0x01C2,
+   0x01C2, 0x1E87, 0x1FB7, 0x0040, 0x0200, 0x0200,
+   }
+   },
},
-   {
-   /* HDTV */
-   0x04A8, 0x, 0x072C, 0x04A8, 0x1F26, 0x1DDE,
-   0x04A8, 0x0873, 0x, 0x

[Patch v3 19/21] media: v4l2-common: add pixel encoding support

2019-10-07 Thread Benoit Parrot
It is often useful to figure out if a pixel_format is either YUV or RGB
especially for driver who can perform the pixel encoding conversion.

Instead of having each driver implement its own "is_this_yuv/rgb"
function based on a restricted set of pixel value, it is better to do
this in centralized manner.

We therefore add a pixel_enc member to the v4l2_format_info structure to
quickly identify the related pixel encoding.
And add helper functions to check pixel encoding.

Signed-off-by: Benoit Parrot 
---
 drivers/media/v4l2-core/v4l2-common.c | 126 +-
 include/media/v4l2-common.h   |  33 ++-
 2 files changed, 95 insertions(+), 64 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-common.c 
b/drivers/media/v4l2-core/v4l2-common.c
index 62f7aa92ac29..09a3915b98a3 100644
--- a/drivers/media/v4l2-core/v4l2-common.c
+++ b/drivers/media/v4l2-core/v4l2-common.c
@@ -236,77 +236,77 @@ const struct v4l2_format_info *v4l2_format_info(u32 
format)
 {
static const struct v4l2_format_info formats[] = {
/* RGB formats */
-   { .format = V4L2_PIX_FMT_BGR24,   .mem_planes = 1, .comp_planes 
= 1, .bpp = { 3, 0, 0, 0 }, .hdiv = 1, .vdiv = 1 },
-   { .format = V4L2_PIX_FMT_RGB24,   .mem_planes = 1, .comp_planes 
= 1, .bpp = { 3, 0, 0, 0 }, .hdiv = 1, .vdiv = 1 },
-   { .format = V4L2_PIX_FMT_HSV24,   .mem_planes = 1, .comp_planes 
= 1, .bpp = { 3, 0, 0, 0 }, .hdiv = 1, .vdiv = 1 },
-   { .format = V4L2_PIX_FMT_BGR32,   .mem_planes = 1, .comp_planes 
= 1, .bpp = { 4, 0, 0, 0 }, .hdiv = 1, .vdiv = 1 },
-   { .format = V4L2_PIX_FMT_XBGR32,  .mem_planes = 1, .comp_planes 
= 1, .bpp = { 4, 0, 0, 0 }, .hdiv = 1, .vdiv = 1 },
-   { .format = V4L2_PIX_FMT_BGRX32,  .mem_planes = 1, .comp_planes 
= 1, .bpp = { 4, 0, 0, 0 }, .hdiv = 1, .vdiv = 1 },
-   { .format = V4L2_PIX_FMT_RGB32,   .mem_planes = 1, .comp_planes 
= 1, .bpp = { 4, 0, 0, 0 }, .hdiv = 1, .vdiv = 1 },
-   { .format = V4L2_PIX_FMT_XRGB32,  .mem_planes = 1, .comp_planes 
= 1, .bpp = { 4, 0, 0, 0 }, .hdiv = 1, .vdiv = 1 },
-   { .format = V4L2_PIX_FMT_RGBX32,  .mem_planes = 1, .comp_planes 
= 1, .bpp = { 4, 0, 0, 0 }, .hdiv = 1, .vdiv = 1 },
-   { .format = V4L2_PIX_FMT_HSV32,   .mem_planes = 1, .comp_planes 
= 1, .bpp = { 4, 0, 0, 0 }, .hdiv = 1, .vdiv = 1 },
-   { .format = V4L2_PIX_FMT_ARGB32,  .mem_planes = 1, .comp_planes 
= 1, .bpp = { 4, 0, 0, 0 }, .hdiv = 1, .vdiv = 1 },
-   { .format = V4L2_PIX_FMT_RGBA32,  .mem_planes = 1, .comp_planes 
= 1, .bpp = { 4, 0, 0, 0 }, .hdiv = 1, .vdiv = 1 },
-   { .format = V4L2_PIX_FMT_ABGR32,  .mem_planes = 1, .comp_planes 
= 1, .bpp = { 4, 0, 0, 0 }, .hdiv = 1, .vdiv = 1 },
-   { .format = V4L2_PIX_FMT_BGRA32,  .mem_planes = 1, .comp_planes 
= 1, .bpp = { 4, 0, 0, 0 }, .hdiv = 1, .vdiv = 1 },
-   { .format = V4L2_PIX_FMT_GREY,.mem_planes = 1, .comp_planes 
= 1, .bpp = { 1, 0, 0, 0 }, .hdiv = 1, .vdiv = 1 },
+   { .format = V4L2_PIX_FMT_BGR24,   .pixel_enc = 
V4L2_PIXEL_ENC_RGB, .mem_planes = 1, .comp_planes = 1, .bpp = { 3, 0, 0, 0 }, 
.hdiv = 1, .vdiv = 1 },
+   { .format = V4L2_PIX_FMT_RGB24,   .pixel_enc = 
V4L2_PIXEL_ENC_RGB, .mem_planes = 1, .comp_planes = 1, .bpp = { 3, 0, 0, 0 }, 
.hdiv = 1, .vdiv = 1 },
+   { .format = V4L2_PIX_FMT_HSV24,   .pixel_enc = 
V4L2_PIXEL_ENC_RGB, .mem_planes = 1, .comp_planes = 1, .bpp = { 3, 0, 0, 0 }, 
.hdiv = 1, .vdiv = 1 },
+   { .format = V4L2_PIX_FMT_BGR32,   .pixel_enc = 
V4L2_PIXEL_ENC_RGB, .mem_planes = 1, .comp_planes = 1, .bpp = { 4, 0, 0, 0 }, 
.hdiv = 1, .vdiv = 1 },
+   { .format = V4L2_PIX_FMT_XBGR32,  .pixel_enc = 
V4L2_PIXEL_ENC_RGB, .mem_planes = 1, .comp_planes = 1, .bpp = { 4, 0, 0, 0 }, 
.hdiv = 1, .vdiv = 1 },
+   { .format = V4L2_PIX_FMT_BGRX32,  .pixel_enc = 
V4L2_PIXEL_ENC_RGB, .mem_planes = 1, .comp_planes = 1, .bpp = { 4, 0, 0, 0 }, 
.hdiv = 1, .vdiv = 1 },
+   { .format = V4L2_PIX_FMT_RGB32,   .pixel_enc = 
V4L2_PIXEL_ENC_RGB, .mem_planes = 1, .comp_planes = 1, .bpp = { 4, 0, 0, 0 }, 
.hdiv = 1, .vdiv = 1 },
+   { .format = V4L2_PIX_FMT_XRGB32,  .pixel_enc = 
V4L2_PIXEL_ENC_RGB, .mem_planes = 1, .comp_planes = 1, .bpp = { 4, 0, 0, 0 }, 
.hdiv = 1, .vdiv = 1 },
+   { .format = V4L2_PIX_FMT_RGBX32,  .pixel_enc = 
V4L2_PIXEL_ENC_RGB, .mem_planes = 1, .comp_planes = 1, .bpp = { 4, 0, 0, 0 }, 
.hdiv = 1, .vdiv = 1 },
+   { .format = V4L2_PIX_FMT_HSV32,   .pixel_enc = 
V4L2_PIXEL_ENC_RGB, .mem_planes = 1, .comp_planes = 1, .bpp = { 4, 0, 0, 0 }, 
.hdiv = 1, .vdiv = 1 },
+   { .format = V4L2_PIX_FMT_ARGB32,  .pixel_enc = 
V4L2_PIXEL_ENC_RGB, .mem_planes = 1, .comp_planes = 1, .bpp = { 4, 0, 0, 0 }, 
.hdiv = 1, .vdiv = 1 },
+   { .format = V4L2_PIX_FMT_RGBA32,  

[Patch v3 18/21] media: ti-vpe: csc: rgb-to-yuv HD full range coeff are wrong

2019-10-07 Thread Benoit Parrot
The RGB to YUV HD full range coefficients did not match the TRM values
and appeared to be a cut-n-paste from the YUV to RGB section.

Replace the entries with the values from the TRM.

Signed-off-by: Benoit Parrot 
---
 drivers/media/platform/ti-vpe/csc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/csc.c 
b/drivers/media/platform/ti-vpe/csc.c
index eda2a5985da7..f0c45d187b5f 100644
--- a/drivers/media/platform/ti-vpe/csc.c
+++ b/drivers/media/platform/ti-vpe/csc.c
@@ -81,8 +81,8 @@ static struct colorspace_coeffs colorspace_coeffs[4] = {
},
{
/* HDTV */
-   0x04A8, 0x, 0x072C, 0x04A8, 0x1F26, 0x1DDE,
-   0x04A8, 0x0873, 0x, 0x0C20, 0x0134, 0x0B7C,
+   0x00bb, 0x0275, 0x003f, 0x1f99, 0x1ea5, 0x01c2,
+   0x01c2, 0x1e67, 0x1fd7, 0x0040, 0x0200, 0x0200,
},
},
 };
-- 
2.17.1



[Patch v3 13/21] media: ti-vpe: vpe: ensure buffers are cleaned up properly in abort cases

2019-10-07 Thread Benoit Parrot
v4l2-compliance fails with this message:

   fail: v4l2-test-buffers.cpp(691): ret == 0
   fail: v4l2-test-buffers.cpp(974): captureBufs(node, q, m2m_q,
frame_count, true)
   test MMAP: FAIL

This caused the following Kernel Warning:

WARNING: CPU: 0 PID: 961 at
drivers/media/v4l2-core/videobuf2-core.c:1658
__vb2_queue_cancel+0x174/0x1d8
...
CPU: 0 PID: 961 Comm: v4l2-compliance Not tainted
4.14.62-01720-g20ecd717e87a #6
Hardware name: Generic DRA72X (Flattened Device Tree)
Backtrace:
[] (dump_backtrace) from [] (show_stack+0x18/0x1c)
 r7:0009 r6:60070013 r5: r4:c1053824
[] (show_stack) from [] (dump_stack+0x90/0xa4)
[] (dump_stack) from [] (__warn+0xec/0x104)
  r7:0009 r6:c0c0ad50 r5: r4:
[] (__warn) from [] (warn_slowpath_null+0x28/0x30)
  r9:0008 r8: r7:eced4808 r6:edbc9bac r5:eced4844
r4:eced4808
[] (warn_slowpath_null) from []
(__vb2_queue_cancel+0x174/0x1d8)
[] (__vb2_queue_cancel) from []
(vb2_core_queue_release+0x20/0x40)
  r10:ecc7bd70 r9:0008 r8: r7:edb73010 r6:edbc9bac
r5:eced4844
  r4:eced4808 r3:0004
[] (vb2_core_queue_release) from []
(vb2_queue_release+0x10/0x14)
  r5:edbc9810 r4:eced4800
[] (vb2_queue_release) from []
(v4l2_m2m_ctx_release+0x1c/0x30)
[] (v4l2_m2m_ctx_release) from []
(vpe_release+0x74/0xb0 [ti_vpe])
  r5:edbc9810 r4:ed67a400
[] (vpe_release [ti_vpe]) from []
(v4l2_release+0x3c/0x80)
  r7:edb73010 r6:ed176aa0 r5:edbc9868 r4:ed5119c0
[] (v4l2_release) from [] (__fput+0x8c/0x1dc)
  r5:ecc7bd70 r4:ed5119c0
[] (__fput) from [] (fput+0x10/0x14)
  r10: r9:ed5119c0 r8:ece392d0 r7:c1059544 r6:ece38d80
r5:ece392b4
  r4:
[] (fput) from [] (task_work_run+0x98/0xb8)
[] (task_work_run) from [] (do_exit+0x170/0xa80)
  r9:ece351fc r8: r7:ecde3f58 r6:e000 r5:ece351c0
r4:ece38d80
[] (do_exit) from [] (do_group_exit+0x48/0xc4)
  r7:00f8
[] (do_group_exit) from []
(__wake_up_parent+0x0/0x28)
  r7:00f8 r6:b6c6a798 r5:0001 r4:0001
[] (SyS_exit_group) from []
(ret_fast_syscall+0x0/0x4c)

These warnings are caused by buffers which not properly cleaned
up/release during an abort use case.

In the abort cases the VPDMA desc buffers would still be mapped and the
in-flight VB2 buffers would not be released properly causing a kernel
warning from being generated by the videobuf2-core level.

Signed-off-by: Benoit Parrot 
Reviewed-by: Tomi Valkeinen 
---
 drivers/media/platform/ti-vpe/vpe.c | 12 +---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/vpe.c 
b/drivers/media/platform/ti-vpe/vpe.c
index 8ab1c3241b74..ad9d8b559cad 100644
--- a/drivers/media/platform/ti-vpe/vpe.c
+++ b/drivers/media/platform/ti-vpe/vpe.c
@@ -1427,9 +1427,6 @@ static irqreturn_t vpe_irq(int irq_vpe, void *data)
 /* the previous dst mv buffer becomes the next src mv buffer */
ctx->src_mv_buf_selector = !ctx->src_mv_buf_selector;
 
-   if (ctx->aborting)
-   goto finished;
-
s_vb = ctx->src_vbs[0];
d_vb = ctx->dst_vb;
 
@@ -1494,6 +1491,9 @@ static irqreturn_t vpe_irq(int irq_vpe, void *data)
ctx->src_vbs[0] = NULL;
ctx->dst_vb = NULL;
 
+   if (ctx->aborting)
+   goto finished;
+
ctx->bufs_completed++;
if (ctx->bufs_completed < ctx->bufs_per_job && job_ready(ctx)) {
device_run(ctx);
@@ -2404,6 +2404,12 @@ static int vpe_release(struct file *file)
 
mutex_lock(&dev->dev_mutex);
free_mv_buffers(ctx);
+
+   vpdma_unmap_desc_buf(dev->vpdma, &ctx->desc_list.buf);
+   vpdma_unmap_desc_buf(dev->vpdma, &ctx->mmr_adb);
+   vpdma_unmap_desc_buf(dev->vpdma, &ctx->sc_coeff_h);
+   vpdma_unmap_desc_buf(dev->vpdma, &ctx->sc_coeff_v);
+
vpdma_free_desc_list(&ctx->desc_list);
vpdma_free_desc_buf(&ctx->mmr_adb);
 
-- 
2.17.1



[Patch v3 20/21] media: v4l2-common: add RGB565 and RGB55 to v4l2_format_info

2019-10-07 Thread Benoit Parrot
Add RGB565 and RGB555 to the v4l2_format_info table.

Signed-off-by: Benoit Parrot 
---
 drivers/media/v4l2-core/v4l2-common.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/media/v4l2-core/v4l2-common.c 
b/drivers/media/v4l2-core/v4l2-common.c
index 09a3915b98a3..d0e5ebc736f9 100644
--- a/drivers/media/v4l2-core/v4l2-common.c
+++ b/drivers/media/v4l2-core/v4l2-common.c
@@ -251,6 +251,8 @@ const struct v4l2_format_info *v4l2_format_info(u32 format)
{ .format = V4L2_PIX_FMT_ABGR32,  .pixel_enc = 
V4L2_PIXEL_ENC_RGB, .mem_planes = 1, .comp_planes = 1, .bpp = { 4, 0, 0, 0 }, 
.hdiv = 1, .vdiv = 1 },
{ .format = V4L2_PIX_FMT_BGRA32,  .pixel_enc = 
V4L2_PIXEL_ENC_RGB, .mem_planes = 1, .comp_planes = 1, .bpp = { 4, 0, 0, 0 }, 
.hdiv = 1, .vdiv = 1 },
{ .format = V4L2_PIX_FMT_GREY,.pixel_enc = 
V4L2_PIXEL_ENC_RGB, .mem_planes = 1, .comp_planes = 1, .bpp = { 1, 0, 0, 0 }, 
.hdiv = 1, .vdiv = 1 },
+   { .format = V4L2_PIX_FMT_RGB565,  .pixel_enc = 
V4L2_PIXEL_ENC_RGB, .mem_planes = 1, .comp_planes = 1, .bpp = { 2, 0, 0, 0 }, 
.hdiv = 1, .vdiv = 1 },
+   { .format = V4L2_PIX_FMT_RGB555,  .pixel_enc = 
V4L2_PIXEL_ENC_RGB, .mem_planes = 1, .comp_planes = 1, .bpp = { 2, 0, 0, 0 }, 
.hdiv = 1, .vdiv = 1 },
 
/* YUV packed formats */
{ .format = V4L2_PIX_FMT_YUYV,.pixel_enc = 
V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 1, .bpp = { 2, 0, 0, 0 }, 
.hdiv = 2, .vdiv = 1 },
-- 
2.17.1



[Patch v3 15/21] media: ti-vpe: Set the DMA mask and coherent mask

2019-10-07 Thread Benoit Parrot
VPE uses VPDMA (built-in dma engine) to transfer data to and from the IP
and memory. VPDMA expect 32 bits addresses. To make sure that is always
the case set the DMA mask and coherent mask for the device.

Signed-off-by: Benoit Parrot 
---
 drivers/media/platform/ti-vpe/vpe.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/drivers/media/platform/ti-vpe/vpe.c 
b/drivers/media/platform/ti-vpe/vpe.c
index ad9d8b559cad..d7f8eb901475 100644
--- a/drivers/media/platform/ti-vpe/vpe.c
+++ b/drivers/media/platform/ti-vpe/vpe.c
@@ -2517,6 +2517,13 @@ static int vpe_probe(struct platform_device *pdev)
struct vpe_dev *dev;
int ret, irq, func;
 
+   ret = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
+   if (ret) {
+   dev_err(&pdev->dev,
+   "32-bit consistent DMA enable failed\n");
+   return ret;
+   }
+
dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL);
if (!dev)
return -ENOMEM;
-- 
2.17.1



[Patch v3 02/21] media: ti-vpe: vpe: Fix Motion Vector vpdma stride

2019-10-07 Thread Benoit Parrot
commit 52831a418fa6 ("[media] media: ti-vpe: vpe: allow use of user
specified stride") and commit 8c1e4fa17e92 ("[media] media: ti-vpe: vpdma:
add support for user specified stride") resulted in the Motion Vector
stride to be the same as the image stride.

This caused memory corruption in the output image as mentionned in
commit 44f98adf71a8 ("[media] media: ti-vpe: vpe: Fix line stride
for output motion vector").

Fixes: 52831a418fa6 ("[media] media: ti-vpe: vpe: allow use of user specified 
stride")
Fixes: 8c1e4fa17e92 ("[media] media: ti-vpe: vpdma: add support for user 
specified stride")
Signed-off-by: Benoit Parrot 
Acked-by: Nikhil Devshatwar 
---
 drivers/media/platform/ti-vpe/vpe.c | 18 +-
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/vpe.c 
b/drivers/media/platform/ti-vpe/vpe.c
index 60b575bb44c4..5ba72445584d 100644
--- a/drivers/media/platform/ti-vpe/vpe.c
+++ b/drivers/media/platform/ti-vpe/vpe.c
@@ -1013,11 +1013,14 @@ static void add_out_dtd(struct vpe_ctx *ctx, int port)
dma_addr_t dma_addr;
u32 flags = 0;
u32 offset = 0;
+   u32 stride;
 
if (port == VPE_PORT_MV_OUT) {
vpdma_fmt = &vpdma_misc_fmts[VPDMA_DATA_FMT_MV];
dma_addr = ctx->mv_buf_dma[mv_buf_selector];
q_data = &ctx->q_data[Q_DATA_SRC];
+   stride = ALIGN((q_data->width * vpdma_fmt->depth) >> 3,
+  VPDMA_STRIDE_ALIGN);
} else {
/* to incorporate interleaved formats */
int plane = fmt->coplanar ? p_data->vb_part : 0;
@@ -1044,6 +1047,7 @@ static void add_out_dtd(struct vpe_ctx *ctx, int port)
}
/* Apply the offset */
dma_addr += offset;
+   stride = q_data->bytesperline[VPE_LUMA];
}
 
if (q_data->flags & Q_DATA_FRAME_1D)
@@ -1055,7 +1059,7 @@ static void add_out_dtd(struct vpe_ctx *ctx, int port)
   MAX_W, MAX_H);
 
vpdma_add_out_dtd(&ctx->desc_list, q_data->width,
- q_data->bytesperline[VPE_LUMA], &q_data->c_rect,
+ stride, &q_data->c_rect,
  vpdma_fmt, dma_addr, MAX_OUT_WIDTH_REG1,
  MAX_OUT_HEIGHT_REG1, p_data->channel, flags);
 }
@@ -1074,10 +1078,13 @@ static void add_in_dtd(struct vpe_ctx *ctx, int port)
dma_addr_t dma_addr;
u32 flags = 0;
u32 offset = 0;
+   u32 stride;
 
if (port == VPE_PORT_MV_IN) {
vpdma_fmt = &vpdma_misc_fmts[VPDMA_DATA_FMT_MV];
dma_addr = ctx->mv_buf_dma[mv_buf_selector];
+   stride = ALIGN((q_data->width * vpdma_fmt->depth) >> 3,
+  VPDMA_STRIDE_ALIGN);
} else {
/* to incorporate interleaved formats */
int plane = fmt->coplanar ? p_data->vb_part : 0;
@@ -1104,6 +,7 @@ static void add_in_dtd(struct vpe_ctx *ctx, int port)
}
/* Apply the offset */
dma_addr += offset;
+   stride = q_data->bytesperline[VPE_LUMA];
 
if (q_data->flags & Q_DATA_INTERLACED_SEQ_TB) {
/*
@@ -1139,10 +1147,10 @@ static void add_in_dtd(struct vpe_ctx *ctx, int port)
if (p_data->vb_part && fmt->fourcc == V4L2_PIX_FMT_NV12)
frame_height /= 2;
 
-   vpdma_add_in_dtd(&ctx->desc_list, q_data->width,
-q_data->bytesperline[VPE_LUMA], &q_data->c_rect,
-   vpdma_fmt, dma_addr, p_data->channel, field, flags, frame_width,
-   frame_height, 0, 0);
+   vpdma_add_in_dtd(&ctx->desc_list, q_data->width, stride,
+&q_data->c_rect, vpdma_fmt, dma_addr,
+p_data->channel, field, flags, frame_width,
+frame_height, 0, 0);
 }
 
 /*
-- 
2.17.1



[Patch v3 12/21] media: ti-vpe: vpe: fix a v4l2-compliance failure about frame sequence number

2019-10-07 Thread Benoit Parrot
v4l2-compliance fails with this message:

   fail: v4l2-test-buffers.cpp(294): \
(int)g_sequence() < seq.last_seq + 1
   fail: v4l2-test-buffers.cpp(740): \
buf.check(m2m_q, last_m2m_seq)
   fail: v4l2-test-buffers.cpp(974): \
captureBufs(node, q, m2m_q, frame_count, true)
   test MMAP: FAIL

The driver is failing to update the source frame sequence number in the
vb2 buffer object. Only the destination frame sequence was being
updated.

This is only a reporting issue if the user space app actually cares
about the frame sequence number. But it is fixed nonetheless.

Signed-off-by: Benoit Parrot 
Reviewed-by: Tomi Valkeinen 
---
 drivers/media/platform/ti-vpe/vpe.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/media/platform/ti-vpe/vpe.c 
b/drivers/media/platform/ti-vpe/vpe.c
index 0a7cf9c820c6..8ab1c3241b74 100644
--- a/drivers/media/platform/ti-vpe/vpe.c
+++ b/drivers/media/platform/ti-vpe/vpe.c
@@ -1440,6 +1440,7 @@ static irqreturn_t vpe_irq(int irq_vpe, void *data)
d_vb->timecode = s_vb->timecode;
 
d_vb->sequence = ctx->sequence;
+   s_vb->sequence = ctx->sequence;
 
d_q_data = &ctx->q_data[Q_DATA_DST];
if (d_q_data->flags & Q_IS_INTERLACED) {
-- 
2.17.1



[Patch v3 07/21] media: ti-vpe: Set MAX height supported to 2048 pixels

2019-10-07 Thread Benoit Parrot
From: Ram Prasad 

VPE's max height supported MAX_H is set to 1184 which is the
padded height from VC1 decoder output.

In case of 90, 270 degree rotated video processing, input to
VPE will be 1080x1920, 720x1280 etc and MAX_H needs to be set
correct value. Setting MAX_H to 2048 as worst case height.

Signed-off-by: Ram Prasad 
Signed-off-by: Benoit Parrot 
---
 drivers/media/platform/ti-vpe/vpe.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/platform/ti-vpe/vpe.c 
b/drivers/media/platform/ti-vpe/vpe.c
index f3ee9ff87927..bbbf11174e16 100644
--- a/drivers/media/platform/ti-vpe/vpe.c
+++ b/drivers/media/platform/ti-vpe/vpe.c
@@ -52,7 +52,7 @@
 #define MIN_W  32
 #define MIN_H  32
 #define MAX_W  2048
-#define MAX_H  1184
+#define MAX_H  2048
 
 /* required alignments */
 #define S_ALIGN0   /* multiple of 1 */
-- 
2.17.1



[Patch v3 14/21] media: ti-vpe: vpdma: Use fixed type for address in descriptor

2019-10-07 Thread Benoit Parrot
Using dma_addr_t as the type to hold address inside of a fix sized
descriptor used by the vpdma firmware is prone to fail when the expected
width is 32 bits and suddenly when CONFIG_LPAE is enabled the data size
is now 64 bits shifted the remaining members of the descriptor in memory
which confuses the firmware.

Signed-off-by: Benoit Parrot 
---
 drivers/media/platform/ti-vpe/vpdma_priv.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/vpdma_priv.h 
b/drivers/media/platform/ti-vpe/vpdma_priv.h
index d8ae3e1cd54d..0bbee45338bd 100644
--- a/drivers/media/platform/ti-vpe/vpdma_priv.h
+++ b/drivers/media/platform/ti-vpe/vpdma_priv.h
@@ -166,11 +166,11 @@ struct vpdma_dtd {
u32 xfer_length_height;
u32 w1;
};
-   dma_addr_t  start_addr;
+   u32 start_addr;
u32 pkt_ctl;
union {
u32 frame_width_height; /* inbound */
-   dma_addr_t  desc_write_addr;/* outbound */
+   u32 desc_write_addr;/* outbound */
};
union {
u32 start_h_v;  /* inbound */
-- 
2.17.1



[Patch v3 03/21] media: ti-vpe: vpe: Add missing null pointer checks

2019-10-07 Thread Benoit Parrot
A few NULL pointer checks were missing.
Add check with appropriate return code.

Signed-off-by: Benoit Parrot 
---
 drivers/media/platform/ti-vpe/vpe.c | 13 -
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/ti-vpe/vpe.c 
b/drivers/media/platform/ti-vpe/vpe.c
index 5ba72445584d..56f60dbea15c 100644
--- a/drivers/media/platform/ti-vpe/vpe.c
+++ b/drivers/media/platform/ti-vpe/vpe.c
@@ -1537,6 +1537,8 @@ static int vpe_g_fmt(struct file *file, void *priv, 
struct v4l2_format *f)
return -EINVAL;
 
q_data = get_q_data(ctx, f->type);
+   if (!q_data)
+   return -EINVAL;
 
pix->width = q_data->width;
pix->height = q_data->height;
@@ -2001,6 +2003,8 @@ static int vpe_queue_setup(struct vb2_queue *vq,
struct vpe_q_data *q_data;
 
q_data = get_q_data(ctx, vq->type);
+   if (!q_data)
+   return -EINVAL;
 
*nplanes = q_data->nplanes;
 
@@ -2025,6 +2029,8 @@ static int vpe_buf_prepare(struct vb2_buffer *vb)
vpe_dbg(ctx->dev, "type: %d\n", vb->vb2_queue->type);
 
q_data = get_q_data(ctx, vb->vb2_queue->type);
+   if (!q_data)
+   return -EINVAL;
num_planes = q_data->nplanes;
 
if (vb->vb2_queue->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
@@ -2481,7 +2487,12 @@ static int vpe_probe(struct platform_device *pdev)
mutex_init(&dev->dev_mutex);
 
dev->res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
-   "vpe_top");
+   "vpe_top");
+   if (!dev->res) {
+   dev_err(&pdev->dev, "missing 'vpe_top' resources data\n");
+   return -ENODEV;
+   }
+
/*
 * HACK: we get resource info from device tree in the form of a list of
 * VPE sub blocks, the driver currently uses only the base of vpe_top
-- 
2.17.1



[Patch v3 08/21] media: ti-vpe: vpe: fix a v4l2-compliance failure causing a kernel panic

2019-10-07 Thread Benoit Parrot
v4l2-compliance fails with this message:

   warn: v4l2-test-formats.cpp(717): \
TRY_FMT cannot handle an invalid pixelformat.
   test VIDIOC_TRY_FMT: FAIL

This causes the following kernel panic:

Unable to handle kernel paging request at virtual address 56595561
pgd = ecd80e00
*pgd=
Internal error: Oops: 205 [#1] PREEMPT SMP ARM
...
CPU: 0 PID: 930 Comm: v4l2-compliance Not tainted \
4.14.62-01715-gc8cd67f49a19 #1
Hardware name: Generic DRA72X (Flattened Device Tree)
task: ece44d80 task.stack: ecc6e000
PC is at __vpe_try_fmt+0x18c/0x2a8 [ti_vpe]
LR is at 0x8

Because the driver fails to properly check the 'num_planes' values for
proper ranges it ends up accessing out of bound data causing the kernel
panic.

Since this driver only handle single or dual plane pixel format, make
sure the provided value does not exceed 2 planes.

Signed-off-by: Benoit Parrot 
Reviewed-by: Tomi Valkeinen 
---
 drivers/media/platform/ti-vpe/vpe.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/platform/ti-vpe/vpe.c 
b/drivers/media/platform/ti-vpe/vpe.c
index bbbf11174e16..1278d457f753 100644
--- a/drivers/media/platform/ti-vpe/vpe.c
+++ b/drivers/media/platform/ti-vpe/vpe.c
@@ -1650,7 +1650,7 @@ static int __vpe_try_fmt(struct vpe_ctx *ctx, struct 
v4l2_format *f,
  &pix->height, MIN_H, MAX_H, H_ALIGN,
  S_ALIGN);
 
-   if (!pix->num_planes)
+   if (!pix->num_planes || pix->num_planes > 2)
pix->num_planes = fmt->coplanar ? 2 : 1;
else if (pix->num_planes > 1 && !fmt->coplanar)
pix->num_planes = 1;
-- 
2.17.1



[Patch v3 11/21] media: ti-vpe: vpe: fix a v4l2-compliance failure about invalid sizeimage

2019-10-07 Thread Benoit Parrot
v4l2-compliance fails with this message:

   fail: v4l2-test-formats.cpp(463): !pfmt.sizeimage
   fail: v4l2-test-formats.cpp(736): \
Video Capture Multiplanar is valid, \
but TRY_FMT failed to return a format
   test VIDIOC_TRY_FMT: FAIL

This failure is causd by the driver failing to handle out range
'bytesperline' values from user space applications.

VPDMA hardware is limited to 64k line stride (16 bytes aligned, so 65520
bytes). So make sure the provided or calculated 'bytesperline' is
smaller than the maximum value.

Signed-off-by: Benoit Parrot 
Reviewed-by: Tomi Valkeinen 
---
 drivers/media/platform/ti-vpe/vpdma.h | 1 +
 drivers/media/platform/ti-vpe/vpe.c   | 4 
 2 files changed, 5 insertions(+)

diff --git a/drivers/media/platform/ti-vpe/vpdma.h 
b/drivers/media/platform/ti-vpe/vpdma.h
index bce17329c4c9..393fcbb3cb40 100644
--- a/drivers/media/platform/ti-vpe/vpdma.h
+++ b/drivers/media/platform/ti-vpe/vpdma.h
@@ -57,6 +57,7 @@ struct vpdma_data_format {
 * line stride of source and 
dest
 * buffers should be 16 byte 
aligned
 */
+#define VPDMA_MAX_STRIDE   65520   /* Max line stride 16 byte 
aligned */
 #define VPDMA_DTD_DESC_SIZE32  /* 8 words */
 #define VPDMA_CFD_CTD_DESC_SIZE16  /* 4 words */
 
diff --git a/drivers/media/platform/ti-vpe/vpe.c 
b/drivers/media/platform/ti-vpe/vpe.c
index 7aa83026fb6c..0a7cf9c820c6 100644
--- a/drivers/media/platform/ti-vpe/vpe.c
+++ b/drivers/media/platform/ti-vpe/vpe.c
@@ -1694,6 +1694,10 @@ static int __vpe_try_fmt(struct vpe_ctx *ctx, struct 
v4l2_format *f,
if (stride > plane_fmt->bytesperline)
plane_fmt->bytesperline = stride;
 
+   plane_fmt->bytesperline = clamp_t(u32, plane_fmt->bytesperline,
+ stride,
+ VPDMA_MAX_STRIDE);
+
plane_fmt->bytesperline = ALIGN(plane_fmt->bytesperline,
VPDMA_STRIDE_ALIGN);
 
-- 
2.17.1



[Patch v3 06/21] media: ti-vpe: Add support for NV21 format

2019-10-07 Thread Benoit Parrot
From: Nikhil Devshatwar 

In NV21 format, the chroma plane is written to memory such that the U
and V components are swapped for NV12.

Create a new entry in the VPDMA formats to describe the correct data
types used in the data descriptors.

Update all checks for NV12 and add NV21 there as well.

Add support for V4L2_PIX_FMT_NV21 format for both capture and output
streams.

Signed-off-by: Nikhil Devshatwar 
Signed-off-by: Benoit Parrot 
Reviewed-by: Tomi Valkeinen 
---
 drivers/media/platform/ti-vpe/vpdma.c  | 11 ++--
 drivers/media/platform/ti-vpe/vpdma.h  |  1 +
 drivers/media/platform/ti-vpe/vpdma_priv.h |  1 +
 drivers/media/platform/ti-vpe/vpe.c| 29 +-
 4 files changed, 34 insertions(+), 8 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/vpdma.c 
b/drivers/media/platform/ti-vpe/vpdma.c
index 53d27cd6e10a..817d287c8138 100644
--- a/drivers/media/platform/ti-vpe/vpdma.c
+++ b/drivers/media/platform/ti-vpe/vpdma.c
@@ -56,6 +56,11 @@ const struct vpdma_data_format vpdma_yuv_fmts[] = {
.data_type  = DATA_TYPE_C420,
.depth  = 4,
},
+   [VPDMA_DATA_FMT_CB420] = {
+   .type   = VPDMA_DATA_FMT_TYPE_YUV,
+   .data_type  = DATA_TYPE_CB420,
+   .depth  = 4,
+   },
[VPDMA_DATA_FMT_YCR422] = {
.type   = VPDMA_DATA_FMT_TYPE_YUV,
.data_type  = DATA_TYPE_YCR422,
@@ -825,7 +830,8 @@ void vpdma_rawchan_add_out_dtd(struct vpdma_desc_list 
*list, int width,
channel = next_chan = raw_vpdma_chan;
 
if (fmt->type == VPDMA_DATA_FMT_TYPE_YUV &&
-   fmt->data_type == DATA_TYPE_C420) {
+   (fmt->data_type == DATA_TYPE_C420 ||
+fmt->data_type == DATA_TYPE_CB420)) {
rect.height >>= 1;
rect.top >>= 1;
depth = 8;
@@ -893,7 +899,8 @@ void vpdma_add_in_dtd(struct vpdma_desc_list *list, int 
width,
channel = next_chan = chan_info[chan].num;
 
if (fmt->type == VPDMA_DATA_FMT_TYPE_YUV &&
-   fmt->data_type == DATA_TYPE_C420) {
+   (fmt->data_type == DATA_TYPE_C420 ||
+fmt->data_type == DATA_TYPE_CB420)) {
rect.height >>= 1;
rect.top >>= 1;
depth = 8;
diff --git a/drivers/media/platform/ti-vpe/vpdma.h 
b/drivers/media/platform/ti-vpe/vpdma.h
index 28bc94129348..bce17329c4c9 100644
--- a/drivers/media/platform/ti-vpe/vpdma.h
+++ b/drivers/media/platform/ti-vpe/vpdma.h
@@ -71,6 +71,7 @@ enum vpdma_yuv_formats {
VPDMA_DATA_FMT_C444,
VPDMA_DATA_FMT_C422,
VPDMA_DATA_FMT_C420,
+   VPDMA_DATA_FMT_CB420,
VPDMA_DATA_FMT_YCR422,
VPDMA_DATA_FMT_YC444,
VPDMA_DATA_FMT_CRY422,
diff --git a/drivers/media/platform/ti-vpe/vpdma_priv.h 
b/drivers/media/platform/ti-vpe/vpdma_priv.h
index c488609bc162..d8ae3e1cd54d 100644
--- a/drivers/media/platform/ti-vpe/vpdma_priv.h
+++ b/drivers/media/platform/ti-vpe/vpdma_priv.h
@@ -92,6 +92,7 @@
 #define DATA_TYPE_C444 0x4
 #define DATA_TYPE_C422 0x5
 #define DATA_TYPE_C420 0x6
+#define DATA_TYPE_CB4200x16
 #define DATA_TYPE_YC4440x8
 #define DATA_TYPE_YCB422   0x7
 #define DATA_TYPE_YCR422   0x17
diff --git a/drivers/media/platform/ti-vpe/vpe.c 
b/drivers/media/platform/ti-vpe/vpe.c
index 5d0ec5f7ca25..f3ee9ff87927 100644
--- a/drivers/media/platform/ti-vpe/vpe.c
+++ b/drivers/media/platform/ti-vpe/vpe.c
@@ -248,6 +248,14 @@ static struct vpe_fmt vpe_formats[] = {
&vpdma_yuv_fmts[VPDMA_DATA_FMT_C420],
  },
},
+   {
+   .fourcc = V4L2_PIX_FMT_NV21,
+   .types  = VPE_FMT_TYPE_CAPTURE | VPE_FMT_TYPE_OUTPUT,
+   .coplanar   = 1,
+   .vpdma_fmt  = { &vpdma_yuv_fmts[VPDMA_DATA_FMT_Y420],
+   &vpdma_yuv_fmts[VPDMA_DATA_FMT_CB420],
+ },
+   },
{
.fourcc = V4L2_PIX_FMT_YUYV,
.types  = VPE_FMT_TYPE_CAPTURE | VPE_FMT_TYPE_OUTPUT,
@@ -686,7 +694,8 @@ static void set_cfg_modes(struct vpe_ctx *ctx)
 * Cfg Mode 1: YUV422 source, disable upsampler, DEI is de-interlacing.
 */
 
-   if (fmt->fourcc == V4L2_PIX_FMT_NV12)
+   if (fmt->fourcc == V4L2_PIX_FMT_NV12 ||
+   fmt->fourcc == V4L2_PIX_FMT_NV21)
cfg_mode = 0;
 
write_field(us1_reg0, cfg_mode, VPE_US_MODE_MASK, VPE_US_MODE_SHIFT);
@@ -701,7 +710,8 @@ static void set_line_modes(struct vpe_ctx *ctx)
struct vpe_fmt *fm

Re: [Patch v2 19/21] media: v4l2-common: add pixel encoding support

2019-10-07 Thread Benoit Parrot
Hans Verkuil  wrote on Mon [2019-Oct-07 10:06:39 +0200]:
> On 10/4/19 6:29 PM, Benoit Parrot wrote:
> > It is often useful to figure out if a pixel_format is either YUV or RGB
> > especially for driver who can perform the pixel encoding conversion.
> > 
> > Instead of having each driver implement its own "is_this_yuv/rgb"
> > function based on a restricted set of pixel value, it is better to do
> > this in centralized manner.
> > 
> > We therefore add a pix_enc member to the v4l2_format_info structure to
> > quickly identify the related pixel encoding.
> > And add helper function to find/check pixel encoding.
> > 
> > Signed-off-by: Benoit Parrot 
> > ---
> >  drivers/media/v4l2-core/v4l2-common.c | 162 --
> >  include/media/v4l2-common.h   |  20 
> >  2 files changed, 119 insertions(+), 63 deletions(-)
> > 
> > diff --git a/drivers/media/v4l2-core/v4l2-common.c 
> > b/drivers/media/v4l2-core/v4l2-common.c
> > index 62f7aa92ac29..474cdb5863f4 100644
> > --- a/drivers/media/v4l2-core/v4l2-common.c
> > +++ b/drivers/media/v4l2-core/v4l2-common.c
> > @@ -236,77 +236,77 @@ const struct v4l2_format_info *v4l2_format_info(u32 
> > format)
> >  {
> > static const struct v4l2_format_info formats[] = {
> > /* RGB formats */
> > -   { .format = V4L2_PIX_FMT_BGR24,   .mem_planes = 1, .comp_planes 
> > = 1, .bpp = { 3, 0, 0, 0 }, .hdiv = 1, .vdiv = 1 },
> > -   { .format = V4L2_PIX_FMT_RGB24,   .mem_planes = 1, .comp_planes 
> > = 1, .bpp = { 3, 0, 0, 0 }, .hdiv = 1, .vdiv = 1 },
> > -   { .format = V4L2_PIX_FMT_HSV24,   .mem_planes = 1, .comp_planes 
> > = 1, .bpp = { 3, 0, 0, 0 }, .hdiv = 1, .vdiv = 1 },
> > -   { .format = V4L2_PIX_FMT_BGR32,   .mem_planes = 1, .comp_planes 
> > = 1, .bpp = { 4, 0, 0, 0 }, .hdiv = 1, .vdiv = 1 },
> > -   { .format = V4L2_PIX_FMT_XBGR32,  .mem_planes = 1, .comp_planes 
> > = 1, .bpp = { 4, 0, 0, 0 }, .hdiv = 1, .vdiv = 1 },
> > -   { .format = V4L2_PIX_FMT_BGRX32,  .mem_planes = 1, .comp_planes 
> > = 1, .bpp = { 4, 0, 0, 0 }, .hdiv = 1, .vdiv = 1 },
> > -   { .format = V4L2_PIX_FMT_RGB32,   .mem_planes = 1, .comp_planes 
> > = 1, .bpp = { 4, 0, 0, 0 }, .hdiv = 1, .vdiv = 1 },
> > -   { .format = V4L2_PIX_FMT_XRGB32,  .mem_planes = 1, .comp_planes 
> > = 1, .bpp = { 4, 0, 0, 0 }, .hdiv = 1, .vdiv = 1 },
> > -   { .format = V4L2_PIX_FMT_RGBX32,  .mem_planes = 1, .comp_planes 
> > = 1, .bpp = { 4, 0, 0, 0 }, .hdiv = 1, .vdiv = 1 },
> > -   { .format = V4L2_PIX_FMT_HSV32,   .mem_planes = 1, .comp_planes 
> > = 1, .bpp = { 4, 0, 0, 0 }, .hdiv = 1, .vdiv = 1 },
> > -   { .format = V4L2_PIX_FMT_ARGB32,  .mem_planes = 1, .comp_planes 
> > = 1, .bpp = { 4, 0, 0, 0 }, .hdiv = 1, .vdiv = 1 },
> > -   { .format = V4L2_PIX_FMT_RGBA32,  .mem_planes = 1, .comp_planes 
> > = 1, .bpp = { 4, 0, 0, 0 }, .hdiv = 1, .vdiv = 1 },
> > -   { .format = V4L2_PIX_FMT_ABGR32,  .mem_planes = 1, .comp_planes 
> > = 1, .bpp = { 4, 0, 0, 0 }, .hdiv = 1, .vdiv = 1 },
> > -   { .format = V4L2_PIX_FMT_BGRA32,  .mem_planes = 1, .comp_planes 
> > = 1, .bpp = { 4, 0, 0, 0 }, .hdiv = 1, .vdiv = 1 },
> > -   { .format = V4L2_PIX_FMT_GREY,.mem_planes = 1, .comp_planes 
> > = 1, .bpp = { 1, 0, 0, 0 }, .hdiv = 1, .vdiv = 1 },
> > +   { .format = V4L2_PIX_FMT_BGR24,   .pix_enc = V4L2_ENC_RGB, 
> > .mem_planes = 1, .comp_planes = 1, .bpp = { 3, 0, 0, 0 }, .hdiv = 1, .vdiv 
> > = 1 },
> > +   { .format = V4L2_PIX_FMT_RGB24,   .pix_enc = V4L2_ENC_RGB, 
> > .mem_planes = 1, .comp_planes = 1, .bpp = { 3, 0, 0, 0 }, .hdiv = 1, .vdiv 
> > = 1 },
> > +   { .format = V4L2_PIX_FMT_HSV24,   .pix_enc = V4L2_ENC_RGB, 
> > .mem_planes = 1, .comp_planes = 1, .bpp = { 3, 0, 0, 0 }, .hdiv = 1, .vdiv 
> > = 1 },
> > +   { .format = V4L2_PIX_FMT_BGR32,   .pix_enc = V4L2_ENC_RGB, 
> > .mem_planes = 1, .comp_planes = 1, .bpp = { 4, 0, 0, 0 }, .hdiv = 1, .vdiv 
> > = 1 },
> > +   { .format = V4L2_PIX_FMT_XBGR32,  .pix_enc = V4L2_ENC_RGB, 
> > .mem_planes = 1, .comp_planes = 1, .bpp = { 4, 0, 0, 0 }, .hdiv = 1, .vdiv 
> > = 1 },
> > +   { .format = V4L2_PIX_FMT_BGRX32,  .pix_enc = V4L2_ENC_RGB, 
> > .mem_planes = 1, .comp_planes = 1, .bpp = { 4, 0, 0, 0 }, .hdiv = 1, .vdiv 
> > = 1 },
> > +   { .format = V4L2_PIX_FMT_RGB32,   .pix_enc = V4L2_ENC_RGB, 
> > .mem_planes = 1, .comp_planes = 1, .bpp = { 4, 0, 0, 0 }, .hdiv = 1, .vdiv 
> > = 1 },

Re: [Patch v2 16/21] media: ti-vpe: vpe: use standard struct instead of duplicating fields

2019-10-07 Thread Benoit Parrot
Hans Verkuil  wrote on Mon [2019-Oct-07 09:57:26 +0200]:
> On 10/4/19 6:29 PM, Benoit Parrot wrote:
> > For each queue we need to maintain resolutions, pixel format,
> > bytesperline, sizeimage, colorspace, etc.
> > 
> > Instead of manually adding more entries in the vpe_q_data struct, it is
> > better to just add a "struct v4l2_format" member and use that to store
> > all needed information.
> > 
> > Signed-off-by: Benoit Parrot 
> > ---
> >  drivers/media/platform/ti-vpe/vpe.c | 185 ++--
> >  1 file changed, 91 insertions(+), 94 deletions(-)
> > 
> > diff --git a/drivers/media/platform/ti-vpe/vpe.c 
> > b/drivers/media/platform/ti-vpe/vpe.c
> > index d7f8eb901475..5b1e9908fff2 100644
> > --- a/drivers/media/platform/ti-vpe/vpe.c
> > +++ b/drivers/media/platform/ti-vpe/vpe.c
> > @@ -319,14 +319,9 @@ static struct vpe_fmt vpe_formats[] = {
> >   * there is one source queue and one destination queue for each m2m 
> > context.
> >   */
> >  struct vpe_q_data {
> > -   unsigned intwidth;  /* frame width 
> > */
> > -   unsigned intheight; /* frame height 
> > */
> > -   unsigned intnplanes;/* Current 
> > number of planes */
> > -   unsigned intbytesperline[VPE_MAX_PLANES];   /* bytes per 
> > line in memory */
> > -   enum v4l2_colorspacecolorspace;
> > -   enum v4l2_field field;  /* supported 
> > field value */
> > +   /* current v4l2 format info */
> > +   struct v4l2_format  format;
> 
> Wouldn't it make more sense to use struct v4l2_pix_format_mplane? That avoid 
> having to
> use the '.fmt.pix_mp' sequence every time you need to access it.

Maybe, I chose "struct v4l2_format" because that is the parameter type used
in all related IOCTL. But I guess I can change it, if it make the code
cleaner :).

Benoit

> 
> Regards,
> 
>   Hans
> 


[Patch v3 0/3] media: ov5640: updates

2019-10-04 Thread Benoit Parrot
This patch series is a collection of patches we have been carrying for a
while.

First, it adds support for PIXEL_RATE control which is used by some
CSI2 receiver driver to properly set-up their DPHY.

Then we fix an issue related to having extra sensor enable/disable in
the register array for the 1920x1080 mode.

Finally we restrict the largest resolution which should only be
available at the lowest FPS.

Changes since v2:
- Addressed comment from Sakari and Jacopo.
- Make use of the calc_pixel_rate in set_mode also
- Cleaned up the pixel_rate ctrl struct
- Fix the fps condition checking for the max resolution case

Changes since v1:
- Addressed comment from Sakari.
  added a function to calculate the pixel rate and remove the need to
  cache its value

Benoit Parrot (3):
  media: ov5640: add PIXEL_RATE control
  media: ov5640: Fix 1920x1080 mode to remove extra enable/disable
  media: ov5640: Make 2592x1944 mode only available at 15 fps

 drivers/media/i2c/ov5640.c | 33 +
 1 file changed, 29 insertions(+), 4 deletions(-)

-- 
2.17.1



[Patch v3 1/3] media: ov5640: add PIXEL_RATE control

2019-10-04 Thread Benoit Parrot
Add v4l2 controls to report the pixel rates of each mode. This is
needed by some CSI2 receiver in order to perform proper DPHY
configuration.

Signed-off-by: Benoit Parrot 
---
 drivers/media/i2c/ov5640.c | 25 +++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/drivers/media/i2c/ov5640.c b/drivers/media/i2c/ov5640.c
index 500d9bbff10b..a3946ca6a13d 100644
--- a/drivers/media/i2c/ov5640.c
+++ b/drivers/media/i2c/ov5640.c
@@ -193,6 +193,7 @@ struct ov5640_mode_info {
 
 struct ov5640_ctrls {
struct v4l2_ctrl_handler handler;
+   struct v4l2_ctrl *pixel_rate;
struct {
struct v4l2_ctrl *auto_exp;
struct v4l2_ctrl *exposure;
@@ -1614,6 +1615,16 @@ ov5640_find_mode(struct ov5640_dev *sensor, enum 
ov5640_frame_rate fr,
return mode;
 }
 
+static u64 ov5640_calc_pixel_rate(struct ov5640_dev *sensor)
+{
+   u64 rate;
+
+   rate = sensor->current_mode->vtot * sensor->current_mode->htot;
+   rate *= ov5640_framerates[sensor->current_fr];
+
+   return rate;
+}
+
 /*
  * sensor changes between scaling and subsampling, go through
  * exposure calculation
@@ -1818,8 +1829,7 @@ static int ov5640_set_mode(struct ov5640_dev *sensor)
 * All the formats we support have 16 bits per pixel, seems to require
 * the same rate than YUV, so we can just use 16 bpp all the time.
 */
-   rate = mode->vtot * mode->htot * 16;
-   rate *= ov5640_framerates[sensor->current_fr];
+   rate = ov5640_calc_pixel_rate(sensor) * 16;
if (sensor->ep.bus_type == V4L2_MBUS_CSI2_DPHY) {
rate = rate / sensor->ep.bus.mipi_csi2.num_data_lanes;
ret = ov5640_set_mipi_pclk(sensor, rate);
@@ -2233,6 +2243,8 @@ static int ov5640_set_fmt(struct v4l2_subdev *sd,
if (mbus_fmt->code != sensor->fmt.code)
sensor->pending_fmt_change = true;
 
+   __v4l2_ctrl_s_ctrl_int64(sensor->ctrls.pixel_rate,
+ov5640_calc_pixel_rate(sensor));
 out:
mutex_unlock(&sensor->lock);
return ret;
@@ -2657,6 +2669,12 @@ static int ov5640_init_controls(struct ov5640_dev 
*sensor)
/* we can use our own mutex for the ctrl lock */
hdl->lock = &sensor->lock;
 
+   /* Clock related controls */
+   ctrls->pixel_rate = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_PIXEL_RATE,
+ 0, INT_MAX, 1,
+ ov5640_calc_pixel_rate(sensor));
+   ctrls->pixel_rate->flags |= V4L2_CTRL_FLAG_READ_ONLY;
+
/* Auto/manual white balance */
ctrls->auto_wb = v4l2_ctrl_new_std(hdl, ops,
   V4L2_CID_AUTO_WHITE_BALANCE,
@@ -2816,6 +2834,9 @@ static int ov5640_s_frame_interval(struct v4l2_subdev *sd,
sensor->frame_interval = fi->interval;
sensor->current_mode = mode;
sensor->pending_mode_change = true;
+
+   __v4l2_ctrl_s_ctrl_int64(sensor->ctrls.pixel_rate,
+ov5640_calc_pixel_rate(sensor));
}
 out:
mutex_unlock(&sensor->lock);
-- 
2.17.1



[Patch v3 3/3] media: ov5640: Make 2592x1944 mode only available at 15 fps

2019-10-04 Thread Benoit Parrot
The sensor data sheet clearly state that 2592x1944 only works at 15 fps
make sure we don't try to miss configure the pll out of acceptable
range.

Signed-off-by: Benoit Parrot 
Reviewed-by: Jacopo Mondi 
---
 drivers/media/i2c/ov5640.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/drivers/media/i2c/ov5640.c b/drivers/media/i2c/ov5640.c
index 5cebad151546..8ffb3a55ca27 100644
--- a/drivers/media/i2c/ov5640.c
+++ b/drivers/media/i2c/ov5640.c
@@ -1611,6 +1611,11 @@ ov5640_find_mode(struct ov5640_dev *sensor, enum 
ov5640_frame_rate fr,
!(mode->hact == 640 && mode->vact == 480))
return NULL;
 
+   /* 2592x1944 only works at 15fps max */
+   if ((mode->hact == 2592 && mode->vact == 1944) &&
+   fr > OV5640_15_FPS)
+   return NULL;
+
return mode;
 }
 
-- 
2.17.1



[Patch v3 2/3] media: ov5640: Fix 1920x1080 mode to remove extra enable/disable

2019-10-04 Thread Benoit Parrot
In the 1920x1080 register array an extra pair of reset ctrl disable
re-enable was causing unwanted init delays.

Signed-off-by: Benoit Parrot 
Reviewed-by: Jacopo Mondi 
---
 drivers/media/i2c/ov5640.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/media/i2c/ov5640.c b/drivers/media/i2c/ov5640.c
index a3946ca6a13d..5cebad151546 100644
--- a/drivers/media/i2c/ov5640.c
+++ b/drivers/media/i2c/ov5640.c
@@ -490,7 +490,6 @@ static const struct reg_value 
ov5640_setting_720P_1280_720[] = {
 };
 
 static const struct reg_value ov5640_setting_1080P_1920_1080[] = {
-   {0x3008, 0x42, 0, 0},
{0x3c07, 0x08, 0, 0},
{0x3c09, 0x1c, 0, 0}, {0x3c0a, 0x9c, 0, 0}, {0x3c0b, 0x40, 0, 0},
{0x3814, 0x11, 0, 0},
@@ -518,7 +517,7 @@ static const struct reg_value 
ov5640_setting_1080P_1920_1080[] = {
{0x3a0e, 0x03, 0, 0}, {0x3a0d, 0x04, 0, 0}, {0x3a14, 0x04, 0, 0},
{0x3a15, 0x60, 0, 0}, {0x4407, 0x04, 0, 0},
{0x460b, 0x37, 0, 0}, {0x460c, 0x20, 0, 0}, {0x3824, 0x04, 0, 0},
-   {0x4005, 0x1a, 0, 0}, {0x3008, 0x02, 0, 0},
+   {0x4005, 0x1a, 0, 0},
 };
 
 static const struct reg_value ov5640_setting_QSXGA_2592_1944[] = {
-- 
2.17.1



[Patch v2 00/21] media: vpe: maintenance

2019-10-04 Thread Benoit Parrot
This a collection of backlog patches I have been carrying for the VPE
driver.

It adds supports for SEQ_BT as well as NV21.
And fixes a number of issues both through v4l2-compliance and normal
usage.

Changes since v1:
- Added a missing from my first set fixing a Makefile issue
- Added a csc table fix to match the technical specification
- Base on Hans' comment I reworked the last two patches which
  yielded one more patch
- This also led me to create additional patches to the
  v4l2_format_info table to simplify pixel encoding lookup

==
v4l2-compliance SHA: 5b168dc8473911227890526bad26553d9e8ff81b, 32 bits

Compliance test for vpe device /dev/video0:

Driver Info:
Driver name  : vpe
Card type: vpe
Bus info : platform:vpe
Driver version   : 5.3.0
Capabilities : 0x84204000
Video Memory-to-Memory Multiplanar
Streaming
Extended Pix Format
Device Capabilities
Device Caps  : 0x04204000
Video Memory-to-Memory Multiplanar
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 (Not Supported)
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: 1 Private Controls: 1

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
test Composing: OK
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:
warn: v4l2-test-buffers.cpp(683): VIDIOC_CREATE_BUFS not 
supported
warn: v4l2-test-buffers.cpp(683): VIDIOC_CREATE_BUFS not 
supported
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK
test VIDIOC_EXPBUF: OK
test Requests: OK (Not Supported)

Test input 0:

Streaming ioctls:
test read/write: OK (Not Supported)
test blocking wait: OK
Video Capture Multiplanar: Captured 58 buffers
test MMAP (no poll): OK
Video Capture Multiplanar: Captured 58 buffers
test MMAP (select): OK
Video Capture Multiplanar: Captured 58 buffers
test MMAP (epoll): OK
test USERPTR (no poll): OK (Not Supported)
test USERPTR (select): OK (Not Supported)
test DMABUF: Cannot test, specify --expbuf-device

Total for vpe device /dev/video0: 51, Succeeded: 51, Failed: 0, Warnings: 2
======

Benoit Parrot (18):
  media: ti-vpe: Fix a parallel build issue
  media: ti-vpe: vpe: Fix Motion Vector vpdma stride
  media: ti-vpe: vpe: Add missing null pointer checks
  media: ti-vpe: vpe: Remove unnecessary use of container_of
  media: ti-vpe: vpe: fix a v4l2-compliance failure causing a kernel
panic
  media: ti-vpe: vpe: fix a v4l2-compliance warning about invalid pixel
format
  media: ti-vpe: vpe: Make sure YUYV is set as default format
  media: ti-vpe: vpe: fix a v4l2-compliance failure about invalid
sizeimage
  media: ti-vpe: vpe: fix a v4l2-compliance failure about 

[Patch v2 04/21] media: ti-vpe: vpe: Remove unnecessary use of container_of

2019-10-04 Thread Benoit Parrot
Instead of saving a pointer to the 'fh' member of struct vpe_ctx to
later have to use container_of to retrieve the actual pointer to the
context structure, which seems to confuse static code analysis tool
anyways, just save the pointer to the actual structure and then retrieve
it directly.

Signed-off-by: Benoit Parrot 
---
 drivers/media/platform/ti-vpe/vpe.c | 22 +++---
 1 file changed, 7 insertions(+), 15 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/vpe.c 
b/drivers/media/platform/ti-vpe/vpe.c
index 56f60dbea15c..0e9cb0319a92 100644
--- a/drivers/media/platform/ti-vpe/vpe.c
+++ b/drivers/media/platform/ti-vpe/vpe.c
@@ -900,14 +900,6 @@ static int set_srcdst_params(struct vpe_ctx *ctx)
return 0;
 }
 
-/*
- * Return the vpe_ctx structure for a given struct file
- */
-static struct vpe_ctx *file2ctx(struct file *file)
-{
-   return container_of(file->private_data, struct vpe_ctx, fh);
-}
-
 /*
  * mem2mem callbacks
  */
@@ -1527,7 +1519,7 @@ static int vpe_enum_fmt(struct file *file, void *priv,
 static int vpe_g_fmt(struct file *file, void *priv, struct v4l2_format *f)
 {
struct v4l2_pix_format_mplane *pix = &f->fmt.pix_mp;
-   struct vpe_ctx *ctx = file2ctx(file);
+   struct vpe_ctx *ctx = file->private_data;
struct vb2_queue *vq;
struct vpe_q_data *q_data;
int i;
@@ -1689,7 +1681,7 @@ static int __vpe_try_fmt(struct vpe_ctx *ctx, struct 
v4l2_format *f,
 
 static int vpe_try_fmt(struct file *file, void *priv, struct v4l2_format *f)
 {
-   struct vpe_ctx *ctx = file2ctx(file);
+   struct vpe_ctx *ctx = file->private_data;
struct vpe_fmt *fmt = find_format(f);
 
if (V4L2_TYPE_IS_OUTPUT(f->type))
@@ -1762,7 +1754,7 @@ static int __vpe_s_fmt(struct vpe_ctx *ctx, struct 
v4l2_format *f)
 static int vpe_s_fmt(struct file *file, void *priv, struct v4l2_format *f)
 {
int ret;
-   struct vpe_ctx *ctx = file2ctx(file);
+   struct vpe_ctx *ctx = file->private_data;
 
ret = vpe_try_fmt(file, priv, f);
if (ret)
@@ -1847,7 +1839,7 @@ static int __vpe_try_selection(struct vpe_ctx *ctx, 
struct v4l2_selection *s)
 static int vpe_g_selection(struct file *file, void *fh,
struct v4l2_selection *s)
 {
-   struct vpe_ctx *ctx = file2ctx(file);
+   struct vpe_ctx *ctx = file->private_data;
struct vpe_q_data *q_data;
bool use_c_rect = false;
 
@@ -1908,7 +1900,7 @@ static int vpe_g_selection(struct file *file, void *fh,
 static int vpe_s_selection(struct file *file, void *fh,
struct v4l2_selection *s)
 {
-   struct vpe_ctx *ctx = file2ctx(file);
+   struct vpe_ctx *ctx = file->private_data;
struct vpe_q_data *q_data;
struct v4l2_selection sel = *s;
int ret;
@@ -2275,7 +2267,7 @@ static int vpe_open(struct file *file)
init_adb_hdrs(ctx);
 
v4l2_fh_init(&ctx->fh, video_devdata(file));
-   file->private_data = &ctx->fh;
+   file->private_data = ctx;
 
hdl = &ctx->hdl;
v4l2_ctrl_handler_init(hdl, 1);
@@ -2360,7 +2352,7 @@ static int vpe_open(struct file *file)
 static int vpe_release(struct file *file)
 {
struct vpe_dev *dev = video_drvdata(file);
-   struct vpe_ctx *ctx = file2ctx(file);
+   struct vpe_ctx *ctx = file->private_data;
 
vpe_dbg(dev, "releasing instance %p\n", ctx);
 
-- 
2.17.1



[Patch v2 09/21] media: ti-vpe: vpe: fix a v4l2-compliance warning about invalid pixel format

2019-10-04 Thread Benoit Parrot
v4l2-compliance warns with this message:

   warn: v4l2-test-formats.cpp(717): \
TRY_FMT cannot handle an invalid pixelformat.
   warn: v4l2-test-formats.cpp(718): \
This may or may not be a problem. For more information see:
   warn: v4l2-test-formats.cpp(719): \
http://www.mail-archive.com/linux-media@vger.kernel.org/msg56550.html
...
   test VIDIOC_TRY_FMT: FAIL

We need to make sure that the returns a valid pixel format in all
instance. Based on the v4l2 framework convention drivers must return a
valid pixel format when the requested pixel format is either invalid or
not supported.

Signed-off-by: Benoit Parrot 
Reviewed-by: Tomi Valkeinen 
---
 drivers/media/platform/ti-vpe/vpe.c | 13 +
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/vpe.c 
b/drivers/media/platform/ti-vpe/vpe.c
index 1278d457f753..d3f1ae8b72fa 100644
--- a/drivers/media/platform/ti-vpe/vpe.c
+++ b/drivers/media/platform/ti-vpe/vpe.c
@@ -351,20 +351,25 @@ enum {
 };
 
 /* find our format description corresponding to the passed v4l2_format */
-static struct vpe_fmt *find_format(struct v4l2_format *f)
+static struct vpe_fmt *__find_format(u32 fourcc)
 {
struct vpe_fmt *fmt;
unsigned int k;
 
for (k = 0; k < ARRAY_SIZE(vpe_formats); k++) {
fmt = &vpe_formats[k];
-   if (fmt->fourcc == f->fmt.pix.pixelformat)
+   if (fmt->fourcc == fourcc)
return fmt;
}
 
return NULL;
 }
 
+static struct vpe_fmt *find_format(struct v4l2_format *f)
+{
+   return __find_format(f->fmt.pix.pixelformat);
+}
+
 /*
  * there is one vpe_dev structure in the driver, it is shared by
  * all instances.
@@ -1599,9 +1604,9 @@ static int __vpe_try_fmt(struct vpe_ctx *ctx, struct 
v4l2_format *f,
unsigned int stride = 0;
 
if (!fmt || !(fmt->types & type)) {
-   vpe_err(ctx->dev, "Fourcc format (0x%08x) invalid.\n",
+   vpe_dbg(ctx->dev, "Fourcc format (0x%08x) invalid.\n",
pix->pixelformat);
-   return -EINVAL;
+   fmt = __find_format(V4L2_PIX_FMT_YUYV);
}
 
if (pix->field != V4L2_FIELD_NONE &&
-- 
2.17.1



[Patch v2 06/21] media: ti-vpe: Add support for NV21 format

2019-10-04 Thread Benoit Parrot
From: Nikhil Devshatwar 

In NV21 format, the chroma plane is written to memory such that the U
and V components are swapped for NV12.

Create a new entry in the VPDMA formats to describe the correct data
types used in the data descriptors.

Update all checks for NV12 and add NV21 there as well.

Add support for V4L2_PIX_FMT_NV21 format for both capture and output
streams.

Signed-off-by: Nikhil Devshatwar 
Signed-off-by: Benoit Parrot 
Reviewed-by: Tomi Valkeinen 
---
 drivers/media/platform/ti-vpe/vpdma.c  | 11 ++--
 drivers/media/platform/ti-vpe/vpdma.h  |  1 +
 drivers/media/platform/ti-vpe/vpdma_priv.h |  1 +
 drivers/media/platform/ti-vpe/vpe.c| 29 +-
 4 files changed, 34 insertions(+), 8 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/vpdma.c 
b/drivers/media/platform/ti-vpe/vpdma.c
index 53d27cd6e10a..817d287c8138 100644
--- a/drivers/media/platform/ti-vpe/vpdma.c
+++ b/drivers/media/platform/ti-vpe/vpdma.c
@@ -56,6 +56,11 @@ const struct vpdma_data_format vpdma_yuv_fmts[] = {
.data_type  = DATA_TYPE_C420,
.depth  = 4,
},
+   [VPDMA_DATA_FMT_CB420] = {
+   .type   = VPDMA_DATA_FMT_TYPE_YUV,
+   .data_type  = DATA_TYPE_CB420,
+   .depth  = 4,
+   },
[VPDMA_DATA_FMT_YCR422] = {
.type   = VPDMA_DATA_FMT_TYPE_YUV,
.data_type  = DATA_TYPE_YCR422,
@@ -825,7 +830,8 @@ void vpdma_rawchan_add_out_dtd(struct vpdma_desc_list 
*list, int width,
channel = next_chan = raw_vpdma_chan;
 
if (fmt->type == VPDMA_DATA_FMT_TYPE_YUV &&
-   fmt->data_type == DATA_TYPE_C420) {
+   (fmt->data_type == DATA_TYPE_C420 ||
+fmt->data_type == DATA_TYPE_CB420)) {
rect.height >>= 1;
rect.top >>= 1;
depth = 8;
@@ -893,7 +899,8 @@ void vpdma_add_in_dtd(struct vpdma_desc_list *list, int 
width,
channel = next_chan = chan_info[chan].num;
 
if (fmt->type == VPDMA_DATA_FMT_TYPE_YUV &&
-   fmt->data_type == DATA_TYPE_C420) {
+   (fmt->data_type == DATA_TYPE_C420 ||
+fmt->data_type == DATA_TYPE_CB420)) {
rect.height >>= 1;
rect.top >>= 1;
depth = 8;
diff --git a/drivers/media/platform/ti-vpe/vpdma.h 
b/drivers/media/platform/ti-vpe/vpdma.h
index 28bc94129348..bce17329c4c9 100644
--- a/drivers/media/platform/ti-vpe/vpdma.h
+++ b/drivers/media/platform/ti-vpe/vpdma.h
@@ -71,6 +71,7 @@ enum vpdma_yuv_formats {
VPDMA_DATA_FMT_C444,
VPDMA_DATA_FMT_C422,
VPDMA_DATA_FMT_C420,
+   VPDMA_DATA_FMT_CB420,
VPDMA_DATA_FMT_YCR422,
VPDMA_DATA_FMT_YC444,
VPDMA_DATA_FMT_CRY422,
diff --git a/drivers/media/platform/ti-vpe/vpdma_priv.h 
b/drivers/media/platform/ti-vpe/vpdma_priv.h
index c488609bc162..d8ae3e1cd54d 100644
--- a/drivers/media/platform/ti-vpe/vpdma_priv.h
+++ b/drivers/media/platform/ti-vpe/vpdma_priv.h
@@ -92,6 +92,7 @@
 #define DATA_TYPE_C444 0x4
 #define DATA_TYPE_C422 0x5
 #define DATA_TYPE_C420 0x6
+#define DATA_TYPE_CB4200x16
 #define DATA_TYPE_YC4440x8
 #define DATA_TYPE_YCB422   0x7
 #define DATA_TYPE_YCR422   0x17
diff --git a/drivers/media/platform/ti-vpe/vpe.c 
b/drivers/media/platform/ti-vpe/vpe.c
index 5d0ec5f7ca25..f3ee9ff87927 100644
--- a/drivers/media/platform/ti-vpe/vpe.c
+++ b/drivers/media/platform/ti-vpe/vpe.c
@@ -248,6 +248,14 @@ static struct vpe_fmt vpe_formats[] = {
&vpdma_yuv_fmts[VPDMA_DATA_FMT_C420],
  },
},
+   {
+   .fourcc = V4L2_PIX_FMT_NV21,
+   .types  = VPE_FMT_TYPE_CAPTURE | VPE_FMT_TYPE_OUTPUT,
+   .coplanar   = 1,
+   .vpdma_fmt  = { &vpdma_yuv_fmts[VPDMA_DATA_FMT_Y420],
+   &vpdma_yuv_fmts[VPDMA_DATA_FMT_CB420],
+ },
+   },
{
.fourcc = V4L2_PIX_FMT_YUYV,
.types  = VPE_FMT_TYPE_CAPTURE | VPE_FMT_TYPE_OUTPUT,
@@ -686,7 +694,8 @@ static void set_cfg_modes(struct vpe_ctx *ctx)
 * Cfg Mode 1: YUV422 source, disable upsampler, DEI is de-interlacing.
 */
 
-   if (fmt->fourcc == V4L2_PIX_FMT_NV12)
+   if (fmt->fourcc == V4L2_PIX_FMT_NV12 ||
+   fmt->fourcc == V4L2_PIX_FMT_NV21)
cfg_mode = 0;
 
write_field(us1_reg0, cfg_mode, VPE_US_MODE_MASK, VPE_US_MODE_SHIFT);
@@ -701,7 +710,8 @@ static void set_line_modes(struct vpe_ctx *ctx)
struct vpe_fmt *fm

  1   2   3   4   5   >