Re: [PATCH 0/3] Add support compat in dvb_frontend.c

2017-12-01 Thread Mauro Carvalho Chehab
Hi Jaedon,

Em Fri,  1 Dec 2017 21:31:27 +0900
Jaedon Shin  escreveu:

> This patch series supports compat ioctl for 32-bit user space applications
> in 64-bit system.
> 
> Jaedon Shin (3):
>   media: dvb_frontend: Add unlocked_ioctl in dvb_frontend.c
>   media: dvb_frontend: Add compat_ioctl callback
>   media: dvb_frontend: Add commands implementation for compat ioct

Thanks for the series. Yeah, indeed we need something like that.

Yet, I suspect that you should also move the logic inside
dvb_frontend_handle_ioctl() with copies from/to userspace.

We don't want the logic there to be called when a 32-bit userspace
copy happens, as it should now use the new compat32 code.


Thanks,
Mauro


[PATCH] [media] soc_camera: add MODULE_LICENSE to soc_scale_crop.c

2017-12-01 Thread Daniel Axtens
This fixes the following warning on an allmodconfig build:
WARNING: modpost: missing MODULE_LICENSE() in 
drivers/media/platform/soc_camera/soc_scale_crop.o

Use license "GPL" to match the GPLv2+ license from the header at
the top of the file.

Signed-off-by: Daniel Axtens 
---
 drivers/media/platform/soc_camera/soc_scale_crop.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/media/platform/soc_camera/soc_scale_crop.c 
b/drivers/media/platform/soc_camera/soc_scale_crop.c
index 270ec613c27c..095753951888 100644
--- a/drivers/media/platform/soc_camera/soc_scale_crop.c
+++ b/drivers/media/platform/soc_camera/soc_scale_crop.c
@@ -420,3 +420,5 @@ void soc_camera_calc_client_output(struct soc_camera_device 
*icd,
mf->height = soc_camera_shift_scale(rect->height, shift, scale_v);
 }
 EXPORT_SYMBOL(soc_camera_calc_client_output);
+
+MODULE_LICENSE("GPL");
-- 
2.11.0



[PATCH] media: tegra-cec: add MODULE_LICENSE()

2017-12-01 Thread Daniel Axtens
This fixes the following warning in an allmodconfig build:
WARNING: modpost: missing MODULE_LICENSE() in 
drivers/media/platform/tegra-cec/tegra_cec.o

The license matches the header.

Signed-off-by: Daniel Axtens 
---
 drivers/media/platform/tegra-cec/tegra_cec.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/media/platform/tegra-cec/tegra_cec.c 
b/drivers/media/platform/tegra-cec/tegra_cec.c
index 807c94c70049..680884a69f9f 100644
--- a/drivers/media/platform/tegra-cec/tegra_cec.c
+++ b/drivers/media/platform/tegra-cec/tegra_cec.c
@@ -493,3 +493,5 @@ static struct platform_driver tegra_cec_driver = {
 };
 
 module_platform_driver(tegra_cec_driver);
+
+MODULE_LICENSE("GPL v2");
-- 
2.11.0



cron job: media_tree daily build: ERRORS

2017-12-01 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:   Sat Dec  2 05:00:16 CET 2017
media-tree git hash:781b045baefdabf7e0bc9f33672ca830d3db9f27
media_build git hash:   320b9b80ebbf318a67a9479c18a0e4be244c8409
v4l-utils git hash: 26eca33b62f988ecbc4df8134ebdef20f9f75c97
gcc version:i686-linux-gcc (GCC) 7.1.0
sparse version: 0.5.1 (Debian: 0.5.1-2)
smatch version: v0.5.0-3553-g78b2ea6
host hardware:  x86_64
host os:4.13.0-164

linux-git-arm-at91: OK
linux-git-arm-davinci: OK
linux-git-arm-multi: OK
linux-git-arm-pxa: OK
linux-git-arm-stm32: OK
linux-git-blackfin-bf561: OK
linux-git-i686: OK
linux-git-m32r: OK
linux-git-mips: OK
linux-git-powerpc64: OK
linux-git-sh: OK
linux-git-x86_64: OK
linux-2.6.36.4-i686: ERRORS
linux-2.6.37.6-i686: ERRORS
linux-2.6.38.8-i686: ERRORS
linux-2.6.39.4-i686: ERRORS
linux-3.0.60-i686: ERRORS
linux-3.1.10-i686: ERRORS
linux-3.2.37-i686: ERRORS
linux-3.3.8-i686: ERRORS
linux-3.4.27-i686: ERRORS
linux-3.5.7-i686: ERRORS
linux-3.6.11-i686: ERRORS
linux-3.7.4-i686: ERRORS
linux-3.8-i686: ERRORS
linux-3.9.2-i686: ERRORS
linux-3.10.1-i686: ERRORS
linux-3.11.1-i686: ERRORS
linux-3.12.67-i686: ERRORS
linux-3.13.11-i686: ERRORS
linux-3.14.9-i686: ERRORS
linux-3.15.2-i686: ERRORS
linux-3.16.7-i686: ERRORS
linux-3.17.8-i686: ERRORS
linux-3.18.7-i686: ERRORS
linux-3.19-i686: ERRORS
linux-4.0.9-i686: ERRORS
linux-4.1.33-i686: ERRORS
linux-4.2.8-i686: ERRORS
linux-4.3.6-i686: ERRORS
linux-4.4.22-i686: ERRORS
linux-4.5.7-i686: ERRORS
linux-4.6.7-i686: ERRORS
linux-4.7.5-i686: ERRORS
linux-4.8-i686: ERRORS
linux-4.9.26-i686: ERRORS
linux-4.10.14-i686: ERRORS
linux-4.11-i686: ERRORS
linux-4.12.1-i686: ERRORS
linux-4.13-i686: ERRORS
linux-4.14-i686: ERRORS
linux-2.6.36.4-x86_64: ERRORS
linux-2.6.37.6-x86_64: ERRORS
linux-2.6.38.8-x86_64: ERRORS
linux-2.6.39.4-x86_64: ERRORS
linux-3.0.60-x86_64: ERRORS
linux-3.1.10-x86_64: ERRORS
linux-3.2.37-x86_64: ERRORS
linux-3.3.8-x86_64: ERRORS
linux-3.4.27-x86_64: ERRORS
linux-3.5.7-x86_64: ERRORS
linux-3.6.11-x86_64: ERRORS
linux-3.7.4-x86_64: ERRORS
linux-3.8-x86_64: ERRORS
linux-3.9.2-x86_64: ERRORS
linux-3.10.1-x86_64: ERRORS
linux-3.11.1-x86_64: ERRORS
linux-3.12.67-x86_64: ERRORS
linux-3.13.11-x86_64: ERRORS
linux-3.14.9-x86_64: ERRORS
linux-3.15.2-x86_64: ERRORS
linux-3.16.7-x86_64: ERRORS
linux-3.17.8-x86_64: ERRORS
linux-3.18.7-x86_64: ERRORS
linux-3.19-x86_64: ERRORS
linux-4.0.9-x86_64: ERRORS
linux-4.1.33-x86_64: ERRORS
linux-4.2.8-x86_64: ERRORS
linux-4.3.6-x86_64: ERRORS
linux-4.4.22-x86_64: ERRORS
linux-4.5.7-x86_64: ERRORS
linux-4.6.7-x86_64: ERRORS
linux-4.7.5-x86_64: ERRORS
linux-4.8-x86_64: ERRORS
linux-4.9.26-x86_64: ERRORS
linux-4.10.14-x86_64: ERRORS
linux-4.11-x86_64: ERRORS
linux-4.12.1-x86_64: ERRORS
linux-4.13-x86_64: ERRORS
linux-4.14-x86_64: ERRORS
apps: OK
spec-git: OK

Detailed results are available here:

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

Full logs are available here:

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

The Media Infrastructure API from this daily build is here:

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


[PATCH v5 11/12] intel-ipu3: Add v4l2 driver based on media framework

2017-12-01 Thread Yong Zhi
This implements video driver that utilizes v4l2, vb2 queue
support and media controller APIs. The driver exposes single
subdevice and seven nodes.

Signed-off-by: Yong Zhi 
Signed-off-by: Ramya Vijaykumar 
---
 drivers/media/pci/intel/ipu3/ipu3-v4l2.c | 1066 ++
 1 file changed, 1066 insertions(+)
 create mode 100644 drivers/media/pci/intel/ipu3/ipu3-v4l2.c

diff --git a/drivers/media/pci/intel/ipu3/ipu3-v4l2.c 
b/drivers/media/pci/intel/ipu3/ipu3-v4l2.c
new file mode 100644
index ..a1f9a8f6
--- /dev/null
+++ b/drivers/media/pci/intel/ipu3/ipu3-v4l2.c
@@ -0,0 +1,1066 @@
+/*
+ * Copyright (c) 2017 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License version
+ * 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include 
+#include 
+
+#include 
+
+#include "ipu3.h"
+#include "ipu3-dmamap.h"
+
+/ v4l2_subdev_ops /
+
+static int ipu3_subdev_s_stream(struct v4l2_subdev *sd, int enable)
+{
+   struct imgu_device *imgu = container_of(sd, struct imgu_device, subdev);
+   int r = 0;
+
+   r = imgu_s_stream(imgu, enable);
+   if (!r)
+   imgu->streaming = enable;
+
+   return r;
+}
+
+static int ipu3_subdev_get_fmt(struct v4l2_subdev *sd,
+  struct v4l2_subdev_pad_config *cfg,
+  struct v4l2_subdev_format *fmt)
+{
+   struct imgu_device *imgu = container_of(sd, struct imgu_device, subdev);
+   struct v4l2_mbus_framefmt *mf;
+   u32 pad = fmt->pad;
+
+   if (fmt->which == V4L2_SUBDEV_FORMAT_ACTIVE) {
+   fmt->format = imgu->nodes[pad].pad_fmt;
+   } else {
+   mf = v4l2_subdev_get_try_format(sd, cfg, pad);
+   fmt->format = *mf;
+   }
+
+   return 0;
+}
+
+static int ipu3_subdev_set_fmt(struct v4l2_subdev *sd,
+  struct v4l2_subdev_pad_config *cfg,
+  struct v4l2_subdev_format *fmt)
+{
+   struct imgu_device *imgu = container_of(sd, struct imgu_device, subdev);
+   struct v4l2_mbus_framefmt *mf;
+   u32 pad = fmt->pad;
+
+   if (fmt->which == V4L2_SUBDEV_FORMAT_TRY)
+   mf = v4l2_subdev_get_try_format(sd, cfg, pad);
+   else
+   mf = >nodes[pad].pad_fmt;
+
+   /* Clamp the w and h based on the hardware capabilities */
+   if (imgu->subdev_pads[pad].flags & MEDIA_PAD_FL_SOURCE) {
+   fmt->format.width = clamp(fmt->format.width,
+ IPU3_OUTPUT_MIN_WIDTH,
+ IPU3_OUTPUT_MAX_WIDTH);
+   fmt->format.height = clamp(fmt->format.height,
+  IPU3_OUTPUT_MIN_HEIGHT,
+  IPU3_OUTPUT_MAX_HEIGHT);
+   } else {
+   fmt->format.width = clamp(fmt->format.width,
+ IPU3_INPUT_MIN_WIDTH,
+ IPU3_INPUT_MAX_WIDTH);
+   fmt->format.height = clamp(fmt->format.height,
+  IPU3_INPUT_MIN_HEIGHT,
+  IPU3_INPUT_MAX_HEIGHT);
+   }
+
+   *mf = fmt->format;
+
+   return 0;
+}
+
+static int ipu3_subdev_get_selection(struct v4l2_subdev *sd,
+struct v4l2_subdev_pad_config *cfg,
+struct v4l2_subdev_selection *sel)
+{
+   struct imgu_device *imgu = container_of(sd, struct imgu_device, subdev);
+   struct v4l2_rect *rect, *try_sel;
+
+   if (sel->pad != IMGU_NODE_IN)
+   return -EINVAL;
+
+   switch (sel->target) {
+   case V4L2_SEL_TGT_CROP:
+   try_sel = v4l2_subdev_get_try_crop(sd, cfg, sel->pad);
+   rect = >rect.eff;
+   break;
+   case V4L2_SEL_TGT_COMPOSE:
+   try_sel = v4l2_subdev_get_try_compose(sd, cfg, sel->pad);
+   rect = >rect.bds;
+   break;
+   default:
+   return -EINVAL;
+   }
+
+   if (sel->which == V4L2_SUBDEV_FORMAT_TRY)
+   sel->r = *try_sel;
+   else
+   sel->r = *rect;
+
+   return 0;
+}
+
+static int ipu3_subdev_set_selection(struct v4l2_subdev *sd,
+struct v4l2_subdev_pad_config *cfg,
+struct v4l2_subdev_selection *sel)
+{
+   struct imgu_device *imgu = container_of(sd, struct imgu_device, subdev);
+   

[PATCH v5 12/12] intel-ipu3: Add imgu top level pci device driver

2017-12-01 Thread Yong Zhi
This patch adds support for the Intel IPU v3 as found
on Skylake and Kaby Lake SoCs.

The driver glues v4l2, css(camera sub system) and other
pieces together to perform its functions, it also loads
the IPU3 firmware binary as part of its initialization.

Signed-off-by: Yong Zhi 
Signed-off-by: Tomasz Figa 
---
 drivers/media/pci/intel/ipu3/Kconfig  |  15 +
 drivers/media/pci/intel/ipu3/Makefile |   7 +
 drivers/media/pci/intel/ipu3/ipu3.c   | 883 ++
 3 files changed, 905 insertions(+)
 create mode 100644 drivers/media/pci/intel/ipu3/ipu3.c

diff --git a/drivers/media/pci/intel/ipu3/Kconfig 
b/drivers/media/pci/intel/ipu3/Kconfig
index 91312cd8a26e..49ec4c379c1c 100644
--- a/drivers/media/pci/intel/ipu3/Kconfig
+++ b/drivers/media/pci/intel/ipu3/Kconfig
@@ -32,3 +32,18 @@ config INTEL_IPU3_DMAMAP
select INTEL_IPU3_MMU
---help---
  This is IPU3 IOMMU domain specific DMA driver.
+
+config VIDEO_IPU3_IMGU
+   tristate "Intel ipu3-imgu driver"
+   depends on PCI && VIDEO_V4L2
+   depends on MEDIA_CONTROLLER && VIDEO_V4L2_SUBDEV_API
+   depends on X86 || COMPILE_TEST
+   select INTEL_IPU3_DMAMAP
+   select VIDEOBUF2_DMA_SG
+   ---help---
+ This is the video4linux2 driver for Intel IPU3 image processing unit,
+ found in Intel Skylake and Kaby Lake SoCs and used for processing
+ images and video.
+
+ Say Y or M here if you have a Skylake/Kaby Lake SoC with a MIPI
+ camera.   The module will be called ipu3-imgu.
diff --git a/drivers/media/pci/intel/ipu3/Makefile 
b/drivers/media/pci/intel/ipu3/Makefile
index d2e655b11802..cc040c1b0403 100644
--- a/drivers/media/pci/intel/ipu3/Makefile
+++ b/drivers/media/pci/intel/ipu3/Makefile
@@ -5,3 +5,10 @@
 obj-$(CONFIG_VIDEO_IPU3_CIO2) += ipu3-cio2.o
 obj-$(CONFIG_INTEL_IPU3_MMU) += ipu3-mmu.o
 obj-$(CONFIG_INTEL_IPU3_DMAMAP) += ipu3-dmamap.o
+
+ipu3-imgu-objs += \
+   ipu3-tables.o ipu3-css-pool.o \
+   ipu3-css-fw.o ipu3-css-params.o \
+   ipu3-css.o ipu3-v4l2.o ipu3.o
+
+obj-$(CONFIG_VIDEO_IPU3_IMGU) += ipu3-imgu.o
diff --git a/drivers/media/pci/intel/ipu3/ipu3.c 
b/drivers/media/pci/intel/ipu3/ipu3.c
new file mode 100644
index ..62f15746a4a6
--- /dev/null
+++ b/drivers/media/pci/intel/ipu3/ipu3.c
@@ -0,0 +1,883 @@
+/*
+ * Copyright (c) 2017 Intel Corporation.
+ * Copyright (C) 2017 Google, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License version
+ * 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * Based on Intel IPU4 driver.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+#include "ipu3.h"
+#include "ipu3-dmamap.h"
+#include "ipu3-mmu.h"
+
+#define IMGU_PCI_ID0x1919
+#define IMGU_PCI_BAR   0
+#define IMGU_DMA_MASK  DMA_BIT_MASK(39)
+#define IMGU_MAX_QUEUE_DEPTH   (2 + 2)
+
+/*
+ * pre-allocated buffer size for IMGU dummy buffers. Those
+ * values should be tuned to big enough to avoid buffer
+ * re-allocation when streaming to lower streaming latency.
+ */
+#define CSS_QUEUE_IN_BUF_SIZE  0
+#define CSS_QUEUE_PARAMS_BUF_SIZE  0
+#define CSS_QUEUE_OUT_BUF_SIZE (4160 * 3120 * 12 / 8)
+#define CSS_QUEUE_VF_BUF_SIZE  (1920 * 1080 * 12 / 8)
+#define CSS_QUEUE_STAT_3A_BUF_SIZE 125664
+#define CSS_QUEUE_STAT_DVS_BUF_SIZE10336
+
+static const size_t css_queue_buf_size_map[IPU3_CSS_QUEUES] = {
+   [IPU3_CSS_QUEUE_IN] = CSS_QUEUE_IN_BUF_SIZE,
+   [IPU3_CSS_QUEUE_PARAMS] = CSS_QUEUE_PARAMS_BUF_SIZE,
+   [IPU3_CSS_QUEUE_OUT] = CSS_QUEUE_OUT_BUF_SIZE,
+   [IPU3_CSS_QUEUE_VF] = CSS_QUEUE_VF_BUF_SIZE,
+   [IPU3_CSS_QUEUE_STAT_3A] = CSS_QUEUE_STAT_3A_BUF_SIZE,
+   [IPU3_CSS_QUEUE_STAT_DVS] = CSS_QUEUE_STAT_DVS_BUF_SIZE,
+};
+
+static const struct imgu_node_mapping imgu_node_map[IMGU_NODE_NUM] = {
+   [IMGU_NODE_IN] = {IPU3_CSS_QUEUE_IN, "input"},
+   [IMGU_NODE_PARAMS] = {IPU3_CSS_QUEUE_PARAMS, "parameters"},
+   [IMGU_NODE_OUT] = {IPU3_CSS_QUEUE_OUT, "output"},
+   [IMGU_NODE_VF] = {IPU3_CSS_QUEUE_VF, "viewfinder"},
+   [IMGU_NODE_PV] = {IPU3_CSS_QUEUE_VF, "postview"},
+   [IMGU_NODE_STAT_3A] = {IPU3_CSS_QUEUE_STAT_3A, "3a stat"},
+   [IMGU_NODE_STAT_DVS] = {IPU3_CSS_QUEUE_STAT_DVS, "dvs stat"},
+};
+
+unsigned int imgu_node_to_queue(unsigned int node)
+{
+   return imgu_node_map[node].css_queue;
+}
+
+unsigned int imgu_map_node(struct imgu_device *imgu, unsigned int css_queue)
+{
+   unsigned int i;
+
+   if (css_queue == IPU3_CSS_QUEUE_VF)
+   return 

[PATCH v5 10/12] intel-ipu3: Add css pipeline programming

2017-12-01 Thread Yong Zhi
This provides helper library to be used by
v4l2 level to program imaging pipelines and
control the streaming.

Signed-off-by: Yong Zhi 
---
 drivers/media/pci/intel/ipu3/ipu3-css.c | 1780 +++
 1 file changed, 1780 insertions(+)

diff --git a/drivers/media/pci/intel/ipu3/ipu3-css.c 
b/drivers/media/pci/intel/ipu3/ipu3-css.c
index 1e61ecb64334..b720588a2ce5 100644
--- a/drivers/media/pci/intel/ipu3/ipu3-css.c
+++ b/drivers/media/pci/intel/ipu3/ipu3-css.c
@@ -26,6 +26,177 @@
 IMGU_IRQCTRL_IRQ_SW_PIN(0) | \
 IMGU_IRQCTRL_IRQ_SW_PIN(1))
 
+#define IPU3_CSS_FORMAT_BPP_DEN50  /* Denominator */
+
+/* Some sane limits for resolutions */
+#define IPU3_CSS_MIN_RES   32
+#define IPU3_CSS_MAX_H 3136
+#define IPU3_CSS_MAX_W 4224
+
+/* filter size from graph settings is fixed as 4 */
+#define FILTER_SIZE 4
+#define MIN_ENVELOPE8
+
+/*
+ * pre-allocated buffer size for CSS ABI, auxiliary frames
+ * after BDS and before GDC. Those values should be tuned
+ * to big enough to avoid buffer re-allocation when
+ * streaming to lower streaming latency.
+ */
+#define CSS_ABI_SIZE136
+#define CSS_BDS_SIZE(4480 * 3200 * 3)
+#define CSS_GDC_SIZE(4224 * 3200 * 12 / 8)
+
+#define IPU3_CSS_QUEUE_TO_FLAGS(q) (1 << (q))
+#define IPU3_CSS_FORMAT_FL_IN  \
+   IPU3_CSS_QUEUE_TO_FLAGS(IPU3_CSS_QUEUE_IN)
+#define IPU3_CSS_FORMAT_FL_OUT \
+   IPU3_CSS_QUEUE_TO_FLAGS(IPU3_CSS_QUEUE_OUT)
+#define IPU3_CSS_FORMAT_FL_VF  \
+   IPU3_CSS_QUEUE_TO_FLAGS(IPU3_CSS_QUEUE_VF)
+
+/* Formats supported by IPU3 Camera Sub System */
+static const struct ipu3_css_format ipu3_css_formats[] = {
+   {
+   .pixelformat = V4L2_PIX_FMT_NV12,
+   .colorspace = V4L2_COLORSPACE_SRGB,
+   .frame_format = IMGU_ABI_FRAME_FORMAT_NV12,
+   .osys_format = IMGU_ABI_OSYS_FORMAT_NV12,
+   .osys_tiling = IMGU_ABI_OSYS_TILING_NONE,
+   .bytesperpixel_num = 1 * IPU3_CSS_FORMAT_BPP_DEN,
+   .chroma_decim = 4,
+   .width_align = IPU3_UAPI_ISP_VEC_ELEMS,
+   .flags = IPU3_CSS_FORMAT_FL_OUT | IPU3_CSS_FORMAT_FL_VF,
+   }, {
+   /* Each 32 bytes contains 25 10-bit pixels */
+   .pixelformat = V4L2_PIX_FMT_IPU3_SBGGR10,
+   .colorspace = V4L2_COLORSPACE_RAW,
+   .frame_format = IMGU_ABI_FRAME_FORMAT_RAW_PACKED,
+   .bayer_order = IMGU_ABI_BAYER_ORDER_BGGR,
+   .bit_depth = 10,
+   .bytesperpixel_num = 64,
+   .width_align = 2 * IPU3_UAPI_ISP_VEC_ELEMS,
+   .flags = IPU3_CSS_FORMAT_FL_IN,
+   }, {
+   .pixelformat = V4L2_PIX_FMT_IPU3_SGBRG10,
+   .colorspace = V4L2_COLORSPACE_RAW,
+   .frame_format = IMGU_ABI_FRAME_FORMAT_RAW_PACKED,
+   .bayer_order = IMGU_ABI_BAYER_ORDER_GBRG,
+   .bit_depth = 10,
+   .bytesperpixel_num = 64,
+   .width_align = 2 * IPU3_UAPI_ISP_VEC_ELEMS,
+   .flags = IPU3_CSS_FORMAT_FL_IN,
+   }, {
+   .pixelformat = V4L2_PIX_FMT_IPU3_SGRBG10,
+   .colorspace = V4L2_COLORSPACE_RAW,
+   .frame_format = IMGU_ABI_FRAME_FORMAT_RAW_PACKED,
+   .bayer_order = IMGU_ABI_BAYER_ORDER_GRBG,
+   .bit_depth = 10,
+   .bytesperpixel_num = 64,
+   .width_align = 2 * IPU3_UAPI_ISP_VEC_ELEMS,
+   .flags = IPU3_CSS_FORMAT_FL_IN,
+   }, {
+   .pixelformat = V4L2_PIX_FMT_IPU3_SRGGB10,
+   .colorspace = V4L2_COLORSPACE_RAW,
+   .frame_format = IMGU_ABI_FRAME_FORMAT_RAW_PACKED,
+   .bayer_order = IMGU_ABI_BAYER_ORDER_RGGB,
+   .bit_depth = 10,
+   .bytesperpixel_num = 64,
+   .width_align = 2 * IPU3_UAPI_ISP_VEC_ELEMS,
+   .flags = IPU3_CSS_FORMAT_FL_IN,
+   },
+};
+
+static const struct {
+   enum imgu_abi_queue_id qid;
+   size_t ptr_ofs;
+} ipu3_css_queues[IPU3_CSS_QUEUES] = {
+   [IPU3_CSS_QUEUE_IN] = {
+   IMGU_ABI_QUEUE_C_ID,
+   offsetof(struct imgu_abi_buffer, payload.frame.frame_data)
+   },
+   [IPU3_CSS_QUEUE_OUT] = {
+   IMGU_ABI_QUEUE_D_ID,
+   offsetof(struct imgu_abi_buffer, payload.frame.frame_data)
+   },
+   [IPU3_CSS_QUEUE_VF] = {
+   IMGU_ABI_QUEUE_E_ID,
+   offsetof(struct imgu_abi_buffer, payload.frame.frame_data)
+   },
+   [IPU3_CSS_QUEUE_STAT_3A] = {
+   IMGU_ABI_QUEUE_F_ID,
+   offsetof(struct imgu_abi_buffer, payload.s3a.data_ptr)
+   },
+   [IPU3_CSS_QUEUE_STAT_DVS] = {
+   IMGU_ABI_QUEUE_G_ID,
+   offsetof(struct 

[PATCH v5 08/12] intel-ipu3: css: Compute and program ccs

2017-12-01 Thread Yong Zhi
A collection of routines that are mainly used
to calculate the parameters for accelerator cluster.

Signed-off-by: Yong Zhi 
---
 drivers/media/pci/intel/ipu3/ipu3-css-params.c | 3169 
 drivers/media/pci/intel/ipu3/ipu3-css-params.h |   36 +
 drivers/media/pci/intel/ipu3/ipu3-css.h|  218 ++
 3 files changed, 3423 insertions(+)
 create mode 100644 drivers/media/pci/intel/ipu3/ipu3-css-params.c
 create mode 100644 drivers/media/pci/intel/ipu3/ipu3-css-params.h
 create mode 100644 drivers/media/pci/intel/ipu3/ipu3-css.h

diff --git a/drivers/media/pci/intel/ipu3/ipu3-css-params.c 
b/drivers/media/pci/intel/ipu3/ipu3-css-params.c
new file mode 100644
index ..fb45a3451057
--- /dev/null
+++ b/drivers/media/pci/intel/ipu3/ipu3-css-params.c
@@ -0,0 +1,3169 @@
+/*
+ * Copyright (c) 2017 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License version
+ * 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include 
+
+#include "ipu3-css.h"
+#include "ipu3-css-fw.h"
+#include "ipu3-tables.h"
+
+struct ipu3_css_scaler_info {
+   unsigned int phase_step;/* Same for luma/chroma */
+   int exp_shift;
+
+   unsigned int phase_init;/* luma/chroma dependent */
+   int pad_left;
+   int pad_right;
+   int crop_left;
+   int crop_top;
+};
+
+static unsigned int ipu3_css_scaler_get_exp(unsigned int counter,
+   unsigned int divider)
+{
+   int i = fls(divider) - fls(counter);
+
+   if (i <= 0)
+   return 0;
+
+   if (divider >> i < counter)
+   i = i - 1;
+
+   return i;
+}
+
+/* Set up the CSS scaler look up table */
+static void
+ipu3_css_scaler_setup_lut(unsigned int taps, unsigned int input_width,
+ unsigned int output_width, int phase_step_correction,
+ const int *coeffs, unsigned int coeffs_size,
+ s8 coeff_lut[], struct ipu3_css_scaler_info *info)
+{
+   int tap, phase, phase_sum_left, phase_sum_right;
+   int exponent = ipu3_css_scaler_get_exp(output_width, input_width);
+   int mantissa = (1 << exponent) * output_width;
+   unsigned int phase_step;
+
+   if (input_width == output_width) {
+   for (phase = 0; phase < IMGU_SCALER_PHASES; phase++) {
+   for (tap = 0; tap < taps; tap++) {
+   coeff_lut[phase * IMGU_SCALER_FILTER_TAPS + tap]
+   = 0;
+   }
+   }
+
+   info->phase_step = IMGU_SCALER_PHASES *
+   (1 << IMGU_SCALER_PHASE_COUNTER_PREC_REF);
+   info->exp_shift = 0;
+   info->pad_left = 0;
+   info->pad_right = 0;
+   info->phase_init = 0;
+   info->crop_left = 0;
+   info->crop_top = 0;
+   return;
+   }
+
+   for (phase = 0; phase < IMGU_SCALER_PHASES; phase++) {
+   for (tap = 0; tap < taps; tap++) {
+   /* flip table to for convolution reverse indexing */
+   s64 coeff = coeffs[coeffs_size -
+   ((tap * (coeffs_size / taps)) + phase) - 1];
+   coeff *= mantissa;
+   coeff = div64_long(coeff, input_width);
+
+   /* Add +"0.5" */
+   coeff += 1 << (IMGU_SCALER_COEFF_BITS - 1);
+   coeff >>= IMGU_SCALER_COEFF_BITS;
+
+   coeff_lut[phase * IMGU_SCALER_FILTER_TAPS + tap] =
+   coeff;
+   }
+   }
+
+   phase_step = IMGU_SCALER_PHASES *
+   (1 << IMGU_SCALER_PHASE_COUNTER_PREC_REF)
+   * output_width / input_width;
+   phase_step += phase_step_correction;
+   phase_sum_left = (taps / 2 * IMGU_SCALER_PHASES *
+   (1 << IMGU_SCALER_PHASE_COUNTER_PREC_REF))
+   - (1 << (IMGU_SCALER_PHASE_COUNTER_PREC_REF - 1));
+   phase_sum_right = (taps / 2 * IMGU_SCALER_PHASES *
+   (1 << IMGU_SCALER_PHASE_COUNTER_PREC_REF))
+   + (1 << (IMGU_SCALER_PHASE_COUNTER_PREC_REF - 1));
+
+   info->exp_shift = IMGU_SCALER_MAX_EXPONENT_SHIFT - exponent;
+   info->pad_left = (phase_sum_left % phase_step == 0) ?
+   phase_sum_left / phase_step - 1 : phase_sum_left / phase_step;
+   info->pad_right = (phase_sum_right % phase_step == 0) ?
+   phase_sum_right / 

[PATCH v5 06/12] intel-ipu3: css: Add support for firmware management

2017-12-01 Thread Yong Zhi
Introduce functions to load and install ImgU FW blobs.

Signed-off-by: Yong Zhi 
---
 drivers/media/pci/intel/ipu3/ipu3-abi.h| 1579 
 drivers/media/pci/intel/ipu3/ipu3-css-fw.c |  271 +
 drivers/media/pci/intel/ipu3/ipu3-css-fw.h |  212 
 3 files changed, 2062 insertions(+)
 create mode 100644 drivers/media/pci/intel/ipu3/ipu3-abi.h
 create mode 100644 drivers/media/pci/intel/ipu3/ipu3-css-fw.c
 create mode 100644 drivers/media/pci/intel/ipu3/ipu3-css-fw.h

diff --git a/drivers/media/pci/intel/ipu3/ipu3-abi.h 
b/drivers/media/pci/intel/ipu3/ipu3-abi.h
new file mode 100644
index ..f9780c679c54
--- /dev/null
+++ b/drivers/media/pci/intel/ipu3/ipu3-abi.h
@@ -0,0 +1,1579 @@
+/*
+ * Copyright (c) 2017 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License version
+ * 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#ifndef __IPU3_ABI_H
+#define __IPU3_ABI_H
+
+#include 
+
+/*** IMGU Hardware information ***/
+
+#define IMGU_ISP_VMEM_ALIGN128
+#define IMGU_DVS_BLOCK_W   64
+#define IMGU_DVS_BLOCK_H   32
+#define IMGU_GDC_BUF_X (2 * IMGU_DVS_BLOCK_W)
+#define IMGU_GDC_BUF_Y IMGU_DVS_BLOCK_H
+/* n = 0..1 */
+#define IMGU_SP_PMEM_BASE(n)   (0x2 + (n) * 0x4000)
+#define IMGU_MAX_BQ_GRID_WIDTH 80
+#define IMGU_MAX_BQ_GRID_HEIGHT60
+#define IMGU_OBGRID_TILE_SIZE  16
+#define IMGU_PIXELS_PER_WORD   50
+#define IMGU_BYTES_PER_WORD64
+#define IMGU_STRIPE_FIXED_HALF_OVERLAP 2
+#define IMGU_SHD_SETS  3
+#define IMGU_BDS_MIN_CLIP_VAL  0
+#define IMGU_BDS_MAX_CLIP_VAL  2
+#define IPU3_ABI_AWB_MAX_CELLS_PER_SET 160
+#define IPU3_ABI_AF_MAX_CELLS_PER_SET  32
+#define IPU3_ABI_AWB_FR_MAX_CELLS_PER_SET  32
+
+#define IMGU_ABI_ACC_OP_IDLE   0
+#define IMGU_ABI_ACC_OP_END_OF_ACK 1
+#define IMGU_ABI_ACC_OP_END_OF_OPS 2
+#define IMGU_ABI_ACC_OP_NO_OPS 3
+
+#define IMGU_ABI_ACC_OPTYPE_PROCESS_LINES  0
+#define IMGU_ABI_ACC_OPTYPE_TRANSFER_DATA  1
+
+#define IMGU_MMU_PADDR_SHIFT   12
+
+/* Register definitions */
+
+/* PM_CTRL_0_5_0_IMGHMMADR */
+#define IMGU_REG_PM_CTRL   0x0
+#define IMGU_PM_CTRL_START BIT(0)
+#define IMGU_PM_CTRL_CFG_DONE  BIT(1)
+#define IMGU_PM_CTRL_RACE_TO_HALT  BIT(2)
+#define IMGU_PM_CTRL_NACK_ALL  BIT(3)
+#define IMGU_PM_CTRL_CSS_PWRDN BIT(4)
+#define IMGU_PM_CTRL_RST_AT_EOFBIT(5)
+#define IMGU_PM_CTRL_FORCE_HALTBIT(6)
+#define IMGU_PM_CTRL_FORCE_UNHALT  BIT(7)
+#define IMGU_PM_CTRL_FORCE_PWRDN   BIT(8)
+#define IMGU_PM_CTRL_FORCE_RESET   BIT(9)
+#define IMGU_PM_CTRL_RETURN_LICENSE_AT_EOF BIT(10)
+#define IMGU_PM_CTRL_POWER_DOWN_AT_EOF (IMGU_PM_CTRL_CSS_PWRDN | \
+   IMGU_PM_CTRL_RACE_TO_HALT | \
+   IMGU_PM_CTRL_RETURN_LICENSE_AT_EOF)
+#define IMGU_PM_CTRL_RESET_AT_EOF  (IMGU_PM_CTRL_RST_AT_EOF | \
+   IMGU_PM_CTRL_RACE_TO_HALT | \
+   IMGU_PM_CTRL_RETURN_LICENSE_AT_EOF)
+/* SYSTEM_REQ_0_5_0_IMGHMMADR */
+#define IMGU_REG_SYSTEM_REQ0x18
+#define IMGU_SYSTEM_REQ_FREQ_MASK  0x3f
+#define IMGU_SYSTEM_REQ_FREQ_DIVIDER   25
+#define IMGU_REG_INT_STATUS0x30
+#define IMGU_REG_INT_ENABLE0x34
+#define IMGU_REG_INT_CSS_IRQ   (1 << 31)
+/* STATE_0_5_0_IMGHMMADR */
+#define IMGU_REG_STATE 0x130
+#define IMGU_STATE_HALT_STSBIT(0)
+#define IMGU_STATE_IDLE_STSBIT(1)
+#define IMGU_STATE_POWER_UPBIT(2)
+#define IMGU_STATE_POWER_DOWN  BIT(3)
+#define IMGU_STATE_CSS_BUSY_MASK   0xc0
+#define IMGU_STATE_PM_FSM_MASK 0x180
+#define IMGU_STATE_PWRDNM_FSM_MASK 0x1E0
+/* PM_STS_0_5_0_IMGHMMADR */
+#define IMGU_REG_PM_STS0x140
+
+#define IMGU_REG_BASE  0x4000
+
+#define IMGU_REG_ISP_CTRL  (IMGU_REG_BASE + 0x00)
+#define IMGU_CTRL_RST   

[PATCH v5 09/12] intel-ipu3: css: Initialize css hardware

2017-12-01 Thread Yong Zhi
This patch implements the functions to initialize
and configure IPU3 h/w such as clock, irq and power.

Signed-off-by: Yong Zhi 
Signed-off-by: Tomasz Figa 
---
 drivers/media/pci/intel/ipu3/ipu3-css.c | 523 
 1 file changed, 523 insertions(+)
 create mode 100644 drivers/media/pci/intel/ipu3/ipu3-css.c

diff --git a/drivers/media/pci/intel/ipu3/ipu3-css.c 
b/drivers/media/pci/intel/ipu3/ipu3-css.c
new file mode 100644
index ..1e61ecb64334
--- /dev/null
+++ b/drivers/media/pci/intel/ipu3/ipu3-css.c
@@ -0,0 +1,523 @@
+/*
+ * Copyright (c) 2017 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License version
+ * 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include 
+#include 
+
+#include "ipu3-css.h"
+#include "ipu3-css-fw.h"
+#include "ipu3-css-params.h"
+#include "ipu3-dmamap.h"
+#include "ipu3-tables.h"
+
+/* IRQ configuration */
+#define IMGU_IRQCTRL_IRQ_MASK  (IMGU_IRQCTRL_IRQ_SP1 | \
+IMGU_IRQCTRL_IRQ_SP2 | \
+IMGU_IRQCTRL_IRQ_SW_PIN(0) | \
+IMGU_IRQCTRL_IRQ_SW_PIN(1))
+
+/*** css hw ***/
+
+/* In the style of writesl() defined in include/asm-generic/io.h */
+static inline void writes(const void *mem, ssize_t count, void __iomem *addr)
+{
+   if (count >= 4) {
+   const u32 *buf = mem;
+
+   count /= 4;
+   do {
+   writel(*buf++, addr);
+   addr += 4;
+   } while (--count);
+   }
+}
+
+/* Wait until register `reg', masked with `mask', becomes `cmp' */
+static int ipu3_hw_wait(void __iomem *base, int reg, u32 mask, u32 cmp)
+{
+   u32 val;
+
+   return readl_poll_timeout(base + reg, val, (val & mask) == cmp,
+ 1000, 100 * 1000);
+}
+
+/* Initialize the IPU3 CSS hardware and associated h/w blocks */
+
+int ipu3_css_set_powerup(struct device *dev, void __iomem *base)
+{
+   static const unsigned int freq = 450;
+   u32 pm_ctrl, state, val;
+
+   dev_dbg(dev, "power up.\n");
+   /* Clear the CSS busy signal */
+   readl(base + IMGU_REG_GP_BUSY);
+   writel(0, base + IMGU_REG_GP_BUSY);
+
+   /* Wait for idle signal */
+   if (ipu3_hw_wait(base, IMGU_REG_STATE, IMGU_STATE_IDLE_STS,
+IMGU_STATE_IDLE_STS)) {
+   dev_err(dev, "failed to set CSS idle\n");
+   goto fail;
+   }
+
+   /* Reset the css */
+   writel(readl(base + IMGU_REG_PM_CTRL) | IMGU_PM_CTRL_FORCE_RESET,
+  base + IMGU_REG_PM_CTRL);
+
+   usleep_range(200, 300);
+
+   /** Prepare CSS */
+
+   pm_ctrl = readl(base + IMGU_REG_PM_CTRL);
+   state = readl(base + IMGU_REG_STATE);
+
+   dev_dbg(dev, "CSS pm_ctrl 0x%x state 0x%x (power %s)\n",
+   pm_ctrl, state, state & IMGU_STATE_POWER_DOWN ? "down" : "up");
+
+   /* Power up CSS using wrapper */
+   if (state & IMGU_STATE_POWER_DOWN) {
+   writel(IMGU_PM_CTRL_RACE_TO_HALT | IMGU_PM_CTRL_START,
+  base + IMGU_REG_PM_CTRL);
+   if (ipu3_hw_wait(base, IMGU_REG_PM_CTRL,
+IMGU_PM_CTRL_START, 0)) {
+   dev_err(dev, "failed to power up CSS\n");
+   goto fail;
+   }
+   usleep_range(2000, 3000);
+   } else {
+   writel(IMGU_PM_CTRL_RACE_TO_HALT, base + IMGU_REG_PM_CTRL);
+   }
+
+   /* Set the busy bit */
+   writel(readl(base + IMGU_REG_GP_BUSY) | 1, base + IMGU_REG_GP_BUSY);
+
+   /* Set CSS clock frequency */
+   pm_ctrl = readl(base + IMGU_REG_PM_CTRL);
+   val = pm_ctrl & ~(IMGU_PM_CTRL_CSS_PWRDN | IMGU_PM_CTRL_RST_AT_EOF);
+   writel(val, base + IMGU_REG_PM_CTRL);
+   writel(0, base + IMGU_REG_GP_BUSY);
+   if (ipu3_hw_wait(base, IMGU_REG_STATE,
+IMGU_STATE_PWRDNM_FSM_MASK, 0)) {
+   dev_err(dev, "failed to pwrdn CSS\n");
+   goto fail;
+   }
+   val = (freq / IMGU_SYSTEM_REQ_FREQ_DIVIDER) & IMGU_SYSTEM_REQ_FREQ_MASK;
+   writel(val, base + IMGU_REG_SYSTEM_REQ);
+   writel(1, base + IMGU_REG_GP_BUSY);
+   writel(readl(base + IMGU_REG_PM_CTRL) | IMGU_PM_CTRL_FORCE_HALT,
+  base + IMGU_REG_PM_CTRL);
+   if (ipu3_hw_wait(base, IMGU_REG_STATE, IMGU_STATE_HALT_STS,
+IMGU_STATE_HALT_STS)) {
+   dev_err(dev, "failed to halt CSS\n");
+   goto fail;
+ 

[PATCH v5 01/12] v4l: Add Intel IPU3 meta buffer formats

2017-12-01 Thread Yong Zhi
Add IPU3-specific meta formats for parameter
processing and 3A, DVS statistics:

  V4L2_META_FMT_IPU3_PARAMS
  V4L2_META_FMT_IPU3_STAT_3A
  V4L2_META_FMT_IPU3_STAT_DVS

Signed-off-by: Yong Zhi 
---
 drivers/media/v4l2-core/v4l2-ioctl.c | 3 +++
 include/uapi/linux/videodev2.h   | 5 +
 2 files changed, 8 insertions(+)

diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c 
b/drivers/media/v4l2-core/v4l2-ioctl.c
index aa4cbddbc064..425720dd9432 100644
--- a/drivers/media/v4l2-core/v4l2-ioctl.c
+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
@@ -1256,6 +1256,9 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)
case V4L2_TCH_FMT_TU08: descr = "8-bit unsigned touch data"; 
break;
case V4L2_META_FMT_VSP1_HGO:descr = "R-Car VSP1 1-D Histogram"; 
break;
case V4L2_META_FMT_VSP1_HGT:descr = "R-Car VSP1 2-D Histogram"; 
break;
+   case V4L2_META_FMT_IPU3_PARAMS: descr = "IPU3 processing parameters"; 
break;
+   case V4L2_META_FMT_IPU3_STAT_3A:descr = "IPU3 3A statistics"; 
break;
+   case V4L2_META_FMT_IPU3_STAT_DVS:   descr = "IPU3 DVS statistics"; 
break;
 
default:
/* Compressed formats */
diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
index 76c14cf9436f..51f607b23e80 100644
--- a/include/uapi/linux/videodev2.h
+++ b/include/uapi/linux/videodev2.h
@@ -697,6 +697,11 @@ struct v4l2_pix_format {
 #define V4L2_META_FMT_VSP1_HGOv4l2_fourcc('V', 'S', 'P', 'H') /* R-Car 
VSP1 1-D Histogram */
 #define V4L2_META_FMT_VSP1_HGTv4l2_fourcc('V', 'S', 'P', 'T') /* R-Car 
VSP1 2-D Histogram */
 
+/* Vendor specific - used for IPU3 camera sub-system */
+#define V4L2_META_FMT_IPU3_PARAMS  v4l2_fourcc('i', 'p', '3', 'p') /* IPU3 
params */
+#define V4L2_META_FMT_IPU3_STAT_3A v4l2_fourcc('i', 'p', '3', 's') /* IPU3 
3A statistics */
+#define V4L2_META_FMT_IPU3_STAT_DVSv4l2_fourcc('i', 'p', '3', 'd') /* IPU3 
DVS statistics */
+
 /* priv field value to indicates that subsequent fields are valid. */
 #define V4L2_PIX_FMT_PRIV_MAGIC0xfeedcafe
 
-- 
2.7.4



[PATCH v5 04/12] intel-ipu3: Implement DMA mapping functions

2017-12-01 Thread Yong Zhi
From: Tomasz Figa 

This driver uses IOVA space for buffer mapping through IPU3 MMU
to transfer data between imaging pipelines and system DDR.

Signed-off-by: Tomasz Figa 
Signed-off-by: Yong Zhi 
---
 drivers/media/pci/intel/ipu3/Kconfig |   8 +
 drivers/media/pci/intel/ipu3/Makefile|   2 +-
 drivers/media/pci/intel/ipu3/ipu3-css-pool.h |  53 +
 drivers/media/pci/intel/ipu3/ipu3-dmamap.c   | 291 +++
 drivers/media/pci/intel/ipu3/ipu3-dmamap.h   |  33 +++
 drivers/media/pci/intel/ipu3/ipu3.h  | 165 +++
 6 files changed, 551 insertions(+), 1 deletion(-)
 create mode 100644 drivers/media/pci/intel/ipu3/ipu3-css-pool.h
 create mode 100644 drivers/media/pci/intel/ipu3/ipu3-dmamap.c
 create mode 100644 drivers/media/pci/intel/ipu3/ipu3-dmamap.h
 create mode 100644 drivers/media/pci/intel/ipu3/ipu3.h

diff --git a/drivers/media/pci/intel/ipu3/Kconfig 
b/drivers/media/pci/intel/ipu3/Kconfig
index 6beb11189ed2..91312cd8a26e 100644
--- a/drivers/media/pci/intel/ipu3/Kconfig
+++ b/drivers/media/pci/intel/ipu3/Kconfig
@@ -24,3 +24,11 @@ config INTEL_IPU3_MMU
---help---
  For IPU3, this option enables its MMU driver to translate its internal
  virtual address to 39 bits wide physical address for 64GBytes space 
access.
+
+config INTEL_IPU3_DMAMAP
+   tristate
+   default n
+   select IOMMU_IOVA
+   select INTEL_IPU3_MMU
+   ---help---
+ This is IPU3 IOMMU domain specific DMA driver.
diff --git a/drivers/media/pci/intel/ipu3/Makefile 
b/drivers/media/pci/intel/ipu3/Makefile
index 1cbb3cab83ef..d2e655b11802 100644
--- a/drivers/media/pci/intel/ipu3/Makefile
+++ b/drivers/media/pci/intel/ipu3/Makefile
@@ -4,4 +4,4 @@
 
 obj-$(CONFIG_VIDEO_IPU3_CIO2) += ipu3-cio2.o
 obj-$(CONFIG_INTEL_IPU3_MMU) += ipu3-mmu.o
-
+obj-$(CONFIG_INTEL_IPU3_DMAMAP) += ipu3-dmamap.o
diff --git a/drivers/media/pci/intel/ipu3/ipu3-css-pool.h 
b/drivers/media/pci/intel/ipu3/ipu3-css-pool.h
new file mode 100644
index ..b60bcf2ad432
--- /dev/null
+++ b/drivers/media/pci/intel/ipu3/ipu3-css-pool.h
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2017 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License version
+ * 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#ifndef __IPU3_UTIL_H
+#define __IPU3_UTIL_H
+
+struct device;
+
+#define sqr(x) ((x) * (x))
+#define DIV_ROUND_CLOSEST_DOWN(a, b)   (((a) + (b / 2) - 1) / (b))
+#define roundclosest_down(a, b)(DIV_ROUND_CLOSEST_DOWN(a, b) * 
(b))
+#define roundclosest(n, di)\
+   ({ typeof(n) __n = (n); typeof(di) __di = (di); \
+   DIV_ROUND_CLOSEST(__n, __di) * __di; })
+
+#define IPU3_CSS_POOL_SIZE 4
+
+struct ipu3_css_map {
+   size_t size;
+   void *vaddr;
+   dma_addr_t daddr;
+   struct vm_struct *vma;
+};
+
+struct ipu3_css_pool {
+   struct {
+   struct ipu3_css_map param;
+   long framenum;
+   } entry[IPU3_CSS_POOL_SIZE];
+   unsigned int last; /* Latest entry */
+};
+
+int ipu3_css_dma_buffer_resize(struct device *dev, struct ipu3_css_map *map,
+  size_t size);
+void ipu3_css_pool_cleanup(struct device *dev, struct ipu3_css_pool *pool);
+int ipu3_css_pool_init(struct device *dev, struct ipu3_css_pool *pool,
+  int size);
+int ipu3_css_pool_get(struct ipu3_css_pool *pool, long framenum);
+void ipu3_css_pool_put(struct ipu3_css_pool *pool);
+const struct ipu3_css_map *ipu3_css_pool_last(struct ipu3_css_pool *pool,
+ unsigned int last);
+
+#endif
diff --git a/drivers/media/pci/intel/ipu3/ipu3-dmamap.c 
b/drivers/media/pci/intel/ipu3/ipu3-dmamap.c
new file mode 100644
index ..db33572b5feb
--- /dev/null
+++ b/drivers/media/pci/intel/ipu3/ipu3-dmamap.c
@@ -0,0 +1,291 @@
+/*
+ * Copyright (c) 2017 Intel Corporation.
+ * Copyright (C) 2017 Google, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License version
+ * 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include 
+#include 
+
+#include "ipu3.h"
+#include "ipu3-css-pool.h"
+#include "ipu3-mmu.h"
+
+static void 

[PATCH v5 02/12] intel-ipu3: Add user space ABI definitions

2017-12-01 Thread Yong Zhi
The UAPI header defines the structures and macros
to be used by user space.

Signed-off-by: Rajmohan Mani 
Signed-off-by: Yong Zhi 
---
 include/uapi/linux/intel-ipu3.h | 2196 +++
 1 file changed, 2196 insertions(+)
 create mode 100644 include/uapi/linux/intel-ipu3.h

diff --git a/include/uapi/linux/intel-ipu3.h b/include/uapi/linux/intel-ipu3.h
new file mode 100644
index ..0911bb360dac
--- /dev/null
+++ b/include/uapi/linux/intel-ipu3.h
@@ -0,0 +1,2196 @@
+/*
+ * Copyright (c) 2017 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License version
+ * 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#ifndef __IPU3_UAPI_H
+#define __IPU3_UAPI_H
+
+#include 
+
+#define IPU3_UAPI_ISP_VEC_ELEMS64
+
+#define IMGU_ABI_PAD   __aligned(IPU3_UAPI_ISP_WORD_BYTES)
+#define IPU3_ALIGN __attribute__((aligned(IPU3_UAPI_ISP_WORD_BYTES)))
+
+#define IPU3_UAPI_ISP_WORD_BYTES   32
+#define IPU3_UAPI_MAX_STRIPES  2
+
+/*** ipu3_uapi_stats_3a ***/
+
+#define IPU3_UAPI_MAX_BUBBLE_SIZE  10
+
+#define IPU3_UAPI_AE_COLORS4
+#define IPU3_UAPI_AE_BINS  256
+
+#define IPU3_UAPI_AWB_MD_ITEM_SIZE 8
+#define IPU3_UAPI_AWB_MAX_SETS 60
+#define IPU3_UAPI_AWB_SET_SIZE 0x500
+#define IPU3_UAPI_AWB_SPARE_FOR_BUBBLES \
+   (IPU3_UAPI_MAX_BUBBLE_SIZE * IPU3_UAPI_MAX_STRIPES * \
+IPU3_UAPI_AWB_MD_ITEM_SIZE)
+#define IPU3_UAPI_AWB_MAX_BUFFER_SIZE \
+   (IPU3_UAPI_AWB_MAX_SETS * \
+(IPU3_UAPI_AWB_SET_SIZE + IPU3_UAPI_AWB_SPARE_FOR_BUBBLES))
+
+#define IPU3_UAPI_AF_MAX_SETS  24
+#define IPU3_UAPI_AF_MD_ITEM_SIZE  4
+#define IPU3_UAPI_AF_SPARE_FOR_BUBBLES \
+   (IPU3_UAPI_MAX_BUBBLE_SIZE * IPU3_UAPI_MAX_STRIPES * \
+IPU3_UAPI_AF_MD_ITEM_SIZE)
+#define IPU3_UAPI_AF_Y_TABLE_SET_SIZE  0x80
+#define IPU3_UAPI_AF_Y_TABLE_MAX_SIZE \
+   (IPU3_UAPI_AF_MAX_SETS * \
+(IPU3_UAPI_AF_Y_TABLE_SET_SIZE + IPU3_UAPI_AF_SPARE_FOR_BUBBLES) * \
+IPU3_UAPI_MAX_STRIPES)
+
+#define IPU3_UAPI_AWB_FR_MAX_SETS  24
+#define IPU3_UAPI_AWB_FR_MD_ITEM_SIZE  8
+#define IPU3_UAPI_AWB_FR_BAYER_TBL_SIZE0x100
+#define IPU3_UAPI_AWB_FR_SPARE_FOR_BUBBLES \
+   (IPU3_UAPI_MAX_BUBBLE_SIZE * IPU3_UAPI_MAX_STRIPES * \
+   IPU3_UAPI_AWB_FR_MD_ITEM_SIZE)
+#define IPU3_UAPI_AWB_FR_BAYER_TABLE_MAX_SIZE \
+   (IPU3_UAPI_AWB_FR_MAX_SETS * \
+   (IPU3_UAPI_AWB_FR_BAYER_TBL_SIZE + \
+IPU3_UAPI_AWB_FR_SPARE_FOR_BUBBLES) * \
+   IPU3_UAPI_MAX_STRIPES)
+
+struct ipu3_uapi_grid_config {
+   __u8 width; /* 6 or 7 (rgbs_grd_cfg) bits */
+   __u8 height;
+   __u16 block_width_log2:3;
+   __u16 block_height_log2:3;
+   __u16 height_per_slice:8;   /* default value 1 */
+   __u16 x_start;  /* 12 bits */
+   __u16 y_start;
+#define IPU3_UAPI_GRID_START_MASK  ((1 << 12) - 1)
+#define IPU3_UAPI_GRID_Y_START_EN  (1 << 15)
+   __u16 x_end;/* 12 bits */
+   __u16 y_end;
+} __packed;
+
+struct ipu3_uapi_awb_meta_data {
+   __u8 meta_data_buffer[IPU3_UAPI_AWB_MAX_BUFFER_SIZE];
+} __packed;
+
+struct ipu3_uapi_awb_raw_buffer {
+   struct ipu3_uapi_awb_meta_data meta_data;
+} __packed;
+
+struct IPU3_ALIGN ipu3_uapi_awb_config_s {
+   __u16 rgbs_thr_gr;
+   __u16 rgbs_thr_r;
+   __u16 rgbs_thr_gb;
+   __u16 rgbs_thr_b;
+/* controls generation of meta_data (like FF enable/disable) */
+#define IPU3_UAPI_AWB_RGBS_THR_B_EN(1 << 14)
+#define IPU3_UAPI_AWB_RGBS_THR_B_INCL_SAT  (1 << 15)
+
+   struct ipu3_uapi_grid_config grid;
+} __packed;
+
+struct ipu3_uapi_ae_raw_buffer {
+   __u32 vals[IPU3_UAPI_AE_BINS * IPU3_UAPI_AE_COLORS];
+} __packed;
+
+struct ipu3_uapi_ae_raw_buffer_aligned {
+   struct ipu3_uapi_ae_raw_buffer buff IPU3_ALIGN;
+} __packed;
+
+struct ipu3_uapi_ae_grid_config {
+   __u8 width;
+   __u8 height;
+   __u8 block_width_log2:4;
+   __u8 block_height_log2:4;
+   __u8 __reserved0:5;
+   __u8 ae_en:1;
+   __u8 rst_hist_array:1;
+   __u8 done_rst_hist_array:1;
+   __u16 

[PATCH v5 00/12] Intel IPU3 ImgU patchset

2017-12-01 Thread Yong Zhi
Hi,

This series adds support for the Intel IPU3 (Image Processing Unit)
ImgU which is essentially a modern memory-to-memory ISP. It implements
raw Bayer to YUV image format conversion as well as a large number of
other pixel processing algorithms for improving the image quality.

Meta data formats are defined for image statistics (3A, i.e. automatic
white balance, exposure and focus, histogram and local area contrast
enhancement) as well as for the pixel processing algorithm parameters.
The documentation for these formats is currently not included in the
patchset but will be added in a future version of this set.

The algorithm parameters need to be considered specific to a given frame
and typically a large number of these parameters change on frame to frame
basis. Additionally, the parameters are highly structured (and not a flat
space of independent configuration primitives). They also reflect the
data structures used by the firmware and the hardware. On top of that,
the algorithms require highly specialized user space to make meaningful
use of them. For these reasons it has been chosen video buffers to pass
the parameters to the device.

On individual patches:

The heart of ImgU is the CSS, or Camera Subsystem, which contains the
image processors and HW accelerators.

The libraries for image processing inputs computation are provided
in patch 8.

Patch 9 implements all h/w related functions, patch 10 is of the same file 
which maps
v4l2 level operations to low level imaging pipeline programming using a simple
interface. The communication between firmware and host driver is implemented 
with
circular queues.

To access DDR via ImgU's own memory space, IPU3 is also equipped with
its own MMU unit, the driver is implemented in patch 3.

The original driver uses iommu_ops, in current version, however, the iommu
dependency was removed based on review, few new functions are added in v5 based 
on
drivers/iommu/iommu.c.

Patch 4 is the DMAMAP driver that calls above MMU driver directly.

Patch 5 implements buffer pool to support dynamic parameters, each pool is 
intialized
to contain a specific type of parameter structure.

Patch 6 manages IPU3 fw download and install using standard linux firmware API.

The firmware which is called ipu3-fw.bin can be downloaded from:

git://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git
(commit 2c27b0cb02f18c022d8378e0e1abaf8b7ae8188f)

Patch 7 supplies various default settings and tables for IPU3 programming.

Patch 11 is the v4l2 driver that exposes controls and device nodes, it currently
has a out-of-tree dependency on Sakari's V4L2_BUF_TYPE_META_OUTPUT work:



Patch 12 is the top level ImgU PCI device driver, it uses Kconfig and Makefile 
created
by IPU3 cio2 patch series.

Link to user space implementation:



The IPU3 modules are tested on Kaby Lake based platform, the media topology and
v4l2 compliance results are posted at the end for reference.

===
= history =
===

version v5:
- ipu3-css-pool.c/ipu3_css_pool_check().
  add handling of the framenum wrap around case in ipu3_css_pool_check().
- ipu3.c, ipu3-v4l2.c, ipu3.h
  merge struct ipu3_mem2mem2_device into imgu_device and update the code
  accordingly. (Suggested by Sakari)
- ipu3-mmu.c driver:
  use __get_free_page() for page-aligned allocations (Tomasz).
  optimize tlb invalidation by calling them at the end of map/unmap. (Tomasz).
  remove dependency on iommu. (Sakari)
  introduce few new functions from iommu.c.
- ipu3-dmamap.c driver
  call mmu directly without IOMMU_SUPPORT (Sakari)
  update dmamap APIs. (Suggested by Tomasz)
- ipu3_v4l2.c
  move g/s_selection callback to V4l2 sub-device (Sakari)
  remove colon from ImgU sub-device name. (Sakari)
- ipu3-css-params.c
  fix indentation, 0-day scan warnings etc.
- ipu3-css.c
  fix warning about NULL comparison. (Sakari)
- intel-ipu3.h: 
  remove redundant IPU3_ALIGN attribute (Sakari).
  fix up un-needed fields in struct ipu3_uapi_params (Sakari)
  re-order this to be 2nd in the patch set.
- Makefile: remove Copyright header. (Sakari)
- Internal fix: 
  optimize shot-to-shot performance.
  update default white balance gains defined in ipu3-tables.c

TODOs:

- Documentation on ImgU driver programming interface to configure and enable
  ISP HW,  which will include details on complete V4L2 Kernel driver interface
  and IO-Control parameters, except for the ISP internal algorithm and its 
  parameters (which is Intel proprietary IP).

- Review ipu3_css_pool_* group APIs usage.

version 4:
- Used V4L2_BUF_TYPE_META_OUTPUT for:
- V4L2_META_FMT_IPU3_STAT_PARAMS

- Used V4L2_BUF_TYPE_META_CAPTURE for:
- V4L2_META_FMT_IPU3_STAT_3A
- V4L2_META_FMT_IPU3_STAT_DVS
- V4L2_META_FMT_IPU3_STAT_LACE
- Supported v4l2 MPLANE format on video nodes.
- ipu3-dmamap.c: Removed dma ops and dependencies on 

[PATCH v5 05/12] intel-ipu3: css: Add dma buff pool utility functions

2017-12-01 Thread Yong Zhi
The pools are used to store previous parameters set by
user with the parameter queue. Due to pipelining,
there needs to be multiple sets (up to four)
of parameters which are queued in a host-to-sp queue.

Signed-off-by: Yong Zhi 
---
 drivers/media/pci/intel/ipu3/ipu3-css-pool.c | 137 +++
 drivers/media/pci/intel/ipu3/ipu3-css-pool.h |   2 +-
 2 files changed, 138 insertions(+), 1 deletion(-)
 create mode 100644 drivers/media/pci/intel/ipu3/ipu3-css-pool.c

diff --git a/drivers/media/pci/intel/ipu3/ipu3-css-pool.c 
b/drivers/media/pci/intel/ipu3/ipu3-css-pool.c
new file mode 100644
index ..2f9cdda803de
--- /dev/null
+++ b/drivers/media/pci/intel/ipu3/ipu3-css-pool.c
@@ -0,0 +1,137 @@
+/*
+ * Copyright (c) 2017 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License version
+ * 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include 
+
+#include "ipu3-css-pool.h"
+#include "ipu3-dmamap.h"
+
+int ipu3_css_dma_buffer_resize(struct device *dev, struct ipu3_css_map *map,
+  size_t size)
+{
+   if (map->size < size && map->vaddr) {
+   dev_warn(dev, "dma buffer is resized from %zu to %zu",
+map->size, size);
+
+   ipu3_dmamap_free(dev, map);
+   if (!ipu3_dmamap_alloc(dev, map, size))
+   return -ENOMEM;
+   }
+
+   return 0;
+}
+
+void ipu3_css_pool_cleanup(struct device *dev, struct ipu3_css_pool *pool)
+{
+   unsigned int i;
+
+   for (i = 0; i < IPU3_CSS_POOL_SIZE; i++)
+   ipu3_dmamap_free(dev, >entry[i].param);
+}
+
+int ipu3_css_pool_init(struct device *dev, struct ipu3_css_pool *pool,
+  size_t size)
+{
+   unsigned int i;
+
+   for (i = 0; i < IPU3_CSS_POOL_SIZE; i++) {
+   /*
+* entry[i].framenum is initialized to INT_MIN so that
+* ipu3_css_pool_check() can treat it as usesable slot.
+*/
+   pool->entry[i].framenum = INT_MIN;
+
+   if (size == 0) {
+   pool->entry[i].param.vaddr = NULL;
+   continue;
+   }
+
+   if (!ipu3_dmamap_alloc(dev, >entry[i].param, size))
+   goto fail;
+   }
+
+   pool->last = IPU3_CSS_POOL_SIZE;
+
+   return 0;
+
+fail:
+   ipu3_css_pool_cleanup(dev, pool);
+   return -ENOMEM;
+}
+
+/*
+ * Check that the following call to pool_get succeeds.
+ * Return negative on error.
+ */
+static int ipu3_css_pool_check(struct ipu3_css_pool *pool, long framenum)
+{
+   /* Get the oldest entry */
+   int n = (pool->last + 1) % IPU3_CSS_POOL_SIZE;
+   long diff = framenum - pool->entry[n].framenum;
+
+   /* if framenum wraps around and becomes smaller than entry n */
+   if (diff < 0)
+   diff += LONG_MAX;
+
+   /*
+* pool->entry[n].framenum stores the frame number where that
+* entry was allocated. If that was allocated more than POOL_SIZE
+* frames back, it is old enough that we know it is no more in
+* use by firmware.
+*/
+   if (diff > IPU3_CSS_POOL_SIZE)
+   return n;
+
+   return -ENOSPC;
+}
+
+/*
+ * Allocate a new parameter from pool at frame number `framenum'.
+ * Release the oldest entry in the pool to make space for the new entry.
+ * Return negative on error.
+ */
+int ipu3_css_pool_get(struct ipu3_css_pool *pool, long framenum)
+{
+   int n = ipu3_css_pool_check(pool, framenum);
+
+   if (n < 0)
+   return n;
+
+   pool->entry[n].framenum = framenum;
+   pool->last = n;
+
+   return n;
+}
+
+/*
+ * Undo, for all practical purposes, the effect of pool_get().
+ */
+void ipu3_css_pool_put(struct ipu3_css_pool *pool)
+{
+   pool->entry[pool->last].framenum = INT_MIN;
+   pool->last = (pool->last + IPU3_CSS_POOL_SIZE - 1) % IPU3_CSS_POOL_SIZE;
+}
+
+const struct ipu3_css_map *
+ipu3_css_pool_last(struct ipu3_css_pool *pool, unsigned int n)
+{
+   static const struct ipu3_css_map null_map = { 0 };
+   int i = (pool->last + IPU3_CSS_POOL_SIZE - n) % IPU3_CSS_POOL_SIZE;
+
+   WARN_ON(n >= IPU3_CSS_POOL_SIZE);
+
+   if (pool->entry[i].framenum < 0)
+   return _map;
+
+   return >entry[i].param;
+}
diff --git a/drivers/media/pci/intel/ipu3/ipu3-css-pool.h 
b/drivers/media/pci/intel/ipu3/ipu3-css-pool.h
index b60bcf2ad432..a94760a6de82 100644
--- a/drivers/media/pci/intel/ipu3/ipu3-css-pool.h
+++ b/drivers/media/pci/intel/ipu3/ipu3-css-pool.h
@@ -44,7 +44,7 @@ int 

[PATCH v5 03/12] intel-ipu3: mmu: Implement driver

2017-12-01 Thread Yong Zhi
From: Tomasz Figa 

This driver translates IO virtual address to physical
address based on two levels page tables.

Signed-off-by: Tomasz Figa 
Signed-off-by: Yong Zhi 
---
 drivers/media/pci/intel/ipu3/Kconfig|   7 +
 drivers/media/pci/intel/ipu3/Makefile   |   6 +
 drivers/media/pci/intel/ipu3/ipu3-mmu.c | 581 
 drivers/media/pci/intel/ipu3/ipu3-mmu.h |  39 +++
 4 files changed, 633 insertions(+)
 create mode 100644 drivers/media/pci/intel/ipu3/ipu3-mmu.c
 create mode 100644 drivers/media/pci/intel/ipu3/ipu3-mmu.h

diff --git a/drivers/media/pci/intel/ipu3/Kconfig 
b/drivers/media/pci/intel/ipu3/Kconfig
index 0861077a4dae..6beb11189ed2 100644
--- a/drivers/media/pci/intel/ipu3/Kconfig
+++ b/drivers/media/pci/intel/ipu3/Kconfig
@@ -17,3 +17,10 @@ config VIDEO_IPU3_CIO2
Say Y or M here if you have a Skylake/Kaby Lake SoC with MIPI CSI-2
connected camera.
The module will be called ipu3-cio2.
+
+config INTEL_IPU3_MMU
+   tristate
+   default n
+   ---help---
+ For IPU3, this option enables its MMU driver to translate its internal
+ virtual address to 39 bits wide physical address for 64GBytes space 
access.
diff --git a/drivers/media/pci/intel/ipu3/Makefile 
b/drivers/media/pci/intel/ipu3/Makefile
index 20186e3ff2ae..1cbb3cab83ef 100644
--- a/drivers/media/pci/intel/ipu3/Makefile
+++ b/drivers/media/pci/intel/ipu3/Makefile
@@ -1 +1,7 @@
+#
+# Makefile for the IPU3 cio2 and ImgU drivers
+#
+
 obj-$(CONFIG_VIDEO_IPU3_CIO2) += ipu3-cio2.o
+obj-$(CONFIG_INTEL_IPU3_MMU) += ipu3-mmu.o
+
diff --git a/drivers/media/pci/intel/ipu3/ipu3-mmu.c 
b/drivers/media/pci/intel/ipu3/ipu3-mmu.c
new file mode 100644
index ..8dd231ac8718
--- /dev/null
+++ b/drivers/media/pci/intel/ipu3/ipu3-mmu.c
@@ -0,0 +1,581 @@
+/*
+ * Copyright (c) 2017 Intel Corporation.
+ * Copyright (C) 2017 Google, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License version
+ * 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#include "ipu3-mmu.h"
+
+#define IPU3_PAGE_SHIFT12
+#define IPU3_PAGE_SIZE (1UL << IPU3_PAGE_SHIFT)
+
+#define IPU3_PT_BITS   10
+#define IPU3_PT_PTES   (1UL << IPU3_PT_BITS)
+#define IPU3_PT_SIZE   (IPU3_PT_PTES << 2)
+#define IPU3_PT_ORDER  (IPU3_PT_SIZE >> PAGE_SHIFT)
+
+#define IPU3_ADDR2PTE(addr)((addr) >> IPU3_PAGE_SHIFT)
+#define IPU3_PTE2ADDR(pte) ((phys_addr_t)(pte) << IPU3_PAGE_SHIFT)
+
+#define IPU3_L2PT_SHIFTIPU3_PT_BITS
+#define IPU3_L2PT_MASK ((1UL << IPU3_L2PT_SHIFT) - 1)
+
+#define IPU3_L1PT_SHIFTIPU3_PT_BITS
+#define IPU3_L1PT_MASK ((1UL << IPU3_L1PT_SHIFT) - 1)
+
+#define IPU3_MMU_ADDRESS_BITS  (IPU3_PAGE_SHIFT + \
+IPU3_L2PT_SHIFT + \
+IPU3_L1PT_SHIFT)
+
+#define IMGU_REG_BASE  0x4000
+#define REG_TLB_INVALIDATE (IMGU_REG_BASE + 0x300)
+#define TLB_INVALIDATE 1
+#define REG_L1_PHYS(IMGU_REG_BASE + 0x304) /* 27-bit pfn */
+#define REG_GP_HALT(IMGU_REG_BASE + 0x5dc)
+#define REG_GP_HALTED  (IMGU_REG_BASE + 0x5e0)
+
+struct ipu3_mmu {
+   struct device *dev;
+   void __iomem *base;
+   /* protect access to l2pts, l1pt */
+   spinlock_t lock;
+
+   void *dummy_page;
+   u32 dummy_page_pteval;
+
+   u32 *dummy_l2pt;
+   u32 dummy_l2pt_pteval;
+
+   u32 **l2pts;
+   u32 *l1pt;
+
+   struct ipu3_mmu_info geometry;
+};
+
+static inline struct ipu3_mmu *to_ipu3_mmu(struct ipu3_mmu_info *info)
+{
+   return container_of(info, struct ipu3_mmu, geometry);
+}
+
+/**
+ * ipu3_mmu_tlb_invalidate - invalidate translation look-aside buffer
+ * @mmu: MMU to perform the invalidate operation on
+ *
+ * This function invalidates the whole TLB. Must be called when the hardware
+ * is powered on.
+ */
+static void ipu3_mmu_tlb_invalidate(struct ipu3_mmu *mmu)
+{
+   writel(TLB_INVALIDATE, mmu->base + REG_TLB_INVALIDATE);
+}
+
+static void call_if_ipu3_is_powered(struct ipu3_mmu *mmu,
+   void (*func)(struct ipu3_mmu *mmu))
+{
+   pm_runtime_get_noresume(mmu->dev);
+   if (pm_runtime_active(mmu->dev))
+   func(mmu);
+   pm_runtime_put(mmu->dev);
+}
+
+/**
+ * ipu3_mmu_set_halt - set CIO gate halt bit
+ * @mmu: MMU to set the CIO gate bit in.
+ * @halt: Desired state of the gate bit.
+ *
+ * This function sets the CIO gate bit 

RE: [PATCH v4 04/12] intel-ipu3: Add user space ABI definitions

2017-12-01 Thread Mani, Rajmohan
Hi Sakari,

> -Original Message-
> From: sakari.ai...@linux.intel.com [mailto:sakari.ai...@linux.intel.com]
> Sent: Tuesday, November 21, 2017 9:22 AM
> To: Mani, Rajmohan 
> Cc: Sakari Ailus ; Zhi, Yong ; linux-
> me...@vger.kernel.org; Zheng, Jian Xu ; Toivonen,
> Tuukka ; Hu, Jerry W 
> Subject: Re: [PATCH v4 04/12] intel-ipu3: Add user space ABI definitions
> 
> Hi Rajmohan,
> 
> My apologies for the late reply.
> 
> On Sat, Nov 11, 2017 at 04:07:22AM +, Mani, Rajmohan wrote:
> > Hi Sakari,
> >
> > > -Original Message-
> > > From: Sakari Ailus [mailto:sakari.ai...@iki.fi]
> > > Sent: Friday, October 20, 2017 2:30 AM
> > > To: Zhi, Yong 
> > > Cc: linux-media@vger.kernel.org; sakari.ai...@linux.intel.com;
> > > Zheng, Jian Xu ; Mani, Rajmohan
> > > ; Toivonen, Tuukka
> > > ; Hu, Jerry W 
> > > Subject: Re: [PATCH v4 04/12] intel-ipu3: Add user space ABI
> > > definitions
> > >
> > > Hi Yong,
> > >
> > > On Tue, Oct 17, 2017 at 10:54:49PM -0500, Yong Zhi wrote:
> 
> ...
> 
> > > > +struct ipu3_uapi_params {
> > > > +   __u32 fourcc;   /* V4L2_PIX_FMT_IPU3_PARAMS */
> > > > +   __u32 version;  /* Must be 0x100 */
> > >
> > > These were called padding1 and padding2 in the previous version.
> > > What happened?
> > >
> > > I'd just call them reserved, and maybe also make the use field the
> > > first member of the struct.
> > >
> >
> > These fields were repurposed after v3 of this patch series. Please see the 
> > user
> space code that uses these fields.
> > https://chromium.googlesource.com/chromiumos/platform/arc-
> camera/+/mas
> > ter/hal/intel/psl/ipu3/workers/IPU3AicToFwEncoder.cpp
> 
> They were fourcc and version in the beginning, and then replaced by
> padding1 and padding 2. Is there a particular reason for changing them back?
> 

We looked into this further to see that we have no compelling reasons to use 
these variables.
I will revert these names back to padding1 and padding2, along with the 
required user space code changes.


Re: [PATCH 8/8] [media] staging: imx: use ktime_t for timestamps

2017-12-01 Thread Steve Longerbeam

Hi Arnd,

This looks fine to me, except for a couple things...

On 11/27/2017 05:20 AM, Arnd Bergmann wrote:

The imx media driver passes around monotonic timestamps in the deprecated
'timespec' format. This is not a problem for the driver, as they won't
overflow, but moving to either timespec64 or ktime_t is preferred.

I'm picking ktime_t for simplicity here. frame_interval_monitor() is
the main function that changes, as it tries to compare a time interval
in microseconds. The algorithm slightly changes here, to avoid 64-bit
division. The code previously assumed that the error was at most 32-bit
worth of microseconds here, so I'm making the same assumption but add
an explicit test for it.

Signed-off-by: Arnd Bergmann 
---
  drivers/staging/media/imx/imx-media-csi.c |  8 ++--
  drivers/staging/media/imx/imx-media-fim.c | 30 +-
  drivers/staging/media/imx/imx-media.h |  2 +-
  3 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/drivers/staging/media/imx/imx-media-csi.c 
b/drivers/staging/media/imx/imx-media-csi.c
index bb1d6dafca83..26994b429cf2 100644
--- a/drivers/staging/media/imx/imx-media-csi.c
+++ b/drivers/staging/media/imx/imx-media-csi.c
@@ -207,13 +207,9 @@ static irqreturn_t csi_idmac_eof_interrupt(int irq, void 
*dev_id)
goto unlock;
}
  
-	if (priv->fim) {

-   struct timespec cur_ts;
-
-   ktime_get_ts(_ts);
+   if (priv->fim)
/* call frame interval monitor */
-   imx_media_fim_eof_monitor(priv->fim, _ts);
-   }
+   imx_media_fim_eof_monitor(priv->fim, ktime_get());
  
  	csi_vb2_buf_done(priv);
  
diff --git a/drivers/staging/media/imx/imx-media-fim.c b/drivers/staging/media/imx/imx-media-fim.c

index 47275ef803f3..6df189135db8 100644
--- a/drivers/staging/media/imx/imx-media-fim.c
+++ b/drivers/staging/media/imx/imx-media-fim.c
@@ -66,7 +66,7 @@ struct imx_media_fim {
int   icap_flags;
  
  	int   counter;

-   struct timespec   last_ts;
+   ktime_t   last_ts;
unsigned long sum;   /* usec */
unsigned long nominal;   /* usec */
  
@@ -147,22 +147,26 @@ static void send_fim_event(struct imx_media_fim *fim, unsigned long error)

   * (presumably random) interrupt latency.
   */
  static void frame_interval_monitor(struct imx_media_fim *fim,
-  struct timespec *ts)
+  ktime_t timestamp)
  {
-   unsigned long interval, error, error_avg;
+   long long interval, error;
+   unsigned long error_avg;
bool send_event = false;
-   struct timespec diff;
  
  	if (!fim->enabled || ++fim->counter <= 0)

goto out_update_ts;
  
-	diff = timespec_sub(*ts, fim->last_ts);

-   interval = diff.tv_sec * 1000 * 1000 + diff.tv_nsec / 1000;
-   error = abs(interval - fim->nominal);
+   /* max error is less than l00µs, so use 32-bit division or fail */


This comment doesn't make sense. By "max error" maybe you are referring
to the tolerance_max control, which is limited to 500 usec, but if set 
to zero

(or less than tolerance_min), there is no max error, it is unbounded. Please
just remove this comment.


+   interval = ktime_to_ns(ktime_sub(timestamp, fim->last_ts));
+   error = abs(interval - NSEC_PER_USEC * (u64)fim->nominal);
+   if (error > U32_MAX)
+   error = U32_MAX;
+   else
+   error = abs((u32)error / NSEC_PER_USEC);


Why the second abs() ?

How about the following:

-   if (error > U32_MAX)
-   error = U32_MAX;
-   else
-   error = abs((u32)error / NSEC_PER_USEC);
+   /* convert interval error to usec using 32-bit divide */
+   error = (u32)min_t(long long, error, U32_MAX) / NSEC_PER_USEC;


Steve


  
  	if (fim->tolerance_max && error >= fim->tolerance_max) {

dev_dbg(fim->sd->dev,
-   "FIM: %lu ignored, out of tolerance bounds\n",
+   "FIM: %llu ignored, out of tolerance bounds\n",
error);
fim->counter--;
goto out_update_ts;
@@ -184,7 +188,7 @@ static void frame_interval_monitor(struct imx_media_fim 
*fim,
}
  
  out_update_ts:

-   fim->last_ts = *ts;
+   fim->last_ts = timestamp;
if (send_event)
send_fim_event(fim, error_avg);
  }
@@ -195,14 +199,14 @@ static void frame_interval_monitor(struct imx_media_fim 
*fim,
   * to interrupt latency.
   */
  static void fim_input_capture_handler(int channel, void *dev_id,
- struct timespec *ts)
+ ktime_t timestamp)
  {
struct imx_media_fim *fim = dev_id;
unsigned long flags;
  
  	spin_lock_irqsave(>lock, flags);
  
-	frame_interval_monitor(fim, ts);

+   frame_interval_monitor(fim, 

[PATCH v3 3/3] media: atomisp: delete empty default struct values.

2017-12-01 Thread Jeremy Sowden
Removing zero-valued struct-members left a number of the default
struct-values empty.  These values have now been removed.

Signed-off-by: Jeremy Sowden 
---
 .../atomisp/pci/atomisp2/css2400/ia_css_pipe.h |  1 -
 .../atomisp/pci/atomisp2/css2400/ia_css_types.h|  1 -
 .../isp/kernels/s3a/s3a_1.0/ia_css_s3a_types.h |  6 ---
 .../kernels/sdis/common/ia_css_sdis_common_types.h | 46 --
 .../isp/kernels/sdis/sdis_1.0/ia_css_sdis.host.c   |  2 +-
 .../runtime/binary/interface/ia_css_binary.h   |  9 -
 .../isp_param/interface/ia_css_isp_param_types.h   | 15 ---
 .../media/atomisp/pci/atomisp2/css2400/sh_css.c|  9 ++---
 .../atomisp/pci/atomisp2/css2400/sh_css_legacy.h   |  5 ---
 .../atomisp/pci/atomisp2/css2400/sh_css_metrics.h  | 12 --
 10 files changed, 12 insertions(+), 94 deletions(-)

diff --git a/drivers/staging/media/atomisp/pci/atomisp2/css2400/ia_css_pipe.h 
b/drivers/staging/media/atomisp/pci/atomisp2/css2400/ia_css_pipe.h
index a68eac6de36a..3f3c85c2f360 100644
--- a/drivers/staging/media/atomisp/pci/atomisp2/css2400/ia_css_pipe.h
+++ b/drivers/staging/media/atomisp/pci/atomisp2/css2400/ia_css_pipe.h
@@ -167,7 +167,6 @@ struct ia_css_pipe {
 #define IA_CSS_DEFAULT_PIPE ( \
(struct ia_css_pipe) { \
.config = DEFAULT_PIPE_CONFIG, \
-   .extra_config   = DEFAULT_PIPE_EXTRA_CONFIG, \
.info   = DEFAULT_PIPE_INFO, \
.mode   = IA_CSS_PIPE_ID_ACC, /* (pipe_id) */ \
.pipeline   = DEFAULT_PIPELINE, \
diff --git a/drivers/staging/media/atomisp/pci/atomisp2/css2400/ia_css_types.h 
b/drivers/staging/media/atomisp/pci/atomisp2/css2400/ia_css_types.h
index e9ab800ae128..914049b56bc7 100644
--- a/drivers/staging/media/atomisp/pci/atomisp2/css2400/ia_css_types.h
+++ b/drivers/staging/media/atomisp/pci/atomisp2/css2400/ia_css_types.h
@@ -408,7 +408,6 @@ struct ia_css_grid_info {
 /* defaults for ia_css_grid_info structs */
 #define DEFAULT_GRID_INFO ( \
(struct ia_css_grid_info) { \
-   .s3a_grid   = DEFAULT_3A_GRID_INFO, \
.dvs_grid   = DEFAULT_DVS_GRID_INFO, \
.vamem_type = IA_CSS_VAMEM_TYPE_1 \
} \
diff --git 
a/drivers/staging/media/atomisp/pci/atomisp2/css2400/isp/kernels/s3a/s3a_1.0/ia_css_s3a_types.h
 
b/drivers/staging/media/atomisp/pci/atomisp2/css2400/isp/kernels/s3a/s3a_1.0/ia_css_s3a_types.h
index 4b8bdc973d4b..63e70669f085 100644
--- 
a/drivers/staging/media/atomisp/pci/atomisp2/css2400/isp/kernels/s3a/s3a_1.0/ia_css_s3a_types.h
+++ 
b/drivers/staging/media/atomisp/pci/atomisp2/css2400/isp/kernels/s3a/s3a_1.0/ia_css_s3a_types.h
@@ -98,12 +98,6 @@ struct ia_css_3a_grid_info {
 };
 
 
-#define DEFAULT_3A_GRID_INFO ( \
-   (struct ia_css_3a_grid_info) { \
-   } \
-)
-
-
 /* This struct should be split into 3, for AE, AWB and AF.
  * However, that will require driver/ 3A lib modifications.
  */
diff --git 
a/drivers/staging/media/atomisp/pci/atomisp2/css2400/isp/kernels/sdis/common/ia_css_sdis_common_types.h
 
b/drivers/staging/media/atomisp/pci/atomisp2/css2400/isp/kernels/sdis/common/ia_css_sdis_common_types.h
index b9adc2af7603..f74941d49e8b 100644
--- 
a/drivers/staging/media/atomisp/pci/atomisp2/css2400/isp/kernels/sdis/common/ia_css_sdis_common_types.h
+++ 
b/drivers/staging/media/atomisp/pci/atomisp2/css2400/isp/kernels/sdis/common/ia_css_sdis_common_types.h
@@ -41,12 +41,6 @@ struct ia_css_sdis_info {
uint32_t deci_factor_log2;
 };
 
-#define IA_CSS_DEFAULT_SDIS_INFO ( \
-   (struct ia_css_sdis_info) { \
-   } \
-)
-
-
 /* DVS statistics grid
  *
  *  ISP block: SDVS1 (DIS/DVS Support for DIS/DVS ver.1 (2-axes))
@@ -201,41 +195,15 @@ struct ia_css_dvs_stat_grid_info {
 
 /* DVS statistics generated by accelerator default grid info
  */
-#define DEFAULT_DVS_STAT_PUBLIC_DVS_GLOBAL_CFG ( \
-   (struct dvs_stat_public_dvs_global_cfg) { \
-   } \
-)
-
-#define DEFAULT_DVS_STAT_PUBLIC_DVS_GRD_CFG ( \
-   (struct dvs_stat_public_dvs_grd_cfg) { \
-   } \
-)
-
-#define DEFAULT_DVS_STAT_PUBLIC_DVS_LEVEL_FE_ROI_CFG(X_START) ( \
-   (struct dvs_stat_public_dvs_level_fe_roi_cfg) { \
-   .x_start = X_START, \
-   } \
-)
-
-#define DEFAULT_DVS_STAT_GRID_INFO ( \
-   (struct ia_css_dvs_stat_grid_info) { \
-   .dvs_gbl_cfg = DEFAULT_DVS_STAT_PUBLIC_DVS_GLOBAL_CFG, \
-   .grd_cfg = { \
-   DEFAULT_DVS_STAT_PUBLIC_DVS_GRD_CFG, \
-   DEFAULT_DVS_STAT_PUBLIC_DVS_GRD_CFG, \
-   DEFAULT_DVS_STAT_PUBLIC_DVS_GRD_CFG \
-   }, \
-   .fe_roi_cfg = { \
-   DEFAULT_DVS_STAT_PUBLIC_DVS_LEVEL_FE_ROI_CFG(0), \
-   DEFAULT_DVS_STAT_PUBLIC_DVS_LEVEL_FE_ROI_CFG(4), \
-   DEFAULT_DVS_STAT_PUBLIC_DVS_LEVEL_FE_ROI_CFG(0), 

[PATCH v3 1/3] media: atomisp: convert default struct values to use compound-literals with designated initializers.

2017-12-01 Thread Jeremy Sowden
The CSS API uses a lot of nested anonymous structs defined in object
macros to assign default values to its data-structures.  These have been
changed to use compound-literals and designated initializers to make
them more comprehensible and less fragile.

The compound-literals can also be used in assignment, which means we can
get rid of some temporary variables whose only purpose is to be
initialized by one of these anonymous structs and then serve as the
rvalue in an assignment expression.

Signed-off-by: Jeremy Sowden 
---
 .../hive_isp_css_common/input_formatter_global.h   |  31 ++--
 .../pci/atomisp2/css2400/ia_css_frame_public.h |  56 ---
 .../atomisp/pci/atomisp2/css2400/ia_css_pipe.h | 173 +++--
 .../pci/atomisp2/css2400/ia_css_pipe_public.h  | 159 +--
 .../atomisp/pci/atomisp2/css2400/ia_css_types.h|  98 ++--
 .../isp/kernels/s3a/s3a_1.0/ia_css_s3a_types.h | 149 +-
 .../kernels/sdis/common/ia_css_sdis_common_types.h |  96 +---
 .../isp/kernels/sdis/sdis_1.0/ia_css_sdis.host.c   |   3 +-
 .../runtime/binary/interface/ia_css_binary.h   | 155 +-
 .../atomisp2/css2400/runtime/binary/src/binary.c   |   3 +-
 .../isp_param/interface/ia_css_isp_param_types.h   |  32 ++--
 .../runtime/pipeline/interface/ia_css_pipeline.h   |  35 +++--
 .../css2400/runtime/pipeline/src/pipeline.c|   7 +-
 .../media/atomisp/pci/atomisp2/css2400/sh_css.c|  22 +--
 .../atomisp/pci/atomisp2/css2400/sh_css_legacy.h   |  21 +--
 .../atomisp/pci/atomisp2/css2400/sh_css_metrics.h  |  36 ++---
 16 files changed, 613 insertions(+), 463 deletions(-)

diff --git 
a/drivers/staging/media/atomisp/pci/atomisp2/css2400/hive_isp_css_common/input_formatter_global.h
 
b/drivers/staging/media/atomisp/pci/atomisp2/css2400/hive_isp_css_common/input_formatter_global.h
index 5654d911db65..5e19b5bd56e6 100644
--- 
a/drivers/staging/media/atomisp/pci/atomisp2/css2400/hive_isp_css_common/input_formatter_global.h
+++ 
b/drivers/staging/media/atomisp/pci/atomisp2/css2400/hive_isp_css_common/input_formatter_global.h
@@ -107,21 +107,22 @@ struct input_formatter_cfg_s {
uint32_tblock_no_reqs;
 };
 
-#define DEFAULT_IF_CONFIG \
-{ \
-   0,  /* start_line */\
-   0,  /* start_column */\
-   0,  /* left_padding */\
-   0,  /* cropped_height */\
-   0,  /* cropped_width */\
-   0,  /* deinterleaving */\
-   0,  /*.buf_vecs */\
-   0,  /* buf_start_index */\
-   0,  /* buf_increment */\
-   0,  /* buf_eol_offset */\
-   false,  /* is_yuv420_format */\
-   false   /* block_no_reqs */\
-}
+#define DEFAULT_IF_CONFIG ( \
+   (struct input_formatter_cfg_s) { \
+   .start_line = 0, \
+   .start_column   = 0, \
+   .left_padding   = 0, \
+   .cropped_height = 0, \
+   .cropped_width  = 0, \
+   .deinterleaving = 0, \
+   .buf_vecs   = 0, \
+   .buf_start_index= 0, \
+   .buf_increment  = 0, \
+   .buf_eol_offset = 0, \
+   .is_yuv420_format   = false, \
+   .block_no_reqs  = false \
+   } \
+)
 
 extern const hrt_address HIVE_IF_SRST_ADDRESS[N_INPUT_FORMATTER_ID];
 extern const hrt_data HIVE_IF_SRST_MASK[N_INPUT_FORMATTER_ID];
diff --git 
a/drivers/staging/media/atomisp/pci/atomisp2/css2400/ia_css_frame_public.h 
b/drivers/staging/media/atomisp/pci/atomisp2/css2400/ia_css_frame_public.h
index ba7a076c3afa..d0408884c524 100644
--- a/drivers/staging/media/atomisp/pci/atomisp2/css2400/ia_css_frame_public.h
+++ b/drivers/staging/media/atomisp/pci/atomisp2/css2400/ia_css_frame_public.h
@@ -120,17 +120,22 @@ struct ia_css_frame_info {
struct ia_css_crop_info crop_info;
 };
 
-#define IA_CSS_BINARY_DEFAULT_FRAME_INFO \
-{ \
-   {0,  /* width */ \
-0}, /* height */ \
-   0,   /* padded_width */ \
-   IA_CSS_FRAME_FORMAT_NUM, /* format */ \
-   0,   /* raw_bit_depth */ \
-   IA_CSS_BAYER_ORDER_NUM,  /* raw_bayer_order */ \
-   {0,   /*start col */ \
-0},   /*start line */ \
-}
+#define IA_CSS_BINARY_DEFAULT_FRAME_INFO ( \
+   (struct ia_css_frame_info) { \
+   .res= (struct ia_css_resolution) { \
+   .width = 0, \
+   .height = 0 \
+   }, \
+   .padded_width   = 0, \
+   .format = IA_CSS_FRAME_FORMAT_NUM,  \
+   .raw_bit_depth  = 0, \
+   

[PATCH v3 2/3] media: atomisp: delete zero-valued struct members.

2017-12-01 Thread Jeremy Sowden
A lot of the members of the default struct values used by the CSS API
were explicitly initialized to zero values.  Designated initializers
have allowed these members to be removed.

Signed-off-by: Jeremy Sowden 
---
 .../hive_isp_css_common/input_formatter_global.h   |  17 
 .../pci/atomisp2/css2400/ia_css_frame_public.h |  17 
 .../atomisp/pci/atomisp2/css2400/ia_css_pipe.h |  44 +---
 .../pci/atomisp2/css2400/ia_css_pipe_public.h  |  81 ---
 .../atomisp/pci/atomisp2/css2400/ia_css_types.h|  48 +
 .../isp/kernels/s3a/s3a_1.0/ia_css_s3a_types.h | 111 -
 .../kernels/sdis/common/ia_css_sdis_common_types.h |  34 ---
 .../runtime/binary/interface/ia_css_binary.h   |  89 ++---
 .../isp_param/interface/ia_css_isp_param_types.h   |   9 --
 .../runtime/pipeline/interface/ia_css_pipeline.h   |   6 --
 .../atomisp/pci/atomisp2/css2400/sh_css_legacy.h   |   7 --
 .../atomisp/pci/atomisp2/css2400/sh_css_metrics.h  |   7 --
 12 files changed, 20 insertions(+), 450 deletions(-)

diff --git 
a/drivers/staging/media/atomisp/pci/atomisp2/css2400/hive_isp_css_common/input_formatter_global.h
 
b/drivers/staging/media/atomisp/pci/atomisp2/css2400/hive_isp_css_common/input_formatter_global.h
index 5e19b5bd56e6..7558f4964313 100644
--- 
a/drivers/staging/media/atomisp/pci/atomisp2/css2400/hive_isp_css_common/input_formatter_global.h
+++ 
b/drivers/staging/media/atomisp/pci/atomisp2/css2400/hive_isp_css_common/input_formatter_global.h
@@ -107,23 +107,6 @@ struct input_formatter_cfg_s {
uint32_tblock_no_reqs;
 };
 
-#define DEFAULT_IF_CONFIG ( \
-   (struct input_formatter_cfg_s) { \
-   .start_line = 0, \
-   .start_column   = 0, \
-   .left_padding   = 0, \
-   .cropped_height = 0, \
-   .cropped_width  = 0, \
-   .deinterleaving = 0, \
-   .buf_vecs   = 0, \
-   .buf_start_index= 0, \
-   .buf_increment  = 0, \
-   .buf_eol_offset = 0, \
-   .is_yuv420_format   = false, \
-   .block_no_reqs  = false \
-   } \
-)
-
 extern const hrt_address HIVE_IF_SRST_ADDRESS[N_INPUT_FORMATTER_ID];
 extern const hrt_data HIVE_IF_SRST_MASK[N_INPUT_FORMATTER_ID];
 extern const uint8_t HIVE_IF_SWITCH_CODE[N_INPUT_FORMATTER_ID];
diff --git 
a/drivers/staging/media/atomisp/pci/atomisp2/css2400/ia_css_frame_public.h 
b/drivers/staging/media/atomisp/pci/atomisp2/css2400/ia_css_frame_public.h
index d0408884c524..972863fcaf9e 100644
--- a/drivers/staging/media/atomisp/pci/atomisp2/css2400/ia_css_frame_public.h
+++ b/drivers/staging/media/atomisp/pci/atomisp2/css2400/ia_css_frame_public.h
@@ -122,18 +122,8 @@ struct ia_css_frame_info {
 
 #define IA_CSS_BINARY_DEFAULT_FRAME_INFO ( \
(struct ia_css_frame_info) { \
-   .res= (struct ia_css_resolution) { \
-   .width = 0, \
-   .height = 0 \
-   }, \
-   .padded_width   = 0, \
.format = IA_CSS_FRAME_FORMAT_NUM,  \
-   .raw_bit_depth  = 0, \
.raw_bayer_order= IA_CSS_BAYER_ORDER_NUM, \
-   .crop_info  = (struct ia_css_crop_info) { \
-   .start_column   = 0, \
-   .start_line = 0 \
-   }, \
} \
 )
 
@@ -197,16 +187,9 @@ struct ia_css_frame {
 #define DEFAULT_FRAME ( \
(struct ia_css_frame) { \
.info   = IA_CSS_BINARY_DEFAULT_FRAME_INFO, \
-   .data   = 0, \
-   .data_bytes = 0, \
.dynamic_queue_id   = SH_CSS_INVALID_QUEUE_ID, \
.buf_type   = IA_CSS_BUFFER_TYPE_INVALID, \
.flash_state= IA_CSS_FRAME_FLASH_STATE_NONE, \
-   .exp_id = 0, \
-   .isp_config_id  = 0, \
-   .valid  = false, \
-   .contiguous = false, \
-   .planes = { 0 } \
} \
 )
 
diff --git a/drivers/staging/media/atomisp/pci/atomisp2/css2400/ia_css_pipe.h 
b/drivers/staging/media/atomisp/pci/atomisp2/css2400/ia_css_pipe.h
index bfebfd8d6e63..a68eac6de36a 100644
--- a/drivers/staging/media/atomisp/pci/atomisp2/css2400/ia_css_pipe.h
+++ b/drivers/staging/media/atomisp/pci/atomisp2/css2400/ia_css_pipe.h
@@ -39,16 +39,11 @@ struct ia_css_preview_settings {
struct ia_css_pipe *acc_pipe;
 };
 
-#define IA_CSS_DEFAULT_PREVIEW_SETTINGS  ( \
+#define 

[PATCH v3 0/3] media: atomisp: clean up of data-structure initialization in the CSS API

2017-12-01 Thread Jeremy Sowden
v3.

  Rebased on to git://linuxtv.org/media_tree.git.  Patch-set applies cleanly to
  linux-next as of 20171201.

v2.

  Fixed a couple of bugs and addressed checkpatch errors.

v1.

  The CSS API uses a lot of nested anonymous structs defined in object
  macros to assign default values to its data-structures.  These have
  been changed to use compound-literals and designated initializers to
  make them more comprehensible and less fragile.

  The compound-literals can also be used in assignment, which made it
  possible get rid of some temporary variables whose only purpose is to
  be initialized by one of these anonymous structs and then serve as the
  rvalue in an assignment expression.

  The designated initializers also allow the removal of lots of
  struct-members initialized to zero values.

  I made the changes in three stages: firstly, I converted the default
  values to compound-literals and designated initializers and removed
  the temporary variables; secondly, I removed the zero-valued
  struct-members; finally, I removed some structs which had become
  empty.

Jeremy Sowden (3):
  media: atomisp: convert default struct values to use compound-literals
with designated initializers.
  media: atomisp: delete zero-valued struct members.
  media: atomisp: delete empty default struct values.

 .../hive_isp_css_common/input_formatter_global.h   |  16 ---
 .../pci/atomisp2/css2400/ia_css_frame_public.h |  39 +++---
 .../atomisp/pci/atomisp2/css2400/ia_css_pipe.h | 138 -
 .../pci/atomisp2/css2400/ia_css_pipe_public.h  | 118 +++---
 .../atomisp/pci/atomisp2/css2400/ia_css_types.h|  79 
 .../isp/kernels/s3a/s3a_1.0/ia_css_s3a_types.h |  50 +---
 .../kernels/sdis/common/ia_css_sdis_common_types.h |  34 ++---
 .../isp/kernels/sdis/sdis_1.0/ia_css_sdis.host.c   |   3 +-
 .../runtime/binary/interface/ia_css_binary.h   |  93 ++
 .../atomisp2/css2400/runtime/binary/src/binary.c   |   3 +-
 .../isp_param/interface/ia_css_isp_param_types.h   |  10 --
 .../runtime/pipeline/interface/ia_css_pipeline.h   |  29 ++---
 .../css2400/runtime/pipeline/src/pipeline.c|   7 +-
 .../media/atomisp/pci/atomisp2/css2400/sh_css.c|  31 ++---
 .../atomisp/pci/atomisp2/css2400/sh_css_legacy.h   |  11 --
 .../atomisp/pci/atomisp2/css2400/sh_css_metrics.h  |  21 
 16 files changed, 160 insertions(+), 522 deletions(-)


base-commit: 781b045baefdabf7e0bc9f33672ca830d3db9f27
-- 
2.15.0



Re: [PATCH v2] media: imx: Remove incorrect check for queue state in start/stop_streaming

2017-12-01 Thread Steve Longerbeam



On 12/01/2017 10:53 AM, Ian Jamison wrote:

It is possible to call STREAMON without the minimum number of
buffers queued. In this case the vb2_queue state will be set to
streaming but the start_streaming vb2_op will not be called.
Later when enough buffers are queued, start_streaming will
be called but vb2_is_streaming will already return true.

Also removed the queue state check in stop_streaming since it's
not valid there either.


Reviewed-by: Steve Longerbeam 


Signed-off-by: Ian Jamison 
---
Since v1:
 Remove check in capture_stop_streaming as recommended by Hans.

  drivers/staging/media/imx/imx-media-capture.c | 6 --
  1 file changed, 6 deletions(-)

diff --git a/drivers/staging/media/imx/imx-media-capture.c 
b/drivers/staging/media/imx/imx-media-capture.c
index ea145bafb880..7b6763802db8 100644
--- a/drivers/staging/media/imx/imx-media-capture.c
+++ b/drivers/staging/media/imx/imx-media-capture.c
@@ -449,9 +449,6 @@ static int capture_start_streaming(struct vb2_queue *vq, 
unsigned int count)
unsigned long flags;
int ret;
  
-	if (vb2_is_streaming(vq))

-   return 0;
-
ret = imx_media_pipeline_set_stream(priv->md, >src_sd->entity,
true);
if (ret) {
@@ -480,9 +477,6 @@ static void capture_stop_streaming(struct vb2_queue *vq)
unsigned long flags;
int ret;
  
-	if (!vb2_is_streaming(vq))

-   return;
-
spin_lock_irqsave(>q_lock, flags);
priv->stop = true;
spin_unlock_irqrestore(>q_lock, flags);




[PATCH v2] media: imx: Remove incorrect check for queue state in start/stop_streaming

2017-12-01 Thread Ian Jamison
It is possible to call STREAMON without the minimum number of
buffers queued. In this case the vb2_queue state will be set to
streaming but the start_streaming vb2_op will not be called.
Later when enough buffers are queued, start_streaming will
be called but vb2_is_streaming will already return true.

Also removed the queue state check in stop_streaming since it's
not valid there either.

Signed-off-by: Ian Jamison 
---
Since v1:
Remove check in capture_stop_streaming as recommended by Hans.

 drivers/staging/media/imx/imx-media-capture.c | 6 --
 1 file changed, 6 deletions(-)

diff --git a/drivers/staging/media/imx/imx-media-capture.c 
b/drivers/staging/media/imx/imx-media-capture.c
index ea145bafb880..7b6763802db8 100644
--- a/drivers/staging/media/imx/imx-media-capture.c
+++ b/drivers/staging/media/imx/imx-media-capture.c
@@ -449,9 +449,6 @@ static int capture_start_streaming(struct vb2_queue *vq, 
unsigned int count)
unsigned long flags;
int ret;
 
-   if (vb2_is_streaming(vq))
-   return 0;
-
ret = imx_media_pipeline_set_stream(priv->md, >src_sd->entity,
true);
if (ret) {
@@ -480,9 +477,6 @@ static void capture_stop_streaming(struct vb2_queue *vq)
unsigned long flags;
int ret;
 
-   if (!vb2_is_streaming(vq))
-   return;
-
spin_lock_irqsave(>q_lock, flags);
priv->stop = true;
spin_unlock_irqrestore(>q_lock, flags);
-- 
2.15.0



Re: [PATCH v2 2/3] media: atomisp: delete zero-valued struct members.

2017-12-01 Thread Alan Cox

> --- a/drivers/staging/media/atomisp/pci/atomisp2/css2400/ia_css_pipe_public.h
> +++ b/drivers/staging/media/atomisp/pci/atomisp2/css2400/ia_css_pipe_public.h
> @@ -152,14 +152,6 @@ struct ia_css_pipe_config {
>  };
>  


Thani you that's a really good cleanup.

Alan



[PATCH v2 2/3] media: atomisp: delete zero-valued struct members.

2017-12-01 Thread Jeremy Sowden
A lot of the members of the default struct values used by the CSS API
were explicitly initialized to zero values.  Designated initializers
have allowed these members to be removed.

Signed-off-by: Jeremy Sowden 
---
 .../hive_isp_css_common/input_formatter_global.h   |  17 
 .../pci/atomisp2/css2400/ia_css_frame_public.h |  17 
 .../atomisp/pci/atomisp2/css2400/ia_css_pipe.h |  44 +---
 .../pci/atomisp2/css2400/ia_css_pipe_public.h  |  81 ---
 .../atomisp/pci/atomisp2/css2400/ia_css_types.h|  48 +
 .../isp/kernels/s3a/s3a_1.0/ia_css_s3a_types.h | 111 -
 .../kernels/sdis/common/ia_css_sdis_common_types.h |  35 ---
 .../runtime/binary/interface/ia_css_binary.h   |  89 ++---
 .../isp_param/interface/ia_css_isp_param_types.h   |   9 --
 .../runtime/pipeline/interface/ia_css_pipeline.h   |   6 --
 .../atomisp/pci/atomisp2/css2400/sh_css_legacy.h   |   7 --
 .../atomisp/pci/atomisp2/css2400/sh_css_metrics.h  |   7 --
 12 files changed, 20 insertions(+), 451 deletions(-)

diff --git 
a/drivers/staging/media/atomisp/pci/atomisp2/css2400/hive_isp_css_common/input_formatter_global.h
 
b/drivers/staging/media/atomisp/pci/atomisp2/css2400/hive_isp_css_common/input_formatter_global.h
index 5e19b5bd56e6..7558f4964313 100644
--- 
a/drivers/staging/media/atomisp/pci/atomisp2/css2400/hive_isp_css_common/input_formatter_global.h
+++ 
b/drivers/staging/media/atomisp/pci/atomisp2/css2400/hive_isp_css_common/input_formatter_global.h
@@ -107,23 +107,6 @@ struct input_formatter_cfg_s {
uint32_tblock_no_reqs;
 };
 
-#define DEFAULT_IF_CONFIG ( \
-   (struct input_formatter_cfg_s) { \
-   .start_line = 0, \
-   .start_column   = 0, \
-   .left_padding   = 0, \
-   .cropped_height = 0, \
-   .cropped_width  = 0, \
-   .deinterleaving = 0, \
-   .buf_vecs   = 0, \
-   .buf_start_index= 0, \
-   .buf_increment  = 0, \
-   .buf_eol_offset = 0, \
-   .is_yuv420_format   = false, \
-   .block_no_reqs  = false \
-   } \
-)
-
 extern const hrt_address HIVE_IF_SRST_ADDRESS[N_INPUT_FORMATTER_ID];
 extern const hrt_data HIVE_IF_SRST_MASK[N_INPUT_FORMATTER_ID];
 extern const uint8_t HIVE_IF_SWITCH_CODE[N_INPUT_FORMATTER_ID];
diff --git 
a/drivers/staging/media/atomisp/pci/atomisp2/css2400/ia_css_frame_public.h 
b/drivers/staging/media/atomisp/pci/atomisp2/css2400/ia_css_frame_public.h
index 56527feeb558..980b36171ca7 100644
--- a/drivers/staging/media/atomisp/pci/atomisp2/css2400/ia_css_frame_public.h
+++ b/drivers/staging/media/atomisp/pci/atomisp2/css2400/ia_css_frame_public.h
@@ -122,18 +122,8 @@ struct ia_css_frame_info {
 
 #define IA_CSS_BINARY_DEFAULT_FRAME_INFO ( \
(struct ia_css_frame_info) { \
-   .res= (struct ia_css_resolution) { \
-   .width = 0, \
-   .height = 0 \
-   }, \
-   .padded_width   = 0, \
.format = IA_CSS_FRAME_FORMAT_NUM,  \
-   .raw_bit_depth  = 0, \
.raw_bayer_order= IA_CSS_BAYER_ORDER_NUM, \
-   .crop_info  = (struct ia_css_crop_info) { \
-   .start_column   = 0, \
-   .start_line = 0 \
-   }, \
} \
 )
 
@@ -197,16 +187,9 @@ struct ia_css_frame {
 #define DEFAULT_FRAME ( \
(struct ia_css_frame) { \
.info   = IA_CSS_BINARY_DEFAULT_FRAME_INFO, \
-   .data   = 0, \
-   .data_bytes = 0, \
.dynamic_queue_id   = SH_CSS_INVALID_QUEUE_ID, \
.buf_type   = IA_CSS_BUFFER_TYPE_INVALID, \
.flash_state= IA_CSS_FRAME_FLASH_STATE_NONE, \
-   .exp_id = 0, \
-   .isp_config_id  = 0, \
-   .valid  = false, \
-   .contiguous = false, \
-   .planes = { 0 } \
} \
 )
 
diff --git a/drivers/staging/media/atomisp/pci/atomisp2/css2400/ia_css_pipe.h 
b/drivers/staging/media/atomisp/pci/atomisp2/css2400/ia_css_pipe.h
index bfebfd8d6e63..a68eac6de36a 100644
--- a/drivers/staging/media/atomisp/pci/atomisp2/css2400/ia_css_pipe.h
+++ b/drivers/staging/media/atomisp/pci/atomisp2/css2400/ia_css_pipe.h
@@ -39,16 +39,11 @@ struct ia_css_preview_settings {
struct ia_css_pipe *acc_pipe;
 };
 
-#define IA_CSS_DEFAULT_PREVIEW_SETTINGS  ( \
+#define 

[PATCH v2 1/3] media: atomisp: convert default struct values to use compound-literals with designated initializers.

2017-12-01 Thread Jeremy Sowden
The CSS API uses a lot of nested anonymous structs defined in object
macros to assign default values to its data-structures.  These have been
changed to use compound-literals and designated initializers to make
them more comprehensible and less fragile.

The compound-literals can also be used in assignment, which means we can
get rid of some temporary variables whose only purpose is to be
initialized by one of these anonymous structs and then serve as the
rvalue in an assignment expression.

Signed-off-by: Jeremy Sowden 
---
 .../hive_isp_css_common/input_formatter_global.h   |  31 ++--
 .../pci/atomisp2/css2400/ia_css_frame_public.h |  56 ---
 .../atomisp/pci/atomisp2/css2400/ia_css_pipe.h | 173 +++--
 .../pci/atomisp2/css2400/ia_css_pipe_public.h  | 159 +--
 .../atomisp/pci/atomisp2/css2400/ia_css_types.h|  98 ++--
 .../isp/kernels/s3a/s3a_1.0/ia_css_s3a_types.h | 149 +-
 .../kernels/sdis/common/ia_css_sdis_common_types.h |  96 +---
 .../isp/kernels/sdis/sdis_1.0/ia_css_sdis.host.c   |   3 +-
 .../runtime/binary/interface/ia_css_binary.h   | 155 +-
 .../atomisp2/css2400/runtime/binary/src/binary.c   |   3 +-
 .../isp_param/interface/ia_css_isp_param_types.h   |  32 ++--
 .../runtime/pipeline/interface/ia_css_pipeline.h   |  35 +++--
 .../css2400/runtime/pipeline/src/pipeline.c|   7 +-
 .../media/atomisp/pci/atomisp2/css2400/sh_css.c|  22 +--
 .../atomisp/pci/atomisp2/css2400/sh_css_legacy.h   |  21 +--
 .../atomisp/pci/atomisp2/css2400/sh_css_metrics.h  |  36 ++---
 16 files changed, 613 insertions(+), 463 deletions(-)

diff --git 
a/drivers/staging/media/atomisp/pci/atomisp2/css2400/hive_isp_css_common/input_formatter_global.h
 
b/drivers/staging/media/atomisp/pci/atomisp2/css2400/hive_isp_css_common/input_formatter_global.h
index 5654d911db65..5e19b5bd56e6 100644
--- 
a/drivers/staging/media/atomisp/pci/atomisp2/css2400/hive_isp_css_common/input_formatter_global.h
+++ 
b/drivers/staging/media/atomisp/pci/atomisp2/css2400/hive_isp_css_common/input_formatter_global.h
@@ -107,21 +107,22 @@ struct input_formatter_cfg_s {
uint32_tblock_no_reqs;
 };
 
-#define DEFAULT_IF_CONFIG \
-{ \
-   0,  /* start_line */\
-   0,  /* start_column */\
-   0,  /* left_padding */\
-   0,  /* cropped_height */\
-   0,  /* cropped_width */\
-   0,  /* deinterleaving */\
-   0,  /*.buf_vecs */\
-   0,  /* buf_start_index */\
-   0,  /* buf_increment */\
-   0,  /* buf_eol_offset */\
-   false,  /* is_yuv420_format */\
-   false   /* block_no_reqs */\
-}
+#define DEFAULT_IF_CONFIG ( \
+   (struct input_formatter_cfg_s) { \
+   .start_line = 0, \
+   .start_column   = 0, \
+   .left_padding   = 0, \
+   .cropped_height = 0, \
+   .cropped_width  = 0, \
+   .deinterleaving = 0, \
+   .buf_vecs   = 0, \
+   .buf_start_index= 0, \
+   .buf_increment  = 0, \
+   .buf_eol_offset = 0, \
+   .is_yuv420_format   = false, \
+   .block_no_reqs  = false \
+   } \
+)
 
 extern const hrt_address HIVE_IF_SRST_ADDRESS[N_INPUT_FORMATTER_ID];
 extern const hrt_data HIVE_IF_SRST_MASK[N_INPUT_FORMATTER_ID];
diff --git 
a/drivers/staging/media/atomisp/pci/atomisp2/css2400/ia_css_frame_public.h 
b/drivers/staging/media/atomisp/pci/atomisp2/css2400/ia_css_frame_public.h
index 92f2389176b2..56527feeb558 100644
--- a/drivers/staging/media/atomisp/pci/atomisp2/css2400/ia_css_frame_public.h
+++ b/drivers/staging/media/atomisp/pci/atomisp2/css2400/ia_css_frame_public.h
@@ -120,17 +120,22 @@ struct ia_css_frame_info {
struct ia_css_crop_info crop_info;
 };
 
-#define IA_CSS_BINARY_DEFAULT_FRAME_INFO \
-{ \
-   {0,  /* width */ \
-0}, /* height */ \
-   0,   /* padded_width */ \
-   IA_CSS_FRAME_FORMAT_NUM, /* format */ \
-   0,   /* raw_bit_depth */ \
-   IA_CSS_BAYER_ORDER_NUM,  /* raw_bayer_order */ \
-   {0,   /*start col */ \
-0},   /*start line */ \
-}
+#define IA_CSS_BINARY_DEFAULT_FRAME_INFO ( \
+   (struct ia_css_frame_info) { \
+   .res= (struct ia_css_resolution) { \
+   .width = 0, \
+   .height = 0 \
+   }, \
+   .padded_width   = 0, \
+   .format = IA_CSS_FRAME_FORMAT_NUM,  \
+   .raw_bit_depth  = 0, \
+   

[PATCH v2 3/3] media: atomisp: delete empty default struct values.

2017-12-01 Thread Jeremy Sowden
Removing zero-valued struct-members left a number of the default
struct-values empty.  These values have now been removed.

Signed-off-by: Jeremy Sowden 
---
 .../atomisp/pci/atomisp2/css2400/ia_css_pipe.h |  1 -
 .../atomisp/pci/atomisp2/css2400/ia_css_types.h|  1 -
 .../isp/kernels/s3a/s3a_1.0/ia_css_s3a_types.h |  6 ---
 .../kernels/sdis/common/ia_css_sdis_common_types.h | 45 --
 .../isp/kernels/sdis/sdis_1.0/ia_css_sdis.host.c   |  2 +-
 .../runtime/binary/interface/ia_css_binary.h   |  9 -
 .../isp_param/interface/ia_css_isp_param_types.h   | 15 
 .../media/atomisp/pci/atomisp2/css2400/sh_css.c|  9 ++---
 .../atomisp/pci/atomisp2/css2400/sh_css_legacy.h   |  5 ---
 .../atomisp/pci/atomisp2/css2400/sh_css_metrics.h  | 12 --
 10 files changed, 12 insertions(+), 93 deletions(-)

diff --git a/drivers/staging/media/atomisp/pci/atomisp2/css2400/ia_css_pipe.h 
b/drivers/staging/media/atomisp/pci/atomisp2/css2400/ia_css_pipe.h
index a68eac6de36a..3f3c85c2f360 100644
--- a/drivers/staging/media/atomisp/pci/atomisp2/css2400/ia_css_pipe.h
+++ b/drivers/staging/media/atomisp/pci/atomisp2/css2400/ia_css_pipe.h
@@ -167,7 +167,6 @@ struct ia_css_pipe {
 #define IA_CSS_DEFAULT_PIPE ( \
(struct ia_css_pipe) { \
.config = DEFAULT_PIPE_CONFIG, \
-   .extra_config   = DEFAULT_PIPE_EXTRA_CONFIG, \
.info   = DEFAULT_PIPE_INFO, \
.mode   = IA_CSS_PIPE_ID_ACC, /* (pipe_id) */ \
.pipeline   = DEFAULT_PIPELINE, \
diff --git a/drivers/staging/media/atomisp/pci/atomisp2/css2400/ia_css_types.h 
b/drivers/staging/media/atomisp/pci/atomisp2/css2400/ia_css_types.h
index afde2d10ad70..4a77c61a9fdb 100644
--- a/drivers/staging/media/atomisp/pci/atomisp2/css2400/ia_css_types.h
+++ b/drivers/staging/media/atomisp/pci/atomisp2/css2400/ia_css_types.h
@@ -408,7 +408,6 @@ struct ia_css_grid_info {
 /** defaults for ia_css_grid_info structs */
 #define DEFAULT_GRID_INFO ( \
(struct ia_css_grid_info) { \
-   .s3a_grid   = DEFAULT_3A_GRID_INFO, \
.dvs_grid   = DEFAULT_DVS_GRID_INFO, \
.vamem_type = IA_CSS_VAMEM_TYPE_1 \
} \
diff --git 
a/drivers/staging/media/atomisp/pci/atomisp2/css2400/isp/kernels/s3a/s3a_1.0/ia_css_s3a_types.h
 
b/drivers/staging/media/atomisp/pci/atomisp2/css2400/isp/kernels/s3a/s3a_1.0/ia_css_s3a_types.h
index e62410cdb282..4297c3addcb2 100644
--- 
a/drivers/staging/media/atomisp/pci/atomisp2/css2400/isp/kernels/s3a/s3a_1.0/ia_css_s3a_types.h
+++ 
b/drivers/staging/media/atomisp/pci/atomisp2/css2400/isp/kernels/s3a/s3a_1.0/ia_css_s3a_types.h
@@ -98,12 +98,6 @@ struct ia_css_3a_grid_info {
 };
 
 
-#define DEFAULT_3A_GRID_INFO ( \
-   (struct ia_css_3a_grid_info) { \
-   } \
-)
-
-
 /* This struct should be split into 3, for AE, AWB and AF.
  * However, that will require driver/ 3A lib modifications.
  */
diff --git 
a/drivers/staging/media/atomisp/pci/atomisp2/css2400/isp/kernels/sdis/common/ia_css_sdis_common_types.h
 
b/drivers/staging/media/atomisp/pci/atomisp2/css2400/isp/kernels/sdis/common/ia_css_sdis_common_types.h
index 4319e0191f6d..2eca83d88c14 100644
--- 
a/drivers/staging/media/atomisp/pci/atomisp2/css2400/isp/kernels/sdis/common/ia_css_sdis_common_types.h
+++ 
b/drivers/staging/media/atomisp/pci/atomisp2/css2400/isp/kernels/sdis/common/ia_css_sdis_common_types.h
@@ -41,11 +41,6 @@ struct ia_css_sdis_info {
uint32_t deci_factor_log2;
 };
 
-#define IA_CSS_DEFAULT_SDIS_INFO ( \
-   (struct ia_css_sdis_info) { \
-   } \
-)
-
 /** DVS statistics grid
  *
  *  ISP block: SDVS1 (DIS/DVS Support for DIS/DVS ver.1 (2-axes))
@@ -200,41 +195,15 @@ struct ia_css_dvs_stat_grid_info {
 
 /** DVS statistics generated by accelerator default grid info
  */
-#define DEFAULT_DVS_STAT_PUBLIC_DVS_GLOBAL_CFG ( \
-   (struct dvs_stat_public_dvs_global_cfg) { \
-   } \
-)
-
-#define DEFAULT_DVS_STAT_PUBLIC_DVS_GRD_CFG ( \
-   (struct dvs_stat_public_dvs_grd_cfg) { \
-   } \
-)
-
-#define DEFAULT_DVS_STAT_PUBLIC_DVS_LEVEL_FE_ROI_CFG(X_START) ( \
-   (struct dvs_stat_public_dvs_level_fe_roi_cfg) { \
-   .x_start = X_START, \
-   } \
-)
-
-#define DEFAULT_DVS_STAT_GRID_INFO ( \
-   (struct ia_css_dvs_stat_grid_info) { \
-   .dvs_gbl_cfg = DEFAULT_DVS_STAT_PUBLIC_DVS_GLOBAL_CFG, \
-   .grd_cfg = { \
-   DEFAULT_DVS_STAT_PUBLIC_DVS_GRD_CFG, \
-   DEFAULT_DVS_STAT_PUBLIC_DVS_GRD_CFG, \
-   DEFAULT_DVS_STAT_PUBLIC_DVS_GRD_CFG \
-   }, \
-   .fe_roi_cfg = { \
-   DEFAULT_DVS_STAT_PUBLIC_DVS_LEVEL_FE_ROI_CFG(0), \
-   DEFAULT_DVS_STAT_PUBLIC_DVS_LEVEL_FE_ROI_CFG(4), \
-   

[PATCH v2 0/3] media: atomisp: clean up of data-structure initialization in the CSS API

2017-12-01 Thread Jeremy Sowden
v2.

  Fixed a couple of bugs and addressed checkpatch errors.

v1.

  The CSS API uses a lot of nested anonymous structs defined in object
  macros to assign default values to its data-structures.  These have
  been changed to use compound-literals and designated initializers to
  make them more comprehensible and less fragile.

  The compound-literals can also be used in assignment, which made it
  possible get rid of some temporary variables whose only purpose is to
  be initialized by one of these anonymous structs and then serve as the
  rvalue in an assignment expression.

  The designated initializers also allow the removal of lots of
  struct-members initialized to zero values.

  I made the changes in three stages: firstly, I converted the default
  values to compound-literals and designated initializers and removed
  the temporary variables; secondly, I removed the zero-valued
  struct-members; finally, I removed some structs which had become
  empty.

Jeremy Sowden (3):
  media: atomisp: convert default struct values to use compound-literals
with designated initializers.
  media: atomisp: delete zero-valued struct members.
  media: atomisp: delete empty default struct values.

 .../hive_isp_css_common/input_formatter_global.h   |  16 ---
 .../pci/atomisp2/css2400/ia_css_frame_public.h |  39 +++---
 .../atomisp/pci/atomisp2/css2400/ia_css_pipe.h | 138 -
 .../pci/atomisp2/css2400/ia_css_pipe_public.h  | 118 +++---
 .../atomisp/pci/atomisp2/css2400/ia_css_types.h|  79 
 .../isp/kernels/s3a/s3a_1.0/ia_css_s3a_types.h |  50 +---
 .../kernels/sdis/common/ia_css_sdis_common_types.h |  34 ++---
 .../isp/kernels/sdis/sdis_1.0/ia_css_sdis.host.c   |   3 +-
 .../runtime/binary/interface/ia_css_binary.h   |  93 ++
 .../atomisp2/css2400/runtime/binary/src/binary.c   |   3 +-
 .../isp_param/interface/ia_css_isp_param_types.h   |  10 --
 .../runtime/pipeline/interface/ia_css_pipeline.h   |  29 ++---
 .../css2400/runtime/pipeline/src/pipeline.c|   7 +-
 .../media/atomisp/pci/atomisp2/css2400/sh_css.c|  31 ++---
 .../atomisp/pci/atomisp2/css2400/sh_css_legacy.h   |  11 --
 .../atomisp/pci/atomisp2/css2400/sh_css_metrics.h  |  21 
 16 files changed, 160 insertions(+), 522 deletions(-)


base-commit: 37cb8e1f8e10c6e9bd2a1b95cdda0620a21b0551
-- 
2.15.0



Re: [PATCH 1/3] media: atomisp: convert default struct values to use compound-literals with designated initializers.

2017-12-01 Thread Jeremy Sowden
On 2017-12-01, at 18:07:25 +0300, Dan Carpenter wrote:
> I can't apply this (to today's linux-next) but does this really work:
>
> > +(struct ia_css_3a_grid_info) { \
> > +   .ae_enable  = 0, \
> > +   .ae_grd_info= (struct ae_public_config_grid_config) { \
> > +   width = 0, \
> > +   height = 0, \
> > +   b_width = 0, \
> > +   b_height = 0, \
> > +   x_start = 0, \
> > +   y_start = 0, \
> > +   x_end = 0, \
> > +   y_end = 0 \
>
> I'm pretty sure those lines should start with a period.
>
> - width = 0, \
> + .width = 0, \

Indeed they should.  A second version is in the pipeline.

J.


signature.asc
Description: PGP signature


[PATCH v2] venus: venc: set correctly GOP size and number of B-frames

2017-12-01 Thread Stanimir Varbanov
This change fixes the calculation of B-frames and GOP size by
adopt v4l2 controls with the firmware interface expectations.

Signed-off-by: Stanimir Varbanov 
---
Drop usage of do_div to avoid compiler warnings on 32bit systems.

 drivers/media/platform/qcom/venus/venc.c   | 15 ---
 drivers/media/platform/qcom/venus/venc_ctrls.c | 59 +-
 2 files changed, 68 insertions(+), 6 deletions(-)

diff --git a/drivers/media/platform/qcom/venus/venc.c 
b/drivers/media/platform/qcom/venus/venc.c
index 36d31540c59d..e3a10a852cad 100644
--- a/drivers/media/platform/qcom/venus/venc.c
+++ b/drivers/media/platform/qcom/venus/venc.c
@@ -685,8 +685,13 @@ static int venc_set_properties(struct venus_inst *inst)
return ret;
}
 
+   /* IDR periodicity, n:
+* n = 0 - only the first I-frame is IDR frame
+* n = 1 - all I-frames will be IDR frames
+* n > 1 - every n-th I-frame will be IDR frame
+*/
ptype = HFI_PROPERTY_CONFIG_VENC_IDR_PERIOD;
-   idrp.idr_period = ctr->gop_size;
+   idrp.idr_period = 0;
ret = hfi_session_set_property(inst, ptype, );
if (ret)
return ret;
@@ -700,10 +705,6 @@ static int venc_set_properties(struct venus_inst *inst)
return ret;
}
 
-   /* intra_period = pframes + bframes + 1 */
-   if (!ctr->num_p_frames)
-   ctr->num_p_frames = 2 * 15 - 1,
-
ptype = HFI_PROPERTY_CONFIG_VENC_INTRA_PERIOD;
intra_period.pframes = ctr->num_p_frames;
intra_period.bframes = ctr->num_b_frames;
@@ -800,6 +801,10 @@ static int venc_init_session(struct venus_inst *inst)
if (ret)
goto deinit;
 
+   ret = venc_set_properties(inst);
+   if (ret)
+   goto deinit;
+
return 0;
 deinit:
hfi_session_deinit(inst);
diff --git a/drivers/media/platform/qcom/venus/venc_ctrls.c 
b/drivers/media/platform/qcom/venus/venc_ctrls.c
index ab0fe51ff0f7..8dbb32ebae89 100644
--- a/drivers/media/platform/qcom/venus/venc_ctrls.c
+++ b/drivers/media/platform/qcom/venus/venc_ctrls.c
@@ -30,10 +30,57 @@
 #define AT_SLICE_BOUNDARY  \
V4L2_MPEG_VIDEO_H264_LOOP_FILTER_MODE_DISABLED_AT_SLICE_BOUNDARY
 
+static int venc_calc_bpframes(u32 gop_size, u32 conseq_b, u32 *bf, u32 *pf)
+{
+   uint32_t half = (gop_size - 1) >> 1;
+   uint32_t b, p, ratio;
+   bool found = false;
+
+   if (!gop_size)
+   return -EINVAL;
+
+   *bf = *pf = 0;
+
+   if (!conseq_b) {
+   *pf = gop_size -  1;
+   return 0;
+   }
+
+   b = p = half;
+
+   for (; b <= gop_size - 1; b++, p--) {
+   if (b % p)
+   continue;
+
+   ratio = b / p;
+
+   if (ratio == conseq_b) {
+   found = true;
+   break;
+   }
+
+   if (ratio > conseq_b)
+   break;
+   }
+
+   if (found == false)
+   return -EINVAL;
+
+   if (b + p + 1 != gop_size)
+   return -EINVAL;
+
+   *bf = b;
+   *pf = p;
+
+   return 0;
+}
+
 static int venc_op_s_ctrl(struct v4l2_ctrl *ctrl)
 {
struct venus_inst *inst = ctrl_to_inst(ctrl);
struct venc_controls *ctr = >controls.enc;
+   u32 bframes;
+   int ret;
 
switch (ctrl->id) {
case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
@@ -102,6 +149,11 @@ static int venc_op_s_ctrl(struct v4l2_ctrl *ctrl)
case V4L2_CID_MPEG_VIDEO_CYCLIC_INTRA_REFRESH_MB:
break;
case V4L2_CID_MPEG_VIDEO_GOP_SIZE:
+   ret = venc_calc_bpframes(ctrl->val, ctr->num_b_frames, ,
+>num_p_frames);
+   if (ret)
+   return ret;
+
ctr->gop_size = ctrl->val;
break;
case V4L2_CID_MPEG_VIDEO_H264_I_PERIOD:
@@ -114,7 +166,12 @@ static int venc_op_s_ctrl(struct v4l2_ctrl *ctrl)
ctr->vp8_max_qp = ctrl->val;
break;
case V4L2_CID_MPEG_VIDEO_B_FRAMES:
-   ctr->num_b_frames = ctrl->val;
+   ret = venc_calc_bpframes(ctr->gop_size, ctrl->val, ,
+>num_p_frames);
+   if (ret)
+   return ret;
+
+   ctr->num_b_frames = bframes;
break;
default:
return -EINVAL;
-- 
2.11.0



Re: [PATCH 1/3] media: atomisp: convert default struct values to use compound-literals with designated initializers.

2017-12-01 Thread Dan Carpenter
I can't apply this (to today's linux-next) but does this really work:

> +(struct ia_css_3a_grid_info) { \
> + .ae_enable  = 0, \
> + .ae_grd_info= (struct ae_public_config_grid_config) { \
> + width = 0, \
> + height = 0, \
> + b_width = 0, \
> + b_height = 0, \
> + x_start = 0, \
> + y_start = 0, \
> + x_end = 0, \
> + y_end = 0 \

I'm pretty sure those lines should start with a period.

-   width = 0, \
+   .width = 0, \

regards,
dan



Re: [PATCH v2 4/7] media: usb: add SPDX identifiers to some code I wrote

2017-12-01 Thread Sakari Ailus
Bom dia!

On Fri, Dec 01, 2017 at 11:59:33AM -0200, Mauro Carvalho Chehab wrote:
> Em Fri, 1 Dec 2017 15:52:55 +0200
> Sakari Ailus  escreveu:
> 
> > Hi Mauro,
> > 
> > On Fri, Dec 01, 2017 at 11:47:10AM -0200, Mauro Carvalho Chehab wrote:
> > > diff --git a/drivers/media/usb/au0828/au0828-input.c 
> > > b/drivers/media/usb/au0828/au0828-input.c
> > > index af68afe085b5..832ed9f25784 100644
> > > --- a/drivers/media/usb/au0828/au0828-input.c
> > > +++ b/drivers/media/usb/au0828/au0828-input.c
> > > @@ -1,21 +1,10 @@
> > > -/*
> > > -  handle au0828 IR remotes via linux kernel input layer.
> > > -
> > > -   Copyright (C) 2014 Mauro Carvalho Chehab 
> > > -   Copyright (c) 2014 Samsung Electronics Co., Ltd.
> > > -
> > > -  Based on em28xx-input.c.
> > > -
> > > -  This program is free software; you can redistribute it and/or modify
> > > -  it under the terms of the GNU General Public License as published by
> > > -  the Free Software Foundation; either version 2 of the License, or
> > > -  (at your option) any later version.
> > > -
> > > -  This program is distributed in the hope that it will be useful,
> > > -  but WITHOUT ANY WARRANTY; without even the implied warranty of
> > > -  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> > > -  GNU General Public License for more details.
> > > - */
> > > +// SPDX-License-Identifier: GPL-2.0+
> > > +// handle au0828 IR remotes via linux kernel input layer.
> > > +//
> > > +// Copyright (c) 2014 Mauro Carvalho Chehab 
> > > +// Copyright (c) 2014 Samsung Electronics Co., Ltd.
> > > +//
> > > +// Based on em28xx-input.c.  
> > 
> > Is the intention really to use C++ comments? 
> 
> Yes.
> 
> > I see that the SPDX license identifiers elsewhere use C comments.
> 
> Linus defined this way:
> 
>   https://www.spinics.net/lists/linux-xfs/msg13289.html

Right. Although you could suspect this to be from someone just pretending
to be Linus. :-D Anyway,

Acked-by: Sakari Ailus 

-- 
Sakari Ailus
sakari.ai...@linux.intel.com


Re: [PATCH v2 6/7] media: i2c: add SPDX identifiers to the code I wrote

2017-12-01 Thread Sakari Ailus
On Fri, Dec 01, 2017 at 11:47:12AM -0200, Mauro Carvalho Chehab wrote:
> As we're now using SPDX identifiers, on the several
> media drivers I wrote, add the proper SPDX, identifying
> the license I meant.
> 
> As we're now using the short license, it doesn't make sense to
> keep the original license text.
> 
> Also, fix MODULE_LICENSE to properly identify GPL v2.
> 
> Signed-off-by: Mauro Carvalho Chehab 

Acked-by: Sakari Ailus 

-- 
Sakari Ailus
sakari.ai...@linux.intel.com


[RESEND GIT PULL for 4.16] Intel IPU3 CIO2 CSI-2 receiver driver

2017-12-01 Thread Sakari Ailus
Hi Mauro,

Here's the Intel IPU3 CIO2 CSI-2 receiver driver, with the accompanying
format definitions.

Please pull.


The following changes since commit be9b53c83792e3898755dce90f8c632d40e7c83e:

  media: dvb-frontends: complete kernel-doc markups (2017-11-30 04:19:05 -0500)

are available in the git repository at:

  ssh://linuxtv.org/git/sailus/media_tree.git ipu3

for you to fetch changes up to f178207daa68e817ab6fd702d81ed7c8637ab72c:

  intel-ipu3: cio2: add new MIPI-CSI2 driver (2017-11-30 14:19:47 +0200)


Yong Zhi (3):
  videodev2.h, v4l2-ioctl: add IPU3 raw10 color format
  doc-rst: add IPU3 raw10 bayer pixel format definitions
  intel-ipu3: cio2: add new MIPI-CSI2 driver

 Documentation/media/uapi/v4l/pixfmt-rgb.rst|1 +
 .../media/uapi/v4l/pixfmt-srggb10-ipu3.rst |  335 
 MAINTAINERS|8 +
 drivers/media/pci/Kconfig  |2 +
 drivers/media/pci/Makefile |3 +-
 drivers/media/pci/intel/Makefile   |5 +
 drivers/media/pci/intel/ipu3/Kconfig   |   19 +
 drivers/media/pci/intel/ipu3/Makefile  |1 +
 drivers/media/pci/intel/ipu3/ipu3-cio2.c   | 2052 
 drivers/media/pci/intel/ipu3/ipu3-cio2.h   |  449 +
 drivers/media/v4l2-core/v4l2-ioctl.c   |4 +
 include/uapi/linux/videodev2.h |6 +
 12 files changed, 2884 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/media/uapi/v4l/pixfmt-srggb10-ipu3.rst
 create mode 100644 drivers/media/pci/intel/Makefile
 create mode 100644 drivers/media/pci/intel/ipu3/Kconfig
 create mode 100644 drivers/media/pci/intel/ipu3/Makefile
 create mode 100644 drivers/media/pci/intel/ipu3/ipu3-cio2.c
 create mode 100644 drivers/media/pci/intel/ipu3/ipu3-cio2.h

-- 
Kind regards,

Sakari Ailus
e-mail: sakari.ai...@iki.fi


Re: [PATCH v2 4/7] media: usb: add SPDX identifiers to some code I wrote

2017-12-01 Thread Mauro Carvalho Chehab
Em Fri, 1 Dec 2017 15:52:55 +0200
Sakari Ailus  escreveu:

> Hi Mauro,
> 
> On Fri, Dec 01, 2017 at 11:47:10AM -0200, Mauro Carvalho Chehab wrote:
> > diff --git a/drivers/media/usb/au0828/au0828-input.c 
> > b/drivers/media/usb/au0828/au0828-input.c
> > index af68afe085b5..832ed9f25784 100644
> > --- a/drivers/media/usb/au0828/au0828-input.c
> > +++ b/drivers/media/usb/au0828/au0828-input.c
> > @@ -1,21 +1,10 @@
> > -/*
> > -  handle au0828 IR remotes via linux kernel input layer.
> > -
> > -   Copyright (C) 2014 Mauro Carvalho Chehab 
> > -   Copyright (c) 2014 Samsung Electronics Co., Ltd.
> > -
> > -  Based on em28xx-input.c.
> > -
> > -  This program is free software; you can redistribute it and/or modify
> > -  it under the terms of the GNU General Public License as published by
> > -  the Free Software Foundation; either version 2 of the License, or
> > -  (at your option) any later version.
> > -
> > -  This program is distributed in the hope that it will be useful,
> > -  but WITHOUT ANY WARRANTY; without even the implied warranty of
> > -  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> > -  GNU General Public License for more details.
> > - */
> > +// SPDX-License-Identifier: GPL-2.0+
> > +// handle au0828 IR remotes via linux kernel input layer.
> > +//
> > +// Copyright (c) 2014 Mauro Carvalho Chehab 
> > +// Copyright (c) 2014 Samsung Electronics Co., Ltd.
> > +//
> > +// Based on em28xx-input.c.  
> 
> Is the intention really to use C++ comments? 

Yes.

> I see that the SPDX license identifiers elsewhere use C comments.

Linus defined this way:

https://www.spinics.net/lists/linux-xfs/msg13289.html

Regards,
Mauro


Re: [PATCH v2 4/7] media: usb: add SPDX identifiers to some code I wrote

2017-12-01 Thread Sakari Ailus
Hi Mauro,

On Fri, Dec 01, 2017 at 11:47:10AM -0200, Mauro Carvalho Chehab wrote:
> diff --git a/drivers/media/usb/au0828/au0828-input.c 
> b/drivers/media/usb/au0828/au0828-input.c
> index af68afe085b5..832ed9f25784 100644
> --- a/drivers/media/usb/au0828/au0828-input.c
> +++ b/drivers/media/usb/au0828/au0828-input.c
> @@ -1,21 +1,10 @@
> -/*
> -  handle au0828 IR remotes via linux kernel input layer.
> -
> -   Copyright (C) 2014 Mauro Carvalho Chehab 
> -   Copyright (c) 2014 Samsung Electronics Co., Ltd.
> -
> -  Based on em28xx-input.c.
> -
> -  This program is free software; you can redistribute it and/or modify
> -  it under the terms of the GNU General Public License as published by
> -  the Free Software Foundation; either version 2 of the License, or
> -  (at your option) any later version.
> -
> -  This program is distributed in the hope that it will be useful,
> -  but WITHOUT ANY WARRANTY; without even the implied warranty of
> -  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> -  GNU General Public License for more details.
> - */
> +// SPDX-License-Identifier: GPL-2.0+
> +// handle au0828 IR remotes via linux kernel input layer.
> +//
> +// Copyright (c) 2014 Mauro Carvalho Chehab 
> +// Copyright (c) 2014 Samsung Electronics Co., Ltd.
> +//
> +// Based on em28xx-input.c.

Is the intention really to use C++ comments? I see that the SPDX license
identifiers elsewhere use C comments.

-- 
Kind regards,

Sakari Ailus
sakari.ai...@linux.intel.com


[GIT PULL FOR v4.16] Various fixes all over the place

2017-12-01 Thread Hans Verkuil
Various fixes.

Regards,

Hans

The following changes since commit 781b045baefdabf7e0bc9f33672ca830d3db9f27:

  media: imx274: Fix error handling, add MAINTAINERS entry (2017-11-30 04:45:12 
-0500)

are available in the git repository at:

  git://linuxtv.org/hverkuil/media_tree.git for-v4.16a

for you to fetch changes up to 1d655e66a92c0a18893d89716800ee8574fb86b2:

  media: exynos4-is: Use PTR_ERR_OR_ZERO() (2017-12-01 14:25:28 +0100)


Arnd Bergmann (5):
  pulse8-cec: print time using time64_t.
  vivid: print time in y2038-safe way
  solo6x10: use ktime_get_ts64() for time sync
  staging: imx: use ktime_t for timestamps
  vivid: use ktime_t for timestamp calculation

Dan Carpenter (1):
  cpia2: Fix a couple off by one bugs

Dean A (1):
  s2255drv: update firmware load.

Geert Uytterhoeven (1):
  media: i2c: adv748x: Restore full DT paths in kernel messages

Greg Kroah-Hartman (1):
  media: usbvision: remove unneeded DRIVER_LICENSE #define

Gustavo A. R. Silva (2):
  staging: media: imx: fix inconsistent IS_ERR and PTR_ERR
  davinci: vpif_capture: add NULL check on devm_kzalloc return value

Hans Verkuil (4):
  vimc: add test_pattern and h/vflip controls to the sensor
  cec: add the adap_monitor_pin_enable op
  cec-core.rst: document the new adap_monitor_pin_enable op
  cec: disable the hardware when unregistered

Jesse Chan (3):
  media: mtk-vcodec: add missing MODULE_LICENSE/DESCRIPTION
  soc_camera: soc_scale_crop: add missing MODULE_DESCRIPTION/AUTHOR/LICENSE
  media: tegra-cec: add missing MODULE_DESCRIPTION/AUTHOR/LICENSE

Loic Poulain (2):
  media: venus: venc: configure entropy mode
  media: venus: venc: Apply inloop deblocking filter

Martin Kepplinger (1):
  media: coda: remove definition of CODA_STD_MJPG

Stanimir Varbanov (1):
  venus: cleanup set_property controls

Steve Longerbeam (1):
  media: staging/imx: do not return error in link_notify for unknown sources

Vasyl Gomonovych (1):
  media: exynos4-is: Use PTR_ERR_OR_ZERO()

 Documentation/media/kapi/cec-core.rst   | 14 ++
 drivers/media/cec/cec-adap.c| 23 
+++
 drivers/media/cec/cec-api.c | 32 

 drivers/media/cec/cec-core.c| 15 +--
 drivers/media/cec/cec-priv.h|  2 ++
 drivers/media/i2c/adv748x/adv748x-core.c| 10 --
 drivers/media/pci/solo6x10/solo6x10-core.c  | 17 +
 drivers/media/platform/coda/coda_regs.h |  1 -
 drivers/media/platform/davinci/vpif_capture.c   |  2 ++
 drivers/media/platform/exynos4-is/fimc-lite.c   |  5 +
 drivers/media/platform/mtk-vcodec/mtk_vcodec_util.c |  3 +++
 drivers/media/platform/qcom/venus/core.h|  4 ++--
 drivers/media/platform/qcom/venus/hfi_cmds.c| 73 
++---
 drivers/media/platform/qcom/venus/hfi_helper.h  |  4 ++--
 drivers/media/platform/qcom/venus/venc.c| 33 
+
 drivers/media/platform/soc_camera/soc_scale_crop.c  |  4 
 drivers/media/platform/tegra-cec/tegra_cec.c|  5 +
 drivers/media/platform/vimc/vimc-common.h   |  5 +
 drivers/media/platform/vimc/vimc-sensor.c   | 63 
++-
 drivers/media/platform/vivid/vivid-core.c   |  2 +-
 drivers/media/platform/vivid/vivid-core.h   |  2 +-
 drivers/media/platform/vivid/vivid-radio-rx.c   | 11 +--
 drivers/media/platform/vivid/vivid-radio-tx.c   |  8 +++-
 drivers/media/platform/vivid/vivid-rds-gen.c|  2 +-
 drivers/media/platform/vivid/vivid-rds-gen.h|  1 +
 drivers/media/platform/vivid/vivid-vbi-gen.c|  2 +-
 drivers/media/usb/cpia2/cpia2_v4l.c |  4 ++--
 drivers/media/usb/pulse8-cec/pulse8-cec.c   |  4 ++--
 drivers/media/usb/s2255/s2255drv.c  | 13 ++---
 drivers/media/usb/usbvision/usbvision-video.c   |  3 +--
 drivers/staging/media/imx/imx-media-csi.c   | 10 +++---
 drivers/staging/media/imx/imx-media-dev.c   | 12 ++--
 drivers/staging/media/imx/imx-media-fim.c   | 30 
+-
 drivers/staging/media/imx/imx-media.h   |  2 +-
 include/media/cec.h | 13 +
 35 files changed, 270 insertions(+), 164 deletions(-)


[PATCH v2 7/7] media: siano: add SPDX markups

2017-12-01 Thread Mauro Carvalho Chehab
As we're now using SPDX identifiers, add the proper SPDX,
better identifying the licenses whith apply to the source code.

As we're now using the short license, it doesn't make sense to
keep the original license text.

Also, fix MODULE_LICENSE to properly identify GPL v2
at the Siano's common driver. Some codes there are licensed
on GPL v2 or latter, while others are GPL v2 only. So,
in order to reflect the common license that applies to
everything, the module itself should be GPLv2 only.

While here, use the Kernel's coding style for the comments
with copyright info.

Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/common/siano/smsdvb-debugfs.c | 21 +++-
 drivers/media/common/siano/smsir.c  | 35 ---
 drivers/media/common/siano/smsir.h  | 37 ++---
 3 files changed, 25 insertions(+), 68 deletions(-)

diff --git a/drivers/media/common/siano/smsdvb-debugfs.c 
b/drivers/media/common/siano/smsdvb-debugfs.c
index 1a8677ade391..e06aec0ed18e 100644
--- a/drivers/media/common/siano/smsdvb-debugfs.c
+++ b/drivers/media/common/siano/smsdvb-debugfs.c
@@ -1,21 +1,6 @@
-/***
- *
- * Copyright(c) 2013 Mauro Carvalho Chehab
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 2 of the License, or
- * (at your option) any later version.
-
- *  This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see .
- *
- ***/
+// SPDX-License-Identifier: GPL-2.0+
+//
+// Copyright(c) 2013 Mauro Carvalho Chehab
 
 #include "smscoreapi.h"
 
diff --git a/drivers/media/common/siano/smsir.c 
b/drivers/media/common/siano/smsir.c
index e77bb0c95e69..56db0a944421 100644
--- a/drivers/media/common/siano/smsir.c
+++ b/drivers/media/common/siano/smsir.c
@@ -1,28 +1,13 @@
-/
-
- Siano Mobile Silicon, Inc.
- MDTV receiver kernel modules.
- Copyright (C) 2006-2009, Uri Shkolnik
-
- Copyright (c) 2010 - Mauro Carvalho Chehab
-   - Ported the driver to use rc-core
-   - IR raw event decoding is now done at rc-core
-   - Code almost re-written
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program.  If not, see .
-
- /
+// SPDX-License-Identifier: GPL-2.0+
+//
+// Siano Mobile Silicon, Inc.
+// MDTV receiver kernel modules.
+// Copyright (C) 2006-2009, Uri Shkolnik
+//
+// Copyright (c) 2010 - Mauro Carvalho Chehab
+// - Ported the driver to use rc-core
+// - IR raw event decoding is now done at rc-core
+// - Code almost re-written
 
 
 #include "smscoreapi.h"
diff --git a/drivers/media/common/siano/smsir.h 
b/drivers/media/common/siano/smsir.h
index d9abd96ef48b..b2c54c256e86 100644
--- a/drivers/media/common/siano/smsir.h
+++ b/drivers/media/common/siano/smsir.h
@@ -1,28 +1,15 @@
-/
-
-Siano Mobile Silicon, Inc.
-MDTV receiver kernel modules.
-Copyright (C) 2006-2009, Uri Shkolnik
-
- Copyright (c) 2010 - Mauro Carvalho Chehab
-   - Ported the driver to use rc-core
-   - IR raw event decoding is now done at rc-core
-   - Code almost re-written
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 2 of the License, or
-(at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program.  If not, see .

[PATCH v2 2/7] media: rc: add SPDX identifiers to the code I wrote

2017-12-01 Thread Mauro Carvalho Chehab
As we're now using SPDX identifiers, on the several
media drivers I wrote, add the proper SPDX, identifying
the license I meant.

As we're now using the short license, it doesn't make sense to
keep the original license text.

Also, fix MODULE_LICENSE to properly identify GPL v2.

Signed-off-by: Mauro Carvalho Chehab 
Reviewed-by: Philippe Ombredanne 
---
 drivers/media/rc/ir-nec-decoder.c   | 19 +--
 drivers/media/rc/ir-rc5-decoder.c   | 21 ++---
 drivers/media/rc/ir-sanyo-decoder.c | 37 ++---
 drivers/media/rc/rc-core-priv.h | 18 --
 drivers/media/rc/rc-ir-raw.c| 17 -
 drivers/media/rc/rc-main.c  | 19 +--
 6 files changed, 38 insertions(+), 93 deletions(-)

diff --git a/drivers/media/rc/ir-nec-decoder.c 
b/drivers/media/rc/ir-nec-decoder.c
index 6880c190dcd2..22eed9505244 100644
--- a/drivers/media/rc/ir-nec-decoder.c
+++ b/drivers/media/rc/ir-nec-decoder.c
@@ -1,16 +1,7 @@
-/* ir-nec-decoder.c - handle NEC IR Pulse/Space protocol
- *
- * Copyright (C) 2010 by Mauro Carvalho Chehab
- *
- * This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation version 2 of the License.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- */
+// SPDX-License-Identifier: GPL-2.0
+// ir-nec-decoder.c - handle NEC IR Pulse/Space protocol
+//
+// Copyright (C) 2010 by Mauro Carvalho Chehab
 
 #include 
 #include 
@@ -281,7 +272,7 @@ static void __exit ir_nec_decode_exit(void)
 module_init(ir_nec_decode_init);
 module_exit(ir_nec_decode_exit);
 
-MODULE_LICENSE("GPL");
+MODULE_LICENSE("GPL v2");
 MODULE_AUTHOR("Mauro Carvalho Chehab");
 MODULE_AUTHOR("Red Hat Inc. (http://www.redhat.com)");
 MODULE_DESCRIPTION("NEC IR protocol decoder");
diff --git a/drivers/media/rc/ir-rc5-decoder.c 
b/drivers/media/rc/ir-rc5-decoder.c
index 1292f534de43..cbff3e26d481 100644
--- a/drivers/media/rc/ir-rc5-decoder.c
+++ b/drivers/media/rc/ir-rc5-decoder.c
@@ -1,17 +1,8 @@
-/* ir-rc5-decoder.c - decoder for RC5(x) and StreamZap protocols
- *
- * Copyright (C) 2010 by Mauro Carvalho Chehab
- * Copyright (C) 2010 by Jarod Wilson 
- *
- * This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation version 2 of the License.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- */
+// SPDX-License-Identifier: GPL-2.0
+// ir-rc5-decoder.c - decoder for RC5(x) and StreamZap protocols
+//
+// Copyright (C) 2010 by Mauro Carvalho Chehab
+// Copyright (C) 2010 by Jarod Wilson 
 
 /*
  * This decoder handles the 14 bit RC5 protocol, 15 bit "StreamZap" protocol
@@ -300,7 +291,7 @@ static void __exit ir_rc5_decode_exit(void)
 module_init(ir_rc5_decode_init);
 module_exit(ir_rc5_decode_exit);
 
-MODULE_LICENSE("GPL");
+MODULE_LICENSE("GPL v2");
 MODULE_AUTHOR("Mauro Carvalho Chehab and Jarod Wilson");
 MODULE_AUTHOR("Red Hat Inc. (http://www.redhat.com)");
 MODULE_DESCRIPTION("RC5(x/sz) IR protocol decoder");
diff --git a/drivers/media/rc/ir-sanyo-decoder.c 
b/drivers/media/rc/ir-sanyo-decoder.c
index d94e07b02f3b..2138f0e9472d 100644
--- a/drivers/media/rc/ir-sanyo-decoder.c
+++ b/drivers/media/rc/ir-sanyo-decoder.c
@@ -1,25 +1,16 @@
-/* ir-sanyo-decoder.c - handle SANYO IR Pulse/Space protocol
- *
- * Copyright (C) 2011 by Mauro Carvalho Chehab
- *
- * This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation version 2 of the License.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- * This protocol uses the NEC protocol timings. However, data is formatted as:
- * 13 bits Custom Code
- * 13 bits NOT(Custom Code)
- * 8 bits Key data
- * 8 bits NOT(Key data)
- *
- * According with LIRC, this protocol is used on Sanyo, Aiwa and Chinon
- * Information for this protocol is available at the Sanyo LC7461 datasheet.
- */
+// SPDX-License-Identifier: GPL-2.0
+// ir-sanyo-decoder.c - handle SANYO IR Pulse/Space protocol
+//
+// Copyright (C) 2011 by Mauro Carvalho Chehab

[PATCH v2 5/7] media: rc keymaps: add SPDX identifiers to the code I wrote

2017-12-01 Thread Mauro Carvalho Chehab
As we're now using SPDX identifiers, on the several
RC keymap files I wrote, add the proper SPDX, identifying
the license I meant.

As we're now using the short license, it doesn't make sense to
keep the original license text.

Also, fix MODULE_LICENSE to identify GPL v2, as this is the
minimal license requirement for those modles.

Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/rc/keymaps/rc-adstech-dvb-t-pci.c| 17 +
 drivers/media/rc/keymaps/rc-apac-viewcomp.c| 17 +
 drivers/media/rc/keymaps/rc-asus-pc39.c| 17 +
 drivers/media/rc/keymaps/rc-asus-ps3-100.c | 17 +
 drivers/media/rc/keymaps/rc-ati-tv-wonder-hd-600.c | 17 +
 drivers/media/rc/keymaps/rc-avermedia-a16d.c   | 17 +
 drivers/media/rc/keymaps/rc-avermedia-cardbus.c| 17 +
 drivers/media/rc/keymaps/rc-avermedia-dvbt.c   | 17 +
 drivers/media/rc/keymaps/rc-avermedia-m135a.c  | 15 ---
 drivers/media/rc/keymaps/rc-avermedia.c| 17 +
 drivers/media/rc/keymaps/rc-avertv-303.c   | 17 +
 drivers/media/rc/keymaps/rc-behold-columbus.c  | 17 +
 drivers/media/rc/keymaps/rc-behold.c   | 17 +
 drivers/media/rc/keymaps/rc-budget-ci-old.c| 17 +
 drivers/media/rc/keymaps/rc-cinergy-1400.c | 17 +
 drivers/media/rc/keymaps/rc-cinergy.c  | 17 +
 drivers/media/rc/keymaps/rc-dib0700-nec.c  | 27 
 drivers/media/rc/keymaps/rc-dib0700-rc5.c  | 27 
 drivers/media/rc/keymaps/rc-dm1105-nec.c   | 17 +
 drivers/media/rc/keymaps/rc-dntv-live-dvb-t.c  | 17 +
 drivers/media/rc/keymaps/rc-dntv-live-dvbt-pro.c   | 17 +
 drivers/media/rc/keymaps/rc-em-terratec.c  | 17 +
 drivers/media/rc/keymaps/rc-encore-enltv-fm53.c| 17 +
 drivers/media/rc/keymaps/rc-encore-enltv.c | 17 +
 drivers/media/rc/keymaps/rc-encore-enltv2.c| 17 +
 drivers/media/rc/keymaps/rc-evga-indtube.c | 17 +
 drivers/media/rc/keymaps/rc-eztv.c | 17 +
 drivers/media/rc/keymaps/rc-flydvb.c   | 17 +
 drivers/media/rc/keymaps/rc-flyvideo.c | 17 +
 drivers/media/rc/keymaps/rc-fusionhdtv-mce.c   | 17 +
 drivers/media/rc/keymaps/rc-gadmei-rm008z.c| 17 +
 drivers/media/rc/keymaps/rc-genius-tvgo-a11mce.c   | 17 +
 drivers/media/rc/keymaps/rc-gotview7135.c  | 17 +
 drivers/media/rc/keymaps/rc-hauppauge.c| 29 +-
 drivers/media/rc/keymaps/rc-iodata-bctv7e.c| 17 +
 drivers/media/rc/keymaps/rc-kaiomy.c   | 17 +
 drivers/media/rc/keymaps/rc-kworld-315u.c  | 17 +
 .../media/rc/keymaps/rc-kworld-plus-tv-analog.c| 17 +
 drivers/media/rc/keymaps/rc-manli.c| 17 +
 drivers/media/rc/keymaps/rc-msi-tvanywhere-plus.c  | 17 +
 drivers/media/rc/keymaps/rc-msi-tvanywhere.c   | 17 +
 drivers/media/rc/keymaps/rc-nebula.c   | 17 +
 .../media/rc/keymaps/rc-nec-terratec-cinergy-xs.c  | 17 +
 drivers/media/rc/keymaps/rc-norwood.c  | 17 +
 drivers/media/rc/keymaps/rc-npgtech.c  | 17 +
 drivers/media/rc/keymaps/rc-pctv-sedna.c   | 17 +
 drivers/media/rc/keymaps/rc-pinnacle-color.c   | 17 +
 drivers/media/rc/keymaps/rc-pinnacle-grey.c| 17 +
 drivers/media/rc/keymaps/rc-pinnacle-pctv-hd.c | 17 +
 drivers/media/rc/keymaps/rc-pixelview-002t.c   | 17 +
 drivers/media/rc/keymaps/rc-pixelview-mk12.c   | 17 +
 drivers/media/rc/keymaps/rc-pixelview-new.c| 17 +
 drivers/media/rc/keymaps/rc-pixelview.c| 17 +
 .../media/rc/keymaps/rc-powercolor-real-angel.c| 17 +
 drivers/media/rc/keymaps/rc-proteus-2309.c | 17 +
 drivers/media/rc/keymaps/rc-purpletv.c | 17 +
 drivers/media/rc/keymaps/rc-pv951.c| 17 +
 .../media/rc/keymaps/rc-real-audio-220-32-keys.c   | 17 +
 drivers/media/rc/keymaps/rc-tbs-nec.c  | 17 +
 drivers/media/rc/keymaps/rc-terratec-cinergy-xs.c  | 17 +
 drivers/media/rc/keymaps/rc-tevii-nec.c| 17 +
 drivers/media/rc/keymaps/rc-tt-1500.c  | 17 +
 drivers/media/rc/keymaps/rc-videomate-s350.c   | 17 +
 drivers/media/rc/keymaps/rc-videomate-tv-pvr.c | 17 +
 

[PATCH v2 3/7] media: tuners: add SPDX identifiers to the code I wrote

2017-12-01 Thread Mauro Carvalho Chehab
As we're now using SPDX identifiers, on the several
media drivers I wrote, add the proper SPDX, identifying
the license I meant.

As we're now using the short license, it doesn't make sense to
keep the original license text.

Also, fix MODULE_LICENSE to properly identify GPL v2.

Signed-off-by: Mauro Carvalho Chehab 
Reviewed-by: Philippe Ombredanne 
---
 drivers/media/tuners/r820t.c  | 56 ---
 drivers/media/tuners/tea5761.c| 15 -
 drivers/media/tuners/tea5767.c| 21 +---
 drivers/media/tuners/tuner-xc2028-types.h |  5 +--
 drivers/media/tuners/tuner-xc2028.c   | 18 +-
 drivers/media/tuners/tuner-xc2028.h   |  5 +--
 6 files changed, 51 insertions(+), 69 deletions(-)

diff --git a/drivers/media/tuners/r820t.c b/drivers/media/tuners/r820t.c
index ba80376a3b86..69a507f355b5 100644
--- a/drivers/media/tuners/r820t.c
+++ b/drivers/media/tuners/r820t.c
@@ -1,36 +1,24 @@
-/*
- * Rafael Micro R820T driver
- *
- * Copyright (C) 2013 Mauro Carvalho Chehab
- *
- * This driver was written from scratch, based on an existing driver
- * that it is part of rtl-sdr git tree, released under GPLv2:
- * https://groups.google.com/forum/#!topic/ultra-cheap-sdr/Y3rBEOFtHug
- * https://github.com/n1gp/gr-baz
- *
- * From what I understood from the threads, the original driver was converted
- * to userspace from a Realtek tree. I couldn't find the original tree.
- * However, the original driver look awkward on my eyes. So, I decided to
- * write a new version from it from the scratch, while trying to reproduce
- * everything found there.
- *
- * TODO:
- * After locking, the original driver seems to have some routines to
- * improve reception. This was not implemented here yet.
- *
- * RF Gain set/get is not implemented.
- *
- *This program is free software; you can redistribute it and/or modify
- *it under the terms of the GNU General Public License as published by
- *the Free Software Foundation; either version 2 of the License, or
- *(at your option) any later version.
- *
- *This program is distributed in the hope that it will be useful,
- *but WITHOUT ANY WARRANTY; without even the implied warranty of
- *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *GNU General Public License for more details.
- *
- */
+// SPDX-License-Identifier: GPL-2.0
+// Rafael Micro R820T driver
+//
+// Copyright (C) 2013 Mauro Carvalho Chehab
+//
+// This driver was written from scratch, based on an existing driver
+// that it is part of rtl-sdr git tree, released under GPLv2:
+// https://groups.google.com/forum/#!topic/ultra-cheap-sdr/Y3rBEOFtHug
+// https://github.com/n1gp/gr-baz
+//
+// From what I understood from the threads, the original driver was converted
+// to userspace from a Realtek tree. I couldn't find the original tree.
+// However, the original driver look awkward on my eyes. So, I decided to
+// write a new version from it from the scratch, while trying to reproduce
+// everything found there.
+//
+// TODO:
+// After locking, the original driver seems to have some routines to
+// improve reception. This was not implemented here yet.
+//
+// RF Gain set/get is not implemented.
 
 #include 
 #include 
@@ -2388,4 +2376,4 @@ EXPORT_SYMBOL_GPL(r820t_attach);
 
 MODULE_DESCRIPTION("Rafael Micro r820t silicon tuner driver");
 MODULE_AUTHOR("Mauro Carvalho Chehab");
-MODULE_LICENSE("GPL");
+MODULE_LICENSE("GPL v2");
diff --git a/drivers/media/tuners/tea5761.c b/drivers/media/tuners/tea5761.c
index a9b1bb134409..88b3e80c38ad 100644
--- a/drivers/media/tuners/tea5761.c
+++ b/drivers/media/tuners/tea5761.c
@@ -1,11 +1,8 @@
-/*
- * For Philips TEA5761 FM Chip
- * I2C address is allways 0x20 (0x10 at 7-bit mode).
- *
- * Copyright (c) 2005-2007 Mauro Carvalho Chehab (mche...@infradead.org)
- * This code is placed under the terms of the GNUv2 General Public License
- *
- */
+// SPDX-License-Identifier: GPL-2.0
+// For Philips TEA5761 FM Chip
+// I2C address is always 0x20 (0x10 at 7-bit mode).
+//
+// Copyright (c) 2005-2007 Mauro Carvalho Chehab (mche...@infradead.org)
 
 #include 
 #include 
@@ -341,4 +338,4 @@ EXPORT_SYMBOL_GPL(tea5761_autodetection);
 
 MODULE_DESCRIPTION("Philips TEA5761 FM tuner driver");
 MODULE_AUTHOR("Mauro Carvalho Chehab ");
-MODULE_LICENSE("GPL");
+MODULE_LICENSE("GPL v2");
diff --git a/drivers/media/tuners/tea5767.c b/drivers/media/tuners/tea5767.c
index 525b7ab90c80..2b2c064d7dc3 100644
--- a/drivers/media/tuners/tea5767.c
+++ b/drivers/media/tuners/tea5767.c
@@ -1,14 +1,11 @@
-/*
- * For Philips TEA5767 FM Chip used on some TV Cards like Prolink Pixelview
- * I2C address is allways 0xC0.
- *
- *
- * Copyright (c) 2005 Mauro Carvalho Chehab (mche...@infradead.org)
- * This code is placed under the terms of the GNU General Public License
- *
- * 

[PATCH v2 4/7] media: usb: add SPDX identifiers to some code I wrote

2017-12-01 Thread Mauro Carvalho Chehab
As we're now using SPDX identifiers, on several
media drivers I wrote, add the proper SPDX, identifying
the license I meant.

As we're now using the short license, it doesn't make sense to
keep the original license text.

Also, fix MODULE_LICENSE to properly identify GPL v2.

Signed-off-by: Mauro Carvalho Chehab 
Reviewed-by: Philippe Ombredanne 
---
 drivers/media/usb/au0828/au0828-input.c| 25 +++--
 drivers/media/usb/cx231xx/cx231xx-input.c  | 28 +---
 drivers/media/usb/tm6000/tm6000-alsa.c | 18 ++
 drivers/media/usb/tm6000/tm6000-cards.c| 20 +---
 drivers/media/usb/tm6000/tm6000-core.c | 24 +++-
 drivers/media/usb/tm6000/tm6000-i2c.c  | 24 +++-
 drivers/media/usb/tm6000/tm6000-regs.h | 18 --
 drivers/media/usb/tm6000/tm6000-stds.c | 18 --
 drivers/media/usb/tm6000/tm6000-usb-isoc.h | 18 --
 drivers/media/usb/tm6000/tm6000-video.c| 24 +++-
 drivers/media/usb/tm6000/tm6000.h  | 24 +++-
 11 files changed, 67 insertions(+), 174 deletions(-)

diff --git a/drivers/media/usb/au0828/au0828-input.c 
b/drivers/media/usb/au0828/au0828-input.c
index af68afe085b5..832ed9f25784 100644
--- a/drivers/media/usb/au0828/au0828-input.c
+++ b/drivers/media/usb/au0828/au0828-input.c
@@ -1,21 +1,10 @@
-/*
-  handle au0828 IR remotes via linux kernel input layer.
-
-   Copyright (C) 2014 Mauro Carvalho Chehab 
-   Copyright (c) 2014 Samsung Electronics Co., Ltd.
-
-  Based on em28xx-input.c.
-
-  This program is free software; you can redistribute it and/or modify
-  it under the terms of the GNU General Public License as published by
-  the Free Software Foundation; either version 2 of the License, or
-  (at your option) any later version.
-
-  This program is distributed in the hope that it will be useful,
-  but WITHOUT ANY WARRANTY; without even the implied warranty of
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-  GNU General Public License for more details.
- */
+// SPDX-License-Identifier: GPL-2.0+
+// handle au0828 IR remotes via linux kernel input layer.
+//
+// Copyright (c) 2014 Mauro Carvalho Chehab 
+// Copyright (c) 2014 Samsung Electronics Co., Ltd.
+//
+// Based on em28xx-input.c.
 
 #include "au0828.h"
 
diff --git a/drivers/media/usb/cx231xx/cx231xx-input.c 
b/drivers/media/usb/cx231xx/cx231xx-input.c
index 02ebeb16055f..3e9b73a6b7c9 100644
--- a/drivers/media/usb/cx231xx/cx231xx-input.c
+++ b/drivers/media/usb/cx231xx/cx231xx-input.c
@@ -1,22 +1,12 @@
-/*
- *   cx231xx IR glue driver
- *
- *   Copyright (C) 2010 Mauro Carvalho Chehab
- *
- *   Polaris (cx231xx) has its support for IR's with a design close to MCE.
- *   however, a few designs are using an external I2C chip for IR, instead
- *   of using the one provided by the chip.
- *   This driver provides support for those extra devices
- *
- *   This program is free software; you can redistribute it and/or
- *   modify it under the terms of the GNU General Public License as
- *   published by the Free Software Foundation version 2.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- *   General Public License for more details.
- */
+// SPDX-License-Identifier: GPL-2.0
+// cx231xx IR glue driver
+//
+// Copyright (c) 2010 Mauro Carvalho Chehab 
+//
+// Polaris (cx231xx) has its support for IR's with a design close to MCE.
+// however, a few designs are using an external I2C chip for IR, instead
+// of using the one provided by the chip.
+// This driver provides support for those extra devices
 
 #include "cx231xx.h"
 #include 
diff --git a/drivers/media/usb/tm6000/tm6000-alsa.c 
b/drivers/media/usb/tm6000/tm6000-alsa.c
index 3717a6844ea8..f18cffae4c85 100644
--- a/drivers/media/usb/tm6000/tm6000-alsa.c
+++ b/drivers/media/usb/tm6000/tm6000-alsa.c
@@ -1,14 +1,8 @@
-/*
- *
- *  Support for audio capture for tm5600/6000/6010
- *(c) 2007-2008 Mauro Carvalho Chehab
- *
- *  Based on cx88-alsa.c
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License version 2 as
- *  published by the Free Software Foundation.
- */
+// SPDX-License-Identifier: GPL-2.0
+// Support for audio capture for tm5600/6000/6010
+// Copyright (c) 2007-2008 Mauro Carvalho Chehab 
+//
+// Based on cx88-alsa.c
 
 #include 
 #include 
@@ -57,7 +51,7 @@ MODULE_PARM_DESC(index, "Index value for tm6000x capture 
interface(s).");
 
 MODULE_DESCRIPTION("ALSA driver module for tm5600/tm6000/tm6010 based TV 
cards");
 MODULE_AUTHOR("Mauro Carvalho Chehab");

[PATCH v2 6/7] media: i2c: add SPDX identifiers to the code I wrote

2017-12-01 Thread Mauro Carvalho Chehab
As we're now using SPDX identifiers, on the several
media drivers I wrote, add the proper SPDX, identifying
the license I meant.

As we're now using the short license, it doesn't make sense to
keep the original license text.

Also, fix MODULE_LICENSE to properly identify GPL v2.

Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/i2c/mt9v011.c  | 13 +
 drivers/media/i2c/saa7115.c  | 58 +---
 drivers/media/i2c/saa711x_regs.h | 14 +++---
 drivers/media/i2c/tvp5150.c  | 13 +
 drivers/media/i2c/tvp5150_reg.h  |  5 ++--
 5 files changed, 42 insertions(+), 61 deletions(-)

diff --git a/drivers/media/i2c/mt9v011.c b/drivers/media/i2c/mt9v011.c
index 9ed1b26b6549..5e29064fae91 100644
--- a/drivers/media/i2c/mt9v011.c
+++ b/drivers/media/i2c/mt9v011.c
@@ -1,9 +1,8 @@
-/*
- * mt9v011 -Micron 1/4-Inch VGA Digital Image Sensor
- *
- * Copyright (c) 2009 Mauro Carvalho Chehab
- * This code is placed under the terms of the GNU General Public License v2
- */
+// SPDX-License-Identifier: GPL-2.0
+//
+// mt9v011 -Micron 1/4-Inch VGA Digital Image Sensor
+//
+// Copyright (c) 2009 Mauro Carvalho Chehab 
 
 #include 
 #include 
@@ -17,7 +16,7 @@
 
 MODULE_DESCRIPTION("Micron mt9v011 sensor driver");
 MODULE_AUTHOR("Mauro Carvalho Chehab");
-MODULE_LICENSE("GPL");
+MODULE_LICENSE("GPL v2");
 
 static int debug;
 module_param(debug, int, 0);
diff --git a/drivers/media/i2c/saa7115.c b/drivers/media/i2c/saa7115.c
index d863b04aa2a8..7dd6cff6d811 100644
--- a/drivers/media/i2c/saa7115.c
+++ b/drivers/media/i2c/saa7115.c
@@ -1,37 +1,27 @@
-/* saa711x - Philips SAA711x video decoder driver
- * This driver can work with saa7111, saa7111a, saa7113, saa7114,
- *  saa7115 and saa7118.
- *
- * Based on saa7114 driver by Maxim Yevtyushkin, which is based on
- * the saa7111 driver by Dave Perks.
- *
- * Copyright (C) 1998 Dave Perks 
- * Copyright (C) 2002 Maxim Yevtyushkin 
- *
- * Slight changes for video timing and attachment output by
- * Wolfgang Scherr 
- *
- * Moved over to the linux >= 2.4.x i2c protocol (1/1/2003)
- * by Ronald Bultje 
- *
- * Added saa7115 support by Kevin Thayer 
- * (2/17/2003)
- *
- * VBI support (2004) and cleanups (2005) by Hans Verkuil 
- *
- * Copyright (c) 2005-2006 Mauro Carvalho Chehab 
- * SAA7111, SAA7113 and SAA7118 support
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- */
+// SPDX-License-Identifier: GPL-2.0+
+// saa711x - Philips SAA711x video decoder driver
+// This driver can work with saa7111, saa7111a, saa7113, saa7114,
+//  saa7115 and saa7118.
+//
+// Based on saa7114 driver by Maxim Yevtyushkin, which is based on
+// the saa7111 driver by Dave Perks.
+//
+// Copyright (C) 1998 Dave Perks 
+// Copyright (C) 2002 Maxim Yevtyushkin 
+//
+// Slight changes for video timing and attachment output by
+// Wolfgang Scherr 
+//
+// Moved over to the linux >= 2.4.x i2c protocol (1/1/2003)
+// by Ronald Bultje 
+//
+// Added saa7115 support by Kevin Thayer 
+// (2/17/2003)
+//
+// VBI support (2004) and cleanups (2005) by Hans Verkuil 
+//
+// Copyright (c) 2005-2006 Mauro Carvalho Chehab 
+// SAA7111, SAA7113 and SAA7118 support
 
 #include "saa711x_regs.h"
 
diff --git a/drivers/media/i2c/saa711x_regs.h b/drivers/media/i2c/saa711x_regs.h
index 730ca90b30ac..a50d480e101a 100644
--- a/drivers/media/i2c/saa711x_regs.h
+++ b/drivers/media/i2c/saa711x_regs.h
@@ -1,16 +1,8 @@
-/* saa711x - Philips SAA711x video decoder register specifications
+/*
+ * SPDX-License-Identifier: GPL-2.0+
+ * saa711x - Philips SAA711x video decoder register specifications
  *
  * Copyright (c) 2006 Mauro Carvalho Chehab 
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for 

[PATCH v2 1/7] edac: adjust GPLv2 license and SPDX identifiers at the code I wrote

2017-12-01 Thread Mauro Carvalho Chehab
As we're now using SPDX identifiers, on the several EDAC drivers
I wrote, add the proper SPDX, identifying the license I meant.

As we're now using the short license, it doesn't make sense to
keep the original license text.

Also, fix MODULE_LICENSE to properly identify GPL v2.

Signed-off-by: Mauro Carvalho Chehab 
Reviewed-by: Philippe Ombredanne 
---
 drivers/edac/ghes_edac.c   | 16 ++-
 drivers/edac/i5400_edac.c  | 50 ++---
 drivers/edac/i7300_edac.c  | 36 +++-
 drivers/edac/i7core_edac.c | 51 ++
 drivers/edac/sb_edac.c | 21 ---
 5 files changed, 79 insertions(+), 95 deletions(-)

diff --git a/drivers/edac/ghes_edac.c b/drivers/edac/ghes_edac.c
index 68b6ee18bea6..7b722f3f4cdd 100644
--- a/drivers/edac/ghes_edac.c
+++ b/drivers/edac/ghes_edac.c
@@ -1,13 +1,9 @@
-/*
- * GHES/EDAC Linux driver
- *
- * This file may be distributed under the terms of the GNU General Public
- * License version 2.
- *
- * Copyright (c) 2013 by Mauro Carvalho Chehab
- *
- * Red Hat Inc. http://www.redhat.com
- */
+// SPDX-License-Identifier: GPL-2.0
+// GHES/EDAC Linux driver
+//
+// Copyright (c) 2013 by Mauro Carvalho Chehab
+//
+// Red Hat Inc. http://www.redhat.com
 
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
diff --git a/drivers/edac/i5400_edac.c b/drivers/edac/i5400_edac.c
index 6f8bcdb9256a..9ab6965874ae 100644
--- a/drivers/edac/i5400_edac.c
+++ b/drivers/edac/i5400_edac.c
@@ -1,28 +1,26 @@
-/*
- * Intel 5400 class Memory Controllers kernel module (Seaburg)
- *
- * This file may be distributed under the terms of the
- * GNU General Public License.
- *
- * Copyright (c) 2008 by:
- *  Ben Woodard 
- *  Mauro Carvalho Chehab
- *
- * Red Hat Inc. http://www.redhat.com
- *
- * Forked and adapted from the i5000_edac driver which was
- * written by Douglas Thompson Linux Networx 
- *
- * This module is based on the following document:
- *
- * Intel 5400 Chipset Memory Controller Hub (MCH) - Datasheet
- * http://developer.intel.com/design/chipsets/datashts/313070.htm
- *
- * This Memory Controller manages DDR2 FB-DIMMs. It has 2 branches, each with
- * 2 channels operating in lockstep no-mirror mode. Each channel can have up to
- * 4 dimm's, each with up to 8GB.
- *
- */
+// SPDX-License-Identifier: GPL-2.0
+// Intel 5400 class Memory Controllers kernel module (Seaburg)
+//
+// This file may be distributed under the terms of the
+// GNU General Public License.
+//
+// Copyright (c) 2008 by:
+//  Ben Woodard 
+//  Mauro Carvalho Chehab
+//
+// Red Hat Inc. http://www.redhat.com
+//
+// Forked and adapted from the i5000_edac driver which was
+// written by Douglas Thompson Linux Networx 
+//
+// This module is based on the following document:
+//
+// Intel 5400 Chipset Memory Controller Hub (MCH) - Datasheet
+// http://developer.intel.com/design/chipsets/datashts/313070.htm
+//
+// This Memory Controller manages DDR2 FB-DIMMs. It has 2 branches, each with
+// 2 channels operating in lockstep no-mirror mode. Each channel can have up to
+// 4 dimm's, each with up to 8GB.
 
 #include 
 #include 
@@ -1467,7 +1465,7 @@ static void __exit i5400_exit(void)
 module_init(i5400_init);
 module_exit(i5400_exit);
 
-MODULE_LICENSE("GPL");
+MODULE_LICENSE("GPL v2");
 MODULE_AUTHOR("Ben Woodard ");
 MODULE_AUTHOR("Mauro Carvalho Chehab");
 MODULE_AUTHOR("Red Hat Inc. (http://www.redhat.com)");
diff --git a/drivers/edac/i7300_edac.c b/drivers/edac/i7300_edac.c
index 6b5a554ba8e4..36d1ef559ab6 100644
--- a/drivers/edac/i7300_edac.c
+++ b/drivers/edac/i7300_edac.c
@@ -1,22 +1,18 @@
-/*
- * Intel 7300 class Memory Controllers kernel module (Clarksboro)
- *
- * This file may be distributed under the terms of the
- * GNU General Public License version 2 only.
- *
- * Copyright (c) 2010 by:
- *  Mauro Carvalho Chehab
- *
- * Red Hat Inc. http://www.redhat.com
- *
- * Intel 7300 Chipset Memory Controller Hub (MCH) - Datasheet
- * http://www.intel.com/Assets/PDF/datasheet/318082.pdf
- *
- * TODO: The chipset allow checking for PCI Express errors also. Currently,
- *  the driver covers only memory error errors
- *
- * This driver uses "csrows" EDAC attribute to represent DIMM slot#
- */
+// SPDX-License-Identifier: GPL-2.0
+// Intel 7300 class Memory Controllers kernel module (Clarksboro)
+//
+// Copyright (c) 2010 by:
+//  Mauro Carvalho Chehab
+//
+// Red Hat Inc. http://www.redhat.com
+//
+// Intel 7300 Chipset Memory Controller Hub (MCH) - Datasheet
+// http://www.intel.com/Assets/PDF/datasheet/318082.pdf
+//
+// TODO: The chipset allow checking for PCI Express errors also. Currently,
+//  the driver covers only memory error errors
+//
+// This driver uses "csrows" EDAC attribute to represent DIMM slot#
 
 

Re: [PATCH 2/2] venus: venc: set correctly GOP size and number of B-frames

2017-12-01 Thread Hans Verkuil
On 11/29/17 14:25, Stanimir Varbanov wrote:
> This change fixes the calculation of B-frames and GOP size by
> adopt v4l2 controls with the firmware interface expectations.
> 
> Signed-off-by: Stanimir Varbanov 
> ---
>  drivers/media/platform/qcom/venus/venc.c   | 15 ---
>  drivers/media/platform/qcom/venus/venc_ctrls.c | 60 
> +-
>  2 files changed, 69 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/media/platform/qcom/venus/venc.c 
> b/drivers/media/platform/qcom/venus/venc.c
> index 36d31540c59d..e3a10a852cad 100644
> --- a/drivers/media/platform/qcom/venus/venc.c
> +++ b/drivers/media/platform/qcom/venus/venc.c
> @@ -685,8 +685,13 @@ static int venc_set_properties(struct venus_inst *inst)
>   return ret;
>   }
>  
> + /* IDR periodicity, n:
> +  * n = 0 - only the first I-frame is IDR frame
> +  * n = 1 - all I-frames will be IDR frames
> +  * n > 1 - every n-th I-frame will be IDR frame
> +  */
>   ptype = HFI_PROPERTY_CONFIG_VENC_IDR_PERIOD;
> - idrp.idr_period = ctr->gop_size;
> + idrp.idr_period = 0;
>   ret = hfi_session_set_property(inst, ptype, );
>   if (ret)
>   return ret;
> @@ -700,10 +705,6 @@ static int venc_set_properties(struct venus_inst *inst)
>   return ret;
>   }
>  
> - /* intra_period = pframes + bframes + 1 */
> - if (!ctr->num_p_frames)
> - ctr->num_p_frames = 2 * 15 - 1,
> -
>   ptype = HFI_PROPERTY_CONFIG_VENC_INTRA_PERIOD;
>   intra_period.pframes = ctr->num_p_frames;
>   intra_period.bframes = ctr->num_b_frames;
> @@ -800,6 +801,10 @@ static int venc_init_session(struct venus_inst *inst)
>   if (ret)
>   goto deinit;
>  
> + ret = venc_set_properties(inst);
> + if (ret)
> + goto deinit;
> +
>   return 0;
>  deinit:
>   hfi_session_deinit(inst);
> diff --git a/drivers/media/platform/qcom/venus/venc_ctrls.c 
> b/drivers/media/platform/qcom/venus/venc_ctrls.c
> index ab0fe51ff0f7..53130d4774d3 100644
> --- a/drivers/media/platform/qcom/venus/venc_ctrls.c
> +++ b/drivers/media/platform/qcom/venus/venc_ctrls.c
> @@ -30,10 +30,58 @@
>  #define AT_SLICE_BOUNDARY\
>   V4L2_MPEG_VIDEO_H264_LOOP_FILTER_MODE_DISABLED_AT_SLICE_BOUNDARY
>  
> +static int venc_calc_bpframes(u32 gop_size, u32 conseq_b, u32 *bf, u32 *pf)
> +{
> + uint32_t half = (gop_size - 1) >> 1;
> + uint32_t b, p, ratio;
> + bool found = false;
> +
> + if (!gop_size)
> + return -EINVAL;
> +
> + *bf = *pf = 0;
> +
> + if (!conseq_b) {
> + *pf = gop_size -  1;
> + return 0;
> + }
> +
> + b = p = half;
> +
> + for (; b <= gop_size - 1; b++, p--) {
> + if (b % p)
> + continue;
> +
> + ratio = b;
> + do_div(ratio, p);

Huh? Why use do_div when both arguments are uint32_t?

This gives a pile of compile warnings:

In file included from 
/home/hans/work/build/media-git/arch/arm/include/asm/div64.h:127:0,
 from 
/home/hans/work/build/media-git/include/linux/kernel.h:173,
 from /home/hans/work/build/media-git/include/linux/list.h:9,
 from 
/home/hans/work/build/media-git/include/media/v4l2-ctrls.h:20,
 from 
/home/hans/work/build/media-git/drivers/media/platform/qcom/venus/venc_ctrls.c:16:
/home/hans/work/build/media-git/drivers/media/platform/qcom/venus/venc_ctrls.c: 
In function 'venc_calc_bpframes':
/home/hans/work/build/media-git/include/asm-generic/div64.h:222:28: warning: 
comparison of distinct pointer types lacks a cast
  (void)(((typeof((n)) *)0) == ((uint64_t *)0)); \
^
/home/hans/work/build/media-git/drivers/media/platform/qcom/venus/venc_ctrls.c:56:3:
 note: in expansion of macro 'do_div'
   do_div(ratio, p);
   ^~
In file included from 
/home/hans/work/build/media-git/include/linux/kernel.h:10:0,
 from /home/hans/work/build/media-git/include/linux/list.h:9,
 from 
/home/hans/work/build/media-git/include/media/v4l2-ctrls.h:20,
 from 
/home/hans/work/build/media-git/drivers/media/platform/qcom/venus/venc_ctrls.c:16:
/home/hans/work/build/media-git/include/asm-generic/div64.h:235:25: warning: 
right shift count >= width of type [-Wshift-count-overflow]
  } else if (likely(((n) >> 32) == 0)) {  \
 ^
/home/hans/work/build/media-git/include/linux/compiler.h:76:40: note: in 
definition of macro 'likely'
 # define likely(x) __builtin_expect(!!(x), 1)
^
/home/hans/work/build/media-git/drivers/media/platform/qcom/venus/venc_ctrls.c:56:3:
 note: in expansion of macro 'do_div'
   do_div(ratio, p);
   ^~
In file included from 
/home/hans/work/build/media-git/arch/arm/include/asm/div64.h:127:0,
 from 

Re: [PATCH v12 2/2] rcar-csi2: add Renesas R-Car MIPI CSI-2 receiver driver

2017-12-01 Thread Sakari Ailus
Hej Niklas,

Tack för dina nya lappar!

On Wed, Nov 29, 2017 at 08:32:35PM +0100, Niklas Söderlund wrote:
> A V4L2 driver for Renesas R-Car MIPI CSI-2 receiver. The driver
> supports the rcar-vin driver on R-Car Gen3 SoCs where separate CSI-2
> hardware blocks are connected between the video sources and the video
> grabbers (VIN).
> 
> Driver is based on a prototype by Koji Matsuoka in the Renesas BSP.
> 
> Signed-off-by: Niklas Söderlund 
> Reviewed-by: Hans Verkuil 
> ---
>  drivers/media/platform/rcar-vin/Kconfig |  12 +
>  drivers/media/platform/rcar-vin/Makefile|   1 +
>  drivers/media/platform/rcar-vin/rcar-csi2.c | 898 
> 
>  3 files changed, 911 insertions(+)
>  create mode 100644 drivers/media/platform/rcar-vin/rcar-csi2.c
> 
> diff --git a/drivers/media/platform/rcar-vin/Kconfig 
> b/drivers/media/platform/rcar-vin/Kconfig
> index af4c98b44d2e22cb..6875f30c1ae42631 100644
> --- a/drivers/media/platform/rcar-vin/Kconfig
> +++ b/drivers/media/platform/rcar-vin/Kconfig
> @@ -1,3 +1,15 @@
> +config VIDEO_RCAR_CSI2
> + tristate "R-Car MIPI CSI-2 Receiver"
> + depends on VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API && OF
> + depends on ARCH_RENESAS || COMPILE_TEST
> + select V4L2_FWNODE
> + ---help---
> +   Support for Renesas R-Car MIPI CSI-2 receiver.
> +   Supports R-Car Gen3 SoCs.
> +
> +   To compile this driver as a module, choose M here: the
> +   module will be called rcar-csi2.
> +
>  config VIDEO_RCAR_VIN
>   tristate "R-Car Video Input (VIN) Driver"
>   depends on VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API && OF && HAS_DMA && 
> MEDIA_CONTROLLER
> diff --git a/drivers/media/platform/rcar-vin/Makefile 
> b/drivers/media/platform/rcar-vin/Makefile
> index 48c5632c21dc060b..5ab803d3e7c1aa57 100644
> --- a/drivers/media/platform/rcar-vin/Makefile
> +++ b/drivers/media/platform/rcar-vin/Makefile
> @@ -1,3 +1,4 @@
>  rcar-vin-objs = rcar-core.o rcar-dma.o rcar-v4l2.o
>  
> +obj-$(CONFIG_VIDEO_RCAR_CSI2) += rcar-csi2.o
>  obj-$(CONFIG_VIDEO_RCAR_VIN) += rcar-vin.o
> diff --git a/drivers/media/platform/rcar-vin/rcar-csi2.c 
> b/drivers/media/platform/rcar-vin/rcar-csi2.c
> new file mode 100644
> index ..30aafcbb7a3642c6
> --- /dev/null
> +++ b/drivers/media/platform/rcar-vin/rcar-csi2.c
> @@ -0,0 +1,898 @@
> +/*
> + * Driver for Renesas R-Car MIPI CSI-2 Receiver
> + *
> + * Copyright (C) 2017 Renesas Electronics Corp.
> + *
> + * This program is free software; you can redistribute  it and/or modify it
> + * under  the terms of  the GNU General  Public License as published by the
> + * Free Software Foundation;  either version 2 of the  License, or (at your
> + * option) any later version.
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +/* Register offsets and bits */
> +
> +/* Control Timing Select */
> +#define TREF_REG 0x00
> +#define TREF_TREFBIT(0)
> +
> +/* Software Reset */
> +#define SRST_REG 0x04
> +#define SRST_SRSTBIT(0)
> +
> +/* PHY Operation Control */
> +#define PHYCNT_REG   0x08
> +#define PHYCNT_SHUTDOWNZ BIT(17)
> +#define PHYCNT_RSTZ  BIT(16)
> +#define PHYCNT_ENABLECLK BIT(4)
> +#define PHYCNT_ENABLE_3  BIT(3)
> +#define PHYCNT_ENABLE_2  BIT(2)
> +#define PHYCNT_ENABLE_1  BIT(1)
> +#define PHYCNT_ENABLE_0  BIT(0)
> +
> +/* Checksum Control */
> +#define CHKSUM_REG   0x0c
> +#define CHKSUM_ECC_ENBIT(1)
> +#define CHKSUM_CRC_ENBIT(0)
> +
> +/*
> + * Channel Data Type Select
> + * VCDT[0-15]:  Channel 1 VCDT[16-31]:  Channel 2
> + * VCDT2[0-15]: Channel 3 VCDT2[16-31]: Channel 4
> + */
> +#define VCDT_REG 0x10
> +#define VCDT2_REG0x14
> +#define VCDT_VCDTN_ENBIT(15)
> +#define VCDT_SEL_VC(n)   (((n) & 0x3) << 8)
> +#define VCDT_SEL_DTN_ON  BIT(6)
> +#define VCDT_SEL_DT(n)   (((n) & 0x3f) << 0)
> +
> +/* Frame Data Type Select */
> +#define FRDT_REG 0x18
> +
> +/* Field Detection Control */
> +#define FLD_REG  0x1c
> +#define FLD_FLD_NUM(n)   (((n) & 0xff) << 16)
> +#define FLD_FLD_EN4  BIT(3)
> +#define FLD_FLD_EN3  BIT(2)
> +#define FLD_FLD_EN2  BIT(1)
> +#define FLD_FLD_EN   BIT(0)
> +
> +/* Automatic Standby Control */
> +#define ASTBY_REG0x20
> +
> +/* Long Data Type Setting 0 */
> +#define LNGDT0_REG   0x28
> +

Re: [PATCH] media: imx: Remove incorrect check for queue state in start_streaming

2017-12-01 Thread Hans Verkuil
On 11/17/17 19:23, Ian Jamison wrote:
> It is possible to call STREAMON without the minimum number of
> buffers queued. In this case the vb2_queue state will be set to
> streaming but the start_streaming vb2_op will not be called.
> Later when enough buffers are queued, start_streaming will
> be called but vb2_is_streaming will already return true.
> 
> Signed-off-by: Ian Jamison 
> ---
>  drivers/staging/media/imx/imx-media-capture.c | 3 ---
>  1 file changed, 3 deletions(-)
> 
> diff --git a/drivers/staging/media/imx/imx-media-capture.c 
> b/drivers/staging/media/imx/imx-media-capture.c
> index ddab4c249da2..34b492c2419c 100644
> --- a/drivers/staging/media/imx/imx-media-capture.c
> +++ b/drivers/staging/media/imx/imx-media-capture.c
> @@ -449,9 +449,6 @@ static int capture_start_streaming(struct vb2_queue *vq, 
> unsigned int count)
>   unsigned long flags;
>   int ret;
>  
> - if (vb2_is_streaming(vq))
> - return 0;
> -
>   ret = imx_media_pipeline_set_stream(priv->md, >src_sd->entity,
>   true);
>   if (ret) {
> 

Can you also remove this from capture_stop_streaming:

if (!vb2_is_streaming(vq))
return;

Both checks are wrong and pointless. The vb2 core will do all the right checks
and this shouldn't be done again (and wrongly) in the driver.

Regards,

Hans


[PATCH 1/3] media: dvb_frontend: Add unlocked_ioctl in dvb_frontend.c

2017-12-01 Thread Jaedon Shin
Adds unlocked ioctl function directly in dvb_frontend.c instead of using
dvb_generic_ioctl().

Signed-off-by: Jaedon Shin 
---
 drivers/media/dvb-core/dvb_frontend.c | 17 ++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/drivers/media/dvb-core/dvb_frontend.c 
b/drivers/media/dvb-core/dvb_frontend.c
index 3ad83359098b..6d8f4dd39c0c 100644
--- a/drivers/media/dvb-core/dvb_frontend.c
+++ b/drivers/media/dvb-core/dvb_frontend.c
@@ -1920,7 +1920,8 @@ static int dtv_property_process_set(struct dvb_frontend 
*fe,
return r;
 }
 
-static int dvb_frontend_ioctl(struct file *file, unsigned int cmd, void *parg)
+static int dvb_frontend_do_ioctl(struct file *file, unsigned int cmd,
+void *parg)
 {
struct dvb_device *dvbdev = file->private_data;
struct dvb_frontend *fe = dvbdev->priv;
@@ -1963,6 +1964,17 @@ static int dvb_frontend_ioctl(struct file *file, 
unsigned int cmd, void *parg)
return err;
 }
 
+static long dvb_frontend_ioctl(struct file *file, unsigned int cmd,
+  unsigned long arg)
+{
+   struct dvb_device *dvbdev = file->private_data;
+
+   if (!dvbdev)
+   return -ENODEV;
+
+   return dvb_usercopy(file, cmd, arg, dvb_frontend_do_ioctl);
+}
+
 static int dtv_set_frontend(struct dvb_frontend *fe)
 {
struct dvb_frontend_private *fepriv = fe->frontend_priv;
@@ -2644,7 +2656,7 @@ static int dvb_frontend_release(struct inode *inode, 
struct file *file)
 
 static const struct file_operations dvb_frontend_fops = {
.owner  = THIS_MODULE,
-   .unlocked_ioctl = dvb_generic_ioctl,
+   .unlocked_ioctl = dvb_frontend_ioctl,
.poll   = dvb_frontend_poll,
.open   = dvb_frontend_open,
.release= dvb_frontend_release,
@@ -2712,7 +2724,6 @@ int dvb_register_frontend(struct dvb_adapter* dvb,
 #if defined(CONFIG_MEDIA_CONTROLLER_DVB)
.name = fe->ops.info.name,
 #endif
-   .kernel_ioctl = dvb_frontend_ioctl
};
 
dev_dbg(dvb->device, "%s:\n", __func__);
-- 
2.15.0



[PATCH 2/3] media: dvb_frontend: Add compat_ioctl callback

2017-12-01 Thread Jaedon Shin
Adds compat_ioctl for 32-bit user space applications on a 64-bit system.

Signed-off-by: Jaedon Shin 
---
 drivers/media/dvb-core/dvb_frontend.c | 11 +++
 fs/compat_ioctl.c | 17 -
 2 files changed, 11 insertions(+), 17 deletions(-)

diff --git a/drivers/media/dvb-core/dvb_frontend.c 
b/drivers/media/dvb-core/dvb_frontend.c
index 6d8f4dd39c0c..1ae23403a0ab 100644
--- a/drivers/media/dvb-core/dvb_frontend.c
+++ b/drivers/media/dvb-core/dvb_frontend.c
@@ -1975,6 +1975,14 @@ static long dvb_frontend_ioctl(struct file *file, 
unsigned int cmd,
return dvb_usercopy(file, cmd, arg, dvb_frontend_do_ioctl);
 }
 
+#ifdef CONFIG_COMPAT
+static long dvb_frontend_compat_ioctl(struct file *file, unsigned int cmd,
+ unsigned long arg)
+{
+   return dvb_frontend_ioctl(file, cmd, (unsigned long)compat_ptr(arg));
+}
+#endif
+
 static int dtv_set_frontend(struct dvb_frontend *fe)
 {
struct dvb_frontend_private *fepriv = fe->frontend_priv;
@@ -2657,6 +2665,9 @@ static int dvb_frontend_release(struct inode *inode, 
struct file *file)
 static const struct file_operations dvb_frontend_fops = {
.owner  = THIS_MODULE,
.unlocked_ioctl = dvb_frontend_ioctl,
+#ifdef CONFIG_COMPAT
+   .compat_ioctl   = dvb_frontend_compat_ioctl,
+#endif
.poll   = dvb_frontend_poll,
.open   = dvb_frontend_open,
.release= dvb_frontend_release,
diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
index 5fc5dc660600..9a1fe60cce9a 100644
--- a/fs/compat_ioctl.c
+++ b/fs/compat_ioctl.c
@@ -1218,23 +1218,6 @@ COMPATIBLE_IOCTL(DMX_SET_PES_FILTER)
 COMPATIBLE_IOCTL(DMX_SET_BUFFER_SIZE)
 COMPATIBLE_IOCTL(DMX_GET_PES_PIDS)
 COMPATIBLE_IOCTL(DMX_GET_STC)
-COMPATIBLE_IOCTL(FE_GET_INFO)
-COMPATIBLE_IOCTL(FE_DISEQC_RESET_OVERLOAD)
-COMPATIBLE_IOCTL(FE_DISEQC_SEND_MASTER_CMD)
-COMPATIBLE_IOCTL(FE_DISEQC_RECV_SLAVE_REPLY)
-COMPATIBLE_IOCTL(FE_DISEQC_SEND_BURST)
-COMPATIBLE_IOCTL(FE_SET_TONE)
-COMPATIBLE_IOCTL(FE_SET_VOLTAGE)
-COMPATIBLE_IOCTL(FE_ENABLE_HIGH_LNB_VOLTAGE)
-COMPATIBLE_IOCTL(FE_READ_STATUS)
-COMPATIBLE_IOCTL(FE_READ_BER)
-COMPATIBLE_IOCTL(FE_READ_SIGNAL_STRENGTH)
-COMPATIBLE_IOCTL(FE_READ_SNR)
-COMPATIBLE_IOCTL(FE_READ_UNCORRECTED_BLOCKS)
-COMPATIBLE_IOCTL(FE_SET_FRONTEND)
-COMPATIBLE_IOCTL(FE_GET_FRONTEND)
-COMPATIBLE_IOCTL(FE_GET_EVENT)
-COMPATIBLE_IOCTL(FE_DISHNETWORK_SEND_LEGACY_CMD)
 COMPATIBLE_IOCTL(VIDEO_STOP)
 COMPATIBLE_IOCTL(VIDEO_PLAY)
 COMPATIBLE_IOCTL(VIDEO_FREEZE)
-- 
2.15.0



[PATCH 3/3] media: dvb_frontend: Add commands implementation for compat ioct

2017-12-01 Thread Jaedon Shin
The dtv_properties structure and the dtv_property structure are
different sizes in 32-bit and 64-bit system. This patch provides
FE_SET_PROPERTY and FE_GET_PROPERTY ioctl commands implementation for
32-bit user space applications.

Signed-off-by: Jaedon Shin 
---
 drivers/media/dvb-core/dvb_frontend.c | 131 ++
 1 file changed, 131 insertions(+)

diff --git a/drivers/media/dvb-core/dvb_frontend.c 
b/drivers/media/dvb-core/dvb_frontend.c
index 1ae23403a0ab..f3751a573dfe 100644
--- a/drivers/media/dvb-core/dvb_frontend.c
+++ b/drivers/media/dvb-core/dvb_frontend.c
@@ -1976,9 +1976,140 @@ static long dvb_frontend_ioctl(struct file *file, 
unsigned int cmd,
 }
 
 #ifdef CONFIG_COMPAT
+struct compat_dtv_property {
+   __u32 cmd;
+   __u32 reserved[3];
+   union {
+   __u32 data;
+   struct dtv_fe_stats st;
+   struct {
+   __u8 data[32];
+   __u32 len;
+   __u32 reserved1[3];
+   compat_uptr_t reserved2;
+   } buffer;
+   } u;
+   int result;
+} __attribute__ ((packed));
+
+struct compat_dtv_properties {
+   __u32 num;
+   compat_uptr_t props;
+};
+
+#define COMPAT_FE_SET_PROPERTY_IOW('o', 82, struct compat_dtv_properties)
+#define COMPAT_FE_GET_PROPERTY_IOR('o', 83, struct compat_dtv_properties)
+
+static int dvb_frontend_handle_compat_ioctl(struct file *file, unsigned int 
cmd,
+   unsigned long arg)
+{
+   struct dvb_device *dvbdev = file->private_data;
+   struct dvb_frontend *fe = dvbdev->priv;
+   struct dvb_frontend_private *fepriv = fe->frontend_priv;
+   int i, err = 0;
+
+   if (cmd == COMPAT_FE_SET_PROPERTY) {
+   struct compat_dtv_properties prop, *tvps = NULL;
+   struct compat_dtv_property *tvp = NULL;
+
+   if (copy_from_user(, compat_ptr(arg), sizeof(prop)))
+   return -EFAULT;
+
+   tvps = 
+
+   /*
+* Put an arbitrary limit on the number of messages that can
+* be sent at once
+*/
+   if (!tvps->num || (tvps->num > DTV_IOCTL_MAX_MSGS))
+   return -EINVAL;
+
+   tvp = memdup_user(compat_ptr(tvps->props), tvps->num * 
sizeof(*tvp));
+   if (IS_ERR(tvp))
+   return PTR_ERR(tvp);
+
+   for (i = 0; i < tvps->num; i++) {
+   err = dtv_property_process_set(fe, file,
+   (tvp + i)->cmd,
+   (tvp + i)->u.data);
+   if (err < 0) {
+   kfree(tvp);
+   return err;
+   }
+   }
+   kfree(tvp);
+   } else if (cmd == COMPAT_FE_GET_PROPERTY) {
+   struct compat_dtv_properties prop, *tvps = NULL;
+   struct compat_dtv_property *tvp = NULL;
+   struct dtv_frontend_properties getp = fe->dtv_property_cache;
+
+   if (copy_from_user(, compat_ptr(arg), sizeof(prop)))
+   return -EFAULT;
+
+   tvps = 
+
+   /*
+* Put an arbitrary limit on the number of messages that can
+* be sent at once
+*/
+   if (!tvps->num || (tvps->num > DTV_IOCTL_MAX_MSGS))
+   return -EINVAL;
+
+   tvp = memdup_user(compat_ptr(tvps->props), tvps->num * 
sizeof(*tvp));
+   if (IS_ERR(tvp))
+   return PTR_ERR(tvp);
+
+   /*
+* Let's use our own copy of property cache, in order to
+* avoid mangling with DTV zigzag logic, as drivers might
+* return crap, if they don't check if the data is available
+* before updating the properties cache.
+*/
+   if (fepriv->state != FESTATE_IDLE) {
+   err = dtv_get_frontend(fe, , NULL);
+   if (err < 0) {
+   kfree(tvp);
+   return err;
+   }
+   }
+   for (i = 0; i < tvps->num; i++) {
+   err = dtv_property_process_get(
+   fe, , (struct dtv_property *)tvp + i, file);
+   if (err < 0) {
+   kfree(tvp);
+   return err;
+   }
+   }
+
+   if (copy_to_user((void __user *)compat_ptr(tvps->props), tvp,
+tvps->num * sizeof(struct 
compat_dtv_property))) {
+   kfree(tvp);
+   return -EFAULT;
+   

[PATCH 0/3] Add support compat in dvb_frontend.c

2017-12-01 Thread Jaedon Shin
This patch series supports compat ioctl for 32-bit user space applications
in 64-bit system.

Jaedon Shin (3):
  media: dvb_frontend: Add unlocked_ioctl in dvb_frontend.c
  media: dvb_frontend: Add compat_ioctl callback
  media: dvb_frontend: Add commands implementation for compat ioct

 drivers/media/dvb-core/dvb_frontend.c | 159 +-
 fs/compat_ioctl.c |  17 
 2 files changed, 156 insertions(+), 20 deletions(-)

-- 
2.15.0



Re: multiple frontends on a single dvb adapter

2017-12-01 Thread Mauro Carvalho Chehab
Em Fri, 1 Dec 2017 12:38:14 +0100
pieterg  escreveu:

> Hi,
> 
> The recent removal of DMX_SET_SOURCE
> 
> https://github.com/torvalds/linux/commit/13adefbe9e566c6db91579e4ce17f1e5193d6f2c
> 
> and earlier removal of the set_source callback
> 
> https://github.com/torvalds/linux/commit/1e92bbe08ad9fc0d5ec05174c176a9bc54921733
> 
> leads to the question how the situation of having multiple frontends on
> a single dvb adapter should be handled nowadays.
> Suppose the routing is flexible, any demux could be sourced by any frontend.
> In the past, this has been achieved by using the set_source callback,
> allowing userspace to configure the routing by using the DMX_SET_SOURCE
> ioctl.
> 
> The connect_frontend / disconnect_frontend callbacks are currently only
> called for the memory frontend, so it seems no longer possible to select
> hardware frontends.
> How do you guys see this, what does the standard dictate in this case?
> Should we assume a 1:1 mapping between frontendN:demuxN and forbid
> dynamic routing? Or am I overlooking something?
> 
> In my opinion, supporting dynamic routing would be an advantage.
> Especially when the number of (hardware) demuxes is smaller than the
> number of (hardware) frontends.

The best way to support dynamic routing is via the media controller
API. the DVB core already creates media controller entities for
the existing hardware, but the links for the non-trivial case
(e. g. there's no 1:1 mapping) should be created by the driver.

The big advantage of using the media controller is that you could
dynamically setup the pipeline, not only between frontend and
demux, but also with some other hardware. For example, with that,
you could easily add a CI module at the pipeline, for an scrambled
channel, or remove it, when the channel doesn't require, or when
it is required to store a movie scrambled (that's usually required
for embedded systems). At reproduction, a pipeline with the CI
descrambler could be used.


Thanks,
Mauro


Re: DVB-S2 and S2X API extensions

2017-12-01 Thread Mauro Carvalho Chehab
Em Thu, 30 Nov 2017 23:15:40 +0200
Αθανάσιος Οικονόμου  escreveu:

> 2017-11-30 20:26 GMT+02:00 Mauro Carvalho Chehab :
> > Em Mon, 20 Nov 2017 02:05:35 +0100
> > Ralph Metzler  escreveu:
> >  
> >> Hi,  
> >
> > (C/C Athanasios, as he also rised concerns about S2X).  
> >>
> >> Mauro Carvalho Chehab writes:  
> >>  > Em Thu, 9 Nov 2017 16:28:18 +0100
> >>  > Ralph Metzler  escreveu:
> >>  >  
> >>  > > Hi,
> >>  > >
> >>  > > I have a few RFCs regarding new needed enums and
> >>  > > properties for DVB-S2 and DVB-S2X:
> >>  > >
> >>  > > - DVB-S2/X physical layer scrambling
> >>  > >
> >>  > > I currently use the inofficial DTV_PLS for setting the scrambling
> >>  > > sequence index (cf. ETSI EN 300 468 table 41) of
> >>  > > the physical layer scrambling in DVB-S2 and DVB-S2X.
> >>  > > Some drivers already misuse bits 8-27 of the DTV_STREAM_ID
> >>  > > for setting this. They also differentiate between gold, root
> >>  > > and combo codes.
> >>  > > The gold code is the actual scrambling sequence index.
> >>  > > The root code is just an intermediate calculation
> >>  > > accepted by some chips, but derived from the gold code.
> >>  > > It can be easily mapped one-to-one to the gold code.
> >>  > > (see https://github.com/DigitalDevices/dddvb/blob/master/apps/pls.c,
> >>  > > A more optimized version of this could be added to dvb-math.c)
> >>  > > The combo code does not really exist but is a by-product
> >>  > > of the buggy usage of a gold to root code conversion in ST chips.
> >>  > >
> >>  > > So, I would propose to officially introduce a property
> >>  > > for the scrambling sequence index (=gold code).
> >>  > > Should it be called DTV_PLS (which I already used in the dddvb 
> >> package)
> >>  > > or rather DTV_SSI?
> >>  > > I realized PLS can be confused with physical layer signalling which
> >>  > > uses the acronym PLS in the DVB-S2 specs.  
> >>  >
> >>  > Yes, it makes sense to have a DTV property for the PLS gold code.
> >>  >
> >>  > I would prefer to use a clearer name, like DTV_PLS_GOLD_CODE,
> >>  > to make easier to identify what it means.
> >>  >
> >>  > At documentation, we should point to EN 302 307 section 5.5.4 and
> >>  > to EN 300 468 table 41, with a good enough description to make
> >>  > clear that it is the gold code, and not the root code (or
> >>  > a chipset-specific "combo" code).  
> >>
> >> If we use a long descriptive name, DTV_SCRAMBLING_SEQUENCE_INDEX might
> >> be better because it is the actual name used for it in the documentation
> >> and SI fields.  
> >
> > I'm OK with that.
> >  
> >> And, to make it absolutely clear, the combo code is not just a
> >> chipset-specific code, it is utter BS!
> >> Here is why (sorry for the lengthy explanation):
> >>
> >> The STV090X/0910 chips have 3 8-bit registers for setting the
> >> root code called PLROOT0, PLROOT1 and PLROOT2.
> >> The code has 18 bits. So PLROOT0, PLROOT1 and the lower 2 bits
> >> (bits 0 and 1) of PLROOT2 are the root code.
> >> Bits 2 and 3 of PLROOT2 determine a mode with the following
> >> 3 possible values:
> >> 0 = the 18 bits are the root code
> >> 1 = the 18 bits are the gold code
> >> 2 = if you write the gold code to the 18 bits, they will
> >> be converted to the root code and you can then
> >> read them back, mode will be changed to 0 after
> >> conversion
> >>
> >> This mode 2 is what somebody called "combo code".
> >> But why is it seen as a different code? It should
> >> behave just identical to writing a gold code!
> >> Because some Linux drivers, probably also some
> >> Windows drivers, first write PLROOT2, then PLROOT1 and
> >> PLROOT0, also in the case of mode 2.
> >> Writing the 2 in the mode bits actually triggers the
> >> gold->root conversion and this conversion takes some time!
> >>
> >> So, the conversion is triggered by the write to PLROOT2
> >> even though PLROOT1 and PLROOT0 have not yet been written.
> >> Depending on many factors like I2C write speed, the
> >> computer speed, other tasks running, etc. and especially also
> >> the previous values of PLROOT1 and PLROOT2, you will get
> >> varying results after the conversion.
> >> The length of the conversion also depends on the size of
> >> the gold code.
> >> For small gold codes the conversion is so fast that
> >> it is finished before PLROOT1 and PLROOT2 are written.
> >> The lower 16 bits of the conversion results will actually be overwritten
> >> again! For larger gold codes only the lower 8 bits, etc.
> >>
> >> Think about all the race conditions and wrong initial values in this
> >> process and everybody please forget about "combo code"!  
> >
> > Yeah, it sounds messy ;-)
> >  
> >>  > > DVB-S2X also defines 7 preferred scrambling code sequences
> >>  > > (EN 302 307-2 5.5.4) which should be checked during tuning.
> >>  > > If the demod does not do this, should the DVB kernel layer or
> >>  > > application do 

Re: multiple frontends on a single dvb adapter

2017-12-01 Thread Honza Petrouš
2017-12-01 12:38 GMT+01:00 pieterg :
> Hi,
>
> The recent removal of DMX_SET_SOURCE
>
> https://github.com/torvalds/linux/commit/13adefbe9e566c6db91579e4ce17f1e5193d6f2c
>
> and earlier removal of the set_source callback
>
> https://github.com/torvalds/linux/commit/1e92bbe08ad9fc0d5ec05174c176a9bc54921733
>
> leads to the question how the situation of having multiple frontends on
> a single dvb adapter should be handled nowadays.
> Suppose the routing is flexible, any demux could be sourced by any frontend.
> In the past, this has been achieved by using the set_source callback,
> allowing userspace to configure the routing by using the DMX_SET_SOURCE
> ioctl.
>
> The connect_frontend / disconnect_frontend callbacks are currently only
> called for the memory frontend, so it seems no longer possible to select
> hardware frontends.
> How do you guys see this, what does the standard dictate in this case?
> Should we assume a 1:1 mapping between frontendN:demuxN and forbid
> dynamic routing? Or am I overlooking something?
>
> In my opinion, supporting dynamic routing would be an advantage.
> Especially when the number of (hardware) demuxes is smaller than the
> number of (hardware) frontends.


It was already discussed with Mauro, when me (and may be some others
complained about such removals).

The rule is simple - if you have HW with multiple frontends, then you can
provide patch and revive the old stuffs.

Mauro's POV is = no user of such callbacks/ioctl means removal of that.

/Honza


multiple frontends on a single dvb adapter

2017-12-01 Thread pieterg
Hi,

The recent removal of DMX_SET_SOURCE

https://github.com/torvalds/linux/commit/13adefbe9e566c6db91579e4ce17f1e5193d6f2c

and earlier removal of the set_source callback

https://github.com/torvalds/linux/commit/1e92bbe08ad9fc0d5ec05174c176a9bc54921733

leads to the question how the situation of having multiple frontends on
a single dvb adapter should be handled nowadays.
Suppose the routing is flexible, any demux could be sourced by any frontend.
In the past, this has been achieved by using the set_source callback,
allowing userspace to configure the routing by using the DMX_SET_SOURCE
ioctl.

The connect_frontend / disconnect_frontend callbacks are currently only
called for the memory frontend, so it seems no longer possible to select
hardware frontends.
How do you guys see this, what does the standard dictate in this case?
Should we assume a 1:1 mapping between frontendN:demuxN and forbid
dynamic routing? Or am I overlooking something?

In my opinion, supporting dynamic routing would be an advantage.
Especially when the number of (hardware) demuxes is smaller than the
number of (hardware) frontends.

Regards,
Pieter


Re: notifier is skipped in some situations

2017-12-01 Thread Sakari Ailus
Hi Jacob,

On Thu, Nov 30, 2017 at 09:37:06AM +0800, Jacob Chen wrote:
> Hi Sakari,
> 
> On 2017年11月29日星期三 CST 下午2:29:03 you wrote:
> > Hi Jacob,
> > 
> > On Mon, Nov 27, 2017 at 03:03:59PM +0800, Jacob Chen wrote:
> > > Hi,
> > > 
> > > On 2017年11月25日星期六 CST 下午1:05:42 you wrote:
> > > > Hi,
> > > > 
> > > > On 2017年11月24日星期五 CST 下午6:19:36 you wrote:
> > > > > On Fri, Nov 24, 2017 at 6:17 PM, Sakari Ailus
> > > > > 
> > > > >  wrote:
> > > > > > Hi Tomasz,
> > > > > > 
> > > > > > On Fri, Nov 24, 2017 at 06:03:26PM +0900, Tomasz Figa wrote:
> > > > > >> Hi Sakari,
> > > > > >> 
> > > > > >> We have the following graph:
> > > > > >> ISP (registers notifier for v4l2_dev)
> > > > > >> 
> > > > > >> 
> > > > > >> 
> > > > > >> PHY (registers notifier for v4l2_subdev, just like sensors for
> > > > > >> 
> > > > > >> flash/focuser)
> > > > > >> 
> > > > > >>   |   \
> > > > > >> 
> > > > > >> sensor0   sensor1
> > > > > >> 
> > > > > >> ...
> > > > > >> 
> > > > > >> Both ISP and PHY are completely separate drivers not directly aware
> > > > > >> of
> > > > > >> each other, since we have several different PHY IP blocks that we
> > > > > >> need
> > > > > >> to support and some of them are multi-functional, such as CSI+DSI
> > > > > >> PHY
> > > > > >> and need to be supported by drivers independent from the ISP
> > > > > >> driver.
> > > > > > 
> > > > > > That should work fine. In the above case there are two notifiers,
> > > > > > indeed,
> > > > > > but they're not expecting the *same* sub-devices.
> > > > > 
> > > > > Got it.
> > > > > 
> > > > > Jacob, could you make sure there are no mistakes in the Device Tree
> > > > > source?
> > > > > 
> > > > > Best regards,
> > > > > Tomasz
> > > > 
> > > > I see...
> > > > This problem might be sloved by moving
> > > > `v4l2_async_subdev_notifier_register` after
> > > > `v4l2_async_register_subdev`. I will test it.
> > > > 
> > > > > > What this could be about is that in some version of the set I
> > > > > > disabled
> > > > > > the
> > > > > > complete callback on the sub-notifiers for two reasons: there was no
> > > > > > need
> > > > > > seen for them and the complete callback is problematic in general
> > > > > > (there's
> > > > > > been discussion on that, mostly related to earlier versions of the
> > > > > > fwnode
> > > > > > parsing patchset, on #v4l and along the Renesas rcar-csi2
> > > > > > patchsets).
> > > > > > 
> > > > > >> Best regards,
> > > > > >> Tomasz
> > > > > >> 
> > > > > >> 
> > > > > >> On Fri, Nov 24, 2017 at 5:55 PM, Sakari Ailus
> > > > > >> 
> > > > > >>  wrote:
> > > > > >> > Hi Jacob,
> > > > > >> > 
> > > > > >> > On Fri, Nov 24, 2017 at 09:00:14AM +0800, Jacob Chen wrote:
> > > > > >> >> Hi Sakari,
> > > > > >> >> 
> > > > > >> >> I encountered a problem when using async sub-notifiers.
> > > > > >> >> 
> > > > > >> >> It's like that:
> > > > > >> >> There are two notifiers, and they are waiting for one
> > > > > >> >> subdev.
> > > > > >> >> When this subdev is probing, only one notifier is completed
> > > > > >> >> and
> > > > > >> >> 
> > > > > >> >> the other one is skipped.
> > > > > >> > 
> > > > > >> > Do you have a graph that has two master drivers (that register
> > > > > >> > the
> > > > > >> > notifier) and both are connected to the same sub-device? Could
> > > > > >> > you
> > > > > >> > provide
> > > > > >> > exact graph you have?
> > > > > >> > 
> > > > > >> >> I found that in v15 of patch "v4l: async: Allow binding
> > > > > >> >> notifiers to
> > > > > >> >> sub-devices", "v4l2_async_notifier_complete" is replaced by
> > > > > >> >> v4l2_async_notifier_call_complete, which make it only complete
> > > > > >> >> one
> > > > > >> >> notifier.
> > > > > >> >> 
> > > > > >> >> Why is it changed? Can this be fixed?
> > > > > >> > 
> > > > > >> > --
> > > > > >> > Sakari Ailus
> > > > > >> > sakari.ai...@linux.intel.com
> > > > > > 
> > > > > > --
> > > > > > Sakari Ailus
> > > > > > sakari.ai...@linux.intel.com
> > > 
> > > I make a mistake, they are not expecting same subdev.
> > > 
> > > The problem is that a notifier regsitered by
> > > `v4l2_async_subdev_notifier_register` will never be completed, becuase
> > > 1.`notifier->waiting` is always not empty, so
> > > v4l2_async_notifier_try_complete won't be called.
> > > 2. In old code, it's called by its parent, but now it won't.
> > 
> > Could you provide a bit more context, what exactly fails and in which order
> > the notifiers are registered and async sub-device matches are found?
> > 
> 
> The order doesn't matter.
> Both of below orders will fail.
> 1.
> v4l2_async_notifier_parse_fwnode_endpoints_by_port(NOTIFIER1)
> v4l2_async_subdev_notifier_register(NOTIFIER1, PHY)
> v4l2_async_register_subdev(PHY)
> 
> 1.
> v4l2_async_register_subdev(PHY)
> v4l2_async_notifier_parse_fwnode_endpoints_by_port(NOTIFIER1)
> v4l2_async_subdev_notifier_register(NOTIFIER1, PHY)
> 
> 

[PATCH] dma-buf: add some lockdep asserts to the reservation object implementation

2017-12-01 Thread Lucas Stach
This adds lockdep asserts to the reservation functions which state in their
documentation that obj->lock must be held. Allows builds with PROVE_LOCKING
enabled to check that the locking requirements are met.

Signed-off-by: Lucas Stach 
---
 drivers/dma-buf/reservation.c | 8 
 include/linux/reservation.h   | 2 ++
 2 files changed, 10 insertions(+)

diff --git a/drivers/dma-buf/reservation.c b/drivers/dma-buf/reservation.c
index b44d9d7db347..accd398e2ea6 100644
--- a/drivers/dma-buf/reservation.c
+++ b/drivers/dma-buf/reservation.c
@@ -71,6 +71,8 @@ int reservation_object_reserve_shared(struct 
reservation_object *obj)
struct reservation_object_list *fobj, *old;
u32 max;
 
+   reservation_object_assert_held(obj);
+
old = reservation_object_get_list(obj);
 
if (old && old->shared_max) {
@@ -211,6 +213,8 @@ void reservation_object_add_shared_fence(struct 
reservation_object *obj,
 {
struct reservation_object_list *old, *fobj = obj->staged;
 
+   reservation_object_assert_held(obj);
+
old = reservation_object_get_list(obj);
obj->staged = NULL;
 
@@ -236,6 +240,8 @@ void reservation_object_add_excl_fence(struct 
reservation_object *obj,
struct reservation_object_list *old;
u32 i = 0;
 
+   reservation_object_assert_held(obj);
+
old = reservation_object_get_list(obj);
if (old)
i = old->shared_count;
@@ -276,6 +282,8 @@ int reservation_object_copy_fences(struct 
reservation_object *dst,
size_t size;
unsigned i;
 
+   reservation_object_assert_held(dst);
+
rcu_read_lock();
src_list = rcu_dereference(src->fence);
 
diff --git a/include/linux/reservation.h b/include/linux/reservation.h
index 21fc84d82d41..55e7318800fd 100644
--- a/include/linux/reservation.h
+++ b/include/linux/reservation.h
@@ -212,6 +212,8 @@ reservation_object_unlock(struct reservation_object *obj)
 static inline struct dma_fence *
 reservation_object_get_excl(struct reservation_object *obj)
 {
+   reservation_object_assert_held(obj);
+
return rcu_dereference_protected(obj->fence_excl,
 reservation_object_held(obj));
 }
-- 
2.11.0



Re: [PATCH 0/4] Backported amdgpu ttm deadlock fixes for 4.14

2017-12-01 Thread Christian König

Am 01.12.2017 um 01:23 schrieb Lyude Paul:

I haven't gone to see where it started, but as of late a good number of
pretty nasty deadlock issues have appeared with the kernel. Easy
reproduction recipe on a laptop with i915/amdgpu prime with lockdep enabled:

DRI_PRIME=1 glxinfo


Acked-by: Christian König 

Thanks for taking care of this,
Christian.



Additionally, some more race conditions exist that I've managed to
trigger with piglit and lockdep enabled after applying these patches:

 =
 WARNING: suspicious RCU usage
 4.14.3Lyude-Test+ #2 Not tainted
 -
 ./include/linux/reservation.h:216 suspicious rcu_dereference_protected() 
usage!

 other info that might help us debug this:

 rcu_scheduler_active = 2, debug_locks = 1
 1 lock held by ext_image_dma_b/27451:
  #0:  (reservation_ww_class_mutex){+.+.}, at: [] 
ttm_bo_unref+0x9f/0x3c0 [ttm]

 stack backtrace:
 CPU: 0 PID: 27451 Comm: ext_image_dma_b Not tainted 4.14.3Lyude-Test+ #2
 Hardware name: HP HP ZBook 15 G4/8275, BIOS P70 Ver. 01.02 06/09/2017
 Call Trace:
  dump_stack+0x8e/0xce
  lockdep_rcu_suspicious+0xc5/0x100
  reservation_object_copy_fences+0x292/0x2b0
  ? ttm_bo_unref+0x9f/0x3c0 [ttm]
  ttm_bo_unref+0xbd/0x3c0 [ttm]
  amdgpu_bo_unref+0x2a/0x50 [amdgpu]
  amdgpu_gem_object_free+0x4b/0x50 [amdgpu]
  drm_gem_object_free+0x1f/0x40 [drm]
  drm_gem_object_put_unlocked+0x40/0xb0 [drm]
  drm_gem_object_handle_put_unlocked+0x6c/0xb0 [drm]
  drm_gem_object_release_handle+0x51/0x90 [drm]
  drm_gem_handle_delete+0x5e/0x90 [drm]
  ? drm_gem_handle_create+0x40/0x40 [drm]
  drm_gem_close_ioctl+0x20/0x30 [drm]
  drm_ioctl_kernel+0x5d/0xb0 [drm]
  drm_ioctl+0x2f7/0x3b0 [drm]
  ? drm_gem_handle_create+0x40/0x40 [drm]
  ? trace_hardirqs_on_caller+0xf4/0x190
  ? trace_hardirqs_on+0xd/0x10
  amdgpu_drm_ioctl+0x4f/0x90 [amdgpu]
  do_vfs_ioctl+0x93/0x670
  ? __fget+0x108/0x1f0
  SyS_ioctl+0x79/0x90
  entry_SYSCALL_64_fastpath+0x23/0xc2

I've also added the relevant fixes for the issue mentioned above.

Christian König (3):
   drm/ttm: fix ttm_bo_cleanup_refs_or_queue once more
   dma-buf: make reservation_object_copy_fences rcu save
   drm/amdgpu: reserve root PD while releasing it

Michel Dänzer (1):
   drm/ttm: Always and only destroy bo->ttm_resv in ttm_bo_release_list

  drivers/dma-buf/reservation.c  | 56 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 13 ++--
  drivers/gpu/drm/ttm/ttm_bo.c   | 43 +-
  3 files changed, 74 insertions(+), 38 deletions(-)

--
2.14.3

___
amd-gfx mailing list
amd-...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx