Re: [PATCH v11 3/4] dt-bindings: media: Add Cadence MIPI-CSI2 TX Device Tree bindings

2018-04-24 Thread Benoit Parrot
Acked-by: Benoit Parrot <bpar...@ti.com>

Maxime Ripard <maxime.rip...@bootlin.com> wrote on Tue [2018-Apr-24 14:26:59 
+0200]:
> The Cadence MIPI-CSI2 TX controller is a CSI2 bridge that supports up to 4
> video streams and can output on up to 4 CSI-2 lanes, depending on the
> hardware implementation.
> 
> It can operate with an external D-PHY, an internal one or no D-PHY at all
> in some configurations.
> 
> Acked-by: Rob Herring <r...@kernel.org>
> Acked-by: Sakari Ailus <sakari.ai...@linux.intel.com>
> Reviewed-by: Niklas Söderlund <niklas.soderlund+rene...@ragnatech.se>
> Signed-off-by: Maxime Ripard <maxime.rip...@bootlin.com>
> ---
>  .../devicetree/bindings/media/cdns,csi2tx.txt | 98 +++
>  1 file changed, 98 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/media/cdns,csi2tx.txt
> 
> diff --git a/Documentation/devicetree/bindings/media/cdns,csi2tx.txt 
> b/Documentation/devicetree/bindings/media/cdns,csi2tx.txt
> new file mode 100644
> index ..459c6e332f52
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/media/cdns,csi2tx.txt
> @@ -0,0 +1,98 @@
> +Cadence MIPI-CSI2 TX controller
> +===
> +
> +The Cadence MIPI-CSI2 TX controller is a CSI-2 bridge supporting up to
> +4 CSI lanes in output, and up to 4 different pixel streams in input.
> +
> +Required properties:
> +  - compatible: must be set to "cdns,csi2tx"
> +  - reg: base address and size of the memory mapped region
> +  - clocks: phandles to the clocks driving the controller
> +  - clock-names: must contain:
> +* esc_clk: escape mode clock
> +* p_clk: register bank clock
> +* pixel_if[0-3]_clk: pixel stream output clock, one for each stream
> + implemented in hardware, between 0 and 3
> +
> +Optional properties
> +  - phys: phandle to the D-PHY. If it is set, phy-names need to be set
> +  - phy-names: must contain "dphy"
> +
> +Required subnodes:
> +  - ports: A ports node with one port child node per device input and output
> +   port, in accordance with the video interface bindings defined in
> +   Documentation/devicetree/bindings/media/video-interfaces.txt. The
> +   port nodes are numbered as follows.
> +
> +   Port Description
> +   -
> +   0CSI-2 output
> +   1Stream 0 input
> +   2Stream 1 input
> +   3Stream 2 input
> +   4Stream 3 input
> +
> +   The stream input port nodes are optional if they are not
> +   connected to anything at the hardware level or implemented
> +   in the design. Since there is only one endpoint per port,
> +   the endpoints are not numbered.
> +
> +Example:
> +
> +csi2tx: csi-bridge@0d0e1000 {
> + compatible = "cdns,csi2tx";
> + reg = <0x0d0e1000 0x1000>;
> + clocks = <>, <>,
> +  <>, <>,
> +  <>, <>;
> + clock-names = "p_clk", "esc_clk",
> +   "pixel_if0_clk", "pixel_if1_clk",
> +   "pixel_if2_clk", "pixel_if3_clk";
> +
> + ports {
> + #address-cells = <1>;
> + #size-cells = <0>;
> +
> + port@0 {
> + reg = <0>;
> +
> + csi2tx_out: endpoint {
> + remote-endpoint = <_in>;
> + clock-lanes = <0>;
> + data-lanes = <1 2>;
> + };
> + };
> +
> + port@1 {
> + reg = <1>;
> +
> + csi2tx_in_stream0: endpoint {
> + remote-endpoint = <_out>;
> + };
> + };
> +
> + port@2 {
> + reg = <2>;
> +
> + csi2tx_in_stream1: endpoint {
> + remote-endpoint = <_out>;
> + };
> + };
> +
> + port@3 {
> + reg = <3>;
> +
> + csi2tx_in_stream2: endpoint {
> + remote-endpoint = <_out>;
> + };
> + };
> +
> + port@4 {
> + reg = <4>;
> +
> + csi2tx_in_stream3: endpoint {
> + remote-endpoint = <_out>;
> + };
> + };
> + };
> +};
> -- 
> 2.17.0
> 


Re: [PATCH v11 4/4] v4l: cadence: Add Cadence MIPI-CSI2 TX driver

2018-04-24 Thread Benoit Parrot
Acked-by: Benoit Parrot <bpar...@ti.com>

Maxime Ripard <maxime.rip...@bootlin.com> wrote on Tue [2018-Apr-24 14:27:00 
+0200]:
> The Cadence MIPI-CSI2 TX controller is an hardware block meant to be used
> as a bridge between pixel interfaces and a CSI-2 bus.
> 
> It supports operating with an internal or external D-PHY, with up to 4
> lanes, or without any D-PHY. The current code only supports the latter
> case.
> 
> While the virtual channel input on the pixel interface can be directly
> mapped to CSI2, the datatype input is actually a selection signal (3-bits)
> mapping to a table of up to 8 preconfigured datatypes/formats (programmed
> at start-up)
> 
> The block supports up to 8 input datatypes.
> 
> Acked-by: Sakari Ailus <sakari.ai...@linux.intel.com>
> Reviewed-by: Niklas Söderlund <niklas.soderlund+rene...@ragnatech.se>
> Signed-off-by: Maxime Ripard <maxime.rip...@bootlin.com>
> ---
>  drivers/media/platform/cadence/Kconfig   |  11 +
>  drivers/media/platform/cadence/Makefile  |   1 +
>  drivers/media/platform/cadence/cdns-csi2tx.c | 563 +++
>  3 files changed, 575 insertions(+)
>  create mode 100644 drivers/media/platform/cadence/cdns-csi2tx.c
> 
> diff --git a/drivers/media/platform/cadence/Kconfig 
> b/drivers/media/platform/cadence/Kconfig
> index 70c95d79c8f7..3bf0f2454384 100644
> --- a/drivers/media/platform/cadence/Kconfig
> +++ b/drivers/media/platform/cadence/Kconfig
> @@ -20,4 +20,15 @@ config VIDEO_CADENCE_CSI2RX
> To compile this driver as a module, choose M here: the module will be
> called cdns-csi2rx.
>  
> +config VIDEO_CADENCE_CSI2TX
> + tristate "Cadence MIPI-CSI2 TX Controller"
> + depends on MEDIA_CONTROLLER
> + depends on VIDEO_V4L2_SUBDEV_API
> + select V4L2_FWNODE
> + help
> +   Support for the Cadence MIPI CSI2 Transceiver controller.
> +
> +   To compile this driver as a module, choose M here: the module will be
> +   called cdns-csi2tx.
> +
>  endif
> diff --git a/drivers/media/platform/cadence/Makefile 
> b/drivers/media/platform/cadence/Makefile
> index 99a4086b7448..7fe992273162 100644
> --- a/drivers/media/platform/cadence/Makefile
> +++ b/drivers/media/platform/cadence/Makefile
> @@ -1 +1,2 @@
>  obj-$(CONFIG_VIDEO_CADENCE_CSI2RX)   += cdns-csi2rx.o
> +obj-$(CONFIG_VIDEO_CADENCE_CSI2TX)   += cdns-csi2tx.o
> diff --git a/drivers/media/platform/cadence/cdns-csi2tx.c 
> b/drivers/media/platform/cadence/cdns-csi2tx.c
> new file mode 100644
> index ..dfa1d88d955b
> --- /dev/null
> +++ b/drivers/media/platform/cadence/cdns-csi2tx.c
> @@ -0,0 +1,563 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * Driver for Cadence MIPI-CSI2 TX Controller
> + *
> + * Copyright (C) 2017-2018 Cadence Design Systems Inc.
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#define CSI2TX_DEVICE_CONFIG_REG 0x00
> +#define CSI2TX_DEVICE_CONFIG_STREAMS_MASKGENMASK(6, 4)
> +#define CSI2TX_DEVICE_CONFIG_HAS_DPHYBIT(3)
> +#define CSI2TX_DEVICE_CONFIG_LANES_MASK  GENMASK(2, 0)
> +
> +#define CSI2TX_CONFIG_REG0x20
> +#define CSI2TX_CONFIG_CFG_REQBIT(2)
> +#define CSI2TX_CONFIG_SRST_REQ   BIT(1)
> +
> +#define CSI2TX_DPHY_CFG_REG  0x28
> +#define CSI2TX_DPHY_CFG_CLK_RESETBIT(16)
> +#define CSI2TX_DPHY_CFG_LANE_RESET(n)BIT((n) + 12)
> +#define CSI2TX_DPHY_CFG_MODE_MASKGENMASK(9, 8)
> +#define CSI2TX_DPHY_CFG_MODE_LPDT(2 << 8)
> +#define CSI2TX_DPHY_CFG_MODE_HS  (1 << 8)
> +#define CSI2TX_DPHY_CFG_MODE_ULPS(0 << 8)
> +#define CSI2TX_DPHY_CFG_CLK_ENABLE   BIT(4)
> +#define CSI2TX_DPHY_CFG_LANE_ENABLE(n)   BIT(n)
> +
> +#define CSI2TX_DPHY_CLK_WAKEUP_REG   0x2c
> +#define CSI2TX_DPHY_CLK_WAKEUP_ULPS_CYCLES(n)((n) & 0x)
> +
> +#define CSI2TX_DT_CFG_REG(n) (0x80 + (n) * 8)
> +#define CSI2TX_DT_CFG_DT(n)  (((n) & 0x3f) << 2)
> +
> +#define CSI2TX_DT_FORMAT_REG(n)  (0x84 + (n) * 8)
> +#define CSI2TX_DT_FORMAT_BYTES_PER_LINE(n)   (((n) & 0x) << 16)
> +#define CSI2TX_DT_FORMAT_MAX_LINE_NUM(n) ((n) & 0x)
> +
> +#define CSI2TX_STREAM_IF_CFG_REG(n)  (0x100 + (n) * 4)
> +#define CSI2TX_STREAM_IF_CFG_FILL_LEVEL(n)   ((n) & 0x1f)
> +
> +#define CSI2TX_LANES_MAX 4
> +#define CSI2TX_STREAMS_MAX

Re: [PATCH v11 2/4] v4l: cadence: Add Cadence MIPI-CSI2 RX driver

2018-04-24 Thread Benoit Parrot
Maxime Ripard <maxime.rip...@bootlin.com> wrote on Tue [2018-Apr-24 14:26:58 
+0200]:
> The Cadence CSI-2 RX Controller is an hardware block meant to be used as a
> bridge between a CSI-2 bus and pixel grabbers.
> 
> It supports operating with internal or external D-PHY, with up to 4 lanes,
> or without any D-PHY. The current code only supports the latter case.
> 
> It also support dynamic mapping of the CSI-2 virtual channels to the
> associated pixel grabbers, but that isn't allowed at the moment either.
> 
> Acked-by: Sakari Ailus <sakari.ai...@linux.intel.com>
> Reviewed-by: Niklas Söderlund <niklas.soderlund+rene...@ragnatech.se>
> Signed-off-by: Maxime Ripard <maxime.rip...@bootlin.com>
> ---
>  MAINTAINERS  |   7 +
>  drivers/media/platform/Kconfig   |   1 +
>  drivers/media/platform/Makefile  |   1 +
>  drivers/media/platform/cadence/Kconfig   |  23 +
>  drivers/media/platform/cadence/Makefile  |   1 +
>  drivers/media/platform/cadence/cdns-csi2rx.c | 500 +++
>  6 files changed, 533 insertions(+)
>  create mode 100644 drivers/media/platform/cadence/Kconfig
>  create mode 100644 drivers/media/platform/cadence/Makefile
>  create mode 100644 drivers/media/platform/cadence/cdns-csi2rx.c
> 
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 0a1410d5a621..2c27d39611eb 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -3133,6 +3133,13 @@ S: Supported
>  F:   Documentation/filesystems/caching/cachefiles.txt
>  F:   fs/cachefiles/
>  
> +CADENCE MIPI-CSI2 BRIDGES
> +M:   Maxime Ripard <maxime.rip...@bootlin.com>
> +L:   linux-media@vger.kernel.org
> +S:   Maintained
> +F:   Documentation/devicetree/bindings/media/cdns,*.txt
> +F:   drivers/media/platform/cadence/cdns-csi2*
> +
>  CADET FM/AM RADIO RECEIVER DRIVER
>  M:   Hans Verkuil <hverk...@xs4all.nl>
>  L:   linux-media@vger.kernel.org
> diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig
> index c7a1cf8a1b01..029340ec3da4 100644
> --- a/drivers/media/platform/Kconfig
> +++ b/drivers/media/platform/Kconfig
> @@ -26,6 +26,7 @@ config VIDEO_VIA_CAMERA
>  #
>  # Platform multimedia device configuration
>  #
> +source "drivers/media/platform/cadence/Kconfig"
>  
>  source "drivers/media/platform/davinci/Kconfig"
>  
> diff --git a/drivers/media/platform/Makefile b/drivers/media/platform/Makefile
> index 932515df4477..04bc1502a30e 100644
> --- a/drivers/media/platform/Makefile
> +++ b/drivers/media/platform/Makefile
> @@ -3,6 +3,7 @@
>  # Makefile for the video capture/playback device drivers.
>  #
>  
> +obj-$(CONFIG_VIDEO_CADENCE)  += cadence/
>  obj-$(CONFIG_VIDEO_VIA_CAMERA) += via-camera.o
>  obj-$(CONFIG_VIDEO_CAFE_CCIC) += marvell-ccic/
>  obj-$(CONFIG_VIDEO_MMP_CAMERA) += marvell-ccic/
> diff --git a/drivers/media/platform/cadence/Kconfig 
> b/drivers/media/platform/cadence/Kconfig
> new file mode 100644
> index ..70c95d79c8f7
> --- /dev/null
> +++ b/drivers/media/platform/cadence/Kconfig
> @@ -0,0 +1,23 @@
> +config VIDEO_CADENCE
> + bool "Cadence Video Devices"
> + help
> +   If you have a media device designed by Cadence, say Y.
> +
> +   Note that this option doesn't include new drivers in the kernel:
> +   saying N will just cause Kconfig to skip all the questions about
> +   Cadence media devices.
> +
> +if VIDEO_CADENCE
> +
> +config VIDEO_CADENCE_CSI2RX
> + tristate "Cadence MIPI-CSI2 RX Controller"
> + depends on MEDIA_CONTROLLER
> + depends on VIDEO_V4L2_SUBDEV_API
> + select V4L2_FWNODE
> + help
> +   Support for the Cadence MIPI CSI2 Receiver controller.
> +
> +   To compile this driver as a module, choose M here: the module will be
> +   called cdns-csi2rx.
> +
> +endif
> diff --git a/drivers/media/platform/cadence/Makefile 
> b/drivers/media/platform/cadence/Makefile
> new file mode 100644
> index ..99a4086b7448
> --- /dev/null
> +++ b/drivers/media/platform/cadence/Makefile
> @@ -0,0 +1 @@
> +obj-$(CONFIG_VIDEO_CADENCE_CSI2RX)   += cdns-csi2rx.o

You probably want to add an SPDX license tag here also.

At any rate:

Acked-by: Benoit Parrot <bpar...@ti.com>

> diff --git a/drivers/media/platform/cadence/cdns-csi2rx.c 
> b/drivers/media/platform/cadence/cdns-csi2rx.c
> new file mode 100644
> index ..01f8321c12da
> --- /dev/null
> +++ b/drivers/media/platform/cadence/cdns-csi2rx.c
> @@ -0,0 +1,500 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * Driver for Cadence MIPI-CSI2 RX Controller v1.3
> + *
&g

Re: [PATCH v5 2/2] v4l: cadence: Add Cadence MIPI-CSI2 TX driver

2018-03-01 Thread Benoit Parrot
Maxime,

Thanks you for the patch,

Maxime Ripard  wrote on Thu [2018-Mar-01 12:30:49 
+0100]:
> The Cadence MIPI-CSI2 TX controller is an hardware block meant to be used
> as a bridge between pixel interfaces and a CSI-2 bus.
> 
> It supports operating with an internal or external D-PHY, with up to 4
> lanes, or without any D-PHY. The current code only supports the latter
> case.
> 
> While the virtual channel input on the pixel interface can be directly
> mapped to CSI2, the datatype input is actually a selection signal (3-bits)
> mapping to a table of up to 8 preconfigured datatypes/formats (programmed
> at start-up)
> 
> The block supports up to 8 input datatypes.
> 
> Signed-off-by: Maxime Ripard 
> ---
>  drivers/media/platform/cadence/Kconfig   |  11 +
>  drivers/media/platform/cadence/Makefile  |   1 +
>  drivers/media/platform/cadence/cdns-csi2tx.c | 527 
> +++
>  3 files changed, 539 insertions(+)
>  create mode 100644 drivers/media/platform/cadence/cdns-csi2tx.c
> 
> diff --git a/drivers/media/platform/cadence/Kconfig 
> b/drivers/media/platform/cadence/Kconfig
> index 18f061e5cbd1..83dcf2b1814b 100644
> --- a/drivers/media/platform/cadence/Kconfig
> +++ b/drivers/media/platform/cadence/Kconfig
> @@ -14,4 +14,15 @@ config VIDEO_CADENCE_CSI2RX
> To compile this driver as a module, choose M here: the module will be
> called cdns-csi2rx.
>  
> +config VIDEO_CADENCE_CSI2TX
> + tristate "Cadence MIPI-CSI2 TX Controller"
> + depends on MEDIA_CONTROLLER
> + depends on VIDEO_V4L2_SUBDEV_API
> + select V4L2_FWNODE
> + help
> +   Support for the Cadence MIPI CSI2 Transceiver controller.
> +
> +   To compile this driver as a module, choose M here: the module will be
> +   called cdns-csi2tx.
> +
>  endif
> diff --git a/drivers/media/platform/cadence/Makefile 
> b/drivers/media/platform/cadence/Makefile
> index 99a4086b7448..7fe992273162 100644
> --- a/drivers/media/platform/cadence/Makefile
> +++ b/drivers/media/platform/cadence/Makefile
> @@ -1 +1,2 @@
>  obj-$(CONFIG_VIDEO_CADENCE_CSI2RX)   += cdns-csi2rx.o
> +obj-$(CONFIG_VIDEO_CADENCE_CSI2TX)   += cdns-csi2tx.o
> diff --git a/drivers/media/platform/cadence/cdns-csi2tx.c 
> b/drivers/media/platform/cadence/cdns-csi2tx.c
> new file mode 100644
> index ..8de277e6aec1
> --- /dev/null
> +++ b/drivers/media/platform/cadence/cdns-csi2tx.c
> @@ -0,0 +1,527 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * Driver for Cadence MIPI-CSI2 TX Controller
> + *
> + * Copyright (C) 2017 Cadence Design Systems Inc.
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#define CSI2TX_DEVICE_CONFIG_REG 0x00
> +
> +#define CSI2TX_CONFIG_REG0x20
> +#define CSI2TX_CONFIG_CFG_REQBIT(2)
> +#define CSI2TX_CONFIG_SRST_REQ   BIT(1)
> +
> +#define CSI2TX_DPHY_CFG_REG  0x28
> +#define CSI2TX_DPHY_CFG_CLK_RESETBIT(16)
> +#define CSI2TX_DPHY_CFG_LANE_RESET(n)BIT((n) + 12)
> +#define CSI2TX_DPHY_CFG_MODE_MASKGENMASK(9, 8)
> +#define CSI2TX_DPHY_CFG_MODE_LPDT(2 << 8)
> +#define CSI2TX_DPHY_CFG_MODE_HS  (1 << 8)
> +#define CSI2TX_DPHY_CFG_MODE_ULPS(0 << 8)
> +#define CSI2TX_DPHY_CFG_CLK_ENABLE   BIT(4)
> +#define CSI2TX_DPHY_CFG_LANE_ENABLE(n)   BIT(n)
> +
> +#define CSI2TX_DPHY_CLK_WAKEUP_REG   0x2c
> +#define CSI2TX_DPHY_CLK_WAKEUP_ULPS_CYCLES(n)((n) & 0x)
> +
> +#define CSI2TX_DT_CFG_REG(n) (0x80 + (n) * 8)
> +#define CSI2TX_DT_CFG_DT(n)  (((n) & 0x3f) << 2)
> +
> +#define CSI2TX_DT_FORMAT_REG(n)  (0x84 + (n) * 8)
> +#define CSI2TX_DT_FORMAT_BYTES_PER_LINE(n)   (((n) & 0x) << 16)
> +#define CSI2TX_DT_FORMAT_MAX_LINE_NUM(n) ((n) & 0x)
> +
> +#define CSI2TX_STREAM_IF_CFG_REG(n)  (0x100 + (n) * 4)
> +#define CSI2TX_STREAM_IF_CFG_FILL_LEVEL(n)   ((n) & 0x1f)
> +
> +#define CSI2TX_LANES_MAX 4
> +#define CSI2TX_STREAMS_MAX   4
> +
> +enum csi2tx_pads {
> + CSI2TX_PAD_SOURCE,
> + CSI2TX_PAD_SINK_STREAM0,
> + CSI2TX_PAD_SINK_STREAM1,
> + CSI2TX_PAD_SINK_STREAM2,
> + CSI2TX_PAD_SINK_STREAM3,
> + CSI2TX_PAD_MAX,
> +};
> +
> +struct csi2tx_fmt {
> + u32 mbus;
> + u32 dt;
> + u32 bpp;
> +};
> +
> +struct csi2tx_priv {
> + struct device   *dev;
> + unsigned intcount;
> +
> + /*
> +  * Used to prevent race conditions between multiple,
> +  * concurrent calls to start and stop.
> +  */
> + struct mutexlock;
> +
> + void __iomem*base;
> +
> + struct clk  *esc_clk;
> + struct clk  

Re: [PATCH v8 2/2] v4l: cadence: Add Cadence MIPI-CSI2 RX driver

2018-03-01 Thread Benoit Parrot
Maxime,

Thank you for the patch.

Maxime Ripard  wrote on Thu [2018-Feb-15 14:33:35 
+0100]:
> The Cadence CSI-2 RX Controller is an hardware block meant to be used as a
> bridge between a CSI-2 bus and pixel grabbers.
> 
> It supports operating with internal or external D-PHY, with up to 4 lanes,
> or without any D-PHY. The current code only supports the latter case.
> 
> It also support dynamic mapping of the CSI-2 virtual channels to the
> associated pixel grabbers, but that isn't allowed at the moment either.
> 
> Acked-by: Sakari Ailus 
> Signed-off-by: Maxime Ripard 
> ---
>  drivers/media/platform/Kconfig   |   1 +
>  drivers/media/platform/Makefile  |   2 +
>  drivers/media/platform/cadence/Kconfig   |  17 +
>  drivers/media/platform/cadence/Makefile  |   1 +
>  drivers/media/platform/cadence/cdns-csi2rx.c | 499 
> +++
>  5 files changed, 520 insertions(+)
>  create mode 100644 drivers/media/platform/cadence/Kconfig
>  create mode 100644 drivers/media/platform/cadence/Makefile
>  create mode 100644 drivers/media/platform/cadence/cdns-csi2rx.c
> 
> diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig
> index 614fbef08ddc..c001b646d441 100644
> --- a/drivers/media/platform/Kconfig
> +++ b/drivers/media/platform/Kconfig
> @@ -26,6 +26,7 @@ config VIDEO_VIA_CAMERA
>  #
>  # Platform multimedia device configuration
>  #
> +source "drivers/media/platform/cadence/Kconfig"
>  
>  source "drivers/media/platform/davinci/Kconfig"
>  
> diff --git a/drivers/media/platform/Makefile b/drivers/media/platform/Makefile
> index 7f3080437be6..3d29082fcf72 100644
> --- a/drivers/media/platform/Makefile
> +++ b/drivers/media/platform/Makefile
> @@ -3,6 +3,8 @@
>  # Makefile for the video capture/playback device drivers.
>  #
>  
> +obj-$(CONFIG_VIDEO_CADENCE)  += cadence/
> +
>  obj-$(CONFIG_VIDEO_M32R_AR_M64278) += arv.o
>  
>  obj-$(CONFIG_VIDEO_VIA_CAMERA) += via-camera.o
> diff --git a/drivers/media/platform/cadence/Kconfig 
> b/drivers/media/platform/cadence/Kconfig
> new file mode 100644
> index ..18f061e5cbd1
> --- /dev/null
> +++ b/drivers/media/platform/cadence/Kconfig
> @@ -0,0 +1,17 @@
> +config VIDEO_CADENCE
> + bool "Cadence Video Devices"
> +
> +if VIDEO_CADENCE
> +
> +config VIDEO_CADENCE_CSI2RX
> + tristate "Cadence MIPI-CSI2 RX Controller"
> + depends on MEDIA_CONTROLLER
> + depends on VIDEO_V4L2_SUBDEV_API
> + select V4L2_FWNODE
> + help
> +   Support for the Cadence MIPI CSI2 Receiver controller.
> +
> +   To compile this driver as a module, choose M here: the module will be
> +   called cdns-csi2rx.
> +
> +endif
> diff --git a/drivers/media/platform/cadence/Makefile 
> b/drivers/media/platform/cadence/Makefile
> new file mode 100644
> index ..99a4086b7448
> --- /dev/null
> +++ b/drivers/media/platform/cadence/Makefile
> @@ -0,0 +1 @@
> +obj-$(CONFIG_VIDEO_CADENCE_CSI2RX)   += cdns-csi2rx.o
> diff --git a/drivers/media/platform/cadence/cdns-csi2rx.c 
> b/drivers/media/platform/cadence/cdns-csi2rx.c
> new file mode 100644
> index ..99662e1a536b
> --- /dev/null
> +++ b/drivers/media/platform/cadence/cdns-csi2rx.c
> @@ -0,0 +1,499 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * Driver for Cadence MIPI-CSI2 RX Controller v1.3
> + *
> + * Copyright (C) 2017 Cadence Design Systems Inc.
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#define CSI2RX_DEVICE_CFG_REG0x000
> +
> +#define CSI2RX_SOFT_RESET_REG0x004
> +#define CSI2RX_SOFT_RESET_PROTOCOL   BIT(1)
> +#define CSI2RX_SOFT_RESET_FRONT  BIT(0)
> +
> +#define CSI2RX_STATIC_CFG_REG0x008
> +#define CSI2RX_STATIC_CFG_DLANE_MAP(llane, plane)((plane) << (16 + 
> (llane) * 4))
> +#define CSI2RX_STATIC_CFG_LANES_MASK GENMASK(11, 8)
> +
> +#define CSI2RX_STREAM_BASE(n)(((n) + 1) * 0x100)
> +
> +#define CSI2RX_STREAM_CTRL_REG(n)(CSI2RX_STREAM_BASE(n) + 0x000)
> +#define CSI2RX_STREAM_CTRL_START BIT(0)
> +
> +#define CSI2RX_STREAM_DATA_CFG_REG(n)(CSI2RX_STREAM_BASE(n) 
> + 0x008)
> +#define CSI2RX_STREAM_DATA_CFG_EN_VC_SELECT  BIT(31)
> +#define CSI2RX_STREAM_DATA_CFG_VC_SELECT(n)  BIT((n) + 16)
> +
> +#define CSI2RX_STREAM_CFG_REG(n) (CSI2RX_STREAM_BASE(n) + 0x00c)
> +#define CSI2RX_STREAM_CFG_FIFO_MODE_LARGE_BUF(1 << 8)
> +
> +#define CSI2RX_LANES_MAX 4
> +#define CSI2RX_STREAMS_MAX   4
> +
> +enum csi2rx_pads {
> + CSI2RX_PAD_SINK,
> + CSI2RX_PAD_SOURCE_STREAM0,
> + CSI2RX_PAD_SOURCE_STREAM1,
> + 

Re: [PATCH v2 2/2] v4l: cadence: Add Cadence MIPI-CSI2 TX driver

2018-01-29 Thread Benoit Parrot
Maxime,

Thank you for the patch.

Maxime Ripard  wrote on Fri [2018-Jan-19 
09:15:47 +0100]:
> The Cadence MIPI-CSI2 TX controller is an hardware block meant to be used
> as a bridge between pixel interfaces and a CSI-2 bus.
> 
> It supports operating with an internal or external D-PHY, with up to 4
> lanes, or without any D-PHY. The current code only supports the former
> case.
> 
> While the virtual channel input on the pixel interface can be directly
> mapped to CSI2, the datatype input is actually a selection signal (3-bits)
> mapping to a table of up to 8 preconfigured datatypes/formats (programmed
> at start-up)
> 
> The block supports up to 8 input datatypes.
> 
> Signed-off-by: Maxime Ripard 
> ---
>  drivers/media/platform/cadence/Kconfig   |   6 +
>  drivers/media/platform/cadence/Makefile  |   1 +
>  drivers/media/platform/cadence/cdns-csi2tx.c | 586 
> +++
>  3 files changed, 593 insertions(+)
>  create mode 100644 drivers/media/platform/cadence/cdns-csi2tx.c
> 
> diff --git a/drivers/media/platform/cadence/Kconfig 
> b/drivers/media/platform/cadence/Kconfig
> index d1b6bbb6a0eb..db49328ee8b2 100644
> --- a/drivers/media/platform/cadence/Kconfig
> +++ b/drivers/media/platform/cadence/Kconfig
> @@ -9,4 +9,10 @@ config VIDEO_CADENCE_CSI2RX
>   depends on VIDEO_V4L2_SUBDEV_API
>   select V4L2_FWNODE
>  
> +config VIDEO_CADENCE_CSI2TX
> + tristate "Cadence MIPI-CSI2 TX Controller"
> + depends on MEDIA_CONTROLLER
> + depends on VIDEO_V4L2_SUBDEV_API
> + select V4L2_FWNODE
> +
>  endif
> diff --git a/drivers/media/platform/cadence/Makefile 
> b/drivers/media/platform/cadence/Makefile
> index 99a4086b7448..7fe992273162 100644
> --- a/drivers/media/platform/cadence/Makefile
> +++ b/drivers/media/platform/cadence/Makefile
> @@ -1 +1,2 @@
>  obj-$(CONFIG_VIDEO_CADENCE_CSI2RX)   += cdns-csi2rx.o
> +obj-$(CONFIG_VIDEO_CADENCE_CSI2TX)   += cdns-csi2tx.o
> diff --git a/drivers/media/platform/cadence/cdns-csi2tx.c 
> b/drivers/media/platform/cadence/cdns-csi2tx.c
> new file mode 100644
> index ..850701020836
> --- /dev/null
> +++ b/drivers/media/platform/cadence/cdns-csi2tx.c
> @@ -0,0 +1,586 @@
> +/*
> + * Driver for Cadence MIPI-CSI2 TX Controller
> + *
> + * Copyright (C) 2017 Cadence Design Systems Inc.
> + *
> + * This program is free software; you can redistribute  it and/or modify it
> + * under  the terms of  the GNU General  Public License as published by the
> + * Free Software Foundation;  either version 2 of the  License, or (at your
> + * option) any later version.

Should use SPDX license tag line instead.

> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#define CSI2TX_DEVICE_CONFIG_REG 0x00
> +
> +#define CSI2TX_CONFIG_REG0x20
> +#define CSI2TX_CONFIG_CFG_REQBIT(2)
> +#define CSI2TX_CONFIG_SRST_REQ   BIT(1)
> +
> +#define CSI2TX_DPHY_CFG_REG  0x28
> +#define CSI2TX_DPHY_CFG_CLK_RESETBIT(16)
> +#define CSI2TX_DPHY_CFG_LANE_RESET(n)BIT((n) + 12)
> +#define CSI2TX_DPHY_CFG_MODE_MASKGENMASK(9, 8)
> +#define CSI2TX_DPHY_CFG_MODE_LPDT(2 << 8)
> +#define CSI2TX_DPHY_CFG_MODE_HS  (1 << 8)
> +#define CSI2TX_DPHY_CFG_MODE_ULPS(0 << 8)
> +#define CSI2TX_DPHY_CFG_CLK_ENABLE   BIT(4)
> +#define CSI2TX_DPHY_CFG_LANE_ENABLE(n)   BIT(n)
> +
> +#define CSI2TX_DPHY_CLK_WAKEUP_REG   0x2c
> +#define CSI2TX_DPHY_CLK_WAKEUP_ULPS_CYCLES(n)((n) & 0x)
> +
> +#define CSI2TX_DT_CFG_REG(n) (0x80 + (n) * 8)
> +#define CSI2TX_DT_CFG_DT(n)  (((n) & 0x3f) << 2)
> +
> +#define CSI2TX_DT_FORMAT_REG(n)  (0x84 + (n) * 8)
> +#define CSI2TX_DT_FORMAT_BYTES_PER_LINE(n)   (((n) & 0x) << 16)
> +#define CSI2TX_DT_FORMAT_MAX_LINE_NUM(n) ((n) & 0x)
> +
> +#define CSI2TX_STREAM_IF_CFG_REG(n)  (0x100 + (n) * 4)
> +#define CSI2TX_STREAM_IF_CFG_FILL_LEVEL(n)   ((n) & 0x1f)
> +
> +#define CSI2TX_STREAMS_MAX   4
> +
> +enum csi2tx_pads {
> + CSI2TX_PAD_SOURCE,
> + CSI2TX_PAD_SINK_STREAM0,
> + CSI2TX_PAD_SINK_STREAM1,
> + CSI2TX_PAD_SINK_STREAM2,
> + CSI2TX_PAD_SINK_STREAM3,
> + CSI2TX_PAD_MAX,
> +};
> +
> +struct csi2tx_fmt {
> + u32 mbus;
> + u32 dt;
> + u32 bpp;
> +};
> +
> +struct csi2tx_priv {
> + struct device   *dev;
> + atomic_tcount;
> +
> + void __iomem*base;
> +
> + struct clk  *esc_clk;
> + struct clk  *p_clk;
> + struct clk  *pixel_clk[CSI2TX_STREAMS_MAX];
> +
> + struct v4l2_subdev  subdev;
> + struct 

Re: [PATCH v5 2/2] v4l: cadence: Add Cadence MIPI-CSI2 RX driver

2018-01-29 Thread Benoit Parrot
Maxime,

Thank you for the patch.

Maxime Ripard  wrote on Fri [2018-Jan-19 
09:13:57 +0100]:
> The Cadence CSI-2 RX Controller is an hardware block meant to be used as a
> bridge between a CSI-2 bus and pixel grabbers.
> 
> It supports operating with internal or external D-PHY, with up to 4 lanes,
> or without any D-PHY. The current code only supports the former case.
> 
> It also support dynamic mapping of the CSI-2 virtual channels to the
> associated pixel grabbers, but that isn't allowed at the moment either.
> 
> Signed-off-by: Maxime Ripard 
> ---
>  drivers/media/platform/Kconfig   |   1 +
>  drivers/media/platform/Makefile  |   2 +
>  drivers/media/platform/cadence/Kconfig   |  12 +
>  drivers/media/platform/cadence/Makefile  |   1 +
>  drivers/media/platform/cadence/cdns-csi2rx.c | 463 
> +++
>  5 files changed, 479 insertions(+)
>  create mode 100644 drivers/media/platform/cadence/Kconfig
>  create mode 100644 drivers/media/platform/cadence/Makefile
>  create mode 100644 drivers/media/platform/cadence/cdns-csi2rx.c
> 
> diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig
> index fd0c99859d6f..6e790a317fbc 100644
> --- a/drivers/media/platform/Kconfig
> +++ b/drivers/media/platform/Kconfig
> @@ -26,6 +26,7 @@ config VIDEO_VIA_CAMERA
>  #
>  # Platform multimedia device configuration
>  #
> +source "drivers/media/platform/cadence/Kconfig"
>  
>  source "drivers/media/platform/davinci/Kconfig"
>  
> diff --git a/drivers/media/platform/Makefile b/drivers/media/platform/Makefile
> index 003b0bb2cddf..1cd2984c55d1 100644
> --- a/drivers/media/platform/Makefile
> +++ b/drivers/media/platform/Makefile
> @@ -3,6 +3,8 @@
>  # Makefile for the video capture/playback device drivers.
>  #
>  
> +obj-$(CONFIG_VIDEO_CADENCE)  += cadence/
> +
>  obj-$(CONFIG_VIDEO_M32R_AR_M64278) += arv.o
>  
>  obj-$(CONFIG_VIDEO_VIA_CAMERA) += via-camera.o
> diff --git a/drivers/media/platform/cadence/Kconfig 
> b/drivers/media/platform/cadence/Kconfig
> new file mode 100644
> index ..d1b6bbb6a0eb
> --- /dev/null
> +++ b/drivers/media/platform/cadence/Kconfig
> @@ -0,0 +1,12 @@
> +config VIDEO_CADENCE
> + bool "Cadence Video Devices"
> +
> +if VIDEO_CADENCE
> +
> +config VIDEO_CADENCE_CSI2RX
> + tristate "Cadence MIPI-CSI2 RX Controller v1.3"
> + depends on MEDIA_CONTROLLER
> + depends on VIDEO_V4L2_SUBDEV_API
> + select V4L2_FWNODE
> +
> +endif
> diff --git a/drivers/media/platform/cadence/Makefile 
> b/drivers/media/platform/cadence/Makefile
> new file mode 100644
> index ..99a4086b7448
> --- /dev/null
> +++ b/drivers/media/platform/cadence/Makefile
> @@ -0,0 +1 @@
> +obj-$(CONFIG_VIDEO_CADENCE_CSI2RX)   += cdns-csi2rx.o
> diff --git a/drivers/media/platform/cadence/cdns-csi2rx.c 
> b/drivers/media/platform/cadence/cdns-csi2rx.c
> new file mode 100644
> index ..ce042b9d403c
> --- /dev/null
> +++ b/drivers/media/platform/cadence/cdns-csi2rx.c
> @@ -0,0 +1,463 @@
> +/*
> + * Driver for Cadence MIPI-CSI2 RX Controller v1.3
> + *
> + * Copyright (C) 2017 Cadence Design Systems Inc.
> + *
> + * This program is free software; you can redistribute  it and/or modify it
> + * under  the terms of  the GNU General  Public License as published by the
> + * Free Software Foundation;  either version 2 of the  License, or (at your
> + * option) any later version.

This being a new driver, it would probably make sense to replace the above
license text with the appropriate SPDX license tag line.

> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#define CSI2RX_DEVICE_CFG_REG0x000
> +
> +#define CSI2RX_SOFT_RESET_REG0x004
> +#define CSI2RX_SOFT_RESET_PROTOCOL   BIT(1)
> +#define CSI2RX_SOFT_RESET_FRONT  BIT(0)
> +
> +#define CSI2RX_STATIC_CFG_REG0x008
> +#define CSI2RX_STATIC_CFG_DLANE_MAP(llane, plane)((plane) << (16 + 
> (llane) * 4))
> +#define CSI2RX_STATIC_CFG_LANES_MASK GENMASK(11, 8)
> +
> +#define CSI2RX_STREAM_BASE(n)(((n) + 1) * 0x100)
> +
> +#define CSI2RX_STREAM_CTRL_REG(n)(CSI2RX_STREAM_BASE(n) + 0x000)
> +#define CSI2RX_STREAM_CTRL_START BIT(0)
> +
> +#define CSI2RX_STREAM_DATA_CFG_REG(n)(CSI2RX_STREAM_BASE(n) 
> + 0x008)
> +#define CSI2RX_STREAM_DATA_CFG_EN_VC_SELECT  BIT(31)
> +#define CSI2RX_STREAM_DATA_CFG_VC_SELECT(n)  BIT((n) + 16)
> +
> +#define CSI2RX_STREAM_CFG_REG(n) (CSI2RX_STREAM_BASE(n) + 0x00c)
> +#define CSI2RX_STREAM_CFG_FIFO_MODE_LARGE_BUF(1 << 8)
> +
> +#define CSI2RX_LANES_MAX 4
> +#define 

Re: [PATCH 3/8] media: v4l2-async: simplify v4l2_async_subdev structure

2017-12-18 Thread Benoit Parrot
For am437x/am437x-vpfe.c & ti-vpe/cal.c

Acked-by: Benoit Parrot <bpar...@ti.com>

Mauro Carvalho Chehab <mche...@s-opensource.com> wrote on Mon [2017-Dec-18 
17:53:57 -0200]:
> The V4L2_ASYNC_MATCH_FWNODE match criteria requires just one
> struct to be filled (struct fwnode_handle). The V4L2_ASYNC_MATCH_DEVNAME
> match criteria requires just a device name.
> 
> So, it doesn't make sense to enclose those into structs,
> as the criteria can go directly into the union.
> 
> That makes easier to document it, as we don't need to document
> weird senseless structs.
> 
> At drivers, this makes even clearer about the match criteria.
> 
> Acked-by: Sylwester Nawrocki <s.nawro...@samsung.com>
> Signed-off-by: Mauro Carvalho Chehab <mche...@s-opensource.com>
> ---
>  drivers/media/platform/am437x/am437x-vpfe.c|  6 +++---
>  drivers/media/platform/atmel/atmel-isc.c   |  2 +-
>  drivers/media/platform/atmel/atmel-isi.c   |  2 +-
>  drivers/media/platform/davinci/vpif_capture.c  |  4 ++--
>  drivers/media/platform/exynos4-is/media-dev.c  |  4 ++--
>  drivers/media/platform/pxa_camera.c|  2 +-
>  drivers/media/platform/qcom/camss-8x16/camss.c |  2 +-
>  drivers/media/platform/rcar-vin/rcar-core.c|  2 +-
>  drivers/media/platform/rcar_drif.c |  4 ++--
>  drivers/media/platform/soc_camera/soc_camera.c |  2 +-
>  drivers/media/platform/stm32/stm32-dcmi.c  |  2 +-
>  drivers/media/platform/ti-vpe/cal.c|  2 +-
>  drivers/media/platform/xilinx/xilinx-vipp.c|  2 +-
>  drivers/media/v4l2-core/v4l2-async.c   | 16 
>  drivers/media/v4l2-core/v4l2-fwnode.c  | 10 +-
>  drivers/staging/media/imx/imx-media-dev.c  |  4 ++--
>  include/media/v4l2-async.h |  8 ++--
>  17 files changed, 35 insertions(+), 39 deletions(-)
> 
> diff --git a/drivers/media/platform/am437x/am437x-vpfe.c 
> b/drivers/media/platform/am437x/am437x-vpfe.c
> index 0997c640191d..601ae6487617 100644
> --- a/drivers/media/platform/am437x/am437x-vpfe.c
> +++ b/drivers/media/platform/am437x/am437x-vpfe.c
> @@ -2304,8 +2304,8 @@ vpfe_async_bound(struct v4l2_async_notifier *notifier,
>   vpfe_dbg(1, vpfe, "vpfe_async_bound\n");
>  
>   for (i = 0; i < ARRAY_SIZE(vpfe->cfg->asd); i++) {
> - if (vpfe->cfg->asd[i]->match.fwnode.fwnode ==
> - asd[i].match.fwnode.fwnode) {
> + if (vpfe->cfg->asd[i]->match.fwnode ==
> + asd[i].match.fwnode) {
>   sdinfo = >cfg->sub_devs[i];
>   vpfe->sd[i] = subdev;
>   vpfe->sd[i]->grp_id = sdinfo->grp_id;
> @@ -2510,7 +2510,7 @@ vpfe_get_pdata(struct platform_device *pdev)
>   }
>  
>   pdata->asd[i]->match_type = V4L2_ASYNC_MATCH_FWNODE;
> - pdata->asd[i]->match.fwnode.fwnode = of_fwnode_handle(rem);
> + pdata->asd[i]->match.fwnode = of_fwnode_handle(rem);
>   of_node_put(rem);
>   }
>  
> diff --git a/drivers/media/platform/atmel/atmel-isc.c 
> b/drivers/media/platform/atmel/atmel-isc.c
> index 0c2635647f69..34676409ca08 100644
> --- a/drivers/media/platform/atmel/atmel-isc.c
> +++ b/drivers/media/platform/atmel/atmel-isc.c
> @@ -2088,7 +2088,7 @@ static int isc_parse_dt(struct device *dev, struct 
> isc_device *isc)
>   subdev_entity->pfe_cfg0 |= ISC_PFE_CFG0_PPOL_LOW;
>  
>   subdev_entity->asd->match_type = V4L2_ASYNC_MATCH_FWNODE;
> - subdev_entity->asd->match.fwnode.fwnode =
> + subdev_entity->asd->match.fwnode =
>   of_fwnode_handle(rem);
>   list_add_tail(_entity->list, >subdev_entities);
>   }
> diff --git a/drivers/media/platform/atmel/atmel-isi.c 
> b/drivers/media/platform/atmel/atmel-isi.c
> index e900995143a3..9958918e2449 100644
> --- a/drivers/media/platform/atmel/atmel-isi.c
> +++ b/drivers/media/platform/atmel/atmel-isi.c
> @@ -1128,7 +1128,7 @@ static int isi_graph_parse(struct atmel_isi *isi, 
> struct device_node *node)
>   /* Remote node to connect */
>   isi->entity.node = remote;
>   isi->entity.asd.match_type = V4L2_ASYNC_MATCH_FWNODE;
> - isi->entity.asd.match.fwnode.fwnode = of_fwnode_handle(remote);
> + isi->entity.asd.match.fwnode = of_fwnode_handle(remote);
>   return 0;
>   }
>  }
> diff --git a/drivers/media/platform/davinci/vpif_capture.c 
> b/drivers/media/platform/davinci/vpif_capture.c
> index e45916f69def..e1

Re: [Patch 4/6] dt-bindings: media: ti-vpe: Document VPE driver

2017-10-18 Thread Benoit Parrot
Rob Herring <r...@kernel.org> wrote on Tue [2017-Oct-17 16:00:51 -0500]:
> On Thu, Oct 12, 2017 at 02:27:17PM -0500, Benoit Parrot wrote:
> > Device Tree bindings for the Video Processing Engine (VPE) driver.
> > 
> > Signed-off-by: Benoit Parrot <bpar...@ti.com>
> > ---
> >  Documentation/devicetree/bindings/media/ti-vpe.txt | 41 
> > ++
> >  1 file changed, 41 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 ..c2ef93d08417
> > --- /dev/null
> > +++ b/Documentation/devicetree/bindings/media/ti-vpe.txt
> > @@ -0,0 +1,41 @@
> > +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 SoC specific compatibles.

This particular I/P is present on all DRA7x family of devices
so would "ti,dra7-vpe" be acceptable?

> 
> > +- reg: physical base address and length of the registers set for the 8
> > +   memory regions required;
> > +- reg-names: name associated with the memory regions described is ;
> > +- interrupts: should contain IRQ line for VPE;
> > +
> > +Example:
> > +   vpe {
> > +   compatible = "ti,vpe";
> > +   ti,hwmods = "vpe";
> > +   clocks = <_core_h23x2_ck>;
> > +   clock-names = "fck";
> > +   reg =   <0x489d 0x120>,
> > +   <0x489d0300 0x20>,
> > +   <0x489d0400 0x20>,
> > +   <0x489d0500 0x20>,
> > +   <0x489d0600 0x3c>,
> > +   <0x489d0700 0x80>,
> 
> Is there other stuff between these regions?

No, they listed separately because each sub-region/module is
individually mapped and accessed using a starting 0 offset.

> 
> > +   <0x489d5700 0x18>,
> > +   <0x489dd000 0x400>;
> > +   reg-names = "vpe_top",
> > +   "vpe_chr_us0",
> > +   "vpe_chr_us1",
> > +   "vpe_chr_us2",
> > +   "vpe_dei",
> > +   "sc",
> > +   "csc",
> > +   "vpdma";
> > +   interrupts = ;
> 
> > +   #address-cells = <1>;
> > +   #size-cells = <0>;
> 
> These aren't needed.

OK, I'll remove those.

Benoit

> 
> > +   };
> > -- 
> > 2.9.0
> > 


Re: [Patch 5/6] ARM: DRA7: hwmod: Add VPE nodes

2017-10-13 Thread Benoit Parrot
Tony Lindgren <t...@atomide.com> wrote on Fri [2017-Oct-13 10:05:13 -0700]:
> * Benoit Parrot <bpar...@ti.com> [171012 12:28]:
> > +static struct omap_hwmod_class_sysconfig dra7xx_vpe_sysc = {
> > +   .sysc_offs  = 0x0010,
> > +   .sysc_flags = (SYSC_HAS_MIDLEMODE | SYSC_HAS_SIDLEMODE),
> > +   .idlemodes  = (SIDLE_FORCE | SIDLE_NO | SIDLE_SMART |
> > +  MSTANDBY_FORCE | MSTANDBY_NO |
> > +  MSTANDBY_SMART),
> > +   .sysc_fields= _hwmod_sysc_type2,
> > +};
> 
> I think checkpatch.pl --strict would complain about unnecessary
> parentheses, might as well check the whole series while at it.

I actually ran the whole series through "checkpatch.pl --strict"
before posting. And other then the usual MAINTAINER file needing
update warning for the binding patch it no other warning or error.

Based on the rest of the file I believe the parentheses around those
flags are at least consistent.

Now, would the .rev_offs comment also apply here?

Benoit

> 
> Regards,
> 
> Tony


Re: [Patch 3/6] ARM: OMAP: DRA7xx: Make CAM clock domain SWSUP only

2017-10-13 Thread Benoit Parrot
Tony Lindgren <t...@atomide.com> wrote on Fri [2017-Oct-13 10:01:13 -0700]:
> * Benoit Parrot <bpar...@ti.com> [171012 12:29]:
> > HWSUP on this domain is only working when VIP1 probes.
> > If only VIP2 on DRA74x or CAL on DRA72x probes the domain does
> > not get enabled. This might indicates an issue in the HW Auto
> > state-machine for this domain.
> >
> > Work around is to set the CAM domain to use SWSUP only.
> 
> Hmm this you might get fixed automatically by configuring the
> parent interconnect target module to use "ti,sysc-omap4" and
> adding VIP1 and VIP2 as children to it.
> 
> The reason why I suspect it will fix the issue is because
> with the parent being "ti,sysc-omap4" with "ti,hwmods" being
> in that parent node too, you automatically get PM runtime
> refcounting keep the parent active for either child.
> 
> Maybe give it a try against today's Linux next and see for
> example how it was done for musb:
> 
> https://patchwork.kernel.org/patch/9978783/
> 
> Just use "ti,sysc-omap2" for type1 and "ti,sysc-omap4"
> for type2.

Hmm interesting, I'll give that a try and if it fixes it.

Benoit

> 
> Regards,
> 
> Tony


Re: [Patch 2/6] ARM: DRA7: hwmod: Add CAL nodes

2017-10-13 Thread Benoit Parrot
Tony Lindgren <t...@atomide.com> wrote on Fri [2017-Oct-13 09:56:54 -0700]:
> * Benoit Parrot <bpar...@ti.com> [171012 12:28]:
> > This patch adds the required hwmod nodes to support the Camera
> > Adaptation Layer (CAL) for the DRA72 family of devices.
> ...
> 
> > +static struct omap_hwmod_class_sysconfig dra7xx_cal_sysc = {
> > +   .sysc_offs  = 0x0010,
> 
> Also has .rev_offs at 0 so please add that too.

Ok, I'll add that.

Benoit

> 
> Regards,
> 
> Tony


Re: [Patch 1/6] ARM: dts: DRA72: Add CAL dtsi node

2017-10-13 Thread Benoit Parrot
Tony Lindgren <t...@atomide.com> wrote on Fri [2017-Oct-13 09:54:09 -0700]:
> * Benoit Parrot <bpar...@ti.com> [171012 12:29]:
> > This patch adds the required dtsi node to support the Camera
> > Adaptation Layer (CAL) for the DRA72 family of devices.
> > 
> > - Added CAL entry in dra72x.dtsi.
> > 
> > Signed-off-by: Benoit Parrot <bpar...@ti.com>
> > ---
> >  arch/arm/boot/dts/dra72x.dtsi | 31 +++
> >  1 file changed, 31 insertions(+)
> > 
> > diff --git a/arch/arm/boot/dts/dra72x.dtsi b/arch/arm/boot/dts/dra72x.dtsi
> > index 67107605fb4c..d0ba4f238084 100644
> > --- a/arch/arm/boot/dts/dra72x.dtsi
> > +++ b/arch/arm/boot/dts/dra72x.dtsi
> > @@ -17,6 +17,37 @@
> > interrupt-parent = <>;
> > interrupts = ;
> > };
> > +
> > +   ocp {
> > +   cal: cal@4845b000 {
> > +   compatible = "ti,dra72-cal";
> > +   ti,hwmods = "cal";
> > +   reg = <0x4845B000 0x400>,
> > + <0x4845B800 0x40>,
> > + <0x4845B900 0x40>,
> > + <0x4A002e94 0x4>;
> 
> Care to fix the cAmelcasing here? All lower case hex is pretty much the
> standard with linux, so might as well lower case them all while at it.

Sure thing, I'll fix it.

Benoit

> 
> Regards,
> 
> Tony


Re: [ANN] Agenda (v1) for the media mini-summit on Friday Oct 27 in Prague

2017-10-13 Thread Benoit Parrot
Hans,

Just to confirm that I will be attending the media mini-summit.

Regards,
Benoit


Hans Verkuil  wrote on Fri [2017-Oct-13 10:02:53 +0200]:
> Hi all,
> 
> We are organizing a media mini-summit on Friday October 27 in Prague, 
> co-located
> with the ELCE conference:
> 
> http://events.linuxfoundation.org/events/embedded-linux-conference-europe
> 
> If you plan to attend, please let me know. It is open for all, but it is
> nice if we know beforehand who we can expect.
> 
> Location: Mauro, do you have this information?
> 
> Attendees:
> 
> Sakari Ailus 
> Mauro Carvalho Chehab 
> Alexandre Courbot 
> Michael Ira Krufky 
> Gustavo Padovan 
> Laurent Pinchart 
> Ricardo Ribalda Delgado 
> Hans Verkuil 
> 
> Agenda
> ==
> 
> General remarks: the given start/end times for the various topics are
> approximate since it is always hard to predict how long a discussion will 
> take.
> The Request/Jobs API topic is placed last since I expect that that will take
> most of our time.
> 
> Let me know asap if there are problems with this schedule, or if new topics
> are requested.
> 
> 8:00-9:00: Continental Breakfast served in the room
> 
> 9:00-9:15: Introduction (Hans)
> 
> 9:15-9:30: Status of the HDMI CEC kernel support (Hans)
>  Give a quick overview of the status: what has been merged, what is 
> still
>  pending, what is under development.
> 
> 9:30-10:00: V4L2 Explicit Synchronization (Gustavo)
>   Quick overview and discussion of the API/direction we are going
> with fences.
> 
> 10:00-10:30 Media development process: what works, what doesn't (Hans)
>   In the past 6 months or so we tried to improve the media development
>   process. This is an overview of what we did and why we did it, what
>   works and what doesn't. Feedback is very much appreciated. It is 
> even
>   more appreciated if people/companies would be willing to assign
>   new developers to help improve the media subsystem!
> 
> 10:30-11:00: Morning Break served in the room
> 
> 11:00-12:00: Media kAPI and uAPI documentation (Mauro)
>Give the current status of media API documentation and identify 
> possible
>gaps and how to improve it.
> 
> 12:00-13:30: Lunch
> 
> 13:30-??:??: Request/jobs API (Alexandre)
>Overview of the work based on the request API (proposed new name: 
> jobs API),
>to hopefully converge to something that can be merged soon.
> 
> 15:00-15:30: Afternoon Break served in the room
> 
> 16:30-17:00 (or earlier if we're lucky): Wrap up (Hans)
>Create action items (and who will take care of them) if needed.
>Summarize and conclude the day.
> 
> Regards,
> 
>   Hans


[Patch 4/6] dt-bindings: media: ti-vpe: Document VPE driver

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

Signed-off-by: Benoit Parrot <bpar...@ti.com>
---
 Documentation/devicetree/bindings/media/ti-vpe.txt | 41 ++
 1 file changed, 41 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 ..c2ef93d08417
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/ti-vpe.txt
@@ -0,0 +1,41 @@
+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 8
+   memory regions required;
+- reg-names: name associated with the memory regions described is ;
+- interrupts: should contain IRQ line for VPE;
+
+Example:
+   vpe {
+   compatible = "ti,vpe";
+   ti,hwmods = "vpe";
+   clocks = <_core_h23x2_ck>;
+   clock-names = "fck";
+   reg =   <0x489d 0x120>,
+   <0x489d0300 0x20>,
+   <0x489d0400 0x20>,
+   <0x489d0500 0x20>,
+   <0x489d0600 0x3c>,
+   <0x489d0700 0x80>,
+   <0x489d5700 0x18>,
+   <0x489dd000 0x400>;
+   reg-names = "vpe_top",
+   "vpe_chr_us0",
+   "vpe_chr_us1",
+   "vpe_chr_us2",
+   "vpe_dei",
+   "sc",
+   "csc",
+   "vpdma";
+   interrupts = ;
+   #address-cells = <1>;
+   #size-cells = <0>;
+   };
-- 
2.9.0



[Patch 0/6] ARM: dts/hwmod: Add CAL and VPE nodes

2017-10-12 Thread Benoit Parrot
This patch series adds the needed HWMOD and DTSI nodes
for the CAL and VPE modules.
We also document the VPE DT bindings.

Benoit Parrot (6):
  ARM: dts: DRA72: Add CAL dtsi node
  ARM: DRA7: hwmod: Add CAL nodes
  ARM: OMAP: DRA7xx: Make CAM clock domain SWSUP only
  dt-bindings: media: ti-vpe: Document VPE driver
  ARM: DRA7: hwmod: Add VPE nodes
  ARM: dts: dra7: Add VPE dtsi node

 Documentation/devicetree/bindings/media/ti-vpe.txt | 41 ++
 arch/arm/boot/dts/dra7.dtsi| 26 +++
 arch/arm/boot/dts/dra72x.dtsi  | 31 
 arch/arm/mach-omap2/clockdomains7xx_data.c |  2 +-
 arch/arm/mach-omap2/omap_hwmod_7xx_data.c  | 87 ++
 5 files changed, 186 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/devicetree/bindings/media/ti-vpe.txt

-- 
2.9.0



[Patch 2/6] ARM: DRA7: hwmod: Add CAL nodes

2017-10-12 Thread Benoit Parrot
This patch adds the required hwmod nodes to support the Camera
Adaptation Layer (CAL) for the DRA72 family of devices.

- Added CAL hwmod entry in the DRA72x section.

The DRA72x TRM (Literature Number SPRUHP2x) states that CAL only
support NO_IDLE, FORCE_IDLE and SMART_IDLE.
Although CAL does not support standby mode per se hwmod would not
enabled the functional/interface clock if module is not a master.
Hence the SWSUP mode flags ifor SIDLE ans MSTANDBY are also enabled.
This ensure that i/f clocks are available when CAL is enabled.

Signed-off-by: Benoit Parrot <bpar...@ti.com>
---
 arch/arm/mach-omap2/omap_hwmod_7xx_data.c | 44 +++
 1 file changed, 44 insertions(+)

diff --git a/arch/arm/mach-omap2/omap_hwmod_7xx_data.c 
b/arch/arm/mach-omap2/omap_hwmod_7xx_data.c
index 2f4f7002f38d..fc53b498975c 100644
--- a/arch/arm/mach-omap2/omap_hwmod_7xx_data.c
+++ b/arch/arm/mach-omap2/omap_hwmod_7xx_data.c
@@ -240,6 +240,41 @@ static struct omap_hwmod dra7xx_bb2d_hwmod = {
 };
 
 /*
+ * 'cal' class
+ *
+ */
+
+static struct omap_hwmod_class_sysconfig dra7xx_cal_sysc = {
+   .sysc_offs  = 0x0010,
+   .sysc_flags = (SYSC_HAS_SIDLEMODE | SYSC_HAS_RESET_STATUS |
+  SYSC_HAS_SOFTRESET | SYSC_HAS_MIDLEMODE),
+   .idlemodes  = (SIDLE_FORCE | SIDLE_NO | SIDLE_SMART |
+  MSTANDBY_FORCE | MSTANDBY_NO),
+   .sysc_fields= _hwmod_sysc_type2,
+};
+
+static struct omap_hwmod_class dra7xx_cal_hwmod_class = {
+   .name   = "cal",
+   .sysc   = _cal_sysc,
+};
+
+/* cal */
+static struct omap_hwmod dra7xx_cal_hwmod = {
+   .name   = "cal",
+   .class  = _cal_hwmod_class,
+   .clkdm_name = "cam_clkdm",
+   .main_clk   = "vip2_gclk_mux",
+   .flags  = (HWMOD_SWSUP_SIDLE | HWMOD_SWSUP_MSTANDBY),
+   .prcm = {
+   .omap4 = {
+   .clkctrl_offs = DRA7XX_CM_CAM_VIP2_CLKCTRL_OFFSET,
+   .context_offs = DRA7XX_RM_CAM_VIP2_CONTEXT_OFFSET,
+   .modulemode   = MODULEMODE_HWCTRL,
+   },
+   },
+};
+
+/*
  * 'counter' class
  *
  */
@@ -3901,6 +3936,14 @@ static struct omap_hwmod_ocp_if dra7xx_l4_per2__vcp2 = {
.user   = OCP_USER_MPU | OCP_USER_SDMA,
 };
 
+/* l4_per3 -> cal */
+static struct omap_hwmod_ocp_if dra7xx_l4_per3__cal = {
+   .master = _l4_per3_hwmod,
+   .slave  = _cal_hwmod,
+   .clk= "l3_iclk_div",
+   .user   = OCP_USER_MPU | OCP_USER_SDMA,
+};
+
 /* l4_wkup -> wd_timer2 */
 static struct omap_hwmod_ocp_if dra7xx_l4_wkup__wd_timer2 = {
.master = _l4_wkup_hwmod,
@@ -4082,6 +4125,7 @@ static struct omap_hwmod_ocp_if *dra74x_hwmod_ocp_ifs[] 
__initdata = {
 };
 
 static struct omap_hwmod_ocp_if *dra72x_hwmod_ocp_ifs[] __initdata = {
+   _l4_per3__cal,
NULL,
 };
 
-- 
2.9.0



[Patch 6/6] ARM: dts: dra7: Add VPE dtsi node

2017-10-12 Thread Benoit Parrot
Add the necessary node and configuration data for the VPE (Video
Processing Engine) hardware block on DRA7x.

The corresponding driver for this entry is in
drivers/media/platform/ti-vpe/vpe.c.

Signed-off-by: Benoit Parrot <bpar...@ti.com>
---
 arch/arm/boot/dts/dra7.dtsi | 26 ++
 1 file changed, 26 insertions(+)

diff --git a/arch/arm/boot/dts/dra7.dtsi b/arch/arm/boot/dts/dra7.dtsi
index 02a136a4661a..f302d2e5eede 100644
--- a/arch/arm/boot/dts/dra7.dtsi
+++ b/arch/arm/boot/dts/dra7.dtsi
@@ -2018,6 +2018,32 @@
clocks = <_iclk_div>;
clock-names = "fck";
};
+
+   vpe {
+   compatible = "ti,vpe";
+   ti,hwmods = "vpe";
+   clocks = <_core_h23x2_ck>;
+   clock-names = "fck";
+   reg = <0x489d 0x120>,
+ <0x489d0300 0x20>,
+ <0x489d0400 0x20>,
+ <0x489d0500 0x20>,
+ <0x489d0600 0x3c>,
+ <0x489d0700 0x80>,
+ <0x489d5700 0x18>,
+ <0x489dd000 0x400>;
+   reg-names = "vpe_top",
+   "vpe_chr_us0",
+   "vpe_chr_us1",
+   "vpe_chr_us2",
+   "vpe_dei",
+   "sc",
+   "csc",
+   "vpdma";
+   interrupts = ;
+   #address-cells = <1>;
+   #size-cells = <0>;
+   };
};
 
thermal_zones: thermal-zones {
-- 
2.9.0



[Patch 1/6] ARM: dts: DRA72: Add CAL dtsi node

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

- Added CAL entry in dra72x.dtsi.

Signed-off-by: Benoit Parrot <bpar...@ti.com>
---
 arch/arm/boot/dts/dra72x.dtsi | 31 +++
 1 file changed, 31 insertions(+)

diff --git a/arch/arm/boot/dts/dra72x.dtsi b/arch/arm/boot/dts/dra72x.dtsi
index 67107605fb4c..d0ba4f238084 100644
--- a/arch/arm/boot/dts/dra72x.dtsi
+++ b/arch/arm/boot/dts/dra72x.dtsi
@@ -17,6 +17,37 @@
interrupt-parent = <>;
interrupts = ;
};
+
+   ocp {
+   cal: cal@4845b000 {
+   compatible = "ti,dra72-cal";
+   ti,hwmods = "cal";
+   reg = <0x4845B000 0x400>,
+ <0x4845B800 0x40>,
+ <0x4845B900 0x40>,
+ <0x4A002e94 0x4>;
+   reg-names = "cal_top",
+   "cal_rx_core0",
+   "cal_rx_core1",
+   "camerrx_control";
+   interrupts = ;
+   #address-cells = <1>;
+   #size-cells = <0>;
+   status = "disabled";
+
+   ports {
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   csi2_0: port@0 {
+   reg = <0>;
+   };
+   csi2_1: port@1 {
+   reg = <1>;
+   };
+   };
+   };
+   };
 };
 
  {
-- 
2.9.0



[Patch 3/6] ARM: OMAP: DRA7xx: Make CAM clock domain SWSUP only

2017-10-12 Thread Benoit Parrot
HWSUP on this domain is only working when VIP1 probes.
If only VIP2 on DRA74x or CAL on DRA72x probes the domain does
not get enabled. This might indicates an issue in the HW Auto
state-machine for this domain.

Work around is to set the CAM domain to use SWSUP only.

Signed-off-by: Benoit Parrot <bpar...@ti.com>
---
 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 67ebff829cf2..dd37efa2c652 100644
--- a/arch/arm/mach-omap2/clockdomains7xx_data.c
+++ b/arch/arm/mach-omap2/clockdomains7xx_data.c
@@ -609,7 +609,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.9.0



[Patch 5/6] ARM: DRA7: hwmod: Add VPE nodes

2017-10-12 Thread Benoit Parrot
Add hwmod entries for VPE (Video Processing Engine) hardware block
found in DRA7x family of devices.

DRA75x_DRA74x_ES1.1 Version T Technical Reference Manual
(Literature Number SPRUHI2T) states that VPE only support NO_STANDBY,
FORCE_STANDBY, NO_IDLE, FORCE_IDLE and SMART_IDLE.
The hwmod flags were set to reflect this fact and make sure that
both are software supervised (SWSUSP).

Signed-off-by: Benoit Parrot <bpar...@ti.com>
---
 arch/arm/mach-omap2/omap_hwmod_7xx_data.c | 43 +++
 1 file changed, 43 insertions(+)

diff --git a/arch/arm/mach-omap2/omap_hwmod_7xx_data.c 
b/arch/arm/mach-omap2/omap_hwmod_7xx_data.c
index fc53b498975c..c0bbc1099a11 100644
--- a/arch/arm/mach-omap2/omap_hwmod_7xx_data.c
+++ b/arch/arm/mach-omap2/omap_hwmod_7xx_data.c
@@ -240,6 +240,40 @@ static struct omap_hwmod dra7xx_bb2d_hwmod = {
 };
 
 /*
+ * 'vpe' class
+ *
+ */
+
+static struct omap_hwmod_class_sysconfig dra7xx_vpe_sysc = {
+   .sysc_offs  = 0x0010,
+   .sysc_flags = (SYSC_HAS_MIDLEMODE | SYSC_HAS_SIDLEMODE),
+   .idlemodes  = (SIDLE_FORCE | SIDLE_NO | SIDLE_SMART |
+  MSTANDBY_FORCE | MSTANDBY_NO |
+  MSTANDBY_SMART),
+   .sysc_fields= _hwmod_sysc_type2,
+};
+
+static struct omap_hwmod_class dra7xx_vpe_hwmod_class = {
+   .name   = "vpe",
+   .sysc   = _vpe_sysc,
+};
+
+/* vpe */
+static struct omap_hwmod dra7xx_vpe_hwmod = {
+   .name   = "vpe",
+   .class  = _vpe_hwmod_class,
+   .clkdm_name = "vpe_clkdm",
+   .flags  = (HWMOD_SWSUP_SIDLE | HWMOD_SWSUP_MSTANDBY),
+   .prcm = {
+   .omap4 = {
+   .clkctrl_offs = DRA7XX_CM_VPE_VPE_CLKCTRL_OFFSET,
+   .context_offs = DRA7XX_RM_VPE_VPE_CONTEXT_OFFSET,
+   .modulemode   = MODULEMODE_HWCTRL,
+   },
+   },
+};
+
+/*
  * 'cal' class
  *
  */
@@ -3936,6 +3970,14 @@ static struct omap_hwmod_ocp_if dra7xx_l4_per2__vcp2 = {
.user   = OCP_USER_MPU | OCP_USER_SDMA,
 };
 
+/* l4_per3 -> vpe */
+static struct omap_hwmod_ocp_if dra7xx_l4_per3__vpe = {
+   .master = _l4_per3_hwmod,
+   .slave  = _vpe_hwmod,
+   .clk= "l3_iclk_div",
+   .user   = OCP_USER_MPU | OCP_USER_SDMA,
+};
+
 /* l4_per3 -> cal */
 static struct omap_hwmod_ocp_if dra7xx_l4_per3__cal = {
.master = _l4_per3_hwmod,
@@ -4099,6 +4141,7 @@ static struct omap_hwmod_ocp_if *dra7xx_hwmod_ocp_ifs[] 
__initdata = {
_l4_per2__vcp1,
_l3_main_1__vcp2,
_l4_per2__vcp2,
+   _l4_per3__vpe,
_l4_wkup__wd_timer2,
_l4_per2__epwmss0,
_l4_per2__epwmss1,
-- 
2.9.0



Re: [PATCH 2/2] v4l: cadence: Add Cadence MIPI-CSI2 TX driver

2017-10-11 Thread Benoit Parrot
Hi Maxime,

Maxime Ripard <maxime.rip...@free-electrons.com> wrote on Wed [2017-Oct-11 
13:55:44 +0200]:
> Hi Benoit,
> 
> On Fri, Sep 29, 2017 at 06:21:25PM +, Benoit Parrot wrote:
> > > +struct csi2tx_priv {
> > > + struct device   *dev;
> > > + atomic_tcount;
> > > +
> > > + void __iomem*base;
> > > +
> > > + struct clk  *esc_clk;
> > > + struct clk  *p_clk;
> > > + struct clk  *pixel_clk[CSI2TX_STREAMS_MAX];
> > > +
> > > + struct v4l2_subdev  subdev;
> > > + struct media_padpads[CSI2TX_PAD_MAX];
> > > + struct v4l2_mbus_framefmt   pad_fmts[CSI2TX_PAD_MAX];
> > > +
> > > + boolhas_internal_dphy;
> > 
> > I assume dphy support is for a subsequent revision?
> 
> Yes, the situation is similar to the CSI2-RX driver.
> 
> > > + /*
> > > +  * We use the stream ID there, but it's wrong.
> > > +  *
> > > +  * A stream could very well send a data type that is
> > > +  * not equal to its stream ID. We need to find a
> > > +  * proper way to address it.
> > > +  */
> > 
> > I don't quite get the above comment, from the code below it looks like
> > you are using the current fmt as a source to provide the correct DT.
> > Am I missing soemthing?
> 
> Yes, so far the datatype is inferred from the format set. Is there
> anything wrong with that?

No, nothing wrong with that behavior it just doesn't not match the comment
above, where it is says that the DT is set to the stream ID...

Regards,
Benoit



Re: [PATCH v4 2/2] v4l: cadence: Add Cadence MIPI-CSI2 RX driver

2017-10-11 Thread Benoit Parrot
Hi Maxime,

Maxime Ripard <maxime.rip...@free-electrons.com> wrote on Wed [2017-Oct-11 
11:24:09 +0200]:
> Hi Benoit,
> 
> On Fri, Sep 29, 2017 at 05:27:09PM +, Benoit Parrot wrote:
> > > +static int csi2rx_get_resources(struct csi2rx_priv *csi2rx,
> > > + struct platform_device *pdev)
> > > +{
> > > + struct resource *res;
> > > + unsigned char i;
> > > + u32 reg;
> > > +
> > > + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> > > + csi2rx->base = devm_ioremap_resource(>dev, res);
> > > + if (IS_ERR(csi2rx->base))
> > > + return PTR_ERR(csi2rx->base);
> > > +
> > > + csi2rx->sys_clk = devm_clk_get(>dev, "sys_clk");
> > > + if (IS_ERR(csi2rx->sys_clk)) {
> > > + dev_err(>dev, "Couldn't get sys clock\n");
> > > + return PTR_ERR(csi2rx->sys_clk);
> > > + }
> > > +
> > > + csi2rx->p_clk = devm_clk_get(>dev, "p_clk");
> > > + if (IS_ERR(csi2rx->p_clk)) {
> > > + dev_err(>dev, "Couldn't get P clock\n");
> > > + return PTR_ERR(csi2rx->p_clk);
> > > + }
> > > +
> > > + csi2rx->dphy = devm_phy_optional_get(>dev, "dphy");
> > > + if (IS_ERR(csi2rx->dphy)) {
> > > + dev_err(>dev, "Couldn't get external D-PHY\n");
> > > + return PTR_ERR(csi2rx->dphy);
> > > + }
> > > +
> > > + /*
> > > +  * FIXME: Once we'll have external D-PHY support, the check
> > > +  * will need to be removed.
> > > +  */
> > > + if (csi2rx->dphy) {
> > > + dev_err(>dev, "External D-PHY not supported yet\n");
> > > + return -EINVAL;
> > > + }
> > 
> > I understand that in your current environment you do not have a
> > DPHY. But I am wondering in a real setup where you will have either
> > an internal or an external DPHY, how are they going to interact with
> > this driver or vice-versa?
> 
> It's difficult to give an answer with so little details. How would you
> choose between those two PHYs? Is there a mux, or should we just power
> one of the two? If that's the case, is there any use case were we
> might want to power both? If not, which one should we favor, in which
> situations?

Oops, I guess I should clarify, in this case I did not mean we would
have both an internal and an external DPHY. I just meant one or the other.
Basically just want to see how you would actually handle a DPHY here whether
it's internal or external?

For instance, using direct register access from within this driver or make
use of an separate phy driver...

> 
> I guess all those questions actually depend on the way the integration
> has been done, and we're not quite there yet. I guess we could do
> either a platform specific structure or a glue, depending on the
> complexity. The platform specific compatible will allow us to do that
> as we see fit anyway.
> 

Regards,
Benoit



Re: [PATCH 2/2] v4l: cadence: Add Cadence MIPI-CSI2 TX driver

2017-09-29 Thread Benoit Parrot
Maxime,

Thank you for the patch.

Maxime Ripard  wrote on Fri [2017-Sep-22 
13:47:03 +0200]:
> The Cadence MIPI-CSI2 TX controller is an hardware block meant to be used
> as a bridge between pixel interfaces and a CSI-2 bus.
> 
> It supports operating with an internal or external D-PHY, with up to 4
> lanes, or without any D-PHY. The current code only supports the former
> case.
> 
> While the virtual channel input on the pixel interface can be directly
> mapped to CSI2, the datatype input is actually a selection signal (3-bits)
> mapping to a table of up to 8 preconfigured datatypes/formats (programmed
> at start-up)
> 
> The block supports up to 8 input datatypes.
> 
> Signed-off-by: Maxime Ripard 
> ---
>  drivers/media/platform/cadence/Kconfig   |   6 +
>  drivers/media/platform/cadence/Makefile  |   1 +
>  drivers/media/platform/cadence/cdns-csi2tx.c | 479 
> +++
>  3 files changed, 486 insertions(+)
>  create mode 100644 drivers/media/platform/cadence/cdns-csi2tx.c
> 
> diff --git a/drivers/media/platform/cadence/Kconfig 
> b/drivers/media/platform/cadence/Kconfig
> index d1b6bbb6a0eb..db49328ee8b2 100644
> --- a/drivers/media/platform/cadence/Kconfig
> +++ b/drivers/media/platform/cadence/Kconfig
> @@ -9,4 +9,10 @@ config VIDEO_CADENCE_CSI2RX
>   depends on VIDEO_V4L2_SUBDEV_API
>   select V4L2_FWNODE
>  
> +config VIDEO_CADENCE_CSI2TX
> + tristate "Cadence MIPI-CSI2 TX Controller"
> + depends on MEDIA_CONTROLLER
> + depends on VIDEO_V4L2_SUBDEV_API
> + select V4L2_FWNODE
> +
>  endif
> diff --git a/drivers/media/platform/cadence/Makefile 
> b/drivers/media/platform/cadence/Makefile
> index 99a4086b7448..7fe992273162 100644
> --- a/drivers/media/platform/cadence/Makefile
> +++ b/drivers/media/platform/cadence/Makefile
> @@ -1 +1,2 @@
>  obj-$(CONFIG_VIDEO_CADENCE_CSI2RX)   += cdns-csi2rx.o
> +obj-$(CONFIG_VIDEO_CADENCE_CSI2TX)   += cdns-csi2tx.o
> diff --git a/drivers/media/platform/cadence/cdns-csi2tx.c 
> b/drivers/media/platform/cadence/cdns-csi2tx.c
> new file mode 100644
> index ..859bbce8772b
> --- /dev/null
> +++ b/drivers/media/platform/cadence/cdns-csi2tx.c
> @@ -0,0 +1,479 @@
> +/*
> + * Driver for Cadence MIPI-CSI2 TX Controller
> + *
> + * Copyright (C) 2017 Cadence Design Systems Inc.
> + *
> + * This program is free software; you can redistribute  it and/or modify it
> + * under  the terms of  the GNU General  Public License as published by the
> + * Free Software Foundation;  either version 2 of the  License, or (at your
> + * option) any later version.
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#define CSI2TX_DEVICE_CONFIG_REG 0x00
> +
> +#define CSI2TX_CONFIG_REG0x20
> +#define CSI2TX_CONFIG_CFG_REQBIT(2)
> +#define CSI2TX_CONFIG_SRST_REQ   BIT(1)
> +
> +#define CSI2TX_DPHY_CFG_REG  0x28
> +#define CSI2TX_DPHY_CFG_CLK_RESETBIT(16)
> +#define CSI2TX_DPHY_CFG_LANE_RESET(n)BIT((n) + 12)
> +#define CSI2TX_DPHY_CFG_MODE_MASKGENMASK(9, 8)
> +#define CSI2TX_DPHY_CFG_MODE_LPDT(2 << 8)
> +#define CSI2TX_DPHY_CFG_MODE_HS  (1 << 8)
> +#define CSI2TX_DPHY_CFG_MODE_ULPS(0 << 8)
> +#define CSI2TX_DPHY_CFG_CLK_ENABLE   BIT(4)
> +#define CSI2TX_DPHY_CFG_LANE_ENABLE(n)   BIT(n)
> +
> +#define CSI2TX_DPHY_CLK_WAKEUP_REG   0x2c
> +#define CSI2TX_DPHY_CLK_WAKEUP_ULPS_CYCLES(n)((n) & 0x)
> +
> +#define CSI2TX_DT_CFG_REG(n) (0x80 + (n) * 8)
> +#define CSI2TX_DT_CFG_DT(n)  (((n) & 0x3f) << 2)
> +
> +#define CSI2TX_DT_FORMAT_REG(n)  (0x84 + (n) * 8)
> +#define CSI2TX_DT_FORMAT_BYTES_PER_LINE(n)   (((n) & 0x) << 16)
> +#define CSI2TX_DT_FORMAT_MAX_LINE_NUM(n) ((n) & 0x)
> +
> +#define CSI2TX_STREAM_IF_CFG_REG(n)  (0x100 + (n) * 4)
> +#define CSI2TX_STREAM_IF_CFG_FILL_LEVEL(n)   ((n) & 0x1f)
> +
> +#define CSI2TX_STREAMS_MAX   4
> +
> +enum csi2tx_pads {
> + CSI2TX_PAD_SOURCE,
> + CSI2TX_PAD_SINK_STREAM0,
> + CSI2TX_PAD_SINK_STREAM1,
> + CSI2TX_PAD_SINK_STREAM2,
> + CSI2TX_PAD_SINK_STREAM3,
> + CSI2TX_PAD_MAX,
> +};
> +
> +struct csi2tx_fmt {
> + u32 mbus;
> + u32 dt;
> + u32 bpp;
> +};
> +
> +struct csi2tx_priv {
> + struct device   *dev;
> + atomic_tcount;
> +
> + void __iomem*base;
> +
> + struct clk  *esc_clk;
> + struct clk  *p_clk;
> + struct clk  *pixel_clk[CSI2TX_STREAMS_MAX];
> +
> + struct v4l2_subdev  subdev;
> + struct media_padpads[CSI2TX_PAD_MAX];
> + struct 

Re: [PATCH v4 2/2] v4l: cadence: Add Cadence MIPI-CSI2 RX driver

2017-09-29 Thread Benoit Parrot
Maxime Ripard  wrote on Fri [2017-Sep-22 
12:08:23 +0200]:
> The Cadence CSI-2 RX Controller is an hardware block meant to be used as a
> bridge between a CSI-2 bus and pixel grabbers.
> 
> It supports operating with internal or external D-PHY, with up to 4 lanes,
> or without any D-PHY. The current code only supports the former case.
> 
> It also support dynamic mapping of the CSI-2 virtual channels to the
> associated pixel grabbers, but that isn't allowed at the moment either.
> 
> Signed-off-by: Maxime Ripard 
> ---
>  drivers/media/platform/Kconfig   |   1 +
>  drivers/media/platform/Makefile  |   2 +
>  drivers/media/platform/cadence/Kconfig   |  12 +
>  drivers/media/platform/cadence/Makefile  |   1 +
>  drivers/media/platform/cadence/cdns-csi2rx.c | 486 
> +++
>  5 files changed, 502 insertions(+)
>  create mode 100644 drivers/media/platform/cadence/Kconfig
>  create mode 100644 drivers/media/platform/cadence/Makefile
>  create mode 100644 drivers/media/platform/cadence/cdns-csi2rx.c
> 



> +static int csi2rx_get_resources(struct csi2rx_priv *csi2rx,
> + struct platform_device *pdev)
> +{
> + struct resource *res;
> + unsigned char i;
> + u32 reg;
> +
> + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> + csi2rx->base = devm_ioremap_resource(>dev, res);
> + if (IS_ERR(csi2rx->base))
> + return PTR_ERR(csi2rx->base);
> +
> + csi2rx->sys_clk = devm_clk_get(>dev, "sys_clk");
> + if (IS_ERR(csi2rx->sys_clk)) {
> + dev_err(>dev, "Couldn't get sys clock\n");
> + return PTR_ERR(csi2rx->sys_clk);
> + }
> +
> + csi2rx->p_clk = devm_clk_get(>dev, "p_clk");
> + if (IS_ERR(csi2rx->p_clk)) {
> + dev_err(>dev, "Couldn't get P clock\n");
> + return PTR_ERR(csi2rx->p_clk);
> + }
> +
> + csi2rx->dphy = devm_phy_optional_get(>dev, "dphy");
> + if (IS_ERR(csi2rx->dphy)) {
> + dev_err(>dev, "Couldn't get external D-PHY\n");
> + return PTR_ERR(csi2rx->dphy);
> + }
> +
> + /*
> +  * FIXME: Once we'll have external D-PHY support, the check
> +  * will need to be removed.
> +  */
> + if (csi2rx->dphy) {
> + dev_err(>dev, "External D-PHY not supported yet\n");
> + return -EINVAL;
> + }

I understand that in your current environment you do not have a
DPHY. But I am wondering in a real setup where you will have either
an internal or an external DPHY, how are they going to interact with
this driver or vice-versa?

> +
> + clk_prepare_enable(csi2rx->p_clk);
> + reg = readl(csi2rx->base + CSI2RX_DEVICE_CFG_REG);
> + clk_disable_unprepare(csi2rx->p_clk);
> +
> + csi2rx->max_lanes = (reg & 7);
> + if (csi2rx->max_lanes > CSI2RX_LANES_MAX) {
> + dev_err(>dev, "Invalid number of lanes: %u\n",
> + csi2rx->max_lanes);
> + return -EINVAL;
> + }
> +
> + csi2rx->max_streams = ((reg >> 4) & 7);
> + if (csi2rx->max_streams > CSI2RX_STREAMS_MAX) {
> + dev_err(>dev, "Invalid number of streams: %u\n",
> + csi2rx->max_streams);
> + return -EINVAL;
> + }
> +
> + csi2rx->has_internal_dphy = (reg & BIT(3)) ? true : false;
> +
> + /*
> +  * FIXME: Once we'll have internal D-PHY support, the check
> +  * will need to be removed.
> +  */
> + if (csi2rx->has_internal_dphy) {
> + dev_err(>dev, "Internal D-PHY not supported yet\n");
> + return -EINVAL;
> + }
> +
> + for (i = 0; i < csi2rx->max_streams; i++) {
> + char clk_name[16];
> +
> + snprintf(clk_name, sizeof(clk_name), "pixel_if%u_clk", i);
> + csi2rx->pixel_clk[i] = devm_clk_get(>dev, clk_name);
> + if (IS_ERR(csi2rx->pixel_clk[i])) {
> + dev_err(>dev, "Couldn't get clock %s\n", 
> clk_name);
> + return PTR_ERR(csi2rx->pixel_clk[i]);
> + }
> + }
> +
> + return 0;
> +}
> +
> +static int csi2rx_parse_dt(struct csi2rx_priv *csi2rx)
> +{
> + struct v4l2_fwnode_endpoint v4l2_ep;
> + struct device_node *ep, *remote;

*remote is now unused.

Regards,
Benoit




Re: [PATCH v3 2/2] v4l: cadence: Add Cadence MIPI-CSI2 RX driver

2017-09-12 Thread Benoit Parrot
Benoit Parrot <bpar...@ti.com> wrote on Tue [2017-Sep-12 13:23:39 -0500]:



> > +static int csi2rx_start(struct csi2rx_priv *csi2rx)
> > +{
> > +   unsigned int i;
> > +   u32 reg;
> > +   int ret;
> > +
> > +   /*
> > +* We're not the first users, there's no need to enable the
> > +* whole controller.
> > +*/
> > +   if (atomic_inc_return(>count) > 1)
> > +   return 0;
> > +
> > +   clk_prepare_enable(csi2rx->p_clk);
> > +
> > +   printk("%s %d\n", __func__, __LINE__);
> 
> Some left over debug...
> 
> > +
> > +   csi2rx_reset(csi2rx);
> > +
> > +   reg = csi2rx->num_lanes << 8;
> > +   for (i = 0; i < csi2rx->num_lanes; i++)
> > +   reg |= CSI2RX_STATIC_CFG_DLANE_MAP(i, csi2rx->lanes[i]);
> > +
> > +   writel(reg, csi2rx->base + CSI2RX_STATIC_CFG_REG);
> > +
> > +   ret = v4l2_subdev_call(csi2rx->source_subdev, video, s_stream, true);
> > +   if (ret)
> > +   return ret;
> > +
> > +   /*
> > +* Create a static mapping between the CSI virtual channels
> > +* and the output stream.
> > +*
> > +* This should be enhanced, but v4l2 lacks the support for
> > +* changing that mapping dynamically.
> > +*
> > +* We also cannot enable and disable independant streams here,
> > +* hence the reference counting.
> > +*/
> > +   for (i = 0; i < csi2rx->max_streams; i++) {
> > +   clk_prepare_enable(csi2rx->pixel_clk[i]);
> > +
> > +   writel(CSI2RX_STREAM_CFG_FIFO_MODE_LARGE_BUF,
> > +  csi2rx->base + CSI2RX_STREAM_CFG_REG(i));
> > +
> > +   writel(CSI2RX_STREAM_DATA_CFG_EN_VC_SELECT |
> > +  CSI2RX_STREAM_DATA_CFG_VC_SELECT(i),
> > +  csi2rx->base + CSI2RX_STREAM_DATA_CFG_REG(i));

I see here that we are setting the data_type to 0 (as we are not setting
it) so effectively capturing everything on the channel(s).
Will we be adding a method to select/filter specific data type?
For instance if we only want to grab YUV data in one stream and only
RGB24 in another. Of course that would not be possible here as is...

Benoit

> > +
> > +   writel(CSI2RX_STREAM_CTRL_START,
> > +  csi2rx->base + CSI2RX_STREAM_CTRL_REG(i));
> > +   }
> > +
> > +   clk_prepare_enable(csi2rx->sys_clk);
> > +
> > +   clk_disable_unprepare(csi2rx->p_clk);
> > +
> > +   return 0;
> > +}




Re: [PATCH v3 2/2] v4l: cadence: Add Cadence MIPI-CSI2 RX driver

2017-09-12 Thread Benoit Parrot
Maxime,

Thanks for the patch.

Maxime Ripard  wrote on Mon [2017-Sep-04 
15:03:35 +0200]:
> The Cadence CSI-2 RX Controller is an hardware block meant to be used as a
> bridge between a CSI-2 bus and pixel grabbers.
> 
> It supports operating with internal or external D-PHY, with up to 4 lanes,
> or without any D-PHY. The current code only supports the former case.
> 
> It also support dynamic mapping of the CSI-2 virtual channels to the
> associated pixel grabbers, but that isn't allowed at the moment either.
> 
> Signed-off-by: Maxime Ripard 
> ---
>  drivers/media/platform/Kconfig   |   1 +
>  drivers/media/platform/Makefile  |   2 +
>  drivers/media/platform/cadence/Kconfig   |  12 +
>  drivers/media/platform/cadence/Makefile  |   1 +
>  drivers/media/platform/cadence/cdns-csi2rx.c | 494 
> +++
>  5 files changed, 510 insertions(+)
>  create mode 100644 drivers/media/platform/cadence/Kconfig
>  create mode 100644 drivers/media/platform/cadence/Makefile
>  create mode 100644 drivers/media/platform/cadence/cdns-csi2rx.c
>



> diff --git a/drivers/media/platform/cadence/cdns-csi2rx.c 
> b/drivers/media/platform/cadence/cdns-csi2rx.c
> new file mode 100644
> index ..e662b1890bba
> --- /dev/null
> +++ b/drivers/media/platform/cadence/cdns-csi2rx.c
> @@ -0,0 +1,494 @@
> +/*
> + * Driver for Cadence MIPI-CSI2 RX Controller v1.3
> + *
> + * Copyright (C) 2017 Cadence Design Systems Inc.
> + *
> + * This program is free software; you can redistribute  it and/or modify it
> + * under  the terms of  the GNU General  Public License as published by the
> + * Free Software Foundation;  either version 2 of the  License, or (at your
> + * option) any later version.
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#define CSI2RX_DEVICE_CFG_REG0x000
> +
> +#define CSI2RX_SOFT_RESET_REG0x004
> +#define CSI2RX_SOFT_RESET_PROTOCOL   BIT(1)
> +#define CSI2RX_SOFT_RESET_FRONT  BIT(0)
> +
> +#define CSI2RX_STATIC_CFG_REG0x008
> +#define CSI2RX_STATIC_CFG_DLANE_MAP(llane, plane)((plane) << (16 + 
> (llane) * 4))
> +#define CSI2RX_STATIC_CFG_LANES_MASK GENMASK(11, 8)
> +
> +#define CSI2RX_STREAM_BASE(n)(((n) + 1) * 0x100)
> +
> +#define CSI2RX_STREAM_CTRL_REG(n)(CSI2RX_STREAM_BASE(n) + 0x000)
> +#define CSI2RX_STREAM_CTRL_START BIT(0)
> +
> +#define CSI2RX_STREAM_DATA_CFG_REG(n)(CSI2RX_STREAM_BASE(n) 
> + 0x008)
> +#define CSI2RX_STREAM_DATA_CFG_EN_VC_SELECT  BIT(31)
> +#define CSI2RX_STREAM_DATA_CFG_VC_SELECT(n)  BIT((n) + 16)
> +
> +#define CSI2RX_STREAM_CFG_REG(n) (CSI2RX_STREAM_BASE(n) + 0x00c)
> +#define CSI2RX_STREAM_CFG_FIFO_MODE_LARGE_BUF(1 << 8)
> +
> +#define CSI2RX_STREAMS_MAX   4
> +
> +enum csi2rx_pads {
> + CSI2RX_PAD_SINK,
> + CSI2RX_PAD_SOURCE_STREAM0,
> + CSI2RX_PAD_SOURCE_STREAM1,
> + CSI2RX_PAD_SOURCE_STREAM2,
> + CSI2RX_PAD_SOURCE_STREAM3,
> + CSI2RX_PAD_MAX,
> +};
> +
> +struct csi2rx_priv {
> + struct device   *dev;
> + atomic_tcount;
> +
> + void __iomem*base;
> + struct clk  *sys_clk;
> + struct clk  *p_clk;
> + struct clk  *pixel_clk[CSI2RX_STREAMS_MAX];
> + struct phy  *dphy;
> +
> + u8  lanes[4];
> + u8  num_lanes;
> + u8  max_lanes;
> + u8  max_streams;
> + boolhas_internal_dphy;
> +
> + struct v4l2_subdev  subdev;
> + struct media_padpads[CSI2RX_PAD_MAX];
> +
> + /* Remote source */
> + struct v4l2_async_subdevasd;
> + struct device_node  *source_node;
> + struct v4l2_subdev  *source_subdev;
> + int source_pad;
> +};
> +
> +static inline
> +struct csi2rx_priv *v4l2_subdev_to_csi2rx(struct v4l2_subdev *subdev)
> +{
> + return container_of(subdev, struct csi2rx_priv, subdev);
> +}
> +
> +static void csi2rx_reset(struct csi2rx_priv *csi2rx)
> +{
> + writel(CSI2RX_SOFT_RESET_PROTOCOL | CSI2RX_SOFT_RESET_FRONT,
> +csi2rx->base + CSI2RX_SOFT_RESET_REG);
> +
> + usleep_range(10, 20);
> +
> + writel(0, csi2rx->base + CSI2RX_SOFT_RESET_REG);
> +}
> +
> +static int csi2rx_start(struct csi2rx_priv *csi2rx)
> +{
> + unsigned int i;
> + u32 reg;
> + int ret;
> +
> + /*
> +  * 

Re: [PATCH v2 1/2] dt-bindings: media: Add Cadence MIPI-CSI2 RX Device Tree bindings

2017-08-07 Thread Benoit Parrot
Maxime Ripard <maxime.rip...@free-electrons.com> wrote on Thu [2017-Jul-20 
11:23:01 +0200]:
> The Cadence MIPI-CSI2 RX controller is a CSI2RX bridge that supports up to
> 4 CSI-2 lanes, and can route the frames to up to 4 streams, depending on
> the hardware implementation.
> 
> It can operate with an external D-PHY, an internal one or no D-PHY at all
> in some configurations.
> 
> Signed-off-by: Maxime Ripard <maxime.rip...@free-electrons.com>
> ---
>  .../devicetree/bindings/media/cdns-csi2rx.txt  | 87 
> ++
>  1 file changed, 87 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/media/cdns-csi2rx.txt
> 

Acked-by: Benoit Parrot <bpar...@ti.com>


Re: [PATCH v2 2/2] v4l: cadence: Add Cadence MIPI-CSI2 RX driver

2017-08-07 Thread Benoit Parrot
Maxime Ripard  wrote on Thu [2017-Jul-20 
11:23:02 +0200]:
> The Cadence CSI-2 RX Controller is an hardware block meant to be used as a
> bridge between a CSI-2 bus and pixel grabbers.
> 
> It supports operating with internal or external D-PHY, with up to 4 lanes,
> or without any D-PHY. The current code only supports the former case.
> 
> It also support dynamic mapping of the CSI-2 virtual channels to the
> associated pixel grabbers, but that isn't allowed at the moment either.
> 
> Signed-off-by: Maxime Ripard 
> ---
>  drivers/media/platform/Kconfig   |   1 +
>  drivers/media/platform/Makefile  |   2 +
>  drivers/media/platform/cadence/Kconfig   |  12 +
>  drivers/media/platform/cadence/Makefile  |   1 +
>  drivers/media/platform/cadence/cdns-csi2rx.c | 413 
> +++
>  5 files changed, 429 insertions(+)
>  create mode 100644 drivers/media/platform/cadence/Kconfig
>  create mode 100644 drivers/media/platform/cadence/Makefile
>  create mode 100644 drivers/media/platform/cadence/cdns-csi2rx.c
> 
> diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig
> index 1313cd533436..a79d96e9b723 100644
> --- a/drivers/media/platform/Kconfig
> +++ b/drivers/media/platform/Kconfig
> @@ -26,6 +26,7 @@ config VIDEO_VIA_CAMERA
>  #
>  # Platform multimedia device configuration
>  #
> +source "drivers/media/platform/cadence/Kconfig"
>  
>  source "drivers/media/platform/davinci/Kconfig"
>  
> diff --git a/drivers/media/platform/Makefile b/drivers/media/platform/Makefile
> index 9beadc760467..1d31eb51e9bb 100644
> --- a/drivers/media/platform/Makefile
> +++ b/drivers/media/platform/Makefile
> @@ -2,6 +2,8 @@
>  # Makefile for the video capture/playback device drivers.
>  #
>  
> +obj-$(CONFIG_VIDEO_CADENCE)  += cadence/
> +
>  obj-$(CONFIG_VIDEO_M32R_AR_M64278) += arv.o
>  
>  obj-$(CONFIG_VIDEO_VIA_CAMERA) += via-camera.o
> diff --git a/drivers/media/platform/cadence/Kconfig 
> b/drivers/media/platform/cadence/Kconfig
> new file mode 100644
> index ..d1b6bbb6a0eb
> --- /dev/null
> +++ b/drivers/media/platform/cadence/Kconfig
> @@ -0,0 +1,12 @@
> +config VIDEO_CADENCE
> + bool "Cadence Video Devices"
> +
> +if VIDEO_CADENCE
> +
> +config VIDEO_CADENCE_CSI2RX
> + tristate "Cadence MIPI-CSI2 RX Controller v1.3"
> + depends on MEDIA_CONTROLLER
> + depends on VIDEO_V4L2_SUBDEV_API
> + select V4L2_FWNODE
> +
> +endif
> diff --git a/drivers/media/platform/cadence/Makefile 
> b/drivers/media/platform/cadence/Makefile
> new file mode 100644
> index ..99a4086b7448
> --- /dev/null
> +++ b/drivers/media/platform/cadence/Makefile
> @@ -0,0 +1 @@
> +obj-$(CONFIG_VIDEO_CADENCE_CSI2RX)   += cdns-csi2rx.o
> diff --git a/drivers/media/platform/cadence/cdns-csi2rx.c 
> b/drivers/media/platform/cadence/cdns-csi2rx.c
> new file mode 100644
> index ..9a58f275f53c
> --- /dev/null
> +++ b/drivers/media/platform/cadence/cdns-csi2rx.c
> @@ -0,0 +1,413 @@
> +/*
> + * Driver for Cadence MIPI-CSI2 RX Controller v1.3
> + *
> + * Copyright (C) 2017 Cadence Design Systems Inc.
> + *
> + * This program is free software; you can redistribute  it and/or modify it
> + * under  the terms of  the GNU General  Public License as published by the
> + * Free Software Foundation;  either version 2 of the  License, or (at your
> + * option) any later version.
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#define CSI2RX_DEVICE_CFG_REG0x000
> +
> +#define CSI2RX_SOFT_RESET_REG0x004
> +#define CSI2RX_SOFT_RESET_PROTOCOL   BIT(1)
> +#define CSI2RX_SOFT_RESET_FRONT  BIT(0)
> +
> +#define CSI2RX_STATIC_CFG_REG0x008
> +
> +#define CSI2RX_STREAM_BASE(n)(((n) + 1) * 0x100)
> +
> +#define CSI2RX_STREAM_CTRL_REG(n)(CSI2RX_STREAM_BASE(n) + 0x000)
> +#define CSI2RX_STREAM_CTRL_START BIT(0)
> +
> +#define CSI2RX_STREAM_DATA_CFG_REG(n)(CSI2RX_STREAM_BASE(n) 
> + 0x008)
> +#define CSI2RX_STREAM_DATA_CFG_EN_VC_SELECT  BIT(31)
> +#define CSI2RX_STREAM_DATA_CFG_VC_SELECT(n)  BIT((n) + 16)
> +
> +#define CSI2RX_STREAM_CFG_REG(n) (CSI2RX_STREAM_BASE(n) + 0x00c)
> +#define CSI2RX_STREAM_CFG_FIFO_MODE_LARGE_BUF(1 << 8)
> +
> +#define CSI2RX_STREAMS_MAX   4
> +

Just to confirm here that "streams" in this case are equivalent to
"Virtual Channel", correct?

> +enum csi2rx_pads {
> + CSI2RX_PAD_SINK,
> + CSI2RX_PAD_SOURCE_VC0,
> + CSI2RX_PAD_SOURCE_VC1,
> + CSI2RX_PAD_SOURCE_VC2,
> + CSI2RX_PAD_SOURCE_VC3,
> + CSI2RX_PAD_MAX,
> +};
> +
> +struct csi2rx_priv {
> + struct device   *dev;
> +
> + void __iomem 

Re: [PATCH] davinci: vpif_capture: fix default pixel format for BT.656/BT.1120 video

2017-05-30 Thread Benoit Parrot
Sekhar Nori <nsek...@ti.com> wrote on Fri [2017-May-26 16:25:27 +0530]:
> For both BT.656 and BT.1120 video, the pixel format
> used by VPIF is Y/CbCr 4:2:2 in semi-planar format
> (Luma in one plane and Chroma in another). This
> corresponds to NV16 pixel format.
> 
> This is documented in section 36.2.3 of OMAP-L138
> Technical Reference Manual, SPRUH77A.
> 
> The VPIF driver incorrectly sets the default format
> to V4L2_PIX_FMT_YUV422P. Fix it.
> 
> Reported-by: Alejandro Hernandez <ajhernan...@ti.com>
> Signed-off-by: Sekhar Nori <nsek...@ti.com>
> ---
>  drivers/media/platform/davinci/vpif_capture.c | 10 +-
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 

Acked-by: Benoit Parrot <bpar...@ti.com>



Re: [Patch 0/2] media: ti-vpe: allow user specified stride

2017-03-02 Thread Benoit Parrot
Hans, Mauro,

Ping.

Regards,
Benoit

Tomi Valkeinen <tomi.valkei...@ti.com> wrote on Fri [2017-Feb-17 11:45:41 
+0200]:
> On 13/02/17 15:06, Benoit Parrot wrote:
> > This patch series enables user specified buffer stride to be used
> > instead of always forcing the stride from the driver side.
> > 
> > Benoit Parrot (2):
> >   media: ti-vpe: vpdma: add support for user specified stride
> >   media: ti-vpe: vpe: allow use of user specified stride
> > 
> >  drivers/media/platform/ti-vpe/vpdma.c | 14 --
> >  drivers/media/platform/ti-vpe/vpdma.h |  6 +++---
> >  drivers/media/platform/ti-vpe/vpe.c   | 34 
> > --
> >  3 files changed, 31 insertions(+), 23 deletions(-)
> 
> Reviewed-by: Tomi Valkeinen <tomi.valkei...@ti.com>
> 
>  Tomi
> 





Re: [PATCH v1.1 5/8] v4l: Switch from V4L2 OF not V4L2 fwnode API

2017-02-15 Thread Benoit Parrot

For: ov2569.c, am437x/am437x-vpfe.c and ti-cal/cal.c:

Acked-by: Benoit Parrot <bpar...@ti.com>


Sakari Ailus <sakari.ai...@linux.intel.com> wrote on Tue [2017-Feb-14 09:12:32 
+0200]:
> Switch users of the v4l2_of_ APIs to the more generic v4l2_fwnode_ APIs.
> 
> Existing OF matching continues to be supported. omap3isp and smiapp
> drivers are converted to fwnode matching as well.
> 
> Signed-off-by: Sakari Ailus <sakari.ai...@linux.intel.com>
> ---
> Resending because of a mis-copied e-mail address.
> 
>  drivers/media/i2c/Kconfig  |  9 
>  drivers/media/i2c/adv7604.c|  7 +--
>  drivers/media/i2c/mt9v032.c|  7 +--
>  drivers/media/i2c/ov2659.c |  8 +--
>  drivers/media/i2c/s5c73m3/s5c73m3-core.c   |  7 +--
>  drivers/media/i2c/s5k5baf.c|  6 +--
>  drivers/media/i2c/smiapp/Kconfig   |  1 +
>  drivers/media/i2c/smiapp/smiapp-core.c | 29 ++-
>  drivers/media/i2c/tc358743.c   | 11 ++--
>  drivers/media/i2c/tvp514x.c|  6 +--
>  drivers/media/i2c/tvp5150.c|  7 +--
>  drivers/media/i2c/tvp7002.c|  6 +--
>  drivers/media/platform/Kconfig |  3 ++
>  drivers/media/platform/am437x/Kconfig  |  1 +
>  drivers/media/platform/am437x/am437x-vpfe.c|  8 +--
>  drivers/media/platform/atmel/Kconfig   |  1 +
>  drivers/media/platform/atmel/atmel-isc.c   |  8 +--
>  drivers/media/platform/exynos4-is/Kconfig  |  2 +
>  drivers/media/platform/exynos4-is/media-dev.c  |  6 +--
>  drivers/media/platform/exynos4-is/mipi-csis.c  |  6 +--
>  drivers/media/platform/omap3isp/isp.c  | 71 
> +-
>  drivers/media/platform/pxa_camera.c|  7 +--
>  drivers/media/platform/rcar-vin/Kconfig|  1 +
>  drivers/media/platform/rcar-vin/rcar-core.c|  6 +--
>  drivers/media/platform/soc_camera/Kconfig  |  1 +
>  drivers/media/platform/soc_camera/atmel-isi.c  |  7 +--
>  drivers/media/platform/soc_camera/soc_camera.c |  2 +-
>  drivers/media/platform/ti-vpe/cal.c| 11 ++--
>  drivers/media/platform/xilinx/Kconfig  |  1 +
>  drivers/media/platform/xilinx/xilinx-vipp.c| 59 +++--
>  include/media/v4l2-fwnode.h|  4 +-
>  31 files changed, 175 insertions(+), 134 deletions(-)
> 
> diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
> index cee1dae..6b2423a 100644
> --- a/drivers/media/i2c/Kconfig
> +++ b/drivers/media/i2c/Kconfig
> @@ -210,6 +210,7 @@ config VIDEO_ADV7604
>   depends on GPIOLIB || COMPILE_TEST
>   select HDMI
>   select MEDIA_CEC_EDID
> + select V4L2_FWNODE
>   ---help---
> Support for the Analog Devices ADV7604 video decoder.
>  
> @@ -324,6 +325,7 @@ config VIDEO_TC358743
>   tristate "Toshiba TC358743 decoder"
>   depends on VIDEO_V4L2 && I2C && VIDEO_V4L2_SUBDEV_API
>   select HDMI
> + select V4L2_FWNODE
>   ---help---
> Support for the Toshiba TC358743 HDMI to MIPI CSI-2 bridge.
>  
> @@ -333,6 +335,7 @@ config VIDEO_TC358743
>  config VIDEO_TVP514X
>   tristate "Texas Instruments TVP514x video decoder"
>   depends on VIDEO_V4L2 && I2C
> + select V4L2_FWNODE
>   ---help---
> This is a Video4Linux2 sensor-level driver for the TI TVP5146/47
> decoder. It is currently working with the TI OMAP3 camera
> @@ -344,6 +347,7 @@ config VIDEO_TVP514X
>  config VIDEO_TVP5150
>   tristate "Texas Instruments TVP5150 video decoder"
>   depends on VIDEO_V4L2 && I2C
> + select V4L2_FWNODE
>   ---help---
> Support for the Texas Instruments TVP5150 video decoder.
>  
> @@ -353,6 +357,7 @@ config VIDEO_TVP5150
>  config VIDEO_TVP7002
>   tristate "Texas Instruments TVP7002 video decoder"
>   depends on VIDEO_V4L2 && I2C
> + select V4L2_FWNODE
>   ---help---
> Support for the Texas Instruments TVP7002 video decoder.
>  
> @@ -524,6 +529,7 @@ config VIDEO_OV2659
>   tristate "OmniVision OV2659 sensor support"
>   depends on VIDEO_V4L2 && I2C
>   depends on MEDIA_CAMERA_SUPPORT
> + select V4L2_FWNODE
>   ---help---
> This is a Video4Linux2 sensor-level driver for the OmniVision
> OV2659 camera.
> @@ -616,6 +622,7 @@ config VIDEO_MT9V032
>   depends on I2C && VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API
>   depends on MEDIA_CAMERA_SUPPORT
>   select REGMAP_I2C
> + select

Re: [Patch 2/2] media: ti-vpe: vpe: allow use of user specified stride

2017-02-15 Thread Benoit Parrot
Tomi Valkeinen <tomi.valkei...@ti.com> wrote on Wed [2017-Feb-15 13:22:42 
+0200]:
> Hi,
> 
> On 13/02/17 15:06, Benoit Parrot wrote:
> > Bytesperline/stride was always overwritten by VPE to the most
> > adequate value based on needed alignment.
> > 
> > However in order to make use of arbitrary size DMA buffer it
> > is better to use the user space provide stride instead.
> > 
> > The driver will still calculate an appropriate stride but will
> > use the provided one when it is larger than the calculated one.
> > 
> > Signed-off-by: Benoit Parrot <bpar...@ti.com>
> > ---
> >  drivers/media/platform/ti-vpe/vpe.c | 28 
> >  1 file changed, 20 insertions(+), 8 deletions(-)
> > 
> > diff --git a/drivers/media/platform/ti-vpe/vpe.c 
> > b/drivers/media/platform/ti-vpe/vpe.c
> > index 2dd67232b3bc..c47151495b6f 100644
> > --- a/drivers/media/platform/ti-vpe/vpe.c
> > +++ b/drivers/media/platform/ti-vpe/vpe.c
> > @@ -1597,6 +1597,7 @@ static int __vpe_try_fmt(struct vpe_ctx *ctx, struct 
> > v4l2_format *f,
> > struct v4l2_plane_pix_format *plane_fmt;
> > unsigned int w_align;
> > int i, depth, depth_bytes, height;
> > +   unsigned int stride = 0;
> >  
> > if (!fmt || !(fmt->types & type)) {
> > vpe_err(ctx->dev, "Fourcc format (0x%08x) invalid.\n",
> > @@ -1683,16 +1684,27 @@ static int __vpe_try_fmt(struct vpe_ctx *ctx, 
> > struct v4l2_format *f,
> > plane_fmt = >plane_fmt[i];
> > depth = fmt->vpdma_fmt[i]->depth;
> >  
> > -   if (i == VPE_LUMA)
> > -   plane_fmt->bytesperline = (pix->width * depth) >> 3;
> > -   else
> > -   plane_fmt->bytesperline = pix->width;
> > +   stride = (pix->width * fmt->vpdma_fmt[VPE_LUMA]->depth) >> 3;
> > +   if (stride > plane_fmt->bytesperline)
> > +   plane_fmt->bytesperline = stride;
> 
> The old code calculates different bytes per line for luma and chroma,
> but the new one calculates only for luma. Is that correct?

The previous method which happened to produce the correct value was
not proper as the spec for NV12/NV16 states that the chroma bytes per
line/stride should be the same as the LUMA stride only the number of
lines might differ which affect how the sizeimage component is
calculated. This patch takes that into account.

Benoit

> 
>  Tomi
> 





Re: [PATCH 5/8] v4l: Switch from V4L2 OF not V4L2 fwnode API

2017-02-13 Thread Benoit Parrot
Sakari Ailus  wrote on Mon [2017-Feb-13 15:28:13 
+0200]:
> Switch users of the v4l2_of_ APIs to the more generic v4l2_fwnode_ APIs.
> 
> Existing OF matching continues to be supported. omap3isp and smiapp
> drivers are converted to fwnode matching as well.
> 
> Signed-off-by: Sakari Ailus 
> ---
>  drivers/media/i2c/Kconfig  |  9 
>  drivers/media/i2c/adv7604.c|  7 +--
>  drivers/media/i2c/mt9v032.c|  7 +--
>  drivers/media/i2c/ov2659.c |  8 +--
>  drivers/media/i2c/s5c73m3/s5c73m3-core.c   |  7 +--
>  drivers/media/i2c/s5k5baf.c|  6 +--
>  drivers/media/i2c/smiapp/Kconfig   |  1 +
>  drivers/media/i2c/smiapp/smiapp-core.c | 29 ++-
>  drivers/media/i2c/tc358743.c   | 11 ++--
>  drivers/media/i2c/tvp514x.c|  6 +--
>  drivers/media/i2c/tvp5150.c|  7 +--
>  drivers/media/i2c/tvp7002.c|  6 +--
>  drivers/media/platform/Kconfig |  3 ++
>  drivers/media/platform/am437x/Kconfig  |  1 +
>  drivers/media/platform/am437x/am437x-vpfe.c|  8 +--
>  drivers/media/platform/atmel/Kconfig   |  1 +
>  drivers/media/platform/atmel/atmel-isc.c   |  8 +--
>  drivers/media/platform/exynos4-is/Kconfig  |  2 +
>  drivers/media/platform/exynos4-is/media-dev.c  |  6 +--
>  drivers/media/platform/exynos4-is/mipi-csis.c  |  6 +--
>  drivers/media/platform/omap3isp/isp.c  | 71 
> +-
>  drivers/media/platform/pxa_camera.c|  7 +--
>  drivers/media/platform/rcar-vin/Kconfig|  1 +
>  drivers/media/platform/rcar-vin/rcar-core.c|  6 +--
>  drivers/media/platform/soc_camera/Kconfig  |  1 +
>  drivers/media/platform/soc_camera/atmel-isi.c  |  7 +--
>  drivers/media/platform/soc_camera/soc_camera.c |  2 +-
>  drivers/media/platform/ti-vpe/cal.c| 11 ++--
>  drivers/media/platform/xilinx/Kconfig  |  1 +
>  drivers/media/platform/xilinx/xilinx-vipp.c| 59 +++--
>  include/media/v4l2-fwnode.h|  4 +-
>  31 files changed, 175 insertions(+), 134 deletions(-)
> 
> diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
> index cee1dae..6b2423a 100644
> --- a/drivers/media/i2c/Kconfig
> +++ b/drivers/media/i2c/Kconfig
> @@ -210,6 +210,7 @@ config VIDEO_ADV7604
>   depends on GPIOLIB || COMPILE_TEST
>   select HDMI
>   select MEDIA_CEC_EDID
> + select V4L2_FWNODE
>   ---help---
> Support for the Analog Devices ADV7604 video decoder.
>  
> @@ -324,6 +325,7 @@ config VIDEO_TC358743
>   tristate "Toshiba TC358743 decoder"
>   depends on VIDEO_V4L2 && I2C && VIDEO_V4L2_SUBDEV_API
>   select HDMI
> + select V4L2_FWNODE
>   ---help---
> Support for the Toshiba TC358743 HDMI to MIPI CSI-2 bridge.
>  
> @@ -333,6 +335,7 @@ config VIDEO_TC358743
>  config VIDEO_TVP514X
>   tristate "Texas Instruments TVP514x video decoder"
>   depends on VIDEO_V4L2 && I2C
> + select V4L2_FWNODE
>   ---help---
> This is a Video4Linux2 sensor-level driver for the TI TVP5146/47
> decoder. It is currently working with the TI OMAP3 camera
> @@ -344,6 +347,7 @@ config VIDEO_TVP514X
>  config VIDEO_TVP5150
>   tristate "Texas Instruments TVP5150 video decoder"
>   depends on VIDEO_V4L2 && I2C
> + select V4L2_FWNODE
>   ---help---
> Support for the Texas Instruments TVP5150 video decoder.
>  
> @@ -353,6 +357,7 @@ config VIDEO_TVP5150
>  config VIDEO_TVP7002
>   tristate "Texas Instruments TVP7002 video decoder"
>   depends on VIDEO_V4L2 && I2C
> + select V4L2_FWNODE
>   ---help---
> Support for the Texas Instruments TVP7002 video decoder.
>  
> @@ -524,6 +529,7 @@ config VIDEO_OV2659
>   tristate "OmniVision OV2659 sensor support"
>   depends on VIDEO_V4L2 && I2C
>   depends on MEDIA_CAMERA_SUPPORT
> + select V4L2_FWNODE
>   ---help---
> This is a Video4Linux2 sensor-level driver for the OmniVision
> OV2659 camera.
> @@ -616,6 +622,7 @@ config VIDEO_MT9V032
>   depends on I2C && VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API
>   depends on MEDIA_CAMERA_SUPPORT
>   select REGMAP_I2C
> + select V4L2_FWNODE
>   ---help---
> This is a Video4Linux2 sensor-level driver for the Micron
> MT9V032 752x480 CMOS sensor.
> @@ -663,6 +670,7 @@ config VIDEO_S5K4ECGX
>  config VIDEO_S5K5BAF
>   tristate "Samsung S5K5BAF sensor support"
>   depends on I2C && VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API
> + select V4L2_FWNODE
>   ---help---
> This is a V4L2 sensor-level driver for Samsung S5K5BAF 2M
> camera sensor with an embedded SoC image signal processor.
> @@ -673,6 +681,7 @@ source "drivers/media/i2c/et8ek8/Kconfig"
>  config VIDEO_S5C73M3
>  

[Patch 0/2] media: ti-vpe: allow user specified stride

2017-02-13 Thread Benoit Parrot
This patch series enables user specified buffer stride to be used
instead of always forcing the stride from the driver side.

Benoit Parrot (2):
  media: ti-vpe: vpdma: add support for user specified stride
  media: ti-vpe: vpe: allow use of user specified stride

 drivers/media/platform/ti-vpe/vpdma.c | 14 --
 drivers/media/platform/ti-vpe/vpdma.h |  6 +++---
 drivers/media/platform/ti-vpe/vpe.c   | 34 --
 3 files changed, 31 insertions(+), 23 deletions(-)

-- 
2.9.0



[Patch 1/2] media: ti-vpe: vpdma: add support for user specified stride

2017-02-13 Thread Benoit Parrot
This patch introduce the needed vpdma API changes to support
user space specified stride instead of forcing a driver calculated
one.

Signed-off-by: Benoit Parrot <bpar...@ti.com>
---
 drivers/media/platform/ti-vpe/vpdma.c | 14 --
 drivers/media/platform/ti-vpe/vpdma.h |  6 +++---
 drivers/media/platform/ti-vpe/vpe.c   |  6 --
 3 files changed, 11 insertions(+), 15 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/vpdma.c 
b/drivers/media/platform/ti-vpe/vpdma.c
index 23472e3784ff..e2cf2b90e500 100644
--- a/drivers/media/platform/ti-vpe/vpdma.c
+++ b/drivers/media/platform/ti-vpe/vpdma.c
@@ -801,17 +801,17 @@ static void dump_dtd(struct vpdma_dtd *dtd)
  * flags: VPDMA flags to configure some descriptor fileds
  */
 void vpdma_add_out_dtd(struct vpdma_desc_list *list, int width,
-   const struct v4l2_rect *c_rect,
+   int stride, const struct v4l2_rect *c_rect,
const struct vpdma_data_format *fmt, dma_addr_t dma_addr,
int max_w, int max_h, enum vpdma_channel chan, u32 flags)
 {
-   vpdma_rawchan_add_out_dtd(list, width, c_rect, fmt, dma_addr,
+   vpdma_rawchan_add_out_dtd(list, width, stride, c_rect, fmt, dma_addr,
  max_w, max_h, chan_info[chan].num, flags);
 }
 EXPORT_SYMBOL(vpdma_add_out_dtd);
 
 void vpdma_rawchan_add_out_dtd(struct vpdma_desc_list *list, int width,
-   const struct v4l2_rect *c_rect,
+   int stride, const struct v4l2_rect *c_rect,
const struct vpdma_data_format *fmt, dma_addr_t dma_addr,
int max_w, int max_h, int raw_vpdma_chan, u32 flags)
 {
@@ -821,7 +821,6 @@ void vpdma_rawchan_add_out_dtd(struct vpdma_desc_list 
*list, int width,
int channel, next_chan;
struct v4l2_rect rect = *c_rect;
int depth = fmt->depth;
-   int stride;
struct vpdma_dtd *dtd;
 
channel = next_chan = raw_vpdma_chan;
@@ -833,8 +832,6 @@ void vpdma_rawchan_add_out_dtd(struct vpdma_desc_list 
*list, int width,
depth = 8;
}
 
-   stride = ALIGN((depth * width) >> 3, VPDMA_STRIDE_ALIGN);
-
dma_addr += rect.top * stride + (rect.left * depth >> 3);
 
dtd = list->next;
@@ -882,7 +879,7 @@ EXPORT_SYMBOL(vpdma_rawchan_add_out_dtd);
  * contribute to the client)
  */
 void vpdma_add_in_dtd(struct vpdma_desc_list *list, int width,
-   const struct v4l2_rect *c_rect,
+   int stride, const struct v4l2_rect *c_rect,
const struct vpdma_data_format *fmt, dma_addr_t dma_addr,
enum vpdma_channel chan, int field, u32 flags, int frame_width,
int frame_height, int start_h, int start_v)
@@ -892,7 +889,6 @@ void vpdma_add_in_dtd(struct vpdma_desc_list *list, int 
width,
int depth = fmt->depth;
int channel, next_chan;
struct v4l2_rect rect = *c_rect;
-   int stride;
struct vpdma_dtd *dtd;
 
channel = next_chan = chan_info[chan].num;
@@ -904,8 +900,6 @@ void vpdma_add_in_dtd(struct vpdma_desc_list *list, int 
width,
depth = 8;
}
 
-   stride = ALIGN((depth * width) >> 3, VPDMA_STRIDE_ALIGN);
-
dma_addr += rect.top * stride + (rect.left * depth >> 3);
 
dtd = list->next;
diff --git a/drivers/media/platform/ti-vpe/vpdma.h 
b/drivers/media/platform/ti-vpe/vpdma.h
index 131700c112b2..7e611501c291 100644
--- a/drivers/media/platform/ti-vpe/vpdma.h
+++ b/drivers/media/platform/ti-vpe/vpdma.h
@@ -242,16 +242,16 @@ void vpdma_add_sync_on_channel_ctd(struct vpdma_desc_list 
*list,
 void vpdma_add_abort_channel_ctd(struct vpdma_desc_list *list,
int chan_num);
 void vpdma_add_out_dtd(struct vpdma_desc_list *list, int width,
-   const struct v4l2_rect *c_rect,
+   int stride, const struct v4l2_rect *c_rect,
const struct vpdma_data_format *fmt, dma_addr_t dma_addr,
int max_w, int max_h, enum vpdma_channel chan, u32 flags);
 void vpdma_rawchan_add_out_dtd(struct vpdma_desc_list *list, int width,
-   const struct v4l2_rect *c_rect,
+   int stride, const struct v4l2_rect *c_rect,
const struct vpdma_data_format *fmt, dma_addr_t dma_addr,
int max_w, int max_h, int raw_vpdma_chan, u32 flags);
 
 void vpdma_add_in_dtd(struct vpdma_desc_list *list, int width,
-   const struct v4l2_rect *c_rect,
+   int stride, const struct v4l2_rect *c_rect,
const struct vpdma_data_format *fmt, dma_addr_t dma_addr,
enum vpdma_channel chan, int field, u32 flags, int frame_width,
int frame_height, int start_h, int start_v);
diff --git a/drivers/media/platform/ti-vpe/vpe.c 
b/drivers/media/platform/ti-vpe/vpe.c
index f0156b7759e9..2dd67232b3bc 100644
--- a/drivers/media/platform/ti-vpe/vpe.c
+++ b/driv

[Patch 2/2] media: ti-vpe: vpe: allow use of user specified stride

2017-02-13 Thread Benoit Parrot
Bytesperline/stride was always overwritten by VPE to the most
adequate value based on needed alignment.

However in order to make use of arbitrary size DMA buffer it
is better to use the user space provide stride instead.

The driver will still calculate an appropriate stride but will
use the provided one when it is larger than the calculated one.

Signed-off-by: Benoit Parrot <bpar...@ti.com>
---
 drivers/media/platform/ti-vpe/vpe.c | 28 
 1 file changed, 20 insertions(+), 8 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/vpe.c 
b/drivers/media/platform/ti-vpe/vpe.c
index 2dd67232b3bc..c47151495b6f 100644
--- a/drivers/media/platform/ti-vpe/vpe.c
+++ b/drivers/media/platform/ti-vpe/vpe.c
@@ -1597,6 +1597,7 @@ static int __vpe_try_fmt(struct vpe_ctx *ctx, struct 
v4l2_format *f,
struct v4l2_plane_pix_format *plane_fmt;
unsigned int w_align;
int i, depth, depth_bytes, height;
+   unsigned int stride = 0;
 
if (!fmt || !(fmt->types & type)) {
vpe_err(ctx->dev, "Fourcc format (0x%08x) invalid.\n",
@@ -1683,16 +1684,27 @@ static int __vpe_try_fmt(struct vpe_ctx *ctx, struct 
v4l2_format *f,
plane_fmt = >plane_fmt[i];
depth = fmt->vpdma_fmt[i]->depth;
 
-   if (i == VPE_LUMA)
-   plane_fmt->bytesperline = (pix->width * depth) >> 3;
-   else
-   plane_fmt->bytesperline = pix->width;
+   stride = (pix->width * fmt->vpdma_fmt[VPE_LUMA]->depth) >> 3;
+   if (stride > plane_fmt->bytesperline)
+   plane_fmt->bytesperline = stride;
+
+   plane_fmt->bytesperline = ALIGN(plane_fmt->bytesperline,
+   VPDMA_STRIDE_ALIGN);
 
-   if (pix->num_planes == 1 && fmt->coplanar)
-   depth += fmt->vpdma_fmt[VPE_CHROMA]->depth;
-   plane_fmt->sizeimage =
-   (pix->height * pix->width * depth) >> 3;
+   if (i == VPE_LUMA) {
+   plane_fmt->sizeimage = pix->height *
+  plane_fmt->bytesperline;
 
+   if (pix->num_planes == 1 && fmt->coplanar)
+   plane_fmt->sizeimage += pix->height *
+   plane_fmt->bytesperline *
+   fmt->vpdma_fmt[VPE_CHROMA]->depth >> 3;
+
+   } else { /* i == VIP_CHROMA */
+   plane_fmt->sizeimage = (pix->height *
+  plane_fmt->bytesperline *
+  depth) >> 3;
+   }
memset(plane_fmt->reserved, 0, sizeof(plane_fmt->reserved));
}
 
-- 
2.9.0



Re: [PATCH v3 13/24] platform: add video-multiplexer subdevice driver

2017-02-07 Thread Benoit Parrot
Laurent Pinchart  wrote on Tue [2017-Feb-07 
12:26:32 +0200]:
> Hi Steve,
> 
> On Monday 06 Feb 2017 15:10:46 Steve Longerbeam wrote:
> > On 02/06/2017 02:33 PM, Laurent Pinchart wrote:
> > > On Monday 06 Feb 2017 10:50:22 Hans Verkuil wrote:
> > >> On 02/05/2017 04:48 PM, Laurent Pinchart wrote:
> > >>> On Tuesday 24 Jan 2017 18:07:55 Steve Longerbeam wrote:
> >  On 01/24/2017 04:02 AM, Philipp Zabel wrote:
> > > On Fri, 2017-01-20 at 15:03 +0100, Hans Verkuil wrote:
> > >>> +
> > >>> +int vidsw_g_mbus_config(struct v4l2_subdev *sd, struct
> > >>> v4l2_mbus_config *cfg)
> 
> [snip]
> 
> > >> I am not certain this op is needed at all. In the current kernel this
> > >> op is only used by soc_camera, pxa_camera and omap3isp (somewhat
> > >> dubious). Normally this information should come from the device tree
> > >> and there should be no need for this op.
> > >> 
> > >> My (tentative) long-term plan was to get rid of this op.
> > >> 
> > >> If you don't need it, then I recommend it is removed.
> >  
> >  Hi Hans, the imx-media driver was only calling g_mbus_config to the
> >  camera sensor, and it was doing that to determine the sensor's bus
> >  type. This info was already available from parsing a v4l2_of_endpoint
> >  from the sensor node. So it was simple to remove the g_mbus_config
> >  calls, and instead rely on the parsed sensor v4l2_of_endpoint.
> > >>> 
> > >>> That's not a good point.
> > > 
> > > (mea culpa, s/point/idea/)
> > > 
> > >>> The imx-media driver must not parse the sensor DT node as it is not
> > >>> aware of what bindings the sensor is compatible with.
> > 
> > Hi Laurent,
> > 
> > I don't really understand this argument. The sensor node has been found
> > by parsing the OF graph, so it is known to be a camera sensor node at
> > that point.
> 
> All you know in the i.MX6 driver is that the remote node is a video source. 
> You can rely on the fact that it implements the OF graph bindings to locate 
> other ports in that DT node, but that's more or less it.
> 
> DT properties are defined by DT bindings and thus qualified by a compatible 
> string. Unless you match on sensor compat strings in the i.MX6 driver (which 
> you shouldn't do, to keep the driver generic) you can't know for certain how 
> to parse the sensor node DT properties. For all you know, the video source 
> could be a bridge such as an HDMI to CSI-2 converter for instance, so you 
> can't even rely on the fact that it's a sensor.
> 
> > >>> Information must instead be queried from the sensor subdev at runtime,
> > >>> through the g_mbus_config() operation.
> > >>> 
> > >>> Of course, if you can get the information from the imx-media DT node,
> > >>> that's certainly an option. It's only information provided by the sensor
> > >>> driver that you have no choice but query using a subdev operation.
> > >> 
> > >> Shouldn't this come from the imx-media DT node? BTW, why is omap3isp
> > >> using this?
> > > 
> > > It all depends on what type of information needs to be retrieved, and
> > > whether it can change at runtime or is fixed. Adding properties to the
> > > imx-media DT node is certainly fine as long as those properties describe
> > > the i.MX side.
> >
> > In this case the info needed is the media bus type. That info is most easily
> > available by calling v4l2_of_parse_endpoint() on the sensor's endpoint
> > node.
> 
> I haven't had time to check the code in details yet, so I can't really 
> comment 
> on what you need and how it should be implemented exactly.
> 
> > The media bus type is not something that can be added to the
> > imx-media node since it contains no endpoint nodes.
> 
> Agreed. You have endpoints in the CSI nodes though.
> 
> > > In the omap3isp case, we use the operation to query whether parallel data
> > > contains embedded sync (BT.656) or uses separate h/v sync signals.
> > > 
> > >> The reason I am suspicious about this op is that it came from soc-camera
> > >> and predates the DT. The contents of v4l2_mbus_config seems very much
> > >> like a HW description to me, i.e. something that belongs in the DT.
> > > 
> > > Part of it is possibly outdated, but for buses that support multiple modes
> > > of operation (such as the parallel bus case described above) we need to
> > > make that information discoverable at runtime. Maybe this should be
> > > considered as related to Sakari's efforts to support VC/DT for CSI-2, and
> > > supported through the API he is working on.
> > 
> > That sounds interesting, can you point me to some info on this effort?
> 
> Sure.
> 
> http://git.retiisi.org.uk/?p=~sailus/linux.git;a=shortlog;h=refs/heads/vc
> 
> > I've been thinking the DT should contain virtual channel info for CSI-2
> > buses.
> 
> I don't think it should. CSI-2 virtual channels and data types should be 
> handled as a software concept, and thus supported through driver code without 
> 

Re: [patch] [media] media: ti-vpe: vpdma: fix a timeout loop

2016-11-28 Thread Benoit Parrot
Dan,

Thanks for the patch.

Acked-by: Benoit Parrot <bpar...@ti.com>

Dan Carpenter <dan.carpen...@oracle.com> wrote on Sat [2016-Nov-26 00:28:34 
+0300]:
> The check assumes that we end on zero but actually we end on -1.  Change
> the post-op to a pre-op so that we do end on zero.  Techinically now we
> only loop 499 times instead of 500 but that's fine.
> 
> Fixes: dc12b124353b ("[media] media: ti-vpe: vpdma: Add abort channel desc 
> and cleanup APIs")
> Signed-off-by: Dan Carpenter <dan.carpen...@oracle.com>
> 
> diff --git a/drivers/media/platform/ti-vpe/vpdma.c 
> b/drivers/media/platform/ti-vpe/vpdma.c
> index 13bfd71..23472e3 100644
> --- a/drivers/media/platform/ti-vpe/vpdma.c
> +++ b/drivers/media/platform/ti-vpe/vpdma.c
> @@ -453,7 +453,7 @@ int vpdma_list_cleanup(struct vpdma_data *vpdma, int 
> list_num,
>   if (ret)
>   return ret;
>  
> - while (vpdma_list_busy(vpdma, list_num) && timeout--)
> + while (vpdma_list_busy(vpdma, list_num) && --timeout)
>   ;
>  
>   if (timeout == 0) {
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Patch v2 01/35] media: ti-vpe: vpdma: Make vpdma library into its own module

2016-11-18 Thread Benoit Parrot
The VPDMA (Video Port DMA) as found in devices such as DRA7xx is
used for both the Video Processing Engine (VPE) and the Video Input
Port (VIP).

In preparation for this we need to turn vpdma into its own
kernel module.

Signed-off-by: Benoit Parrot <bpar...@ti.com>
---
 drivers/media/platform/Kconfig |  6 ++
 drivers/media/platform/ti-vpe/Makefile |  4 +++-
 drivers/media/platform/ti-vpe/vpdma.c  | 28 +++-
 3 files changed, 36 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig
index 3c5a0b6b23a9..b52b6771fc4d 100644
--- a/drivers/media/platform/Kconfig
+++ b/drivers/media/platform/Kconfig
@@ -364,6 +364,7 @@ config VIDEO_TI_VPE
depends on HAS_DMA
select VIDEOBUF2_DMA_CONTIG
select V4L2_MEM2MEM_DEV
+   select VIDEO_TI_VPDMA
default n
---help---
  Support for the TI VPE(Video Processing Engine) block
@@ -377,6 +378,11 @@ config VIDEO_TI_VPE_DEBUG
 
 endif # V4L_MEM2MEM_DRIVERS
 
+# TI VIDEO PORT Helper Modules
+# These will be selected by VPE and VIP
+config VIDEO_TI_VPDMA
+   tristate
+
 menuconfig V4L_TEST_DRIVERS
bool "Media test drivers"
depends on MEDIA_CAMERA_SUPPORT
diff --git a/drivers/media/platform/ti-vpe/Makefile 
b/drivers/media/platform/ti-vpe/Makefile
index e236059a60ad..faca5e115c1d 100644
--- a/drivers/media/platform/ti-vpe/Makefile
+++ b/drivers/media/platform/ti-vpe/Makefile
@@ -1,6 +1,8 @@
 obj-$(CONFIG_VIDEO_TI_VPE) += ti-vpe.o
+obj-$(CONFIG_VIDEO_TI_VPDMA) += ti-vpdma.o
 
-ti-vpe-y := vpe.o sc.o csc.o vpdma.o
+ti-vpe-y := vpe.o sc.o csc.o
+ti-vpdma-y := vpdma.o
 
 ccflags-$(CONFIG_VIDEO_TI_VPE_DEBUG) += -DDEBUG
 
diff --git a/drivers/media/platform/ti-vpe/vpdma.c 
b/drivers/media/platform/ti-vpe/vpdma.c
index 4aff05915051..7de0f3f55dcc 100644
--- a/drivers/media/platform/ti-vpe/vpdma.c
+++ b/drivers/media/platform/ti-vpe/vpdma.c
@@ -75,6 +75,7 @@ const struct vpdma_data_format vpdma_yuv_fmts[] = {
.depth  = 16,
},
 };
+EXPORT_SYMBOL(vpdma_yuv_fmts);
 
 const struct vpdma_data_format vpdma_rgb_fmts[] = {
[VPDMA_DATA_FMT_RGB565] = {
@@ -178,6 +179,7 @@ const struct vpdma_data_format vpdma_rgb_fmts[] = {
.depth  = 32,
},
 };
+EXPORT_SYMBOL(vpdma_rgb_fmts);
 
 const struct vpdma_data_format vpdma_misc_fmts[] = {
[VPDMA_DATA_FMT_MV] = {
@@ -186,6 +188,7 @@ const struct vpdma_data_format vpdma_misc_fmts[] = {
.depth  = 4,
},
 };
+EXPORT_SYMBOL(vpdma_misc_fmts);
 
 struct vpdma_channel_info {
int num;/* VPDMA channel number */
@@ -317,6 +320,7 @@ void vpdma_dump_regs(struct vpdma_data *vpdma)
DUMPREG(VIP_UP_UV_CSTAT);
DUMPREG(VPI_CTL_CSTAT);
 }
+EXPORT_SYMBOL(vpdma_dump_regs);
 
 /*
  * Allocate a DMA buffer
@@ -333,6 +337,7 @@ int vpdma_alloc_desc_buf(struct vpdma_buf *buf, size_t size)
 
return 0;
 }
+EXPORT_SYMBOL(vpdma_alloc_desc_buf);
 
 void vpdma_free_desc_buf(struct vpdma_buf *buf)
 {
@@ -341,6 +346,7 @@ void vpdma_free_desc_buf(struct vpdma_buf *buf)
buf->addr = NULL;
buf->size = 0;
 }
+EXPORT_SYMBOL(vpdma_free_desc_buf);
 
 /*
  * map descriptor/payload DMA buffer, enabling DMA access
@@ -361,6 +367,7 @@ int vpdma_map_desc_buf(struct vpdma_data *vpdma, struct 
vpdma_buf *buf)
 
return 0;
 }
+EXPORT_SYMBOL(vpdma_map_desc_buf);
 
 /*
  * unmap descriptor/payload DMA buffer, disabling DMA access and
@@ -375,6 +382,7 @@ void vpdma_unmap_desc_buf(struct vpdma_data *vpdma, struct 
vpdma_buf *buf)
 
buf->mapped = false;
 }
+EXPORT_SYMBOL(vpdma_unmap_desc_buf);
 
 /*
  * create a descriptor list, the user of this list will append configuration,
@@ -396,6 +404,7 @@ int vpdma_create_desc_list(struct vpdma_desc_list *list, 
size_t size, int type)
 
return 0;
 }
+EXPORT_SYMBOL(vpdma_create_desc_list);
 
 /*
  * once a descriptor list is parsed by VPDMA, we reset the list by emptying it,
@@ -405,6 +414,7 @@ void vpdma_reset_desc_list(struct vpdma_desc_list *list)
 {
list->next = list->buf.addr;
 }
+EXPORT_SYMBOL(vpdma_reset_desc_list);
 
 /*
  * free the buffer allocated fot the VPDMA descriptor list, this should be
@@ -416,11 +426,13 @@ void vpdma_free_desc_list(struct vpdma_desc_list *list)
 
list->next = NULL;
 }
+EXPORT_SYMBOL(vpdma_free_desc_list);
 
-static bool vpdma_list_busy(struct vpdma_data *vpdma, int list_num)
+bool vpdma_list_busy(struct vpdma_data *vpdma, int list_num)
 {
return read_reg(vpdma, VPDMA_LIST_STAT_SYNC) & BIT(list_num + 16);
 }
+EXPORT_SYMBOL(vpdma_list_busy);
 
 /*
  * submit a list of DMA descriptors to the VPE VPDMA, do not wait for 
completion
@@ -446,6 +458,7 @@ int vpdma_submit_descs(struct vpdma_data *vpdma, struct 
vpdma_desc_list *list)
 
return 0;
 }
+EXPORT_SYMBOL(vpdma_submit_descs);
 
 static void dump_cfd(struct vpdma

[Patch v2 08/35] media: ti-vpe: Increasing max buffer height and width

2016-11-18 Thread Benoit Parrot
From: Harinarayan Bhatta <harinara...@ti.com>

Increasing max buffer height and width to allow for padded buffers.

Signed-off-by: Harinarayan Bhatta <harinara...@ti.com>
Signed-off-by: Nikhil Devshatwar <nikhil...@ti.com>
Signed-off-by: Benoit Parrot <bpar...@ti.com>
Acked-by: Hans Verkuil <hans.verk...@cisco.com>
---
 drivers/media/platform/ti-vpe/vpe.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/vpe.c 
b/drivers/media/platform/ti-vpe/vpe.c
index e5d55575350f..c624f5db7f08 100644
--- a/drivers/media/platform/ti-vpe/vpe.c
+++ b/drivers/media/platform/ti-vpe/vpe.c
@@ -53,8 +53,8 @@
 /* minimum and maximum frame sizes */
 #define MIN_W  32
 #define MIN_H  32
-#define MAX_W  1920
-#define MAX_H  1080
+#define MAX_W  2048
+#define MAX_H  1184
 
 /* required alignments */
 #define S_ALIGN0   /* multiple of 1 */
-- 
2.9.0

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Patch v2 00/35] media: ti-vpe: fixes and enhancements

2016-11-18 Thread Benoit Parrot
This patch series is to publish a number of enhancements
we have been carrying for a while.

A number of bug fixes and feature enhancements have been
included.

We also need to prepare the way for the introduction of
the VIP (Video Input Port) driver (coming soon) which
has internal IP module in common with VPE.

The relevant modules (vpdma, sc and csc) are therefore converted
into individual kernel modules.

Changes since v1:
- Fix typos from comments
- Clarified commit log based on comments
- Added Acked-by and Reviewed-by tags to relevant patches.

Archit Taneja (1):
  media: ti-vpe: Use line average de-interlacing for first 2 frames

Benoit Parrot (16):
  media: ti-vpe: vpdma: Make vpdma library into its own module
  media: ti-vpe: vpdma: Add multi-instance and multi-client support
  media: ti-vpe: vpdma: Add helper to set a background color
  media: ti-vpe: vpdma: Fix bus error when vpdma is writing a descriptor
  media: ti-vpe: vpe: Added MODULE_DEVICE_TABLE hint
  media: ti-vpe: vpdma: Corrected YUV422 data type label.
  media: ti-vpe: vpdma: RGB data type yield inverted data
  media: ti-vpe: vpe: Fix vb2 buffer cleanup
  media: ti-vpe: vpe: Enable DMABUF export
  media: ti-vpe: Make scaler library into its own module
  media: ti-vpe: scaler: Add debug support for multi-instance
  media: ti-vpe: vpe: Make sure frame size dont exceed scaler capacity
  media: ti-vpe: vpdma: Add RAW8 and RAW16 data types
  media: ti-vpe: Make colorspace converter library into its own module
  media: ti-vpe: csc: Add debug support for multi-instance
  media: ti-vpe: vpe: Add proper support single and multi-plane buffer

Harinarayan Bhatta (2):
  media: ti-vpe: Increasing max buffer height and width
  media: ti-vpe: Free vpdma buffers in vpe_release

Nikhil Devshatwar (16):
  media: ti-vpe: vpe: Do not perform job transaction atomically
  media: ti-vpe: Add support for SEQ_TB buffers
  media: ti-vpe: vpe: Return NULL for invalid buffer type
  media: ti-vpe: vpdma: Add support for setting max width height
  media: ti-vpe: vpdma: Add abort channel desc and cleanup APIs
  media: ti-vpe: vpdma: Make list post atomic operation
  media: ti-vpe: vpdma: Clear IRQs for individual lists
  media: ti-vpe: vpe: configure line mode separately
  media: ti-vpe: vpe: Setup srcdst parameters in start_streaming
  media: ti-vpe: vpe: Post next descriptor only for list complete IRQ
  media: ti-vpe: vpe: Add RGB565 and RGB5551 support
  media: ti-vpe: vpdma: allocate and maintain hwlist
  media: ti-vpe: sc: Fix incorrect optimization
  media: ti-vpe: vpdma: Fix race condition for firmware loading
  media: ti-vpe: vpdma: Use bidirectional cached buffers
  media: ti-vpe: vpe: Fix line stride for output motion vector

 drivers/media/platform/Kconfig |  14 +
 drivers/media/platform/ti-vpe/Makefile |  10 +-
 drivers/media/platform/ti-vpe/csc.c|  18 +-
 drivers/media/platform/ti-vpe/csc.h|   2 +-
 drivers/media/platform/ti-vpe/sc.c |  28 +-
 drivers/media/platform/ti-vpe/sc.h |  11 +-
 drivers/media/platform/ti-vpe/vpdma.c  | 349 +++---
 drivers/media/platform/ti-vpe/vpdma.h  |  85 +-
 drivers/media/platform/ti-vpe/vpdma_priv.h | 130 -
 drivers/media/platform/ti-vpe/vpe.c| 450 -
 10 files changed, 891 insertions(+), 206 deletions(-)

-- 
2.9.0

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Patch v2 05/35] media: ti-vpe: Use line average de-interlacing for first 2 frames

2016-11-18 Thread Benoit Parrot
From: Archit Taneja <arc...@ti.com>

The motion detection block requires 3 fields to create the motion vector
data. This means that using the default method the first progressive
frame is only generated after 3rd field is consumed.
Hence by default for N input field we would generate N - 2 progressive
frames.

In order to generate N progressive frames from N fields we use the
line averaging mode of the de-interlacer for the first 2 fields and then
revert back to the preferred Edge Directed Interpolation method (using
the motion vector).
Thus creating 2 line averaged frames + N - 2 motion based frames for a
total of N frames.

Signed-off-by: Archit Taneja <arc...@ti.com>
Signed-off-by: Nikhil Devshatwar <nikhil...@ti.com>
Signed-off-by: Benoit Parrot <bpar...@ti.com>
---
 drivers/media/platform/ti-vpe/vpe.c | 33 +++--
 1 file changed, 31 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/vpe.c 
b/drivers/media/platform/ti-vpe/vpe.c
index bd385c5bae2f..ad838b8a98c4 100644
--- a/drivers/media/platform/ti-vpe/vpe.c
+++ b/drivers/media/platform/ti-vpe/vpe.c
@@ -141,7 +141,7 @@ struct vpe_dei_regs {
  */
 static const struct vpe_dei_regs dei_regs = {
.mdt_spacial_freq_thr_reg = 0x020C0804u,
-   .edi_config_reg = 0x0118100Fu,
+   .edi_config_reg = 0x0118100Cu,
.edi_lut_reg0 = 0x08040200u,
.edi_lut_reg1 = 0x1010100Cu,
.edi_lut_reg2 = 0x10101010u,
@@ -798,6 +798,23 @@ static void set_dei_shadow_registers(struct vpe_ctx *ctx)
ctx->load_mmrs = true;
 }
 
+static void config_edi_input_mode(struct vpe_ctx *ctx, int mode)
+{
+   struct vpe_mmr_adb *mmr_adb = ctx->mmr_adb.addr;
+   u32 *edi_config_reg = _adb->dei_regs[3];
+
+   if (mode & 0x2)
+   write_field(edi_config_reg, 1, 1, 2);   /* EDI_ENABLE_3D */
+
+   if (mode & 0x3)
+   write_field(edi_config_reg, 1, 1, 3);   /* EDI_CHROMA_3D  */
+
+   write_field(edi_config_reg, mode, VPE_EDI_INP_MODE_MASK,
+   VPE_EDI_INP_MODE_SHIFT);
+
+   ctx->load_mmrs = true;
+}
+
 /*
  * Set the shadow registers whose values are modified when either the
  * source or destination format is changed.
@@ -,6 +1128,15 @@ static void device_run(void *priv)
ctx->dst_vb = v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx);
WARN_ON(ctx->dst_vb == NULL);
 
+   if (ctx->deinterlacing) {
+   /*
+* we have output the first 2 frames through line average, we
+* now switch to EDI de-interlacer
+*/
+   if (ctx->sequence == 2)
+   config_edi_input_mode(ctx, 0x3); /* EDI (Y + UV) */
+   }
+
/* config descriptors */
if (ctx->dev->loaded_mmrs != ctx->mmr_adb.dma_addr || ctx->load_mmrs) {
vpdma_map_desc_buf(ctx->dev->vpdma, >mmr_adb);
@@ -1864,7 +1890,10 @@ static void vpe_buf_queue(struct vb2_buffer *vb)
 
 static int vpe_start_streaming(struct vb2_queue *q, unsigned int count)
 {
-   /* currently we do nothing here */
+   struct vpe_ctx *ctx = vb2_get_drv_priv(q);
+
+   if (ctx->deinterlacing)
+   config_edi_input_mode(ctx, 0x0);
 
return 0;
 }
-- 
2.9.0

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Patch v2 07/35] media: ti-vpe: Add support for SEQ_TB buffers

2016-11-18 Thread Benoit Parrot
From: Nikhil Devshatwar <nikhil...@ti.com>

The video source can generate the data in the SEQ_TB buffer format.
In the case of TI SoC, the IVA_HD can generate the interlaced content in
the SEQ_TB buffer format. This is the format where the top and bottom field
data can be contained in a single buffer. For example, for NV12, interlaced
format, the data in Y buffer will be arranged as Y-top followed by
Y-bottom. And likewise for UV plane.

Also, queuing one buffer of SEQ_TB is equivalent to queuing two different
buffers for top and bottom fields. Driver needs to take care of this when
handling source buffer lists.

Signed-off-by: Nikhil Devshatwar <nikhil...@ti.com>
Signed-off-by: Benoit Parrot <bpar...@ti.com>
Acked-by: Hans Verkuil <hans.verk...@cisco.com>
---
 drivers/media/platform/ti-vpe/vpe.c | 125 +---
 1 file changed, 103 insertions(+), 22 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/vpe.c 
b/drivers/media/platform/ti-vpe/vpe.c
index 9b7b9be5641d..e5d55575350f 100644
--- a/drivers/media/platform/ti-vpe/vpe.c
+++ b/drivers/media/platform/ti-vpe/vpe.c
@@ -320,9 +320,13 @@ struct vpe_q_data {
 };
 
 /* vpe_q_data flag bits */
-#defineQ_DATA_FRAME_1D (1 << 0)
-#defineQ_DATA_MODE_TILED   (1 << 1)
-#defineQ_DATA_INTERLACED   (1 << 2)
+#defineQ_DATA_FRAME_1D BIT(0)
+#defineQ_DATA_MODE_TILED   BIT(1)
+#defineQ_DATA_INTERLACED_ALTERNATE BIT(2)
+#defineQ_DATA_INTERLACED_SEQ_TBBIT(3)
+
+#define Q_IS_INTERLACED(Q_DATA_INTERLACED_ALTERNATE | \
+   Q_DATA_INTERLACED_SEQ_TB)
 
 enum {
Q_DATA_SRC = 0,
@@ -638,7 +642,7 @@ static void set_us_coefficients(struct vpe_ctx *ctx)
 
cp = _coeffs[0].anchor_fid0_c0;
 
-   if (s_q_data->flags & Q_DATA_INTERLACED)/* interlaced */
+   if (s_q_data->flags & Q_IS_INTERLACED)  /* interlaced */
cp += sizeof(us_coeffs[0]) / sizeof(*cp);
 
end_cp = cp + sizeof(us_coeffs[0]) / sizeof(*cp);
@@ -765,8 +769,7 @@ static void set_dei_regs(struct vpe_ctx *ctx)
 * for both progressive and interlace content in interlace bypass mode.
 * It has been recommended not to use progressive bypass mode.
 */
-   if ((!ctx->deinterlacing && (s_q_data->flags & Q_DATA_INTERLACED)) ||
-   !(s_q_data->flags & Q_DATA_INTERLACED)) {
+   if (!(s_q_data->flags & Q_IS_INTERLACED) || !ctx->deinterlacing) {
deinterlace = false;
val = VPE_DEI_INTERLACE_BYPASS;
}
@@ -834,8 +837,8 @@ static int set_srcdst_params(struct vpe_ctx *ctx)
ctx->sequence = 0;
ctx->field = V4L2_FIELD_TOP;
 
-   if ((s_q_data->flags & Q_DATA_INTERLACED) &&
-   !(d_q_data->flags & Q_DATA_INTERLACED)) {
+   if ((s_q_data->flags & Q_IS_INTERLACED) &&
+   !(d_q_data->flags & Q_IS_INTERLACED)) {
int bytes_per_line;
const struct vpdma_data_format *mv =
_misc_fmts[VPDMA_DATA_FMT_MV];
@@ -1066,6 +1069,28 @@ static void add_in_dtd(struct vpe_ctx *ctx, int port)
port);
return;
}
+
+   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;
+
+   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;
+   }
+   }
}
 
if (q_data->flags & Q_DATA_FRAME_1D)
@@ -1114,9 +1139,22 @@ static void device_run(void *priv)
struct vpe_ctx *ctx = priv;
struct sc_data *sc = ctx->dev->sc;
struct vpe_q_data *d_q_data = >q_data[Q_DATA_DST];
+   struct vpe_q_data *s_q_data = >q_data[Q_DATA_SRC];
+
+   if (ctx->deinterlacing && s_q_data->flags & Q_DATA_IN

[Patch v2 02/35] media: ti-vpe: vpdma: Add multi-instance and multi-client support

2016-11-18 Thread Benoit Parrot
The VPDMA (Video Port DMA) as found in devices such as DRA7xx is
used for both the Video Processing Engine (VPE) and the Video Input
Port (VIP). Some devices may have multiple VIP instances each with
its own VPDMA engine. Within VIP two slices can use a single VPDMA
engine simultaneously. So support for multi instances and multiple
clients has been added to VPDMA. Needed modification to the existing
helper functions were then reflected to VPE.

Multi-clients registers offset have also been added in preparation.

Signed-off-by: Benoit Parrot <bpar...@ti.com>
Acked-by: Hans Verkuil <hans.verk...@cisco.com>
---
 drivers/media/platform/ti-vpe/vpdma.c  | 104 +
 drivers/media/platform/ti-vpe/vpdma.h  |  25 +--
 drivers/media/platform/ti-vpe/vpdma_priv.h |  15 -
 drivers/media/platform/ti-vpe/vpe.c|   8 +--
 4 files changed, 128 insertions(+), 24 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/vpdma.c 
b/drivers/media/platform/ti-vpe/vpdma.c
index 7de0f3f55dcc..2b094016b470 100644
--- a/drivers/media/platform/ti-vpe/vpdma.c
+++ b/drivers/media/platform/ti-vpe/vpdma.c
@@ -437,10 +437,9 @@ EXPORT_SYMBOL(vpdma_list_busy);
 /*
  * submit a list of DMA descriptors to the VPE VPDMA, do not wait for 
completion
  */
-int vpdma_submit_descs(struct vpdma_data *vpdma, struct vpdma_desc_list *list)
+int vpdma_submit_descs(struct vpdma_data *vpdma,
+   struct vpdma_desc_list *list, int list_num)
 {
-   /* we always use the first list */
-   int list_num = 0;
int list_size;
 
if (vpdma_list_busy(vpdma, list_num))
@@ -460,6 +459,40 @@ int vpdma_submit_descs(struct vpdma_data *vpdma, struct 
vpdma_desc_list *list)
 }
 EXPORT_SYMBOL(vpdma_submit_descs);
 
+static void dump_dtd(struct vpdma_dtd *dtd);
+
+void vpdma_update_dma_addr(struct vpdma_data *vpdma,
+   struct vpdma_desc_list *list, dma_addr_t dma_addr,
+   void *write_dtd, int drop, int idx)
+{
+   struct vpdma_dtd *dtd = list->buf.addr;
+   dma_addr_t write_desc_addr;
+   int offset;
+
+   dtd += idx;
+   vpdma_unmap_desc_buf(vpdma, >buf);
+
+   dtd->start_addr = dma_addr;
+
+   /* Calculate write address from the offset of write_dtd from start
+* of the list->buf
+*/
+   offset = (void *)write_dtd - list->buf.addr;
+   write_desc_addr = list->buf.dma_addr + offset;
+
+   if (drop)
+   dtd->desc_write_addr = dtd_desc_write_addr(write_desc_addr,
+  1, 1, 0);
+   else
+   dtd->desc_write_addr = dtd_desc_write_addr(write_desc_addr,
+  1, 0, 0);
+
+   vpdma_map_desc_buf(vpdma, >buf);
+
+   dump_dtd(dtd);
+}
+EXPORT_SYMBOL(vpdma_update_dma_addr);
+
 static void dump_cfd(struct vpdma_cfd *cfd)
 {
int class;
@@ -642,6 +675,16 @@ void vpdma_add_out_dtd(struct vpdma_desc_list *list, int 
width,
const struct vpdma_data_format *fmt, dma_addr_t dma_addr,
enum vpdma_channel chan, u32 flags)
 {
+   vpdma_rawchan_add_out_dtd(list, width, c_rect, fmt, dma_addr,
+ chan_info[chan].num, flags);
+}
+EXPORT_SYMBOL(vpdma_add_out_dtd);
+
+void vpdma_rawchan_add_out_dtd(struct vpdma_desc_list *list, int width,
+   const struct v4l2_rect *c_rect,
+   const struct vpdma_data_format *fmt, dma_addr_t dma_addr,
+   int raw_vpdma_chan, u32 flags)
+{
int priority = 0;
int field = 0;
int notify = 1;
@@ -651,7 +694,7 @@ void vpdma_add_out_dtd(struct vpdma_desc_list *list, int 
width,
int stride;
struct vpdma_dtd *dtd;
 
-   channel = next_chan = chan_info[chan].num;
+   channel = next_chan = raw_vpdma_chan;
 
if (fmt->type == VPDMA_DATA_FMT_TYPE_YUV &&
fmt->data_type == DATA_TYPE_C420) {
@@ -688,7 +731,7 @@ void vpdma_add_out_dtd(struct vpdma_desc_list *list, int 
width,
 
dump_dtd(dtd);
 }
-EXPORT_SYMBOL(vpdma_add_out_dtd);
+EXPORT_SYMBOL(vpdma_rawchan_add_out_dtd);
 
 /*
  * append an inbound data transfer descriptor to the given descriptor list,
@@ -765,25 +808,62 @@ void vpdma_add_in_dtd(struct vpdma_desc_list *list, int 
width,
 EXPORT_SYMBOL(vpdma_add_in_dtd);
 
 /* set or clear the mask for list complete interrupt */
-void vpdma_enable_list_complete_irq(struct vpdma_data *vpdma, int list_num,
-   bool enable)
+void vpdma_enable_list_complete_irq(struct vpdma_data *vpdma, int irq_num,
+   int list_num, bool enable)
 {
+   u32 reg_addr = VPDMA_INT_LIST0_MASK + VPDMA_INTX_OFFSET * irq_num;
u32 val;
 
-   val = read_reg(vpdma, VPDMA_INT_LIST0_MASK);
+   val = read_reg(vpdma, reg_addr);
if (enable)
val |= (1 << (list_num * 2));
else
   

[Patch v2 15/35] media: ti-vpe: vpe: configure line mode separately

2016-11-18 Thread Benoit Parrot
From: Nikhil Devshatwar <nikhil...@ti.com>

Current driver configures the line mode of the DEI clients
from the open function directly. Even if the newly created context
is not yet scheduled, it updates some of the VPDMA registers.
This causes a problem in multi instance use case where just opening
the m2m device second time causes the running job to stall. This
happens especially if the source buffers used are NV12.

While all other configuration is being written to context specific
shadow registers, only line mode configuration is happening directly.

As there is no shadow register for line mode configuration, it's better
to separate the config_mode setting and line_mode setting. Call the
new "set_line_modes" functions only when actually loading the mmrs.
This makes sure that no non-running job will write to the registers
directly.

Signed-off-by: Nikhil Devshatwar <nikhil...@ti.com>
Signed-off-by: Benoit Parrot <bpar...@ti.com>
Acked-by: Hans Verkuil <hans.verk...@cisco.com>
---
 drivers/media/platform/ti-vpe/vpe.c | 25 +
 1 file changed, 17 insertions(+), 8 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/vpe.c 
b/drivers/media/platform/ti-vpe/vpe.c
index 6fcdd0ea50e4..c79137b404ea 100644
--- a/drivers/media/platform/ti-vpe/vpe.c
+++ b/drivers/media/platform/ti-vpe/vpe.c
@@ -660,14 +660,13 @@ static void set_us_coefficients(struct vpe_ctx *ctx)
 /*
  * Set the upsampler config mode and the VPDMA line mode in the shadow MMRs.
  */
-static void set_cfg_and_line_modes(struct vpe_ctx *ctx)
+static void set_cfg_modes(struct vpe_ctx *ctx)
 {
struct vpe_fmt *fmt = ctx->q_data[Q_DATA_SRC].fmt;
struct vpe_mmr_adb *mmr_adb = ctx->mmr_adb.addr;
u32 *us1_reg0 = _adb->us1_regs[0];
u32 *us2_reg0 = _adb->us2_regs[0];
u32 *us3_reg0 = _adb->us3_regs[0];
-   int line_mode = 1;
int cfg_mode = 1;
 
/*
@@ -675,15 +674,24 @@ static void set_cfg_and_line_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)
cfg_mode = 0;
-   line_mode = 0;  /* double lines to line buffer */
-   }
 
write_field(us1_reg0, cfg_mode, VPE_US_MODE_MASK, VPE_US_MODE_SHIFT);
write_field(us2_reg0, cfg_mode, VPE_US_MODE_MASK, VPE_US_MODE_SHIFT);
write_field(us3_reg0, cfg_mode, VPE_US_MODE_MASK, VPE_US_MODE_SHIFT);
 
+   ctx->load_mmrs = true;
+}
+
+static void set_line_modes(struct vpe_ctx *ctx)
+{
+   struct vpe_fmt *fmt = ctx->q_data[Q_DATA_SRC].fmt;
+   int line_mode = 1;
+
+   if (fmt->fourcc == V4L2_PIX_FMT_NV12)
+   line_mode = 0;  /* double lines to line buffer */
+
/* regs for now */
vpdma_set_line_mode(ctx->dev->vpdma, line_mode, VPE_CHAN_CHROMA1_IN);
vpdma_set_line_mode(ctx->dev->vpdma, line_mode, VPE_CHAN_CHROMA2_IN);
@@ -708,8 +716,6 @@ static void set_cfg_and_line_modes(struct vpe_ctx *ctx)
/* frame start for MV in client */
vpdma_set_frame_start_event(ctx->dev->vpdma, 
VPDMA_FSEVENT_CHANNEL_ACTIVE,
VPE_CHAN_MV_IN);
-
-   ctx->load_mmrs = true;
 }
 
 /*
@@ -868,7 +874,7 @@ static int set_srcdst_params(struct vpe_ctx *ctx)
if (ret)
return ret;
 
-   set_cfg_and_line_modes(ctx);
+   set_cfg_modes(ctx);
set_dei_regs(ctx);
 
csc_set_coeff(ctx->dev->csc, _adb->csc_regs[0],
@@ -1184,6 +1190,9 @@ static void device_run(void *priv)
if (ctx->dev->loaded_mmrs != ctx->mmr_adb.dma_addr || ctx->load_mmrs) {
vpdma_map_desc_buf(ctx->dev->vpdma, >mmr_adb);
vpdma_add_cfd_adb(>desc_list, CFD_MMR_CLIENT, 
>mmr_adb);
+
+   set_line_modes(ctx);
+
ctx->dev->loaded_mmrs = ctx->mmr_adb.dma_addr;
ctx->load_mmrs = false;
}
-- 
2.9.0

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Patch v2 13/35] media: ti-vpe: vpdma: Make list post atomic operation

2016-11-18 Thread Benoit Parrot
From: Nikhil Devshatwar <nikhil...@ti.com>

Writing to the "VPDMA list attribute" register is considered as a list
post. This informs the VPDMA firmware to load the list from the address
which should be taken from the "VPDMA list address" register.

As these two register writes are dependent, it is important that the two
writes happen in atomic manner. This ensures multiple slices (which share
same VPDMA) can post lists asynchronously and all of them point to the
correct addresses.

Slightly modified to implementation for the original patch to use
spin_lock instead of mutex as the list post is also called from
interrupt context.

Signed-off-by: Nikhil Devshatwar <nikhil...@ti.com>
Signed-off-by: Benoit Parrot <bpar...@ti.com>
Acked-by: Hans Verkuil <hans.verk...@cisco.com>
---
 drivers/media/platform/ti-vpe/vpdma.c | 4 
 drivers/media/platform/ti-vpe/vpdma.h | 1 +
 2 files changed, 5 insertions(+)

diff --git a/drivers/media/platform/ti-vpe/vpdma.c 
b/drivers/media/platform/ti-vpe/vpdma.c
index 7808c9c1828b..ffc281d2b065 100644
--- a/drivers/media/platform/ti-vpe/vpdma.c
+++ b/drivers/media/platform/ti-vpe/vpdma.c
@@ -491,6 +491,7 @@ int vpdma_submit_descs(struct vpdma_data *vpdma,
struct vpdma_desc_list *list, int list_num)
 {
int list_size;
+   unsigned long flags;
 
if (vpdma_list_busy(vpdma, list_num))
return -EBUSY;
@@ -498,12 +499,14 @@ int vpdma_submit_descs(struct vpdma_data *vpdma,
/* 16-byte granularity */
list_size = (list->next - list->buf.addr) >> 4;
 
+   spin_lock_irqsave(>lock, flags);
write_reg(vpdma, VPDMA_LIST_ADDR, (u32) list->buf.dma_addr);
 
write_reg(vpdma, VPDMA_LIST_ATTR,
(list_num << VPDMA_LIST_NUM_SHFT) |
(list->type << VPDMA_LIST_TYPE_SHFT) |
list_size);
+   spin_unlock_irqrestore(>lock, flags);
 
return 0;
 }
@@ -1090,6 +1093,7 @@ struct vpdma_data *vpdma_create(struct platform_device 
*pdev,
 
vpdma->pdev = pdev;
vpdma->cb = cb;
+   spin_lock_init(>lock);
 
res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "vpdma");
if (res == NULL) {
diff --git a/drivers/media/platform/ti-vpe/vpdma.h 
b/drivers/media/platform/ti-vpe/vpdma.h
index 4dafc1bcf116..f08f4370ce4a 100644
--- a/drivers/media/platform/ti-vpe/vpdma.h
+++ b/drivers/media/platform/ti-vpe/vpdma.h
@@ -35,6 +35,7 @@ struct vpdma_data {
 
struct platform_device  *pdev;
 
+   spinlock_t  lock;
/* callback to VPE driver when the firmware is loaded */
void (*cb)(struct platform_device *pdev);
 };
-- 
2.9.0

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Patch v2 03/35] media: ti-vpe: vpdma: Add helper to set a background color

2016-11-18 Thread Benoit Parrot
Add a helper to set the background color during vpdma transfer.
This is needed when VPDMA is generating 32 bits RGB format
to have the Alpha channel set to an appropriate value.

Signed-off-by: Benoit Parrot <bpar...@ti.com>
Acked-by: Hans Verkuil <hans.verk...@cisco.com>
---
 drivers/media/platform/ti-vpe/vpdma.c | 10 ++
 drivers/media/platform/ti-vpe/vpdma.h |  3 ++-
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/ti-vpe/vpdma.c 
b/drivers/media/platform/ti-vpe/vpdma.c
index 2b094016b470..133154628543 100644
--- a/drivers/media/platform/ti-vpe/vpdma.c
+++ b/drivers/media/platform/ti-vpe/vpdma.c
@@ -867,6 +867,16 @@ void vpdma_clear_list_stat(struct vpdma_data *vpdma, int 
irq_num)
 }
 EXPORT_SYMBOL(vpdma_clear_list_stat);
 
+void vpdma_set_bg_color(struct vpdma_data *vpdma,
+   struct vpdma_data_format *fmt, u32 color)
+{
+   if (fmt->type == VPDMA_DATA_FMT_TYPE_RGB)
+   write_reg(vpdma, VPDMA_BG_RGB, color);
+   else if (fmt->type == VPDMA_DATA_FMT_TYPE_YUV)
+   write_reg(vpdma, VPDMA_BG_YUV, color);
+}
+EXPORT_SYMBOL(vpdma_set_bg_color);
+
 /*
  * configures the output mode of the line buffer for the given client, the
  * line buffer content can either be mirrored(each line repeated twice) or
diff --git a/drivers/media/platform/ti-vpe/vpdma.h 
b/drivers/media/platform/ti-vpe/vpdma.h
index 83325d887546..220dc7e793f6 100644
--- a/drivers/media/platform/ti-vpe/vpdma.h
+++ b/drivers/media/platform/ti-vpe/vpdma.h
@@ -221,7 +221,8 @@ void vpdma_set_line_mode(struct vpdma_data *vpdma, int 
line_mode,
enum vpdma_channel chan);
 void vpdma_set_frame_start_event(struct vpdma_data *vpdma,
enum vpdma_frame_start_event fs_event, enum vpdma_channel chan);
-
+void vpdma_set_bg_color(struct vpdma_data *vpdma,
+   struct vpdma_data_format *fmt, u32 color);
 void vpdma_dump_regs(struct vpdma_data *vpdma);
 
 /* initialize vpdma, passed with VPE's platform device pointer */
-- 
2.9.0

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Patch v2 04/35] media: ti-vpe: vpdma: Fix bus error when vpdma is writing a descriptor

2016-11-18 Thread Benoit Parrot
On DRA7 since l3_noc event are being reported it was found that
when the write descriptor was being written it was consistently
causing bus error events.

The write address was improperly programmed.

Signed-off-by: Benoit Parrot <bpar...@ti.com>
Acked-by: Hans Verkuil <hans.verk...@cisco.com>
---
 drivers/media/platform/ti-vpe/vpdma_priv.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/vpdma_priv.h 
b/drivers/media/platform/ti-vpe/vpdma_priv.h
index 65f0c067bed1..aeade5edc8ac 100644
--- a/drivers/media/platform/ti-vpe/vpdma_priv.h
+++ b/drivers/media/platform/ti-vpe/vpdma_priv.h
@@ -212,6 +212,7 @@ struct vpdma_dtd {
 #define DTD_V_START_MASK   0x
 #define DTD_V_START_SHFT   0
 
+#define DTD_DESC_START_MASK0xffe0
 #define DTD_DESC_START_SHIFT   5
 #define DTD_WRITE_DESC_MASK0x01
 #define DTD_WRITE_DESC_SHIFT   2
@@ -294,7 +295,7 @@ static inline u32 dtd_frame_width_height(int width, int 
height)
 static inline u32 dtd_desc_write_addr(unsigned int addr, bool write_desc,
bool drop_data, bool use_desc)
 {
-   return (addr << DTD_DESC_START_SHIFT) |
+   return (addr & DTD_DESC_START_MASK) |
(write_desc << DTD_WRITE_DESC_SHIFT) |
(drop_data << DTD_DROP_DATA_SHIFT) |
use_desc;
@@ -399,7 +400,7 @@ static inline int dtd_get_frame_height(struct vpdma_dtd 
*dtd)
 
 static inline int dtd_get_desc_write_addr(struct vpdma_dtd *dtd)
 {
-   return dtd->desc_write_addr >> DTD_DESC_START_SHIFT;
+   return dtd->desc_write_addr & DTD_DESC_START_MASK;
 }
 
 static inline bool dtd_get_write_desc(struct vpdma_dtd *dtd)
-- 
2.9.0

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Patch v2 10/35] media: ti-vpe: Free vpdma buffers in vpe_release

2016-11-18 Thread Benoit Parrot
From: Harinarayan Bhatta <harinara...@ti.com>

Free vpdma buffers in vpe_release. Otherwise it was generating random
backtrace.

Signed-off-by: Harinarayan Bhatta <harinara...@ti.com>
Signed-off-by: Somnath Mukherjee <somn...@ti.com>
Signed-off-by: Nikhil Devshatwar <nikhil...@ti.com>
Signed-off-by: Benoit Parrot <bpar...@ti.com>
Acked-by: Hans Verkuil <hans.verk...@cisco.com>
---
 drivers/media/platform/ti-vpe/vpe.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/media/platform/ti-vpe/vpe.c 
b/drivers/media/platform/ti-vpe/vpe.c
index 4b6e8839dd83..f2b90d42b408 100644
--- a/drivers/media/platform/ti-vpe/vpe.c
+++ b/drivers/media/platform/ti-vpe/vpe.c
@@ -2182,6 +2182,9 @@ static int vpe_release(struct file *file)
vpdma_free_desc_list(>desc_list);
vpdma_free_desc_buf(>mmr_adb);
 
+   vpdma_free_desc_buf(>sc_coeff_v);
+   vpdma_free_desc_buf(>sc_coeff_h);
+
v4l2_fh_del(>fh);
v4l2_fh_exit(>fh);
v4l2_ctrl_handler_free(>hdl);
-- 
2.9.0

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Patch v2 09/35] media: ti-vpe: vpe: Return NULL for invalid buffer type

2016-11-18 Thread Benoit Parrot
From: Nikhil Devshatwar <nikhil...@ti.com>

get_q_data can be called with different values for type
e.g. vpe_try_crop calls it with the buffer type which gets passed
from user space

Framework doesn't check wheather its correct type or not
If user space passes wrong type, kernel should not crash.
Return NULL when the passed type is invalid.

Signed-off-by: Nikhil Devshatwar <nikhil...@ti.com>
Signed-off-by: Benoit Parrot <bpar...@ti.com>
Acked-by: Hans Verkuil <hans.verk...@cisco.com>
---
 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 c624f5db7f08..4b6e8839dd83 100644
--- a/drivers/media/platform/ti-vpe/vpe.c
+++ b/drivers/media/platform/ti-vpe/vpe.c
@@ -420,7 +420,7 @@ static struct vpe_q_data *get_q_data(struct vpe_ctx *ctx,
case V4L2_BUF_TYPE_VIDEO_CAPTURE:
return >q_data[Q_DATA_DST];
default:
-   BUG();
+   return NULL;
}
return NULL;
 }
-- 
2.9.0

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Patch v2 19/35] media: ti-vpe: vpdma: allocate and maintain hwlist

2016-11-18 Thread Benoit Parrot
From: Nikhil Devshatwar <nikhil...@ti.com>

VPDMA block used in ti-vip and ti-vpe modules have support for
up to 8 hardware descriptor lists. A descriptor list can be
submitted to any of the 8 lists (as long as it's not busy).

When multiple clients want to transfer data in parallel, its easier
to allocate one list per client and let it use it. This way, the
list numbers need not be hard-coded into the driver.

Add support for allocating hwlist and maintain them with a priv data.

Signed-off-by: Nikhil Devshatwar <nikhil...@ti.com>
Signed-off-by: Benoit Parrot <bpar...@ti.com>
Acked-by: Hans Verkuil <hans.verk...@cisco.com>
---
 drivers/media/platform/ti-vpe/vpdma.c | 44 +++
 drivers/media/platform/ti-vpe/vpdma.h |  9 +++
 2 files changed, 53 insertions(+)

diff --git a/drivers/media/platform/ti-vpe/vpdma.c 
b/drivers/media/platform/ti-vpe/vpdma.c
index c0a4e035bc2a..f85727a0ac44 100644
--- a/drivers/media/platform/ti-vpe/vpdma.c
+++ b/drivers/media/platform/ti-vpe/vpdma.c
@@ -902,6 +902,50 @@ void vpdma_add_in_dtd(struct vpdma_desc_list *list, int 
width,
 }
 EXPORT_SYMBOL(vpdma_add_in_dtd);
 
+int vpdma_hwlist_alloc(struct vpdma_data *vpdma, void *priv)
+{
+   int i, list_num = -1;
+   unsigned long flags;
+
+   spin_lock_irqsave(>lock, flags);
+   for (i = 0; i < VPDMA_MAX_NUM_LIST &&
+   vpdma->hwlist_used[i] == true; i++)
+   ;
+
+   if (i < VPDMA_MAX_NUM_LIST) {
+   list_num = i;
+   vpdma->hwlist_used[i] = true;
+   vpdma->hwlist_priv[i] = priv;
+   }
+   spin_unlock_irqrestore(>lock, flags);
+
+   return list_num;
+}
+EXPORT_SYMBOL(vpdma_hwlist_alloc);
+
+void *vpdma_hwlist_get_priv(struct vpdma_data *vpdma, int list_num)
+{
+   if (!vpdma || list_num >= VPDMA_MAX_NUM_LIST)
+   return NULL;
+
+   return vpdma->hwlist_priv[list_num];
+}
+EXPORT_SYMBOL(vpdma_hwlist_get_priv);
+
+void *vpdma_hwlist_release(struct vpdma_data *vpdma, int list_num)
+{
+   void *priv;
+   unsigned long flags;
+
+   spin_lock_irqsave(>lock, flags);
+   vpdma->hwlist_used[list_num] = false;
+   priv = vpdma->hwlist_priv;
+   spin_unlock_irqrestore(>lock, flags);
+
+   return priv;
+}
+EXPORT_SYMBOL(vpdma_hwlist_release);
+
 /* set or clear the mask for list complete interrupt */
 void vpdma_enable_list_complete_irq(struct vpdma_data *vpdma, int irq_num,
int list_num, bool enable)
diff --git a/drivers/media/platform/ti-vpe/vpdma.h 
b/drivers/media/platform/ti-vpe/vpdma.h
index 65961147e8f7..ccf871ad8800 100644
--- a/drivers/media/platform/ti-vpe/vpdma.h
+++ b/drivers/media/platform/ti-vpe/vpdma.h
@@ -13,6 +13,7 @@
 #ifndef __TI_VPDMA_H_
 #define __TI_VPDMA_H_
 
+#define VPDMA_MAX_NUM_LIST 8
 /*
  * A vpdma_buf tracks the size, DMA address and mapping status of each
  * driver DMA area.
@@ -36,6 +37,8 @@ struct vpdma_data {
struct platform_device  *pdev;
 
spinlock_t  lock;
+   boolhwlist_used[VPDMA_MAX_NUM_LIST];
+   void*hwlist_priv[VPDMA_MAX_NUM_LIST];
/* callback to VPE driver when the firmware is loaded */
void (*cb)(struct platform_device *pdev);
 };
@@ -215,6 +218,12 @@ bool vpdma_list_busy(struct vpdma_data *vpdma, int 
list_num);
 void vpdma_update_dma_addr(struct vpdma_data *vpdma,
struct vpdma_desc_list *list, dma_addr_t dma_addr,
void *write_dtd, int drop, int idx);
+
+/* VPDMA hardware list funcs */
+int vpdma_hwlist_alloc(struct vpdma_data *vpdma, void *priv);
+void *vpdma_hwlist_get_priv(struct vpdma_data *vpdma, int list_num);
+void *vpdma_hwlist_release(struct vpdma_data *vpdma, int list_num);
+
 /* helpers for creating vpdma descriptors */
 void vpdma_add_cfd_block(struct vpdma_desc_list *list, int client,
struct vpdma_buf *blk, u32 dest_offset);
-- 
2.9.0

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Patch v2 06/35] media: ti-vpe: vpe: Do not perform job transaction atomically

2016-11-18 Thread Benoit Parrot
From: Nikhil Devshatwar <nikhil...@ti.com>

Current VPE driver does not start the job until all the buffers for
a transaction are queued. When running in multiple context, this might
increase the processing latency.

Alternate solution would be to try to continue the same context as long as
buffers for the transaction are ready; else switch the context. This may
increase number of context switches but it reduces latency significantly.

In this approach, the job_ready always succeeds as long as there are
buffers on the CAPTURE and OUTPUT stream. Processing may start immediately
as the first 2 iterations don't need extra source buffers. Shift all the
source buffers after each iteration and remove the oldest buffer.

Also, with this removes the constraint of pre buffering 3 buffers before
call to STREAMON in case of de-interlacing.

Signed-off-by: Nikhil Devshatwar <nikhil...@ti.com>
Signed-off-by: Benoit Parrot <bpar...@ti.com>
---
 drivers/media/platform/ti-vpe/vpe.c | 32 
 1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/vpe.c 
b/drivers/media/platform/ti-vpe/vpe.c
index ad838b8a98c4..9b7b9be5641d 100644
--- a/drivers/media/platform/ti-vpe/vpe.c
+++ b/drivers/media/platform/ti-vpe/vpe.c
@@ -898,15 +898,14 @@ static struct vpe_ctx *file2ctx(struct file *file)
 static int job_ready(void *priv)
 {
struct vpe_ctx *ctx = priv;
-   int needed = ctx->bufs_per_job;
 
-   if (ctx->deinterlacing && ctx->src_vbs[2] == NULL)
-   needed += 2;/* need additional two most recent fields */
-
-   if (v4l2_m2m_num_src_bufs_ready(ctx->fh.m2m_ctx) < needed)
-   return 0;
-
-   if (v4l2_m2m_num_dst_bufs_ready(ctx->fh.m2m_ctx) < needed)
+   /*
+* This check is needed as this might be called directly from driver
+* When called by m2m framework, this will always satisfy, but when
+* called from vpe_irq, this might fail. (src stream with zero buffers)
+*/
+   if (v4l2_m2m_num_src_bufs_ready(ctx->fh.m2m_ctx) <= 0 ||
+   v4l2_m2m_num_dst_bufs_ready(ctx->fh.m2m_ctx) <= 0)
return 0;
 
return 1;
@@ -1116,19 +1115,20 @@ static void device_run(void *priv)
struct sc_data *sc = ctx->dev->sc;
struct vpe_q_data *d_q_data = >q_data[Q_DATA_DST];
 
-   if (ctx->deinterlacing && ctx->src_vbs[2] == NULL) {
-   ctx->src_vbs[2] = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx);
-   WARN_ON(ctx->src_vbs[2] == NULL);
-   ctx->src_vbs[1] = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx);
-   WARN_ON(ctx->src_vbs[1] == NULL);
-   }
-
ctx->src_vbs[0] = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx);
WARN_ON(ctx->src_vbs[0] == NULL);
ctx->dst_vb = v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx);
WARN_ON(ctx->dst_vb == NULL);
 
if (ctx->deinterlacing) {
+
+   if (ctx->src_vbs[2] == NULL) {
+   ctx->src_vbs[2] = ctx->src_vbs[0];
+   WARN_ON(ctx->src_vbs[2] == NULL);
+   ctx->src_vbs[1] = ctx->src_vbs[0];
+   WARN_ON(ctx->src_vbs[1] == NULL);
+   }
+
/*
 * we have output the first 2 frames through line average, we
 * now switch to EDI de-interlacer
@@ -1348,7 +1348,7 @@ static irqreturn_t vpe_irq(int irq_vpe, void *data)
}
 
ctx->bufs_completed++;
-   if (ctx->bufs_completed < ctx->bufs_per_job) {
+   if (ctx->bufs_completed < ctx->bufs_per_job && job_ready(ctx)) {
device_run(ctx);
goto handled;
}
-- 
2.9.0

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Patch v2 16/35] media: ti-vpe: vpe: Setup srcdst parameters in start_streaming

2016-11-18 Thread Benoit Parrot
From: Nikhil Devshatwar <nikhil...@ti.com>

For deinterlacing operation, each operation needs 2 fields in the
history. This is achieved by holding three buffers in
ctx->src_vbs[0,1,2] (f,f-1,f-2)

This is achieved by using the ctx->sequence which gets reset via the
s_fmt ioctl.

These buffers are dequeued in stream OFF by calling free_vbs()
But the corresponding references aren't removed anywhere.

When application tries to stream ON and OFF continuously, s_fmt ioctl
won't be called and it won't setup the srcdst parameters.

Setting source/destination parameters in stream ON ioctl would make
sure that the context is re-initialized before it is being used by
the driver.

Signed-off-by: Nikhil Devshatwar <nikhil...@ti.com>
Signed-off-by: Benoit Parrot <bpar...@ti.com>
Acked-by: Hans Verkuil <hans.verk...@cisco.com>
---
 drivers/media/platform/ti-vpe/vpe.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/media/platform/ti-vpe/vpe.c 
b/drivers/media/platform/ti-vpe/vpe.c
index c79137b404ea..1ee7e611e41b 100644
--- a/drivers/media/platform/ti-vpe/vpe.c
+++ b/drivers/media/platform/ti-vpe/vpe.c
@@ -869,6 +869,7 @@ static int set_srcdst_params(struct vpe_ctx *ctx)
}
 
free_vbs(ctx);
+   ctx->src_vbs[2] = ctx->src_vbs[1] = ctx->src_vbs[0] = NULL;
 
ret = realloc_mv_buffers(ctx, mv_buf_size);
if (ret)
@@ -1990,6 +1991,9 @@ static int vpe_start_streaming(struct vb2_queue *q, 
unsigned int count)
if (ctx->deinterlacing)
config_edi_input_mode(ctx, 0x0);
 
+   if (ctx->sequence != 0)
+   set_srcdst_params(ctx);
+
return 0;
 }
 
-- 
2.9.0

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Patch v2 11/35] media: ti-vpe: vpdma: Add support for setting max width height

2016-11-18 Thread Benoit Parrot
From: Nikhil Devshatwar <nikhil...@ti.com>

Add a helper function to be able to set the maximum
VPDMA transfer size to limit potential buffer overrun.

Added enums for max_width and max_height fields of the
outbound data descriptor.

Changed vpdma_add_out_dtd to accept two more arguments
for max width and height.

Make use of different max width & height sets for different
of capture module (i.e. slices).

Signed-off-by: Nikhil Devshatwar <nikhil...@ti.com>
Signed-off-by: Benoit Parrot <bpar...@ti.com>
Acked-by: Hans Verkuil <hans.verk...@cisco.com>
---
 drivers/media/platform/ti-vpe/vpdma.c  | 27 
 drivers/media/platform/ti-vpe/vpdma.h  | 32 ++--
 drivers/media/platform/ti-vpe/vpdma_priv.h | 40 +++---
 drivers/media/platform/ti-vpe/vpe.c|  7 +-
 4 files changed, 62 insertions(+), 44 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/vpdma.c 
b/drivers/media/platform/ti-vpe/vpdma.c
index 133154628543..1a0152842a17 100644
--- a/drivers/media/platform/ti-vpe/vpdma.c
+++ b/drivers/media/platform/ti-vpe/vpdma.c
@@ -493,6 +493,22 @@ void vpdma_update_dma_addr(struct vpdma_data *vpdma,
 }
 EXPORT_SYMBOL(vpdma_update_dma_addr);
 
+void vpdma_set_max_size(struct vpdma_data *vpdma, int reg_addr,
+   u32 width, u32 height)
+{
+   if (reg_addr != VPDMA_MAX_SIZE1 && reg_addr != VPDMA_MAX_SIZE2 &&
+   reg_addr != VPDMA_MAX_SIZE3)
+   reg_addr = VPDMA_MAX_SIZE1;
+
+   write_field_reg(vpdma, reg_addr, width - 1,
+   VPDMA_MAX_SIZE_WIDTH_MASK, VPDMA_MAX_SIZE_WIDTH_SHFT);
+
+   write_field_reg(vpdma, reg_addr, height - 1,
+   VPDMA_MAX_SIZE_HEIGHT_MASK, VPDMA_MAX_SIZE_HEIGHT_SHFT);
+
+}
+EXPORT_SYMBOL(vpdma_set_max_size);
+
 static void dump_cfd(struct vpdma_cfd *cfd)
 {
int class;
@@ -667,23 +683,25 @@ static void dump_dtd(struct vpdma_dtd *dtd)
  * @c_rect: compose params of output image
  * @fmt: vpdma data format of the buffer
  * dma_addr: dma address as seen by VPDMA
+ * max_width: enum for maximum width of data transfer
+ * max_height: enum for maximum height of data transfer
  * chan: VPDMA channel
  * flags: VPDMA flags to configure some descriptor fileds
  */
 void vpdma_add_out_dtd(struct vpdma_desc_list *list, int width,
const struct v4l2_rect *c_rect,
const struct vpdma_data_format *fmt, dma_addr_t dma_addr,
-   enum vpdma_channel chan, u32 flags)
+   int max_w, int max_h, enum vpdma_channel chan, u32 flags)
 {
vpdma_rawchan_add_out_dtd(list, width, c_rect, fmt, dma_addr,
- chan_info[chan].num, flags);
+ max_w, max_h, chan_info[chan].num, flags);
 }
 EXPORT_SYMBOL(vpdma_add_out_dtd);
 
 void vpdma_rawchan_add_out_dtd(struct vpdma_desc_list *list, int width,
const struct v4l2_rect *c_rect,
const struct vpdma_data_format *fmt, dma_addr_t dma_addr,
-   int raw_vpdma_chan, u32 flags)
+   int max_w, int max_h, int raw_vpdma_chan, u32 flags)
 {
int priority = 0;
int field = 0;
@@ -722,8 +740,7 @@ void vpdma_rawchan_add_out_dtd(struct vpdma_desc_list 
*list, int width,
dtd->pkt_ctl = dtd_pkt_ctl(!!(flags & VPDMA_DATA_MODE_TILED),
DTD_DIR_OUT, channel, priority, next_chan);
dtd->desc_write_addr = dtd_desc_write_addr(0, 0, 0, 0);
-   dtd->max_width_height = dtd_max_width_height(MAX_OUT_WIDTH_1920,
-   MAX_OUT_HEIGHT_1080);
+   dtd->max_width_height = dtd_max_width_height(max_w, max_h);
dtd->client_attr0 = 0;
dtd->client_attr1 = 0;
 
diff --git a/drivers/media/platform/ti-vpe/vpdma.h 
b/drivers/media/platform/ti-vpe/vpdma.h
index 220dc7e793f6..32b9ed5191c5 100644
--- a/drivers/media/platform/ti-vpe/vpdma.h
+++ b/drivers/media/platform/ti-vpe/vpdma.h
@@ -117,6 +117,30 @@ enum vpdma_frame_start_event {
VPDMA_FSEVENT_CHANNEL_ACTIVE,
 };
 
+/* max width configurations */
+enum vpdma_max_width {
+   MAX_OUT_WIDTH_UNLIMITED = 0,
+   MAX_OUT_WIDTH_REG1,
+   MAX_OUT_WIDTH_REG2,
+   MAX_OUT_WIDTH_REG3,
+   MAX_OUT_WIDTH_352,
+   MAX_OUT_WIDTH_768,
+   MAX_OUT_WIDTH_1280,
+   MAX_OUT_WIDTH_1920,
+};
+
+/* max height configurations */
+enum vpdma_max_height {
+   MAX_OUT_HEIGHT_UNLIMITED = 0,
+   MAX_OUT_HEIGHT_REG1,
+   MAX_OUT_HEIGHT_REG2,
+   MAX_OUT_HEIGHT_REG3,
+   MAX_OUT_HEIGHT_288,
+   MAX_OUT_HEIGHT_576,
+   MAX_OUT_HEIGHT_720,
+   MAX_OUT_HEIGHT_1080,
+};
+
 /*
  * VPDMA channel numbers
  */
@@ -198,11 +222,12 @@ void vpdma_add_sync_on_channel_ctd(struct vpdma_desc_list 
*list,
 void vpdma_add_out_dtd(struct vpdma_desc_list *list, int width,
const struct v4l2_rect *c_rect,
  

[Patch v2 22/35] media: ti-vpe: vpdma: RGB data type yield inverted data

2016-11-18 Thread Benoit Parrot
The VPDMA RGB data type definition have been updated
to match with Errata i839.

But some of the ARGB definition appeared to be wrong
in the document also. As they would yield RGBA instead.
They have been corrected based on experimentation.

Signed-off-by: Benoit Parrot <bpar...@ti.com>
Acked-by: Hans Verkuil <hans.verk...@cisco.com>
---
 drivers/media/platform/ti-vpe/vpdma_priv.h | 49 ++
 1 file changed, 29 insertions(+), 20 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/vpdma_priv.h 
b/drivers/media/platform/ti-vpe/vpdma_priv.h
index f974a803fa27..72c7f13b4a9d 100644
--- a/drivers/media/platform/ti-vpe/vpdma_priv.h
+++ b/drivers/media/platform/ti-vpe/vpdma_priv.h
@@ -101,26 +101,35 @@
 #define DATA_TYPE_CBY422   0x27
 #define DATA_TYPE_CRY422   0x37
 
-#define DATA_TYPE_RGB16_5650x0
-#define DATA_TYPE_ARGB_15550x1
-#define DATA_TYPE_ARGB_0x2
-#define DATA_TYPE_RGBA_55510x3
-#define DATA_TYPE_RGBA_0x4
-#define DATA_TYPE_ARGB24_  0x5
-#define DATA_TYPE_RGB24_8880x6
-#define DATA_TYPE_ARGB32_  0x7
-#define DATA_TYPE_RGBA24_  0x8
-#define DATA_TYPE_RGBA32_  0x9
-#define DATA_TYPE_BGR16_5650x10
-#define DATA_TYPE_ABGR_15550x11
-#define DATA_TYPE_ABGR_0x12
-#define DATA_TYPE_BGRA_55510x13
-#define DATA_TYPE_BGRA_0x14
-#define DATA_TYPE_ABGR24_  0x15
-#define DATA_TYPE_BGR24_8880x16
-#define DATA_TYPE_ABGR32_  0x17
-#define DATA_TYPE_BGRA24_  0x18
-#define DATA_TYPE_BGRA32_  0x19
+/*
+ * The RGB data type definition below are defined
+ * to follow Errata i819.
+ * The initial values were taken from:
+ * VPDMA_data_type_mapping_v0.2vayu_c.pdf
+ * But some of the ARGB definition appeared to be wrong
+ * in the document also. As they would yield RGBA instead.
+ * They have been corrected based on experimentation.
+ */
+#define DATA_TYPE_RGB16_5650x10
+#define DATA_TYPE_ARGB_15550x13
+#define DATA_TYPE_ARGB_0x14
+#define DATA_TYPE_RGBA_55510x11
+#define DATA_TYPE_RGBA_0x12
+#define DATA_TYPE_ARGB24_  0x18
+#define DATA_TYPE_RGB24_8880x16
+#define DATA_TYPE_ARGB32_  0x17
+#define DATA_TYPE_RGBA24_  0x15
+#define DATA_TYPE_RGBA32_  0x19
+#define DATA_TYPE_BGR16_5650x0
+#define DATA_TYPE_ABGR_15550x3
+#define DATA_TYPE_ABGR_0x4
+#define DATA_TYPE_BGRA_55510x1
+#define DATA_TYPE_BGRA_0x2
+#define DATA_TYPE_ABGR24_  0x8
+#define DATA_TYPE_BGR24_8880x6
+#define DATA_TYPE_ABGR32_  0x7
+#define DATA_TYPE_BGRA24_  0x5
+#define DATA_TYPE_BGRA32_  0x9
 
 #define DATA_TYPE_MV   0x3
 
-- 
2.9.0

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Patch v2 17/35] media: ti-vpe: vpe: Post next descriptor only for list complete IRQ

2016-11-18 Thread Benoit Parrot
From: Nikhil Devshatwar <nikhil...@ti.com>

vpe_irq checks for the possible interrupt sources and prints the
errors for the DEI_ERROR and DS_UV interrupts. But it also post the
next descriptor list irrespective of whichever interrupt has occurred.

Because of this, driver may release the buffers even before DMA is
complete and also schedule next descriptor list.

Fix this by _actually_ handling the IRQ only when ListComplete IRQ
occurs.

Signed-off-by: Nikhil Devshatwar <nikhil...@ti.com>
Signed-off-by: Benoit Parrot <bpar...@ti.com>
Acked-by: Hans Verkuil <hans.verk...@cisco.com>
---
 drivers/media/platform/ti-vpe/vpe.c | 9 +
 1 file changed, 9 insertions(+)

diff --git a/drivers/media/platform/ti-vpe/vpe.c 
b/drivers/media/platform/ti-vpe/vpe.c
index 1ee7e611e41b..0f652a049ede 100644
--- a/drivers/media/platform/ti-vpe/vpe.c
+++ b/drivers/media/platform/ti-vpe/vpe.c
@@ -1304,6 +1304,7 @@ static irqreturn_t vpe_irq(int irq_vpe, void *data)
struct vb2_v4l2_buffer *s_vb, *d_vb;
unsigned long flags;
u32 irqst0, irqst1;
+   bool list_complete = false;
 
irqst0 = read_reg(dev, VPE_INT0_STATUS0);
if (irqst0) {
@@ -1339,6 +1340,7 @@ static irqreturn_t vpe_irq(int irq_vpe, void *data)
vpdma_clear_list_stat(ctx->dev->vpdma, 0, 0);
 
irqst0 &= ~(VPE_INT0_LIST0_COMPLETE);
+   list_complete = true;
}
 
if (irqst0 | irqst1) {
@@ -1346,6 +1348,13 @@ static irqreturn_t vpe_irq(int irq_vpe, void *data)
irqst0, irqst1);
}
 
+   /*
+* Setup next operation only when list complete IRQ occurs
+* otherwise, skip the following code
+*/
+   if (!list_complete)
+   goto handled;
+
disable_irqs(ctx);
 
vpdma_unmap_desc_buf(dev->vpdma, >desc_list.buf);
-- 
2.9.0

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Patch v2 20/35] media: ti-vpe: vpe: Added MODULE_DEVICE_TABLE hint

2016-11-18 Thread Benoit Parrot
ti_vpe module currently does not get loaded automatically.
Added MODULE_DEVICE_TABLE hint to the driver to assist.

Signed-off-by: Benoit Parrot <bpar...@ti.com>
Acked-by: Hans Verkuil <hans.verk...@cisco.com>
Reviewed-by: Javier Martinez Canillas <jav...@osg.samsung.com>
---
 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 d3412accf564..05b793595ce9 100644
--- a/drivers/media/platform/ti-vpe/vpe.c
+++ b/drivers/media/platform/ti-vpe/vpe.c
@@ -2447,6 +2447,7 @@ static const struct of_device_id vpe_of_match[] = {
},
{},
 };
+MODULE_DEVICE_TABLE(of, vpe_of_match);
 #endif
 
 static struct platform_driver vpe_pdrv = {
-- 
2.9.0

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Patch v2 18/35] media: ti-vpe: vpe: Add RGB565 and RGB5551 support

2016-11-18 Thread Benoit Parrot
From: Nikhil Devshatwar <nikhil...@ti.com>

VPE hardware can generate output in RGB565 or in RGB5551 format.
Add these formats in the supported format list for CAPTURE stream.
Also, for RGB5551 format, the alpha component is not processed,
so the alpha value is taken from the default color.
Set the default color to make alpha component full when the dst
format is of RGB color space.

Signed-off-by: Nikhil Devshatwar <nikhil...@ti.com>
Signed-off-by: Benoit Parrot <bpar...@ti.com>
Acked-by: Hans Verkuil <hans.verk...@cisco.com>
---
 drivers/media/platform/ti-vpe/vpe.c | 22 --
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/vpe.c 
b/drivers/media/platform/ti-vpe/vpe.c
index 0f652a049ede..d3412accf564 100644
--- a/drivers/media/platform/ti-vpe/vpe.c
+++ b/drivers/media/platform/ti-vpe/vpe.c
@@ -302,6 +302,22 @@ static struct vpe_fmt vpe_formats[] = {
.vpdma_fmt  = { _rgb_fmts[VPDMA_DATA_FMT_ABGR32],
  },
},
+   {
+   .name   = "RGB565",
+   .fourcc = V4L2_PIX_FMT_RGB565,
+   .types  = VPE_FMT_TYPE_CAPTURE,
+   .coplanar   = 0,
+   .vpdma_fmt  = { _rgb_fmts[VPDMA_DATA_FMT_RGB565],
+ },
+   },
+   {
+   .name   = "RGB5551",
+   .fourcc = V4L2_PIX_FMT_RGB555,
+   .types  = VPE_FMT_TYPE_CAPTURE,
+   .coplanar   = 0,
+   .vpdma_fmt  = { _rgb_fmts[VPDMA_DATA_FMT_RGBA16_5551],
+ },
+   },
 };
 
 /*
@@ -738,9 +754,11 @@ static void set_dst_registers(struct vpe_ctx *ctx)
struct vpe_fmt *fmt = ctx->q_data[Q_DATA_DST].fmt;
u32 val = 0;
 
-   if (clrspc == V4L2_COLORSPACE_SRGB)
+   if (clrspc == V4L2_COLORSPACE_SRGB) {
val |= VPE_RGB_OUT_SELECT;
-   else if (fmt->fourcc == V4L2_PIX_FMT_NV16)
+   vpdma_set_bg_color(ctx->dev->vpdma,
+   (struct vpdma_data_format *)fmt->vpdma_fmt[0], 0xff);
+   } else if (fmt->fourcc == V4L2_PIX_FMT_NV16)
val |= VPE_COLOR_SEPARATE_422;
 
/*
-- 
2.9.0

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Patch v2 21/35] media: ti-vpe: vpdma: Corrected YUV422 data type label.

2016-11-18 Thread Benoit Parrot
The YUV data type definition below are taken from
both the TRM and i839 Errata information.
Use the correct data type considering byte
reordering of components.

Added the 2 missing YUV422 variant.
Also since the single use of "C" in the 422 case
to mean "Cr" (i.e. V component). It was decided
to explicitly label them CR to remove any confusion.
Bear in mind that the type label refer to the memory
packed order (LSB - MSB).

Signed-off-by: Benoit Parrot <bpar...@ti.com>
Acked-by: Hans Verkuil <hans.verk...@cisco.com>
---
 drivers/media/platform/ti-vpe/vpdma.c  | 18 ++
 drivers/media/platform/ti-vpe/vpdma.h  |  6 --
 drivers/media/platform/ti-vpe/vpdma_priv.h | 19 ---
 drivers/media/platform/ti-vpe/vpe.c|  8 
 4 files changed, 38 insertions(+), 13 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/vpdma.c 
b/drivers/media/platform/ti-vpe/vpdma.c
index f85727a0ac44..8f0d608c70f6 100644
--- a/drivers/media/platform/ti-vpe/vpdma.c
+++ b/drivers/media/platform/ti-vpe/vpdma.c
@@ -59,9 +59,9 @@ const struct vpdma_data_format vpdma_yuv_fmts[] = {
.data_type  = DATA_TYPE_C420,
.depth  = 4,
},
-   [VPDMA_DATA_FMT_YC422] = {
+   [VPDMA_DATA_FMT_YCR422] = {
.type   = VPDMA_DATA_FMT_TYPE_YUV,
-   .data_type  = DATA_TYPE_YC422,
+   .data_type  = DATA_TYPE_YCR422,
.depth  = 16,
},
[VPDMA_DATA_FMT_YC444] = {
@@ -69,9 +69,19 @@ const struct vpdma_data_format vpdma_yuv_fmts[] = {
.data_type  = DATA_TYPE_YC444,
.depth  = 24,
},
-   [VPDMA_DATA_FMT_CY422] = {
+   [VPDMA_DATA_FMT_CRY422] = {
.type   = VPDMA_DATA_FMT_TYPE_YUV,
-   .data_type  = DATA_TYPE_CY422,
+   .data_type  = DATA_TYPE_CRY422,
+   .depth  = 16,
+   },
+   [VPDMA_DATA_FMT_CBY422] = {
+   .type   = VPDMA_DATA_FMT_TYPE_YUV,
+   .data_type  = DATA_TYPE_CBY422,
+   .depth  = 16,
+   },
+   [VPDMA_DATA_FMT_YCB422] = {
+   .type   = VPDMA_DATA_FMT_TYPE_YUV,
+   .data_type  = DATA_TYPE_YCB422,
.depth  = 16,
},
 };
diff --git a/drivers/media/platform/ti-vpe/vpdma.h 
b/drivers/media/platform/ti-vpe/vpdma.h
index ccf871ad8800..405a6febc254 100644
--- a/drivers/media/platform/ti-vpe/vpdma.h
+++ b/drivers/media/platform/ti-vpe/vpdma.h
@@ -74,9 +74,11 @@ enum vpdma_yuv_formats {
VPDMA_DATA_FMT_C444,
VPDMA_DATA_FMT_C422,
VPDMA_DATA_FMT_C420,
-   VPDMA_DATA_FMT_YC422,
+   VPDMA_DATA_FMT_YCR422,
VPDMA_DATA_FMT_YC444,
-   VPDMA_DATA_FMT_CY422,
+   VPDMA_DATA_FMT_CRY422,
+   VPDMA_DATA_FMT_CBY422,
+   VPDMA_DATA_FMT_YCB422,
 };
 
 enum vpdma_rgb_formats {
diff --git a/drivers/media/platform/ti-vpe/vpdma_priv.h 
b/drivers/media/platform/ti-vpe/vpdma_priv.h
index 54b6aa866c74..f974a803fa27 100644
--- a/drivers/media/platform/ti-vpe/vpdma_priv.h
+++ b/drivers/media/platform/ti-vpe/vpdma_priv.h
@@ -77,16 +77,29 @@
 #define VPDMA_LIST_TYPE_SHFT   16
 #define VPDMA_LIST_SIZE_MASK   0x
 
-/* VPDMA data type values for data formats */
+/*
+ * The YUV data type definition below are taken from
+ * both the TRM and i839 Errata information.
+ * Use the correct data type considering byte
+ * reordering of components.
+ *
+ * Also since the single use of "C" in the 422 case
+ * to mean "Cr" (i.e. V component). It was decided
+ * to explicitly label them CR to remove any confusion.
+ * Bear in mind that the type label refer to the memory
+ * packed order (LSB - MSB).
+ */
 #define DATA_TYPE_Y444 0x0
 #define DATA_TYPE_Y422 0x1
 #define DATA_TYPE_Y420 0x2
 #define DATA_TYPE_C444 0x4
 #define DATA_TYPE_C422 0x5
 #define DATA_TYPE_C420 0x6
-#define DATA_TYPE_YC4220x7
 #define DATA_TYPE_YC4440x8
-#define DATA_TYPE_CY4220x27
+#define DATA_TYPE_YCB422   0x7
+#define DATA_TYPE_YCR422   0x17
+#define DATA_TYPE_CBY422   0x27
+#define DATA_TYPE_CRY422   0x37
 
 #define DATA_TYPE_RGB16_5650x0
 #define DATA_TYPE_ARGB_15550x1
diff --git a/drivers/media/platform/ti-vpe/vpe.c 
b/drivers/media/platform/ti-vpe/vpe.c
index 05b793595ce9..ef55fb45d0be 100644
--- a/drivers/media/platform/ti-vpe/vpe.c
+++ b/drivers/media/platform/ti-vpe/vpe.c
@@ -237,7 +237,7 @@ struct vpe_fmt {
 
 static struct vpe_fmt vpe_formats[] = {
{

[Patch v2 23/35] media: ti-vpe: sc: Fix incorrect optimization

2016-11-18 Thread Benoit Parrot
From: Nikhil Devshatwar <nikhil...@ti.com>

Current scaler library implementation of sc_set_hs_coeffs and
sc_set_vs_coeffs tries to return immediately if the calculated
coefficient index is already being used.

As the same scaler block is going to be used for all the VPE contexts,
even if the calculated index is same, the parameters have to be
reconfigured for each of the context.

Because of this, when multiple contexts use the same coefficients,
all other contexts would have zero scaling coefficients.
Fix this and also remove the unnecessary hs_index and vs_index fields.

Signed-off-by: Nikhil Devshatwar <nikhil...@ti.com>
Signed-off-by: Benoit Parrot <bpar...@ti.com>
Acked-by: Hans Verkuil <hans.verk...@cisco.com>
---
 drivers/media/platform/ti-vpe/sc.c | 9 -
 drivers/media/platform/ti-vpe/sc.h | 3 ---
 2 files changed, 12 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/sc.c 
b/drivers/media/platform/ti-vpe/sc.c
index f82d1c7f667f..02f3dae8ae42 100644
--- a/drivers/media/platform/ti-vpe/sc.c
+++ b/drivers/media/platform/ti-vpe/sc.c
@@ -84,9 +84,6 @@ void sc_set_hs_coeffs(struct sc_data *sc, void *addr, 
unsigned int src_w,
}
}
 
-   if (idx == sc->hs_index)
-   return;
-
cp = scaler_hs_coeffs[idx];
 
for (i = 0; i < SC_NUM_PHASES * 2; i++) {
@@ -101,8 +98,6 @@ void sc_set_hs_coeffs(struct sc_data *sc, void *addr, 
unsigned int src_w,
coeff_h += SC_NUM_TAPS_MEM_ALIGN - SC_H_NUM_TAPS;
}
 
-   sc->hs_index = idx;
-
sc->load_coeff_h = true;
 }
 
@@ -130,9 +125,6 @@ void sc_set_vs_coeffs(struct sc_data *sc, void *addr, 
unsigned int src_h,
idx = VS_LT_9_16_SCALE + sixteenths - 8;
}
 
-   if (idx == sc->vs_index)
-   return;
-
cp = scaler_vs_coeffs[idx];
 
for (i = 0; i < SC_NUM_PHASES * 2; i++) {
@@ -146,7 +138,6 @@ void sc_set_vs_coeffs(struct sc_data *sc, void *addr, 
unsigned int src_h,
coeff_v += SC_NUM_TAPS_MEM_ALIGN - SC_V_NUM_TAPS;
}
 
-   sc->vs_index = idx;
sc->load_coeff_v = true;
 }
 
diff --git a/drivers/media/platform/ti-vpe/sc.h 
b/drivers/media/platform/ti-vpe/sc.h
index 60e411e05c30..de947db98990 100644
--- a/drivers/media/platform/ti-vpe/sc.h
+++ b/drivers/media/platform/ti-vpe/sc.h
@@ -189,9 +189,6 @@ struct sc_data {
boolload_coeff_h;   /* have new h SC coeffs */
boolload_coeff_v;   /* have new v SC coeffs */
 
-   unsigned inths_index;   /* h SC coeffs selector */
-   unsigned intvs_index;   /* v SC coeffs selector */
-
struct platform_device *pdev;
 };
 
-- 
2.9.0

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Patch v2 27/35] media: ti-vpe: vpe: Fix line stride for output motion vector

2016-11-18 Thread Benoit Parrot
From: Nikhil Devshatwar <nikhil...@ti.com>

For deinterlacing operation, VPE hardware uses motion vectors.
MV calculated in the previous iteration are used for next interation.
Therefore driver allocates two motion vectors in ping-pong fashion.

For every transaction, one MV is DMAed in and one is DMAed out.
All the outbound DMAs (DMA to memory) use output parameters, but as
the motion vectors is generated purely out of input fields, it should
use the input parameters for DMA.

Fix the add_out_dtd to use source q_data for creating descriptor.
If the output size is greater than input stride, without this change,
MV DMA may overwrite the buffer causing memory corruption.

This CRITICAL fix ensures that the motion vector DMA descriptor is
created based on the attributes with which the buffer was allocated.

Signed-off-by: Nikhil Devshatwar <nikhil...@ti.com>
Signed-off-by: Ravikumar Kattekola <r...@ti.com>
Signed-off-by: Ravi Babu <ravib...@ti.com>
Signed-off-by: Benoit Parrot <bpar...@ti.com>
Acked-by: Hans Verkuil <hans.verk...@cisco.com>
---
 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 15e846b95719..608d11344147 100644
--- a/drivers/media/platform/ti-vpe/vpe.c
+++ b/drivers/media/platform/ti-vpe/vpe.c
@@ -1046,6 +1046,7 @@ static void add_out_dtd(struct vpe_ctx *ctx, int port)
if (port == VPE_PORT_MV_OUT) {
vpdma_fmt = _misc_fmts[VPDMA_DATA_FMT_MV];
dma_addr = ctx->mv_buf_dma[mv_buf_selector];
+   q_data = >q_data[Q_DATA_SRC];
} else {
/* to incorporate interleaved formats */
int plane = fmt->coplanar ? p_data->vb_part : 0;
-- 
2.9.0

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Patch v2 29/35] media: ti-vpe: Make scaler library into its own module

2016-11-18 Thread Benoit Parrot
In preparation to add scaler support into VIP we need to
turn sc.c into its own kernel module.

Add support for multiple SC memory block as VIP contains
2 scaler instances.
This is done by passing the resource name to sc_create() and
modify the vpe invocation accordingly.

Signed-off-by: Benoit Parrot <bpar...@ti.com>
Acked-by: Hans Verkuil <hans.verk...@cisco.com>
---
 drivers/media/platform/Kconfig |  4 
 drivers/media/platform/ti-vpe/Makefile |  4 +++-
 drivers/media/platform/ti-vpe/sc.c | 17 ++---
 drivers/media/platform/ti-vpe/sc.h |  2 +-
 drivers/media/platform/ti-vpe/vpe.c|  2 +-
 5 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig
index b52b6771fc4d..5d7befad90e0 100644
--- a/drivers/media/platform/Kconfig
+++ b/drivers/media/platform/Kconfig
@@ -365,6 +365,7 @@ config VIDEO_TI_VPE
select VIDEOBUF2_DMA_CONTIG
select V4L2_MEM2MEM_DEV
select VIDEO_TI_VPDMA
+   select VIDEO_TI_SC
default n
---help---
  Support for the TI VPE(Video Processing Engine) block
@@ -383,6 +384,9 @@ endif # V4L_MEM2MEM_DRIVERS
 config VIDEO_TI_VPDMA
tristate
 
+config VIDEO_TI_SC
+   tristate
+
 menuconfig V4L_TEST_DRIVERS
bool "Media test drivers"
depends on MEDIA_CAMERA_SUPPORT
diff --git a/drivers/media/platform/ti-vpe/Makefile 
b/drivers/media/platform/ti-vpe/Makefile
index faca5e115c1d..736558d309ad 100644
--- a/drivers/media/platform/ti-vpe/Makefile
+++ b/drivers/media/platform/ti-vpe/Makefile
@@ -1,8 +1,10 @@
 obj-$(CONFIG_VIDEO_TI_VPE) += ti-vpe.o
 obj-$(CONFIG_VIDEO_TI_VPDMA) += ti-vpdma.o
+obj-$(CONFIG_VIDEO_TI_SC) += ti-sc.o
 
-ti-vpe-y := vpe.o sc.o csc.o
+ti-vpe-y := vpe.o csc.o
 ti-vpdma-y := vpdma.o
+ti-sc-y := sc.o
 
 ccflags-$(CONFIG_VIDEO_TI_VPE_DEBUG) += -DDEBUG
 
diff --git a/drivers/media/platform/ti-vpe/sc.c 
b/drivers/media/platform/ti-vpe/sc.c
index 02f3dae8ae42..52ce1450362f 100644
--- a/drivers/media/platform/ti-vpe/sc.c
+++ b/drivers/media/platform/ti-vpe/sc.c
@@ -14,6 +14,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -52,6 +53,7 @@ void sc_dump_regs(struct sc_data *sc)
 
 #undef DUMPREG
 }
+EXPORT_SYMBOL(sc_dump_regs);
 
 /*
  * set the horizontal scaler coefficients according to the ratio of output to
@@ -100,6 +102,7 @@ void sc_set_hs_coeffs(struct sc_data *sc, void *addr, 
unsigned int src_w,
 
sc->load_coeff_h = true;
 }
+EXPORT_SYMBOL(sc_set_hs_coeffs);
 
 /*
  * set the vertical scaler coefficients according to the ratio of output to
@@ -140,6 +143,7 @@ void sc_set_vs_coeffs(struct sc_data *sc, void *addr, 
unsigned int src_h,
 
sc->load_coeff_v = true;
 }
+EXPORT_SYMBOL(sc_set_vs_coeffs);
 
 void sc_config_scaler(struct sc_data *sc, u32 *sc_reg0, u32 *sc_reg8,
u32 *sc_reg17, unsigned int src_w, unsigned int src_h,
@@ -267,8 +271,9 @@ void sc_config_scaler(struct sc_data *sc, u32 *sc_reg0, u32 
*sc_reg8,
 
*sc_reg24 = (src_w << CFG_ORG_W_SHIFT) | (src_h << CFG_ORG_H_SHIFT);
 }
+EXPORT_SYMBOL(sc_config_scaler);
 
-struct sc_data *sc_create(struct platform_device *pdev)
+struct sc_data *sc_create(struct platform_device *pdev, const char *res_name)
 {
struct sc_data *sc;
 
@@ -282,9 +287,10 @@ struct sc_data *sc_create(struct platform_device *pdev)
 
sc->pdev = pdev;
 
-   sc->res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "sc");
+   sc->res = platform_get_resource_byname(pdev, IORESOURCE_MEM, res_name);
if (!sc->res) {
-   dev_err(>dev, "missing platform resources data\n");
+   dev_err(>dev, "missing '%s' platform resources data\n",
+   res_name);
return ERR_PTR(-ENODEV);
}
 
@@ -296,3 +302,8 @@ struct sc_data *sc_create(struct platform_device *pdev)
 
return sc;
 }
+EXPORT_SYMBOL(sc_create);
+
+MODULE_DESCRIPTION("TI VIP/VPE Scaler");
+MODULE_AUTHOR("Texas Instruments Inc.");
+MODULE_LICENSE("GPL v2");
diff --git a/drivers/media/platform/ti-vpe/sc.h 
b/drivers/media/platform/ti-vpe/sc.h
index de947db98990..d0aab5ef0eca 100644
--- a/drivers/media/platform/ti-vpe/sc.h
+++ b/drivers/media/platform/ti-vpe/sc.h
@@ -200,6 +200,6 @@ void sc_set_vs_coeffs(struct sc_data *sc, void *addr, 
unsigned int src_h,
 void sc_config_scaler(struct sc_data *sc, u32 *sc_reg0, u32 *sc_reg8,
u32 *sc_reg17, unsigned int src_w, unsigned int src_h,
unsigned int dst_w, unsigned int dst_h);
-struct sc_data *sc_create(struct platform_device *pdev);
+struct sc_data *sc_create(struct platform_device *pdev, const char *res_name);
 
 #endif
diff --git a/drivers/media/platform/ti-vpe/vpe.c 
b/drivers/media/platform/ti-vpe/vpe.c
index 1d780ac7ff82..ebde4f4586e6 100644
--- a/drivers/media/platform/ti-vpe/v

[Patch v2 25/35] media: ti-vpe: vpdma: Fix race condition for firmware loading

2016-11-18 Thread Benoit Parrot
From: Nikhil Devshatwar <nikhil...@ti.com>

vpdma_create API is supposed to allocated the struct vpdma_data and
return it to the driver. Also, it would call the callback function
when the VPDMA firmware is loaded.

Typically, VPE driver have following function call:
dev->vpdma = vpdma_create(pdev, firmware_load_callback);
And the callback implementation would continue the probe further.
Also, the dev->vpdma is accessed from the callback implementation.

This may lead to race condition between assignment of dev->vpdma
and the callback function being triggered.
This would lead to kernel crash because of NULL pointer access.

Fix this by passing a driver wrapped _data instead of allocating
inside vpdma_create.
Change the vpdma_create prototype accordingly and fix return paths.

Also, update the VPE driver to use the updated API and
initialize the dev->vpdma before hand so that the race condition
is avoided.

Signed-off-by: Nikhil Devshatwar <nikhil...@ti.com>
Signed-off-by: Benoit Parrot <bpar...@ti.com>
Acked-by: Hans Verkuil <hans.verk...@cisco.com>
---
 drivers/media/platform/ti-vpe/vpdma.c | 17 +
 drivers/media/platform/ti-vpe/vpdma.h |  2 +-
 drivers/media/platform/ti-vpe/vpe.c   |  8 
 3 files changed, 10 insertions(+), 17 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/vpdma.c 
b/drivers/media/platform/ti-vpe/vpdma.c
index 8f0d608c70f6..070937fe1af6 100644
--- a/drivers/media/platform/ti-vpe/vpdma.c
+++ b/drivers/media/platform/ti-vpe/vpdma.c
@@ -1130,21 +1130,14 @@ static int vpdma_load_firmware(struct vpdma_data *vpdma)
return 0;
 }
 
-struct vpdma_data *vpdma_create(struct platform_device *pdev,
+int vpdma_create(struct platform_device *pdev, struct vpdma_data *vpdma,
void (*cb)(struct platform_device *pdev))
 {
struct resource *res;
-   struct vpdma_data *vpdma;
int r;
 
dev_dbg(>dev, "vpdma_create\n");
 
-   vpdma = devm_kzalloc(>dev, sizeof(*vpdma), GFP_KERNEL);
-   if (!vpdma) {
-   dev_err(>dev, "couldn't alloc vpdma_dev\n");
-   return ERR_PTR(-ENOMEM);
-   }
-
vpdma->pdev = pdev;
vpdma->cb = cb;
spin_lock_init(>lock);
@@ -1152,22 +1145,22 @@ struct vpdma_data *vpdma_create(struct platform_device 
*pdev,
res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "vpdma");
if (res == NULL) {
dev_err(>dev, "missing platform resources data\n");
-   return ERR_PTR(-ENODEV);
+   return -ENODEV;
}
 
vpdma->base = devm_ioremap(>dev, res->start, resource_size(res));
if (!vpdma->base) {
dev_err(>dev, "failed to ioremap\n");
-   return ERR_PTR(-ENOMEM);
+   return -ENOMEM;
}
 
r = vpdma_load_firmware(vpdma);
if (r) {
pr_err("failed to load firmware %s\n", VPDMA_FIRMWARE);
-   return ERR_PTR(r);
+   return r;
}
 
-   return vpdma;
+   return 0;
 }
 EXPORT_SYMBOL(vpdma_create);
 
diff --git a/drivers/media/platform/ti-vpe/vpdma.h 
b/drivers/media/platform/ti-vpe/vpdma.h
index 405a6febc254..0df156b7c1cf 100644
--- a/drivers/media/platform/ti-vpe/vpdma.h
+++ b/drivers/media/platform/ti-vpe/vpdma.h
@@ -273,7 +273,7 @@ void vpdma_set_bg_color(struct vpdma_data *vpdma,
 void vpdma_dump_regs(struct vpdma_data *vpdma);
 
 /* initialize vpdma, passed with VPE's platform device pointer */
-struct vpdma_data *vpdma_create(struct platform_device *pdev,
+int vpdma_create(struct platform_device *pdev, struct vpdma_data *vpdma,
void (*cb)(struct platform_device *pdev));
 
 #endif
diff --git a/drivers/media/platform/ti-vpe/vpe.c 
b/drivers/media/platform/ti-vpe/vpe.c
index f92ad7a473c1..15e846b95719 100644
--- a/drivers/media/platform/ti-vpe/vpe.c
+++ b/drivers/media/platform/ti-vpe/vpe.c
@@ -383,6 +383,7 @@ struct vpe_dev {
void __iomem*base;
struct resource *res;
 
+   struct vpdma_data   vpdma_data;
struct vpdma_data   *vpdma; /* vpdma data handle */
struct sc_data  *sc;/* scaler data handle */
struct csc_data *csc;   /* csc data handle */
@@ -2462,11 +2463,10 @@ static int vpe_probe(struct platform_device *pdev)
goto runtime_put;
}
 
-   dev->vpdma = vpdma_create(pdev, vpe_fw_cb);
-   if (IS_ERR(dev->vpdma)) {
-   ret = PTR_ERR(dev->vpdma);
+   dev->vpdma = >vpdma_data;
+   ret = vpdma_create(pdev, dev->vpdma, vpe_fw_cb);
+   if (ret)
goto runtime_put;
-   }
 
return 0;
 
-- 
2.9.0

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Patch v2 12/35] media: ti-vpe: vpdma: Add abort channel desc and cleanup APIs

2016-11-18 Thread Benoit Parrot
From: Nikhil Devshatwar <nikhil...@ti.com>

Whenever VPDMA processes a data descriptor of a list, it processes it
and sets up the channel for the DMA transaction. List manager holds the
descriptor in the list until the DMA is complete. If sync_on_channel
descriptor, or another descriptor for the same channel is present in
the FIFO, list manager keeps them until the current channel is free.

When the capture stream is closed suddenly while there are pending
descriptors in the FIFO (streamON failed, application killed), it would
keep the VPDMA in a busy state. Any further list post would fail with
EBUSY.

To avoid this, drivers need to stop the current processing list and
cleanup all the resources VPDMA has taken and also clear the internal FSM
of list manager. The state machine is cleared by issuing channel specific
abort descriptor.

Therefore, the vpdma_list_cleanup accepts an array of channels for which
abort_channel descriptors should be posted. It is driver's responsibility
to post for all the channels or the channels which were used in the last
context.

Signed-off-by: Nikhil Devshatwar <nikhil...@ti.com>
Signed-off-by: Benoit Parrot <bpar...@ti.com>
Acked-by: Hans Verkuil <hans.verk...@cisco.com>
---
 drivers/media/platform/ti-vpe/vpdma.c | 75 +++
 drivers/media/platform/ti-vpe/vpdma.h |  6 +++
 2 files changed, 81 insertions(+)

diff --git a/drivers/media/platform/ti-vpe/vpdma.c 
b/drivers/media/platform/ti-vpe/vpdma.c
index 1a0152842a17..7808c9c1828b 100644
--- a/drivers/media/platform/ti-vpe/vpdma.c
+++ b/drivers/media/platform/ti-vpe/vpdma.c
@@ -385,6 +385,56 @@ void vpdma_unmap_desc_buf(struct vpdma_data *vpdma, struct 
vpdma_buf *buf)
 EXPORT_SYMBOL(vpdma_unmap_desc_buf);
 
 /*
+ * Cleanup all pending descriptors of a list
+ * First, stop the current list being processed.
+ * If the VPDMA was busy, this step makes vpdma to accept post lists.
+ * To cleanup the internal FSM, post abort list descriptor for all the
+ * channels from @channels array of size @size.
+ */
+int vpdma_list_cleanup(struct vpdma_data *vpdma, int list_num,
+   int *channels, int size)
+{
+   struct vpdma_desc_list abort_list;
+   int i, ret, timeout = 500;
+
+   write_reg(vpdma, VPDMA_LIST_ATTR,
+   (list_num << VPDMA_LIST_NUM_SHFT) |
+   (1 << VPDMA_LIST_STOP_SHFT));
+
+   if (size <= 0 || !channels)
+   return 0;
+
+   ret = vpdma_create_desc_list(_list,
+   size * sizeof(struct vpdma_dtd), VPDMA_LIST_TYPE_NORMAL);
+   if (ret)
+   return ret;
+
+   for (i = 0; i < size; i++)
+   vpdma_add_abort_channel_ctd(_list, channels[i]);
+
+   ret = vpdma_map_desc_buf(vpdma, _list.buf);
+   if (ret)
+   return ret;
+   ret = vpdma_submit_descs(vpdma, _list, list_num);
+   if (ret)
+   return ret;
+
+   while (vpdma_list_busy(vpdma, list_num) && timeout--)
+   ;
+
+   if (timeout == 0) {
+   dev_err(>pdev->dev, "Timed out cleaning up VPDMA 
list\n");
+   return -EBUSY;
+   }
+
+   vpdma_unmap_desc_buf(vpdma, _list.buf);
+   vpdma_free_desc_buf(_list.buf);
+
+   return 0;
+}
+EXPORT_SYMBOL(vpdma_list_cleanup);
+
+/*
  * create a descriptor list, the user of this list will append configuration,
  * control and data descriptors to this list, this list will be submitted to
  * VPDMA. VPDMA's list parser will go through each descriptor and perform the
@@ -629,6 +679,31 @@ void vpdma_add_sync_on_channel_ctd(struct vpdma_desc_list 
*list,
 }
 EXPORT_SYMBOL(vpdma_add_sync_on_channel_ctd);
 
+/*
+ * append an 'abort_channel' type control descriptor to the given descriptor
+ * list, this descriptor aborts any DMA transaction happening using the
+ * specified channel
+ */
+void vpdma_add_abort_channel_ctd(struct vpdma_desc_list *list,
+   int chan_num)
+{
+   struct vpdma_ctd *ctd;
+
+   ctd = list->next;
+   WARN_ON((void *)(ctd + 1) > (list->buf.addr + list->buf.size));
+
+   ctd->w0 = 0;
+   ctd->w1 = 0;
+   ctd->w2 = 0;
+   ctd->type_source_ctl = ctd_type_source_ctl(chan_num,
+   CTD_TYPE_ABORT_CHANNEL);
+
+   list->next = ctd + 1;
+
+   dump_ctd(ctd);
+}
+EXPORT_SYMBOL(vpdma_add_abort_channel_ctd);
+
 static void dump_dtd(struct vpdma_dtd *dtd)
 {
int dir, chan;
diff --git a/drivers/media/platform/ti-vpe/vpdma.h 
b/drivers/media/platform/ti-vpe/vpdma.h
index 32b9ed5191c5..4dafc1bcf116 100644
--- a/drivers/media/platform/ti-vpe/vpdma.h
+++ b/drivers/media/platform/ti-vpe/vpdma.h
@@ -163,6 +163,8 @@ enum vpdma_channel {
 #define VIP_CHAN_YUV_PORTB_OFFSET  2
 #define VIP_CHAN_RGB_PORTB_OFFSET  1
 
+#define VPDMA_MAX_CHANNELS 256
+
 /* flags for VPDMA data descriptors */
 #define VPDMA_DATA_O

[Patch v2 30/35] media: ti-vpe: scaler: Add debug support for multi-instance

2016-11-18 Thread Benoit Parrot
Since there might be more then one instance it is better to
show the base address when dumping registers to help
with debugging.

Signed-off-by: Benoit Parrot <bpar...@ti.com>
Acked-by: Hans Verkuil <hans.verk...@cisco.com>
---
 drivers/media/platform/ti-vpe/sc.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/media/platform/ti-vpe/sc.c 
b/drivers/media/platform/ti-vpe/sc.c
index 52ce1450362f..e9273b713782 100644
--- a/drivers/media/platform/ti-vpe/sc.c
+++ b/drivers/media/platform/ti-vpe/sc.c
@@ -28,6 +28,8 @@ void sc_dump_regs(struct sc_data *sc)
 #define DUMPREG(r) dev_dbg(dev, "%-35s %08x\n", #r, \
ioread32(sc->base + CFG_##r))
 
+   dev_dbg(dev, "SC Registers @ %pa:\n", >res->start);
+
DUMPREG(SC0);
DUMPREG(SC1);
DUMPREG(SC2);
-- 
2.9.0

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Patch v2 26/35] media: ti-vpe: vpdma: Use bidirectional cached buffers

2016-11-18 Thread Benoit Parrot
From: Nikhil Devshatwar <nikhil...@ti.com>

VPDMA buffer will be used by CPU as well as by the VPDMA.
CPU will write/update the VPDMA descriptors containing data
about the video buffer DMA addresses.
VPDMA will write the "write descriptor" containing the
data about the DMA operation.

When mapping/unmapping the buffer, driver has to take care of
WriteBack and invalidation of the cache so that all the
coherency is maintained from both directions.

Use DMA_BIDIRECTIONAL to maintain coherency between CPU and VPDMA.

Signed-off-by: Nikhil Devshatwar <nikhil...@ti.com>
Signed-off-by: Benoit Parrot <bpar...@ti.com>
Acked-by: Hans Verkuil <hans.verk...@cisco.com>
---
 drivers/media/platform/ti-vpe/vpdma.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/vpdma.c 
b/drivers/media/platform/ti-vpe/vpdma.c
index 070937fe1af6..2d13644a28a8 100644
--- a/drivers/media/platform/ti-vpe/vpdma.c
+++ b/drivers/media/platform/ti-vpe/vpdma.c
@@ -367,7 +367,7 @@ int vpdma_map_desc_buf(struct vpdma_data *vpdma, struct 
vpdma_buf *buf)
 
WARN_ON(buf->mapped);
buf->dma_addr = dma_map_single(dev, buf->addr, buf->size,
-   DMA_TO_DEVICE);
+   DMA_BIDIRECTIONAL);
if (dma_mapping_error(dev, buf->dma_addr)) {
dev_err(dev, "failed to map buffer\n");
return -EINVAL;
@@ -388,7 +388,8 @@ void vpdma_unmap_desc_buf(struct vpdma_data *vpdma, struct 
vpdma_buf *buf)
struct device *dev = >pdev->dev;
 
if (buf->mapped)
-   dma_unmap_single(dev, buf->dma_addr, buf->size, DMA_TO_DEVICE);
+   dma_unmap_single(dev, buf->dma_addr, buf->size,
+   DMA_BIDIRECTIONAL);
 
buf->mapped = false;
 }
-- 
2.9.0

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Patch v2 33/35] media: ti-vpe: Make colorspace converter library into its own module

2016-11-18 Thread Benoit Parrot
In preparation to add colorspace conversion support to VIP,
we need to turn csc.c into its own kernel module.

Signed-off-by: Benoit Parrot <bpar...@ti.com>
Acked-by: Hans Verkuil <hans.verk...@cisco.com>
---
 drivers/media/platform/Kconfig |  4 
 drivers/media/platform/ti-vpe/Makefile |  4 +++-
 drivers/media/platform/ti-vpe/csc.c| 16 +---
 drivers/media/platform/ti-vpe/csc.h|  2 +-
 drivers/media/platform/ti-vpe/vpe.c|  2 +-
 5 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig
index 5d7befad90e0..60e20e5f4282 100644
--- a/drivers/media/platform/Kconfig
+++ b/drivers/media/platform/Kconfig
@@ -366,6 +366,7 @@ config VIDEO_TI_VPE
select V4L2_MEM2MEM_DEV
select VIDEO_TI_VPDMA
select VIDEO_TI_SC
+   select VIDEO_TI_CSC
default n
---help---
  Support for the TI VPE(Video Processing Engine) block
@@ -387,6 +388,9 @@ config VIDEO_TI_VPDMA
 config VIDEO_TI_SC
tristate
 
+config VIDEO_TI_CSC
+   tristate
+
 menuconfig V4L_TEST_DRIVERS
bool "Media test drivers"
depends on MEDIA_CAMERA_SUPPORT
diff --git a/drivers/media/platform/ti-vpe/Makefile 
b/drivers/media/platform/ti-vpe/Makefile
index 736558d309ad..32504b724b5d 100644
--- a/drivers/media/platform/ti-vpe/Makefile
+++ b/drivers/media/platform/ti-vpe/Makefile
@@ -1,10 +1,12 @@
 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
 
-ti-vpe-y := vpe.o csc.o
+ti-vpe-y := vpe.o
 ti-vpdma-y := vpdma.o
 ti-sc-y := sc.o
+ti-csc-y := csc.o
 
 ccflags-$(CONFIG_VIDEO_TI_VPE_DEBUG) += -DDEBUG
 
diff --git a/drivers/media/platform/ti-vpe/csc.c 
b/drivers/media/platform/ti-vpe/csc.c
index bec674994752..9fc6f70adeeb 100644
--- a/drivers/media/platform/ti-vpe/csc.c
+++ b/drivers/media/platform/ti-vpe/csc.c
@@ -14,6 +14,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -105,11 +106,13 @@ void csc_dump_regs(struct csc_data *csc)
 
 #undef DUMPREG
 }
+EXPORT_SYMBOL(csc_dump_regs);
 
 void csc_set_coeff_bypass(struct csc_data *csc, u32 *csc_reg5)
 {
*csc_reg5 |= CSC_BYPASS;
 }
+EXPORT_SYMBOL(csc_set_coeff_bypass);
 
 /*
  * set the color space converter coefficient shadow register values
@@ -160,8 +163,9 @@ void csc_set_coeff(struct csc_data *csc, u32 *csc_reg0,
for (; coeff < end_coeff; coeff += 2)
*shadow_csc++ = (*(coeff + 1) << 16) | *coeff;
 }
+EXPORT_SYMBOL(csc_set_coeff);
 
-struct csc_data *csc_create(struct platform_device *pdev)
+struct csc_data *csc_create(struct platform_device *pdev, const char *res_name)
 {
struct csc_data *csc;
 
@@ -176,9 +180,10 @@ struct csc_data *csc_create(struct platform_device *pdev)
csc->pdev = pdev;
 
csc->res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
-   "csc");
+   res_name);
if (csc->res == NULL) {
-   dev_err(>dev, "missing platform resources data\n");
+   dev_err(>dev, "missing '%s' platform resources data\n",
+   res_name);
return ERR_PTR(-ENODEV);
}
 
@@ -190,3 +195,8 @@ struct csc_data *csc_create(struct platform_device *pdev)
 
return csc;
 }
+EXPORT_SYMBOL(csc_create);
+
+MODULE_DESCRIPTION("TI VIP/VPE Color Space Converter");
+MODULE_AUTHOR("Texas Instruments Inc.");
+MODULE_LICENSE("GPL v2");
diff --git a/drivers/media/platform/ti-vpe/csc.h 
b/drivers/media/platform/ti-vpe/csc.h
index 1ad2b6dad561..024700b15152 100644
--- a/drivers/media/platform/ti-vpe/csc.h
+++ b/drivers/media/platform/ti-vpe/csc.h
@@ -63,6 +63,6 @@ void csc_set_coeff_bypass(struct csc_data *csc, u32 
*csc_reg5);
 void csc_set_coeff(struct csc_data *csc, u32 *csc_reg0,
enum v4l2_colorspace src_colorspace,
enum v4l2_colorspace dst_colorspace);
-struct csc_data *csc_create(struct platform_device *pdev);
+struct csc_data *csc_create(struct platform_device *pdev, const char 
*res_name);
 
 #endif
diff --git a/drivers/media/platform/ti-vpe/vpe.c 
b/drivers/media/platform/ti-vpe/vpe.c
index 32489d6369ca..1e4d614bd3b6 100644
--- a/drivers/media/platform/ti-vpe/vpe.c
+++ b/drivers/media/platform/ti-vpe/vpe.c
@@ -2496,7 +2496,7 @@ static int vpe_probe(struct platform_device *pdev)
goto runtime_put;
}
 
-   dev->csc = csc_create(pdev);
+   dev->csc = csc_create(pdev, "csc");
if (IS_ERR(dev->csc)) {
ret = PTR_ERR(dev->csc);
goto runtime_put;
-- 
2.9.0

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Patch v2 32/35] media: ti-vpe: vpdma: Add RAW8 and RAW16 data types

2016-11-18 Thread Benoit Parrot
Add RAW8 and RAW16 data type to VPDMA.
To handle RAW format we are re-using the YUV CBY422
vpdma data type so that we use the vpdma to re-order
the incoming bytes, as the VIP parser assumes that the
first byte presented on the bus is the MSB of a 2
bytes value.

RAW8 handles from 1 to 8 bits.
RAW16 handles from 9 to 16 bits.

Signed-off-by: Benoit Parrot <bpar...@ti.com>
Acked-by: Hans Verkuil <hans.verk...@cisco.com>
---
 drivers/media/platform/ti-vpe/vpdma.c | 23 +++
 drivers/media/platform/ti-vpe/vpdma.h |  6 ++
 2 files changed, 29 insertions(+)

diff --git a/drivers/media/platform/ti-vpe/vpdma.c 
b/drivers/media/platform/ti-vpe/vpdma.c
index 2d13644a28a8..c8f842fd7f75 100644
--- a/drivers/media/platform/ti-vpe/vpdma.c
+++ b/drivers/media/platform/ti-vpe/vpdma.c
@@ -191,6 +191,29 @@ const struct vpdma_data_format vpdma_rgb_fmts[] = {
 };
 EXPORT_SYMBOL(vpdma_rgb_fmts);
 
+/*
+ * To handle RAW format we are re-using the CBY422
+ * vpdma data type so that we use the vpdma to re-order
+ * the incoming bytes, as the parser assumes that the
+ * first byte presented on the bus is the MSB of a 2
+ * bytes value.
+ * RAW8 handles from 1 to 8 bits
+ * RAW16 handles from 9 to 16 bits
+ */
+const struct vpdma_data_format vpdma_raw_fmts[] = {
+   [VPDMA_DATA_FMT_RAW8] = {
+   .type   = VPDMA_DATA_FMT_TYPE_YUV,
+   .data_type  = DATA_TYPE_CBY422,
+   .depth  = 8,
+   },
+   [VPDMA_DATA_FMT_RAW16] = {
+   .type   = VPDMA_DATA_FMT_TYPE_YUV,
+   .data_type  = DATA_TYPE_CBY422,
+   .depth  = 16,
+   },
+};
+EXPORT_SYMBOL(vpdma_raw_fmts);
+
 const struct vpdma_data_format vpdma_misc_fmts[] = {
[VPDMA_DATA_FMT_MV] = {
.type   = VPDMA_DATA_FMT_TYPE_MISC,
diff --git a/drivers/media/platform/ti-vpe/vpdma.h 
b/drivers/media/platform/ti-vpe/vpdma.h
index 0df156b7c1cf..131700c112b2 100644
--- a/drivers/media/platform/ti-vpe/vpdma.h
+++ b/drivers/media/platform/ti-vpe/vpdma.h
@@ -104,12 +104,18 @@ enum vpdma_rgb_formats {
VPDMA_DATA_FMT_BGRA32,
 };
 
+enum vpdma_raw_formats {
+   VPDMA_DATA_FMT_RAW8 = 0,
+   VPDMA_DATA_FMT_RAW16,
+};
+
 enum vpdma_misc_formats {
VPDMA_DATA_FMT_MV = 0,
 };
 
 extern const struct vpdma_data_format vpdma_yuv_fmts[];
 extern const struct vpdma_data_format vpdma_rgb_fmts[];
+extern const struct vpdma_data_format vpdma_raw_fmts[];
 extern const struct vpdma_data_format vpdma_misc_fmts[];
 
 enum vpdma_frame_start_event {
-- 
2.9.0

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Patch v2 35/35] media: ti-vpe: vpe: Add proper support single and multi-plane buffer

2016-11-18 Thread Benoit Parrot
The VPE was restricting the number of plane per buffer based on
the fact that if a particular format had color separation it was
meant to need 2 planes.

However NV12/NV16 are color separate format which are meant to be
presented in a single contiguous buffer/plane.
It could also be presented in a multi-plane as well if need be.
So we must support both modes for more flexibility.

The number of plane requested by user space was previously ignored
and was therefore always overwritten.
The driver now use the requested num plane as hint to calculate needed
offset when required.

Signed-off-by: Benoit Parrot <bpar...@ti.com>
Acked-by: Hans Verkuil <hans.verk...@cisco.com>
---
 drivers/media/platform/ti-vpe/vpe.c | 58 ++---
 1 file changed, 48 insertions(+), 10 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/vpe.c 
b/drivers/media/platform/ti-vpe/vpe.c
index 1e4d614bd3b6..0626593a8b22 100644
--- a/drivers/media/platform/ti-vpe/vpe.c
+++ b/drivers/media/platform/ti-vpe/vpe.c
@@ -327,6 +327,7 @@ static struct vpe_fmt vpe_formats[] = {
 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 */
@@ -1042,6 +1043,7 @@ static void add_out_dtd(struct vpe_ctx *ctx, int port)
int mv_buf_selector = !ctx->src_mv_buf_selector;
dma_addr_t dma_addr;
u32 flags = 0;
+   u32 offset = 0;
 
if (port == VPE_PORT_MV_OUT) {
vpdma_fmt = _misc_fmts[VPDMA_DATA_FMT_MV];
@@ -1052,13 +1054,27 @@ static void add_out_dtd(struct vpe_ctx *ctx, int port)
int plane = fmt->coplanar ? p_data->vb_part : 0;
 
vpdma_fmt = fmt->vpdma_fmt[plane];
-   dma_addr = vb2_dma_contig_plane_dma_addr(vb, plane);
+   /*
+* If we are using a single plane buffer and
+* we need to set a separate vpdma chroma channel.
+*/
+   if (q_data->nplanes == 1 && plane) {
+   dma_addr = vb2_dma_contig_plane_dma_addr(vb, 0);
+   /* Compute required offset */
+   offset = q_data->bytesperline[0] * q_data->height;
+   } else {
+   dma_addr = vb2_dma_contig_plane_dma_addr(vb, plane);
+   /* Use address as is, no offset */
+   offset = 0;
+   }
if (!dma_addr) {
vpe_err(ctx->dev,
"acquiring output buffer(%d) dma_addr failed\n",
port);
return;
}
+   /* Apply the offset */
+   dma_addr += offset;
}
 
if (q_data->flags & Q_DATA_FRAME_1D)
@@ -1087,6 +1103,7 @@ static void add_in_dtd(struct vpe_ctx *ctx, int port)
int frame_width, frame_height;
dma_addr_t dma_addr;
u32 flags = 0;
+   u32 offset = 0;
 
if (port == VPE_PORT_MV_IN) {
vpdma_fmt = _misc_fmts[VPDMA_DATA_FMT_MV];
@@ -1096,14 +1113,27 @@ static void add_in_dtd(struct vpe_ctx *ctx, int port)
int plane = fmt->coplanar ? p_data->vb_part : 0;
 
vpdma_fmt = fmt->vpdma_fmt[plane];
-
-   dma_addr = vb2_dma_contig_plane_dma_addr(vb, plane);
+   /*
+* If we are using a single plane buffer and
+* we need to set a separate vpdma chroma channel.
+*/
+   if (q_data->nplanes == 1 && plane) {
+   dma_addr = vb2_dma_contig_plane_dma_addr(vb, 0);
+   /* Compute required offset */
+   offset = q_data->bytesperline[0] * q_data->height;
+   } else {
+   dma_addr = vb2_dma_contig_plane_dma_addr(vb, plane);
+   /* Use address as is, no offset */
+   offset = 0;
+   }
if (!dma_addr) {
vpe_err(ctx->dev,
-   "acquiring input buffer(%d) dma_addr failed\n",
+   "acquiring output buffer(%d) dma_addr failed\n",
port);
return;
}
+   /* Apply the offset */
+   dma_addr += offset;
 
if (q_data->flags & Q_DATA_INTERLACED_SEQ_TB) {
/*

[Patch v2 31/35] media: ti-vpe: vpe: Make sure frame size dont exceed scaler capacity

2016-11-18 Thread Benoit Parrot
When scaler is to be used we need to make sure that the input and
output frame size do not exceed the maximum frame sizes that the
scaler h/w can handle otherwise streaming stall as the scaler
cannot proceed.

The scaler buffer is limited to 2047 pixels (i.e. 11 bits) when
attempting anything larger (2048 for example) the scaler stalls.

Realistically in an mem2mem device we can only check for this type
of issue when start_streaming is called. We can't do it during the
try_fmt/s_fmt because we do not have all of the info needed at that
point. So instead when start_streaming is called we need to check
that the input and output frames size do not exceed the scaler's
capability. The only time larger frame size are allowed is when
the input frame szie is the same as the output frame size.

Now in the case where we need to fail, start_streaming must return
all previously queued buffer back otherwise the vb2 framework
will issue kernel WARN messages.
In this case we also give an error message.

Signed-off-by: Benoit Parrot <bpar...@ti.com>
Acked-by: Hans Verkuil <hans.verk...@cisco.com>
---
 drivers/media/platform/ti-vpe/sc.h  |  6 
 drivers/media/platform/ti-vpe/vpe.c | 71 -
 2 files changed, 60 insertions(+), 17 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/sc.h 
b/drivers/media/platform/ti-vpe/sc.h
index d0aab5ef0eca..f1fe80b38c9f 100644
--- a/drivers/media/platform/ti-vpe/sc.h
+++ b/drivers/media/platform/ti-vpe/sc.h
@@ -173,6 +173,12 @@
 /* number of taps expected by the scaler in it's coefficient memory */
 #define SC_NUM_TAPS_MEM_ALIGN  8
 
+/* Maximum frame width the scaler can handle (in pixels) */
+#define SC_MAX_PIXEL_WIDTH 2047
+
+/* Maximum frame height the scaler can handle (in lines) */
+#define SC_MAX_PIXEL_HEIGHT2047
+
 /*
  * coefficient memory size in bytes:
  * num phases x num sets(luma and chroma) x num taps(aligned) x coeff size
diff --git a/drivers/media/platform/ti-vpe/vpe.c 
b/drivers/media/platform/ti-vpe/vpe.c
index ebde4f4586e6..32489d6369ca 100644
--- a/drivers/media/platform/ti-vpe/vpe.c
+++ b/drivers/media/platform/ti-vpe/vpe.c
@@ -2025,28 +2025,33 @@ static void vpe_buf_queue(struct vb2_buffer *vb)
v4l2_m2m_buf_queue(ctx->fh.m2m_ctx, vbuf);
 }
 
-static int vpe_start_streaming(struct vb2_queue *q, unsigned int count)
+static int check_srcdst_sizes(struct vpe_ctx *ctx)
 {
-   struct vpe_ctx *ctx = vb2_get_drv_priv(q);
+   struct vpe_q_data *s_q_data =  >q_data[Q_DATA_SRC];
+   struct vpe_q_data *d_q_data =  >q_data[Q_DATA_DST];
+   unsigned int src_w = s_q_data->c_rect.width;
+   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;
 
-   if (ctx->deinterlacing)
-   config_edi_input_mode(ctx, 0x0);
+   if (src_w == dst_w && src_h == dst_h)
+   return 0;
 
-   if (ctx->sequence != 0)
-   set_srcdst_params(ctx);
+   if (src_h <= SC_MAX_PIXEL_HEIGHT &&
+   src_w <= SC_MAX_PIXEL_WIDTH &&
+   dst_h <= SC_MAX_PIXEL_HEIGHT &&
+   dst_w <= SC_MAX_PIXEL_WIDTH)
+   return 0;
 
-   return 0;
+   return -1;
 }
 
-static void vpe_stop_streaming(struct vb2_queue *q)
+static void vpe_return_all_buffers(struct vpe_ctx *ctx,  struct vb2_queue *q,
+  enum vb2_buffer_state state)
 {
-   struct vpe_ctx *ctx = vb2_get_drv_priv(q);
struct vb2_v4l2_buffer *vb;
unsigned long flags;
 
-   vpe_dump_regs(ctx->dev);
-   vpdma_dump_regs(ctx->dev->vpdma);
-
for (;;) {
if (V4L2_TYPE_IS_OUTPUT(q->type))
vb = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx);
@@ -2055,7 +2060,7 @@ static void vpe_stop_streaming(struct vb2_queue *q)
if (!vb)
break;
spin_lock_irqsave(>dev->lock, flags);
-   v4l2_m2m_buf_done(vb, VB2_BUF_STATE_ERROR);
+   v4l2_m2m_buf_done(vb, state);
spin_unlock_irqrestore(>dev->lock, flags);
}
 
@@ -2068,15 +2073,15 @@ static void vpe_stop_streaming(struct vb2_queue *q)
spin_lock_irqsave(>dev->lock, flags);
 
if (ctx->src_vbs[2])
-   v4l2_m2m_buf_done(ctx->src_vbs[2], VB2_BUF_STATE_ERROR);
+   v4l2_m2m_buf_done(ctx->src_vbs[2], state);
 
if (ctx->src_vbs[1] && (ctx->src_vbs[1] != ctx->src_vbs[2]))
-   v4l2_m2m_buf_done(ctx->src_vbs[1], VB2_BUF_STATE_ERROR);
+   v4l2_m2m_buf_done(ctx->src_vbs[1], state);
 
if (ctx->src_vbs[0] &&
(ctx->src_vbs[

[Patch v2 34/35] media: ti-vpe: csc: Add debug support for multi-instance

2016-11-18 Thread Benoit Parrot
Since there might be more then one instance it is better to
show the base address when dumping registers to help
with debugging.

Signed-off-by: Benoit Parrot <bpar...@ti.com>
Acked-by: Hans Verkuil <hans.verk...@cisco.com>
---
 drivers/media/platform/ti-vpe/csc.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/media/platform/ti-vpe/csc.c 
b/drivers/media/platform/ti-vpe/csc.c
index 9fc6f70adeeb..44b8465cf101 100644
--- a/drivers/media/platform/ti-vpe/csc.c
+++ b/drivers/media/platform/ti-vpe/csc.c
@@ -97,6 +97,8 @@ void csc_dump_regs(struct csc_data *csc)
 #define DUMPREG(r) dev_dbg(dev, "%-35s %08x\n", #r, \
ioread32(csc->base + CSC_##r))
 
+   dev_dbg(dev, "CSC Registers @ %pa:\n", >res->start);
+
DUMPREG(CSC00);
DUMPREG(CSC01);
DUMPREG(CSC02);
-- 
2.9.0

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Patch v2 28/35] media: ti-vpe: vpe: Enable DMABUF export

2016-11-18 Thread Benoit Parrot
Allow VPE to be able to export DMA buffer.

Signed-off-by: Benoit Parrot <bpar...@ti.com>
Acked-by: Hans Verkuil <hans.verk...@cisco.com>
---
 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 608d11344147..1d780ac7ff82 100644
--- a/drivers/media/platform/ti-vpe/vpe.c
+++ b/drivers/media/platform/ti-vpe/vpe.c
@@ -1944,6 +1944,7 @@ static const struct v4l2_ioctl_ops vpe_ioctl_ops = {
.vidioc_querybuf= v4l2_m2m_ioctl_querybuf,
.vidioc_qbuf= v4l2_m2m_ioctl_qbuf,
.vidioc_dqbuf   = v4l2_m2m_ioctl_dqbuf,
+   .vidioc_expbuf  = v4l2_m2m_ioctl_expbuf,
.vidioc_streamon= v4l2_m2m_ioctl_streamon,
.vidioc_streamoff   = v4l2_m2m_ioctl_streamoff,
 
-- 
2.9.0

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Patch v2 24/35] media: ti-vpe: vpe: Fix vb2 buffer cleanup

2016-11-18 Thread Benoit Parrot
When stop_streaming is called we need to cleanup the queued
vb2 buffers properly.
This was not previously being done which caused kernel
warning when the application using the resources was killed.
Kernel warnings were also generated on successful completion
of a de-interlacing case as well as upon aborting a
conversion.

Make sure every vb2 buffers is properly handled in all cases.

Signed-off-by: Benoit Parrot <bpar...@ti.com>
Acked-by: Hans Verkuil <hans.verk...@cisco.com>
---
 drivers/media/platform/ti-vpe/vpe.c | 62 +++--
 1 file changed, 60 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/vpe.c 
b/drivers/media/platform/ti-vpe/vpe.c
index ef55fb45d0be..f92ad7a473c1 100644
--- a/drivers/media/platform/ti-vpe/vpe.c
+++ b/drivers/media/platform/ti-vpe/vpe.c
@@ -605,7 +605,10 @@ static void free_vbs(struct vpe_ctx *ctx)
spin_lock_irqsave(>lock, flags);
if (ctx->src_vbs[2]) {
v4l2_m2m_buf_done(ctx->src_vbs[2], VB2_BUF_STATE_DONE);
-   v4l2_m2m_buf_done(ctx->src_vbs[1], VB2_BUF_STATE_DONE);
+   if (ctx->src_vbs[1] && (ctx->src_vbs[1] != ctx->src_vbs[2]))
+   v4l2_m2m_buf_done(ctx->src_vbs[1], VB2_BUF_STATE_DONE);
+   ctx->src_vbs[2] = NULL;
+   ctx->src_vbs[1] = NULL;
}
spin_unlock_irqrestore(>lock, flags);
 }
@@ -1443,6 +1446,14 @@ static irqreturn_t vpe_irq(int irq_vpe, void *data)
ctx->src_vbs[1] = ctx->src_vbs[0];
}
 
+   /*
+* Since the vb2_buf_done has already been called fir therse
+* buffer we can now NULL them out so that we won't try
+* to clean out stray pointer later on.
+   */
+   ctx->src_vbs[0] = NULL;
+   ctx->dst_vb = NULL;
+
ctx->bufs_completed++;
if (ctx->bufs_completed < ctx->bufs_per_job && job_ready(ctx)) {
device_run(ctx);
@@ -2027,9 +2038,57 @@ static int vpe_start_streaming(struct vb2_queue *q, 
unsigned int count)
 static void vpe_stop_streaming(struct vb2_queue *q)
 {
struct vpe_ctx *ctx = vb2_get_drv_priv(q);
+   struct vb2_v4l2_buffer *vb;
+   unsigned long flags;
 
vpe_dump_regs(ctx->dev);
vpdma_dump_regs(ctx->dev->vpdma);
+
+   for (;;) {
+   if (V4L2_TYPE_IS_OUTPUT(q->type))
+   vb = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx);
+   else
+   vb = v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx);
+   if (!vb)
+   break;
+   spin_lock_irqsave(>dev->lock, flags);
+   v4l2_m2m_buf_done(vb, VB2_BUF_STATE_ERROR);
+   spin_unlock_irqrestore(>dev->lock, flags);
+   }
+
+   /*
+* Cleanup the in-transit vb2 buffers that have been
+* removed from their respective queue already but for
+* which procecessing has not been completed yet.
+*/
+   if (V4L2_TYPE_IS_OUTPUT(q->type)) {
+   spin_lock_irqsave(>dev->lock, flags);
+
+   if (ctx->src_vbs[2])
+   v4l2_m2m_buf_done(ctx->src_vbs[2], VB2_BUF_STATE_ERROR);
+
+   if (ctx->src_vbs[1] && (ctx->src_vbs[1] != ctx->src_vbs[2]))
+   v4l2_m2m_buf_done(ctx->src_vbs[1], VB2_BUF_STATE_ERROR);
+
+   if (ctx->src_vbs[0] &&
+   (ctx->src_vbs[0] != ctx->src_vbs[1]) &&
+   (ctx->src_vbs[0] != ctx->src_vbs[2]))
+   v4l2_m2m_buf_done(ctx->src_vbs[0], VB2_BUF_STATE_ERROR);
+
+   ctx->src_vbs[2] = NULL;
+   ctx->src_vbs[1] = NULL;
+   ctx->src_vbs[0] = NULL;
+
+   spin_unlock_irqrestore(>dev->lock, flags);
+   } else {
+   if (ctx->dst_vb) {
+   spin_lock_irqsave(>dev->lock, flags);
+
+   v4l2_m2m_buf_done(ctx->dst_vb, VB2_BUF_STATE_ERROR);
+   ctx->dst_vb = NULL;
+   spin_unlock_irqrestore(>dev->lock, flags);
+   }
+   }
 }
 
 static const struct vb2_ops vpe_qops = {
@@ -,7 +2281,6 @@ static int vpe_release(struct file *file)
vpe_dbg(dev, "releasing instance %p\n", ctx);
 
mutex_lock(>dev_mutex);
-   free_vbs(ctx);
free_mv_buffers(ctx);
vpdma_free_desc_list(>desc_list);
vpdma_free_desc_buf(>mmr_adb);
-- 
2.9.0

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Patch v2 14/35] media: ti-vpe: vpdma: Clear IRQs for individual lists

2016-11-18 Thread Benoit Parrot
From: Nikhil Devshatwar <nikhil...@ti.com>

VPDMA IRQs are registered for multiple lists
When clearing an IRQ for a list interrupt, all the
IRQs for the individual lists are to be cleared separately.

Signed-off-by: Nikhil Devshatwar <nikhil...@ti.com>
Signed-off-by: Benoit Parrot <bpar...@ti.com>
Acked-by: Hans Verkuil <hans.verk...@cisco.com>
---
 drivers/media/platform/ti-vpe/vpdma.c | 6 +++---
 drivers/media/platform/ti-vpe/vpdma.h | 3 ++-
 drivers/media/platform/ti-vpe/vpe.c   | 2 +-
 3 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/vpdma.c 
b/drivers/media/platform/ti-vpe/vpdma.c
index ffc281d2b065..c0a4e035bc2a 100644
--- a/drivers/media/platform/ti-vpe/vpdma.c
+++ b/drivers/media/platform/ti-vpe/vpdma.c
@@ -953,12 +953,12 @@ unsigned int vpdma_get_list_mask(struct vpdma_data 
*vpdma, int irq_num)
 EXPORT_SYMBOL(vpdma_get_list_mask);
 
 /* clear previosuly occured list intterupts in the LIST_STAT register */
-void vpdma_clear_list_stat(struct vpdma_data *vpdma, int irq_num)
+void vpdma_clear_list_stat(struct vpdma_data *vpdma, int irq_num,
+  int list_num)
 {
u32 reg_addr = VPDMA_INT_LIST0_STAT + VPDMA_INTX_OFFSET * irq_num;
 
-   write_reg(vpdma, reg_addr,
-   read_reg(vpdma, reg_addr));
+   write_reg(vpdma, reg_addr, 3 << (list_num * 2));
 }
 EXPORT_SYMBOL(vpdma_clear_list_stat);
 
diff --git a/drivers/media/platform/ti-vpe/vpdma.h 
b/drivers/media/platform/ti-vpe/vpdma.h
index f08f4370ce4a..65961147e8f7 100644
--- a/drivers/media/platform/ti-vpe/vpdma.h
+++ b/drivers/media/platform/ti-vpe/vpdma.h
@@ -244,7 +244,8 @@ int vpdma_list_cleanup(struct vpdma_data *vpdma, int 
list_num,
 /* vpdma list interrupt management */
 void vpdma_enable_list_complete_irq(struct vpdma_data *vpdma, int irq_num,
int list_num, bool enable);
-void vpdma_clear_list_stat(struct vpdma_data *vpdma, int irq_num);
+void vpdma_clear_list_stat(struct vpdma_data *vpdma, int irq_num,
+  int list_num);
 unsigned int vpdma_get_list_stat(struct vpdma_data *vpdma, int irq_num);
 unsigned int vpdma_get_list_mask(struct vpdma_data *vpdma, int irq_num);
 
diff --git a/drivers/media/platform/ti-vpe/vpe.c 
b/drivers/media/platform/ti-vpe/vpe.c
index 151a9280bb85..6fcdd0ea50e4 100644
--- a/drivers/media/platform/ti-vpe/vpe.c
+++ b/drivers/media/platform/ti-vpe/vpe.c
@@ -1326,7 +1326,7 @@ static irqreturn_t vpe_irq(int irq_vpe, void *data)
 
if (irqst0) {
if (irqst0 & VPE_INT0_LIST0_COMPLETE)
-   vpdma_clear_list_stat(ctx->dev->vpdma, 0);
+   vpdma_clear_list_stat(ctx->dev->vpdma, 0, 0);
 
irqst0 &= ~(VPE_INT0_LIST0_COMPLETE);
}
-- 
2.9.0

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Patch 05/35] media: ti-vpe: Use line average de-interlacing for first 2 frames

2016-10-24 Thread Benoit Parrot
Hans Verkuil <hverk...@xs4all.nl> wrote on Mon [2016-Oct-17 16:14:35 +0200]:
> On 09/28/2016 11:20 PM, Benoit Parrot wrote:
> > From: Archit Taneja <arc...@ti.com>
> > 
> > For n input fields, the VPE de-interlacer creates n - 2 progressive frames.
> 
> That's confusing. I think you mean '(n / 2) - 1'? Two fields make one frame, 
> right?

No it is (N - 2), the motion detection block requires 3 fields to create the 
motion
vector data. So without doing anything special the first progressive frame 
would be
generated after the 3 field is consumed and then a progressive frame is 
generated
every field after that always keeping the last 2 fields in reserve.

This patch adds a special modes so that line averaging mode is use for the
first two fields so that in the end we get N progressive frames generated
from N fields.

Benoit

> 
> Regards,
> 
>   Hans
> 
> > 
> > To support this, we use line average mode of de-interlacer for the first 2
> > input fields to generate 2 progressive frames. We then revert back to the
> > preferred EDI method, and create n - 2 frames, creating a sum of n frames.
> > 
> > Signed-off-by: Archit Taneja <arc...@ti.com>
> > Signed-off-by: Nikhil Devshatwar <nikhil...@ti.com>
> > Signed-off-by: Benoit Parrot <bpar...@ti.com>
> > ---
> >  drivers/media/platform/ti-vpe/vpe.c | 33 +++--
> >  1 file changed, 31 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/media/platform/ti-vpe/vpe.c 
> > b/drivers/media/platform/ti-vpe/vpe.c
> > index 3921fd8cdf1d..a0b29685fb69 100644
> > --- a/drivers/media/platform/ti-vpe/vpe.c
> > +++ b/drivers/media/platform/ti-vpe/vpe.c
> > @@ -141,7 +141,7 @@ struct vpe_dei_regs {
> >   */
> >  static const struct vpe_dei_regs dei_regs = {
> > .mdt_spacial_freq_thr_reg = 0x020C0804u,
> > -   .edi_config_reg = 0x0118100Fu,
> > +   .edi_config_reg = 0x0118100Cu,
> > .edi_lut_reg0 = 0x08040200u,
> > .edi_lut_reg1 = 0x1010100Cu,
> > .edi_lut_reg2 = 0x10101010u,
> > @@ -798,6 +798,23 @@ static void set_dei_shadow_registers(struct vpe_ctx 
> > *ctx)
> > ctx->load_mmrs = true;
> >  }
> >  
> > +static void config_edi_input_mode(struct vpe_ctx *ctx, int mode)
> > +{
> > +   struct vpe_mmr_adb *mmr_adb = ctx->mmr_adb.addr;
> > +   u32 *edi_config_reg = _adb->dei_regs[3];
> > +
> > +   if (mode & 0x2)
> > +   write_field(edi_config_reg, 1, 1, 2);   /* EDI_ENABLE_3D */
> > +
> > +   if (mode & 0x3)
> > +   write_field(edi_config_reg, 1, 1, 3);   /* EDI_CHROMA_3D  */
> > +
> > +   write_field(edi_config_reg, mode, VPE_EDI_INP_MODE_MASK,
> > +   VPE_EDI_INP_MODE_SHIFT);
> > +
> > +   ctx->load_mmrs = true;
> > +}
> > +
> >  /*
> >   * Set the shadow registers whose values are modified when either the
> >   * source or destination format is changed.
> > @@ -,6 +1128,15 @@ static void device_run(void *priv)
> > ctx->dst_vb = v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx);
> > WARN_ON(ctx->dst_vb == NULL);
> >  
> > +   if (ctx->deinterlacing) {
> > +   /*
> > +* we have output the first 2 frames through line average, we
> > +* now switch to EDI de-interlacer
> > +*/
> > +   if (ctx->sequence == 2)
> > +   config_edi_input_mode(ctx, 0x3); /* EDI (Y + UV) */
> > +   }
> > +
> > /* config descriptors */
> > if (ctx->dev->loaded_mmrs != ctx->mmr_adb.dma_addr || ctx->load_mmrs) {
> > vpdma_map_desc_buf(ctx->dev->vpdma, >mmr_adb);
> > @@ -1865,7 +1891,10 @@ static void vpe_buf_queue(struct vb2_buffer *vb)
> >  
> >  static int vpe_start_streaming(struct vb2_queue *q, unsigned int count)
> >  {
> > -   /* currently we do nothing here */
> > +   struct vpe_ctx *ctx = vb2_get_drv_priv(q);
> > +
> > +   if (ctx->deinterlacing)
> > +   config_edi_input_mode(ctx, 0x0);
> >  
> > return 0;
> >  }
> > 
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Patch 00/35] media: ti-vpe: fixes and enhancements

2016-10-24 Thread Benoit Parrot
Hans,

Thank you for taking the time to review my patches.
I'll update the patch set relating to your comments
and submit a v2 shortly.

Regards
Benoit

Hans Verkuil <hverk...@xs4all.nl> wrote on Mon [2016-Oct-17 16:35:01 +0200]:
> On 09/28/2016 11:16 PM, Benoit Parrot wrote:
> > This patch series is to publish a number of enhancements
> > we have been carrying for a while.
> > 
> > A number of bug fixes and feature enhancements have been
> > included.
> > 
> > We also need to prepare the way for the introduction of
> > the VIP (Video Input Port) driver (coming soon) which
> > has internal IP module in common with VPE.
> > 
> > The relevant modules (vpdma, sc and csc) are therefore converted
> > into individual kernel modules.
> 
> Other than the few comments I made this patch series looks OK.
> 
> You can add my
> 
>   Acked-by: Hans Verkuil <hans.verk...@cisco.com>
> 
> to those patches where I didn't make any comments.
> 
> Regards,
> 
>   Hans
> 
> > 
> > Archit Taneja (1):
> >   media: ti-vpe: Use line average de-interlacing for first 2 frames
> > 
> > Benoit Parrot (16):
> >   media: ti-vpe: vpdma: Make vpdma library into its own module
> >   media: ti-vpe: vpdma: Add multi-instance and multi-client support
> >   media: ti-vpe: vpdma: Add helper to set a background color
> >   media: ti-vpe: vpdma: Fix bus error when vpdma is writing a descriptor
> >   media: ti-vpe: vpe: Added MODULE_DEVICE_TABLE hint
> >   media: ti-vpe: vpdma: Corrected YUV422 data type label.
> >   media: ti-vpe: vpdma: RGB data type yield inverted data
> >   media: ti-vpe: vpe: Fix vb2 buffer cleanup
> >   media: ti-vpe: vpe: Enable DMABUF export
> >   media: ti-vpe: Make scaler library into its own module
> >   media: ti-vpe: scaler: Add debug support for multi-instance
> >   media: ti-vpe: vpe: Make sure frame size dont exceed scaler capacity
> >   media: ti-vpe: vpdma: Add RAW8 and RAW16 data types
> >   media: ti-vpe: Make colorspace converter library into its own module
> >   media: ti-vpe: csc: Add debug support for multi-instance
> >   media: ti-vpe: vpe: Add proper support single and multi-plane buffer
> > 
> > Harinarayan Bhatta (2):
> >   media: ti-vpe: Increasing max buffer height and width
> >   media: ti-vpe: Free vpdma buffers in vpe_release
> > 
> > Nikhil Devshatwar (16):
> >   media: ti-vpe: vpe: Do not perform job transaction atomically
> >   media: ti-vpe: Add support for SEQ_TB buffers
> >   media: ti-vpe: vpe: Return NULL for invalid buffer type
> >   media: ti-vpe: vpdma: Add support for setting max width height
> >   media: ti-vpe: vpdma: Add abort channel desc and cleanup APIs
> >   media: ti-vpe: vpdma: Make list post atomic operation
> >   media: ti-vpe: vpdma: Clear IRQs for individual lists
> >   media: ti-vpe: vpe: configure line mode separately
> >   media: ti-vpe: vpe: Setup srcdst parameters in start_streaming
> >   media: ti-vpe: vpe: Post next descriptor only for list complete IRQ
> >   media: ti-vpe: vpe: Add RGB565 and RGB5551 support
> >   media: ti-vpe: vpdma: allocate and maintain hwlist
> >   media: ti-vpe: sc: Fix incorrect optimization
> >   media: ti-vpe: vpdma: Fix race condition for firmware loading
> >   media: ti-vpe: vpdma: Use bidirectional cached buffers
> >   media: ti-vpe: vpe: Fix line stride for output motion vector
> > 
> >  drivers/media/platform/Kconfig |  14 +
> >  drivers/media/platform/ti-vpe/Makefile |  10 +-
> >  drivers/media/platform/ti-vpe/csc.c|  18 +-
> >  drivers/media/platform/ti-vpe/csc.h|   2 +-
> >  drivers/media/platform/ti-vpe/sc.c |  28 +-
> >  drivers/media/platform/ti-vpe/sc.h |  11 +-
> >  drivers/media/platform/ti-vpe/vpdma.c  | 349 +++---
> >  drivers/media/platform/ti-vpe/vpdma.h  |  85 +-
> >  drivers/media/platform/ti-vpe/vpdma_priv.h | 130 -
> >  drivers/media/platform/ti-vpe/vpe.c| 450 
> > -
> >  10 files changed, 891 insertions(+), 206 deletions(-)
> > 
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Patch 06/35] media: ti-vpe: vpe: Do not perform job transaction atomically

2016-10-24 Thread Benoit Parrot
Hans Verkuil <hverk...@xs4all.nl> wrote on Mon [2016-Oct-17 16:17:15 +0200]:
> On 09/28/2016 11:20 PM, Benoit Parrot wrote:
> > From: Nikhil Devshatwar <nikhil...@ti.com>
> > 
> > Current VPE driver does not start the job until all the buffers for
> > a transaction are not queued. When running in multiple context, this might
> 
> I think this should be: s/not queued/queued/, right?

Yep, will fix that.

> 
> > increase the processing latency.
> > 
> > Alternate solution would be to try to continue the same context as long as
> > buffers for the transaction are ready; else switch the context. This may
> > increase number of context switches but it reduces latency significantly.
> > 
> > In this approach, the job_ready always succeeds as long as there are
> > buffers on the CAPTURE and OUTPUT stream. Processing may start immediately
> > as the first 2 iterations don't need extra source buffers. Shift all the
> > source buffers after each iteration and remove the oldest buffer.
> > 
> > Also, with this removes the constraint of pre buffering 3 buffers before
> > call to STREAMON in case of de-interlacing.
> > 
> > Signed-off-by: Nikhil Devshatwar <nikhil...@ti.com>
> > Signed-off-by: Benoit Parrot <bpar...@ti.com>
> > ---
> >  drivers/media/platform/ti-vpe/vpe.c | 32 
> >  1 file changed, 16 insertions(+), 16 deletions(-)
> > 
> > diff --git a/drivers/media/platform/ti-vpe/vpe.c 
> > b/drivers/media/platform/ti-vpe/vpe.c
> > index a0b29685fb69..9c38eff5df46 100644
> > --- a/drivers/media/platform/ti-vpe/vpe.c
> > +++ b/drivers/media/platform/ti-vpe/vpe.c
> > @@ -898,15 +898,14 @@ static struct vpe_ctx *file2ctx(struct file *file)
> >  static int job_ready(void *priv)
> >  {
> > struct vpe_ctx *ctx = priv;
> > -   int needed = ctx->bufs_per_job;
> >  
> > -   if (ctx->deinterlacing && ctx->src_vbs[2] == NULL)
> > -   needed += 2;/* need additional two most recent fields */
> > -
> > -   if (v4l2_m2m_num_src_bufs_ready(ctx->fh.m2m_ctx) < needed)
> > -   return 0;
> > -
> > -   if (v4l2_m2m_num_dst_bufs_ready(ctx->fh.m2m_ctx) < needed)
> > +   /*
> > +* This check is needed as this might be called directly from driver
> > +* When called by m2m framework, this will always satisy, but when
> 
> typo: satisfy

Will fix.

> 
> > +* called from vpe_irq, this might fail. (src stream with zero buffers)
> > +*/
> > +   if (v4l2_m2m_num_src_bufs_ready(ctx->fh.m2m_ctx) <= 0 ||
> > +   v4l2_m2m_num_dst_bufs_ready(ctx->fh.m2m_ctx) <= 0)
> > return 0;
> >  
> > return 1;
> > @@ -1116,19 +1115,20 @@ static void device_run(void *priv)
> > struct sc_data *sc = ctx->dev->sc;
> > struct vpe_q_data *d_q_data = >q_data[Q_DATA_DST];
> >  
> > -   if (ctx->deinterlacing && ctx->src_vbs[2] == NULL) {
> > -   ctx->src_vbs[2] = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx);
> > -   WARN_ON(ctx->src_vbs[2] == NULL);
> > -   ctx->src_vbs[1] = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx);
> > -   WARN_ON(ctx->src_vbs[1] == NULL);
> > -   }
> > -
> > ctx->src_vbs[0] = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx);
> > WARN_ON(ctx->src_vbs[0] == NULL);
> > ctx->dst_vb = v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx);
> > WARN_ON(ctx->dst_vb == NULL);
> >  
> > if (ctx->deinterlacing) {
> > +
> > +   if (ctx->src_vbs[2] == NULL) {
> > +   ctx->src_vbs[2] = ctx->src_vbs[0];
> > +   WARN_ON(ctx->src_vbs[2] == NULL);
> > +   ctx->src_vbs[1] = ctx->src_vbs[0];
> > +   WARN_ON(ctx->src_vbs[1] == NULL);
> > +   }
> > +
> > /*
> >  * we have output the first 2 frames through line average, we
> >  * now switch to EDI de-interlacer
> > @@ -1349,7 +1349,7 @@ static irqreturn_t vpe_irq(int irq_vpe, void *data)
> > }
> >  
> > ctx->bufs_completed++;
> > -   if (ctx->bufs_completed < ctx->bufs_per_job) {
> > +   if (ctx->bufs_completed < ctx->bufs_per_job && job_ready(ctx)) {
> > device_run(ctx);
> > goto handled;
> > }
> > 
> 
> Regards,
> 
>   Hans
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Patch 01/35] media: ti-vpe: vpdma: Make vpdma library into its own module

2016-10-24 Thread Benoit Parrot
Hans,

Thanks for the review.


Hans Verkuil <hverk...@xs4all.nl> wrote on Mon [2016-Oct-17 16:08:55 +0200]:
> On 09/28/2016 11:16 PM, Benoit Parrot wrote:
> > The VPDMA (Video Port DMA) as found in devices such as DRA7xx is
> > used for both the Video Processing Engine (VPE) and the Video Input
> > Port (VIP).
> > 
> > In preparation for this we need to turn vpdma into its own
> > kernel module.
> > 
> > Signed-off-by: Benoit Parrot <bpar...@ti.com>
> > ---
> >  drivers/media/platform/Kconfig |  6 ++
> >  drivers/media/platform/ti-vpe/Makefile |  4 +++-
> >  drivers/media/platform/ti-vpe/vpdma.c  | 28 +++-
> >  3 files changed, 36 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig
> > index f98ed3fd0efd..3c15c5a53bd5 100644
> > --- a/drivers/media/platform/Kconfig
> > +++ b/drivers/media/platform/Kconfig
> > @@ -334,6 +334,7 @@ config VIDEO_TI_VPE
> > depends on HAS_DMA
> > select VIDEOBUF2_DMA_CONTIG
> > select V4L2_MEM2MEM_DEV
> > +   select VIDEO_TI_VPDMA
> > default n
> > ---help---
> >   Support for the TI VPE(Video Processing Engine) block
> > @@ -347,6 +348,11 @@ config VIDEO_TI_VPE_DEBUG
> >  
> >  endif # V4L_MEM2MEM_DRIVERS
> >  
> > +# TI VIDEO PORT Helper Modules
> > +# These will be selected by VPE and VIP
> > +config VIDEO_TI_VPDMA
> > +   tristate
> > +
> >  menuconfig V4L_TEST_DRIVERS
> > bool "Media test drivers"
> > depends on MEDIA_CAMERA_SUPPORT
> > diff --git a/drivers/media/platform/ti-vpe/Makefile 
> > b/drivers/media/platform/ti-vpe/Makefile
> > index e236059a60ad..faca5e115c1d 100644
> > --- a/drivers/media/platform/ti-vpe/Makefile
> > +++ b/drivers/media/platform/ti-vpe/Makefile
> > @@ -1,6 +1,8 @@
> >  obj-$(CONFIG_VIDEO_TI_VPE) += ti-vpe.o
> > +obj-$(CONFIG_VIDEO_TI_VPDMA) += ti-vpdma.o
> >  
> > -ti-vpe-y := vpe.o sc.o csc.o vpdma.o
> > +ti-vpe-y := vpe.o sc.o csc.o
> > +ti-vpdma-y := vpdma.o
> >  
> >  ccflags-$(CONFIG_VIDEO_TI_VPE_DEBUG) += -DDEBUG
> >  
> > diff --git a/drivers/media/platform/ti-vpe/vpdma.c 
> > b/drivers/media/platform/ti-vpe/vpdma.c
> > index 3e2e3a33e6ed..e55cb58213bf 100644
> > --- a/drivers/media/platform/ti-vpe/vpdma.c
> > +++ b/drivers/media/platform/ti-vpe/vpdma.c
> > @@ -75,6 +75,7 @@ const struct vpdma_data_format vpdma_yuv_fmts[] = {
> > .depth  = 16,
> > },
> >  };
> > +EXPORT_SYMBOL(vpdma_yuv_fmts);
> 
> EXPORT_SYMBOL_GPL?

I think for now I would rather go for consistency.
So I'll leave it as is.

Regards,
Benoit

> 
> (Up to you).
> 
> Regards,
> 
>   Hans
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 29/57] [media] ti-vpe: don't break long lines

2016-10-14 Thread Benoit Parrot
Acked-by: Benoit Parrot <bpar...@ti.com>

Mauro Carvalho Chehab <mche...@s-opensource.com> wrote on Fri [2016-Oct-14 
17:20:17 -0300]:
> Due to the 80-cols checkpatch warnings, several strings
> were broken into multiple lines. This is not considered
> a good practice anymore, as it makes harder to grep for
> strings at the source code. So, join those continuation
> lines.
> 
> Signed-off-by: Mauro Carvalho Chehab <mche...@s-opensource.com>
> ---
>  drivers/media/platform/ti-vpe/vpdma.c | 12 
>  drivers/media/platform/ti-vpe/vpe.c   |  3 +--
>  2 files changed, 5 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/media/platform/ti-vpe/vpdma.c 
> b/drivers/media/platform/ti-vpe/vpdma.c
> index 3e2e3a33e6ed..079a0c894d02 100644
> --- a/drivers/media/platform/ti-vpe/vpdma.c
> +++ b/drivers/media/platform/ti-vpe/vpdma.c
> @@ -466,8 +466,7 @@ static void dump_cfd(struct vpdma_cfd *cfd)
>  
>   pr_debug("word2: payload_addr = 0x%08x\n", cfd->payload_addr);
>  
> - pr_debug("word3: pkt_type = %d, direct = %d, class = %d, dest = %d, "
> - "payload_len = %d\n", cfd_get_pkt_type(cfd),
> + pr_debug("word3: pkt_type = %d, direct = %d, class = %d, dest = %d, 
> payload_len = %d\n", cfd_get_pkt_type(cfd),
>   cfd_get_direct(cfd), class, cfd_get_dest(cfd),
>   cfd_get_payload_len(cfd));
>  }
> @@ -574,8 +573,7 @@ static void dump_dtd(struct vpdma_dtd *dtd)
>   pr_debug("%s data transfer descriptor for channel %d\n",
>   dir == DTD_DIR_OUT ? "outbound" : "inbound", chan);
>  
> - pr_debug("word0: data_type = %d, notify = %d, field = %d, 1D = %d, "
> - "even_ln_skp = %d, odd_ln_skp = %d, line_stride = %d\n",
> + pr_debug("word0: data_type = %d, notify = %d, field = %d, 1D = %d, 
> even_ln_skp = %d, odd_ln_skp = %d, line_stride = %d\n",
>   dtd_get_data_type(dtd), dtd_get_notify(dtd), dtd_get_field(dtd),
>   dtd_get_1d(dtd), dtd_get_even_line_skip(dtd),
>   dtd_get_odd_line_skip(dtd), dtd_get_line_stride(dtd));
> @@ -586,8 +584,7 @@ static void dump_dtd(struct vpdma_dtd *dtd)
>  
>   pr_debug("word2: start_addr = %pad\n", >start_addr);
>  
> - pr_debug("word3: pkt_type = %d, mode = %d, dir = %d, chan = %d, "
> - "pri = %d, next_chan = %d\n", dtd_get_pkt_type(dtd),
> + pr_debug("word3: pkt_type = %d, mode = %d, dir = %d, chan = %d, pri = 
> %d, next_chan = %d\n", dtd_get_pkt_type(dtd),
>   dtd_get_mode(dtd), dir, chan, dtd_get_priority(dtd),
>   dtd_get_next_chan(dtd));
>  
> @@ -595,8 +592,7 @@ static void dump_dtd(struct vpdma_dtd *dtd)
>   pr_debug("word4: frame_width = %d, frame_height = %d\n",
>   dtd_get_frame_width(dtd), dtd_get_frame_height(dtd));
>   else
> - pr_debug("word4: desc_write_addr = 0x%08x, write_desc = %d, "
> - "drp_data = %d, use_desc_reg = %d\n",
> + pr_debug("word4: desc_write_addr = 0x%08x, write_desc = %d, 
> drp_data = %d, use_desc_reg = %d\n",
>   dtd_get_desc_write_addr(dtd), dtd_get_write_desc(dtd),
>   dtd_get_drop_data(dtd), dtd_get_use_desc(dtd));
>  
> diff --git a/drivers/media/platform/ti-vpe/vpe.c 
> b/drivers/media/platform/ti-vpe/vpe.c
> index 0189f7f7cb03..1cf4a4c1b899 100644
> --- a/drivers/media/platform/ti-vpe/vpe.c
> +++ b/drivers/media/platform/ti-vpe/vpe.c
> @@ -1263,8 +1263,7 @@ static irqreturn_t vpe_irq(int irq_vpe, void *data)
>   }
>  
>   if (irqst0 | irqst1) {
> - dev_warn(dev->v4l2_dev.dev, "Unexpected interrupt: "
> - "INT0_STATUS0 = 0x%08x, INT0_STATUS1 = 0x%08x\n",
> + dev_warn(dev->v4l2_dev.dev, "Unexpected interrupt: INT0_STATUS0 
> = 0x%08x, INT0_STATUS1 = 0x%08x\n",
>   irqst0, irqst1);
>   }
>  
> -- 
> 2.7.4
> 
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Patch 16/35] media: ti-vpe: vpe: Setup srcdst parameters in start_streaming

2016-09-28 Thread Benoit Parrot
From: Nikhil Devshatwar <nikhil...@ti.com>

For deinterlacing operation, each operation needs 2 fields in the
history. This is achieved by holding three buffers in
ctx->src_vbs[0,1,2] (f,f-1,f-2)

This is achieved by using the ctx->sequence which gets reset via the
s_fmt ioctl.

These buffers are dequeued in stream OFF by calling free_vbs()
But the corresponding references aren't removed anywhere.

When application tries to stream ON and OFF continuously, s_fmt ioctl
won't be called and it won't setup the srcdst parameters.

Setting source/destination parameters in stream ON ioctl would make
sure that the context is re-initialized before it is being used by
the driver.

Signed-off-by: Nikhil Devshatwar <nikhil...@ti.com>
Signed-off-by: Benoit Parrot <bpar...@ti.com>
---
 drivers/media/platform/ti-vpe/vpe.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/media/platform/ti-vpe/vpe.c 
b/drivers/media/platform/ti-vpe/vpe.c
index ab677f34a627..08b363feb4fc 100644
--- a/drivers/media/platform/ti-vpe/vpe.c
+++ b/drivers/media/platform/ti-vpe/vpe.c
@@ -869,6 +869,7 @@ static int set_srcdst_params(struct vpe_ctx *ctx)
}
 
free_vbs(ctx);
+   ctx->src_vbs[2] = ctx->src_vbs[1] = ctx->src_vbs[0] = NULL;
 
ret = realloc_mv_buffers(ctx, mv_buf_size);
if (ret)
@@ -1991,6 +1992,9 @@ static int vpe_start_streaming(struct vb2_queue *q, 
unsigned int count)
if (ctx->deinterlacing)
config_edi_input_mode(ctx, 0x0);
 
+   if (ctx->sequence != 0)
+   set_srcdst_params(ctx);
+
return 0;
 }
 
-- 
2.9.0

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Patch 10/35] media: ti-vpe: Free vpdma buffers in vpe_release

2016-09-28 Thread Benoit Parrot
From: Harinarayan Bhatta <harinara...@ti.com>

Free vpdma buffers in vpe_release. Otherwise it was generating random
backtrace.

Signed-off-by: Harinarayan Bhatta <harinara...@ti.com>
Signed-off-by: Somnath Mukherjee <somn...@ti.com>
Signed-off-by: Nikhil Devshatwar <nikhil...@ti.com>
Signed-off-by: Benoit Parrot <bpar...@ti.com>
---
 drivers/media/platform/ti-vpe/vpe.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/media/platform/ti-vpe/vpe.c 
b/drivers/media/platform/ti-vpe/vpe.c
index b66b55322dd4..17451237220c 100644
--- a/drivers/media/platform/ti-vpe/vpe.c
+++ b/drivers/media/platform/ti-vpe/vpe.c
@@ -2183,6 +2183,9 @@ static int vpe_release(struct file *file)
vpdma_free_desc_list(>desc_list);
vpdma_free_desc_buf(>mmr_adb);
 
+   vpdma_free_desc_buf(>sc_coeff_v);
+   vpdma_free_desc_buf(>sc_coeff_h);
+
v4l2_fh_del(>fh);
v4l2_fh_exit(>fh);
v4l2_ctrl_handler_free(>hdl);
-- 
2.9.0

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Patch 12/35] media: ti-vpe: vpdma: Add abort channel desc and cleanup APIs

2016-09-28 Thread Benoit Parrot
From: Nikhil Devshatwar <nikhil...@ti.com>

Whenever VPDMA processes a data descriptor of a list, it processes it
and sets up the channel for the DMA transaction. List manager holds the
descriptor in the list until the DMA is complete. If sync_on_channel
descriptor, or another descriptor for the same channel is present in
the FIFO, list manager keeps them until the current channel is free.

When the capture stream is closed suddenly while there are pending
descriptors in the FIFO (streamON failed, application killed), it would
keep the VPDMA in a busy state. Any further list post would fail with
EBUSY.

To avoid this, drivers need to stop the current processing list and
cleanup all the resources VPDMA has taken and also clear the internal FSM
of list manager. The state machine is cleared by issuing channel specific
abort descriptor.

Therefore, the vpdma_list_cleanup accepts an array of channels for which
abort_channel descriptors should be posted. It is driver's responsibility
to post for all the channels or the channels which were used in the last
context.

Signed-off-by: Nikhil Devshatwar <nikhil...@ti.com>
Signed-off-by: Benoit Parrot <bpar...@ti.com>
---
 drivers/media/platform/ti-vpe/vpdma.c | 75 +++
 drivers/media/platform/ti-vpe/vpdma.h |  6 +++
 2 files changed, 81 insertions(+)

diff --git a/drivers/media/platform/ti-vpe/vpdma.c 
b/drivers/media/platform/ti-vpe/vpdma.c
index 587dacce3880..4a2f093dc0df 100644
--- a/drivers/media/platform/ti-vpe/vpdma.c
+++ b/drivers/media/platform/ti-vpe/vpdma.c
@@ -385,6 +385,56 @@ void vpdma_unmap_desc_buf(struct vpdma_data *vpdma, struct 
vpdma_buf *buf)
 EXPORT_SYMBOL(vpdma_unmap_desc_buf);
 
 /*
+ * Cleanup all pending descriptors of a list
+ * First, stop the current list being processed.
+ * If the VPDMA was busy, this step makes vpdma to accept post lists.
+ * To cleanup the internal FSM, post abort list descriptor for all the
+ * channels from @channels array of size @size.
+ */
+int vpdma_list_cleanup(struct vpdma_data *vpdma, int list_num,
+   int *channels, int size)
+{
+   struct vpdma_desc_list abort_list;
+   int i, ret, timeout = 500;
+
+   write_reg(vpdma, VPDMA_LIST_ATTR,
+   (list_num << VPDMA_LIST_NUM_SHFT) |
+   (1 << VPDMA_LIST_STOP_SHFT));
+
+   if (size <= 0 || !channels)
+   return 0;
+
+   ret = vpdma_create_desc_list(_list,
+   size * sizeof(struct vpdma_dtd), VPDMA_LIST_TYPE_NORMAL);
+   if (ret)
+   return ret;
+
+   for (i = 0; i < size; i++)
+   vpdma_add_abort_channel_ctd(_list, channels[i]);
+
+   ret = vpdma_map_desc_buf(vpdma, _list.buf);
+   if (ret)
+   return ret;
+   ret = vpdma_submit_descs(vpdma, _list, list_num);
+   if (ret)
+   return ret;
+
+   while (vpdma_list_busy(vpdma, list_num) && timeout--)
+   ;
+
+   if (timeout == 0) {
+   dev_err(>pdev->dev, "Timed out cleaning up VPDMA 
list\n");
+   return -EBUSY;
+   }
+
+   vpdma_unmap_desc_buf(vpdma, _list.buf);
+   vpdma_free_desc_buf(_list.buf);
+
+   return 0;
+}
+EXPORT_SYMBOL(vpdma_list_cleanup);
+
+/*
  * create a descriptor list, the user of this list will append configuration,
  * control and data descriptors to this list, this list will be submitted to
  * VPDMA. VPDMA's list parser will go through each descriptor and perform the
@@ -629,6 +679,31 @@ void vpdma_add_sync_on_channel_ctd(struct vpdma_desc_list 
*list,
 }
 EXPORT_SYMBOL(vpdma_add_sync_on_channel_ctd);
 
+/*
+ * append an 'abort_channel' type control descriptor to the given descriptor
+ * list, this descriptor aborts any DMA transaction happening using the
+ * specified channel
+ */
+void vpdma_add_abort_channel_ctd(struct vpdma_desc_list *list,
+   int chan_num)
+{
+   struct vpdma_ctd *ctd;
+
+   ctd = list->next;
+   WARN_ON((void *)(ctd + 1) > (list->buf.addr + list->buf.size));
+
+   ctd->w0 = 0;
+   ctd->w1 = 0;
+   ctd->w2 = 0;
+   ctd->type_source_ctl = ctd_type_source_ctl(chan_num,
+   CTD_TYPE_ABORT_CHANNEL);
+
+   list->next = ctd + 1;
+
+   dump_ctd(ctd);
+}
+EXPORT_SYMBOL(vpdma_add_abort_channel_ctd);
+
 static void dump_dtd(struct vpdma_dtd *dtd)
 {
int dir, chan;
diff --git a/drivers/media/platform/ti-vpe/vpdma.h 
b/drivers/media/platform/ti-vpe/vpdma.h
index 32b9ed5191c5..4dafc1bcf116 100644
--- a/drivers/media/platform/ti-vpe/vpdma.h
+++ b/drivers/media/platform/ti-vpe/vpdma.h
@@ -163,6 +163,8 @@ enum vpdma_channel {
 #define VIP_CHAN_YUV_PORTB_OFFSET  2
 #define VIP_CHAN_RGB_PORTB_OFFSET  1
 
+#define VPDMA_MAX_CHANNELS 256
+
 /* flags for VPDMA data descriptors */
 #define VPDMA_DATA_ODD_LINE_SKIP   (1 << 0)
 #def

[Patch 15/35] media: ti-vpe: vpe: configure line mode separately

2016-09-28 Thread Benoit Parrot
From: Nikhil Devshatwar <nikhil...@ti.com>

Current driver configures the line mode of the DEI clients
from the open function directly. Even if the newly created context
is not yet scheduled, it updates some of the VPDMA registers.
This causes a problem in multi instance use case where just opening
the m2m device second time causes the running job to stall. This
happens especially if the source buffers used are NV12.

While all other configuration is being written to context specific
shadow registers, only line mode configuration is happening directly.

As there is no shadow register for line mode configuration, it's better
to separate the config_mode setting and line_mode setting. Call the
new "set_line_modes" functions only when actually loading the mmrs.
This makes sure that no non-running job will write to the registers
directly.

Signed-off-by: Nikhil Devshatwar <nikhil...@ti.com>
Signed-off-by: Benoit Parrot <bpar...@ti.com>
---
 drivers/media/platform/ti-vpe/vpe.c | 25 +
 1 file changed, 17 insertions(+), 8 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/vpe.c 
b/drivers/media/platform/ti-vpe/vpe.c
index 000cd073fa8d..ab677f34a627 100644
--- a/drivers/media/platform/ti-vpe/vpe.c
+++ b/drivers/media/platform/ti-vpe/vpe.c
@@ -660,14 +660,13 @@ static void set_us_coefficients(struct vpe_ctx *ctx)
 /*
  * Set the upsampler config mode and the VPDMA line mode in the shadow MMRs.
  */
-static void set_cfg_and_line_modes(struct vpe_ctx *ctx)
+static void set_cfg_modes(struct vpe_ctx *ctx)
 {
struct vpe_fmt *fmt = ctx->q_data[Q_DATA_SRC].fmt;
struct vpe_mmr_adb *mmr_adb = ctx->mmr_adb.addr;
u32 *us1_reg0 = _adb->us1_regs[0];
u32 *us2_reg0 = _adb->us2_regs[0];
u32 *us3_reg0 = _adb->us3_regs[0];
-   int line_mode = 1;
int cfg_mode = 1;
 
/*
@@ -675,15 +674,24 @@ static void set_cfg_and_line_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)
cfg_mode = 0;
-   line_mode = 0;  /* double lines to line buffer */
-   }
 
write_field(us1_reg0, cfg_mode, VPE_US_MODE_MASK, VPE_US_MODE_SHIFT);
write_field(us2_reg0, cfg_mode, VPE_US_MODE_MASK, VPE_US_MODE_SHIFT);
write_field(us3_reg0, cfg_mode, VPE_US_MODE_MASK, VPE_US_MODE_SHIFT);
 
+   ctx->load_mmrs = true;
+}
+
+static void set_line_modes(struct vpe_ctx *ctx)
+{
+   struct vpe_fmt *fmt = ctx->q_data[Q_DATA_SRC].fmt;
+   int line_mode = 1;
+
+   if (fmt->fourcc == V4L2_PIX_FMT_NV12)
+   line_mode = 0;  /* double lines to line buffer */
+
/* regs for now */
vpdma_set_line_mode(ctx->dev->vpdma, line_mode, VPE_CHAN_CHROMA1_IN);
vpdma_set_line_mode(ctx->dev->vpdma, line_mode, VPE_CHAN_CHROMA2_IN);
@@ -708,8 +716,6 @@ static void set_cfg_and_line_modes(struct vpe_ctx *ctx)
/* frame start for MV in client */
vpdma_set_frame_start_event(ctx->dev->vpdma, 
VPDMA_FSEVENT_CHANNEL_ACTIVE,
VPE_CHAN_MV_IN);
-
-   ctx->load_mmrs = true;
 }
 
 /*
@@ -868,7 +874,7 @@ static int set_srcdst_params(struct vpe_ctx *ctx)
if (ret)
return ret;
 
-   set_cfg_and_line_modes(ctx);
+   set_cfg_modes(ctx);
set_dei_regs(ctx);
 
csc_set_coeff(ctx->dev->csc, _adb->csc_regs[0],
@@ -1184,6 +1190,9 @@ static void device_run(void *priv)
if (ctx->dev->loaded_mmrs != ctx->mmr_adb.dma_addr || ctx->load_mmrs) {
vpdma_map_desc_buf(ctx->dev->vpdma, >mmr_adb);
vpdma_add_cfd_adb(>desc_list, CFD_MMR_CLIENT, 
>mmr_adb);
+
+   set_line_modes(ctx);
+
ctx->dev->loaded_mmrs = ctx->mmr_adb.dma_addr;
ctx->load_mmrs = false;
}
-- 
2.9.0

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Patch 20/35] media: ti-vpe: vpe: Added MODULE_DEVICE_TABLE hint

2016-09-28 Thread Benoit Parrot
ti_vpe module currently does not get loaded automatically.
Added MODULE_DEVICE_TABLE hint to the driver to assist.

Signed-off-by: Benoit Parrot <bpar...@ti.com>
---
 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 a43dcac0b15e..57d19ad6d4a5 100644
--- a/drivers/media/platform/ti-vpe/vpe.c
+++ b/drivers/media/platform/ti-vpe/vpe.c
@@ -2448,6 +2448,7 @@ static const struct of_device_id vpe_of_match[] = {
},
{},
 };
+MODULE_DEVICE_TABLE(of, vpe_of_match);
 #endif
 
 static struct platform_driver vpe_pdrv = {
-- 
2.9.0

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Patch 18/35] media: ti-vpe: vpe: Add RGB565 and RGB5551 support

2016-09-28 Thread Benoit Parrot
From: Nikhil Devshatwar <nikhil...@ti.com>

VPE hardware can generate output in RGB565 or in RGB5551 format.
Add these formats in the supported format list for CAPTURE stream.
Also, for RGB5551 format, the alpha component is not processed,
so the alpha value is taken from the default color.
Set the default color to make alpha component full when the dst
format is of RGB color space.

Signed-off-by: Nikhil Devshatwar <nikhil...@ti.com>
Signed-off-by: Benoit Parrot <bpar...@ti.com>
---
 drivers/media/platform/ti-vpe/vpe.c | 22 --
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/vpe.c 
b/drivers/media/platform/ti-vpe/vpe.c
index 843cbcbf3944..a43dcac0b15e 100644
--- a/drivers/media/platform/ti-vpe/vpe.c
+++ b/drivers/media/platform/ti-vpe/vpe.c
@@ -302,6 +302,22 @@ static struct vpe_fmt vpe_formats[] = {
.vpdma_fmt  = { _rgb_fmts[VPDMA_DATA_FMT_ABGR32],
  },
},
+   {
+   .name   = "RGB565",
+   .fourcc = V4L2_PIX_FMT_RGB565,
+   .types  = VPE_FMT_TYPE_CAPTURE,
+   .coplanar   = 0,
+   .vpdma_fmt  = { _rgb_fmts[VPDMA_DATA_FMT_RGB565],
+ },
+   },
+   {
+   .name   = "RGB5551",
+   .fourcc = V4L2_PIX_FMT_RGB555,
+   .types  = VPE_FMT_TYPE_CAPTURE,
+   .coplanar   = 0,
+   .vpdma_fmt  = { _rgb_fmts[VPDMA_DATA_FMT_RGBA16_5551],
+ },
+   },
 };
 
 /*
@@ -738,9 +754,11 @@ static void set_dst_registers(struct vpe_ctx *ctx)
struct vpe_fmt *fmt = ctx->q_data[Q_DATA_DST].fmt;
u32 val = 0;
 
-   if (clrspc == V4L2_COLORSPACE_SRGB)
+   if (clrspc == V4L2_COLORSPACE_SRGB) {
val |= VPE_RGB_OUT_SELECT;
-   else if (fmt->fourcc == V4L2_PIX_FMT_NV16)
+   vpdma_set_bg_color(ctx->dev->vpdma,
+   (struct vpdma_data_format *)fmt->vpdma_fmt[0], 0xff);
+   } else if (fmt->fourcc == V4L2_PIX_FMT_NV16)
val |= VPE_COLOR_SEPARATE_422;
 
/*
-- 
2.9.0

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Patch 17/35] media: ti-vpe: vpe: Post next descriptor only for list complete IRQ

2016-09-28 Thread Benoit Parrot
From: Nikhil Devshatwar <nikhil...@ti.com>

vpe_irq checks for the possible interrupt sources and prints the
errors for the DEI_ERROR and DS_UV interrupts. But it also post the
next descriptor list irrespective of whichever interrupt has occurred.

Because of this, driver may release the buffers even before DMA is
complete and also schedule next descriptor list.

Fix this by _actually_ handling the IRQ only when ListComplete IRQ
occurs.

Signed-off-by: Nikhil Devshatwar <nikhil...@ti.com>
Signed-off-by: Benoit Parrot <bpar...@ti.com>
---
 drivers/media/platform/ti-vpe/vpe.c | 9 +
 1 file changed, 9 insertions(+)

diff --git a/drivers/media/platform/ti-vpe/vpe.c 
b/drivers/media/platform/ti-vpe/vpe.c
index 08b363feb4fc..843cbcbf3944 100644
--- a/drivers/media/platform/ti-vpe/vpe.c
+++ b/drivers/media/platform/ti-vpe/vpe.c
@@ -1304,6 +1304,7 @@ static irqreturn_t vpe_irq(int irq_vpe, void *data)
struct vb2_v4l2_buffer *s_vb, *d_vb;
unsigned long flags;
u32 irqst0, irqst1;
+   bool list_complete = false;
 
irqst0 = read_reg(dev, VPE_INT0_STATUS0);
if (irqst0) {
@@ -1339,6 +1340,7 @@ static irqreturn_t vpe_irq(int irq_vpe, void *data)
vpdma_clear_list_stat(ctx->dev->vpdma, 0, 0);
 
irqst0 &= ~(VPE_INT0_LIST0_COMPLETE);
+   list_complete = true;
}
 
if (irqst0 | irqst1) {
@@ -1347,6 +1349,13 @@ static irqreturn_t vpe_irq(int irq_vpe, void *data)
irqst0, irqst1);
}
 
+   /*
+* Setup next operation only when list complete IRQ occurs
+* otherwise, skip the following code
+*/
+   if (!list_complete)
+   goto handled;
+
disable_irqs(ctx);
 
vpdma_unmap_desc_buf(dev->vpdma, >desc_list.buf);
-- 
2.9.0

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Patch 09/35] media: ti-vpe: vpe: Return NULL for invalid buffer type

2016-09-28 Thread Benoit Parrot
From: Nikhil Devshatwar <nikhil...@ti.com>

get_q_data can be called with different values for type
e.g. vpe_try_crop calls it with the buffer type which gets passed
from user space

Framework doesn't check wheather its correct type or not
If user space passes wrong type, kernel should not crash.
Return NULL when the passed type is invalid.

Signed-off-by: Nikhil Devshatwar <nikhil...@ti.com>
Signed-off-by: Benoit Parrot <bpar...@ti.com>
---
 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 2a4deceea17d..b66b55322dd4 100644
--- a/drivers/media/platform/ti-vpe/vpe.c
+++ b/drivers/media/platform/ti-vpe/vpe.c
@@ -420,7 +420,7 @@ static struct vpe_q_data *get_q_data(struct vpe_ctx *ctx,
case V4L2_BUF_TYPE_VIDEO_CAPTURE:
return >q_data[Q_DATA_DST];
default:
-   BUG();
+   return NULL;
}
return NULL;
 }
-- 
2.9.0

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Patch 34/35] media: ti-vpe: csc: Add debug support for multi-instance

2016-09-28 Thread Benoit Parrot
Since there might be more then one instance it is better to
show the base address when dumping registers to help
with debugging.

Signed-off-by: Benoit Parrot <bpar...@ti.com>
---
 drivers/media/platform/ti-vpe/csc.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/media/platform/ti-vpe/csc.c 
b/drivers/media/platform/ti-vpe/csc.c
index 9fc6f70adeeb..44b8465cf101 100644
--- a/drivers/media/platform/ti-vpe/csc.c
+++ b/drivers/media/platform/ti-vpe/csc.c
@@ -97,6 +97,8 @@ void csc_dump_regs(struct csc_data *csc)
 #define DUMPREG(r) dev_dbg(dev, "%-35s %08x\n", #r, \
ioread32(csc->base + CSC_##r))
 
+   dev_dbg(dev, "CSC Registers @ %pa:\n", >res->start);
+
DUMPREG(CSC00);
DUMPREG(CSC01);
DUMPREG(CSC02);
-- 
2.9.0

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Patch 29/35] media: ti-vpe: Make scaler library into its own module

2016-09-28 Thread Benoit Parrot
In preparation to add scaler support into VIP we need to
turn sc.c into its own kernel module.

Add support for multiple SC memory block as VIP contains
2 scaler instances.
This is done by passing the resource name to sc_create() and
modify the vpe invocation accordingly.

Signed-off-by: Benoit Parrot <bpar...@ti.com>
---
 drivers/media/platform/Kconfig |  4 
 drivers/media/platform/ti-vpe/Makefile |  4 +++-
 drivers/media/platform/ti-vpe/sc.c | 17 ++---
 drivers/media/platform/ti-vpe/sc.h |  2 +-
 drivers/media/platform/ti-vpe/vpe.c|  2 +-
 5 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig
index 3c15c5a53bd5..169626371a89 100644
--- a/drivers/media/platform/Kconfig
+++ b/drivers/media/platform/Kconfig
@@ -335,6 +335,7 @@ config VIDEO_TI_VPE
select VIDEOBUF2_DMA_CONTIG
select V4L2_MEM2MEM_DEV
select VIDEO_TI_VPDMA
+   select VIDEO_TI_SC
default n
---help---
  Support for the TI VPE(Video Processing Engine) block
@@ -353,6 +354,9 @@ endif # V4L_MEM2MEM_DRIVERS
 config VIDEO_TI_VPDMA
tristate
 
+config VIDEO_TI_SC
+   tristate
+
 menuconfig V4L_TEST_DRIVERS
bool "Media test drivers"
depends on MEDIA_CAMERA_SUPPORT
diff --git a/drivers/media/platform/ti-vpe/Makefile 
b/drivers/media/platform/ti-vpe/Makefile
index faca5e115c1d..736558d309ad 100644
--- a/drivers/media/platform/ti-vpe/Makefile
+++ b/drivers/media/platform/ti-vpe/Makefile
@@ -1,8 +1,10 @@
 obj-$(CONFIG_VIDEO_TI_VPE) += ti-vpe.o
 obj-$(CONFIG_VIDEO_TI_VPDMA) += ti-vpdma.o
+obj-$(CONFIG_VIDEO_TI_SC) += ti-sc.o
 
-ti-vpe-y := vpe.o sc.o csc.o
+ti-vpe-y := vpe.o csc.o
 ti-vpdma-y := vpdma.o
+ti-sc-y := sc.o
 
 ccflags-$(CONFIG_VIDEO_TI_VPE_DEBUG) += -DDEBUG
 
diff --git a/drivers/media/platform/ti-vpe/sc.c 
b/drivers/media/platform/ti-vpe/sc.c
index 02f3dae8ae42..52ce1450362f 100644
--- a/drivers/media/platform/ti-vpe/sc.c
+++ b/drivers/media/platform/ti-vpe/sc.c
@@ -14,6 +14,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -52,6 +53,7 @@ void sc_dump_regs(struct sc_data *sc)
 
 #undef DUMPREG
 }
+EXPORT_SYMBOL(sc_dump_regs);
 
 /*
  * set the horizontal scaler coefficients according to the ratio of output to
@@ -100,6 +102,7 @@ void sc_set_hs_coeffs(struct sc_data *sc, void *addr, 
unsigned int src_w,
 
sc->load_coeff_h = true;
 }
+EXPORT_SYMBOL(sc_set_hs_coeffs);
 
 /*
  * set the vertical scaler coefficients according to the ratio of output to
@@ -140,6 +143,7 @@ void sc_set_vs_coeffs(struct sc_data *sc, void *addr, 
unsigned int src_h,
 
sc->load_coeff_v = true;
 }
+EXPORT_SYMBOL(sc_set_vs_coeffs);
 
 void sc_config_scaler(struct sc_data *sc, u32 *sc_reg0, u32 *sc_reg8,
u32 *sc_reg17, unsigned int src_w, unsigned int src_h,
@@ -267,8 +271,9 @@ void sc_config_scaler(struct sc_data *sc, u32 *sc_reg0, u32 
*sc_reg8,
 
*sc_reg24 = (src_w << CFG_ORG_W_SHIFT) | (src_h << CFG_ORG_H_SHIFT);
 }
+EXPORT_SYMBOL(sc_config_scaler);
 
-struct sc_data *sc_create(struct platform_device *pdev)
+struct sc_data *sc_create(struct platform_device *pdev, const char *res_name)
 {
struct sc_data *sc;
 
@@ -282,9 +287,10 @@ struct sc_data *sc_create(struct platform_device *pdev)
 
sc->pdev = pdev;
 
-   sc->res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "sc");
+   sc->res = platform_get_resource_byname(pdev, IORESOURCE_MEM, res_name);
if (!sc->res) {
-   dev_err(>dev, "missing platform resources data\n");
+   dev_err(>dev, "missing '%s' platform resources data\n",
+   res_name);
return ERR_PTR(-ENODEV);
}
 
@@ -296,3 +302,8 @@ struct sc_data *sc_create(struct platform_device *pdev)
 
return sc;
 }
+EXPORT_SYMBOL(sc_create);
+
+MODULE_DESCRIPTION("TI VIP/VPE Scaler");
+MODULE_AUTHOR("Texas Instruments Inc.");
+MODULE_LICENSE("GPL v2");
diff --git a/drivers/media/platform/ti-vpe/sc.h 
b/drivers/media/platform/ti-vpe/sc.h
index de947db98990..d0aab5ef0eca 100644
--- a/drivers/media/platform/ti-vpe/sc.h
+++ b/drivers/media/platform/ti-vpe/sc.h
@@ -200,6 +200,6 @@ void sc_set_vs_coeffs(struct sc_data *sc, void *addr, 
unsigned int src_h,
 void sc_config_scaler(struct sc_data *sc, u32 *sc_reg0, u32 *sc_reg8,
u32 *sc_reg17, unsigned int src_w, unsigned int src_h,
unsigned int dst_w, unsigned int dst_h);
-struct sc_data *sc_create(struct platform_device *pdev);
+struct sc_data *sc_create(struct platform_device *pdev, const char *res_name);
 
 #endif
diff --git a/drivers/media/platform/ti-vpe/vpe.c 
b/drivers/media/platform/ti-vpe/vpe.c
index 875da06acd67..d0d222b3a173 100644
--- a/drivers/media/platform/ti-vpe/vpe.c
+++ b/drivers/media/platform/ti-vpe/vpe.c
@@ -2454,7 +24

[Patch 33/35] media: ti-vpe: Make colorspace converter library into its own module

2016-09-28 Thread Benoit Parrot
In preparation to add colorspace conversion support to VIP,
we need to turn csc.c into its own kernel module.

Signed-off-by: Benoit Parrot <bpar...@ti.com>
---
 drivers/media/platform/Kconfig |  4 
 drivers/media/platform/ti-vpe/Makefile |  4 +++-
 drivers/media/platform/ti-vpe/csc.c| 16 +---
 drivers/media/platform/ti-vpe/csc.h|  2 +-
 drivers/media/platform/ti-vpe/vpe.c|  2 +-
 5 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig
index 169626371a89..5334caba86d4 100644
--- a/drivers/media/platform/Kconfig
+++ b/drivers/media/platform/Kconfig
@@ -336,6 +336,7 @@ config VIDEO_TI_VPE
select V4L2_MEM2MEM_DEV
select VIDEO_TI_VPDMA
select VIDEO_TI_SC
+   select VIDEO_TI_CSC
default n
---help---
  Support for the TI VPE(Video Processing Engine) block
@@ -357,6 +358,9 @@ config VIDEO_TI_VPDMA
 config VIDEO_TI_SC
tristate
 
+config VIDEO_TI_CSC
+   tristate
+
 menuconfig V4L_TEST_DRIVERS
bool "Media test drivers"
depends on MEDIA_CAMERA_SUPPORT
diff --git a/drivers/media/platform/ti-vpe/Makefile 
b/drivers/media/platform/ti-vpe/Makefile
index 736558d309ad..32504b724b5d 100644
--- a/drivers/media/platform/ti-vpe/Makefile
+++ b/drivers/media/platform/ti-vpe/Makefile
@@ -1,10 +1,12 @@
 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
 
-ti-vpe-y := vpe.o csc.o
+ti-vpe-y := vpe.o
 ti-vpdma-y := vpdma.o
 ti-sc-y := sc.o
+ti-csc-y := csc.o
 
 ccflags-$(CONFIG_VIDEO_TI_VPE_DEBUG) += -DDEBUG
 
diff --git a/drivers/media/platform/ti-vpe/csc.c 
b/drivers/media/platform/ti-vpe/csc.c
index bec674994752..9fc6f70adeeb 100644
--- a/drivers/media/platform/ti-vpe/csc.c
+++ b/drivers/media/platform/ti-vpe/csc.c
@@ -14,6 +14,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -105,11 +106,13 @@ void csc_dump_regs(struct csc_data *csc)
 
 #undef DUMPREG
 }
+EXPORT_SYMBOL(csc_dump_regs);
 
 void csc_set_coeff_bypass(struct csc_data *csc, u32 *csc_reg5)
 {
*csc_reg5 |= CSC_BYPASS;
 }
+EXPORT_SYMBOL(csc_set_coeff_bypass);
 
 /*
  * set the color space converter coefficient shadow register values
@@ -160,8 +163,9 @@ void csc_set_coeff(struct csc_data *csc, u32 *csc_reg0,
for (; coeff < end_coeff; coeff += 2)
*shadow_csc++ = (*(coeff + 1) << 16) | *coeff;
 }
+EXPORT_SYMBOL(csc_set_coeff);
 
-struct csc_data *csc_create(struct platform_device *pdev)
+struct csc_data *csc_create(struct platform_device *pdev, const char *res_name)
 {
struct csc_data *csc;
 
@@ -176,9 +180,10 @@ struct csc_data *csc_create(struct platform_device *pdev)
csc->pdev = pdev;
 
csc->res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
-   "csc");
+   res_name);
if (csc->res == NULL) {
-   dev_err(>dev, "missing platform resources data\n");
+   dev_err(>dev, "missing '%s' platform resources data\n",
+   res_name);
return ERR_PTR(-ENODEV);
}
 
@@ -190,3 +195,8 @@ struct csc_data *csc_create(struct platform_device *pdev)
 
return csc;
 }
+EXPORT_SYMBOL(csc_create);
+
+MODULE_DESCRIPTION("TI VIP/VPE Color Space Converter");
+MODULE_AUTHOR("Texas Instruments Inc.");
+MODULE_LICENSE("GPL v2");
diff --git a/drivers/media/platform/ti-vpe/csc.h 
b/drivers/media/platform/ti-vpe/csc.h
index 1ad2b6dad561..024700b15152 100644
--- a/drivers/media/platform/ti-vpe/csc.h
+++ b/drivers/media/platform/ti-vpe/csc.h
@@ -63,6 +63,6 @@ void csc_set_coeff_bypass(struct csc_data *csc, u32 
*csc_reg5);
 void csc_set_coeff(struct csc_data *csc, u32 *csc_reg0,
enum v4l2_colorspace src_colorspace,
enum v4l2_colorspace dst_colorspace);
-struct csc_data *csc_create(struct platform_device *pdev);
+struct csc_data *csc_create(struct platform_device *pdev, const char 
*res_name);
 
 #endif
diff --git a/drivers/media/platform/ti-vpe/vpe.c 
b/drivers/media/platform/ti-vpe/vpe.c
index 2b661163d695..ae5acb5f42b8 100644
--- a/drivers/media/platform/ti-vpe/vpe.c
+++ b/drivers/media/platform/ti-vpe/vpe.c
@@ -2497,7 +2497,7 @@ static int vpe_probe(struct platform_device *pdev)
goto runtime_put;
}
 
-   dev->csc = csc_create(pdev);
+   dev->csc = csc_create(pdev, "csc");
if (IS_ERR(dev->csc)) {
ret = PTR_ERR(dev->csc);
goto runtime_put;
-- 
2.9.0

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Patch 30/35] media: ti-vpe: scaler: Add debug support for multi-instance

2016-09-28 Thread Benoit Parrot
Since there might be more then one instance it is better to
show the base address when dumping registers to help
with debugging.

Signed-off-by: Benoit Parrot <bpar...@ti.com>
---
 drivers/media/platform/ti-vpe/sc.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/media/platform/ti-vpe/sc.c 
b/drivers/media/platform/ti-vpe/sc.c
index 52ce1450362f..e9273b713782 100644
--- a/drivers/media/platform/ti-vpe/sc.c
+++ b/drivers/media/platform/ti-vpe/sc.c
@@ -28,6 +28,8 @@ void sc_dump_regs(struct sc_data *sc)
 #define DUMPREG(r) dev_dbg(dev, "%-35s %08x\n", #r, \
ioread32(sc->base + CFG_##r))
 
+   dev_dbg(dev, "SC Registers @ %pa:\n", >res->start);
+
DUMPREG(SC0);
DUMPREG(SC1);
DUMPREG(SC2);
-- 
2.9.0

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Patch 24/35] media: ti-vpe: vpe: Fix vb2 buffer cleanup

2016-09-28 Thread Benoit Parrot
When stop_streaming is called we need to cleanup the queued
vb2 buffers properly.
This was not previously being done which caused kernel
warning when the application using the resources was killed.
Kernel warnings were also generated on successful completion
of a de-interlacing case as well as upon aborting a
conversion.

Make sure every vb2 buffers is properly handled in all cases.

Signed-off-by: Benoit Parrot <bpar...@ti.com>
---
 drivers/media/platform/ti-vpe/vpe.c | 62 +++--
 1 file changed, 60 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/vpe.c 
b/drivers/media/platform/ti-vpe/vpe.c
index ee85c68d5771..fda5e02471c9 100644
--- a/drivers/media/platform/ti-vpe/vpe.c
+++ b/drivers/media/platform/ti-vpe/vpe.c
@@ -605,7 +605,10 @@ static void free_vbs(struct vpe_ctx *ctx)
spin_lock_irqsave(>lock, flags);
if (ctx->src_vbs[2]) {
v4l2_m2m_buf_done(ctx->src_vbs[2], VB2_BUF_STATE_DONE);
-   v4l2_m2m_buf_done(ctx->src_vbs[1], VB2_BUF_STATE_DONE);
+   if (ctx->src_vbs[1] && (ctx->src_vbs[1] != ctx->src_vbs[2]))
+   v4l2_m2m_buf_done(ctx->src_vbs[1], VB2_BUF_STATE_DONE);
+   ctx->src_vbs[2] = NULL;
+   ctx->src_vbs[1] = NULL;
}
spin_unlock_irqrestore(>lock, flags);
 }
@@ -1444,6 +1447,14 @@ static irqreturn_t vpe_irq(int irq_vpe, void *data)
ctx->src_vbs[1] = ctx->src_vbs[0];
}
 
+   /*
+* Since the vb2_buf_done has already been called fir therse
+* buffer we can now NULL them out so that we won't try
+* to clean out stray pointer later on.
+   */
+   ctx->src_vbs[0] = NULL;
+   ctx->dst_vb = NULL;
+
ctx->bufs_completed++;
if (ctx->bufs_completed < ctx->bufs_per_job && job_ready(ctx)) {
device_run(ctx);
@@ -2028,9 +2039,57 @@ static int vpe_start_streaming(struct vb2_queue *q, 
unsigned int count)
 static void vpe_stop_streaming(struct vb2_queue *q)
 {
struct vpe_ctx *ctx = vb2_get_drv_priv(q);
+   struct vb2_v4l2_buffer *vb;
+   unsigned long flags;
 
vpe_dump_regs(ctx->dev);
vpdma_dump_regs(ctx->dev->vpdma);
+
+   for (;;) {
+   if (V4L2_TYPE_IS_OUTPUT(q->type))
+   vb = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx);
+   else
+   vb = v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx);
+   if (!vb)
+   break;
+   spin_lock_irqsave(>dev->lock, flags);
+   v4l2_m2m_buf_done(vb, VB2_BUF_STATE_ERROR);
+   spin_unlock_irqrestore(>dev->lock, flags);
+   }
+
+   /*
+* Cleanup the in-transit vb2 buffers that have been
+* removed from their respective queue already but for
+* which procecessing has not been completed yet.
+*/
+   if (V4L2_TYPE_IS_OUTPUT(q->type)) {
+   spin_lock_irqsave(>dev->lock, flags);
+
+   if (ctx->src_vbs[2])
+   v4l2_m2m_buf_done(ctx->src_vbs[2], VB2_BUF_STATE_ERROR);
+
+   if (ctx->src_vbs[1] && (ctx->src_vbs[1] != ctx->src_vbs[2]))
+   v4l2_m2m_buf_done(ctx->src_vbs[1], VB2_BUF_STATE_ERROR);
+
+   if (ctx->src_vbs[0] &&
+   (ctx->src_vbs[0] != ctx->src_vbs[1]) &&
+   (ctx->src_vbs[0] != ctx->src_vbs[2]))
+   v4l2_m2m_buf_done(ctx->src_vbs[0], VB2_BUF_STATE_ERROR);
+
+   ctx->src_vbs[2] = NULL;
+   ctx->src_vbs[1] = NULL;
+   ctx->src_vbs[0] = NULL;
+
+   spin_unlock_irqrestore(>dev->lock, flags);
+   } else {
+   if (ctx->dst_vb) {
+   spin_lock_irqsave(>dev->lock, flags);
+
+   v4l2_m2m_buf_done(ctx->dst_vb, VB2_BUF_STATE_ERROR);
+   ctx->dst_vb = NULL;
+   spin_unlock_irqrestore(>dev->lock, flags);
+   }
+   }
 }
 
 static const struct vb2_ops vpe_qops = {
@@ -2223,7 +2282,6 @@ static int vpe_release(struct file *file)
vpe_dbg(dev, "releasing instance %p\n", ctx);
 
mutex_lock(>dev_mutex);
-   free_vbs(ctx);
free_mv_buffers(ctx);
vpdma_free_desc_list(>desc_list);
vpdma_free_desc_buf(>mmr_adb);
-- 
2.9.0

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Patch 28/35] media: ti-vpe: vpe: Enable DMABUF export

2016-09-28 Thread Benoit Parrot
Allow VPE to be able to export DMA buffer.

Signed-off-by: Benoit Parrot <bpar...@ti.com>
---
 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 3e1b8b1ccb7c..875da06acd67 100644
--- a/drivers/media/platform/ti-vpe/vpe.c
+++ b/drivers/media/platform/ti-vpe/vpe.c
@@ -1945,6 +1945,7 @@ static const struct v4l2_ioctl_ops vpe_ioctl_ops = {
.vidioc_querybuf= v4l2_m2m_ioctl_querybuf,
.vidioc_qbuf= v4l2_m2m_ioctl_qbuf,
.vidioc_dqbuf   = v4l2_m2m_ioctl_dqbuf,
+   .vidioc_expbuf  = v4l2_m2m_ioctl_expbuf,
.vidioc_streamon= v4l2_m2m_ioctl_streamon,
.vidioc_streamoff   = v4l2_m2m_ioctl_streamoff,
 
-- 
2.9.0

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Patch 25/35] media: ti-vpe: vpdma: Fix race condition for firmware loading

2016-09-28 Thread Benoit Parrot
From: Nikhil Devshatwar <nikhil...@ti.com>

vpdma_create API is supposed to allocated the struct vpdma_data and
return it to the driver. Also, it would call the callback function
when the VPDMA firmware is loaded.

Typically, VPE driver have following function call:
dev->vpdma = vpdma_create(pdev, firmware_load_callback);
And the callback implementation would continue the probe further.
Also, the dev->vpdma is accessed from the callback implementation.

This may lead to race condition between assignment of dev->vpdma
and the callback function being triggered.
This would lead to kernel crash because of NULL pointer access.

Fix this by passing a driver wrapped _data instead of allocating
inside vpdma_create.
Change the vpdma_create prototype accordingly and fix return paths.

Also, update the VPE driver to use the updated API and
initialize the dev->vpdma before hand so that the race condition
is avoided.

Signed-off-by: Nikhil Devshatwar <nikhil...@ti.com>
Signed-off-by: Benoit Parrot <bpar...@ti.com>
---
 drivers/media/platform/ti-vpe/vpdma.c | 17 +
 drivers/media/platform/ti-vpe/vpdma.h |  2 +-
 drivers/media/platform/ti-vpe/vpe.c   |  8 
 3 files changed, 10 insertions(+), 17 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/vpdma.c 
b/drivers/media/platform/ti-vpe/vpdma.c
index 8cf2922c9c6f..54c1174cad75 100644
--- a/drivers/media/platform/ti-vpe/vpdma.c
+++ b/drivers/media/platform/ti-vpe/vpdma.c
@@ -1132,21 +1132,14 @@ static int vpdma_load_firmware(struct vpdma_data *vpdma)
return 0;
 }
 
-struct vpdma_data *vpdma_create(struct platform_device *pdev,
+int vpdma_create(struct platform_device *pdev, struct vpdma_data *vpdma,
void (*cb)(struct platform_device *pdev))
 {
struct resource *res;
-   struct vpdma_data *vpdma;
int r;
 
dev_dbg(>dev, "vpdma_create\n");
 
-   vpdma = devm_kzalloc(>dev, sizeof(*vpdma), GFP_KERNEL);
-   if (!vpdma) {
-   dev_err(>dev, "couldn't alloc vpdma_dev\n");
-   return ERR_PTR(-ENOMEM);
-   }
-
vpdma->pdev = pdev;
vpdma->cb = cb;
spin_lock_init(>lock);
@@ -1154,22 +1147,22 @@ struct vpdma_data *vpdma_create(struct platform_device 
*pdev,
res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "vpdma");
if (res == NULL) {
dev_err(>dev, "missing platform resources data\n");
-   return ERR_PTR(-ENODEV);
+   return -ENODEV;
}
 
vpdma->base = devm_ioremap(>dev, res->start, resource_size(res));
if (!vpdma->base) {
dev_err(>dev, "failed to ioremap\n");
-   return ERR_PTR(-ENOMEM);
+   return -ENOMEM;
}
 
r = vpdma_load_firmware(vpdma);
if (r) {
pr_err("failed to load firmware %s\n", VPDMA_FIRMWARE);
-   return ERR_PTR(r);
+   return r;
}
 
-   return vpdma;
+   return 0;
 }
 EXPORT_SYMBOL(vpdma_create);
 
diff --git a/drivers/media/platform/ti-vpe/vpdma.h 
b/drivers/media/platform/ti-vpe/vpdma.h
index 405a6febc254..0df156b7c1cf 100644
--- a/drivers/media/platform/ti-vpe/vpdma.h
+++ b/drivers/media/platform/ti-vpe/vpdma.h
@@ -273,7 +273,7 @@ void vpdma_set_bg_color(struct vpdma_data *vpdma,
 void vpdma_dump_regs(struct vpdma_data *vpdma);
 
 /* initialize vpdma, passed with VPE's platform device pointer */
-struct vpdma_data *vpdma_create(struct platform_device *pdev,
+int vpdma_create(struct platform_device *pdev, struct vpdma_data *vpdma,
void (*cb)(struct platform_device *pdev));
 
 #endif
diff --git a/drivers/media/platform/ti-vpe/vpe.c 
b/drivers/media/platform/ti-vpe/vpe.c
index fda5e02471c9..c09247960550 100644
--- a/drivers/media/platform/ti-vpe/vpe.c
+++ b/drivers/media/platform/ti-vpe/vpe.c
@@ -383,6 +383,7 @@ struct vpe_dev {
void __iomem*base;
struct resource *res;
 
+   struct vpdma_data   vpdma_data;
struct vpdma_data   *vpdma; /* vpdma data handle */
struct sc_data  *sc;/* scaler data handle */
struct csc_data *csc;   /* csc data handle */
@@ -2463,11 +2464,10 @@ static int vpe_probe(struct platform_device *pdev)
goto runtime_put;
}
 
-   dev->vpdma = vpdma_create(pdev, vpe_fw_cb);
-   if (IS_ERR(dev->vpdma)) {
-   ret = PTR_ERR(dev->vpdma);
+   dev->vpdma = >vpdma_data;
+   ret = vpdma_create(pdev, dev->vpdma, vpe_fw_cb);
+   if (ret)
goto runtime_put;
-   }
 
return 0;
 
-- 
2.9.0

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Patch 27/35] media: ti-vpe: vpe: Fix line stride for output motion vector

2016-09-28 Thread Benoit Parrot
From: Nikhil Devshatwar <nikhil...@ti.com>

For deinterlacing operation, VPE hardware uses motion vectors.
MV calculated in the previous iteration are used for next interation.
Therefore driver allocates two motion vectors in ping-pong fashion.

For every transaction, one MV is DMAed in and one is DMAed out.
All the outbound DMAs (DMA to memory) use output parameters, but as
the motion vectors is generated purely out of input fields, it should
use the input parameters for DMA.

Fix the add_out_dtd to use source q_data for creating descriptor.
If the output size is greater than input stride, without this change,
MV DMA may overwrite the buffer causing memory corruption.

This CRITICAL fix ensures that the motion vector DMA descriptor is
created based on the attributes with which the buffer was allocated.

Signed-off-by: Nikhil Devshatwar <nikhil...@ti.com>
Signed-off-by: Ravikumar Kattekola <r...@ti.com>
Signed-off-by: Ravi Babu <ravib...@ti.com>
Signed-off-by: Benoit Parrot <bpar...@ti.com>
---
 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 c09247960550..3e1b8b1ccb7c 100644
--- a/drivers/media/platform/ti-vpe/vpe.c
+++ b/drivers/media/platform/ti-vpe/vpe.c
@@ -1046,6 +1046,7 @@ static void add_out_dtd(struct vpe_ctx *ctx, int port)
if (port == VPE_PORT_MV_OUT) {
vpdma_fmt = _misc_fmts[VPDMA_DATA_FMT_MV];
dma_addr = ctx->mv_buf_dma[mv_buf_selector];
+   q_data = >q_data[Q_DATA_SRC];
} else {
/* to incorporate interleaved formats */
int plane = fmt->coplanar ? p_data->vb_part : 0;
-- 
2.9.0

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Patch 32/35] media: ti-vpe: vpdma: Add RAW8 and RAW16 data types

2016-09-28 Thread Benoit Parrot
Add RAW8 and RAW16 data type to VPDMA.
To handle RAW format we are re-using the YUV CBY422
vpdma data type so that we use the vpdma to re-order
the incoming bytes, as the VIP parser assumes that the
first byte presented on the bus is the MSB of a 2
bytes value.

RAW8 handles from 1 to 8 bits.
RAW16 handles from 9 to 16 bits.

Signed-off-by: Benoit Parrot <bpar...@ti.com>
---
 drivers/media/platform/ti-vpe/vpdma.c | 23 +++
 drivers/media/platform/ti-vpe/vpdma.h |  6 ++
 2 files changed, 29 insertions(+)

diff --git a/drivers/media/platform/ti-vpe/vpdma.c 
b/drivers/media/platform/ti-vpe/vpdma.c
index e8ed6bae83ed..422fb0840e6e 100644
--- a/drivers/media/platform/ti-vpe/vpdma.c
+++ b/drivers/media/platform/ti-vpe/vpdma.c
@@ -191,6 +191,29 @@ const struct vpdma_data_format vpdma_rgb_fmts[] = {
 };
 EXPORT_SYMBOL(vpdma_rgb_fmts);
 
+/*
+ * To handle RAW format we are re-using the CBY422
+ * vpdma data type so that we use the vpdma to re-order
+ * the incoming bytes, as the parser assumes that the
+ * first byte presented on the bus is the MSB of a 2
+ * bytes value.
+ * RAW8 handles from 1 to 8 bits
+ * RAW16 handles from 9 to 16 bits
+ */
+const struct vpdma_data_format vpdma_raw_fmts[] = {
+   [VPDMA_DATA_FMT_RAW8] = {
+   .type   = VPDMA_DATA_FMT_TYPE_YUV,
+   .data_type  = DATA_TYPE_CBY422,
+   .depth  = 8,
+   },
+   [VPDMA_DATA_FMT_RAW16] = {
+   .type   = VPDMA_DATA_FMT_TYPE_YUV,
+   .data_type  = DATA_TYPE_CBY422,
+   .depth  = 16,
+   },
+};
+EXPORT_SYMBOL(vpdma_raw_fmts);
+
 const struct vpdma_data_format vpdma_misc_fmts[] = {
[VPDMA_DATA_FMT_MV] = {
.type   = VPDMA_DATA_FMT_TYPE_MISC,
diff --git a/drivers/media/platform/ti-vpe/vpdma.h 
b/drivers/media/platform/ti-vpe/vpdma.h
index 0df156b7c1cf..131700c112b2 100644
--- a/drivers/media/platform/ti-vpe/vpdma.h
+++ b/drivers/media/platform/ti-vpe/vpdma.h
@@ -104,12 +104,18 @@ enum vpdma_rgb_formats {
VPDMA_DATA_FMT_BGRA32,
 };
 
+enum vpdma_raw_formats {
+   VPDMA_DATA_FMT_RAW8 = 0,
+   VPDMA_DATA_FMT_RAW16,
+};
+
 enum vpdma_misc_formats {
VPDMA_DATA_FMT_MV = 0,
 };
 
 extern const struct vpdma_data_format vpdma_yuv_fmts[];
 extern const struct vpdma_data_format vpdma_rgb_fmts[];
+extern const struct vpdma_data_format vpdma_raw_fmts[];
 extern const struct vpdma_data_format vpdma_misc_fmts[];
 
 enum vpdma_frame_start_event {
-- 
2.9.0

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Patch 31/35] media: ti-vpe: vpe: Make sure frame size dont exceed scaler capacity

2016-09-28 Thread Benoit Parrot
When scaler is to be used we need to make sure that the input and
output frame size do not exceed the maximum frame sizes that the
scaler h/w can handle otherwise streaming stall as the scaler
cannot proceed.

The scaler buffer is limited to 2047 pixels (i.e. 11 bits) when
attempting anything larger (2048 for example) the scaler stalls.

Realistically in an mem2mem device we can only check for this type
of issue when start_streaming is called. We can't do it during the
try_fmt/s_fmt because we do not have all of the info needed at that
point. So instead when start_streaming is called we need to check
that the input and output frames size do not exceed the scaler's
capability. The only time larger frame size are allowed is when
the input frame szie is the same as the output frame size.

Now in the case where we need to fail, start_streaming must return
all previously queued buffer back otherwise the vb2 framework
will issue kernel WARN messages.
In this case we also give an error message.

Signed-off-by: Benoit Parrot <bpar...@ti.com>
---
 drivers/media/platform/ti-vpe/sc.h  |  6 
 drivers/media/platform/ti-vpe/vpe.c | 71 -
 2 files changed, 60 insertions(+), 17 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/sc.h 
b/drivers/media/platform/ti-vpe/sc.h
index d0aab5ef0eca..f1fe80b38c9f 100644
--- a/drivers/media/platform/ti-vpe/sc.h
+++ b/drivers/media/platform/ti-vpe/sc.h
@@ -173,6 +173,12 @@
 /* number of taps expected by the scaler in it's coefficient memory */
 #define SC_NUM_TAPS_MEM_ALIGN  8
 
+/* Maximum frame width the scaler can handle (in pixels) */
+#define SC_MAX_PIXEL_WIDTH 2047
+
+/* Maximum frame height the scaler can handle (in lines) */
+#define SC_MAX_PIXEL_HEIGHT2047
+
 /*
  * coefficient memory size in bytes:
  * num phases x num sets(luma and chroma) x num taps(aligned) x coeff size
diff --git a/drivers/media/platform/ti-vpe/vpe.c 
b/drivers/media/platform/ti-vpe/vpe.c
index d0d222b3a173..2b661163d695 100644
--- a/drivers/media/platform/ti-vpe/vpe.c
+++ b/drivers/media/platform/ti-vpe/vpe.c
@@ -2026,28 +2026,33 @@ static void vpe_buf_queue(struct vb2_buffer *vb)
v4l2_m2m_buf_queue(ctx->fh.m2m_ctx, vbuf);
 }
 
-static int vpe_start_streaming(struct vb2_queue *q, unsigned int count)
+static int check_srcdst_sizes(struct vpe_ctx *ctx)
 {
-   struct vpe_ctx *ctx = vb2_get_drv_priv(q);
+   struct vpe_q_data *s_q_data =  >q_data[Q_DATA_SRC];
+   struct vpe_q_data *d_q_data =  >q_data[Q_DATA_DST];
+   unsigned int src_w = s_q_data->c_rect.width;
+   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;
 
-   if (ctx->deinterlacing)
-   config_edi_input_mode(ctx, 0x0);
+   if (src_w == dst_w && src_h == dst_h)
+   return 0;
 
-   if (ctx->sequence != 0)
-   set_srcdst_params(ctx);
+   if (src_h <= SC_MAX_PIXEL_HEIGHT &&
+   src_w <= SC_MAX_PIXEL_WIDTH &&
+   dst_h <= SC_MAX_PIXEL_HEIGHT &&
+   dst_w <= SC_MAX_PIXEL_WIDTH)
+   return 0;
 
-   return 0;
+   return -1;
 }
 
-static void vpe_stop_streaming(struct vb2_queue *q)
+static void vpe_return_all_buffers(struct vpe_ctx *ctx,  struct vb2_queue *q,
+  enum vb2_buffer_state state)
 {
-   struct vpe_ctx *ctx = vb2_get_drv_priv(q);
struct vb2_v4l2_buffer *vb;
unsigned long flags;
 
-   vpe_dump_regs(ctx->dev);
-   vpdma_dump_regs(ctx->dev->vpdma);
-
for (;;) {
if (V4L2_TYPE_IS_OUTPUT(q->type))
vb = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx);
@@ -2056,7 +2061,7 @@ static void vpe_stop_streaming(struct vb2_queue *q)
if (!vb)
break;
spin_lock_irqsave(>dev->lock, flags);
-   v4l2_m2m_buf_done(vb, VB2_BUF_STATE_ERROR);
+   v4l2_m2m_buf_done(vb, state);
spin_unlock_irqrestore(>dev->lock, flags);
}
 
@@ -2069,15 +2074,15 @@ static void vpe_stop_streaming(struct vb2_queue *q)
spin_lock_irqsave(>dev->lock, flags);
 
if (ctx->src_vbs[2])
-   v4l2_m2m_buf_done(ctx->src_vbs[2], VB2_BUF_STATE_ERROR);
+   v4l2_m2m_buf_done(ctx->src_vbs[2], state);
 
if (ctx->src_vbs[1] && (ctx->src_vbs[1] != ctx->src_vbs[2]))
-   v4l2_m2m_buf_done(ctx->src_vbs[1], VB2_BUF_STATE_ERROR);
+   v4l2_m2m_buf_done(ctx->src_vbs[1], state);
 
if (ctx->src_vbs[0] &&
(ctx->src_vbs[0] != ctx->src_vbs[1]) &&
(ctx->src_vbs

[Patch 35/35] media: ti-vpe: vpe: Add proper support single and multi-plane buffer

2016-09-28 Thread Benoit Parrot
The VPE was restricting the number of plane per buffer based on
the fact that if a particular format had color separation it was
meant to need 2 planes.

However NV12/NV16 are color separate format which are meant to be
presented in a single contiguous buffer/plane.
It could also be presented in a multi-plane as well if need be.
So we must support both modes for more flexibility.

The number of plane requested by user space was previously ignored
and was therefore always overwritten.
The driver now use the requested num plane as hint to calculate needed
offset when required.

Signed-off-by: Benoit Parrot <bpar...@ti.com>
---
 drivers/media/platform/ti-vpe/vpe.c | 58 ++---
 1 file changed, 48 insertions(+), 10 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/vpe.c 
b/drivers/media/platform/ti-vpe/vpe.c
index ae5acb5f42b8..c3ff7df780a9 100644
--- a/drivers/media/platform/ti-vpe/vpe.c
+++ b/drivers/media/platform/ti-vpe/vpe.c
@@ -327,6 +327,7 @@ static struct vpe_fmt vpe_formats[] = {
 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 */
@@ -1042,6 +1043,7 @@ static void add_out_dtd(struct vpe_ctx *ctx, int port)
int mv_buf_selector = !ctx->src_mv_buf_selector;
dma_addr_t dma_addr;
u32 flags = 0;
+   u32 offset = 0;
 
if (port == VPE_PORT_MV_OUT) {
vpdma_fmt = _misc_fmts[VPDMA_DATA_FMT_MV];
@@ -1052,13 +1054,27 @@ static void add_out_dtd(struct vpe_ctx *ctx, int port)
int plane = fmt->coplanar ? p_data->vb_part : 0;
 
vpdma_fmt = fmt->vpdma_fmt[plane];
-   dma_addr = vb2_dma_contig_plane_dma_addr(vb, plane);
+   /*
+* If we are using a single plane buffer and
+* we need to set a separate vpdma chroma channel.
+*/
+   if (q_data->nplanes == 1 && plane) {
+   dma_addr = vb2_dma_contig_plane_dma_addr(vb, 0);
+   /* Compute required offset */
+   offset = q_data->bytesperline[0] * q_data->height;
+   } else {
+   dma_addr = vb2_dma_contig_plane_dma_addr(vb, plane);
+   /* Use address as is, no offset */
+   offset = 0;
+   }
if (!dma_addr) {
vpe_err(ctx->dev,
"acquiring output buffer(%d) dma_addr failed\n",
port);
return;
}
+   /* Apply the offset */
+   dma_addr += offset;
}
 
if (q_data->flags & Q_DATA_FRAME_1D)
@@ -1087,6 +1103,7 @@ static void add_in_dtd(struct vpe_ctx *ctx, int port)
int frame_width, frame_height;
dma_addr_t dma_addr;
u32 flags = 0;
+   u32 offset = 0;
 
if (port == VPE_PORT_MV_IN) {
vpdma_fmt = _misc_fmts[VPDMA_DATA_FMT_MV];
@@ -1096,14 +1113,27 @@ static void add_in_dtd(struct vpe_ctx *ctx, int port)
int plane = fmt->coplanar ? p_data->vb_part : 0;
 
vpdma_fmt = fmt->vpdma_fmt[plane];
-
-   dma_addr = vb2_dma_contig_plane_dma_addr(vb, plane);
+   /*
+* If we are using a single plane buffer and
+* we need to set a separate vpdma chroma channel.
+*/
+   if (q_data->nplanes == 1 && plane) {
+   dma_addr = vb2_dma_contig_plane_dma_addr(vb, 0);
+   /* Compute required offset */
+   offset = q_data->bytesperline[0] * q_data->height;
+   } else {
+   dma_addr = vb2_dma_contig_plane_dma_addr(vb, plane);
+   /* Use address as is, no offset */
+   offset = 0;
+   }
if (!dma_addr) {
vpe_err(ctx->dev,
-   "acquiring input buffer(%d) dma_addr failed\n",
+   "acquiring output buffer(%d) dma_addr failed\n",
port);
return;
}
+   /* Apply the offset */
+   dma_addr += offset;
 
if (q_data->flags & Q_DATA_INTERLACED_SEQ_TB) {
/*
@@ -1549,7 +1579,7 @@ static int vpe_g_fm

[Patch 21/35] media: ti-vpe: vpdma: Corrected YUV422 data type label.

2016-09-28 Thread Benoit Parrot
The YUV data type definition below are taken from
both the TRM and i839 Errata information.
Use the correct data type considering byte
reordering of components.

Added the 2 missing YUV422 variant.
Also since the single use of "C" in the 422 case
to mean "Cr" (i.e. V component). It was decided
to explicitly label them CR to remove any confusion.
Bear in mind that the type label refer to the memory
packed order (LSB - MSB).

Signed-off-by: Benoit Parrot <bpar...@ti.com>
---
 drivers/media/platform/ti-vpe/vpdma.c  | 18 ++
 drivers/media/platform/ti-vpe/vpdma.h  |  6 --
 drivers/media/platform/ti-vpe/vpdma_priv.h | 19 ---
 drivers/media/platform/ti-vpe/vpe.c|  8 
 4 files changed, 38 insertions(+), 13 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/vpdma.c 
b/drivers/media/platform/ti-vpe/vpdma.c
index 9f396ff03394..8cf2922c9c6f 100644
--- a/drivers/media/platform/ti-vpe/vpdma.c
+++ b/drivers/media/platform/ti-vpe/vpdma.c
@@ -59,9 +59,9 @@ const struct vpdma_data_format vpdma_yuv_fmts[] = {
.data_type  = DATA_TYPE_C420,
.depth  = 4,
},
-   [VPDMA_DATA_FMT_YC422] = {
+   [VPDMA_DATA_FMT_YCR422] = {
.type   = VPDMA_DATA_FMT_TYPE_YUV,
-   .data_type  = DATA_TYPE_YC422,
+   .data_type  = DATA_TYPE_YCR422,
.depth  = 16,
},
[VPDMA_DATA_FMT_YC444] = {
@@ -69,9 +69,19 @@ const struct vpdma_data_format vpdma_yuv_fmts[] = {
.data_type  = DATA_TYPE_YC444,
.depth  = 24,
},
-   [VPDMA_DATA_FMT_CY422] = {
+   [VPDMA_DATA_FMT_CRY422] = {
.type   = VPDMA_DATA_FMT_TYPE_YUV,
-   .data_type  = DATA_TYPE_CY422,
+   .data_type  = DATA_TYPE_CRY422,
+   .depth  = 16,
+   },
+   [VPDMA_DATA_FMT_CBY422] = {
+   .type   = VPDMA_DATA_FMT_TYPE_YUV,
+   .data_type  = DATA_TYPE_CBY422,
+   .depth  = 16,
+   },
+   [VPDMA_DATA_FMT_YCB422] = {
+   .type   = VPDMA_DATA_FMT_TYPE_YUV,
+   .data_type  = DATA_TYPE_YCB422,
.depth  = 16,
},
 };
diff --git a/drivers/media/platform/ti-vpe/vpdma.h 
b/drivers/media/platform/ti-vpe/vpdma.h
index ccf871ad8800..405a6febc254 100644
--- a/drivers/media/platform/ti-vpe/vpdma.h
+++ b/drivers/media/platform/ti-vpe/vpdma.h
@@ -74,9 +74,11 @@ enum vpdma_yuv_formats {
VPDMA_DATA_FMT_C444,
VPDMA_DATA_FMT_C422,
VPDMA_DATA_FMT_C420,
-   VPDMA_DATA_FMT_YC422,
+   VPDMA_DATA_FMT_YCR422,
VPDMA_DATA_FMT_YC444,
-   VPDMA_DATA_FMT_CY422,
+   VPDMA_DATA_FMT_CRY422,
+   VPDMA_DATA_FMT_CBY422,
+   VPDMA_DATA_FMT_YCB422,
 };
 
 enum vpdma_rgb_formats {
diff --git a/drivers/media/platform/ti-vpe/vpdma_priv.h 
b/drivers/media/platform/ti-vpe/vpdma_priv.h
index 54b6aa866c74..f974a803fa27 100644
--- a/drivers/media/platform/ti-vpe/vpdma_priv.h
+++ b/drivers/media/platform/ti-vpe/vpdma_priv.h
@@ -77,16 +77,29 @@
 #define VPDMA_LIST_TYPE_SHFT   16
 #define VPDMA_LIST_SIZE_MASK   0x
 
-/* VPDMA data type values for data formats */
+/*
+ * The YUV data type definition below are taken from
+ * both the TRM and i839 Errata information.
+ * Use the correct data type considering byte
+ * reordering of components.
+ *
+ * Also since the single use of "C" in the 422 case
+ * to mean "Cr" (i.e. V component). It was decided
+ * to explicitly label them CR to remove any confusion.
+ * Bear in mind that the type label refer to the memory
+ * packed order (LSB - MSB).
+ */
 #define DATA_TYPE_Y444 0x0
 #define DATA_TYPE_Y422 0x1
 #define DATA_TYPE_Y420 0x2
 #define DATA_TYPE_C444 0x4
 #define DATA_TYPE_C422 0x5
 #define DATA_TYPE_C420 0x6
-#define DATA_TYPE_YC4220x7
 #define DATA_TYPE_YC4440x8
-#define DATA_TYPE_CY4220x27
+#define DATA_TYPE_YCB422   0x7
+#define DATA_TYPE_YCR422   0x17
+#define DATA_TYPE_CBY422   0x27
+#define DATA_TYPE_CRY422   0x37
 
 #define DATA_TYPE_RGB16_5650x0
 #define DATA_TYPE_ARGB_15550x1
diff --git a/drivers/media/platform/ti-vpe/vpe.c 
b/drivers/media/platform/ti-vpe/vpe.c
index 57d19ad6d4a5..ee85c68d5771 100644
--- a/drivers/media/platform/ti-vpe/vpe.c
+++ b/drivers/media/platform/ti-vpe/vpe.c
@@ -237,7 +237,7 @@ struct vpe_fmt {
 
 static struct vpe_fmt vpe_formats[] = {
{
-   .name   = "YUV 422 co-planar",
+

  1   2   >