Re: is it possible to use single IOCTL to setup media pipeline?

2018-11-21 Thread Tomasz Figa
Hi Ning,

On Thu, Nov 22, 2018 at 11:52 AM Zhang, Ning A  wrote:
>
> Hello everyone
>
> when we need to setup media pipeline, eg, for camera capture, media-ctl
> needs to be called multiple time to setup media link and subdev
> formats, or similar code in a single application. this will use
> multiple IOCTLs on "/dev/mediaX" and "/dev/v4l2-subdevY".
>
> to setup media pipeline in userspace requires to fully understanding
> the topology of the media stack. but the fact is only media driver
> developer could know how to setup media pipeline. each time driver
> updates, this would break userspace application if application
> engineers don't know this change.

That's obviously a bug in the driver. Kernel interfaces must not
change in a way that are not compatible with the userspace.

> In this case, if a IOCTL is designed
> to setup media pipeline, no need to update applications, after driver
> is updated.
>
> this will not only benefit for design a single IOCTL, this also helps
> to hide the detail of media pipeline, by load a binary blob which holds
> information about how to setup pipeline, or hide it in bootloader/ACPI
> tables/device tree, etc.

Media pipeline configuration is specific to the use case. If you
hardcode it in the driver or bootloader, the user will not be able to
use any other use case than the hardcoded blob, which is unacceptable
for Linux drivers.

Instead, it sounds like your userspace should be designed in a way
that the media topology configuration is loaded from a configuration
file that you could either get from your kernel driver developer or
just maintain yourself based on any changes the media developers do.
Of course that's unrelated to the backwards compatibility issue, which
should not happen normally. The configuration file would be helpful
for handling future extensions and new hardware platforms.

>
> another benefit is save time for setup media pipeline, if there is a
> PKI like "time for open camera". as my test, this will saves hundreds
> of milliseconds.

For this problem, the proper solution would be to create an ioctl that
can aggregate setting multiple parts of the topology in one go. For
example, V4L2 has VIDIOC_S_CTRL for setting a control, but there is
also VIDIOC_S_EXT_CTRLS, which lets you set multiple controls in one
call. Something like VIDIOC_S_EXT_CTRLS for configuring the media
topology would solve the performance problem.

Best regards,
Tomasz


cron job: media_tree daily build: WARNINGS

2018-11-21 Thread Hans Verkuil
This message is generated daily by a cron job that builds media_tree for
the kernels and architectures in the list below.

Results of the daily build of media_tree:

date:   Thu Nov 22 05:00:11 CET 2018
media-tree git hash:5200ab6a32d6055428896a49ec9e3b1652c1a100
media_build git hash:   a8aef9cea0a4a2f3ea86c0b37bd6a1378018c0c1
v4l-utils git hash: fcde9d178adb91cad74ed705c3009f8b05b4b44b
edid-decode git hash:   5eeb151a748788666534d6ea3da07f90400d24c2
gcc version:i686-linux-gcc (GCC) 8.2.0
sparse version: 0.5.2
smatch version: 0.5.1
host hardware:  x86_64
host os:4.18.0-2-amd64

linux-git-arm-at91: WARNINGS
linux-git-arm-davinci: WARNINGS
linux-git-arm-multi: WARNINGS
linux-git-arm-pxa: WARNINGS
linux-git-arm-stm32: WARNINGS
linux-git-arm64: OK
linux-git-i686: WARNINGS
linux-git-mips: OK
linux-git-powerpc64: WARNINGS
linux-git-sh: OK
linux-git-x86_64: WARNINGS
Check COMPILE_TEST: OK
linux-3.10.108-i686: OK
linux-3.10.108-x86_64: OK
linux-3.11.10-i686: OK
linux-3.11.10-x86_64: OK
linux-3.12.74-i686: OK
linux-3.12.74-x86_64: OK
linux-3.13.11-i686: OK
linux-3.13.11-x86_64: OK
linux-3.14.79-i686: OK
linux-3.14.79-x86_64: OK
linux-3.15.10-i686: OK
linux-3.15.10-x86_64: OK
linux-3.16.57-i686: OK
linux-3.16.57-x86_64: OK
linux-3.17.8-i686: OK
linux-3.17.8-x86_64: OK
linux-3.18.123-i686: OK
linux-3.18.123-x86_64: OK
linux-3.19.8-i686: OK
linux-3.19.8-x86_64: OK
linux-4.0.9-i686: OK
linux-4.0.9-x86_64: OK
linux-4.1.52-i686: OK
linux-4.1.52-x86_64: OK
linux-4.2.8-i686: OK
linux-4.2.8-x86_64: OK
linux-4.3.6-i686: OK
linux-4.3.6-x86_64: OK
linux-4.4.159-i686: OK
linux-4.4.159-x86_64: OK
linux-4.5.7-i686: OK
linux-4.5.7-x86_64: OK
linux-4.6.7-i686: OK
linux-4.6.7-x86_64: OK
linux-4.7.10-i686: OK
linux-4.7.10-x86_64: OK
linux-4.8.17-i686: OK
linux-4.8.17-x86_64: OK
linux-4.9.131-i686: OK
linux-4.9.131-x86_64: OK
linux-4.10.17-i686: OK
linux-4.10.17-x86_64: OK
linux-4.11.12-i686: OK
linux-4.11.12-x86_64: OK
linux-4.12.14-i686: OK
linux-4.12.14-x86_64: OK
linux-4.13.16-i686: OK
linux-4.13.16-x86_64: OK
linux-4.14.74-i686: OK
linux-4.14.74-x86_64: OK
linux-4.15.18-i686: OK
linux-4.15.18-x86_64: OK
linux-4.16.18-i686: OK
linux-4.16.18-x86_64: OK
linux-4.17.19-i686: OK
linux-4.17.19-x86_64: OK
linux-4.18.12-i686: OK
linux-4.18.12-x86_64: OK
linux-4.19.1-i686: OK
linux-4.19.1-x86_64: OK
linux-4.20-rc1-i686: OK
linux-4.20-rc1-x86_64: OK
apps: OK
spec-git: OK
sparse: WARNINGS

Detailed results are available here:

http://www.xs4all.nl/~hverkuil/logs/Thursday.log

Full logs are available here:

http://www.xs4all.nl/~hverkuil/logs/Thursday.tar.bz2

The Media Infrastructure API from this daily build is here:

http://www.xs4all.nl/~hverkuil/spec/index.html


[PATCH v2 1/2] media: video-i2c: check if chip struct has set_power function

2018-11-21 Thread Matt Ranostay
Not all future supported video chips will always have power management
support, and so it is important to check before calling set_power() is
defined.

Signed-off-by: Matt Ranostay 
---
 drivers/media/i2c/video-i2c.c | 21 -
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/drivers/media/i2c/video-i2c.c b/drivers/media/i2c/video-i2c.c
index 981166010c9b..a64e1a725a20 100644
--- a/drivers/media/i2c/video-i2c.c
+++ b/drivers/media/i2c/video-i2c.c
@@ -736,9 +736,11 @@ static int video_i2c_probe(struct i2c_client *client,
video_set_drvdata(>vdev, data);
i2c_set_clientdata(client, data);
 
-   ret = data->chip->set_power(data, true);
-   if (ret)
-   goto error_unregister_device;
+   if (data->chip->set_power) {
+   ret = data->chip->set_power(data, true);
+   if (ret)
+   goto error_unregister_device;
+   }
 
pm_runtime_get_noresume(>dev);
pm_runtime_set_active(>dev);
@@ -767,7 +769,8 @@ static int video_i2c_probe(struct i2c_client *client,
pm_runtime_disable(>dev);
pm_runtime_set_suspended(>dev);
pm_runtime_put_noidle(>dev);
-   data->chip->set_power(data, false);
+   if (data->chip->set_power)
+   data->chip->set_power(data, false);
 
 error_unregister_device:
v4l2_device_unregister(v4l2_dev);
@@ -791,7 +794,9 @@ static int video_i2c_remove(struct i2c_client *client)
pm_runtime_disable(>dev);
pm_runtime_set_suspended(>dev);
pm_runtime_put_noidle(>dev);
-   data->chip->set_power(data, false);
+
+   if (data->chip->set_power)
+   data->chip->set_power(data, false);
 
video_unregister_device(>vdev);
 
@@ -804,6 +809,9 @@ static int video_i2c_pm_runtime_suspend(struct device *dev)
 {
struct video_i2c_data *data = i2c_get_clientdata(to_i2c_client(dev));
 
+   if (!data->chip->set_power)
+   return 0;
+
return data->chip->set_power(data, false);
 }
 
@@ -811,6 +819,9 @@ static int video_i2c_pm_runtime_resume(struct device *dev)
 {
struct video_i2c_data *data = i2c_get_clientdata(to_i2c_client(dev));
 
+   if (!data->chip->set_power)
+   return 0;
+
return data->chip->set_power(data, true);
 }
 
-- 
2.17.1



[PATCH v2 0/2] media: video-i2c: add Melexis MLX90640 thermal camera support

2018-11-21 Thread Matt Ranostay
Add initial support for Melexis line of thermal cameras. This is the first part 
of
processing pipeline in which the real processing is done in userspace using the
V4L2 camera data.

Dependency patchset series: https://patchwork.kernel.org/cover/10650541/

Changes from v1:

* add melexis,mlx90640.txt documentation

Matt Ranostay (2):
  media: video-i2c: check if chip struct has set_power function
  media: video-i2c: add Melexis MLX90640 thermal camera support

 .../bindings/media/i2c/melexis,mlx90640.txt   |  20 +++
 drivers/media/i2c/Kconfig |   1 +
 drivers/media/i2c/video-i2c.c | 131 +-
 3 files changed, 146 insertions(+), 6 deletions(-)
 create mode 100644 
Documentation/devicetree/bindings/media/i2c/melexis,mlx90640.txt

-- 
2.17.1



[PATCH v2 2/2] media: video-i2c: add Melexis MLX90640 thermal camera support

2018-11-21 Thread Matt Ranostay
Add initial support for MLX90640 thermal cameras which output an 32x24
greyscale pixel image along with 2 rows of coefficent data.

Because of this the data outputed is really 32x26 and needs the two rows
removed after using the coefficent information to generate processed
images in userspace.

Cc: devicet...@vger.kernel.org
Signed-off-by: Matt Ranostay 
---
 .../bindings/media/i2c/melexis,mlx90640.txt   |  20 
 drivers/media/i2c/Kconfig |   1 +
 drivers/media/i2c/video-i2c.c | 110 +-
 3 files changed, 130 insertions(+), 1 deletion(-)
 create mode 100644 
Documentation/devicetree/bindings/media/i2c/melexis,mlx90640.txt

diff --git a/Documentation/devicetree/bindings/media/i2c/melexis,mlx90640.txt 
b/Documentation/devicetree/bindings/media/i2c/melexis,mlx90640.txt
new file mode 100644
index ..060d2b7a5893
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/i2c/melexis,mlx90640.txt
@@ -0,0 +1,20 @@
+* Melexis MLX90640 FIR Sensor
+
+Melexis MLX90640 FIR sensor support which allows recording of thermal data
+with 32x24 resolution excluding 2 lines of coefficient data that is used by
+userspace to render processed frames.
+
+Required Properties:
+ - compatible : Must be "melexis,mlx90640"
+ - reg : i2c address of the device
+
+Example:
+
+   i2c0@1c22000 {
+   ...
+   mlx90640@33 {
+   compatible = "melexis,mlx90640";
+   reg = <0x33>;
+   };
+   ...
+   };
diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index 66bbbec487ec..24342f283f2a 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -1097,6 +1097,7 @@ config VIDEO_I2C
  Enable the I2C transport video support which supports the
  following:
   * Panasonic AMG88xx Grid-Eye Sensors
+  * Melexis MLX90640 Thermal Cameras
 
  To compile this driver as a module, choose M here: the
  module will be called video-i2c
diff --git a/drivers/media/i2c/video-i2c.c b/drivers/media/i2c/video-i2c.c
index a64e1a725a20..d58f40334e8b 100644
--- a/drivers/media/i2c/video-i2c.c
+++ b/drivers/media/i2c/video-i2c.c
@@ -6,6 +6,7 @@
  *
  * Supported:
  * - Panasonic AMG88xx Grid-Eye Sensors
+ * - Melexis MLX90640 Thermal Cameras
  */
 
 #include 
@@ -18,6 +19,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -66,12 +68,26 @@ static const struct v4l2_frmsize_discrete amg88xx_size = {
.height = 8,
 };
 
+static const struct v4l2_fmtdesc mlx90640_format = {
+   .pixelformat = V4L2_PIX_FMT_Y16_BE,
+};
+
+static const struct v4l2_frmsize_discrete mlx90640_size = {
+   .width = 32,
+   .height = 26, /* 24 lines of pixel data + 2 lines of processing data */
+};
+
 static const struct regmap_config amg88xx_regmap_config = {
.reg_bits = 8,
.val_bits = 8,
.max_register = 0xff
 };
 
+static const struct regmap_config mlx90640_regmap_config = {
+   .reg_bits = 16,
+   .val_bits = 16,
+};
+
 struct video_i2c_chip {
/* video dimensions */
const struct v4l2_fmtdesc *format;
@@ -88,6 +104,7 @@ struct video_i2c_chip {
unsigned int bpp;
 
const struct regmap_config *regmap_config;
+   struct nvmem_config *nvmem_config;
 
/* setup function */
int (*setup)(struct video_i2c_data *data);
@@ -102,6 +119,22 @@ struct video_i2c_chip {
int (*hwmon_init)(struct video_i2c_data *data);
 };
 
+static int mlx90640_nvram_read(void *priv, unsigned int offset, void *val,
+size_t bytes)
+{
+   struct video_i2c_data *data = priv;
+
+   return regmap_bulk_read(data->regmap, 0x2400 + offset, val, bytes);
+}
+
+static struct nvmem_config mlx90640_nvram_config = {
+   .name = "mlx90640_nvram",
+   .word_size = 2,
+   .stride = 1,
+   .size = 1664,
+   .reg_read = mlx90640_nvram_read,
+};
+
 /* Power control register */
 #define AMG88XX_REG_PCTL   0x00
 #define AMG88XX_PCTL_NORMAL0x00
@@ -122,12 +155,23 @@ struct video_i2c_chip {
 /* Temperature register */
 #define AMG88XX_REG_T01L   0x80
 
+/* Control register */
+#define MLX90640_REG_CTL1  0x800d
+#define MLX90640_REG_CTL1_MASK 0x0380
+#define MLX90640_REG_CTL1_MASK_SHIFT   7
+
 static int amg88xx_xfer(struct video_i2c_data *data, char *buf)
 {
return regmap_bulk_read(data->regmap, AMG88XX_REG_T01L, buf,
data->chip->buffer_size);
 }
 
+static int mlx90640_xfer(struct video_i2c_data *data, char *buf)
+{
+   return regmap_bulk_read(data->regmap, 0x400, buf,
+   data->chip->buffer_size);
+}
+
 static int amg88xx_setup(struct video_i2c_data *data)
 {
unsigned int mask = AMG88XX_FPSC_1FPS;
@@ -141,6 +185,27 @@ static int amg88xx_setup(struct video_i2c_data *data)
return 

Re: [PATCHv2 0/9] vb2/cedrus: add tag support

2018-11-21 Thread Alexandre Courbot
On Wed, Nov 14, 2018 at 10:47 PM Hans Verkuil  wrote:
>
> From: Hans Verkuil 
>
> As was discussed here (among other places):
>
> https://lkml.org/lkml/2018/10/19/440
>
> using capture queue buffer indices to refer to reference frames is
> not a good idea. A better idea is to use a 'tag' where the
> application can assign a u64 tag to an output buffer, which is then
> copied to the capture buffer(s) derived from the output buffer.
>
> A u64 is chosen since this allows userspace to also use pointers to
> internal structures as 'tag'.
>
> The first three patches add core tag support, the next patch document
> the tag support, then a new helper function is added to v4l2-mem2mem.c
> to easily copy data from a source to a destination buffer that drivers
> can use.
>
> Next a new supports_tags vb2_queue flag is added to indicate that
> the driver supports tags. Ideally this should not be necessary, but
> that would require that all m2m drivers are converted to using the
> new helper function introduced in the previous patch. That takes more
> time then I have now since we want to get this in for 4.20.
>
> Finally the vim2m, vicodec and cedrus drivers are converted to support
> tags.
>
> I also removed the 'pad' fields from the mpeg2 control structs (it
> should never been added in the first place) and aligned the structs
> to a u32 boundary (u64 for the tag values).
>
> Note that this might change further (Paul suggested using bitfields).
>
> Also note that the cedrus code doesn't set the sequence counter, that's
> something that should still be added before this driver can be moved
> out of staging.
>
> Note: if no buffer is found for a certain tag, then the dma address
> is just set to 0. That happened before as well with invalid buffer
> indices. This should be checked in the driver!
>
> The previous RFC series was tested successfully with the cedrus driver.
>
> Regards,
>
> Hans
>
> Changes since v1:
>
> - changed to a u32 tag. Using a 64 bit tag was overly complicated due
>   to the bad layout of the v4l2_buffer struct, and there is no real
>   need for it by applications.
>
> Main changes since the RFC:
>
> - Added new buffer capability flag
> - Added m2m helper to copy data between buffers
> - Added documentation
> - Added tag logging in v4l2-ioctl.c
>
> Hans Verkuil (9):
>   videodev2.h: add tag support
>   vb2: add tag support
>   v4l2-ioctl.c: log v4l2_buffer tag
>   buffer.rst: document the new buffer tag feature.
>   v4l2-mem2mem: add v4l2_m2m_buf_copy_data helper function
>   vb2: add new supports_tags queue flag
>   vim2m: add tag support
>   vicodec: add tag support
>   cedrus: add tag support

Good call on the v4l2_m2m_buf_copy_data() function!

Reviewed-by: Alexandre Courbot 

>
>  Documentation/media/uapi/v4l/buffer.rst   | 32 +
>  .../media/uapi/v4l/vidioc-reqbufs.rst |  4 ++
>  .../media/common/videobuf2/videobuf2-v4l2.c   | 45 ---
>  drivers/media/platform/vicodec/vicodec-core.c | 14 ++
>  drivers/media/platform/vim2m.c| 14 ++
>  drivers/media/v4l2-core/v4l2-ctrls.c  |  9 
>  drivers/media/v4l2-core/v4l2-ioctl.c  |  9 ++--
>  drivers/media/v4l2-core/v4l2-mem2mem.c| 23 ++
>  drivers/staging/media/sunxi/cedrus/cedrus.h   |  9 ++--
>  .../staging/media/sunxi/cedrus/cedrus_dec.c   |  2 +
>  .../staging/media/sunxi/cedrus/cedrus_mpeg2.c | 21 -
>  .../staging/media/sunxi/cedrus/cedrus_video.c |  2 +
>  include/media/v4l2-mem2mem.h  | 21 +
>  include/media/videobuf2-core.h|  2 +
>  include/media/videobuf2-v4l2.h| 21 -
>  include/uapi/linux/v4l2-controls.h| 14 +++---
>  include/uapi/linux/videodev2.h|  9 +++-
>  17 files changed, 178 insertions(+), 73 deletions(-)
>
> --
> 2.19.1
>


is it possible to use single IOCTL to setup media pipeline?

2018-11-21 Thread Zhang, Ning A
Hello everyone

when we need to setup media pipeline, eg, for camera capture, media-ctl 
needs to be called multiple time to setup media link and subdev
formats, or similar code in a single application. this will use
multiple IOCTLs on "/dev/mediaX" and "/dev/v4l2-subdevY".

to setup media pipeline in userspace requires to fully understanding
the topology of the media stack. but the fact is only media driver
developer could know how to setup media pipeline. each time driver
updates, this would break userspace application if application
engineers don't know this change. In this case, if a IOCTL is designed
to setup media pipeline, no need to update applications, after driver
is updated.

this will not only benefit for design a single IOCTL, this also helps
to hide the detail of media pipeline, by load a binary blob which holds
information about how to setup pipeline, or hide it in bootloader/ACPI
tables/device tree, etc.

another benefit is save time for setup media pipeline, if there is a
PKI like "time for open camera". as my test, this will saves hundreds
of milliseconds.

is this acceptable?

BR.
Ning.

Re: [PATCH v8 04/12] media: staging/imx7: add MIPI CSI-2 receiver subdev for i.MX7

2018-11-21 Thread kbuild test robot
Hi Rui,

I love your patch! Perhaps something to improve:

[auto build test WARNING on linuxtv-media/master]
[also build test WARNING on v4.20-rc3 next-20181121]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improve the system]

url:
https://github.com/0day-ci/linux/commits/Rui-Miguel-Silva/media-staging-imx7-add-i-MX7-media-driver/20181122-024200
base:   git://linuxtv.org/media_tree.git master


coccinelle warnings: (new ones prefixed by >>)

>> drivers/staging/media/imx/imx7-mipi-csis.c:1125:3-8: No need to set .owner 
>> here. The core will do it.

Please review and possibly fold the followup patch.

---
0-DAY kernel test infrastructureOpen Source Technology Center
https://lists.01.org/pipermail/kbuild-all   Intel Corporation


[PATCH] media: staging/imx7: fix platform_no_drv_owner.cocci warnings

2018-11-21 Thread kbuild test robot
From: kbuild test robot 

drivers/staging/media/imx/imx7-mipi-csis.c:1125:3-8: No need to set .owner 
here. The core will do it.

 Remove .owner field if calls are used which set it automatically

Generated by: scripts/coccinelle/api/platform_no_drv_owner.cocci

Fixes: 181331ab8acb ("media: staging/imx7: add MIPI CSI-2 receiver subdev for 
i.MX7")
CC: Rui Miguel Silva 
Signed-off-by: kbuild test robot 
---

url:
https://github.com/0day-ci/linux/commits/Rui-Miguel-Silva/media-staging-imx7-add-i-MX7-media-driver/20181122-024200
base:   git://linuxtv.org/media_tree.git master

 imx7-mipi-csis.c |1 -
 1 file changed, 1 deletion(-)

--- a/drivers/staging/media/imx/imx7-mipi-csis.c
+++ b/drivers/staging/media/imx/imx7-mipi-csis.c
@@ -1122,7 +1122,6 @@ static struct platform_driver mipi_csis_
.driver = {
.of_match_table = mipi_csis_of_match,
.name   = CSIS_DRIVER_NAME,
-   .owner  = THIS_MODULE,
.pm = _csis_pm_ops,
},
 };


Re: [PATCH v8 01/12] media: staging/imx: refactor imx media device probe

2018-11-21 Thread kbuild test robot
Hi Rui,

I love your patch! Yet something to improve:

[auto build test ERROR on linuxtv-media/master]
[also build test ERROR on v4.20-rc3 next-20181121]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improve the system]

url:
https://github.com/0day-ci/linux/commits/Rui-Miguel-Silva/media-staging-imx7-add-i-MX7-media-driver/20181122-024200
base:   git://linuxtv.org/media_tree.git master
config: i386-allmodconfig (attached as .config)
compiler: gcc-7 (Debian 7.3.0-1) 7.3.0
reproduce:
# save the attached .config to linux build tree
make ARCH=i386 

All errors (new ones prefixed by >>):

>> make[5]: *** No rule to make target 
>> 'drivers/staging/media/imx/imx-media-dev-common.o', needed by 
>> 'drivers/staging/media/imx/imx-media.o'.
   make[5]: Target '__build' not remade because of errors.

---
0-DAY kernel test infrastructureOpen Source Technology Center
https://lists.01.org/pipermail/kbuild-all   Intel Corporation


.config.gz
Description: application/gzip


Re: [PATCH v8 03/12] media: staging/imx7: add imx7 CSI subdev driver

2018-11-21 Thread Sakari Ailus
Hi Rui,

On Wed, Nov 21, 2018 at 11:15:49AM +, Rui Miguel Silva wrote:
> This add the media entity subdevice and control driver for the i.MX7
> CMOS Sensor Interface.
> 
> Signed-off-by: Rui Miguel Silva 
> ---
>  drivers/staging/media/imx/Kconfig  |9 +-
>  drivers/staging/media/imx/Makefile |2 +
>  drivers/staging/media/imx/imx7-media-csi.c | 1352 
>  3 files changed, 1362 insertions(+), 1 deletion(-)
>  create mode 100644 drivers/staging/media/imx/imx7-media-csi.c
> 
> diff --git a/drivers/staging/media/imx/Kconfig 
> b/drivers/staging/media/imx/Kconfig
> index bfc17de56b17..40a11f988fc6 100644
> --- a/drivers/staging/media/imx/Kconfig
> +++ b/drivers/staging/media/imx/Kconfig
> @@ -11,7 +11,7 @@ config VIDEO_IMX_MEDIA
> driver for the i.MX5/6 SOC.
>  
>  if VIDEO_IMX_MEDIA
> -menu "i.MX5/6 Media Sub devices"
> +menu "i.MX5/6/7 Media Sub devices"
>  
>  config VIDEO_IMX_CSI
>   tristate "i.MX5/6 Camera Sensor Interface driver"
> @@ -20,5 +20,12 @@ config VIDEO_IMX_CSI
>   ---help---
> A video4linux camera sensor interface driver for i.MX5/6.
>  
> +config VIDEO_IMX7_CSI
> + tristate "i.MX7 Camera Sensor Interface driver"
> + depends on VIDEO_IMX_MEDIA && VIDEO_DEV && I2C

If you need V4L2 fwnode, you should select V4L2_FWNODE. (I ignore if it's
already selected by VIDEO_IMX_MEDIA.)

> + default y
> + ---help---
> +   A video4linux camera sensor interface driver for i.MX7.
> +
>  endmenu
>  endif
> diff --git a/drivers/staging/media/imx/Makefile 
> b/drivers/staging/media/imx/Makefile
> index a30b3033f9a3..074f016d3519 100644
> --- a/drivers/staging/media/imx/Makefile
> +++ b/drivers/staging/media/imx/Makefile
> @@ -12,3 +12,5 @@ obj-$(CONFIG_VIDEO_IMX_MEDIA) += imx-media-ic.o
>  
>  obj-$(CONFIG_VIDEO_IMX_CSI) += imx-media-csi.o
>  obj-$(CONFIG_VIDEO_IMX_CSI) += imx6-mipi-csi2.o
> +
> +obj-$(CONFIG_VIDEO_IMX7_CSI) += imx7-media-csi.o
> diff --git a/drivers/staging/media/imx/imx7-media-csi.c 
> b/drivers/staging/media/imx/imx7-media-csi.c
> new file mode 100644
> index ..ec5a20880bb6
> --- /dev/null
> +++ b/drivers/staging/media/imx/imx7-media-csi.c
> @@ -0,0 +1,1352 @@
> +// SPDX-License-Identifier: GPL
> +/*
> + * V4L2 Capture CSI Subdev for Freescale i.MX7 SOC
> + *
> + * Copyright (c) 2018 Linaro Ltd
> + *
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include 
> +#include "imx-media.h"
> +
> +#define IMX7_CSI_PAD_SINK0
> +#define IMX7_CSI_PAD_SRC 1
> +#define IMX7_CSI_PADS_NUM2
> +
> +/* reset values */
> +#define CSICR1_RESET_VAL 0x4800
> +#define CSICR2_RESET_VAL 0x0
> +#define CSICR3_RESET_VAL 0x0
> +
> +/* csi control reg 1 */
> +#define BIT_SWAP16_ENBIT(31)
> +#define BIT_EXT_VSYNCBIT(30)
> +#define BIT_EOF_INT_EN   BIT(29)
> +#define BIT_PRP_IF_ENBIT(28)
> +#define BIT_CCIR_MODEBIT(27)
> +#define BIT_COF_INT_EN   BIT(26)
> +#define BIT_SF_OR_INTEN  BIT(25)
> +#define BIT_RF_OR_INTEN  BIT(24)
> +#define BIT_SFF_DMA_DONE_INTEN  BIT(22)
> +#define BIT_STATFF_INTEN BIT(21)
> +#define BIT_FB2_DMA_DONE_INTEN  BIT(20)
> +#define BIT_FB1_DMA_DONE_INTEN  BIT(19)
> +#define BIT_RXFF_INTEN   BIT(18)
> +#define BIT_SOF_POL  BIT(17)
> +#define BIT_SOF_INTENBIT(16)
> +#define BIT_MCLKDIV  (0xF << 12)
> +#define BIT_HSYNC_POLBIT(11)
> +#define BIT_CCIR_EN  BIT(10)
> +#define BIT_MCLKEN   BIT(9)
> +#define BIT_FCC  BIT(8)
> +#define BIT_PACK_DIR BIT(7)
> +#define BIT_CLR_STATFIFO BIT(6)
> +#define BIT_CLR_RXFIFO   BIT(5)
> +#define BIT_GCLK_MODEBIT(4)
> +#define BIT_INV_DATA BIT(3)
> +#define BIT_INV_PCLK BIT(2)
> +#define BIT_REDGEBIT(1)
> +#define BIT_PIXEL_BITBIT(0)
> +
> +#define SHIFT_MCLKDIV12
> +
> +/* control reg 3 */
> +#define BIT_FRMCNT   (0x << 16)
> +#define BIT_FRMCNT_RST   BIT(15)
> +#define BIT_DMA_REFLASH_RFF  BIT(14)
> +#define BIT_DMA_REFLASH_SFF  BIT(13)
> +#define BIT_DMA_REQ_EN_RFF   BIT(12)
> +#define BIT_DMA_REQ_EN_SFF   BIT(11)
> +#define BIT_STATFF_LEVEL (0x7 << 8)
> +#define BIT_HRESP_ERR_EN BIT(7)
> +#define BIT_RXFF_LEVEL   (0x7 << 4)
> +#define BIT_TWO_8BIT_SENSOR  BIT(3)
> +#define BIT_ZERO_PACK_EN BIT(2)
> +#define BIT_ECC_INT_EN   BIT(1)
> +#define BIT_ECC_AUTO_EN  BIT(0)
> +
> +#define SHIFT_FRMCNT 16
> +#define SHIFT_RXFIFO_LEVEL   4
> +
> +/* csi status reg */
> +#define BIT_ADDR_CH_ERR_INT  BIT(28)
> +#define BIT_FIELD0_INT   BIT(27)
> 

Re: [PATCH v8 05/12] media: dt-bindings: add bindings for i.MX7 media driver

2018-11-21 Thread Sakari Ailus
Hi Rui,

On Wed, Nov 21, 2018 at 11:15:51AM +, Rui Miguel Silva wrote:
> Add bindings documentation for i.MX7 media drivers.
> The imx7 MIPI CSI2 and imx7 CMOS Sensor Interface.
> 
> Signed-off-by: Rui Miguel Silva 
> Reviewed-by: Rob Herring 
> Acked-by: Sakari Ailus 
> ---
>  .../devicetree/bindings/media/imx7-csi.txt| 45 ++
>  .../bindings/media/imx7-mipi-csi2.txt | 90 +++
>  2 files changed, 135 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/media/imx7-csi.txt
>  create mode 100644 Documentation/devicetree/bindings/media/imx7-mipi-csi2.txt
> 
> diff --git a/Documentation/devicetree/bindings/media/imx7-csi.txt 
> b/Documentation/devicetree/bindings/media/imx7-csi.txt
> new file mode 100644
> index ..171b089ee91f
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/media/imx7-csi.txt
> @@ -0,0 +1,45 @@
> +Freescale i.MX7 CMOS Sensor Interface
> +=
> +
> +csi node
> +
> +
> +This is device node for the CMOS Sensor Interface (CSI) which enables the 
> chip
> +to connect directly to external CMOS image sensors.
> +
> +Required properties:
> +
> +- compatible: "fsl,imx7-csi";
> +- reg   : base address and length of the register set for the device;
> +- interrupts: should contain CSI interrupt;
> +- clocks: list of clock specifiers, see
> +Documentation/devicetree/bindings/clock/clock-bindings.txt for 
> details;
> +- clock-names   : must contain "axi", "mclk" and "dcic" entries, matching
> + entries in the clock property;
> +
> +The device node shall contain one 'port' child node with one child 'endpoint'
> +node, according to the bindings defined in:
> + Documentation/devicetree/bindings/media/video-interfaces.txt.
> + 
> +In the following example a remote endpoint is a video multiplexer.
> +
> +example:
> +
> +csi: csi@3071 {
> +#address-cells = <1>;
> +#size-cells = <0>;
> +
> +compatible = "fsl,imx7-csi";
> +reg = <0x3071 0x1>;
> +interrupts = ;
> +clocks = < IMX7D_CLK_DUMMY>,
> +< IMX7D_CSI_MCLK_ROOT_CLK>,
> +< IMX7D_CLK_DUMMY>;
> +clock-names = "axi", "mclk", "dcic";
> +
> +port {
> +csi_from_csi_mux: endpoint {
> +remote-endpoint = <_mux_to_csi>;
> +};
> +};
> +};
> diff --git a/Documentation/devicetree/bindings/media/imx7-mipi-csi2.txt 
> b/Documentation/devicetree/bindings/media/imx7-mipi-csi2.txt
> new file mode 100644
> index ..71fd74ed3ec8
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/media/imx7-mipi-csi2.txt
> @@ -0,0 +1,90 @@
> +Freescale i.MX7 Mipi CSI2
> +=
> +
> +mipi_csi2 node
> +--
> +
> +This is the device node for the MIPI CSI-2 receiver core in i.MX7 SoC. It is
> +compatible with previous version of Samsung D-phy.
> +
> +Required properties:
> +
> +- compatible: "fsl,imx7-mipi-csi2";
> +- reg   : base address and length of the register set for the device;
> +- interrupts: should contain MIPI CSIS interrupt;
> +- clocks: list of clock specifiers, see
> +Documentation/devicetree/bindings/clock/clock-bindings.txt for 
> details;
> +- clock-names   : must contain "pclk", "wrap" and "phy" entries, matching
> +  entries in the clock property;
> +- power-domains : a phandle to the power domain, see
> +  Documentation/devicetree/bindings/power/power_domain.txt for 
> details.
> +- reset-names   : should include following entry "mrst";
> +- resets: a list of phandle, should contain reset entry of
> +  reset-names;
> +- phy-supply: from the generic phy bindings, a phandle to a regulator 
> that
> +   provides power to MIPI CSIS core;
> +
> +Optional properties:
> +
> +- clock-frequency : The IP's main (system bus) clock frequency in Hz, default
> + value when this property is not specified is 166 MHz;
> +- fsl,csis-hs-settle : differential receiver (HS-RX) settle time;
> +
> +The device node should contain two 'port' child nodes with one child 
> 'endpoint'
> +node, according to the bindings defined in:
> + Documentation/devicetree/bindings/ media/video-interfaces.txt.

Extra space. The two lines are also prefixed by a space; is that intended?

> + The following are properties specific to those nodes.
> +
> +port node
> +-
> +
> +- reg  : (required) can take the values 0 or 1, where 0 
> shall be
> + related to the sink port and port 1 shall be the source
> + 

[PATCH v10 4/4] media: add Rockchip VPU JPEG encoder driver

2018-11-21 Thread Ezequiel Garcia
Add a mem2mem driver for the VPU available on Rockchip SoCs.
Currently only JPEG encoding is supported, for RK3399 and RK3288
platforms.

Signed-off-by: Ezequiel Garcia 
---
 MAINTAINERS   |   7 +
 drivers/staging/media/Kconfig |   2 +
 drivers/staging/media/Makefile|   1 +
 drivers/staging/media/rockchip/vpu/Kconfig|  13 +
 drivers/staging/media/rockchip/vpu/Makefile   |  10 +
 drivers/staging/media/rockchip/vpu/TODO   |   6 +
 .../media/rockchip/vpu/rk3288_vpu_hw.c| 118 +++
 .../rockchip/vpu/rk3288_vpu_hw_jpeg_enc.c | 133 
 .../media/rockchip/vpu/rk3288_vpu_regs.h  | 442 +++
 .../media/rockchip/vpu/rk3399_vpu_hw.c| 118 +++
 .../rockchip/vpu/rk3399_vpu_hw_jpeg_enc.c | 160 
 .../media/rockchip/vpu/rk3399_vpu_regs.h  | 600 +++
 .../staging/media/rockchip/vpu/rockchip_vpu.h | 237 ++
 .../media/rockchip/vpu/rockchip_vpu_common.h  |  29 +
 .../media/rockchip/vpu/rockchip_vpu_drv.c | 535 +
 .../media/rockchip/vpu/rockchip_vpu_enc.c | 702 ++
 .../media/rockchip/vpu/rockchip_vpu_hw.h  |  58 ++
 .../media/rockchip/vpu/rockchip_vpu_jpeg.c| 290 
 .../media/rockchip/vpu/rockchip_vpu_jpeg.h|  14 +
 19 files changed, 3475 insertions(+)
 create mode 100644 drivers/staging/media/rockchip/vpu/Kconfig
 create mode 100644 drivers/staging/media/rockchip/vpu/Makefile
 create mode 100644 drivers/staging/media/rockchip/vpu/TODO
 create mode 100644 drivers/staging/media/rockchip/vpu/rk3288_vpu_hw.c
 create mode 100644 drivers/staging/media/rockchip/vpu/rk3288_vpu_hw_jpeg_enc.c
 create mode 100644 drivers/staging/media/rockchip/vpu/rk3288_vpu_regs.h
 create mode 100644 drivers/staging/media/rockchip/vpu/rk3399_vpu_hw.c
 create mode 100644 drivers/staging/media/rockchip/vpu/rk3399_vpu_hw_jpeg_enc.c
 create mode 100644 drivers/staging/media/rockchip/vpu/rk3399_vpu_regs.h
 create mode 100644 drivers/staging/media/rockchip/vpu/rockchip_vpu.h
 create mode 100644 drivers/staging/media/rockchip/vpu/rockchip_vpu_common.h
 create mode 100644 drivers/staging/media/rockchip/vpu/rockchip_vpu_drv.c
 create mode 100644 drivers/staging/media/rockchip/vpu/rockchip_vpu_enc.c
 create mode 100644 drivers/staging/media/rockchip/vpu/rockchip_vpu_hw.h
 create mode 100644 drivers/staging/media/rockchip/vpu/rockchip_vpu_jpeg.c
 create mode 100644 drivers/staging/media/rockchip/vpu/rockchip_vpu_jpeg.h

diff --git a/MAINTAINERS b/MAINTAINERS
index a8588dedc683..e5a294453393 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -12742,6 +12742,13 @@ S: Maintained
 F: drivers/media/platform/rockchip/rga/
 F: Documentation/devicetree/bindings/media/rockchip-rga.txt
 
+ROCKCHIP VPU CODEC DRIVER
+M: Ezequiel Garcia 
+L: linux-media@vger.kernel.org
+S: Maintained
+F: drivers/staging/media/platform/rockchip/vpu/
+F: Documentation/devicetree/bindings/media/rockchip-vpu.txt
+
 ROCKER DRIVER
 M: Jiri Pirko 
 L: net...@vger.kernel.org
diff --git a/drivers/staging/media/Kconfig b/drivers/staging/media/Kconfig
index b3620a8f2d9f..c6f3404dea43 100644
--- a/drivers/staging/media/Kconfig
+++ b/drivers/staging/media/Kconfig
@@ -31,6 +31,8 @@ source "drivers/staging/media/mt9t031/Kconfig"
 
 source "drivers/staging/media/omap4iss/Kconfig"
 
+source "drivers/staging/media/rockchip/vpu/Kconfig"
+
 source "drivers/staging/media/sunxi/Kconfig"
 
 source "drivers/staging/media/tegra-vde/Kconfig"
diff --git a/drivers/staging/media/Makefile b/drivers/staging/media/Makefile
index 42948f805548..43c7bee1fc8c 100644
--- a/drivers/staging/media/Makefile
+++ b/drivers/staging/media/Makefile
@@ -8,3 +8,4 @@ obj-$(CONFIG_VIDEO_OMAP4)   += omap4iss/
 obj-$(CONFIG_VIDEO_SUNXI)  += sunxi/
 obj-$(CONFIG_TEGRA_VDE)+= tegra-vde/
 obj-$(CONFIG_VIDEO_ZORAN)  += zoran/
+obj-$(CONFIG_VIDEO_ROCKCHIP_VPU) += rockchip/vpu/
diff --git a/drivers/staging/media/rockchip/vpu/Kconfig 
b/drivers/staging/media/rockchip/vpu/Kconfig
new file mode 100644
index ..9a6fc1378242
--- /dev/null
+++ b/drivers/staging/media/rockchip/vpu/Kconfig
@@ -0,0 +1,13 @@
+config VIDEO_ROCKCHIP_VPU
+   tristate "Rockchip VPU driver"
+   depends on ARCH_ROCKCHIP || COMPILE_TEST
+   depends on VIDEO_DEV && VIDEO_V4L2 && MEDIA_CONTROLLER
+   select VIDEOBUF2_DMA_CONTIG
+   select VIDEOBUF2_VMALLOC
+   select V4L2_MEM2MEM_DEV
+   default n
+   help
+ Support for the Video Processing Unit present on Rockchip SoC,
+ which accelerates video and image encoding and decoding.
+ To compile this driver as a module, choose M here: the module
+ will be called rockchip-vpu.
diff --git a/drivers/staging/media/rockchip/vpu/Makefile 
b/drivers/staging/media/rockchip/vpu/Makefile
new file mode 100644
index ..e9d733bb7632
--- /dev/null
+++ b/drivers/staging/media/rockchip/vpu/Makefile
@@ -0,0 +1,10 @@

[PATCH v10 3/4] arm64: dts: rockchip: add VPU device node for RK3399

2018-11-21 Thread Ezequiel Garcia
Add the Video Processing Unit node for the RK3399 SoC.

Also, fix the VPU IOMMU node, which was disabled and lacking
its power domain property.

Signed-off-by: Ezequiel Garcia 
---
 arch/arm64/boot/dts/rockchip/rk3399.dtsi | 14 +-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/arch/arm64/boot/dts/rockchip/rk3399.dtsi 
b/arch/arm64/boot/dts/rockchip/rk3399.dtsi
index 99e7f65c1779..040d3080565f 100644
--- a/arch/arm64/boot/dts/rockchip/rk3399.dtsi
+++ b/arch/arm64/boot/dts/rockchip/rk3399.dtsi
@@ -1226,6 +1226,18 @@
status = "disabled";
};
 
+   vpu: video-codec@ff65 {
+   compatible = "rockchip,rk3399-vpu";
+   reg = <0x0 0xff65 0x0 0x800>;
+   interrupts = ,
+;
+   interrupt-names = "vepu", "vdpu";
+   clocks = < ACLK_VCODEC>, < HCLK_VCODEC>;
+   clock-names = "aclk", "hclk";
+   power-domains = < RK3399_PD_VCODEC>;
+   iommus = <_mmu>;
+   };
+
vpu_mmu: iommu@ff650800 {
compatible = "rockchip,iommu";
reg = <0x0 0xff650800 0x0 0x40>;
@@ -1233,8 +1245,8 @@
interrupt-names = "vpu_mmu";
clocks = < ACLK_VCODEC>, < HCLK_VCODEC>;
clock-names = "aclk", "iface";
+   power-domains = < RK3399_PD_VCODEC>;
#iommu-cells = <0>;
-   status = "disabled";
};
 
vdec_mmu: iommu@ff660480 {
-- 
2.19.1



[PATCH v10 0/4] Add Rockchip VPU JPEG encoder

2018-11-21 Thread Ezequiel Garcia
This series is based on Mauro's master branch,
with the following patch applied:

https://patchwork.kernel.org/patch/10676149/

Hans,

If you think the driver is now ready, I'd like to merge
only patches 1/4 and 4/4 (the driver per-se) via the media tree.

The devicetree changes could go via Heiko's tree.

v10:
 * Fix SPDX syntax
 * Add missing patch with binding documentation
 * Remove white line in Kconfig

v9:
 * Address some style comments from Hans.
 * Fix TODO file

v8:
 * Drop new JPEG_RAW format.
 * Drop quantization table user controls.
 * Add JPEG headers to produce JPEG frames.

Ezequiel Garcia (4):
  media: dt-bindings: Document the Rockchip VPU bindings
  ARM: dts: rockchip: add VPU device node for RK3288
  arm64: dts: rockchip: add VPU device node for RK3399
  media: add Rockchip VPU JPEG encoder driver

 .../bindings/media/rockchip-vpu.txt   |  29 +
 MAINTAINERS   |   7 +
 arch/arm/boot/dts/rk3288.dtsi |  14 +-
 arch/arm64/boot/dts/rockchip/rk3399.dtsi  |  14 +-
 drivers/staging/media/Kconfig |   2 +
 drivers/staging/media/Makefile|   1 +
 drivers/staging/media/rockchip/vpu/Kconfig|  13 +
 drivers/staging/media/rockchip/vpu/Makefile   |  10 +
 drivers/staging/media/rockchip/vpu/TODO   |   6 +
 .../media/rockchip/vpu/rk3288_vpu_hw.c| 118 +++
 .../rockchip/vpu/rk3288_vpu_hw_jpeg_enc.c | 133 
 .../media/rockchip/vpu/rk3288_vpu_regs.h  | 442 +++
 .../media/rockchip/vpu/rk3399_vpu_hw.c| 118 +++
 .../rockchip/vpu/rk3399_vpu_hw_jpeg_enc.c | 160 
 .../media/rockchip/vpu/rk3399_vpu_regs.h  | 600 +++
 .../staging/media/rockchip/vpu/rockchip_vpu.h | 237 ++
 .../media/rockchip/vpu/rockchip_vpu_common.h  |  29 +
 .../media/rockchip/vpu/rockchip_vpu_drv.c | 535 +
 .../media/rockchip/vpu/rockchip_vpu_enc.c | 702 ++
 .../media/rockchip/vpu/rockchip_vpu_hw.h  |  58 ++
 .../media/rockchip/vpu/rockchip_vpu_jpeg.c| 290 
 .../media/rockchip/vpu/rockchip_vpu_jpeg.h|  14 +
 22 files changed, 3530 insertions(+), 2 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/media/rockchip-vpu.txt
 create mode 100644 drivers/staging/media/rockchip/vpu/Kconfig
 create mode 100644 drivers/staging/media/rockchip/vpu/Makefile
 create mode 100644 drivers/staging/media/rockchip/vpu/TODO
 create mode 100644 drivers/staging/media/rockchip/vpu/rk3288_vpu_hw.c
 create mode 100644 drivers/staging/media/rockchip/vpu/rk3288_vpu_hw_jpeg_enc.c
 create mode 100644 drivers/staging/media/rockchip/vpu/rk3288_vpu_regs.h
 create mode 100644 drivers/staging/media/rockchip/vpu/rk3399_vpu_hw.c
 create mode 100644 drivers/staging/media/rockchip/vpu/rk3399_vpu_hw_jpeg_enc.c
 create mode 100644 drivers/staging/media/rockchip/vpu/rk3399_vpu_regs.h
 create mode 100644 drivers/staging/media/rockchip/vpu/rockchip_vpu.h
 create mode 100644 drivers/staging/media/rockchip/vpu/rockchip_vpu_common.h
 create mode 100644 drivers/staging/media/rockchip/vpu/rockchip_vpu_drv.c
 create mode 100644 drivers/staging/media/rockchip/vpu/rockchip_vpu_enc.c
 create mode 100644 drivers/staging/media/rockchip/vpu/rockchip_vpu_hw.h
 create mode 100644 drivers/staging/media/rockchip/vpu/rockchip_vpu_jpeg.c
 create mode 100644 drivers/staging/media/rockchip/vpu/rockchip_vpu_jpeg.h

-- 
2.19.1



[PATCH v10 1/4] media: dt-bindings: Document the Rockchip VPU bindings

2018-11-21 Thread Ezequiel Garcia
Add devicetree binding documentation for Rockchip Video Processing
Unit IP.

Reviewed-by: Rob Herring 
Signed-off-by: Ezequiel Garcia 
---
 .../bindings/media/rockchip-vpu.txt   | 29 +++
 1 file changed, 29 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/rockchip-vpu.txt

diff --git a/Documentation/devicetree/bindings/media/rockchip-vpu.txt 
b/Documentation/devicetree/bindings/media/rockchip-vpu.txt
new file mode 100644
index ..35dc464ad7c8
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/rockchip-vpu.txt
@@ -0,0 +1,29 @@
+device-tree bindings for rockchip VPU codec
+
+Rockchip (Video Processing Unit) present in various Rockchip platforms,
+such as RK3288 and RK3399.
+
+Required properties:
+- compatible: value should be one of the following
+   "rockchip,rk3288-vpu";
+   "rockchip,rk3399-vpu";
+- interrupts: encoding and decoding interrupt specifiers
+- interrupt-names: should be "vepu" and "vdpu"
+- clocks: phandle to VPU aclk, hclk clocks
+- clock-names: should be "aclk" and "hclk"
+- power-domains: phandle to power domain node
+- iommus: phandle to a iommu node
+
+Example:
+SoC-specific DT entry:
+   vpu: video-codec@ff9a {
+   compatible = "rockchip,rk3288-vpu";
+   reg = <0x0 0xff9a 0x0 0x800>;
+   interrupts = ,
+;
+   interrupt-names = "vepu", "vdpu";
+   clocks = < ACLK_VCODEC>, < HCLK_VCODEC>;
+   clock-names = "aclk", "hclk";
+   power-domains = < RK3288_PD_VIDEO>;
+   iommus = <_mmu>;
+   };
-- 
2.19.1



[PATCH v10 2/4] ARM: dts: rockchip: add VPU device node for RK3288

2018-11-21 Thread Ezequiel Garcia
Add the Video Processing Unit node for RK3288 SoC.

Fix the VPU IOMMU node, which was disabled and lacking
its power domain property.

Signed-off-by: Ezequiel Garcia 
---
 arch/arm/boot/dts/rk3288.dtsi | 14 +-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/arch/arm/boot/dts/rk3288.dtsi b/arch/arm/boot/dts/rk3288.dtsi
index 0840ffb3205c..40d203cdca09 100644
--- a/arch/arm/boot/dts/rk3288.dtsi
+++ b/arch/arm/boot/dts/rk3288.dtsi
@@ -1223,6 +1223,18 @@
};
};
 
+   vpu: video-codec@ff9a {
+   compatible = "rockchip,rk3288-vpu";
+   reg = <0x0 0xff9a 0x0 0x800>;
+   interrupts = ,
+;
+   interrupt-names = "vepu", "vdpu";
+   clocks = < ACLK_VCODEC>, < HCLK_VCODEC>;
+   clock-names = "aclk", "hclk";
+   power-domains = < RK3288_PD_VIDEO>;
+   iommus = <_mmu>;
+   };
+
vpu_mmu: iommu@ff9a0800 {
compatible = "rockchip,iommu";
reg = <0x0 0xff9a0800 0x0 0x100>;
@@ -1230,8 +1242,8 @@
interrupt-names = "vpu_mmu";
clocks = < ACLK_VCODEC>, < HCLK_VCODEC>;
clock-names = "aclk", "iface";
+   power-domains = < RK3288_PD_VIDEO>;
#iommu-cells = <0>;
-   status = "disabled";
};
 
hevc_mmu: iommu@ff9c0440 {
-- 
2.19.1



[PATCH 1/1] v4l: uAPI doc: Changing frame interval won't change format

2018-11-21 Thread Sakari Ailus
Document that changing the frame interval has no effect on frame size.
While this was the assumption in the API, it was not documented as such.

Signed-off-by: Sakari Ailus 
---
 Documentation/media/uapi/v4l/vidioc-g-parm.rst  | 3 +++
 Documentation/media/uapi/v4l/vidioc-subdev-g-frame-interval.rst | 3 +++
 2 files changed, 6 insertions(+)

diff --git a/Documentation/media/uapi/v4l/vidioc-g-parm.rst 
b/Documentation/media/uapi/v4l/vidioc-g-parm.rst
index e831fa5512f0..c31585a7701b 100644
--- a/Documentation/media/uapi/v4l/vidioc-g-parm.rst
+++ b/Documentation/media/uapi/v4l/vidioc-g-parm.rst
@@ -42,6 +42,9 @@ side. This is especially useful when using the :ref:`read() 
` or
 :ref:`write() `, which are not augmented by timestamps or sequence
 counters, and to avoid unnecessary data copying.
 
+Changing the frame interval shall never change the format. Changing the
+format, on the other hand, may change the frame interval.
+
 Further these ioctls can be used to determine the number of buffers used
 internally by a driver in read/write mode. For implications see the
 section discussing the :ref:`read() ` function.
diff --git a/Documentation/media/uapi/v4l/vidioc-subdev-g-frame-interval.rst 
b/Documentation/media/uapi/v4l/vidioc-subdev-g-frame-interval.rst
index 5af0a7179941..f889c20f231c 100644
--- a/Documentation/media/uapi/v4l/vidioc-subdev-g-frame-interval.rst
+++ b/Documentation/media/uapi/v4l/vidioc-subdev-g-frame-interval.rst
@@ -63,6 +63,9 @@ doesn't match the device capabilities. They must instead 
modify the
 interval to match what the hardware can provide. The modified interval
 should be as close as possible to the original request.
 
+Changing the frame interval shall never change the format. Changing the
+format, on the other hand, may change the frame interval.
+
 Sub-devices that support the frame interval ioctls should implement them
 on a single pad only. Their behaviour when supported on multiple pads of
 the same sub-device is not defined.
-- 
2.11.0



[RFCv4 PATCH 3/3] vimc: add property test code

2018-11-21 Thread Hans Verkuil
From: Hans Verkuil 

Add properties to entities and pads to be able to test the
properties API.

Signed-off-by: Hans Verkuil 
---
 drivers/media/platform/vimc/vimc-common.c | 50 +++
 1 file changed, 50 insertions(+)

diff --git a/drivers/media/platform/vimc/vimc-common.c 
b/drivers/media/platform/vimc/vimc-common.c
index dee1b9dfc4f6..2f70e4e64790 100644
--- a/drivers/media/platform/vimc/vimc-common.c
+++ b/drivers/media/platform/vimc/vimc-common.c
@@ -415,6 +415,7 @@ int vimc_ent_sd_register(struct vimc_ent_device *ved,
 const unsigned long *pads_flag,
 const struct v4l2_subdev_ops *sd_ops)
 {
+   struct media_prop *prop = NULL;
int ret;
 
/* Allocate the pads */
@@ -452,6 +453,55 @@ int vimc_ent_sd_register(struct vimc_ent_device *ved,
goto err_clean_m_ent;
}
 
+   ret = media_entity_add_prop_u64(>entity, "u64", ~1);
+   if (!ret)
+   ret = media_entity_add_prop_s64(>entity, "s64", -5);
+   if (!ret)
+   ret = media_entity_add_prop_string(>entity, "string",
+  sd->name);
+   if (!ret) {
+   prop = media_entity_add_prop_group(>entity, "empty-group");
+   ret = PTR_ERR_OR_ZERO(prop);
+   }
+   if (!ret) {
+   prop = media_entity_add_prop_group(>entity, "group");
+   ret = PTR_ERR_OR_ZERO(prop);
+   }
+   if (!ret)
+   ret = media_prop_add_prop_u64(prop, "u64", 42);
+   if (!ret)
+   ret = media_prop_add_prop_s64(prop, "s64", -42);
+   if (!ret)
+   ret = media_prop_add_prop_string(prop, "string", "42");
+   if (!ret)
+   ret = media_pad_add_prop_u64(>entity.pads[num_pads - 1],
+"u64", ~1);
+   if (!ret)
+   ret = media_pad_add_prop_s64(>entity.pads[num_pads - 1],
+"s64", -5);
+   if (!ret) {
+   prop = media_pad_add_prop_group(>entity.pads[num_pads - 1],
+   "group");
+   ret = PTR_ERR_OR_ZERO(prop);
+   }
+   if (!ret)
+   ret = media_prop_add_prop_u64(prop, "u64", 24);
+   if (!ret)
+   ret = media_prop_add_prop_s64(prop, "s64", -24);
+   if (!ret)
+   ret = media_pad_add_prop_string(>entity.pads[0],
+   "string", sd->name);
+   if (!ret)
+   ret = media_prop_add_prop_string(prop, "string", "24");
+   if (!ret) {
+   prop = media_prop_add_prop_group(prop, "subgroup");
+   ret = PTR_ERR_OR_ZERO(prop);
+   }
+   if (!ret)
+   ret = media_prop_add_prop_string(prop, "string", "substring");
+   if (ret)
+   goto err_clean_m_ent;
+
return 0;
 
 err_clean_m_ent:
-- 
2.19.1



[RFCv4 PATCH 0/3] This RFC patch series implements properties for the media controller.

2018-11-21 Thread Hans Verkuil
The main changes since RFCv3 are:

- Add entity index to media_v2_pad
- Add source/sink pad index to media_v2_link
- Add owner_idx and owner type flags to media_v2_prop

An updated v4l2-ctl and v4l2-compliance that can report properties
is available here:

https://git.linuxtv.org/hverkuil/v4l-utils.git/log/?h=props

Currently I support u64, s64 and const char * property types. And also
a 'group' type that groups sub-properties. But it can be extended to any
type including binary data if needed. No array support (as we have for
controls), but there are enough reserved fields in media_v2_prop
to add this if needed.

I added properties for entities and pads to vimc, so I could test this.

Note that the changes to media_device_get_topology() are hard to read
from the patch. It is easier to just look at the source code:

https://git.linuxtv.org/hverkuil/media_tree.git/tree/drivers/media/media-device.c?h=mc-props

I have some ideas to improve this some more:

1) Add the properties directly to media_gobj. This would simplify some
   of the code, but it would require a media_gobj_init function to
   initialize the property list. In general I am a bit unhappy about
   media_gobj_create: it doesn't really create the graph object, instead
   it just adds it to the media_device. It's confusing and it is something
   I would like to change.

2) The links between pads are stored in media_entity instead of in media_pad.
   This is a bit unexpected and makes it harder to traverse the data
   structures since to find the links for a pad you need to walk the entity
   links and find the links for that pad. Putting all links in the entity
   also mixes up pad and interface links, and it would be much cleaner if
   those are separated.

3) I still think adding support for backlinks to G_TOPOLOGY is a good idea.
   Since the current data structure represents a flattened tree that is easy
   to navigate the only thing missing for userspace is backlink support.
   This is still something that userspace needs to figure out when the kernel
   has this readily available. I think that with this in place applications
   can just do all the lookups directly on the topology data structure.

1+2 are internal cleanups that can be done later.

3 is a low-priority future enhancement. This might become easier to implement
once 1+2 are done.

This is pretty much the last RFC. If everyone agree with this approach, then
I can make a final patch series, adding documentation etc.

Regards,

Hans


Hans Verkuil (3):
  uapi/linux/media.h: add property support
  media controller: add properties support
  vimc: add property test code

 drivers/media/media-device.c  | 335 +-
 drivers/media/media-entity.c  | 107 ++-
 drivers/media/platform/vimc/vimc-common.c |  50 
 include/media/media-device.h  |   6 +
 include/media/media-entity.h  | 318 
 include/uapi/linux/media.h|  88 +-
 6 files changed, 819 insertions(+), 85 deletions(-)

-- 
2.19.1



[RFCv4 PATCH 1/3] uapi/linux/media.h: add property support

2018-11-21 Thread Hans Verkuil
From: Hans Verkuil 

Add a new topology struct that includes properties and adds
index fields to quickly find references from one object to
another in the topology arrays.

Signed-off-by: Hans Verkuil 
---
 include/uapi/linux/media.h | 88 --
 1 file changed, 84 insertions(+), 4 deletions(-)

diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
index e5d0c5c611b5..a81e9723204c 100644
--- a/include/uapi/linux/media.h
+++ b/include/uapi/linux/media.h
@@ -144,6 +144,8 @@ struct media_device_info {
 /* Entity flags */
 #define MEDIA_ENT_FL_DEFAULT   (1 << 0)
 #define MEDIA_ENT_FL_CONNECTOR (1 << 1)
+#define MEDIA_ENT_FL_PAD_IDX   (1 << 2)
+#define MEDIA_ENT_FL_PROP_IDX  (1 << 3)
 
 /* OR with the entity id value to find the next entity */
 #define MEDIA_ENT_ID_FLAG_NEXT (1 << 31)
@@ -210,6 +212,9 @@ struct media_entity_desc {
 #define MEDIA_PAD_FL_SINK  (1 << 0)
 #define MEDIA_PAD_FL_SOURCE(1 << 1)
 #define MEDIA_PAD_FL_MUST_CONNECT  (1 << 2)
+#define MEDIA_PAD_FL_LINK_IDX  (1 << 3)
+#define MEDIA_PAD_FL_PROP_IDX  (1 << 4)
+#define MEDIA_PAD_FL_ENTITY_IDX(1 << 5)
 
 struct media_pad_desc {
__u32 entity;   /* entity ID */
@@ -221,6 +226,8 @@ struct media_pad_desc {
 #define MEDIA_LNK_FL_ENABLED   (1 << 0)
 #define MEDIA_LNK_FL_IMMUTABLE (1 << 1)
 #define MEDIA_LNK_FL_DYNAMIC   (1 << 2)
+#define MEDIA_LNK_FL_SOURCE_IDX(1 << 3)
+#define MEDIA_LNK_FL_SINK_IDX  (1 << 4)
 
 #define MEDIA_LNK_FL_LINK_TYPE (0xf << 28)
 #  define MEDIA_LNK_FL_DATA_LINK   (0 << 28)
@@ -296,7 +303,9 @@ struct media_v2_entity {
char name[64];
__u32 function; /* Main function of the entity */
__u32 flags;
-   __u32 reserved[5];
+   __u16 pad_idx;
+   __u16 prop_idx;
+   __u32 reserved[4];
 } __attribute__ ((packed));
 
 /* Should match the specific fields at media_intf_devnode */
@@ -305,11 +314,14 @@ struct media_v2_intf_devnode {
__u32 minor;
 } __attribute__ ((packed));
 
+#define MEDIA_INTF_FL_LINK_IDX (1 << 0)
+
 struct media_v2_interface {
__u32 id;
__u32 intf_type;
__u32 flags;
-   __u32 reserved[9];
+   __u16 link_idx;
+   __u16 reserved[17];
 
union {
struct media_v2_intf_devnode devnode;
@@ -331,7 +343,10 @@ struct media_v2_pad {
__u32 entity_id;
__u32 flags;
__u32 index;
-   __u32 reserved[4];
+   __u16 link_idx;
+   __u16 prop_idx;
+   __u16 entity_idx;
+   __u16 reserved[5];
 } __attribute__ ((packed));
 
 struct media_v2_link {
@@ -339,9 +354,68 @@ struct media_v2_link {
__u32 source_id;
__u32 sink_id;
__u32 flags;
-   __u32 reserved[6];
+   __u16 source_idx;
+   __u16 sink_idx;
+   __u32 reserved[5];
 } __attribute__ ((packed));
 
+#define MEDIA_PROP_TYPE_GROUP  1
+#define MEDIA_PROP_TYPE_U642
+#define MEDIA_PROP_TYPE_S643
+#define MEDIA_PROP_TYPE_STRING 4
+
+#define MEDIA_PROP_FL_OWNER0xf
+#  define MEDIA_PROP_FL_ENTITY 0
+#  define MEDIA_PROP_FL_PAD1
+#  define MEDIA_PROP_FL_LINK   2
+#  define MEDIA_PROP_FL_INTF   3
+#  define MEDIA_PROP_FL_PROP   4
+#define MEDIA_PROP_FL_PROP_IDX (1 << 4)
+
+/**
+ * struct media_v2_prop - A media property
+ *
+ * @id:The unique non-zero ID of this property
+ * @owner_id:  The ID of the object this property belongs to
+ * @type:  Property type
+ * @flags: Property flags
+ * @name:  Property name
+ * @payload_size: Property payload size, 0 for U64/S64
+ * @payload_offset: Property payload starts at this offset from 
+ * This is 0 for U64/S64.
+ * @prop_idx:  Index to sub-properties, 0 means there are no sub-properties.
+ * @owner_idx: Index to entities/pads/properties, depending on the owner ID
+ * type.
+ * @reserved:  Property reserved field, will be zeroed.
+ */
+struct media_v2_prop {
+   __u32 id;
+   __u32 owner_id;
+   __u32 type;
+   __u32 flags;
+   char name[32];
+   __u32 payload_size;
+   __u32 payload_offset;
+   __u16 prop_idx;
+   __u16 owner_idx;
+   __u32 reserved[17];
+} __attribute__ ((packed));
+
+static inline const char *media_prop2s(const struct media_v2_prop *prop)
+{
+   return (const char *)prop + prop->payload_offset;
+}
+
+static inline __u64 media_prop2u64(const struct media_v2_prop *prop)
+{
+   return *(const __u64 *)((const char *)prop + prop->payload_offset);
+}
+
+static inline __s64 media_prop2s64(const struct media_v2_prop *prop)
+{
+   return 

[RFCv4 PATCH 2/3] media controller: add properties support

2018-11-21 Thread Hans Verkuil
From: Hans Verkuil 

Add support for properties. In this initial implementation properties
can be added to entities and pads. In addition, properties can be
nested.

Since this patch adds the topology_idx to the graph objects it is now
easy to fill in the index fields in the topology to allow userspace
to quickly look up a reference from one object to another.

Signed-off-by: Hans Verkuil 
---
 drivers/media/media-device.c | 335 +++
 drivers/media/media-entity.c | 107 ++-
 include/media/media-device.h |   6 +
 include/media/media-entity.h | 318 +
 4 files changed, 685 insertions(+), 81 deletions(-)

diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index bed24372e61f..099ab3532475 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -235,6 +235,21 @@ static long media_device_setup_link(struct media_device 
*mdev, void *arg)
return __media_entity_setup_link(link, linkd->flags);
 }
 
+static void walk_props(struct list_head *head, u32 *prop_idx, u32 
*payload_size)
+{
+   struct media_prop *prop;
+
+   if (list_empty(head))
+   return;
+
+   list_for_each_entry(prop, head, list) {
+   prop->graph_obj.topology_idx = (*prop_idx)++;
+   *payload_size += prop->payload_size;
+   }
+   list_for_each_entry(prop, head, list)
+   walk_props(>props, prop_idx, payload_size);
+}
+
 static long media_device_get_topology(struct media_device *mdev, void *arg)
 {
struct media_v2_topology *topo = arg;
@@ -242,27 +257,96 @@ static long media_device_get_topology(struct media_device 
*mdev, void *arg)
struct media_interface *intf;
struct media_pad *pad;
struct media_link *link;
+   struct media_prop *prop, *subprop;
struct media_v2_entity kentity, __user *uentity;
struct media_v2_interface kintf, __user *uintf;
struct media_v2_pad kpad, __user *upad;
struct media_v2_link klink, __user *ulink;
+   struct media_v2_prop kprop, __user *uprop;
+   u32 payload_size = 0;
+   u32 payload_offset = 0;
+   u32 entity_idx = 0;
+   u32 interface_idx = 0;
+   u32 pad_idx = 0;
+   u32 link_idx = 0;
+   u32 prop_idx = 0;
unsigned int i;
int ret = 0;
 
topo->topology_version = mdev->topology_version;
 
+   /* Set entity/pad/link indices and number of entities */
+   media_device_for_each_entity(entity, mdev) {
+   entity->graph_obj.topology_idx = entity_idx++;
+   walk_props(>props, _idx, _size);
+   for (i = 0; i < entity->num_pads; i++) {
+   pad = entity->pads + i;
+   pad->graph_obj.topology_idx = pad_idx++;
+   walk_props(>props, _idx, _size);
+   }
+   /* Note: links are ordered by source pad index */
+   list_for_each_entry(link, >links, list)
+   if (!link->is_backlink)
+   link->graph_obj.topology_idx = link_idx++;
+   }
+   if (topo->ptr_entities && entity_idx > topo->num_entities)
+   ret = -ENOSPC;
+   topo->num_entities = entity_idx;
+   topo->reserved1 = 0;
+
+   /* Set interface/link indices and number of interfaces */
+   media_device_for_each_intf(intf, mdev) {
+   intf->graph_obj.topology_idx = interface_idx++;
+   list_for_each_entry(link, >links, list)
+   link->graph_obj.topology_idx = link_idx++;
+   }
+
+   if (topo->ptr_interfaces && interface_idx > topo->num_interfaces)
+   ret = -ENOSPC;
+   topo->num_interfaces = interface_idx;
+   topo->reserved2 = 0;
+
+   /* Set number of pads */
+   if (topo->ptr_pads && pad_idx > topo->num_pads)
+   ret = -ENOSPC;
+   topo->num_pads = pad_idx;
+   topo->reserved3 = 0;
+
+   /* Set number of links */
+   if (topo->ptr_links && link_idx > topo->num_links)
+   ret = -ENOSPC;
+   topo->num_links = link_idx;
+   topo->reserved4 = 0;
+
+   /* Set number of properties */
+   if (topo->ptr_props &&
+   (prop_idx > topo->num_props ||
+payload_size > topo->props_payload_size))
+   ret = -ENOSPC;
+   topo->num_props = prop_idx;
+   topo->props_payload_size = payload_size;
+
+   if (ret)
+   return ret;
+
+   /*
+* We use u16 for the graph object indices,
+* so check that it will fit in 16 bits.
+*/
+   if (WARN_ON(entity_idx >= 0x1 ||
+   interface_idx >= 0x1 ||
+   pad_idx >= 0x1 ||
+   link_idx >= 0x1 ||
+   prop_idx >= 0x1))
+   return -EINVAL;
+
/* Get entities and number of entities */
-   i = 0;
uentity = 

RE: [PATCH v1 1/1] media: atmel-isc: Add safety checks for NULL isc->raw_fmt struct

2018-11-21 Thread Ken Sloat
>> From: Ken Sloat 
>>
>> In some usages isc->raw_fmt will not be initialized. If this is the 
>> case, it is very possible that a NULL struct de-reference will occur, 
>> as this member is referenced many times.

> Hello  Ken,

> Do you have any confidence that just by avoiding the NULL situation, this fix 
> makes things right for adding new sensors that for example, do not offer a 
> raw format ?

Hi Eugen,

Thanks for your comments. The primary goal of my patch is to the solve the 
immediate issue of NULL de-reference of the that struct member. My current 
sensors actually do not offer a RAW format, which is why this bug happens in my 
case (see more details below).

> My feeling is that the method of adding this variable (raw_fmt) is very 
> unfortunate, and I did not completely understand the situations where it's 
> needed.

I agree that the current method of setting a struct member based on a RAW flag 
is flawed and ideally there needs to be a more fundamental change to the 
architecture of the driver so that this situation would never possibly occur, 
however I will present one below that can very likely happen as it does for me:

> The check that actually sets the raw_fmt comes from an iteration through the 
> formats, and the one having the RAW flag gets put into this variable. One 
> could just alter the formats table and get the raw_fmt that is needed.

Right, so in the initial iteration in isc_formats_init() the driver calls the 
sub-device/sensor enum_mbus_code function to step through all its supported 
formats and try and find them in the list of supported ISC formats. If none of 
the formats in the sub-device/sensor are of RAW type, then isc-raw_fmt will not 
be set. This is the fundamental flaw in using this member.

Following this, the driver will attempt to set a default format for the ISC in 
isc_set_default_fmt(). This appears to be based on the first format in the list 
of ISC formats. The driver then does a check to see if the sensor is preferred 
to the ISC. If the default format is not supported by the sub-device/sensor, it 
will not be preferred and we will get a resulting crash because it will assume 
that we must use the raw_fmt member that never got set.

>> 
>> To prevent this, add safety checks for this member and handle 
>> situations accordingly.
>> 
>> Signed-off-by: Ken Sloat 
>> ---
>>   drivers/media/platform/atmel/atmel-isc.c | 64 
>>   1 file changed, 44 insertions(+), 20 deletions(-)
>> 
>> diff --git a/drivers/media/platform/atmel/atmel-isc.c 
>> b/drivers/media/platform/atmel/atmel-isc.c
>> index 50178968b8a6..4cccaa4f2ce9 100644
>> --- a/drivers/media/platform/atmel/atmel-isc.c
>> +++ b/drivers/media/platform/atmel/atmel-isc.c
>> @@ -902,6 +902,15 @@ static inline bool sensor_is_preferred(const struct 
>> isc_format *isc_fmt)
>>  !isc_fmt->isc_support;
>>   }
>>   
>> +static inline u32 get_preferred_mbus_code(const struct isc_device *isc,
>> +const struct isc_format *isc_fmt)
>> +{
>> +if (sensor_is_preferred(isc_fmt) || !isc->raw_fmt)
>> +return isc_fmt->mbus_code;

> For example here, if we do _not_ have a raw format, what makes us believe 
> that the right format is the one from the mbus_code from the isc_fmt ? Is 
> there anything useful there at all ?

It's more of a safe case for where this occurs in my example above. As you 
mentioned yourself, raw_fmt could possibly set to any of the RAW flag formats 
supported by the sub-device.  Assuming the sub-device did indeed support a RAW 
format of some sort, but did not necessarily support the current format, the 
driver as of today would be referencing this alternative mbus code anyways. In 
the example above, this occurred while setting the default format, and then 
subsequently will always occur when setting the pipeline in isc_set_pipeline() 
as this function always de-references this member to set the pointer even if a 
RAW format isn't necessarily being used (and so do others as seen in my patch). 

>> +else
>> +return isc->raw_fmt->mbus_code;
>> +}
>> +
>>   static struct fmt_config *get_fmt_config(u32 fourcc)
>>   {
>>  struct fmt_config *config;
>> @@ -955,7 +964,7 @@ static void isc_set_pipeline(struct isc_device *isc, u32 
>> pipeline)
>>   {
>>  struct regmap *regmap = isc->regmap;
>>  struct isc_ctrls *ctrls = >ctrls;
>> -struct fmt_config *config = get_fmt_config(isc->raw_fmt->fourcc);
>> +struct fmt_config *config;
>>  u32 val, bay_cfg;
>>  const u32 *gamma;
>>  unsigned int i;
>> @@ -969,7 +978,12 @@ static void isc_set_pipeline(struct isc_device *isc, 
>> u32 pipeline)
>>  if (!pipeline)
>>  return;
>>   
>> -bay_cfg = config->cfa_baycfg;
>> +if (isc->raw_fmt) {
>> +config = get_fmt_config(isc->raw_fmt->fourcc);
>> +bay_cfg = config->cfa_baycfg;
>> +} else {
>> +bay_cfg = 0;
>> +}

> Having bay_cfg zero, in the case 

Re: [PATCH v9 3/3] media: add Rockchip VPU JPEG encoder driver

2018-11-21 Thread Hans Verkuil
On 11/20/2018 10:20 PM, Ezequiel Garcia wrote:
> Add a mem2mem driver for the VPU available on Rockchip SoCs.
> Currently only JPEG encoding is supported, for RK3399 and RK3288
> platforms.
> 
> Signed-off-by: Ezequiel Garcia 
> ---
>  MAINTAINERS   |   7 +
>  drivers/staging/media/Kconfig |   2 +
>  drivers/staging/media/Makefile|   1 +
>  drivers/staging/media/rockchip/vpu/Kconfig|  14 +
>  drivers/staging/media/rockchip/vpu/Makefile   |  10 +
>  drivers/staging/media/rockchip/vpu/TODO   |   6 +
>  .../media/rockchip/vpu/rk3288_vpu_hw.c| 118 +++
>  .../rockchip/vpu/rk3288_vpu_hw_jpeg_enc.c | 133 
>  .../media/rockchip/vpu/rk3288_vpu_regs.h  | 442 +++
>  .../media/rockchip/vpu/rk3399_vpu_hw.c| 118 +++
>  .../rockchip/vpu/rk3399_vpu_hw_jpeg_enc.c | 160 
>  .../media/rockchip/vpu/rk3399_vpu_regs.h  | 600 +++
>  .../staging/media/rockchip/vpu/rockchip_vpu.h | 237 ++
>  .../media/rockchip/vpu/rockchip_vpu_common.h  |  29 +
>  .../media/rockchip/vpu/rockchip_vpu_drv.c | 535 +
>  .../media/rockchip/vpu/rockchip_vpu_enc.c | 702 ++
>  .../media/rockchip/vpu/rockchip_vpu_hw.h  |  58 ++
>  .../media/rockchip/vpu/rockchip_vpu_jpeg.c| 289 +++
>  .../media/rockchip/vpu/rockchip_vpu_jpeg.h|  12 +
>  19 files changed, 3473 insertions(+)
>  create mode 100644 drivers/staging/media/rockchip/vpu/Kconfig
>  create mode 100644 drivers/staging/media/rockchip/vpu/Makefile
>  create mode 100644 drivers/staging/media/rockchip/vpu/TODO
>  create mode 100644 drivers/staging/media/rockchip/vpu/rk3288_vpu_hw.c
>  create mode 100644 
> drivers/staging/media/rockchip/vpu/rk3288_vpu_hw_jpeg_enc.c
>  create mode 100644 drivers/staging/media/rockchip/vpu/rk3288_vpu_regs.h
>  create mode 100644 drivers/staging/media/rockchip/vpu/rk3399_vpu_hw.c
>  create mode 100644 
> drivers/staging/media/rockchip/vpu/rk3399_vpu_hw_jpeg_enc.c
>  create mode 100644 drivers/staging/media/rockchip/vpu/rk3399_vpu_regs.h
>  create mode 100644 drivers/staging/media/rockchip/vpu/rockchip_vpu.h
>  create mode 100644 drivers/staging/media/rockchip/vpu/rockchip_vpu_common.h
>  create mode 100644 drivers/staging/media/rockchip/vpu/rockchip_vpu_drv.c
>  create mode 100644 drivers/staging/media/rockchip/vpu/rockchip_vpu_enc.c
>  create mode 100644 drivers/staging/media/rockchip/vpu/rockchip_vpu_hw.h
>  create mode 100644 drivers/staging/media/rockchip/vpu/rockchip_vpu_jpeg.c
>  create mode 100644 drivers/staging/media/rockchip/vpu/rockchip_vpu_jpeg.h
> 



> diff --git a/drivers/staging/media/rockchip/vpu/Kconfig 
> b/drivers/staging/media/rockchip/vpu/Kconfig
> new file mode 100644
> index ..fa65c03d65bf
> --- /dev/null
> +++ b/drivers/staging/media/rockchip/vpu/Kconfig
> @@ -0,0 +1,14 @@
> +config VIDEO_ROCKCHIP_VPU
> + tristate "Rockchip VPU driver"
> + depends on ARCH_ROCKCHIP || COMPILE_TEST
> + depends on VIDEO_DEV && VIDEO_V4L2 && MEDIA_CONTROLLER
> + select VIDEOBUF2_DMA_CONTIG
> + select VIDEOBUF2_VMALLOC
> + select V4L2_MEM2MEM_DEV
> + default n
> + help
> +   Support for the Video Processing Unit present on Rockchip SoC,
> +   which accelerates video and image encoding and decoding.
> +   To compile this driver as a module, choose M here: the module
> +   will be called rockchip-vpu.
> +

checkpatch warns about empty line at the end of the Kconfig



> diff --git a/drivers/staging/media/rockchip/vpu/rk3288_vpu_regs.h 
> b/drivers/staging/media/rockchip/vpu/rk3288_vpu_regs.h
> new file mode 100644
> index ..d6cf9c682e7d
> --- /dev/null
> +++ b/drivers/staging/media/rockchip/vpu/rk3288_vpu_regs.h
> @@ -0,0 +1,442 @@
> +// SPDX-License-Identifier: GPL-2.0

Headers must use /* */ for the SPDX license. Sorry, I didn't make up these 
rules.

In any case, checkpatch.pl --strict complains about it.



> diff --git a/drivers/staging/media/rockchip/vpu/rockchip_vpu_jpeg.c 
> b/drivers/staging/media/rockchip/vpu/rockchip_vpu_jpeg.c
> new file mode 100644
> index ..678d53f3c2c2
> --- /dev/null
> +++ b/drivers/staging/media/rockchip/vpu/rockchip_vpu_jpeg.c
> @@ -0,0 +1,289 @@

Missing SPDX license!

> +/*
> + * Copyright (C) Collabora, Ltd.
> + *
> + * Based on GSPCA and CODA drivers:
> + * Copyright (C) Jean-Francois Moine (http://moinejf.free.fr)
> + * Copyright (C) 2014 Philipp Zabel, Pengutronix
> + */



> diff --git a/drivers/staging/media/rockchip/vpu/rockchip_vpu_jpeg.h 
> b/drivers/staging/media/rockchip/vpu/rockchip_vpu_jpeg.h
> new file mode 100644
> index ..a616d85359e8
> --- /dev/null
> +++ b/drivers/staging/media/rockchip/vpu/rockchip_vpu_jpeg.h
> @@ -0,0 +1,12 @@

Missing SPDX license!

> +#define JPEG_HEADER_SIZE 601
> +
> +struct rockchip_vpu_jpeg_ctx {
> + int width;
> + int height;
> + int quality;
> + unsigned char *buffer;
> +};
> +
> +unsigned 

Re: [PATCH v8 00/12] media: staging/imx7: add i.MX7 media driver

2018-11-21 Thread Hans Verkuil
On 11/21/2018 12:15 PM, Rui Miguel Silva wrote:
> Hi,
> This series introduces the Media driver to work with the i.MX7 SoC. it uses 
> the
> already existing imx media core drivers but since the i.MX7, contrary to
> i.MX5/6, do not have an IPU and because of that some changes in the imx media
> core are made along this series to make it support that case.

Can you run scripts/checkpatch.pl --strict over these patches? I get too
many messages from it. Most should be easy to fix.

Regards,

Hans


[PATCH v8 12/12] media: video-mux: add bayer formats

2018-11-21 Thread Rui Miguel Silva
Add non vendor bayer formats to the  allowed format array.

Signed-off-by: Rui Miguel Silva 
---
 drivers/media/platform/video-mux.c | 20 
 1 file changed, 20 insertions(+)

diff --git a/drivers/media/platform/video-mux.c 
b/drivers/media/platform/video-mux.c
index c33900e3c23e..0ba30756e1e4 100644
--- a/drivers/media/platform/video-mux.c
+++ b/drivers/media/platform/video-mux.c
@@ -263,6 +263,26 @@ static int video_mux_set_format(struct v4l2_subdev *sd,
case MEDIA_BUS_FMT_UYYVYY16_0_5X48:
case MEDIA_BUS_FMT_JPEG_1X8:
case MEDIA_BUS_FMT_AHSV_1X32:
+   case MEDIA_BUS_FMT_SBGGR8_1X8:
+   case MEDIA_BUS_FMT_SGBRG8_1X8:
+   case MEDIA_BUS_FMT_SGRBG8_1X8:
+   case MEDIA_BUS_FMT_SRGGB8_1X8:
+   case MEDIA_BUS_FMT_SBGGR10_1X10:
+   case MEDIA_BUS_FMT_SGBRG10_1X10:
+   case MEDIA_BUS_FMT_SGRBG10_1X10:
+   case MEDIA_BUS_FMT_SRGGB10_1X10:
+   case MEDIA_BUS_FMT_SBGGR12_1X12:
+   case MEDIA_BUS_FMT_SGBRG12_1X12:
+   case MEDIA_BUS_FMT_SGRBG12_1X12:
+   case MEDIA_BUS_FMT_SRGGB12_1X12:
+   case MEDIA_BUS_FMT_SBGGR14_1X14:
+   case MEDIA_BUS_FMT_SGBRG14_1X14:
+   case MEDIA_BUS_FMT_SGRBG14_1X14:
+   case MEDIA_BUS_FMT_SRGGB14_1X14:
+   case MEDIA_BUS_FMT_SBGGR16_1X16:
+   case MEDIA_BUS_FMT_SGBRG16_1X16:
+   case MEDIA_BUS_FMT_SGRBG16_1X16:
+   case MEDIA_BUS_FMT_SRGGB16_1X16:
break;
default:
sdformat->format.code = MEDIA_BUS_FMT_Y8_1X8;
-- 
2.19.1



[PATCH v8 07/12] ARM: dts: imx7s: add multiplexer controls

2018-11-21 Thread Rui Miguel Silva
The IOMUXC General Purpose Register has bitfield to control video bus
multiplexer to control the CSI input between the MIPI-CSI2 and parallel
interface. Add that register and mask.

Signed-off-by: Rui Miguel Silva 
Reviewed-by: Philipp Zabel 
---
 arch/arm/boot/dts/imx7s.dtsi | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/arch/arm/boot/dts/imx7s.dtsi b/arch/arm/boot/dts/imx7s.dtsi
index 6e2e4f99cdb0..964f19c997d4 100644
--- a/arch/arm/boot/dts/imx7s.dtsi
+++ b/arch/arm/boot/dts/imx7s.dtsi
@@ -499,8 +499,14 @@
 
gpr: iomuxc-gpr@3034 {
compatible = "fsl,imx7d-iomuxc-gpr",
-   "fsl,imx6q-iomuxc-gpr", "syscon";
+   "fsl,imx6q-iomuxc-gpr", "syscon", 
"simple-mfd";
reg = <0x3034 0x1>;
+
+   mux: mux-controller {
+   compatible = "mmio-mux";
+   #mux-control-cells = <0>;
+   mux-reg-masks = <0x14 0x0010>;
+   };
};
 
ocotp: ocotp-ctrl@3035 {
-- 
2.19.1



[PATCH v8 00/12] media: staging/imx7: add i.MX7 media driver

2018-11-21 Thread Rui Miguel Silva
Hi,
This series introduces the Media driver to work with the i.MX7 SoC. it uses the
already existing imx media core drivers but since the i.MX7, contrary to
i.MX5/6, do not have an IPU and because of that some changes in the imx media
core are made along this series to make it support that case.

This patches adds CSI and MIPI-CSI2 drivers for i.MX7, along with several
configurations changes for this to work as a capture subsystem. Some bugs are
also fixed along the line. And necessary documentation.

For a more detailed view of the capture paths, pads links in the i.MX7 please
take a look at the documentation in PATCH 14.

The system used to test and develop this was the Warp7 board with an OV2680
sensor, which output format is 10-bit bayer. So, only MIPI interface was
tested, a scenario with an parallel input would nice to have.


Bellow goes an example of the output of the pads and links and the output of
v4l2-compliance testing.

The v4l-utils version used is:
v4l2-compliance SHA   : 044d5ab7b0d02683070d01a369c73d462d7a0cee from Nov 19th

The Media Driver fail some tests but this failures are coming from code out of
scope of this series (imx-capture), and some from the sensor OV2680
but that I think not related with the sensor driver but with the testing and
core.

The csi and mipi-csi entities pass all compliance tests.

Cheers,
Rui

v7->v8:
Myself:
 - rebase to latest linux-next (s/V4L2_MBUS_CSI2/V4L2_MBUS_CSI2_DPHY/)
 - Rebuild and test with latest v4l2-compliance
 - add Sakari reviewed-by tag to dt-bindings

v6->v7:
Myself:
 - Clock patches removed from this version since they were already merged
 - Rebuild and test with the latest v4l2-compliance
 - Add patch to video-mux regarding bayer formats
 - remove reference to dependent patch serie (was already merged)

Sakari Ailus:
 - add port and endpoint explanantions
 - fix some wording should -> shall

v5->v6:
Rob Herring:
 - rename power-domain node name from: pgc-power-domain to power-domain
 - change mux-control-cells to 0
 - remove bus-width from mipi bindings and dts
 - remove err... regarding clock names line
 - remove clk-settle from example
 - split mipi-csi2 and csi bindings per file
 - add OF graph description to CSI

Philipp Zabel:
 - rework group IDs and rename them with an _IPU_ prefix, this allowed to remove
   the ipu_present flag need.

v4->v5:
Sakari Ailus:
 - fix remove of the capture entries in dts bindings in the right patch

Stephen Boyd:
 - Send all series to clk list

v3->v4:
Philipp Zabel:
 - refactor initialization code from media device probe to be possible to used
   from other modules
 - Remove index of csi from all accurrencs (dts, code, documentation)
 - Remove need for capture node for imx7
 - fix pinctrl for ov2680
 - add reviewed tag to add multiplexer controls patch

Fabio Estevam:
 - remove always on from new regulator

Randy Dunlap:
 - several text editing fixes in documentation

Myself:
 - rebase on top of v4 of Steve series
 - change CSI probe to initialize imx media device
 - remove csi mux parallel endpoint from mux to avoid warning message

v2->v3:
Philipp Zabel:
 - use of_match_device in imx-media-dev instead of of_device_match
 - fix number of data lanes from 4 to 2
 - change the clock definitions and use of mipi
 - move hs-settle from endpoint

Rob Herring:
 - fix phy-supply description
 - add vendor properties
 - fix examples indentations

Stephen Boyd: patch 3/14
 - fix double sign-off
 - add fixes tag

Dong Aisheng: patch 3/14
 - fix double sign-off
 - add Acked-by tag

Shawn Guo:
patch 4/14
 - remove line breakage in parent redifiniton
 - added Acked-by tag

 - dropped CMA area increase and add more verbose information in case of
   dma allocation failure
patch 9/14
 - remove extra line between cells and reg masks

Myself:
 - rework on frame end in csi
 - add rxcount in csi driver
 - add power supplies to ov2680 node and fix gpio polarity

v1->v2:
Dan Carpenter:
 - fix return paths and codes;
 - fix clk_frequency validation and return code;
 - handle the csi remove (release resources that was missing)
 - revert the logic arround the ipu_present flag

Philipp Zabel:
 - drop patch that changed the rgb formats and address the pixel/bus format in
   mipi_csis code.

MySelf:
 - add patch that add ov2680 node to the warp7 dts, so the all data path is
   complete.
 - add linux-clk mailing list to the clock patches cc:

v4l2-compliance SHA: 044d5ab7b0d02683070d01a369c73d462d7a0cee, 32 bits

Compliance test for device /dev/media0:

Media Driver Info:
Driver name  : imx7-csi
Model: imx-media
Serial   : 
Bus info : 
Media version: 4.20.0
Hardware revision: 0x (0)
Driver version   : 4.20.0

Required ioctls:
test MEDIA_IOC_DEVICE_INFO: OK

Allow for multiple opens:
test second /dev/media0 open: OK
test MEDIA_IOC_DEVICE_INFO: OK
test for unlimited opens: OK

Media Controller ioctls:

[PATCH v8 06/12] ARM: dts: imx7s: add mipi phy power domain

2018-11-21 Thread Rui Miguel Silva
Add power domain index 0 related with mipi-phy to imx7s.

While at it rename pcie power-domain node to remove pgc prefix.

Signed-off-by: Rui Miguel Silva 
---
 arch/arm/boot/dts/imx7s.dtsi | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/arch/arm/boot/dts/imx7s.dtsi b/arch/arm/boot/dts/imx7s.dtsi
index aa8df7d93b2e..6e2e4f99cdb0 100644
--- a/arch/arm/boot/dts/imx7s.dtsi
+++ b/arch/arm/boot/dts/imx7s.dtsi
@@ -608,7 +608,13 @@
#address-cells = <1>;
#size-cells = <0>;
 
-   pgc_pcie_phy: pgc-power-domain@1 {
+   pgc_mipi_phy: power-domain@0 {
+   #power-domain-cells = <0>;
+   reg = <0>;
+   power-supply = <_1p0d>;
+   };
+
+   pgc_pcie_phy: power-domain@1 {
#power-domain-cells = <0>;
reg = <1>;
power-supply = <_1p0d>;
-- 
2.19.1



[PATCH v8 03/12] media: staging/imx7: add imx7 CSI subdev driver

2018-11-21 Thread Rui Miguel Silva
This add the media entity subdevice and control driver for the i.MX7
CMOS Sensor Interface.

Signed-off-by: Rui Miguel Silva 
---
 drivers/staging/media/imx/Kconfig  |9 +-
 drivers/staging/media/imx/Makefile |2 +
 drivers/staging/media/imx/imx7-media-csi.c | 1352 
 3 files changed, 1362 insertions(+), 1 deletion(-)
 create mode 100644 drivers/staging/media/imx/imx7-media-csi.c

diff --git a/drivers/staging/media/imx/Kconfig 
b/drivers/staging/media/imx/Kconfig
index bfc17de56b17..40a11f988fc6 100644
--- a/drivers/staging/media/imx/Kconfig
+++ b/drivers/staging/media/imx/Kconfig
@@ -11,7 +11,7 @@ config VIDEO_IMX_MEDIA
  driver for the i.MX5/6 SOC.
 
 if VIDEO_IMX_MEDIA
-menu "i.MX5/6 Media Sub devices"
+menu "i.MX5/6/7 Media Sub devices"
 
 config VIDEO_IMX_CSI
tristate "i.MX5/6 Camera Sensor Interface driver"
@@ -20,5 +20,12 @@ config VIDEO_IMX_CSI
---help---
  A video4linux camera sensor interface driver for i.MX5/6.
 
+config VIDEO_IMX7_CSI
+   tristate "i.MX7 Camera Sensor Interface driver"
+   depends on VIDEO_IMX_MEDIA && VIDEO_DEV && I2C
+   default y
+   ---help---
+ A video4linux camera sensor interface driver for i.MX7.
+
 endmenu
 endif
diff --git a/drivers/staging/media/imx/Makefile 
b/drivers/staging/media/imx/Makefile
index a30b3033f9a3..074f016d3519 100644
--- a/drivers/staging/media/imx/Makefile
+++ b/drivers/staging/media/imx/Makefile
@@ -12,3 +12,5 @@ obj-$(CONFIG_VIDEO_IMX_MEDIA) += imx-media-ic.o
 
 obj-$(CONFIG_VIDEO_IMX_CSI) += imx-media-csi.o
 obj-$(CONFIG_VIDEO_IMX_CSI) += imx6-mipi-csi2.o
+
+obj-$(CONFIG_VIDEO_IMX7_CSI) += imx7-media-csi.o
diff --git a/drivers/staging/media/imx/imx7-media-csi.c 
b/drivers/staging/media/imx/imx7-media-csi.c
new file mode 100644
index ..ec5a20880bb6
--- /dev/null
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -0,0 +1,1352 @@
+// SPDX-License-Identifier: GPL
+/*
+ * V4L2 Capture CSI Subdev for Freescale i.MX7 SOC
+ *
+ * Copyright (c) 2018 Linaro Ltd
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include "imx-media.h"
+
+#define IMX7_CSI_PAD_SINK  0
+#define IMX7_CSI_PAD_SRC   1
+#define IMX7_CSI_PADS_NUM  2
+
+/* reset values */
+#define CSICR1_RESET_VAL   0x4800
+#define CSICR2_RESET_VAL   0x0
+#define CSICR3_RESET_VAL   0x0
+
+/* csi control reg 1 */
+#define BIT_SWAP16_EN  BIT(31)
+#define BIT_EXT_VSYNC  BIT(30)
+#define BIT_EOF_INT_EN BIT(29)
+#define BIT_PRP_IF_EN  BIT(28)
+#define BIT_CCIR_MODE  BIT(27)
+#define BIT_COF_INT_EN BIT(26)
+#define BIT_SF_OR_INTENBIT(25)
+#define BIT_RF_OR_INTENBIT(24)
+#define BIT_SFF_DMA_DONE_INTEN  BIT(22)
+#define BIT_STATFF_INTEN   BIT(21)
+#define BIT_FB2_DMA_DONE_INTEN  BIT(20)
+#define BIT_FB1_DMA_DONE_INTEN  BIT(19)
+#define BIT_RXFF_INTEN BIT(18)
+#define BIT_SOF_POLBIT(17)
+#define BIT_SOF_INTEN  BIT(16)
+#define BIT_MCLKDIV(0xF << 12)
+#define BIT_HSYNC_POL  BIT(11)
+#define BIT_CCIR_ENBIT(10)
+#define BIT_MCLKEN BIT(9)
+#define BIT_FCCBIT(8)
+#define BIT_PACK_DIR   BIT(7)
+#define BIT_CLR_STATFIFO   BIT(6)
+#define BIT_CLR_RXFIFO BIT(5)
+#define BIT_GCLK_MODE  BIT(4)
+#define BIT_INV_DATA   BIT(3)
+#define BIT_INV_PCLK   BIT(2)
+#define BIT_REDGE  BIT(1)
+#define BIT_PIXEL_BIT  BIT(0)
+
+#define SHIFT_MCLKDIV  12
+
+/* control reg 3 */
+#define BIT_FRMCNT (0x << 16)
+#define BIT_FRMCNT_RST BIT(15)
+#define BIT_DMA_REFLASH_RFFBIT(14)
+#define BIT_DMA_REFLASH_SFFBIT(13)
+#define BIT_DMA_REQ_EN_RFF BIT(12)
+#define BIT_DMA_REQ_EN_SFF BIT(11)
+#define BIT_STATFF_LEVEL   (0x7 << 8)
+#define BIT_HRESP_ERR_EN   BIT(7)
+#define BIT_RXFF_LEVEL (0x7 << 4)
+#define BIT_TWO_8BIT_SENSORBIT(3)
+#define BIT_ZERO_PACK_EN   BIT(2)
+#define BIT_ECC_INT_EN BIT(1)
+#define BIT_ECC_AUTO_ENBIT(0)
+
+#define SHIFT_FRMCNT   16
+#define SHIFT_RXFIFO_LEVEL 4
+
+/* csi status reg */
+#define BIT_ADDR_CH_ERR_INTBIT(28)
+#define BIT_FIELD0_INT BIT(27)
+#define BIT_FIELD1_INT BIT(26)
+#define BIT_SFF_OR_INT BIT(25)
+#define BIT_RFF_OR_INT BIT(24)
+#define BIT_DMA_TSF_DONE_SFF   BIT(22)
+#define BIT_STATFF_INT BIT(21)
+#define BIT_DMA_TSF_DONE_FB2   BIT(20)
+#define BIT_DMA_TSF_DONE_FB1   BIT(19)
+#define BIT_RXFF_INT   BIT(18)
+#define BIT_EOF_INTBIT(17)
+#define BIT_SOF_INTBIT(16)
+#define BIT_F2_INT BIT(15)
+#define BIT_F1_INT BIT(14)
+#define BIT_COF_INT

[PATCH v8 04/12] media: staging/imx7: add MIPI CSI-2 receiver subdev for i.MX7

2018-11-21 Thread Rui Miguel Silva
Adds MIPI CSI-2 subdev for i.MX7 to connect with sensors with a MIPI CSI-2
interface.

Signed-off-by: Rui Miguel Silva 
---
 drivers/staging/media/imx/Makefile |1 +
 drivers/staging/media/imx/imx7-mipi-csis.c | 1134 
 2 files changed, 1135 insertions(+)
 create mode 100644 drivers/staging/media/imx/imx7-mipi-csis.c

diff --git a/drivers/staging/media/imx/Makefile 
b/drivers/staging/media/imx/Makefile
index 074f016d3519..d2d909a36239 100644
--- a/drivers/staging/media/imx/Makefile
+++ b/drivers/staging/media/imx/Makefile
@@ -14,3 +14,4 @@ obj-$(CONFIG_VIDEO_IMX_CSI) += imx-media-csi.o
 obj-$(CONFIG_VIDEO_IMX_CSI) += imx6-mipi-csi2.o
 
 obj-$(CONFIG_VIDEO_IMX7_CSI) += imx7-media-csi.o
+obj-$(CONFIG_VIDEO_IMX7_CSI) += imx7-mipi-csis.o
diff --git a/drivers/staging/media/imx/imx7-mipi-csis.c 
b/drivers/staging/media/imx/imx7-mipi-csis.c
new file mode 100644
index ..39bf0657557e
--- /dev/null
+++ b/drivers/staging/media/imx/imx7-mipi-csis.c
@@ -0,0 +1,1134 @@
+// SPDX-License-Identifier: GPL
+/*
+ * Freescale i.MX7 SoC series MIPI-CSI V3.3 receiver driver
+ *
+ * Copyright (C) 2018 Linaro Ltd
+ * Copyright (C) 2015-2016 Freescale Semiconductor, Inc. All Rights Reserved.
+ * Copyright (C) 2011 - 2013 Samsung Electronics Co., Ltd.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+
+#include "imx-media.h"
+
+static int debug;
+module_param(debug, int, 0644);
+MODULE_PARM_DESC(debug, "Debug level (0-2)");
+
+#define CSIS_DRIVER_NAME   "imx7-mipi-csis"
+#define CSIS_SUBDEV_NAME   CSIS_DRIVER_NAME
+
+#define CSIS_PAD_SINK  0
+#define CSIS_PAD_SOURCE1
+#define CSIS_PADS_NUM  2
+
+#define MIPI_CSIS_DEF_PIX_WIDTH640
+#define MIPI_CSIS_DEF_PIX_HEIGHT   480
+
+/* Register map definition */
+
+/* CSIS common control */
+#define MIPI_CSIS_CMN_CTRL 0x04
+#define MIPI_CSIS_CMN_CTRL_UPDATE_SHADOW   BIT(16)
+#define MIPI_CSIS_CMN_CTRL_INTER_MODE  BIT(10)
+#define MIPI_CSIS_CMN_CTRL_UPDATE_SHADOW_CTRL  BIT(2)
+#define MIPI_CSIS_CMN_CTRL_RESET   BIT(1)
+#define MIPI_CSIS_CMN_CTRL_ENABLE  BIT(0)
+
+#define MIPI_CSIS_CMN_CTRL_LANE_NR_OFFSET  8
+#define MIPI_CSIS_CMN_CTRL_LANE_NR_MASK(3 << 8)
+
+/* CSIS clock control */
+#define MIPI_CSIS_CLK_CTRL 0x08
+#define MIPI_CSIS_CLK_CTRL_CLKGATE_TRAIL_CH3(x)(x << 28)
+#define MIPI_CSIS_CLK_CTRL_CLKGATE_TRAIL_CH2(x)(x << 24)
+#define MIPI_CSIS_CLK_CTRL_CLKGATE_TRAIL_CH1(x)(x << 20)
+#define MIPI_CSIS_CLK_CTRL_CLKGATE_TRAIL_CH0(x)(x << 16)
+#define MIPI_CSIS_CLK_CTRL_CLKGATE_EN_MSK  (0xf << 4)
+#define MIPI_CSIS_CLK_CTRL_WCLK_SRCBIT(0)
+
+/* CSIS Interrupt mask */
+#define MIPI_CSIS_INTMSK   0x10
+#define MIPI_CSIS_INTMSK_EVEN_BEFORE   BIT(31)
+#define MIPI_CSIS_INTMSK_EVEN_AFTERBIT(30)
+#define MIPI_CSIS_INTMSK_ODD_BEFOREBIT(29)
+#define MIPI_CSIS_INTMSK_ODD_AFTER BIT(28)
+#define MIPI_CSIS_INTMSK_FRAME_START   BIT(24)
+#define MIPI_CSIS_INTMSK_FRAME_END BIT(20)
+#define MIPI_CSIS_INTMSK_ERR_SOT_HSBIT(16)
+#define MIPI_CSIS_INTMSK_ERR_LOST_FS   BIT(12)
+#define MIPI_CSIS_INTMSK_ERR_LOST_FE   BIT(8)
+#define MIPI_CSIS_INTMSK_ERR_OVER  BIT(4)
+#define MIPI_CSIS_INTMSK_ERR_WRONG_CFG BIT(3)
+#define MIPI_CSIS_INTMSK_ERR_ECC   BIT(2)
+#define MIPI_CSIS_INTMSK_ERR_CRC   BIT(1)
+#define MIPI_CSIS_INTMSK_ERR_UNKNOWN   BIT(0)
+
+/* CSIS Interrupt source */
+#define MIPI_CSIS_INTSRC   0x14
+#define MIPI_CSIS_INTSRC_EVEN_BEFORE   BIT(31)
+#define MIPI_CSIS_INTSRC_EVEN_AFTERBIT(30)
+#define MIPI_CSIS_INTSRC_EVEN  BIT(30)
+#define MIPI_CSIS_INTSRC_ODD_BEFOREBIT(29)
+#define MIPI_CSIS_INTSRC_ODD_AFTER BIT(28)
+#define MIPI_CSIS_INTSRC_ODD   (0x3 << 28)
+#define MIPI_CSIS_INTSRC_NON_IMAGE_DATA(0xf << 28)
+#define MIPI_CSIS_INTSRC_FRAME_START   BIT(24)
+#define MIPI_CSIS_INTSRC_FRAME_END BIT(20)
+#define MIPI_CSIS_INTSRC_ERR_SOT_HSBIT(16)
+#define MIPI_CSIS_INTSRC_ERR_LOST_FS   BIT(12)
+#define MIPI_CSIS_INTSRC_ERR_LOST_FE   BIT(8)
+#define MIPI_CSIS_INTSRC_ERR_OVER  BIT(4)
+#define MIPI_CSIS_INTSRC_ERR_WRONG_CFG BIT(3)
+#define MIPI_CSIS_INTSRC_ERR_ECC   BIT(2)
+#define MIPI_CSIS_INTSRC_ERR_CRC   BIT(1)
+#define MIPI_CSIS_INTSRC_ERR_UNKNOWN   BIT(0)
+#define MIPI_CSIS_INTSRC_ERRORS0xf
+
+/* D-PHY status control */
+#define MIPI_CSIS_DPHYSTATUS   0x20
+#define MIPI_CSIS_DPHYSTATUS_ULPS_DAT  BIT(8)
+#define MIPI_CSIS_DPHYSTATUS_STOPSTATE_DAT BIT(4)
+#define MIPI_CSIS_DPHYSTATUS_ULPS_CLK  BIT(1)
+#define MIPI_CSIS_DPHYSTATUS_STOPSTATE_CLK BIT(0)
+
+/* D-PHY common control */
+#define MIPI_CSIS_DPHYCTRL 0x24
+#define 

[PATCH v8 05/12] media: dt-bindings: add bindings for i.MX7 media driver

2018-11-21 Thread Rui Miguel Silva
Add bindings documentation for i.MX7 media drivers.
The imx7 MIPI CSI2 and imx7 CMOS Sensor Interface.

Signed-off-by: Rui Miguel Silva 
Reviewed-by: Rob Herring 
Acked-by: Sakari Ailus 
---
 .../devicetree/bindings/media/imx7-csi.txt| 45 ++
 .../bindings/media/imx7-mipi-csi2.txt | 90 +++
 2 files changed, 135 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/imx7-csi.txt
 create mode 100644 Documentation/devicetree/bindings/media/imx7-mipi-csi2.txt

diff --git a/Documentation/devicetree/bindings/media/imx7-csi.txt 
b/Documentation/devicetree/bindings/media/imx7-csi.txt
new file mode 100644
index ..171b089ee91f
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/imx7-csi.txt
@@ -0,0 +1,45 @@
+Freescale i.MX7 CMOS Sensor Interface
+=
+
+csi node
+
+
+This is device node for the CMOS Sensor Interface (CSI) which enables the chip
+to connect directly to external CMOS image sensors.
+
+Required properties:
+
+- compatible: "fsl,imx7-csi";
+- reg   : base address and length of the register set for the device;
+- interrupts: should contain CSI interrupt;
+- clocks: list of clock specifiers, see
+Documentation/devicetree/bindings/clock/clock-bindings.txt for details;
+- clock-names   : must contain "axi", "mclk" and "dcic" entries, matching
+ entries in the clock property;
+
+The device node shall contain one 'port' child node with one child 'endpoint'
+node, according to the bindings defined in:
+ Documentation/devicetree/bindings/media/video-interfaces.txt.
+ 
+In the following example a remote endpoint is a video multiplexer.
+
+example:
+
+csi: csi@3071 {
+#address-cells = <1>;
+#size-cells = <0>;
+
+compatible = "fsl,imx7-csi";
+reg = <0x3071 0x1>;
+interrupts = ;
+clocks = < IMX7D_CLK_DUMMY>,
+< IMX7D_CSI_MCLK_ROOT_CLK>,
+< IMX7D_CLK_DUMMY>;
+clock-names = "axi", "mclk", "dcic";
+
+port {
+csi_from_csi_mux: endpoint {
+remote-endpoint = <_mux_to_csi>;
+};
+};
+};
diff --git a/Documentation/devicetree/bindings/media/imx7-mipi-csi2.txt 
b/Documentation/devicetree/bindings/media/imx7-mipi-csi2.txt
new file mode 100644
index ..71fd74ed3ec8
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/imx7-mipi-csi2.txt
@@ -0,0 +1,90 @@
+Freescale i.MX7 Mipi CSI2
+=
+
+mipi_csi2 node
+--
+
+This is the device node for the MIPI CSI-2 receiver core in i.MX7 SoC. It is
+compatible with previous version of Samsung D-phy.
+
+Required properties:
+
+- compatible: "fsl,imx7-mipi-csi2";
+- reg   : base address and length of the register set for the device;
+- interrupts: should contain MIPI CSIS interrupt;
+- clocks: list of clock specifiers, see
+Documentation/devicetree/bindings/clock/clock-bindings.txt for details;
+- clock-names   : must contain "pclk", "wrap" and "phy" entries, matching
+  entries in the clock property;
+- power-domains : a phandle to the power domain, see
+  Documentation/devicetree/bindings/power/power_domain.txt for details.
+- reset-names   : should include following entry "mrst";
+- resets: a list of phandle, should contain reset entry of
+  reset-names;
+- phy-supply: from the generic phy bindings, a phandle to a regulator that
+ provides power to MIPI CSIS core;
+
+Optional properties:
+
+- clock-frequency : The IP's main (system bus) clock frequency in Hz, default
+   value when this property is not specified is 166 MHz;
+- fsl,csis-hs-settle : differential receiver (HS-RX) settle time;
+
+The device node should contain two 'port' child nodes with one child 'endpoint'
+node, according to the bindings defined in:
+ Documentation/devicetree/bindings/ media/video-interfaces.txt.
+ The following are properties specific to those nodes.
+
+port node
+-
+
+- reg: (required) can take the values 0 or 1, where 0 shall be
+ related to the sink port and port 1 shall be the source
+ one;
+
+endpoint node
+-
+
+- data-lanes: (required) an array specifying active physical MIPI-CSI2
+   data input lanes and their mapping to logical lanes; this
+shall only be applied to port 0 (sink port), the array's
+content is unused only its length is meaningful,
+in this case the maximum length supported 

[PATCH v8 09/12] ARM: dts: imx7s-warp: add ov2680 sensor node

2018-11-21 Thread Rui Miguel Silva
Warp7 comes with a Omnivision OV2680 sensor, add the node here to make complete
the camera data path for this system. Add the needed regulator to the analog
voltage supply, the port and endpoints in mipi_csi node and the pinctrl for the
reset gpio.

Signed-off-by: Rui Miguel Silva 
---
 arch/arm/boot/dts/imx7s-warp.dts | 44 
 1 file changed, 44 insertions(+)

diff --git a/arch/arm/boot/dts/imx7s-warp.dts b/arch/arm/boot/dts/imx7s-warp.dts
index 757856a3964b..4ada85850411 100644
--- a/arch/arm/boot/dts/imx7s-warp.dts
+++ b/arch/arm/boot/dts/imx7s-warp.dts
@@ -54,6 +54,14 @@
regulator-always-on;
};
 
+   reg_peri_3p15v: regulator-peri-3p15v {
+   compatible = "regulator-fixed";
+   regulator-name = "peri_3p15v_reg";
+   regulator-min-microvolt = <315>;
+   regulator-max-microvolt = <315>;
+   regulator-always-on;
+   };
+
sound {
compatible = "simple-audio-card";
simple-audio-card,name = "imx7-sgtl5000";
@@ -177,6 +185,27 @@
pinctrl-names = "default";
pinctrl-0 = <_i2c2>;
status = "okay";
+
+   ov2680: camera@36 {
+   compatible = "ovti,ov2680";
+   pinctrl-names = "default";
+   pinctrl-0 = <_ov2680>;
+   reg = <0x36>;
+   clocks = <>;
+   clock-names = "xvclk";
+   reset-gpios = < 3 GPIO_ACTIVE_LOW>;
+   DOVDD-supply = <_reg>;
+   DVDD-supply = <_reg>;
+   AVDD-supply = <_peri_3p15v>;
+
+   port {
+   ov2680_to_mipi: endpoint {
+   remote-endpoint = <_from_sensor>;
+   clock-lanes = <0>;
+   data-lanes = <1>;
+   };
+   };
+   };
 };
 
  {
@@ -318,6 +347,15 @@
#size-cells = <0>;
fsl,csis-hs-settle = <3>;
 
+   port@0 {
+   reg = <0>;
+
+   mipi_from_sensor: endpoint {
+   remote-endpoint = <_to_mipi>;
+   data-lanes = <1>;
+   };
+   };
+
port@1 {
reg = <1>;
 
@@ -381,6 +419,12 @@
>;
};
 
+   pinctrl_ov2680: ov2660grp {
+   fsl,pins = <
+   MX7D_PAD_LPSR_GPIO1_IO03__GPIO1_IO3 0x14
+   >;
+   };
+
pinctrl_sai1: sai1grp {
fsl,pins = <
MX7D_PAD_SAI1_RX_DATA__SAI1_RX_DATA00x1f
-- 
2.19.1



[PATCH v8 02/12] media: staging/imx: rearrange group id to take in account IPU

2018-11-21 Thread Rui Miguel Silva
Some imx system do not have IPU, so prepare the imx media drivers to support
this kind of devices. Rename the group ids to include an _IPU_ prefix, add a new
group id to support systems with only a CSI without IPU, and also
rename the create internal links to make it clear that only systems with IPU
have internal subdevices.

Signed-off-by: Rui Miguel Silva 
---
 drivers/staging/media/imx/imx-ic-common.c |  6 ++---
 drivers/staging/media/imx/imx-ic-prp.c| 14 +--
 drivers/staging/media/imx/imx-media-csi.c |  6 ++---
 drivers/staging/media/imx/imx-media-dev.c | 22 ++
 .../staging/media/imx/imx-media-internal-sd.c | 20 
 drivers/staging/media/imx/imx-media-utils.c   | 12 +-
 drivers/staging/media/imx/imx-media.h | 23 ++-
 7 files changed, 54 insertions(+), 49 deletions(-)

diff --git a/drivers/staging/media/imx/imx-ic-common.c 
b/drivers/staging/media/imx/imx-ic-common.c
index cfdd4900a3be..765919487a73 100644
--- a/drivers/staging/media/imx/imx-ic-common.c
+++ b/drivers/staging/media/imx/imx-ic-common.c
@@ -41,13 +41,13 @@ static int imx_ic_probe(struct platform_device *pdev)
pdata = priv->dev->platform_data;
priv->ipu_id = pdata->ipu_id;
switch (pdata->grp_id) {
-   case IMX_MEDIA_GRP_ID_IC_PRP:
+   case IMX_MEDIA_GRP_ID_IPU_IC_PRP:
priv->task_id = IC_TASK_PRP;
break;
-   case IMX_MEDIA_GRP_ID_IC_PRPENC:
+   case IMX_MEDIA_GRP_ID_IPU_IC_PRPENC:
priv->task_id = IC_TASK_ENCODER;
break;
-   case IMX_MEDIA_GRP_ID_IC_PRPVF:
+   case IMX_MEDIA_GRP_ID_IPU_IC_PRPVF:
priv->task_id = IC_TASK_VIEWFINDER;
break;
default:
diff --git a/drivers/staging/media/imx/imx-ic-prp.c 
b/drivers/staging/media/imx/imx-ic-prp.c
index 98923fc844ce..795ca61f7cea 100644
--- a/drivers/staging/media/imx/imx-ic-prp.c
+++ b/drivers/staging/media/imx/imx-ic-prp.c
@@ -77,7 +77,7 @@ static int prp_start(struct prp_priv *priv)
priv->ipu = priv->md->ipu[ic_priv->ipu_id];
 
/* set IC to receive from CSI or VDI depending on source */
-   src_is_vdic = !!(priv->src_sd->grp_id & IMX_MEDIA_GRP_ID_VDIC);
+   src_is_vdic = !!(priv->src_sd->grp_id & IMX_MEDIA_GRP_ID_IPU_VDIC);
 
ipu_set_ic_src_mux(priv->ipu, priv->csi_id, src_is_vdic);
 
@@ -238,7 +238,7 @@ static int prp_link_setup(struct media_entity *entity,
goto out;
}
if (priv->sink_sd_prpenc && (remote_sd->grp_id &
-IMX_MEDIA_GRP_ID_VDIC)) {
+
IMX_MEDIA_GRP_ID_IPU_VDIC)) {
ret = -EINVAL;
goto out;
}
@@ -259,7 +259,7 @@ static int prp_link_setup(struct media_entity *entity,
goto out;
}
if (priv->src_sd && (priv->src_sd->grp_id &
-IMX_MEDIA_GRP_ID_VDIC)) {
+IMX_MEDIA_GRP_ID_IPU_VDIC)) {
ret = -EINVAL;
goto out;
}
@@ -309,13 +309,13 @@ static int prp_link_validate(struct v4l2_subdev *sd,
return ret;
 
csi = imx_media_find_upstream_subdev(priv->md, _priv->sd.entity,
-IMX_MEDIA_GRP_ID_CSI);
+IMX_MEDIA_GRP_ID_IPU_CSI);
if (IS_ERR(csi))
csi = NULL;
 
mutex_lock(>lock);
 
-   if (priv->src_sd->grp_id & IMX_MEDIA_GRP_ID_VDIC) {
+   if (priv->src_sd->grp_id & IMX_MEDIA_GRP_ID_IPU_VDIC) {
/*
 * the ->PRPENC link cannot be enabled if the source
 * is the VDIC
@@ -334,10 +334,10 @@ static int prp_link_validate(struct v4l2_subdev *sd,
 
if (csi) {
switch (csi->grp_id) {
-   case IMX_MEDIA_GRP_ID_CSI0:
+   case IMX_MEDIA_GRP_ID_IPU_CSI0:
priv->csi_id = 0;
break;
-   case IMX_MEDIA_GRP_ID_CSI1:
+   case IMX_MEDIA_GRP_ID_IPU_CSI1:
priv->csi_id = 1;
break;
default:
diff --git a/drivers/staging/media/imx/imx-media-csi.c 
b/drivers/staging/media/imx/imx-media-csi.c
index 4223f8d418ae..a12fa1dd989e 100644
--- a/drivers/staging/media/imx/imx-media-csi.c
+++ b/drivers/staging/media/imx/imx-media-csi.c
@@ -1029,10 +1029,10 @@ static int csi_link_setup(struct media_entity *entity,
 
remote_sd = media_entity_to_v4l2_subdev(remote->entity);
switch (remote_sd->grp_id) {
-   case IMX_MEDIA_GRP_ID_VDIC:
+  

[PATCH v8 11/12] media: staging/imx: add i.MX7 entries to TODO file

2018-11-21 Thread Rui Miguel Silva
Add some i.MX7 related entries to TODO file.

Signed-off-by: Rui Miguel Silva 
---
 drivers/staging/media/imx/TODO | 9 +
 1 file changed, 9 insertions(+)

diff --git a/drivers/staging/media/imx/TODO b/drivers/staging/media/imx/TODO
index aeeb15494a49..6f29b5ca5324 100644
--- a/drivers/staging/media/imx/TODO
+++ b/drivers/staging/media/imx/TODO
@@ -45,3 +45,12 @@
 
  Which means a port must not contain mixed-use endpoints, they
  must all refer to media links between V4L2 subdevices.
+
+- i.MX7: all of the above, since it uses the imx media core
+
+- i.MX7: use Frame Interval Monitor
+
+- i.MX7: runtime testing with parallel sensor, links setup and streaming
+
+- i.MX7: runtime testing with different formats, for the time only 10-bit bayer
+  is tested
-- 
2.19.1



[PATCH v8 08/12] ARM: dts: imx7: Add video mux, csi and mipi_csi and connections

2018-11-21 Thread Rui Miguel Silva
This patch adds the device tree nodes for csi, video multiplexer and mipi-csi
besides the graph connecting the necessary endpoints to make the media capture
entities to work in imx7 Warp board.

Signed-off-by: Rui Miguel Silva 
---
 arch/arm/boot/dts/imx7s-warp.dts | 51 
 arch/arm/boot/dts/imx7s.dtsi | 27 +
 2 files changed, 78 insertions(+)

diff --git a/arch/arm/boot/dts/imx7s-warp.dts b/arch/arm/boot/dts/imx7s-warp.dts
index f7ba2c0a24ad..757856a3964b 100644
--- a/arch/arm/boot/dts/imx7s-warp.dts
+++ b/arch/arm/boot/dts/imx7s-warp.dts
@@ -276,6 +276,57 @@
status = "okay";
 };
 
+ {
+   csi_mux {
+   compatible = "video-mux";
+   mux-controls = < 0>;
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   port@1 {
+   reg = <1>;
+
+   csi_mux_from_mipi_vc0: endpoint {
+   remote-endpoint = <_vc0_to_csi_mux>;
+   };
+   };
+
+   port@2 {
+   reg = <2>;
+
+   csi_mux_to_csi: endpoint {
+   remote-endpoint = <_from_csi_mux>;
+   };
+   };
+   };
+};
+
+ {
+   status = "okay";
+
+   port {
+   csi_from_csi_mux: endpoint {
+   remote-endpoint = <_mux_to_csi>;
+   };
+   };
+};
+
+_csi {
+   clock-frequency = <16600>;
+   status = "okay";
+   #address-cells = <1>;
+   #size-cells = <0>;
+   fsl,csis-hs-settle = <3>;
+
+   port@1 {
+   reg = <1>;
+
+   mipi_vc0_to_csi_mux: endpoint {
+   remote-endpoint = <_mux_from_mipi_vc0>;
+   };
+   };
+};
+
  {
pinctrl-names = "default";
pinctrl-0 = <_wdog>;
diff --git a/arch/arm/boot/dts/imx7s.dtsi b/arch/arm/boot/dts/imx7s.dtsi
index 964f19c997d4..fbd2886241b0 100644
--- a/arch/arm/boot/dts/imx7s.dtsi
+++ b/arch/arm/boot/dts/imx7s.dtsi
@@ -8,6 +8,7 @@
 #include 
 #include 
 #include 
+#include 
 #include "imx7d-pinfunc.h"
 
 / {
@@ -710,6 +711,17 @@
status = "disabled";
};
 
+   csi: csi@3071 {
+   compatible = "fsl,imx7-csi";
+   reg = <0x3071 0x1>;
+   interrupts = ;
+   clocks = < IMX7D_CLK_DUMMY>,
+   < IMX7D_CSI_MCLK_ROOT_CLK>,
+   < IMX7D_CLK_DUMMY>;
+   clock-names = "axi", "mclk", "dcic";
+   status = "disabled";
+   };
+
lcdif: lcdif@3073 {
compatible = "fsl,imx7d-lcdif", 
"fsl,imx28-lcdif";
reg = <0x3073 0x1>;
@@ -719,6 +731,21 @@
clock-names = "pix", "axi";
status = "disabled";
};
+
+   mipi_csi: mipi-csi@3075 {
+   compatible = "fsl,imx7-mipi-csi2";
+   reg = <0x3075 0x1>;
+   interrupts = ;
+   clocks = < IMX7D_IPG_ROOT_CLK>,
+   < IMX7D_MIPI_CSI_ROOT_CLK>,
+   < 
IMX7D_MIPI_DPHY_ROOT_CLK>;
+   clock-names = "pclk", "wrap", "phy";
+   power-domains = <_mipi_phy>;
+   phy-supply = <_1p0d>;
+   resets = < IMX7_RESET_MIPI_PHY_MRST>;
+   reset-names = "mrst";
+   status = "disabled";
+   };
};
 
aips3: aips-bus@3080 {
-- 
2.19.1



[PATCH v8 10/12] media: imx7.rst: add documentation for i.MX7 media driver

2018-11-21 Thread Rui Miguel Silva
Add rst document to describe the i.MX7 media driver and also a working
example from the Warp7 board usage with a OV2680 sensor.

Signed-off-by: Rui Miguel Silva 
---
 Documentation/media/v4l-drivers/imx7.rst  | 157 ++
 Documentation/media/v4l-drivers/index.rst |   1 +
 2 files changed, 158 insertions(+)
 create mode 100644 Documentation/media/v4l-drivers/imx7.rst

diff --git a/Documentation/media/v4l-drivers/imx7.rst 
b/Documentation/media/v4l-drivers/imx7.rst
new file mode 100644
index ..cd1195d391c5
--- /dev/null
+++ b/Documentation/media/v4l-drivers/imx7.rst
@@ -0,0 +1,157 @@
+i.MX7 Video Capture Driver
+==
+
+Introduction
+
+
+The i.MX7 contrary to the i.MX5/6 family does not contain an Image Processing
+Unit (IPU); because of that the capabilities to perform operations or
+manipulation of the capture frames are less feature rich.
+
+For image capture the i.MX7 has three units:
+- CMOS Sensor Interface (CSI)
+- Video Multiplexer
+- MIPI CSI-2 Receiver
+
+::
+   |\
+   MIPI Camera Input ---> MIPI CSI-2 --- > | \
+   |  \
+   | M |
+   | U | -->  CSI ---> Capture
+   | X |
+   |  /
+   Parallel Camera Input > | /
+   |/
+
+For additional information, please refer to the latest versions of the i.MX7
+reference manual [#f1]_.
+
+Entities
+
+
+imx7-mipi-csi2
+--
+
+This is the MIPI CSI-2 receiver entity. It has one sink pad to receive the 
pixel
+data from MIPI CSI-2 camera sensor. It has one source pad, corresponding to the
+virtual channel 0. This module is compliant to previous version of Samsung
+D-phy, and supports two D-PHY Rx Data lanes.
+
+csi_mux
+---
+
+This is the video multiplexer. It has two sink pads to select from either 
camera
+sensor with a parallel interface or from MIPI CSI-2 virtual channel 0.  It has
+a single source pad that routes to the CSI.
+
+csi
+---
+
+The CSI enables the chip to connect directly to external CMOS image sensor. CSI
+can interface directly with Parallel and MIPI CSI-2 buses. It has 256 x 64 FIFO
+to store received image pixel data and embedded DMA controllers to transfer 
data
+from the FIFO through AHB bus.
+
+This entity has one sink pad that receives from the csi_mux entity and a single
+source pad that routes video frames directly to memory buffers. This pad is
+routed to a capture device node.
+
+Usage Notes
+---
+
+To aid in configuration and for backward compatibility with V4L2 applications
+that access controls only from video device nodes, the capture device 
interfaces
+inherit controls from the active entities in the current pipeline, so controls
+can be accessed either directly from the subdev or from the active capture
+device interface. For example, the sensor controls are available either from 
the
+sensor subdevs or from the active capture device.
+
+Warp7 with OV2680
+-
+
+On this platform an OV2680 MIPI CSI-2 module is connected to the internal MIPI
+CSI-2 receiver. The following example configures a video capture pipeline with
+an output of 800x600, and BGGR 10 bit bayer format:
+
+.. code-block:: none
+   # Setup links
+   media-ctl -l "'ov2680 1-0036':0 -> 'imx7-mipi-csis.0':0[1]"
+   media-ctl -l "'imx7-mipi-csis.0':1 -> 'csi_mux':1[1]"
+   media-ctl -l "'csi_mux':2 -> 'csi':0[1]"
+   media-ctl -l "'csi':1 -> 'csi capture':0[1]"
+
+   # Configure pads for pipeline
+   media-ctl -V "'ov2680 1-0036':0 [fmt:SBGGR10_1X10/800x600 field:none]"
+   media-ctl -V "'csi_mux':1 [fmt:SBGGR10_1X10/800x600 field:none]"
+   media-ctl -V "'csi_mux':2 [fmt:SBGGR10_1X10/800x600 field:none]"
+   media-ctl -V "'imx7-mipi-csis.0':0 [fmt:SBGGR10_1X10/800x600 field:none]"
+   media-ctl -V "'csi':0 [fmt:SBGGR10_1X10/800x600 field:none]"
+
+After this streaming can start. The v4l2-ctl tool can be used to select any of
+the resolutions supported by the sensor.
+
+.. code-block:: none
+root@imx7s-warp:~# media-ctl -p
+Media controller API version 4.17.0
+
+Media device information
+
+driver  imx-media
+model   imx-media
+serial
+bus info
+hw revision 0x0
+driver version  4.17.0
+
+Device topology
+- entity 1: csi (2 pads, 2 links)
+   type V4L2 subdev subtype Unknown flags 0
+   device node name /dev/v4l-subdev0
+   pad0: Sink
+   [fmt:SBGGR10_1X10/800x600 field:none]
+   <- "csi_mux":2 [ENABLED]
+   pad1: Source
+   [fmt:SBGGR10_1X10/800x600 field:none]
+   -> "csi capture":0 [ENABLED]
+
+- entity 4: csi capture (1 pad, 1 link)
+   type Node subtype 

[PATCH v8 01/12] media: staging/imx: refactor imx media device probe

2018-11-21 Thread Rui Miguel Silva
Refactor and move media device initialization code to a new common module, so it
can be used by other devices, this will allow for example a near to introduce
imx7 CSI driver, to use this media device.

Signed-off-by: Rui Miguel Silva 
---
 drivers/staging/media/imx/Makefile|  1 +
 drivers/staging/media/imx/imx-media-dev.c | 88 +--
 drivers/staging/media/imx/imx-media-of.c  |  6 +-
 drivers/staging/media/imx/imx-media.h | 15 
 4 files changed, 39 insertions(+), 71 deletions(-)

diff --git a/drivers/staging/media/imx/Makefile 
b/drivers/staging/media/imx/Makefile
index 698a4210316e..a30b3033f9a3 100644
--- a/drivers/staging/media/imx/Makefile
+++ b/drivers/staging/media/imx/Makefile
@@ -1,5 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0
 imx-media-objs := imx-media-dev.o imx-media-internal-sd.o imx-media-of.o
+imx-media-objs += imx-media-dev-common.o
 imx-media-common-objs := imx-media-utils.o imx-media-fim.o
 imx-media-ic-objs := imx-ic-common.o imx-ic-prp.o imx-ic-prpencvf.o
 
diff --git a/drivers/staging/media/imx/imx-media-dev.c 
b/drivers/staging/media/imx/imx-media-dev.c
index 4b344a4a3706..21f65af5c738 100644
--- a/drivers/staging/media/imx/imx-media-dev.c
+++ b/drivers/staging/media/imx/imx-media-dev.c
@@ -116,9 +116,9 @@ static int imx_media_get_ipu(struct imx_media_dev *imxmd,
 }
 
 /* async subdev bound notifier */
-static int imx_media_subdev_bound(struct v4l2_async_notifier *notifier,
- struct v4l2_subdev *sd,
- struct v4l2_async_subdev *asd)
+int imx_media_subdev_bound(struct v4l2_async_notifier *notifier,
+  struct v4l2_subdev *sd,
+  struct v4l2_async_subdev *asd)
 {
struct imx_media_dev *imxmd = notifier2dev(notifier);
int ret = 0;
@@ -302,7 +302,7 @@ static int imx_media_create_pad_vdev_lists(struct 
imx_media_dev *imxmd)
 }
 
 /* async subdev complete notifier */
-static int imx_media_probe_complete(struct v4l2_async_notifier *notifier)
+int imx_media_probe_complete(struct v4l2_async_notifier *notifier)
 {
struct imx_media_dev *imxmd = notifier2dev(notifier);
int ret;
@@ -326,11 +326,6 @@ static int imx_media_probe_complete(struct 
v4l2_async_notifier *notifier)
return media_device_register(>md);
 }
 
-static const struct v4l2_async_notifier_operations imx_media_subdev_ops = {
-   .bound = imx_media_subdev_bound,
-   .complete = imx_media_probe_complete,
-};
-
 /*
  * adds controls to a video device from an entity subdevice.
  * Continues upstream from the entity's sink pads.
@@ -374,8 +369,8 @@ static int imx_media_inherit_controls(struct imx_media_dev 
*imxmd,
return ret;
 }
 
-static int imx_media_link_notify(struct media_link *link, u32 flags,
-unsigned int notification)
+int imx_media_link_notify(struct media_link *link, u32 flags,
+ unsigned int notification)
 {
struct media_entity *source = link->source->entity;
struct imx_media_pad_vdev *pad_vdev;
@@ -438,10 +433,6 @@ static int imx_media_link_notify(struct media_link *link, 
u32 flags,
return ret;
 }
 
-static const struct media_device_ops imx_media_md_ops = {
-   .link_notify = imx_media_link_notify,
-};
-
 static int imx_media_probe(struct platform_device *pdev)
 {
struct device *dev = >dev;
@@ -449,76 +440,36 @@ static int imx_media_probe(struct platform_device *pdev)
struct imx_media_dev *imxmd;
int ret;
 
-   imxmd = devm_kzalloc(dev, sizeof(*imxmd), GFP_KERNEL);
-   if (!imxmd)
-   return -ENOMEM;
-
-   dev_set_drvdata(dev, imxmd);
-
-   strscpy(imxmd->md.model, "imx-media", sizeof(imxmd->md.model));
-   imxmd->md.ops = _media_md_ops;
-   imxmd->md.dev = dev;
-
-   mutex_init(>mutex);
-
-   imxmd->v4l2_dev.mdev = >md;
-   strscpy(imxmd->v4l2_dev.name, "imx-media",
-   sizeof(imxmd->v4l2_dev.name));
-
-   media_device_init(>md);
-
-   ret = v4l2_device_register(dev, >v4l2_dev);
-   if (ret < 0) {
-   v4l2_err(>v4l2_dev,
-"Failed to register v4l2_device: %d\n", ret);
-   goto cleanup;
-   }
-
-   dev_set_drvdata(imxmd->v4l2_dev.dev, imxmd);
-
-   INIT_LIST_HEAD(>vdev_list);
-
-   v4l2_async_notifier_init(>notifier);
+   imxmd = imx_media_dev_init(dev);
+   if (IS_ERR(imxmd))
+   return PTR_ERR(imxmd);
 
ret = imx_media_add_of_subdevs(imxmd, node);
if (ret) {
v4l2_err(>v4l2_dev,
 "add_of_subdevs failed with %d\n", ret);
-   goto notifier_cleanup;
+   goto dev_cleanup;
}
 
ret = imx_media_add_internal_subdevs(imxmd);
if (ret) {
v4l2_err(>v4l2_dev,
 "add_internal_subdevs failed with %d\n", ret);
-   goto 

[PATCH] media: ov2680: fix null dereference at power on

2018-11-21 Thread Rui Miguel Silva
Swapping the order between v4l2 subdevice registration and checking chip id in
b7a417628abf ("media: ov2680: don't register the v4l2 subdevice before checking 
chip ID")
makes the mode restore to use the sensor controls before they are set, so move
the mode restore call to s_power after the handler setup for controls is done.

This remove also the need for the error code path in power on function.

Fixes: b7a417628abf ("media: ov2680: don't register the v4l2 subdevice before 
checking chip ID")

Signed-off-by: Rui Miguel Silva 
---
 drivers/media/i2c/ov2680.c | 12 ++--
 1 file changed, 2 insertions(+), 10 deletions(-)

diff --git a/drivers/media/i2c/ov2680.c b/drivers/media/i2c/ov2680.c
index 0e34e15b67b3..b10bcfabaeeb 100644
--- a/drivers/media/i2c/ov2680.c
+++ b/drivers/media/i2c/ov2680.c
@@ -568,10 +568,6 @@ static int ov2680_power_on(struct ov2680_dev *sensor)
if (ret < 0)
return ret;
 
-   ret = ov2680_mode_restore(sensor);
-   if (ret < 0)
-   goto disable;
-
sensor->is_enabled = true;
 
/* Set clock lane into LP-11 state */
@@ -580,12 +576,6 @@ static int ov2680_power_on(struct ov2680_dev *sensor)
ov2680_stream_disable(sensor);
 
return 0;
-
-disable:
-   dev_err(dev, "failed to enable sensor: %d\n", ret);
-   ov2680_power_off(sensor);
-
-   return ret;
 }
 
 static int ov2680_s_power(struct v4l2_subdev *sd, int on)
@@ -606,6 +596,8 @@ static int ov2680_s_power(struct v4l2_subdev *sd, int on)
ret = v4l2_ctrl_handler_setup(>ctrls.handler);
if (ret < 0)
return ret;
+
+   ret = ov2680_mode_restore(sensor);
}
 
return ret;
-- 
2.19.1



[GIT PULL FOR v4.21] Various fixes/improvements

2018-11-21 Thread Hans Verkuil
Note: this supersedes https://patchwork.linuxtv.org/patch/53017/. The only 
change
is an updated device_caps patch: https://patchwork.linuxtv.org/patch/53057/

Regards,

Hans

The following changes since commit 5200ab6a32d6055428896a49ec9e3b1652c1a100:

  media: vidioc_cropcap -> vidioc_g_pixelaspect (2018-11-20 13:57:21 -0500)

are available in the Git repository at:

  git://linuxtv.org/hverkuil/media_tree.git tags/br-v4.21dv2

for you to fetch changes up to 982a0280d5b59963b32e32b14dd77cc14697dfc7:

  media: vicodec: Add support for 4 planes formats (2018-11-21 09:40:32 +0100)


Tag branch


Akinobu Mita (5):
  media: video-i2c: avoid accessing released memory area when removing 
driver
  media: video-i2c: use i2c regmap
  media: v4l2-common: add V4L2_FRACT_COMPARE
  media: vivid: use V4L2_FRACT_COMPARE
  media: video-i2c: support changing frame interval

Alexey Khoroshilov (1):
  media: mtk-vcodec: Release device nodes in mtk_vcodec_init_enc_pm()

Dafna Hirschfeld (3):
  media: vicodec: prepare support for various number of planes
  media: vicodec: Add support of greyscale format
  media: vicodec: Add support for 4 planes formats

Eric Biggers (1):
  media: v4l: constify v4l2_ioctls[]

Hans Verkuil (2):
  vim2m/vicodec: set device_caps in video_device struct
  vidioc-enum-fmt.rst: update list of valid buftypes

Julia Lawall (1):
  media: video-i2c: hwmon: constify vb2_ops structure

Malathi Gottam (1):
  media: venus: change the default value of GOP size

 Documentation/media/uapi/v4l/vidioc-enum-fmt.rst  |   8 ++-
 drivers/media/i2c/video-i2c.c | 153 
+++--
 drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c |  10 ++--
 drivers/media/platform/qcom/venus/venc_ctrls.c|   2 +-
 drivers/media/platform/vicodec/codec-fwht.c   |  84 
+--
 drivers/media/platform/vicodec/codec-fwht.h   |  15 +++--
 drivers/media/platform/vicodec/codec-v4l2-fwht.c  | 123 
+--
 drivers/media/platform/vicodec/codec-v4l2-fwht.h  |   3 +-
 drivers/media/platform/vicodec/vicodec-core.c |  45 +++
 drivers/media/platform/vim2m.c|   3 +-
 drivers/media/platform/vivid/vivid-vid-cap.c  |   9 +--
 drivers/media/v4l2-core/v4l2-ioctl.c  |   2 +-
 include/media/v4l2-common.h   |   5 ++
 13 files changed, 328 insertions(+), 134 deletions(-)


[PATCH v2] vim2m/vicodec: set device_caps in video_device struct

2018-11-21 Thread Hans Verkuil
Instead of setting device_caps/capabilities in the querycap ioctl, set
it in struct video_device instead.

Signed-off-by: Hans Verkuil 
---
Changes in v2: vfd->device_caps was only set for the first of the two video
devices. Set it for the second video_device as well.
---
 drivers/media/platform/vicodec/vicodec-core.c | 9 -
 drivers/media/platform/vim2m.c| 3 +--
 2 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/drivers/media/platform/vicodec/vicodec-core.c 
b/drivers/media/platform/vicodec/vicodec-core.c
index b292cff26c86..9b6416ba5901 100644
--- a/drivers/media/platform/vicodec/vicodec-core.c
+++ b/drivers/media/platform/vicodec/vicodec-core.c
@@ -397,11 +397,6 @@ static int vidioc_querycap(struct file *file, void *priv,
strncpy(cap->card, VICODEC_NAME, sizeof(cap->card) - 1);
snprintf(cap->bus_info, sizeof(cap->bus_info),
"platform:%s", VICODEC_NAME);
-   cap->device_caps =  V4L2_CAP_STREAMING |
-   (multiplanar ?
-V4L2_CAP_VIDEO_M2M_MPLANE :
-V4L2_CAP_VIDEO_M2M);
-   cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
return 0;
 }

@@ -1311,6 +1306,8 @@ static int vicodec_probe(struct platform_device *pdev)
vfd->lock = >enc_mutex;
vfd->v4l2_dev = >v4l2_dev;
strscpy(vfd->name, "vicodec-enc", sizeof(vfd->name));
+   vfd->device_caps = V4L2_CAP_STREAMING |
+   (multiplanar ? V4L2_CAP_VIDEO_M2M_MPLANE : V4L2_CAP_VIDEO_M2M);
v4l2_disable_ioctl(vfd, VIDIOC_DECODER_CMD);
v4l2_disable_ioctl(vfd, VIDIOC_TRY_DECODER_CMD);
video_set_drvdata(vfd, dev);
@@ -1327,6 +1324,8 @@ static int vicodec_probe(struct platform_device *pdev)
vfd = >dec_vfd;
vfd->lock = >dec_mutex;
vfd->v4l2_dev = >v4l2_dev;
+   vfd->device_caps = V4L2_CAP_STREAMING |
+   (multiplanar ? V4L2_CAP_VIDEO_M2M_MPLANE : V4L2_CAP_VIDEO_M2M);
strscpy(vfd->name, "vicodec-dec", sizeof(vfd->name));
v4l2_disable_ioctl(vfd, VIDIOC_ENCODER_CMD);
v4l2_disable_ioctl(vfd, VIDIOC_TRY_ENCODER_CMD);
diff --git a/drivers/media/platform/vim2m.c b/drivers/media/platform/vim2m.c
index d82db738f174..035c7b7c8d87 100644
--- a/drivers/media/platform/vim2m.c
+++ b/drivers/media/platform/vim2m.c
@@ -438,8 +438,6 @@ static int vidioc_querycap(struct file *file, void *priv,
strncpy(cap->card, MEM2MEM_NAME, sizeof(cap->card) - 1);
snprintf(cap->bus_info, sizeof(cap->bus_info),
"platform:%s", MEM2MEM_NAME);
-   cap->device_caps = V4L2_CAP_VIDEO_M2M | V4L2_CAP_STREAMING;
-   cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
return 0;
 }

@@ -999,6 +997,7 @@ static const struct video_device vim2m_videodev = {
.ioctl_ops  = _ioctl_ops,
.minor  = -1,
.release= video_device_release_empty,
+   .device_caps= V4L2_CAP_VIDEO_M2M | V4L2_CAP_STREAMING,
 };

 static const struct v4l2_m2m_ops m2m_ops = {
-- 
2.19.1