[PATCH v4 03/34] media: v4l: Add new 10-bit packed grayscale format

2018-07-25 Thread Todor Tomov
The new format will be called V4L2_PIX_FMT_Y10P.
It is similar to the V4L2_PIX_FMT_SBGGR10P family formats
but V4L2_PIX_FMT_Y10P is a grayscale format.

Signed-off-by: Todor Tomov 
---
 Documentation/media/uapi/v4l/pixfmt-y10p.rst | 33 
 Documentation/media/uapi/v4l/yuv-formats.rst |  1 +
 drivers/media/v4l2-core/v4l2-ioctl.c |  1 +
 include/uapi/linux/videodev2.h   |  1 +
 4 files changed, 36 insertions(+)
 create mode 100644 Documentation/media/uapi/v4l/pixfmt-y10p.rst

diff --git a/Documentation/media/uapi/v4l/pixfmt-y10p.rst 
b/Documentation/media/uapi/v4l/pixfmt-y10p.rst
new file mode 100644
index 000..13b5713
--- /dev/null
+++ b/Documentation/media/uapi/v4l/pixfmt-y10p.rst
@@ -0,0 +1,33 @@
+.. -*- coding: utf-8; mode: rst -*-
+
+.. _V4L2-PIX-FMT-Y10P:
+
+**
+V4L2_PIX_FMT_Y10P ('Y10P')
+**
+
+Grey-scale image as a MIPI RAW10 packed array
+
+
+Description
+===
+
+This is a packed grey-scale image format with a depth of 10 bits per
+pixel. Every four consecutive pixels are packed into 5 bytes. Each of
+the first 4 bytes contain the 8 high order bits of the pixels, and
+the 5th byte contains the 2 least significants bits of each pixel,
+in the same order.
+
+**Bit-packed representation.**
+
+.. flat-table::
+:header-rows:  0
+:stub-columns: 0
+:widths: 8 8 8 8 64
+
+* - Y'\ :sub:`00[9:2]`
+  - Y'\ :sub:`01[9:2]`
+  - Y'\ :sub:`02[9:2]`
+  - Y'\ :sub:`03[9:2]`
+  - Y'\ :sub:`03[1:0]`\ (bits 7--6) Y'\ :sub:`02[1:0]`\ (bits 5--4)
+   Y'\ :sub:`01[1:0]`\ (bits 3--2) Y'\ :sub:`00[1:0]`\ (bits 1--0)
diff --git a/Documentation/media/uapi/v4l/yuv-formats.rst 
b/Documentation/media/uapi/v4l/yuv-formats.rst
index 3334ea4..9ab0592 100644
--- a/Documentation/media/uapi/v4l/yuv-formats.rst
+++ b/Documentation/media/uapi/v4l/yuv-formats.rst
@@ -29,6 +29,7 @@ to brightness information.
 pixfmt-y10
 pixfmt-y12
 pixfmt-y10b
+pixfmt-y10p
 pixfmt-y16
 pixfmt-y16-be
 pixfmt-y8i
diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c 
b/drivers/media/v4l2-core/v4l2-ioctl.c
index 04e1231..e8f7c89 100644
--- a/drivers/media/v4l2-core/v4l2-ioctl.c
+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
@@ -1184,6 +1184,7 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)
case V4L2_PIX_FMT_Y16:  descr = "16-bit Greyscale"; break;
case V4L2_PIX_FMT_Y16_BE:   descr = "16-bit Greyscale BE"; break;
case V4L2_PIX_FMT_Y10BPACK: descr = "10-bit Greyscale (Packed)"; 
break;
+   case V4L2_PIX_FMT_Y10P: descr = "10-bit Greyscale (MIPI 
Packed)"; break;
case V4L2_PIX_FMT_Y8I:  descr = "Interleaved 8-bit Greyscale"; 
break;
case V4L2_PIX_FMT_Y12I: descr = "Interleaved 12-bit Greyscale"; 
break;
case V4L2_PIX_FMT_Z16:  descr = "16-bit Depth"; break;
diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
index a15e03b..fc177d8 100644
--- a/include/uapi/linux/videodev2.h
+++ b/include/uapi/linux/videodev2.h
@@ -522,6 +522,7 @@ struct v4l2_pix_format {
 
 /* Grey bit-packed formats */
 #define V4L2_PIX_FMT_Y10BPACKv4l2_fourcc('Y', '1', '0', 'B') /* 10  
Greyscale bit-packed */
+#define V4L2_PIX_FMT_Y10Pv4l2_fourcc('Y', '1', '0', 'P') /* 10  Greyscale, 
MIPI RAW10 packed */
 
 /* Palette formats */
 #define V4L2_PIX_FMT_PAL8v4l2_fourcc('P', 'A', 'L', '8') /*  8  8-bit 
palette */
-- 
2.7.4



[PATCH v4 06/34] media: camss: Fix OF node usage

2018-07-25 Thread Todor Tomov
of_graph_get_next_endpoint increases the refcount of the returned
node and decreases the refcount of the passed node. Take this into
account and use of_node_put properly.

Signed-off-by: Todor Tomov 
---
 drivers/media/platform/qcom/camss/camss.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/qcom/camss/camss.c 
b/drivers/media/platform/qcom/camss/camss.c
index 45285eb..abf6184 100644
--- a/drivers/media/platform/qcom/camss/camss.c
+++ b/drivers/media/platform/qcom/camss/camss.c
@@ -296,6 +296,7 @@ static int camss_of_parse_ports(struct device *dev,
if (of_device_is_available(node))
notifier->num_subdevs++;
 
+   of_node_put(node);
size = sizeof(*notifier->subdevs) * notifier->num_subdevs;
notifier->subdevs = devm_kzalloc(dev, size, GFP_KERNEL);
if (!notifier->subdevs) {
@@ -326,16 +327,16 @@ static int camss_of_parse_ports(struct device *dev,
}
 
remote = of_graph_get_remote_port_parent(node);
-   of_node_put(node);
-
if (!remote) {
dev_err(dev, "Cannot get remote parent\n");
+   of_node_put(node);
return -EINVAL;
}
 
csd->asd.match_type = V4L2_ASYNC_MATCH_FWNODE;
csd->asd.match.fwnode = of_fwnode_handle(remote);
}
+   of_node_put(node);
 
return notifier->num_subdevs;
 }
-- 
2.7.4



[PATCH v4 04/34] media: Rename CAMSS driver path

2018-07-25 Thread Todor Tomov
Support for camera subsystem on QComm MSM8996/APQ8096 is to be added
so remove hardware version from CAMSS driver's path.

Signed-off-by: Todor Tomov 
---
 MAINTAINERS  | 2 +-
 drivers/media/platform/Kconfig   | 2 +-
 drivers/media/platform/Makefile  | 2 +-
 drivers/media/platform/qcom/{camss-8x16 => camss}/Makefile   | 0
 drivers/media/platform/qcom/{camss-8x16 => camss}/camss-csid.c   | 2 +-
 drivers/media/platform/qcom/{camss-8x16 => camss}/camss-csid.h   | 2 +-
 drivers/media/platform/qcom/{camss-8x16 => camss}/camss-csiphy.c | 2 +-
 drivers/media/platform/qcom/{camss-8x16 => camss}/camss-csiphy.h | 2 +-
 drivers/media/platform/qcom/{camss-8x16 => camss}/camss-ispif.c  | 2 +-
 drivers/media/platform/qcom/{camss-8x16 => camss}/camss-ispif.h  | 2 +-
 drivers/media/platform/qcom/{camss-8x16 => camss}/camss-vfe.c| 2 +-
 drivers/media/platform/qcom/{camss-8x16 => camss}/camss-vfe.h| 2 +-
 drivers/media/platform/qcom/{camss-8x16 => camss}/camss-video.c  | 2 +-
 drivers/media/platform/qcom/{camss-8x16 => camss}/camss-video.h  | 2 +-
 drivers/media/platform/qcom/{camss-8x16 => camss}/camss.c| 2 +-
 drivers/media/platform/qcom/{camss-8x16 => camss}/camss.h| 2 +-
 16 files changed, 15 insertions(+), 15 deletions(-)
 rename drivers/media/platform/qcom/{camss-8x16 => camss}/Makefile (100%)
 rename drivers/media/platform/qcom/{camss-8x16 => camss}/camss-csid.c (99%)
 rename drivers/media/platform/qcom/{camss-8x16 => camss}/camss-csid.h (98%)
 rename drivers/media/platform/qcom/{camss-8x16 => camss}/camss-csiphy.c (99%)
 rename drivers/media/platform/qcom/{camss-8x16 => camss}/camss-csiphy.h (97%)
 rename drivers/media/platform/qcom/{camss-8x16 => camss}/camss-ispif.c (99%)
 rename drivers/media/platform/qcom/{camss-8x16 => camss}/camss-ispif.h (98%)
 rename drivers/media/platform/qcom/{camss-8x16 => camss}/camss-vfe.c (99%)
 rename drivers/media/platform/qcom/{camss-8x16 => camss}/camss-vfe.h (98%)
 rename drivers/media/platform/qcom/{camss-8x16 => camss}/camss-video.c (99%)
 rename drivers/media/platform/qcom/{camss-8x16 => camss}/camss-video.h (98%)
 rename drivers/media/platform/qcom/{camss-8x16 => camss}/camss.c (99%)
 rename drivers/media/platform/qcom/{camss-8x16 => camss}/camss.h (98%)

diff --git a/MAINTAINERS b/MAINTAINERS
index 329d428..f8b3a1b 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -11918,7 +11918,7 @@ L:  linux-media@vger.kernel.org
 S: Maintained
 F: Documentation/devicetree/bindings/media/qcom,camss.txt
 F: Documentation/media/v4l-drivers/qcom_camss.rst
-F: drivers/media/platform/qcom/camss-8x16/
+F: drivers/media/platform/qcom/camss/
 
 QUALCOMM CPUFREQ DRIVER MSM8996/APQ8096
 M:  Ilia Lin 
diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig
index 1cf4011..2bb88d3 100644
--- a/drivers/media/platform/Kconfig
+++ b/drivers/media/platform/Kconfig
@@ -90,7 +90,7 @@ config VIDEO_PXA27x
  This is a v4l2 driver for the PXA27x Quick Capture Interface
 
 config VIDEO_QCOM_CAMSS
-   tristate "Qualcomm 8x16 V4L2 Camera Subsystem driver"
+   tristate "Qualcomm V4L2 Camera Subsystem driver"
depends on VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API
depends on (ARCH_QCOM && IOMMU_DMA) || COMPILE_TEST
select VIDEOBUF2_DMA_SG
diff --git a/drivers/media/platform/Makefile b/drivers/media/platform/Makefile
index 890f919..fac3a89 100644
--- a/drivers/media/platform/Makefile
+++ b/drivers/media/platform/Makefile
@@ -88,7 +88,7 @@ obj-$(CONFIG_VIDEO_MEDIATEK_MDP)  += mtk-mdp/
 
 obj-$(CONFIG_VIDEO_MEDIATEK_JPEG)  += mtk-jpeg/
 
-obj-$(CONFIG_VIDEO_QCOM_CAMSS) += qcom/camss-8x16/
+obj-$(CONFIG_VIDEO_QCOM_CAMSS) += qcom/camss/
 
 obj-$(CONFIG_VIDEO_QCOM_VENUS) += qcom/venus/
 
diff --git a/drivers/media/platform/qcom/camss-8x16/Makefile 
b/drivers/media/platform/qcom/camss/Makefile
similarity index 100%
rename from drivers/media/platform/qcom/camss-8x16/Makefile
rename to drivers/media/platform/qcom/camss/Makefile
diff --git a/drivers/media/platform/qcom/camss-8x16/camss-csid.c 
b/drivers/media/platform/qcom/camss/camss-csid.c
similarity index 99%
rename from drivers/media/platform/qcom/camss-8x16/camss-csid.c
rename to drivers/media/platform/qcom/camss/camss-csid.c
index 226f36e..39ea27b 100644
--- a/drivers/media/platform/qcom/camss-8x16/camss-csid.c
+++ b/drivers/media/platform/qcom/camss/camss-csid.c
@@ -4,7 +4,7 @@
  * Qualcomm MSM Camera Subsystem - CSID (CSI Decoder) Module
  *
  * Copyright (c) 2011-2015, The Linux Foundation. All rights reserved.
- * Copyright (C) 2015-2017 Linaro Ltd.
+ * Copyright (C) 2015-2018 Linaro Ltd.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Publi

[PATCH v4 09/34] media: camss: Unify the clock names

2018-07-25 Thread Todor Tomov
Use more logical clock names - similar to the names in documentation.
This will allow better handling of the clocks in the driver when support
for more hardware versions is added - equivalent clocks on different
hardware versions will have the same name.

Signed-off-by: Todor Tomov 
---
 drivers/media/platform/qcom/camss/camss.c | 20 
 1 file changed, 8 insertions(+), 12 deletions(-)

diff --git a/drivers/media/platform/qcom/camss/camss.c 
b/drivers/media/platform/qcom/camss/camss.c
index abf6184..0b663e0 100644
--- a/drivers/media/platform/qcom/camss/camss.c
+++ b/drivers/media/platform/qcom/camss/camss.c
@@ -32,8 +32,7 @@ static const struct resources csiphy_res[] = {
/* CSIPHY0 */
{
.regulator = { NULL },
-   .clock = { "camss_top_ahb", "ispif_ahb",
-  "camss_ahb", "csiphy0_timer" },
+   .clock = { "top_ahb", "ispif_ahb", "ahb", "csiphy0_timer" },
.clock_rate = { { 0 },
{ 0 },
{ 0 },
@@ -45,8 +44,7 @@ static const struct resources csiphy_res[] = {
/* CSIPHY1 */
{
.regulator = { NULL },
-   .clock = { "camss_top_ahb", "ispif_ahb",
-  "camss_ahb", "csiphy1_timer" },
+   .clock = { "top_ahb", "ispif_ahb", "ahb", "csiphy1_timer" },
.clock_rate = { { 0 },
{ 0 },
{ 0 },
@@ -60,8 +58,7 @@ static const struct resources csid_res[] = {
/* CSID0 */
{
.regulator = { "vdda" },
-   .clock = { "camss_top_ahb", "ispif_ahb",
-  "csi0_ahb", "camss_ahb",
+   .clock = { "top_ahb", "ispif_ahb", "csi0_ahb", "ahb",
   "csi0", "csi0_phy", "csi0_pix", "csi0_rdi" },
.clock_rate = { { 0 },
{ 0 },
@@ -78,8 +75,7 @@ static const struct resources csid_res[] = {
/* CSID1 */
{
.regulator = { "vdda" },
-   .clock = { "camss_top_ahb", "ispif_ahb",
-  "csi1_ahb", "camss_ahb",
+   .clock = { "top_ahb", "ispif_ahb", "csi1_ahb", "ahb",
   "csi1", "csi1_phy", "csi1_pix", "csi1_rdi" },
.clock_rate = { { 0 },
{ 0 },
@@ -96,10 +92,10 @@ static const struct resources csid_res[] = {
 
 static const struct resources_ispif ispif_res = {
/* ISPIF */
-   .clock = { "camss_top_ahb", "camss_ahb", "ispif_ahb",
+   .clock = { "top_ahb", "ahb", "ispif_ahb",
   "csi0", "csi0_pix", "csi0_rdi",
   "csi1", "csi1_pix", "csi1_rdi" },
-   .clock_for_reset = { "camss_vfe_vfe", "camss_csi_vfe" },
+   .clock_for_reset = { "vfe0", "csi_vfe0" },
.reg = { "ispif", "csi_clk_mux" },
.interrupt = "ispif"
 
@@ -108,8 +104,8 @@ static const struct resources_ispif ispif_res = {
 static const struct resources vfe_res = {
/* VFE0 */
.regulator = { NULL },
-   .clock = { "camss_top_ahb", "camss_vfe_vfe", "camss_csi_vfe",
-  "iface", "bus", "camss_ahb" },
+   .clock = { "top_ahb", "vfe0", "csi_vfe0",
+  "vfe_ahb", "vfe_axi", "ahb" },
.clock_rate = { { 0 },
{ 5000, 8000, 1, 16000,
  17778, 2, 26667, 32000,
-- 
2.7.4



[PATCH v4 07/34] media: camss: csiphy: Ensure clock mux config is done before the rest

2018-07-25 Thread Todor Tomov
Add a write memory barier after clock mux config and before the rest
of the csiphy config.

Signed-off-by: Todor Tomov 
---
 drivers/media/platform/qcom/camss/camss-csiphy.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/media/platform/qcom/camss/camss-csiphy.c 
b/drivers/media/platform/qcom/camss/camss-csiphy.c
index b37e691..2a9adcd 100644
--- a/drivers/media/platform/qcom/camss/camss-csiphy.c
+++ b/drivers/media/platform/qcom/camss/camss-csiphy.c
@@ -364,6 +364,7 @@ static int csiphy_stream_on(struct csiphy_device *csiphy)
val |= cfg->csid_id;
}
writel_relaxed(val, csiphy->base_clk_mux);
+   wmb();
 
writel_relaxed(0x1, csiphy->base +
   CAMSS_CSI_PHY_GLBL_T_INIT_CFG0);
-- 
2.7.4



[PATCH v4 10/34] media: camss: csiphy: Update settle count calculation

2018-07-25 Thread Todor Tomov
Update settle count calculation as per specification.

Signed-off-by: Todor Tomov 
---
 drivers/media/platform/qcom/camss/camss-csiphy.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/platform/qcom/camss/camss-csiphy.c 
b/drivers/media/platform/qcom/camss/camss-csiphy.c
index 2a9adcd..6158ffd 100644
--- a/drivers/media/platform/qcom/camss/camss-csiphy.c
+++ b/drivers/media/platform/qcom/camss/camss-csiphy.c
@@ -329,7 +329,7 @@ static u8 csiphy_settle_cnt_calc(struct csiphy_device 
*csiphy)
t_hs_settle = (t_hs_prepare_max + t_hs_prepare_zero_min) / 2;
 
timer_period = div_u64(1LL, csiphy->timer_clk_rate);
-   settle_cnt = t_hs_settle / timer_period;
+   settle_cnt = t_hs_settle / timer_period - 1;
 
return settle_cnt;
 }
-- 
2.7.4



[PATCH v4 05/34] media: camss: Use SPDX license headers

2018-07-25 Thread Todor Tomov
Use SPDX license headers for all files of the Qualcomm CAMSS driver.

Signed-off-by: Todor Tomov 
---
 drivers/media/platform/qcom/camss/camss-csid.c   | 10 +-
 drivers/media/platform/qcom/camss/camss-csid.h   | 10 +-
 drivers/media/platform/qcom/camss/camss-csiphy.c | 10 +-
 drivers/media/platform/qcom/camss/camss-csiphy.h | 10 +-
 drivers/media/platform/qcom/camss/camss-ispif.c  | 10 +-
 drivers/media/platform/qcom/camss/camss-ispif.h  | 10 +-
 drivers/media/platform/qcom/camss/camss-vfe.c| 10 +-
 drivers/media/platform/qcom/camss/camss-vfe.h| 10 +-
 drivers/media/platform/qcom/camss/camss-video.c  | 10 +-
 drivers/media/platform/qcom/camss/camss-video.h  | 10 +-
 drivers/media/platform/qcom/camss/camss.c| 10 +-
 drivers/media/platform/qcom/camss/camss.h| 10 +-
 12 files changed, 12 insertions(+), 108 deletions(-)

diff --git a/drivers/media/platform/qcom/camss/camss-csid.c 
b/drivers/media/platform/qcom/camss/camss-csid.c
index 39ea27b..c0fef17 100644
--- a/drivers/media/platform/qcom/camss/camss-csid.c
+++ b/drivers/media/platform/qcom/camss/camss-csid.c
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0
 /*
  * camss-csid.c
  *
@@ -5,15 +6,6 @@
  *
  * Copyright (c) 2011-2015, The Linux Foundation. All rights reserved.
  * Copyright (C) 2015-2018 Linaro Ltd.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 and
- * only 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 
diff --git a/drivers/media/platform/qcom/camss/camss-csid.h 
b/drivers/media/platform/qcom/camss/camss-csid.h
index 801..ae1d045 100644
--- a/drivers/media/platform/qcom/camss/camss-csid.h
+++ b/drivers/media/platform/qcom/camss/camss-csid.h
@@ -1,3 +1,4 @@
+/* SPDX-License-Identifier: GPL-2.0 */
 /*
  * camss-csid.h
  *
@@ -5,15 +6,6 @@
  *
  * Copyright (c) 2011-2014, The Linux Foundation. All rights reserved.
  * Copyright (C) 2015-2018 Linaro Ltd.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 and
- * only 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 QC_MSM_CAMSS_CSID_H
 #define QC_MSM_CAMSS_CSID_H
diff --git a/drivers/media/platform/qcom/camss/camss-csiphy.c 
b/drivers/media/platform/qcom/camss/camss-csiphy.c
index 642de25..b37e691 100644
--- a/drivers/media/platform/qcom/camss/camss-csiphy.c
+++ b/drivers/media/platform/qcom/camss/camss-csiphy.c
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0
 /*
  * camss-csiphy.c
  *
@@ -5,15 +6,6 @@
  *
  * Copyright (c) 2011-2015, The Linux Foundation. All rights reserved.
  * Copyright (C) 2016-2018 Linaro Ltd.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 and
- * only 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 
diff --git a/drivers/media/platform/qcom/camss/camss-csiphy.h 
b/drivers/media/platform/qcom/camss/camss-csiphy.h
index 9a42209..76fa239 100644
--- a/drivers/media/platform/qcom/camss/camss-csiphy.h
+++ b/drivers/media/platform/qcom/camss/camss-csiphy.h
@@ -1,3 +1,4 @@
+/* SPDX-License-Identifier: GPL-2.0 */
 /*
  * camss-csiphy.h
  *
@@ -5,15 +6,6 @@
  *
  * Copyright (c) 2011-2015, The Linux Foundation. All rights reserved.
  * Copyright (C) 2016-2018 Linaro Ltd.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 and
- * only 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 QC_MSM_CAMSS_CSIPHY_H
 #define QC_MSM_CAMSS_CSIPHY_H
diff --git a/drivers/media/platform/qcom/camss/camss-ispif.c 
b/drivers/media/platform/qcom/camss/camss-ispif.c
index 636d5e7..5ad719d 100644

[PATCH v4 08/34] media: dt-bindings: media: qcom,camss: Unify the clock names

2018-07-25 Thread Todor Tomov
Use more logical clock names - similar to the names in documentation.
This will allow better handling of the clocks in the driver when support
for more hardware versions is added - equivalent clocks on different
hardware versions will have the same name.

CC: Rob Herring 
CC: Mark Rutland 
CC: devicet...@vger.kernel.org
Signed-off-by: Todor Tomov 
---
 .../devicetree/bindings/media/qcom,camss.txt   | 24 +++---
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/Documentation/devicetree/bindings/media/qcom,camss.txt 
b/Documentation/devicetree/bindings/media/qcom,camss.txt
index cadeceb..032e8ed 100644
--- a/Documentation/devicetree/bindings/media/qcom,camss.txt
+++ b/Documentation/devicetree/bindings/media/qcom,camss.txt
@@ -53,7 +53,7 @@ Qualcomm Camera Subsystem
Usage: required
Value type: 
Definition: Should contain the following entries:
-- "camss_top_ahb"
+- "top_ahb"
 - "ispif_ahb"
 - "csiphy0_timer"
 - "csiphy1_timer"
@@ -67,11 +67,11 @@ Qualcomm Camera Subsystem
 - "csi1_phy"
 - "csi1_pix"
 - "csi1_rdi"
-- "camss_ahb"
-- "camss_vfe_vfe"
-- "camss_csi_vfe"
-- "iface"
-- "bus"
+- "ahb"
+- "vfe0"
+- "csi_vfe0"
+- "vfe_ahb"
+- "vfe_axi"
 - vdda-supply:
Usage: required
Value type: 
@@ -161,7 +161,7 @@ Qualcomm Camera Subsystem
< GCC_CAMSS_CSI_VFE0_CLK>,
< GCC_CAMSS_VFE_AHB_CLK>,
< GCC_CAMSS_VFE_AXI_CLK>;
-clock-names = "camss_top_ahb",
+clock-names = "top_ahb",
 "ispif_ahb",
 "csiphy0_timer",
 "csiphy1_timer",
@@ -175,11 +175,11 @@ Qualcomm Camera Subsystem
 "csi1_phy",
 "csi1_pix",
 "csi1_rdi",
-"camss_ahb",
-"camss_vfe_vfe",
-"camss_csi_vfe",
-"iface",
-"bus";
+"ahb",
+"vfe0",
+"csi_vfe0",
+"vfe_ahb",
+"vfe_axi";
vdda-supply = <_l2>;
iommus = <_iommu 3>;
ports {
-- 
2.7.4



[PATCH v4 14/34] media: camss: vfe: Do not disable CAMIF when clearing its status

2018-07-25 Thread Todor Tomov
Use "no change" value when clearing CAMIF status and make sure
this is done before configuring the new command.

Signed-off-by: Todor Tomov 
---
 drivers/media/platform/qcom/camss/camss-vfe.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/qcom/camss/camss-vfe.c 
b/drivers/media/platform/qcom/camss/camss-vfe.c
index 77167f1..15a1a01 100644
--- a/drivers/media/platform/qcom/camss/camss-vfe.c
+++ b/drivers/media/platform/qcom/camss/camss-vfe.c
@@ -156,6 +156,7 @@
 #define VFE_0_CAMIF_CMD0x2f4
 #define VFE_0_CAMIF_CMD_DISABLE_FRAME_BOUNDARY 0
 #define VFE_0_CAMIF_CMD_ENABLE_FRAME_BOUNDARY  1
+#define VFE_0_CAMIF_CMD_NO_CHANGE  3
 #define VFE_0_CAMIF_CMD_CLEAR_CAMIF_STATUS (1 << 2)
 #define VFE_0_CAMIF_CFG0x2f8
 #define VFE_0_CAMIF_CFG_VFE_OUTPUT_EN  (1 << 6)
@@ -1021,8 +1022,10 @@ static void vfe_set_camif_cfg(struct vfe_device *vfe, 
struct vfe_line *line)
 
 static void vfe_set_camif_cmd(struct vfe_device *vfe, u32 cmd)
 {
-   writel_relaxed(VFE_0_CAMIF_CMD_CLEAR_CAMIF_STATUS,
+   writel_relaxed(VFE_0_CAMIF_CMD_CLEAR_CAMIF_STATUS |
+  VFE_0_CAMIF_CMD_NO_CHANGE,
   vfe->base + VFE_0_CAMIF_CMD);
+   wmb();
 
writel_relaxed(cmd, vfe->base + VFE_0_CAMIF_CMD);
 }
-- 
2.7.4



[PATCH v4 12/34] media: camss: vfe: Fix to_vfe() macro member name

2018-07-25 Thread Todor Tomov
Use the member name which is "line" instead of the pointer argument.

Signed-off-by: Todor Tomov 
---
 drivers/media/platform/qcom/camss/camss-vfe.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/platform/qcom/camss/camss-vfe.c 
b/drivers/media/platform/qcom/camss/camss-vfe.c
index 256dc2d..51ad3f8 100644
--- a/drivers/media/platform/qcom/camss/camss-vfe.c
+++ b/drivers/media/platform/qcom/camss/camss-vfe.c
@@ -30,7 +30,7 @@
((const struct vfe_line (*)[]) &(ptr_line[-(ptr_line->id)]))
 
 #define to_vfe(ptr_line)   \
-   container_of(vfe_line_array(ptr_line), struct vfe_device, ptr_line)
+   container_of(vfe_line_array(ptr_line), struct vfe_device, line)
 
 #define VFE_0_HW_VERSION   0x000
 
-- 
2.7.4



[PATCH v4 16/34] media: dt-bindings: media: qcom,camss: Add 8996 bindings

2018-07-25 Thread Todor Tomov
Update binding document for MSM8996.

CC: Rob Herring 
CC: Mark Rutland 
CC: devicet...@vger.kernel.org
Signed-off-by: Todor Tomov 
Reviewed-by: Rob Herring 
---
 .../devicetree/bindings/media/qcom,camss.txt   | 44 +++---
 1 file changed, 38 insertions(+), 6 deletions(-)

diff --git a/Documentation/devicetree/bindings/media/qcom,camss.txt 
b/Documentation/devicetree/bindings/media/qcom,camss.txt
index e938eb0..09eb6ed 100644
--- a/Documentation/devicetree/bindings/media/qcom,camss.txt
+++ b/Documentation/devicetree/bindings/media/qcom,camss.txt
@@ -5,8 +5,9 @@ Qualcomm Camera Subsystem
 - compatible:
Usage: required
Value type: 
-   Definition: Should contain:
+   Definition: Should contain one of:
- "qcom,msm8916-camss"
+   - "qcom,msm8996-camss"
 - reg:
Usage: required
Value type: 
@@ -19,11 +20,16 @@ Qualcomm Camera Subsystem
- "csiphy0_clk_mux"
- "csiphy1"
- "csiphy1_clk_mux"
+   - "csiphy2" (8996 only)
+   - "csiphy2_clk_mux" (8996 only)
- "csid0"
- "csid1"
+   - "csid2"   (8996 only)
+   - "csid3"   (8996 only)
- "ispif"
- "csi_clk_mux"
- "vfe0"
+   - "vfe1"(8996 only)
 - interrupts:
Usage: required
Value type: 
@@ -34,10 +40,14 @@ Qualcomm Camera Subsystem
Definition: Should contain the following entries:
- "csiphy0"
- "csiphy1"
+   - "csiphy2" (8996 only)
- "csid0"
- "csid1"
+   - "csid2"   (8996 only)
+   - "csid3"   (8996 only)
- "ispif"
- "vfe0"
+   - "vfe1"(8996 only)
 - power-domains:
Usage: required
Value type: 
@@ -57,6 +67,7 @@ Qualcomm Camera Subsystem
- "ispif_ahb"
- "csiphy0_timer"
- "csiphy1_timer"
+   - "csiphy2_timer"   (8996 only)
- "csi0_ahb"
- "csi0"
- "csi0_phy"
@@ -67,9 +78,25 @@ Qualcomm Camera Subsystem
- "csi1_phy"
- "csi1_pix"
- "csi1_rdi"
+   - "csi2_ahb"(8996 only)
+   - "csi2"(8996 only)
+   - "csi2_phy"(8996 only)
+   - "csi2_pix"(8996 only)
+   - "csi2_rdi"(8996 only)
+   - "csi3_ahb"(8996 only)
+   - "csi3"(8996 only)
+   - "csi3_phy"(8996 only)
+   - "csi3_pix"(8996 only)
+   - "csi3_rdi"(8996 only)
- "ahb"
- "vfe0"
- "csi_vfe0"
+   - "vfe0_ahb",   (8996 only)
+   - "vfe0_stream",(8996 only)
+   - "vfe1",   (8996 only)
+   - "csi_vfe1",   (8996 only)
+   - "vfe1_ahb",   (8996 only)
+   - "vfe1_stream",(8996 only)
- "vfe_ahb"
- "vfe_axi"
 - vdda-supply:
@@ -90,14 +117,18 @@ Qualcomm Camera Subsystem
- reg:
Usage: required
Value type: 
-   Definition: Selects CSI2 PHY interface - PHY0 or PHY1.
+   Definition: Selects CSI2 PHY interface - PHY0, PHY1
+   or PHY2 (8996 only)
Endpoint node properties:
- clock-lanes:
Usage: required
Value type: 
-   Definition: The physical clock lane index. The value
-   must always be <1> as the physical clock
-   lane is lane 1.
+   Definition: The physical clock lane index. On 8916
+   the value must always be <1> as the physical
+   clock lane is lane 1. On 8996 the value must
+   always be <7> a

[PATCH v4 11/34] media: camss: csid: Configure data type and decode format properly

2018-07-25 Thread Todor Tomov
The CSID decodes the input data stream. When the input comes from
the Test Generator the format of the stream is set on the source
media pad. When the input comes from the CSIPHY the format is the
one on the sink media pad. Use the proper format for each case.

Signed-off-by: Todor Tomov 
---
 drivers/media/platform/qcom/camss/camss-csid.c | 16 +++-
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/drivers/media/platform/qcom/camss/camss-csid.c 
b/drivers/media/platform/qcom/camss/camss-csid.c
index c0fef17..3cde07e 100644
--- a/drivers/media/platform/qcom/camss/camss-csid.c
+++ b/drivers/media/platform/qcom/camss/camss-csid.c
@@ -384,9 +384,6 @@ static int csid_set_stream(struct v4l2_subdev *sd, int 
enable)
!media_entity_remote_pad(>pads[MSM_CSID_PAD_SINK]))
return -ENOLINK;
 
-   dt = csid_get_fmt_entry(csid->fmt[MSM_CSID_PAD_SRC].code)->
-   data_type;
-
if (tg->enabled) {
/* Config Test Generator */
struct v4l2_mbus_framefmt *f =
@@ -408,6 +405,9 @@ static int csid_set_stream(struct v4l2_subdev *sd, int 
enable)
writel_relaxed(val, csid->base +
   CAMSS_CSID_TG_DT_n_CGG_0(0));
 
+   dt = csid_get_fmt_entry(
+   csid->fmt[MSM_CSID_PAD_SRC].code)->data_type;
+
/* 5:0 data type */
val = dt;
writel_relaxed(val, csid->base +
@@ -417,6 +417,9 @@ static int csid_set_stream(struct v4l2_subdev *sd, int 
enable)
val = tg->payload_mode;
writel_relaxed(val, csid->base +
   CAMSS_CSID_TG_DT_n_CGG_2(0));
+
+   df = csid_get_fmt_entry(
+   
csid->fmt[MSM_CSID_PAD_SRC].code)->decode_format;
} else {
struct csid_phy_config *phy = >phy;
 
@@ -431,13 +434,16 @@ static int csid_set_stream(struct v4l2_subdev *sd, int 
enable)
 
writel_relaxed(val,
   csid->base + CAMSS_CSID_CORE_CTRL_1);
+
+   dt = csid_get_fmt_entry(
+   csid->fmt[MSM_CSID_PAD_SINK].code)->data_type;
+   df = csid_get_fmt_entry(
+   
csid->fmt[MSM_CSID_PAD_SINK].code)->decode_format;
}
 
/* Config LUT */
 
dt_shift = (cid % 4) * 8;
-   df = csid_get_fmt_entry(csid->fmt[MSM_CSID_PAD_SINK].code)->
-   decode_format;
 
val = readl_relaxed(csid->base + CAMSS_CSID_CID_LUT_VC_n(vc));
val &= ~(0xff << dt_shift);
-- 
2.7.4



[PATCH v4 00/34] Qualcomm Camera Subsystem driver - 8x96 support

2018-07-25 Thread Todor Tomov
 to interface /dev/v4l-subdev12)
Link: 0x02000101 (msm_vfe0_rdi2 to interface /dev/v4l-subdev13)
Link: 0x02000103 (msm_vfe0_pix to interface /dev/v4l-subdev14)
Link: 0x02000105 (msm_vfe1_rdi0 to interface /dev/v4l-subdev15)
Link: 0x02000107 (msm_vfe1_rdi1 to interface /dev/v4l-subdev16)
Link: 0x02000109 (msm_vfe1_rdi2 to interface /dev/v4l-subdev17)
Link: 0x0200010b (msm_vfe1_pix to interface /dev/v4l-subdev18)
Link: 0x0200010d (ov5645 3-0039 to interface /dev/v4l-subdev19)
test MEDIA_IOC_G_TOPOLOGY: OK
Entities: 28 Interfaces: 28 Pads: 47 Links: 97
Entity: 0x0001 (Name: 'msm_csiphy0', Type: V4L2 I/O, 
DevPath: /dev/v4l-subdev0)
Entity: 0x0004 (Name: 'msm_csiphy1', Type: V4L2 I/O, 
DevPath: /dev/v4l-subdev1)
Entity: 0x0007 (Name: 'msm_csiphy2', Type: V4L2 I/O, 
DevPath: /dev/v4l-subdev2)
Entity: 0x000a (Name: 'msm_csid0', Type: V4L2 I/O, DevPath: 
/dev/v4l-subdev3)
Entity: 0x000d (Name: 'msm_csid1', Type: V4L2 I/O, DevPath: 
/dev/v4l-subdev4)
Entity: 0x0010 (Name: 'msm_csid2', Type: V4L2 I/O, DevPath: 
/dev/v4l-subdev5)
Entity: 0x0013 (Name: 'msm_csid3', Type: V4L2 I/O, DevPath: 
/dev/v4l-subdev6)
Entity: 0x0016 (Name: 'msm_ispif0', Type: V4L2 I/O, 
DevPath: /dev/v4l-subdev7)
Entity: 0x0019 (Name: 'msm_ispif1', Type: V4L2 I/O, 
DevPath: /dev/v4l-subdev8)
Entity: 0x001c (Name: 'msm_ispif2', Type: V4L2 I/O, 
DevPath: /dev/v4l-subdev9)
Entity: 0x001f (Name: 'msm_ispif3', Type: V4L2 I/O, 
DevPath: /dev/v4l-subdev10)
Entity: 0x0022 (Name: 'msm_vfe0_rdi0', Type: Unknown V4L2 
Sub-Device, DevPath: /dev/v4l-subdev11)
Entity: 0x0025 (Name: 'msm_vfe0_video0', Type: V4L2 I/O, 
DevPath: /dev/video0)
Entity: 0x002b (Name: 'msm_vfe0_rdi1', Type: Unknown V4L2 
Sub-Device, DevPath: /dev/v4l-subdev12)
Entity: 0x002e (Name: 'msm_vfe0_video1', Type: V4L2 I/O, 
DevPath: /dev/video1)
Entity: 0x0034 (Name: 'msm_vfe0_rdi2', Type: Unknown V4L2 
Sub-Device, DevPath: /dev/v4l-subdev13)
Entity: 0x0037 (Name: 'msm_vfe0_video2', Type: V4L2 I/O, 
DevPath: /dev/video2)
Entity: 0x003d (Name: 'msm_vfe0_pix', Type: Unknown V4L2 
Sub-Device, DevPath: /dev/v4l-subdev14)
Entity: 0x0040 (Name: 'msm_vfe0_video3', Type: V4L2 I/O, 
DevPath: /dev/video3)
Entity: 0x0046 (Name: 'msm_vfe1_rdi0', Type: Unknown V4L2 
Sub-Device, DevPath: /dev/v4l-subdev15)
Entity: 0x0049 (Name: 'msm_vfe1_video0', Type: V4L2 I/O, 
DevPath: /dev/video4)
Entity: 0x004f (Name: 'msm_vfe1_rdi1', Type: Unknown V4L2 
Sub-Device, DevPath: /dev/v4l-subdev16)
Entity: 0x0052 (Name: 'msm_vfe1_video1', Type: V4L2 I/O, 
DevPath: /dev/video5)
Entity: 0x0058 (Name: 'msm_vfe1_rdi2', Type: Unknown V4L2 
Sub-Device, DevPath: /dev/v4l-subdev17)
Entity: 0x005b (Name: 'msm_vfe1_video2', Type: V4L2 I/O, 
DevPath: /dev/video6)
Entity: 0x0061 (Name: 'msm_vfe1_pix', Type: Unknown V4L2 
Sub-Device, DevPath: /dev/v4l-subdev18)
Entity: 0x0064 (Name: 'msm_vfe1_video3', Type: V4L2 I/O, 
DevPath: /dev/video7)
Entity: 0x00e2 (Name: 'ov5645 3-0039', Type: Camera Sensor, 
DevPath: /dev/v4l-subdev19)
test MEDIA_IOC_ENUM_ENTITIES/LINKS: OK
test MEDIA_IOC_SETUP_LINK: OK

Total: 7, Succeeded: 7, Failed: 0, Warnings: 0



Sakari Ailus (1):
  doc-rst: Add packed Bayer raw14 pixel formats

Todor Tomov (33):
  media: v4l: Add new 2X8 10-bit grayscale media bus code
  media: v4l: Add new 10-bit packed grayscale format
  media: Rename CAMSS driver path
  media: camss: Use SPDX license headers
  media: camss: Fix OF node usage
  media: camss: csiphy: Ensure clock mux config is done before the rest
  media: dt-bindings: media: qcom,camss: Unify the clock names
  media: camss: Unify the clock names
  media: camss: csiphy: Update settle count calculation
  media: camss: csid: Configure data type and decode format properly
  media: camss: vfe: Fix to_vfe() macro member name
  media: camss: vfe: Get line pointer as container of video_out
  media: camss: vfe: Do not disable CAMIF when clearing its status
  media: dt-bindings: media: qcom,camss: Fix whitespaces
  media: dt-bindings: media: qcom,camss: Add 8996 bindings
  media: camss: Add 8x96 resources
  media: camss: Add basic runtime PM support
  media: camss: csiphy: Split to hardware dependent and independent
parts
  media: camss: csiphy: Unify lane handling
  media: camss: csiphy: Add support for 8x96
  media

[PATCH v4 23/34] media: camss: ispif: Add support for 8x96

2018-07-25 Thread Todor Tomov
ISPIF hardware modules on 8x16 and 8x96 are similar. However on
8x96 the ISPIF routes data to two VFE hardware modules. Add
separate interrupt handler for 8x96 to handle the additional
interrupts.

Signed-off-by: Todor Tomov 
---
 drivers/media/platform/qcom/camss/camss-ispif.c | 76 -
 1 file changed, 73 insertions(+), 3 deletions(-)

diff --git a/drivers/media/platform/qcom/camss/camss-ispif.c 
b/drivers/media/platform/qcom/camss/camss-ispif.c
index 2c6c0d2..ae80732 100644
--- a/drivers/media/platform/qcom/camss/camss-ispif.c
+++ b/drivers/media/platform/qcom/camss/camss-ispif.c
@@ -116,13 +116,77 @@ static const u32 ispif_formats[] = {
 };
 
 /*
- * ispif_isr - ISPIF module interrupt handler
+ * ispif_isr_8x96 - ISPIF module interrupt handler for 8x96
  * @irq: Interrupt line
  * @dev: ISPIF device
  *
  * Return IRQ_HANDLED on success
  */
-static irqreturn_t ispif_isr(int irq, void *dev)
+static irqreturn_t ispif_isr_8x96(int irq, void *dev)
+{
+   struct ispif_device *ispif = dev;
+   u32 value0, value1, value2, value3, value4, value5;
+
+   value0 = readl_relaxed(ispif->base + ISPIF_VFE_m_IRQ_STATUS_0(0));
+   value1 = readl_relaxed(ispif->base + ISPIF_VFE_m_IRQ_STATUS_1(0));
+   value2 = readl_relaxed(ispif->base + ISPIF_VFE_m_IRQ_STATUS_2(0));
+   value3 = readl_relaxed(ispif->base + ISPIF_VFE_m_IRQ_STATUS_0(1));
+   value4 = readl_relaxed(ispif->base + ISPIF_VFE_m_IRQ_STATUS_1(1));
+   value5 = readl_relaxed(ispif->base + ISPIF_VFE_m_IRQ_STATUS_2(1));
+
+   writel_relaxed(value0, ispif->base + ISPIF_VFE_m_IRQ_CLEAR_0(0));
+   writel_relaxed(value1, ispif->base + ISPIF_VFE_m_IRQ_CLEAR_1(0));
+   writel_relaxed(value2, ispif->base + ISPIF_VFE_m_IRQ_CLEAR_2(0));
+   writel_relaxed(value3, ispif->base + ISPIF_VFE_m_IRQ_CLEAR_0(1));
+   writel_relaxed(value4, ispif->base + ISPIF_VFE_m_IRQ_CLEAR_1(1));
+   writel_relaxed(value5, ispif->base + ISPIF_VFE_m_IRQ_CLEAR_2(1));
+
+   writel(0x1, ispif->base + ISPIF_IRQ_GLOBAL_CLEAR_CMD);
+
+   if ((value0 >> 27) & 0x1)
+   complete(>reset_complete);
+
+   if (unlikely(value0 & ISPIF_VFE_m_IRQ_STATUS_0_PIX0_OVERFLOW))
+   dev_err_ratelimited(to_device(ispif), "VFE0 pix0 overflow\n");
+
+   if (unlikely(value0 & ISPIF_VFE_m_IRQ_STATUS_0_RDI0_OVERFLOW))
+   dev_err_ratelimited(to_device(ispif), "VFE0 rdi0 overflow\n");
+
+   if (unlikely(value1 & ISPIF_VFE_m_IRQ_STATUS_1_PIX1_OVERFLOW))
+   dev_err_ratelimited(to_device(ispif), "VFE0 pix1 overflow\n");
+
+   if (unlikely(value1 & ISPIF_VFE_m_IRQ_STATUS_1_RDI1_OVERFLOW))
+   dev_err_ratelimited(to_device(ispif), "VFE0 rdi1 overflow\n");
+
+   if (unlikely(value2 & ISPIF_VFE_m_IRQ_STATUS_2_RDI2_OVERFLOW))
+   dev_err_ratelimited(to_device(ispif), "VFE0 rdi2 overflow\n");
+
+   if (unlikely(value3 & ISPIF_VFE_m_IRQ_STATUS_0_PIX0_OVERFLOW))
+   dev_err_ratelimited(to_device(ispif), "VFE1 pix0 overflow\n");
+
+   if (unlikely(value3 & ISPIF_VFE_m_IRQ_STATUS_0_RDI0_OVERFLOW))
+   dev_err_ratelimited(to_device(ispif), "VFE1 rdi0 overflow\n");
+
+   if (unlikely(value4 & ISPIF_VFE_m_IRQ_STATUS_1_PIX1_OVERFLOW))
+   dev_err_ratelimited(to_device(ispif), "VFE1 pix1 overflow\n");
+
+   if (unlikely(value4 & ISPIF_VFE_m_IRQ_STATUS_1_RDI1_OVERFLOW))
+   dev_err_ratelimited(to_device(ispif), "VFE1 rdi1 overflow\n");
+
+   if (unlikely(value5 & ISPIF_VFE_m_IRQ_STATUS_2_RDI2_OVERFLOW))
+   dev_err_ratelimited(to_device(ispif), "VFE1 rdi2 overflow\n");
+
+   return IRQ_HANDLED;
+}
+
+/*
+ * ispif_isr_8x16 - ISPIF module interrupt handler for 8x16
+ * @irq: Interrupt line
+ * @dev: ISPIF device
+ *
+ * Return IRQ_HANDLED on success
+ */
+static irqreturn_t ispif_isr_8x16(int irq, void *dev)
 {
struct ispif_device *ispif = dev;
u32 value0, value1, value2;
@@ -959,8 +1023,14 @@ int msm_ispif_subdev_init(struct ispif_device *ispif,
ispif->irq = r->start;
snprintf(ispif->irq_name, sizeof(ispif->irq_name), "%s_%s",
 dev_name(dev), MSM_ISPIF_NAME);
-   ret = devm_request_irq(dev, ispif->irq, ispif_isr,
+   if (to_camss(ispif)->version == CAMSS_8x16)
+   ret = devm_request_irq(dev, ispif->irq, ispif_isr_8x16,
   IRQF_TRIGGER_RISING, ispif->irq_name, ispif);
+   else if (to_camss(ispif)->version == CAMSS_8x96)
+   ret = devm_request_irq(dev, ispif->irq, ispif_isr_8x96,
+  IRQF_TRIGGER_RISING, ispif->irq_name, ispif);
+   else
+   ret = -EINVAL;
if (ret < 0) {
dev_err(dev, "request_irq failed: %d\n", ret);
return ret;
-- 
2.7.4



[PATCH v4 30/34] media: camss: csid: MIPI10 to Plain16 format conversion

2018-07-25 Thread Todor Tomov
Use the PRDI mode on 8x96 to allow to configure RAW MIPI10
to Plain16 format conversion.

Signed-off-by: Todor Tomov 
---
 drivers/media/platform/qcom/camss/camss-csid.c  | 33 -
 drivers/media/platform/qcom/camss/camss-ispif.c | 64 +
 drivers/media/platform/qcom/camss/camss-vfe.c   |  1 +
 drivers/media/platform/qcom/camss/camss-video.c |  2 +
 4 files changed, 99 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/qcom/camss/camss-csid.c 
b/drivers/media/platform/qcom/camss/camss-csid.c
index cf543fa..0715a8e 100644
--- a/drivers/media/platform/qcom/camss/camss-csid.c
+++ b/drivers/media/platform/qcom/camss/camss-csid.c
@@ -32,6 +32,15 @@
(((v) == CAMSS_8x16 ? 0x010 : 0x014) + 0x4 * (n))
 #define CAMSS_CSID_CID_n_CFG(v, n) \
(((v) == CAMSS_8x16 ? 0x020 : 0x024) + 0x4 * (n))
+#define CAMSS_CSID_CID_n_CFG_ISPIF_EN  BIT(0)
+#define CAMSS_CSID_CID_n_CFG_RDI_ENBIT(1)
+#define CAMSS_CSID_CID_n_CFG_DECODE_FORMAT_SHIFT   4
+#define CAMSS_CSID_CID_n_CFG_PLAIN_FORMAT_8(0 << 8)
+#define CAMSS_CSID_CID_n_CFG_PLAIN_FORMAT_16   (1 << 8)
+#define CAMSS_CSID_CID_n_CFG_PLAIN_ALIGNMENT_LSB   (0 << 9)
+#define CAMSS_CSID_CID_n_CFG_PLAIN_ALIGNMENT_MSB   (1 << 9)
+#define CAMSS_CSID_CID_n_CFG_RDI_MODE_RAW_DUMP (0 << 10)
+#define CAMSS_CSID_CID_n_CFG_RDI_MODE_PLAIN_PACKING(1 << 10)
 #define CAMSS_CSID_IRQ_CLEAR_CMD(v)((v) == CAMSS_8x16 ? 0x060 : 0x064)
 #define CAMSS_CSID_IRQ_MASK(v) ((v) == CAMSS_8x16 ? 0x064 : 0x068)
 #define CAMSS_CSID_IRQ_STATUS(v)   ((v) == CAMSS_8x16 ? 0x068 : 0x06c)
@@ -330,6 +339,16 @@ static u32 csid_src_pad_code(struct csid_device *csid, u32 
sink_code,
return sink_code;
} else if (csid->camss->version == CAMSS_8x96) {
switch (sink_code) {
+   case MEDIA_BUS_FMT_SBGGR10_1X10:
+   {
+   u32 src_code[] = {
+   MEDIA_BUS_FMT_SBGGR10_1X10,
+   MEDIA_BUS_FMT_SBGGR10_2X8_PADHI_LE,
+   };
+
+   return csid_find_code(src_code, ARRAY_SIZE(src_code),
+ index, src_req_code);
+   }
default:
if (index > 0)
return 0;
@@ -636,7 +655,19 @@ static int csid_set_stream(struct v4l2_subdev *sd, int 
enable)
writel_relaxed(val, csid->base +
   CAMSS_CSID_CID_LUT_VC_n(ver, vc));
 
-   val = (df << 4) | 0x3;
+   val = CAMSS_CSID_CID_n_CFG_ISPIF_EN;
+   val |= CAMSS_CSID_CID_n_CFG_RDI_EN;
+   val |= df << CAMSS_CSID_CID_n_CFG_DECODE_FORMAT_SHIFT;
+   val |= CAMSS_CSID_CID_n_CFG_RDI_MODE_RAW_DUMP;
+   if (csid->camss->version == CAMSS_8x96 &&
+   csid->fmt[MSM_CSID_PAD_SINK].code ==
+   MEDIA_BUS_FMT_SBGGR10_1X10 &&
+   csid->fmt[MSM_CSID_PAD_SRC].code ==
+   MEDIA_BUS_FMT_SBGGR10_2X8_PADHI_LE) {
+   val |= CAMSS_CSID_CID_n_CFG_RDI_MODE_PLAIN_PACKING;
+   val |= CAMSS_CSID_CID_n_CFG_PLAIN_FORMAT_16;
+   val |= CAMSS_CSID_CID_n_CFG_PLAIN_ALIGNMENT_LSB;
+   }
writel_relaxed(val, csid->base +
   CAMSS_CSID_CID_n_CFG(ver, cid));
 
diff --git a/drivers/media/platform/qcom/camss/camss-ispif.c 
b/drivers/media/platform/qcom/camss/camss-ispif.c
index 146d5d2..81d6351 100644
--- a/drivers/media/platform/qcom/camss/camss-ispif.c
+++ b/drivers/media/platform/qcom/camss/camss-ispif.c
@@ -76,6 +76,13 @@
(0x254 + 0x200 * (m) + 0x4 * (n))
 #define ISPIF_VFE_m_RDI_INTF_n_CID_MASK(m, n)  \
(0x264 + 0x200 * (m) + 0x4 * (n))
+/* PACK_CFG registers are 8x96 only */
+#define ISPIF_VFE_m_RDI_INTF_n_PACK_CFG_0(m, n)\
+   (0x270 + 0x200 * (m) + 0x4 * (n))
+#define ISPIF_VFE_m_RDI_INTF_n_PACK_CFG_1(m, n)\
+   (0x27c + 0x200 * (m) + 0x4 * (n))
+#define ISPIF_VFE_m_RDI_INTF_n_PACK_CFG_0_CID_c_PLAIN(c)   \
+   (1 << ((cid % 8) * 4))
 #define ISPIF_VFE_m_PIX_INTF_n_STATUS(m, n)\
(0x2c0 + 0x200 * (m) + 0x4 * (n))
 #define ISPIF_VFE_m_RDI_INTF_n_STATUS(m, n)\
@@ -128,6 +135,7 @@ static const u32 ispif_formats_8x96[] = {
MEDIA_BUS_FMT_SGBRG10_1X10,
MEDIA_BUS_FMT_SGRBG10_1X10,
MEDIA_BUS_FMT_SRGGB10_1X10,
+   MEDIA_BUS_FMT_SBGGR10_2X8_PADHI_LE,
MEDIA_BUS_FMT_SBGGR12_1X12,
  

[PATCH v4 20/34] media: camss: csiphy: Unify lane handling

2018-07-25 Thread Todor Tomov
Restructure lane configuration so it is simpler and will allow
similar (although not the same) handling for different hardware
versions.

Signed-off-by: Todor Tomov 
---
 .../platform/qcom/camss/camss-csiphy-2ph-1-0.c | 48 --
 drivers/media/platform/qcom/camss/camss-csiphy.c   |  4 +-
 drivers/media/platform/qcom/camss/camss-csiphy.h   |  3 +-
 3 files changed, 29 insertions(+), 26 deletions(-)

diff --git a/drivers/media/platform/qcom/camss/camss-csiphy-2ph-1-0.c 
b/drivers/media/platform/qcom/camss/camss-csiphy-2ph-1-0.c
index 7325906..5f499be 100644
--- a/drivers/media/platform/qcom/camss/camss-csiphy-2ph-1-0.c
+++ b/drivers/media/platform/qcom/camss/camss-csiphy-2ph-1-0.c
@@ -86,7 +86,7 @@ static void csiphy_lanes_enable(struct csiphy_device *csiphy,
 {
struct csiphy_lanes_cfg *c = >csi2->lane_cfg;
u8 settle_cnt;
-   u8 val;
+   u8 val, l = 0;
int i = 0;
 
settle_cnt = csiphy_settle_cnt_calc(pixel_clock, bpp, c->num_data,
@@ -104,34 +104,38 @@ static void csiphy_lanes_enable(struct csiphy_device 
*csiphy,
val = cfg->combo_mode << 4;
writel_relaxed(val, csiphy->base + CAMSS_CSI_PHY_GLBL_RESET);
 
-   while (lane_mask) {
-   if (lane_mask & 0x1) {
-   writel_relaxed(0x10, csiphy->base +
-  CAMSS_CSI_PHY_LNn_CFG2(i));
-   writel_relaxed(settle_cnt, csiphy->base +
-  CAMSS_CSI_PHY_LNn_CFG3(i));
-   writel_relaxed(0x3f, csiphy->base +
-  CAMSS_CSI_PHY_INTERRUPT_MASKn(i));
-   writel_relaxed(0x3f, csiphy->base +
-  CAMSS_CSI_PHY_INTERRUPT_CLEARn(i));
-   }
-
-   lane_mask >>= 1;
-   i++;
+   for (i = 0; i <= c->num_data; i++) {
+   if (i == c->num_data)
+   l = c->clk.pos;
+   else
+   l = c->data[i].pos;
+
+   writel_relaxed(0x10, csiphy->base +
+  CAMSS_CSI_PHY_LNn_CFG2(l));
+   writel_relaxed(settle_cnt, csiphy->base +
+  CAMSS_CSI_PHY_LNn_CFG3(l));
+   writel_relaxed(0x3f, csiphy->base +
+  CAMSS_CSI_PHY_INTERRUPT_MASKn(l));
+   writel_relaxed(0x3f, csiphy->base +
+  CAMSS_CSI_PHY_INTERRUPT_CLEARn(l));
}
 }
 
-static void csiphy_lanes_disable(struct csiphy_device *csiphy, u8 lane_mask)
+static void csiphy_lanes_disable(struct csiphy_device *csiphy,
+struct csiphy_config *cfg)
 {
+   struct csiphy_lanes_cfg *c = >csi2->lane_cfg;
+   u8 l = 0;
int i = 0;
 
-   while (lane_mask) {
-   if (lane_mask & 0x1)
-   writel_relaxed(0x0, csiphy->base +
-  CAMSS_CSI_PHY_LNn_CFG2(i));
+   for (i = 0; i <= c->num_data; i++) {
+   if (i == c->num_data)
+   l = c->clk.pos;
+   else
+   l = c->data[i].pos;
 
-   lane_mask >>= 1;
-   i++;
+   writel_relaxed(0x0, csiphy->base +
+  CAMSS_CSI_PHY_LNn_CFG2(l));
}
 
writel_relaxed(0x0, csiphy->base + CAMSS_CSI_PHY_GLBL_PWR_CFG);
diff --git a/drivers/media/platform/qcom/camss/camss-csiphy.c 
b/drivers/media/platform/qcom/camss/camss-csiphy.c
index 8d10e85..d35eea0 100644
--- a/drivers/media/platform/qcom/camss/camss-csiphy.c
+++ b/drivers/media/platform/qcom/camss/camss-csiphy.c
@@ -296,9 +296,7 @@ static int csiphy_stream_on(struct csiphy_device *csiphy)
  */
 static void csiphy_stream_off(struct csiphy_device *csiphy)
 {
-   u8 lane_mask = csiphy_get_lane_mask(>cfg.csi2->lane_cfg);
-
-   csiphy->ops->lanes_disable(csiphy, lane_mask);
+   csiphy->ops->lanes_disable(csiphy, >cfg);
 }
 
 
diff --git a/drivers/media/platform/qcom/camss/camss-csiphy.h 
b/drivers/media/platform/qcom/camss/camss-csiphy.h
index edad941..e3dd257 100644
--- a/drivers/media/platform/qcom/camss/camss-csiphy.h
+++ b/drivers/media/platform/qcom/camss/camss-csiphy.h
@@ -51,7 +51,8 @@ struct csiphy_hw_ops {
void (*lanes_enable)(struct csiphy_device *csiphy,
 struct csiphy_config *cfg,
 u32 pixel_clock, u8 bpp, u8 lane_mask);
-   void (*lanes_disable)(struct csiphy_device *csiphy, u8 lane_mask);
+   void (*lanes_disable)(struct csiphy_device *csiphy,
+ struct csiphy_config *cfg);
irqreturn_t (*isr)(int irq, void *dev);
 };
 
-- 
2.7.4



[PATCH v4 29/34] media: camss: csid: Different format support on source pad

2018-07-25 Thread Todor Tomov
Usually the format on the source pad is the same as on the sink pad.
However the CSID is able to do some format conversions. To support
this make the format on the source pad selectable amongst a list
of formats. This list can be different for each sink pad format.
This is still not used but will be when the format conversions
are implemented.

Signed-off-by: Todor Tomov 
---
 drivers/media/platform/qcom/camss/camss-csid.c | 69 +-
 1 file changed, 56 insertions(+), 13 deletions(-)

diff --git a/drivers/media/platform/qcom/camss/camss-csid.c 
b/drivers/media/platform/qcom/camss/camss-csid.c
index db960da..cf543fa 100644
--- a/drivers/media/platform/qcom/camss/camss-csid.c
+++ b/drivers/media/platform/qcom/camss/camss-csid.c
@@ -300,6 +300,47 @@ static const struct csid_format csid_formats_8x96[] = {
}
 };
 
+static u32 csid_find_code(u32 *code, unsigned int n_code,
+ unsigned int index, u32 req_code)
+{
+   int i;
+
+   if (!req_code && (index >= n_code))
+   return 0;
+
+   for (i = 0; i < n_code; i++)
+   if (req_code) {
+   if (req_code == code[i])
+   return req_code;
+   } else {
+   if (i == index)
+   return code[i];
+   }
+
+   return code[0];
+}
+
+static u32 csid_src_pad_code(struct csid_device *csid, u32 sink_code,
+unsigned int index, u32 src_req_code)
+{
+   if (csid->camss->version == CAMSS_8x16) {
+   if (index > 0)
+   return 0;
+
+   return sink_code;
+   } else if (csid->camss->version == CAMSS_8x96) {
+   switch (sink_code) {
+   default:
+   if (index > 0)
+   return 0;
+
+   return sink_code;
+   }
+   } else {
+   return 0;
+   }
+}
+
 static const struct csid_format *csid_get_fmt_entry(
const struct csid_format *formats,
unsigned int nformat,
@@ -674,15 +715,15 @@ static void csid_try_format(struct csid_device *csid,
 
case MSM_CSID_PAD_SRC:
if (csid->testgen_mode->cur.val == 0) {
-   /* Test generator is disabled, keep pad formats */
-   /* in sync - set and return a format same as sink pad */
-   struct v4l2_mbus_framefmt format;
+   /* Test generator is disabled, */
+   /* keep pad formats in sync */
+   u32 code = fmt->code;
 
-   format = *__csid_get_format(csid, cfg,
-   MSM_CSID_PAD_SINK, which);
-   *fmt = format;
+   *fmt = *__csid_get_format(csid, cfg,
+ MSM_CSID_PAD_SINK, which);
+   fmt->code = csid_src_pad_code(csid, fmt->code, 0, code);
} else {
-   /* Test generator is enabled, set format on source*/
+   /* Test generator is enabled, set format on source */
/* pad to allow test generator usage */
 
for (i = 0; i < csid->nformats; i++)
@@ -716,7 +757,6 @@ static int csid_enum_mbus_code(struct v4l2_subdev *sd,
   struct v4l2_subdev_mbus_code_enum *code)
 {
struct csid_device *csid = v4l2_get_subdevdata(sd);
-   struct v4l2_mbus_framefmt *format;
 
if (code->pad == MSM_CSID_PAD_SINK) {
if (code->index >= csid->nformats)
@@ -725,13 +765,16 @@ static int csid_enum_mbus_code(struct v4l2_subdev *sd,
code->code = csid->formats[code->index].code;
} else {
if (csid->testgen_mode->cur.val == 0) {
-   if (code->index > 0)
-   return -EINVAL;
+   struct v4l2_mbus_framefmt *sink_fmt;
 
-   format = __csid_get_format(csid, cfg, MSM_CSID_PAD_SINK,
-  code->which);
+   sink_fmt = __csid_get_format(csid, cfg,
+MSM_CSID_PAD_SINK,
+code->which);
 
-   code->code = format->code;
+   code->code = csid_src_pad_code(csid, sink_fmt->code,
+  code->index, 0);
+   if (!code->code)
+   return -EINVAL;
} else {
if (code->index >= csid->nformats)
return -EINVAL;
-- 
2.7.4



[PATCH v4 15/34] media: dt-bindings: media: qcom,camss: Fix whitespaces

2018-07-25 Thread Todor Tomov
Use tabs.

CC: Rob Herring 
CC: Mark Rutland 
CC: devicet...@vger.kernel.org
Signed-off-by: Todor Tomov 
Reviewed-by: Rob Herring 
---
 .../devicetree/bindings/media/qcom,camss.txt   | 92 +++---
 1 file changed, 46 insertions(+), 46 deletions(-)

diff --git a/Documentation/devicetree/bindings/media/qcom,camss.txt 
b/Documentation/devicetree/bindings/media/qcom,camss.txt
index 032e8ed..e938eb0 100644
--- a/Documentation/devicetree/bindings/media/qcom,camss.txt
+++ b/Documentation/devicetree/bindings/media/qcom,camss.txt
@@ -53,25 +53,25 @@ Qualcomm Camera Subsystem
Usage: required
Value type: 
Definition: Should contain the following entries:
-- "top_ahb"
-- "ispif_ahb"
-- "csiphy0_timer"
-- "csiphy1_timer"
-- "csi0_ahb"
-- "csi0"
-- "csi0_phy"
-- "csi0_pix"
-- "csi0_rdi"
-- "csi1_ahb"
-- "csi1"
-- "csi1_phy"
-- "csi1_pix"
-- "csi1_rdi"
-- "ahb"
-- "vfe0"
-- "csi_vfe0"
-- "vfe_ahb"
-- "vfe_axi"
+   - "top_ahb"
+   - "ispif_ahb"
+   - "csiphy0_timer"
+   - "csiphy1_timer"
+   - "csi0_ahb"
+   - "csi0"
+   - "csi0_phy"
+   - "csi0_pix"
+   - "csi0_rdi"
+   - "csi1_ahb"
+   - "csi1"
+   - "csi1_phy"
+   - "csi1_pix"
+   - "csi1_rdi"
+   - "ahb"
+   - "vfe0"
+   - "csi_vfe0"
+   - "vfe_ahb"
+   - "vfe_axi"
 - vdda-supply:
Usage: required
Value type: 
@@ -95,17 +95,17 @@ Qualcomm Camera Subsystem
- clock-lanes:
Usage: required
Value type: 
-Definition: The physical clock lane index. The value
-must always be <1> as the physical clock
-lane is lane 1.
+   Definition: The physical clock lane index. The value
+   must always be <1> as the physical clock
+   lane is lane 1.
- data-lanes:
Usage: required
Value type: 
-Definition: An array of physical data lanes indexes.
-Position of an entry determines the logical
-lane number, while the value of an entry
-indicates physical lane index. Lane 
swapping
-is supported.
+   Definition: An array of physical data lanes indexes.
+   Position of an entry determines the logical
+   lane number, while the value of an entry
+   indicates physical lane index. Lane swapping
+   is supported.
 
 * An Example
 
@@ -161,25 +161,25 @@ Qualcomm Camera Subsystem
< GCC_CAMSS_CSI_VFE0_CLK>,
< GCC_CAMSS_VFE_AHB_CLK>,
< GCC_CAMSS_VFE_AXI_CLK>;
-clock-names = "top_ahb",
-"ispif_ahb",
-"csiphy0_timer",
-"csiphy1_timer",
-"csi0_ahb",
-"csi0",
-"csi0_phy",
-"csi0_pix",
-"csi0_rdi",
-"csi1_ahb",
-"csi1",
-"csi1_phy",
-"csi1_pix",
-"csi1_rdi",
-"ahb",
-"vfe0",
-"csi_vfe0",
-"vfe_ahb",
-"vfe_axi";
+   clock-names = "top_ahb",
+   "ispif_ahb",
+   "csiphy0_timer",
+   "csiphy1_timer",
+   "csi0_ahb",
+   "csi0",
+   "csi0_phy",
+   "csi0_pix",
+   "csi0_rdi",
+   "csi1_ahb",
+   "csi1",
+   "csi1_phy",
+   "csi1_pix",
+   "csi1_rdi",
+   "ahb",
+   "vfe0",
+   "csi_vfe0",
+   "vfe_ahb",
+   "vfe_axi";
vdda-supply = <_l2>;
iommus = <_iommu 3>;
ports {
-- 
2.7.4



[PATCH v4 32/34] media: camss: Add support for 10-bit grayscale formats

2018-07-25 Thread Todor Tomov
Add support for 10-bit packed V4L2_PIX_FMT_Y10P (on 8x16 and 8x96)
and unpacked V4L2_PIX_FMT_Y10 (on 8x96 only) pixel formats.

Signed-off-by: Todor Tomov 
---
 drivers/media/platform/qcom/camss/camss-csid.c   | 50 +++-
 drivers/media/platform/qcom/camss/camss-csiphy.c |  2 +
 drivers/media/platform/qcom/camss/camss-ispif.c  |  6 ++-
 drivers/media/platform/qcom/camss/camss-vfe.c|  3 ++
 drivers/media/platform/qcom/camss/camss-video.c  |  6 +++
 5 files changed, 56 insertions(+), 11 deletions(-)

diff --git a/drivers/media/platform/qcom/camss/camss-csid.c 
b/drivers/media/platform/qcom/camss/camss-csid.c
index 472884d..6e141af 100644
--- a/drivers/media/platform/qcom/camss/camss-csid.c
+++ b/drivers/media/platform/qcom/camss/camss-csid.c
@@ -193,7 +193,14 @@ static const struct csid_format csid_formats_8x16[] = {
DECODE_FORMAT_UNCOMPRESSED_12_BIT,
12,
1,
-   }
+   },
+   {
+   MEDIA_BUS_FMT_Y10_1X10,
+   DATA_TYPE_RAW_10BIT,
+   DECODE_FORMAT_UNCOMPRESSED_10_BIT,
+   10,
+   1,
+   },
 };
 
 static const struct csid_format csid_formats_8x96[] = {
@@ -336,7 +343,14 @@ static const struct csid_format csid_formats_8x96[] = {
DECODE_FORMAT_UNCOMPRESSED_14_BIT,
14,
1,
-   }
+   },
+   {
+   MEDIA_BUS_FMT_Y10_1X10,
+   DATA_TYPE_RAW_10BIT,
+   DECODE_FORMAT_UNCOMPRESSED_10_BIT,
+   10,
+   1,
+   },
 };
 
 static u32 csid_find_code(u32 *code, unsigned int n_code,
@@ -379,6 +393,16 @@ static u32 csid_src_pad_code(struct csid_device *csid, u32 
sink_code,
return csid_find_code(src_code, ARRAY_SIZE(src_code),
  index, src_req_code);
}
+   case MEDIA_BUS_FMT_Y10_1X10:
+   {
+   u32 src_code[] = {
+   MEDIA_BUS_FMT_Y10_1X10,
+   MEDIA_BUS_FMT_Y10_2X8_PADHI_LE,
+   };
+
+   return csid_find_code(src_code, ARRAY_SIZE(src_code),
+ index, src_req_code);
+   }
default:
if (index > 0)
return 0;
@@ -689,15 +713,21 @@ static int csid_set_stream(struct v4l2_subdev *sd, int 
enable)
val |= CAMSS_CSID_CID_n_CFG_RDI_EN;
val |= df << CAMSS_CSID_CID_n_CFG_DECODE_FORMAT_SHIFT;
val |= CAMSS_CSID_CID_n_CFG_RDI_MODE_RAW_DUMP;
-   if (csid->camss->version == CAMSS_8x96 &&
-   csid->fmt[MSM_CSID_PAD_SINK].code ==
-   MEDIA_BUS_FMT_SBGGR10_1X10 &&
-   csid->fmt[MSM_CSID_PAD_SRC].code ==
-   MEDIA_BUS_FMT_SBGGR10_2X8_PADHI_LE) {
-   val |= CAMSS_CSID_CID_n_CFG_RDI_MODE_PLAIN_PACKING;
-   val |= CAMSS_CSID_CID_n_CFG_PLAIN_FORMAT_16;
-   val |= CAMSS_CSID_CID_n_CFG_PLAIN_ALIGNMENT_LSB;
+
+   if (csid->camss->version == CAMSS_8x96) {
+   u32 sink_code = csid->fmt[MSM_CSID_PAD_SINK].code;
+   u32 src_code = csid->fmt[MSM_CSID_PAD_SRC].code;
+
+   if ((sink_code == MEDIA_BUS_FMT_SBGGR10_1X10 &&
+src_code == MEDIA_BUS_FMT_SBGGR10_2X8_PADHI_LE) ||
+   (sink_code == MEDIA_BUS_FMT_Y10_1X10 &&
+src_code == MEDIA_BUS_FMT_Y10_2X8_PADHI_LE)) {
+   val |= 
CAMSS_CSID_CID_n_CFG_RDI_MODE_PLAIN_PACKING;
+   val |= CAMSS_CSID_CID_n_CFG_PLAIN_FORMAT_16;
+   val |= CAMSS_CSID_CID_n_CFG_PLAIN_ALIGNMENT_LSB;
+   }
}
+
writel_relaxed(val, csid->base +
   CAMSS_CSID_CID_n_CFG(ver, cid));
 
diff --git a/drivers/media/platform/qcom/camss/camss-csiphy.c 
b/drivers/media/platform/qcom/camss/camss-csiphy.c
index cae3e8b..4559f3b 100644
--- a/drivers/media/platform/qcom/camss/camss-csiphy.c
+++ b/drivers/media/platform/qcom/camss/camss-csiphy.c
@@ -45,6 +45,7 @@ static const struct csiphy_format csiphy_formats_8x16[] = {
{ MEDIA_BUS_FMT_SGBRG12_1X12, 12 },
{ MEDIA_BUS_FMT_SGRBG12_1X12, 12 },
{ MEDIA_BUS_FMT_SRGGB12_1X12, 12 },
+   { MEDIA_BUS_FMT_Y10_1X10, 10 },
 };
 
 static const struct csiphy_format csiphy_formats_8x96[] = {
@@ -68,6 +69,7 @@ static const struct csiphy_format csiphy_formats_8x96[] = {
{ MEDIA_BUS_FMT_SGBRG14_1X14, 14 },
{ MEDIA_BUS_FMT_SGRBG14_1X14, 14 },
{ MEDIA_BUS_FMT_SRGGB1

[PATCH v4 22/34] media: camss: csid: Add support for 8x96

2018-07-25 Thread Todor Tomov
CSID hardware modules on 8x16 and 8x96 are similar. There is no
need to duplicate the code by adding separate versions. Just
update the register macros to return the correct register
addresses.

Signed-off-by: Todor Tomov 
---
 drivers/media/platform/qcom/camss/camss-csid.c | 60 --
 1 file changed, 37 insertions(+), 23 deletions(-)

diff --git a/drivers/media/platform/qcom/camss/camss-csid.c 
b/drivers/media/platform/qcom/camss/camss-csid.c
index 3ba087f..915835e 100644
--- a/drivers/media/platform/qcom/camss/camss-csid.c
+++ b/drivers/media/platform/qcom/camss/camss-csid.c
@@ -27,21 +27,26 @@
 #define CAMSS_CSID_HW_VERSION  0x0
 #define CAMSS_CSID_CORE_CTRL_0 0x004
 #define CAMSS_CSID_CORE_CTRL_1 0x008
-#define CAMSS_CSID_RST_CMD 0x00c
-#define CAMSS_CSID_CID_LUT_VC_n(n) (0x010 + 0x4 * (n))
-#define CAMSS_CSID_CID_n_CFG(n)(0x020 + 0x4 * (n))
-#define CAMSS_CSID_IRQ_CLEAR_CMD   0x060
-#define CAMSS_CSID_IRQ_MASK0x064
-#define CAMSS_CSID_IRQ_STATUS  0x068
-#define CAMSS_CSID_TG_CTRL 0x0a0
+#define CAMSS_CSID_RST_CMD(v)  ((v) == CAMSS_8x16 ? 0x00c : 0x010)
+#define CAMSS_CSID_CID_LUT_VC_n(v, n)  \
+   (((v) == CAMSS_8x16 ? 0x010 : 0x014) + 0x4 * (n))
+#define CAMSS_CSID_CID_n_CFG(v, n) \
+   (((v) == CAMSS_8x16 ? 0x020 : 0x024) + 0x4 * (n))
+#define CAMSS_CSID_IRQ_CLEAR_CMD(v)((v) == CAMSS_8x16 ? 0x060 : 0x064)
+#define CAMSS_CSID_IRQ_MASK(v) ((v) == CAMSS_8x16 ? 0x064 : 0x068)
+#define CAMSS_CSID_IRQ_STATUS(v)   ((v) == CAMSS_8x16 ? 0x068 : 0x06c)
+#define CAMSS_CSID_TG_CTRL(v)  ((v) == CAMSS_8x16 ? 0x0a0 : 0x0a8)
 #define CAMSS_CSID_TG_CTRL_DISABLE 0xa06436
 #define CAMSS_CSID_TG_CTRL_ENABLE  0xa06437
-#define CAMSS_CSID_TG_VC_CFG   0x0a4
+#define CAMSS_CSID_TG_VC_CFG(v)((v) == CAMSS_8x16 ? 0x0a4 : 
0x0ac)
 #define CAMSS_CSID_TG_VC_CFG_H_BLANKING0x3ff
 #define CAMSS_CSID_TG_VC_CFG_V_BLANKING0x7f
-#define CAMSS_CSID_TG_DT_n_CGG_0(n)(0x0ac + 0xc * (n))
-#define CAMSS_CSID_TG_DT_n_CGG_1(n)(0x0b0 + 0xc * (n))
-#define CAMSS_CSID_TG_DT_n_CGG_2(n)(0x0b4 + 0xc * (n))
+#define CAMSS_CSID_TG_DT_n_CGG_0(v, n) \
+   (((v) == CAMSS_8x16 ? 0x0ac : 0x0b4) + 0xc * (n))
+#define CAMSS_CSID_TG_DT_n_CGG_1(v, n) \
+   (((v) == CAMSS_8x16 ? 0x0b0 : 0x0b8) + 0xc * (n))
+#define CAMSS_CSID_TG_DT_n_CGG_2(v, n) \
+   (((v) == CAMSS_8x16 ? 0x0b4 : 0x0bc) + 0xc * (n))
 
 #define DATA_TYPE_EMBEDDED_DATA_8BIT   0x12
 #define DATA_TYPE_YUV422_8BIT  0x1e
@@ -203,10 +208,11 @@ static const struct csid_fmts *csid_get_fmt_entry(u32 
code)
 static irqreturn_t csid_isr(int irq, void *dev)
 {
struct csid_device *csid = dev;
+   enum camss_version ver = csid->camss->version;
u32 value;
 
-   value = readl_relaxed(csid->base + CAMSS_CSID_IRQ_STATUS);
-   writel_relaxed(value, csid->base + CAMSS_CSID_IRQ_CLEAR_CMD);
+   value = readl_relaxed(csid->base + CAMSS_CSID_IRQ_STATUS(ver));
+   writel_relaxed(value, csid->base + CAMSS_CSID_IRQ_CLEAR_CMD(ver));
 
if ((value >> 11) & 0x1)
complete(>reset_complete);
@@ -289,7 +295,8 @@ static int csid_reset(struct csid_device *csid)
 
reinit_completion(>reset_complete);
 
-   writel_relaxed(0x7fff, csid->base + CAMSS_CSID_RST_CMD);
+   writel_relaxed(0x7fff, csid->base +
+  CAMSS_CSID_RST_CMD(csid->camss->version));
 
time = wait_for_completion_timeout(>reset_complete,
msecs_to_jiffies(CSID_RESET_TIMEOUT_MS));
@@ -377,6 +384,7 @@ static int csid_set_stream(struct v4l2_subdev *sd, int 
enable)
 {
struct csid_device *csid = v4l2_get_subdevdata(sd);
struct csid_testgen_config *tg = >testgen;
+   enum camss_version ver = csid->camss->version;
u32 val;
 
if (enable) {
@@ -409,13 +417,14 @@ static int csid_set_stream(struct v4l2_subdev *sd, int 
enable)
/* 1:0 VC */
val = ((CAMSS_CSID_TG_VC_CFG_V_BLANKING & 0xff) << 24) |
  ((CAMSS_CSID_TG_VC_CFG_H_BLANKING & 0x7ff) << 13);
-   writel_relaxed(val, csid->base + CAMSS_CSID_TG_VC_CFG);
+   writel_relaxed(val, csid->base +
+  CAMSS_CSID_TG_VC_CFG(ver));
 
/* 28:16 bytes per lines, 12:0 num of lines */
val = ((num_bytes_per_line & 0x1fff) << 16) |
  (num_lines & 0x1fff);
writel_relaxed(val, csid->base +
-  CAMSS_CSID_TG_DT_n_CGG_0(0));
+  CAMSS_CSID_TG_DT_n_CGG_0(v

[PATCH v4 27/34] media: camss: vfe: Different format support on source pad

2018-07-25 Thread Todor Tomov
Rework the format selection on the source pad. Make the format
on the source pad selectable amongst a list of formats. This
list can be different for each sink pad format.

Signed-off-by: Todor Tomov 
---
 drivers/media/platform/qcom/camss/camss-vfe.c | 172 --
 1 file changed, 135 insertions(+), 37 deletions(-)

diff --git a/drivers/media/platform/qcom/camss/camss-vfe.c 
b/drivers/media/platform/qcom/camss/camss-vfe.c
index c27097c..dc353d6 100644
--- a/drivers/media/platform/qcom/camss/camss-vfe.c
+++ b/drivers/media/platform/qcom/camss/camss-vfe.c
@@ -124,6 +124,131 @@ static u8 vfe_get_bpp(const struct vfe_format *formats,
return formats[0].bpp;
 }
 
+static u32 vfe_find_code(u32 *code, unsigned int n_code,
+unsigned int index, u32 req_code)
+{
+   int i;
+
+   if (!req_code && (index >= n_code))
+   return 0;
+
+   for (i = 0; i < n_code; i++)
+   if (req_code) {
+   if (req_code == code[i])
+   return req_code;
+   } else {
+   if (i == index)
+   return code[i];
+   }
+
+   return code[0];
+}
+
+static u32 vfe_src_pad_code(struct vfe_line *line, u32 sink_code,
+   unsigned int index, u32 src_req_code)
+{
+   struct vfe_device *vfe = to_vfe(line);
+
+   if (vfe->camss->version == CAMSS_8x16)
+   switch (sink_code) {
+   case MEDIA_BUS_FMT_YUYV8_2X8:
+   {
+   u32 src_code[] = {
+   MEDIA_BUS_FMT_YUYV8_2X8,
+   MEDIA_BUS_FMT_YUYV8_1_5X8,
+   };
+
+   return vfe_find_code(src_code, ARRAY_SIZE(src_code),
+index, src_req_code);
+   }
+   case MEDIA_BUS_FMT_YVYU8_2X8:
+   {
+   u32 src_code[] = {
+   MEDIA_BUS_FMT_YVYU8_2X8,
+   MEDIA_BUS_FMT_YVYU8_1_5X8,
+   };
+
+   return vfe_find_code(src_code, ARRAY_SIZE(src_code),
+index, src_req_code);
+   }
+   case MEDIA_BUS_FMT_UYVY8_2X8:
+   {
+   u32 src_code[] = {
+   MEDIA_BUS_FMT_UYVY8_2X8,
+   MEDIA_BUS_FMT_UYVY8_1_5X8,
+   };
+
+   return vfe_find_code(src_code, ARRAY_SIZE(src_code),
+index, src_req_code);
+   }
+   case MEDIA_BUS_FMT_VYUY8_2X8:
+   {
+   u32 src_code[] = {
+   MEDIA_BUS_FMT_VYUY8_2X8,
+   MEDIA_BUS_FMT_VYUY8_1_5X8,
+   };
+
+   return vfe_find_code(src_code, ARRAY_SIZE(src_code),
+index, src_req_code);
+   }
+   default:
+   if (index > 0)
+   return 0;
+
+   return sink_code;
+   }
+   else if (vfe->camss->version == CAMSS_8x96)
+   switch (sink_code) {
+   case MEDIA_BUS_FMT_YUYV8_2X8:
+   {
+   u32 src_code[] = {
+   MEDIA_BUS_FMT_YUYV8_2X8,
+   MEDIA_BUS_FMT_YUYV8_1_5X8,
+   };
+
+   return vfe_find_code(src_code, ARRAY_SIZE(src_code),
+index, src_req_code);
+   }
+   case MEDIA_BUS_FMT_YVYU8_2X8:
+   {
+   u32 src_code[] = {
+   MEDIA_BUS_FMT_YVYU8_2X8,
+   MEDIA_BUS_FMT_YVYU8_1_5X8,
+   };
+
+   return vfe_find_code(src_code, ARRAY_SIZE(src_code),
+index, src_req_code);
+   }
+   case MEDIA_BUS_FMT_UYVY8_2X8:
+   {
+   u32 src_code[] = {
+   MEDIA_BUS_FMT_UYVY8_2X8,
+   MEDIA_BUS_FMT_UYVY8_1_5X8,
+   };
+
+   return vfe_find_code(src_code, ARRAY_SIZE(src_code),
+index, src_req_code);
+   }
+   case MEDIA_BUS_FMT_VYUY8_2X8:
+   {
+   u32 src_code[] = {
+   MEDIA_BUS_FMT_VYUY8_2X8,
+   MEDIA_BUS_FMT_VYUY8_1_5X8,
+   };
+
+   return vfe_find_code(

[PATCH v4 28/34] media: camss: vfe: Add support for UYVY output from VFE on 8x96

2018-07-25 Thread Todor Tomov
Add support to output UYVY formats from the VFE (via the PIX interface).
A configuration for the realign module in the VFE is added. As the
realign module is present on 8x96 but not on 8x16, this is supported
on 8x96 only.

Signed-off-by: Todor Tomov 
---
 drivers/media/platform/qcom/camss/camss-vfe-4-1.c |   6 +
 drivers/media/platform/qcom/camss/camss-vfe-4-7.c | 129 ++
 drivers/media/platform/qcom/camss/camss-vfe.c |  31 +-
 drivers/media/platform/qcom/camss/camss-vfe.h |   2 +
 drivers/media/platform/qcom/camss/camss-video.c   |   8 ++
 5 files changed, 152 insertions(+), 24 deletions(-)

diff --git a/drivers/media/platform/qcom/camss/camss-vfe-4-1.c 
b/drivers/media/platform/qcom/camss/camss-vfe-4-1.c
index 41184dc..da3a9fe 100644
--- a/drivers/media/platform/qcom/camss/camss-vfe-4-1.c
+++ b/drivers/media/platform/qcom/camss/camss-vfe-4-1.c
@@ -542,6 +542,11 @@ static void vfe_set_xbar_cfg(struct vfe_device *vfe, 
struct vfe_output *output,
}
 }
 
+static void vfe_set_realign_cfg(struct vfe_device *vfe, struct vfe_line *line,
+   u8 enable)
+{
+   /* empty */
+}
 static void vfe_set_rdi_cid(struct vfe_device *vfe, enum vfe_line_id id, u8 
cid)
 {
vfe_reg_clr(vfe, VFE_0_RDI_CFG_x(id),
@@ -989,6 +994,7 @@ const struct vfe_hw_ops vfe_ops_4_1 = {
.wm_set_subsample = vfe_wm_set_subsample,
.bus_disconnect_wm_from_rdi = vfe_bus_disconnect_wm_from_rdi,
.set_xbar_cfg = vfe_set_xbar_cfg,
+   .set_realign_cfg = vfe_set_realign_cfg,
.set_rdi_cid = vfe_set_rdi_cid,
.reg_update = vfe_reg_update,
.reg_update_clear = vfe_reg_update_clear,
diff --git a/drivers/media/platform/qcom/camss/camss-vfe-4-7.c 
b/drivers/media/platform/qcom/camss/camss-vfe-4-7.c
index 45e6711..4c584bf 100644
--- a/drivers/media/platform/qcom/camss/camss-vfe-4-7.c
+++ b/drivers/media/platform/qcom/camss/camss-vfe-4-7.c
@@ -34,6 +34,7 @@
 #define VFE_0_MODULE_ZOOM_EN   0x04c
 #define VFE_0_MODULE_ZOOM_EN_SCALE_ENC BIT(1)
 #define VFE_0_MODULE_ZOOM_EN_CROP_ENC  BIT(2)
+#define VFE_0_MODULE_ZOOM_EN_REALIGN_BUF   BIT(9)
 
 #define VFE_0_CORE_CFG 0x050
 #define VFE_0_CORE_CFG_PIXEL_PATTERN_YCBYCR0x4
@@ -87,6 +88,9 @@
 
 #define VFE_0_BUS_XBAR_CFG_x(x)(0x90 + 0x4 * ((x) / 2))
 #define VFE_0_BUS_XBAR_CFG_x_M_PAIR_STREAM_EN  BIT(2)
+#define VFE_0_BUS_XBAR_CFG_x_M_REALIGN_BUF_EN  BIT(3)
+#define VFE_0_BUS_XBAR_CFG_x_M_PAIR_STREAM_SWAP_INTRA  (0x1 << 4)
+#define VFE_0_BUS_XBAR_CFG_x_M_PAIR_STREAM_SWAP_INTER  (0x2 << 4)
 #define VFE_0_BUS_XBAR_CFG_x_M_PAIR_STREAM_SWAP_INTER_INTRA(0x3 << 4)
 #define VFE_0_BUS_XBAR_CFG_x_M_SINGLE_STREAM_SEL_SHIFT 8
 #define VFE_0_BUS_XBAR_CFG_x_M_SINGLE_STREAM_SEL_LUMA  0x0
@@ -221,6 +225,11 @@
 #define VFE_0_CLAMP_ENC_MIN_CFG_CH1(0x0 << 8)
 #define VFE_0_CLAMP_ENC_MIN_CFG_CH2(0x0 << 16)
 
+#define VFE_0_REALIGN_BUF_CFG  0xaac
+#define VFE_0_REALIGN_BUF_CFG_CB_ODD_PIXEL BIT(2)
+#define VFE_0_REALIGN_BUF_CFG_CR_ODD_PIXEL BIT(3)
+#define VFE_0_REALIGN_BUF_CFG_HSUB_ENABLE  BIT(4)
+
 #define CAMIF_TIMEOUT_SLEEP_US 1000
 #define CAMIF_TIMEOUT_ALL_US 100
 
@@ -311,7 +320,7 @@ static void vfe_wm_frame_based(struct vfe_device *vfe, u8 
wm, u8 enable)
 
 #define CALC_WORD(width, M, N) (((width) * (M) + (N) - 1) / (N))
 
-static int vfe_word_per_line(u32 format, u32 pixel_per_line)
+static int vfe_word_per_line_by_pixel(u32 format, u32 pixel_per_line)
 {
int val = 0;
 
@@ -333,6 +342,11 @@ static int vfe_word_per_line(u32 format, u32 
pixel_per_line)
return val;
 }
 
+static int vfe_word_per_line_by_bytes(u32 bytes_per_line)
+{
+   return CALC_WORD(bytes_per_line, 1, 8);
+}
+
 static void vfe_get_wm_sizes(struct v4l2_pix_format_mplane *pix, u8 plane,
 u16 *width, u16 *height, u16 *bytesperline)
 {
@@ -351,6 +365,15 @@ static void vfe_get_wm_sizes(struct v4l2_pix_format_mplane 
*pix, u8 plane,
*height = pix->height;
*bytesperline = pix->plane_fmt[0].bytesperline;
break;
+   case V4L2_PIX_FMT_YUYV:
+   case V4L2_PIX_FMT_YVYU:
+   case V4L2_PIX_FMT_VYUY:
+   case V4L2_PIX_FMT_UYVY:
+   *width = pix->width;
+   *height = pix->height;
+   *bytesperline = pix->plane_fmt[plane].bytesperline;
+   break;
+
}
 }
 
@@ -365,7 +388,7 @@ static void vfe_wm_line_based(struct vfe_device *vfe, u32 
wm,
 
vfe_get_wm_sizes(pix, plane, , , );
 
-   wpl = vfe_word_per_line(pix->pixelformat, width);
+   wpl = vfe_word_per_line_by_pixel(pix->pixelformat, width);
 
reg = height - 1;
reg |= ((wpl + 3) / 4 - 1) << 16;
@@ -373,7 +396,7 @@ stat

[PATCH v4 21/34] media: camss: csiphy: Add support for 8x96

2018-07-25 Thread Todor Tomov
Add CSIPHY hardware dependent part for 8x96.

Signed-off-by: Todor Tomov 
---
 drivers/media/platform/qcom/camss/Makefile |   1 +
 .../platform/qcom/camss/camss-csiphy-3ph-1-0.c | 256 +
 drivers/media/platform/qcom/camss/camss-csiphy.c   |   2 +
 drivers/media/platform/qcom/camss/camss-csiphy.h   |   1 +
 4 files changed, 260 insertions(+)
 create mode 100644 drivers/media/platform/qcom/camss/camss-csiphy-3ph-1-0.c

diff --git a/drivers/media/platform/qcom/camss/Makefile 
b/drivers/media/platform/qcom/camss/Makefile
index 0446b24..36b9f7c 100644
--- a/drivers/media/platform/qcom/camss/Makefile
+++ b/drivers/media/platform/qcom/camss/Makefile
@@ -4,6 +4,7 @@ qcom-camss-objs += \
camss.o \
camss-csid.o \
camss-csiphy-2ph-1-0.o \
+   camss-csiphy-3ph-1-0.o \
camss-csiphy.o \
camss-ispif.o \
camss-vfe.o \
diff --git a/drivers/media/platform/qcom/camss/camss-csiphy-3ph-1-0.c 
b/drivers/media/platform/qcom/camss/camss-csiphy-3ph-1-0.c
new file mode 100644
index 000..bcd0dfd
--- /dev/null
+++ b/drivers/media/platform/qcom/camss/camss-csiphy-3ph-1-0.c
@@ -0,0 +1,256 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * camss-csiphy-3ph-1-0.c
+ *
+ * Qualcomm MSM Camera Subsystem - CSIPHY Module 3phase v1.0
+ *
+ * Copyright (c) 2011-2015, The Linux Foundation. All rights reserved.
+ * Copyright (C) 2016-2018 Linaro Ltd.
+ */
+
+#include "camss-csiphy.h"
+
+#include 
+#include 
+
+#define CSIPHY_3PH_LNn_CFG1(n) (0x000 + 0x100 * (n))
+#define CSIPHY_3PH_LNn_CFG1_SWI_REC_DLY_PRG(BIT(7) | BIT(6))
+#define CSIPHY_3PH_LNn_CFG2(n) (0x004 + 0x100 * (n))
+#define CSIPHY_3PH_LNn_CFG2_LP_REC_EN_INT  BIT(3)
+#define CSIPHY_3PH_LNn_CFG3(n) (0x008 + 0x100 * (n))
+#define CSIPHY_3PH_LNn_CFG4(n) (0x00c + 0x100 * (n))
+#define CSIPHY_3PH_LNn_CFG4_T_HS_CLK_MISS  0xa4
+#define CSIPHY_3PH_LNn_CFG5(n) (0x010 + 0x100 * (n))
+#define CSIPHY_3PH_LNn_CFG5_T_HS_DTERM 0x02
+#define CSIPHY_3PH_LNn_CFG5_HS_REC_EQ_FQ_INT   0x50
+#define CSIPHY_3PH_LNn_TEST_IMP(n) (0x01c + 0x100 * (n))
+#define CSIPHY_3PH_LNn_TEST_IMP_HS_TERM_IMP0xa
+#define CSIPHY_3PH_LNn_MISC1(n)(0x028 + 0x100 * (n))
+#define CSIPHY_3PH_LNn_MISC1_IS_CLKLANEBIT(2)
+#define CSIPHY_3PH_LNn_CFG6(n) (0x02c + 0x100 * (n))
+#define CSIPHY_3PH_LNn_CFG6_SWI_FORCE_INIT_EXITBIT(0)
+#define CSIPHY_3PH_LNn_CFG7(n) (0x030 + 0x100 * (n))
+#define CSIPHY_3PH_LNn_CFG7_SWI_T_INIT 0x2
+#define CSIPHY_3PH_LNn_CFG8(n) (0x034 + 0x100 * (n))
+#define CSIPHY_3PH_LNn_CFG8_SWI_SKIP_WAKEUPBIT(0)
+#define CSIPHY_3PH_LNn_CFG8_SKEW_FILTER_ENABLE BIT(1)
+#define CSIPHY_3PH_LNn_CFG9(n) (0x038 + 0x100 * (n))
+#define CSIPHY_3PH_LNn_CFG9_SWI_T_WAKEUP   0x1
+#define CSIPHY_3PH_LNn_CSI_LANE_CTRL15(n)  (0x03c + 0x100 * (n))
+#define CSIPHY_3PH_LNn_CSI_LANE_CTRL15_SWI_SOT_SYMBOL  0xb8
+
+#define CSIPHY_3PH_CMN_CSI_COMMON_CTRLn(n) (0x800 + 0x4 * (n))
+#define CSIPHY_3PH_CMN_CSI_COMMON_CTRL6_COMMON_PWRDN_B BIT(0)
+#define CSIPHY_3PH_CMN_CSI_COMMON_CTRL6_SHOW_REV_IDBIT(1)
+#define CSIPHY_3PH_CMN_CSI_COMMON_STATUSn(n)   (0x8b0 + 0x4 * (n))
+
+static void csiphy_hw_version_read(struct csiphy_device *csiphy,
+  struct device *dev)
+{
+   u32 hw_version;
+
+   writel(CSIPHY_3PH_CMN_CSI_COMMON_CTRL6_SHOW_REV_ID,
+  csiphy->base + CSIPHY_3PH_CMN_CSI_COMMON_CTRLn(6));
+
+   hw_version = readl_relaxed(csiphy->base +
+  CSIPHY_3PH_CMN_CSI_COMMON_STATUSn(12));
+   hw_version |= readl_relaxed(csiphy->base +
+  CSIPHY_3PH_CMN_CSI_COMMON_STATUSn(13)) << 8;
+   hw_version |= readl_relaxed(csiphy->base +
+  CSIPHY_3PH_CMN_CSI_COMMON_STATUSn(14)) << 16;
+   hw_version |= readl_relaxed(csiphy->base +
+  CSIPHY_3PH_CMN_CSI_COMMON_STATUSn(15)) << 24;
+
+   dev_err(dev, "CSIPHY 3PH HW Version = 0x%08x\n", hw_version);
+}
+
+/*
+ * csiphy_reset - Perform software reset on CSIPHY module
+ * @csiphy: CSIPHY device
+ */
+static void csiphy_reset(struct csiphy_device *csiphy)
+{
+   writel_relaxed(0x1, csiphy->base + CSIPHY_3PH_CMN_CSI_COMMON_CTRLn(0));
+   usleep_range(5000, 8000);
+   writel_relaxed(0x0, csiphy->base + CSIPHY_3PH_CMN_CSI_COMMON_CTRLn(0));
+}
+
+static irqreturn_t csiphy_isr(int irq, void *dev)
+{
+   struct csiphy_device *csiphy = dev;
+   int i;
+
+   for (i = 0; i < 11; i++) {
+   int c = i + 22;
+   u8 val = readl_relaxed(csiphy->base +
+  CSIPHY_3PH_CMN_CSI_COMMO

[PATCH v4 19/34] media: camss: csiphy: Split to hardware dependent and independent parts

2018-07-25 Thread Todor Tomov
This will allow to add support for different hardware.

Signed-off-by: Todor Tomov 
---
 drivers/media/platform/qcom/camss/Makefile |   1 +
 .../platform/qcom/camss/camss-csiphy-2ph-1-0.c | 173 +
 drivers/media/platform/qcom/camss/camss-csiphy.c   | 171 +++-
 drivers/media/platform/qcom/camss/camss-csiphy.h   |  17 ++
 4 files changed, 214 insertions(+), 148 deletions(-)
 create mode 100644 drivers/media/platform/qcom/camss/camss-csiphy-2ph-1-0.c

diff --git a/drivers/media/platform/qcom/camss/Makefile 
b/drivers/media/platform/qcom/camss/Makefile
index 3c4024f..0446b24 100644
--- a/drivers/media/platform/qcom/camss/Makefile
+++ b/drivers/media/platform/qcom/camss/Makefile
@@ -3,6 +3,7 @@
 qcom-camss-objs += \
camss.o \
camss-csid.o \
+   camss-csiphy-2ph-1-0.o \
camss-csiphy.o \
camss-ispif.o \
camss-vfe.o \
diff --git a/drivers/media/platform/qcom/camss/camss-csiphy-2ph-1-0.c 
b/drivers/media/platform/qcom/camss/camss-csiphy-2ph-1-0.c
new file mode 100644
index 000..7325906
--- /dev/null
+++ b/drivers/media/platform/qcom/camss/camss-csiphy-2ph-1-0.c
@@ -0,0 +1,173 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * camss-csiphy-2ph-1-0.c
+ *
+ * Qualcomm MSM Camera Subsystem - CSIPHY Module 2phase v1.0
+ *
+ * Copyright (c) 2011-2015, The Linux Foundation. All rights reserved.
+ * Copyright (C) 2016-2018 Linaro Ltd.
+ */
+
+#include "camss-csiphy.h"
+
+#include 
+#include 
+
+#define CAMSS_CSI_PHY_LNn_CFG2(n)  (0x004 + 0x40 * (n))
+#define CAMSS_CSI_PHY_LNn_CFG3(n)  (0x008 + 0x40 * (n))
+#define CAMSS_CSI_PHY_GLBL_RESET   0x140
+#define CAMSS_CSI_PHY_GLBL_PWR_CFG 0x144
+#define CAMSS_CSI_PHY_GLBL_IRQ_CMD 0x164
+#define CAMSS_CSI_PHY_HW_VERSION   0x188
+#define CAMSS_CSI_PHY_INTERRUPT_STATUSn(n) (0x18c + 0x4 * (n))
+#define CAMSS_CSI_PHY_INTERRUPT_MASKn(n)   (0x1ac + 0x4 * (n))
+#define CAMSS_CSI_PHY_INTERRUPT_CLEARn(n)  (0x1cc + 0x4 * (n))
+#define CAMSS_CSI_PHY_GLBL_T_INIT_CFG0 0x1ec
+#define CAMSS_CSI_PHY_T_WAKEUP_CFG00x1f4
+
+static void csiphy_hw_version_read(struct csiphy_device *csiphy,
+  struct device *dev)
+{
+   u8 hw_version = readl_relaxed(csiphy->base +
+ CAMSS_CSI_PHY_HW_VERSION);
+
+   dev_dbg(dev, "CSIPHY HW Version = 0x%02x\n", hw_version);
+}
+
+/*
+ * csiphy_reset - Perform software reset on CSIPHY module
+ * @csiphy: CSIPHY device
+ */
+static void csiphy_reset(struct csiphy_device *csiphy)
+{
+   writel_relaxed(0x1, csiphy->base + CAMSS_CSI_PHY_GLBL_RESET);
+   usleep_range(5000, 8000);
+   writel_relaxed(0x0, csiphy->base + CAMSS_CSI_PHY_GLBL_RESET);
+}
+
+/*
+ * csiphy_settle_cnt_calc - Calculate settle count value
+ *
+ * Helper function to calculate settle count value. This is
+ * based on the CSI2 T_hs_settle parameter which in turn
+ * is calculated based on the CSI2 transmitter pixel clock
+ * frequency.
+ *
+ * Return settle count value or 0 if the CSI2 pixel clock
+ * frequency is not available
+ */
+static u8 csiphy_settle_cnt_calc(u32 pixel_clock, u8 bpp, u8 num_lanes,
+u32 timer_clk_rate)
+{
+   u32 mipi_clock; /* Hz */
+   u32 ui; /* ps */
+   u32 timer_period; /* ps */
+   u32 t_hs_prepare_max; /* ps */
+   u32 t_hs_prepare_zero_min; /* ps */
+   u32 t_hs_settle; /* ps */
+   u8 settle_cnt;
+
+   mipi_clock = pixel_clock * bpp / (2 * num_lanes);
+   ui = div_u64(1LL, mipi_clock);
+   ui /= 2;
+   t_hs_prepare_max = 85000 + 6 * ui;
+   t_hs_prepare_zero_min = 145000 + 10 * ui;
+   t_hs_settle = (t_hs_prepare_max + t_hs_prepare_zero_min) / 2;
+
+   timer_period = div_u64(1LL, timer_clk_rate);
+   settle_cnt = t_hs_settle / timer_period - 1;
+
+   return settle_cnt;
+}
+
+static void csiphy_lanes_enable(struct csiphy_device *csiphy,
+   struct csiphy_config *cfg,
+   u32 pixel_clock, u8 bpp, u8 lane_mask)
+{
+   struct csiphy_lanes_cfg *c = >csi2->lane_cfg;
+   u8 settle_cnt;
+   u8 val;
+   int i = 0;
+
+   settle_cnt = csiphy_settle_cnt_calc(pixel_clock, bpp, c->num_data,
+   csiphy->timer_clk_rate);
+
+   writel_relaxed(0x1, csiphy->base +
+  CAMSS_CSI_PHY_GLBL_T_INIT_CFG0);
+   writel_relaxed(0x1, csiphy->base +
+  CAMSS_CSI_PHY_T_WAKEUP_CFG0);
+
+   val = 0x1;
+   val |= lane_mask << 1;
+   writel_relaxed(val, csiphy->base + CAMSS_CSI_PHY_GLBL_PWR_CFG);
+
+   val = cfg->combo_mode << 4;
+   writel_relaxed(val, csiphy->base + CAMSS_CSI_PHY_GLBL_RESET

[PATCH v4 34/34] media: camss: csid: Add support for events triggered by user controls

2018-07-25 Thread Todor Tomov
Changing a user control value can trigger an event to other
users. Add support for that.

Signed-off-by: Todor Tomov 
Acked-by: Sakari Ailus 
---
 drivers/media/platform/qcom/camss/camss-csid.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/qcom/camss/camss-csid.c 
b/drivers/media/platform/qcom/camss/camss-csid.c
index 6e141af..729b318 100644
--- a/drivers/media/platform/qcom/camss/camss-csid.c
+++ b/drivers/media/platform/qcom/camss/camss-csid.c
@@ -17,6 +17,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #include "camss-csid.h"
@@ -1273,6 +1274,8 @@ static int csid_link_setup(struct media_entity *entity,
 
 static const struct v4l2_subdev_core_ops csid_core_ops = {
.s_power = csid_set_power,
+   .subscribe_event = v4l2_ctrl_subdev_subscribe_event,
+   .unsubscribe_event = v4l2_event_subdev_unsubscribe,
 };
 
 static const struct v4l2_subdev_video_ops csid_video_ops = {
@@ -1318,7 +1321,8 @@ int msm_csid_register_entity(struct csid_device *csid,
 
v4l2_subdev_init(sd, _v4l2_ops);
sd->internal_ops = _v4l2_internal_ops;
-   sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
+   sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE |
+V4L2_SUBDEV_FL_HAS_EVENTS;
snprintf(sd->name, ARRAY_SIZE(sd->name), "%s%d",
 MSM_CSID_NAME, csid->id);
v4l2_set_subdevdata(sd, csid);
-- 
2.7.4



[PATCH v4 25/34] media: camss: vfe: Add support for 8x96

2018-07-25 Thread Todor Tomov
Add VFE hardware dependent part for 8x96.

Signed-off-by: Todor Tomov 
---
 drivers/media/platform/qcom/camss/Makefile |   1 +
 drivers/media/platform/qcom/camss/camss-vfe-4-1.c  |   6 +
 .../camss/{camss-vfe-4-1.c => camss-vfe-4-7.c} | 347 -
 drivers/media/platform/qcom/camss/camss-vfe.c  |   4 +
 drivers/media/platform/qcom/camss/camss-vfe.h  |   2 +
 5 files changed, 209 insertions(+), 151 deletions(-)
 copy drivers/media/platform/qcom/camss/{camss-vfe-4-1.c => camss-vfe-4-7.c} 
(75%)

diff --git a/drivers/media/platform/qcom/camss/Makefile 
b/drivers/media/platform/qcom/camss/Makefile
index 38dc56e..f5e6e25 100644
--- a/drivers/media/platform/qcom/camss/Makefile
+++ b/drivers/media/platform/qcom/camss/Makefile
@@ -8,6 +8,7 @@ qcom-camss-objs += \
camss-csiphy.o \
camss-ispif.o \
camss-vfe-4-1.o \
+   camss-vfe-4-7.o \
camss-vfe.o \
camss-video.o \
 
diff --git a/drivers/media/platform/qcom/camss/camss-vfe-4-1.c 
b/drivers/media/platform/qcom/camss/camss-vfe-4-1.c
index 070c0c3..41184dc 100644
--- a/drivers/media/platform/qcom/camss/camss-vfe-4-1.c
+++ b/drivers/media/platform/qcom/camss/camss-vfe-4-1.c
@@ -789,6 +789,11 @@ static void vfe_set_qos(struct vfe_device *vfe)
writel_relaxed(val7, vfe->base + VFE_0_BUS_BDG_QOS_CFG_7);
 }
 
+static void vfe_set_ds(struct vfe_device *vfe)
+{
+   /* empty */
+}
+
 static void vfe_set_cgc_override(struct vfe_device *vfe, u8 wm, u8 enable)
 {
u32 val = VFE_0_CGC_OVERRIDE_1_IMAGE_Mx_CGC_OVERRIDE(wm);
@@ -995,6 +1000,7 @@ const struct vfe_hw_ops vfe_ops_4_1 = {
.set_crop_cfg = vfe_set_crop_cfg,
.set_clamp_cfg = vfe_set_clamp_cfg,
.set_qos = vfe_set_qos,
+   .set_ds = vfe_set_ds,
.set_cgc_override = vfe_set_cgc_override,
.set_camif_cfg = vfe_set_camif_cfg,
.set_camif_cmd = vfe_set_camif_cmd,
diff --git a/drivers/media/platform/qcom/camss/camss-vfe-4-1.c 
b/drivers/media/platform/qcom/camss/camss-vfe-4-7.c
similarity index 75%
copy from drivers/media/platform/qcom/camss/camss-vfe-4-1.c
copy to drivers/media/platform/qcom/camss/camss-vfe-4-7.c
index 070c0c3..45e6711 100644
--- a/drivers/media/platform/qcom/camss/camss-vfe-4-1.c
+++ b/drivers/media/platform/qcom/camss/camss-vfe-4-7.c
@@ -1,8 +1,8 @@
 // SPDX-License-Identifier: GPL-2.0
 /*
- * camss-vfe-4-1.c
+ * camss-vfe-4-7.c
  *
- * Qualcomm MSM Camera Subsystem - VFE (Video Front End) Module v4.1
+ * Qualcomm MSM Camera Subsystem - VFE (Video Front End) Module v4.7
  *
  * Copyright (c) 2013-2015, The Linux Foundation. All rights reserved.
  * Copyright (C) 2015-2018 Linaro Ltd.
@@ -15,33 +15,37 @@
 
 #define VFE_0_HW_VERSION   0x000
 
-#define VFE_0_GLOBAL_RESET_CMD 0x00c
+#define VFE_0_GLOBAL_RESET_CMD 0x018
 #define VFE_0_GLOBAL_RESET_CMD_COREBIT(0)
 #define VFE_0_GLOBAL_RESET_CMD_CAMIF   BIT(1)
 #define VFE_0_GLOBAL_RESET_CMD_BUS BIT(2)
 #define VFE_0_GLOBAL_RESET_CMD_BUS_BDG BIT(3)
 #define VFE_0_GLOBAL_RESET_CMD_REGISTERBIT(4)
-#define VFE_0_GLOBAL_RESET_CMD_TIMER   BIT(5)
-#define VFE_0_GLOBAL_RESET_CMD_PM  BIT(6)
-#define VFE_0_GLOBAL_RESET_CMD_BUS_MISRBIT(7)
-#define VFE_0_GLOBAL_RESET_CMD_TESTGEN BIT(8)
-
-#define VFE_0_MODULE_CFG   0x018
-#define VFE_0_MODULE_CFG_DEMUX BIT(2)
-#define VFE_0_MODULE_CFG_CHROMA_UPSAMPLE   BIT(3)
-#define VFE_0_MODULE_CFG_SCALE_ENC BIT(23)
-#define VFE_0_MODULE_CFG_CROP_ENC  BIT(27)
-
-#define VFE_0_CORE_CFG 0x01c
+#define VFE_0_GLOBAL_RESET_CMD_PM  BIT(5)
+#define VFE_0_GLOBAL_RESET_CMD_BUS_MISRBIT(6)
+#define VFE_0_GLOBAL_RESET_CMD_TESTGEN BIT(7)
+#define VFE_0_GLOBAL_RESET_CMD_DSP BIT(8)
+#define VFE_0_GLOBAL_RESET_CMD_IDLE_CGCBIT(9)
+
+#define VFE_0_MODULE_LENS_EN   0x040
+#define VFE_0_MODULE_LENS_EN_DEMUX BIT(2)
+#define VFE_0_MODULE_LENS_EN_CHROMA_UPSAMPLE   BIT(3)
+
+#define VFE_0_MODULE_ZOOM_EN   0x04c
+#define VFE_0_MODULE_ZOOM_EN_SCALE_ENC BIT(1)
+#define VFE_0_MODULE_ZOOM_EN_CROP_ENC  BIT(2)
+
+#define VFE_0_CORE_CFG 0x050
 #define VFE_0_CORE_CFG_PIXEL_PATTERN_YCBYCR0x4
 #define VFE_0_CORE_CFG_PIXEL_PATTERN_YCRYCB0x5
 #define VFE_0_CORE_CFG_PIXEL_PATTERN_CBYCRY0x6
 #define VFE_0_CORE_CFG_PIXEL_PATTERN_CRYCBY0x7
+#define VFE_0_CORE_CFG_COMPOSITE_REG_UPDATE_EN BIT(4)
 
-#define VFE_0_IRQ_CMD  0x024
+#define VFE_0_IRQ_CMD  0x058
 #define VFE_0_IRQ_CMD_GLOBAL_CLEAR BIT(0)
 
-#define VFE_0_IRQ_MASK_0   0x028
+#define VFE_0_IRQ_MASK_0   0x05c
 #define VFE_0_IRQ_MASK_0_CAMIF_SOF BIT(0)
 #define VFE_0_IRQ_MASK_0_CAMIF_EOF BIT(1)
 #define VFE_0_IRQ_MASK_0_RDIn_REG_UPDATE(n)BIT((n) + 5)
@@ -50,17 +54,17 @@

[PATCH v4 26/34] media: camss: Format configuration per hardware version

2018-07-25 Thread Todor Tomov
As the 8x16 and 8x96 support different formats, separate the
arrays which contain the supported formats. For the VFE also
add separate arrays for RDI and PIX subdevices.

Signed-off-by: Todor Tomov 
---
 drivers/media/platform/qcom/camss/camss-csid.c   | 196 +++
 drivers/media/platform/qcom/camss/camss-csid.h   |   2 +
 drivers/media/platform/qcom/camss/camss-csiphy.c | 145 -
 drivers/media/platform/qcom/camss/camss-csiphy.h |   2 +
 drivers/media/platform/qcom/camss/camss-ispif.c  |  43 -
 drivers/media/platform/qcom/camss/camss-ispif.h  |   2 +
 drivers/media/platform/qcom/camss/camss-vfe.c| 189 --
 drivers/media/platform/qcom/camss/camss-vfe.h|   2 +
 drivers/media/platform/qcom/camss/camss-video.c  |  97 ++-
 9 files changed, 467 insertions(+), 211 deletions(-)

diff --git a/drivers/media/platform/qcom/camss/camss-csid.c 
b/drivers/media/platform/qcom/camss/camss-csid.c
index 915835e..db960da 100644
--- a/drivers/media/platform/qcom/camss/camss-csid.c
+++ b/drivers/media/platform/qcom/camss/camss-csid.c
@@ -62,7 +62,7 @@
 
 #define CSID_RESET_TIMEOUT_MS 500
 
-struct csid_fmts {
+struct csid_format {
u32 code;
u8 data_type;
u8 decode_format;
@@ -70,7 +70,7 @@ struct csid_fmts {
u8 spp; /* bus samples per pixel */
 };
 
-static const struct csid_fmts csid_input_fmts[] = {
+static const struct csid_format csid_formats_8x16[] = {
{
MEDIA_BUS_FMT_UYVY8_2X8,
DATA_TYPE_YUV422_8BIT,
@@ -185,17 +185,135 @@ static const struct csid_fmts csid_input_fmts[] = {
}
 };
 
-static const struct csid_fmts *csid_get_fmt_entry(u32 code)
+static const struct csid_format csid_formats_8x96[] = {
+   {
+   MEDIA_BUS_FMT_UYVY8_2X8,
+   DATA_TYPE_YUV422_8BIT,
+   DECODE_FORMAT_UNCOMPRESSED_8_BIT,
+   8,
+   2,
+   },
+   {
+   MEDIA_BUS_FMT_VYUY8_2X8,
+   DATA_TYPE_YUV422_8BIT,
+   DECODE_FORMAT_UNCOMPRESSED_8_BIT,
+   8,
+   2,
+   },
+   {
+   MEDIA_BUS_FMT_YUYV8_2X8,
+   DATA_TYPE_YUV422_8BIT,
+   DECODE_FORMAT_UNCOMPRESSED_8_BIT,
+   8,
+   2,
+   },
+   {
+   MEDIA_BUS_FMT_YVYU8_2X8,
+   DATA_TYPE_YUV422_8BIT,
+   DECODE_FORMAT_UNCOMPRESSED_8_BIT,
+   8,
+   2,
+   },
+   {
+   MEDIA_BUS_FMT_SBGGR8_1X8,
+   DATA_TYPE_RAW_8BIT,
+   DECODE_FORMAT_UNCOMPRESSED_8_BIT,
+   8,
+   1,
+   },
+   {
+   MEDIA_BUS_FMT_SGBRG8_1X8,
+   DATA_TYPE_RAW_8BIT,
+   DECODE_FORMAT_UNCOMPRESSED_8_BIT,
+   8,
+   1,
+   },
+   {
+   MEDIA_BUS_FMT_SGRBG8_1X8,
+   DATA_TYPE_RAW_8BIT,
+   DECODE_FORMAT_UNCOMPRESSED_8_BIT,
+   8,
+   1,
+   },
+   {
+   MEDIA_BUS_FMT_SRGGB8_1X8,
+   DATA_TYPE_RAW_8BIT,
+   DECODE_FORMAT_UNCOMPRESSED_8_BIT,
+   8,
+   1,
+   },
+   {
+   MEDIA_BUS_FMT_SBGGR10_1X10,
+   DATA_TYPE_RAW_10BIT,
+   DECODE_FORMAT_UNCOMPRESSED_10_BIT,
+   10,
+   1,
+   },
+   {
+   MEDIA_BUS_FMT_SGBRG10_1X10,
+   DATA_TYPE_RAW_10BIT,
+   DECODE_FORMAT_UNCOMPRESSED_10_BIT,
+   10,
+   1,
+   },
+   {
+   MEDIA_BUS_FMT_SGRBG10_1X10,
+   DATA_TYPE_RAW_10BIT,
+   DECODE_FORMAT_UNCOMPRESSED_10_BIT,
+   10,
+   1,
+   },
+   {
+   MEDIA_BUS_FMT_SRGGB10_1X10,
+   DATA_TYPE_RAW_10BIT,
+   DECODE_FORMAT_UNCOMPRESSED_10_BIT,
+   10,
+   1,
+   },
+   {
+   MEDIA_BUS_FMT_SBGGR12_1X12,
+   DATA_TYPE_RAW_12BIT,
+   DECODE_FORMAT_UNCOMPRESSED_12_BIT,
+   12,
+   1,
+   },
+   {
+   MEDIA_BUS_FMT_SGBRG12_1X12,
+   DATA_TYPE_RAW_12BIT,
+   DECODE_FORMAT_UNCOMPRESSED_12_BIT,
+   12,
+   1,
+   },
+   {
+   MEDIA_BUS_FMT_SGRBG12_1X12,
+   DATA_TYPE_RAW_12BIT,
+   DECODE_FORMAT_UNCOMPRESSED_12_BIT,
+   12,
+   1,
+   },
+   {
+   MEDIA_BUS_FMT_SRGGB12_1X12,
+   DATA_TYPE_RAW_12BIT,
+   DECODE_FORMAT_UNCOMPRESSED_12_BIT,
+   12,
+   1,
+   }
+};
+
+static const struct csid_format *csid_get_fmt_entry(
+   const struct csid_format *formats,
+   unsigned int nformat

[PATCH v4 31/34] media: camss: Add support for RAW MIPI14 on 8x96

2018-07-25 Thread Todor Tomov
Add support for RAW MIPI14 format for RDI mode on 8x96.

Signed-off-by: Todor Tomov 
---
 drivers/media/platform/qcom/camss/camss-csid.c   | 30 
 drivers/media/platform/qcom/camss/camss-csiphy.c |  4 
 drivers/media/platform/qcom/camss/camss-ispif.c  |  4 
 drivers/media/platform/qcom/camss/camss-vfe.c|  4 
 drivers/media/platform/qcom/camss/camss-video.c  |  8 +++
 5 files changed, 50 insertions(+)

diff --git a/drivers/media/platform/qcom/camss/camss-csid.c 
b/drivers/media/platform/qcom/camss/camss-csid.c
index 0715a8e..472884d 100644
--- a/drivers/media/platform/qcom/camss/camss-csid.c
+++ b/drivers/media/platform/qcom/camss/camss-csid.c
@@ -63,11 +63,13 @@
 #define DATA_TYPE_RAW_8BIT 0x2a
 #define DATA_TYPE_RAW_10BIT0x2b
 #define DATA_TYPE_RAW_12BIT0x2c
+#define DATA_TYPE_RAW_14BIT0x2d
 
 #define DECODE_FORMAT_UNCOMPRESSED_6_BIT   0x0
 #define DECODE_FORMAT_UNCOMPRESSED_8_BIT   0x1
 #define DECODE_FORMAT_UNCOMPRESSED_10_BIT  0x2
 #define DECODE_FORMAT_UNCOMPRESSED_12_BIT  0x3
+#define DECODE_FORMAT_UNCOMPRESSED_14_BIT  0x8
 
 #define CSID_RESET_TIMEOUT_MS 500
 
@@ -306,6 +308,34 @@ static const struct csid_format csid_formats_8x96[] = {
DECODE_FORMAT_UNCOMPRESSED_12_BIT,
12,
1,
+   },
+   {
+   MEDIA_BUS_FMT_SBGGR14_1X14,
+   DATA_TYPE_RAW_14BIT,
+   DECODE_FORMAT_UNCOMPRESSED_14_BIT,
+   14,
+   1,
+   },
+   {
+   MEDIA_BUS_FMT_SGBRG14_1X14,
+   DATA_TYPE_RAW_14BIT,
+   DECODE_FORMAT_UNCOMPRESSED_14_BIT,
+   14,
+   1,
+   },
+   {
+   MEDIA_BUS_FMT_SGRBG14_1X14,
+   DATA_TYPE_RAW_14BIT,
+   DECODE_FORMAT_UNCOMPRESSED_14_BIT,
+   14,
+   1,
+   },
+   {
+   MEDIA_BUS_FMT_SRGGB14_1X14,
+   DATA_TYPE_RAW_14BIT,
+   DECODE_FORMAT_UNCOMPRESSED_14_BIT,
+   14,
+   1,
}
 };
 
diff --git a/drivers/media/platform/qcom/camss/camss-csiphy.c 
b/drivers/media/platform/qcom/camss/camss-csiphy.c
index 3cdab59..cae3e8b 100644
--- a/drivers/media/platform/qcom/camss/camss-csiphy.c
+++ b/drivers/media/platform/qcom/camss/camss-csiphy.c
@@ -64,6 +64,10 @@ static const struct csiphy_format csiphy_formats_8x96[] = {
{ MEDIA_BUS_FMT_SGBRG12_1X12, 12 },
{ MEDIA_BUS_FMT_SGRBG12_1X12, 12 },
{ MEDIA_BUS_FMT_SRGGB12_1X12, 12 },
+   { MEDIA_BUS_FMT_SBGGR14_1X14, 14 },
+   { MEDIA_BUS_FMT_SGBRG14_1X14, 14 },
+   { MEDIA_BUS_FMT_SGRBG14_1X14, 14 },
+   { MEDIA_BUS_FMT_SRGGB14_1X14, 14 },
 };
 
 /*
diff --git a/drivers/media/platform/qcom/camss/camss-ispif.c 
b/drivers/media/platform/qcom/camss/camss-ispif.c
index 81d6351..3e2f341 100644
--- a/drivers/media/platform/qcom/camss/camss-ispif.c
+++ b/drivers/media/platform/qcom/camss/camss-ispif.c
@@ -140,6 +140,10 @@ static const u32 ispif_formats_8x96[] = {
MEDIA_BUS_FMT_SGBRG12_1X12,
MEDIA_BUS_FMT_SGRBG12_1X12,
MEDIA_BUS_FMT_SRGGB12_1X12,
+   MEDIA_BUS_FMT_SBGGR14_1X14,
+   MEDIA_BUS_FMT_SGBRG14_1X14,
+   MEDIA_BUS_FMT_SGRBG14_1X14,
+   MEDIA_BUS_FMT_SRGGB14_1X14,
 };
 
 /*
diff --git a/drivers/media/platform/qcom/camss/camss-vfe.c 
b/drivers/media/platform/qcom/camss/camss-vfe.c
index 11d37b7..9675309 100644
--- a/drivers/media/platform/qcom/camss/camss-vfe.c
+++ b/drivers/media/platform/qcom/camss/camss-vfe.c
@@ -94,6 +94,10 @@ static const struct vfe_format formats_rdi_8x96[] = {
{ MEDIA_BUS_FMT_SGBRG12_1X12, 12 },
{ MEDIA_BUS_FMT_SGRBG12_1X12, 12 },
{ MEDIA_BUS_FMT_SRGGB12_1X12, 12 },
+   { MEDIA_BUS_FMT_SBGGR14_1X14, 14 },
+   { MEDIA_BUS_FMT_SGBRG14_1X14, 14 },
+   { MEDIA_BUS_FMT_SGRBG14_1X14, 14 },
+   { MEDIA_BUS_FMT_SRGGB14_1X14, 14 },
 };
 
 static const struct vfe_format formats_pix_8x96[] = {
diff --git a/drivers/media/platform/qcom/camss/camss-video.c 
b/drivers/media/platform/qcom/camss/camss-video.c
index 28d53bf..2e19bc8 100644
--- a/drivers/media/platform/qcom/camss/camss-video.c
+++ b/drivers/media/platform/qcom/camss/camss-video.c
@@ -111,6 +111,14 @@ static const struct camss_format_info formats_rdi_8x96[] = 
{
  { { 1, 1 } }, { { 1, 1 } }, { 12 } },
{ MEDIA_BUS_FMT_SRGGB12_1X12, V4L2_PIX_FMT_SRGGB12P, 1,
  { { 1, 1 } }, { { 1, 1 } }, { 12 } },
+   { MEDIA_BUS_FMT_SBGGR14_1X14, V4L2_PIX_FMT_SBGGR14P, 1,
+ { { 1, 1 } }, { { 1, 1 } }, { 14 } },
+   { MEDIA_BUS_FMT_SGBRG14_1X14, V4L2_PIX_FMT_SGBRG14P, 1,
+ { { 1, 1 } }, { { 1, 1 } }, { 14 } },
+   { MEDIA_BUS_FMT_SGRBG14_1X14, V4L2_PIX_FMT_SGRBG14P, 1,
+ { { 1, 1 } }, { { 1, 1 } }, { 14 } },
+   { MEDIA_BUS_FMT_SRGGB14_1X14, V4L2_PIX_FMT_SRGGB14P, 1,
+ { { 1, 1 } }, { { 1, 1 } }, { 14

[PATCH v4 17/34] media: camss: Add 8x96 resources

2018-07-25 Thread Todor Tomov
Add structs with 8x96 resources. As the number of CSIPHY, CSID
and VFE hardware modules is different on 8x16 and 8x96 select
the number at runtime and allocate needed structures
dynamically.

Signed-off-by: Todor Tomov 
---
 drivers/media/platform/qcom/camss/camss-csid.c   |  20 +-
 drivers/media/platform/qcom/camss/camss-csid.h   |   3 +-
 drivers/media/platform/qcom/camss/camss-csiphy.c |  19 +-
 drivers/media/platform/qcom/camss/camss-csiphy.h |   4 +-
 drivers/media/platform/qcom/camss/camss-ispif.c  |  35 ++-
 drivers/media/platform/qcom/camss/camss-ispif.h  |   9 +-
 drivers/media/platform/qcom/camss/camss-vfe.c|  61 ++--
 drivers/media/platform/qcom/camss/camss-vfe.h|   4 +-
 drivers/media/platform/qcom/camss/camss.c| 354 ++-
 drivers/media/platform/qcom/camss/camss.h|  20 +-
 10 files changed, 390 insertions(+), 139 deletions(-)

diff --git a/drivers/media/platform/qcom/camss/camss-csid.c 
b/drivers/media/platform/qcom/camss/camss-csid.c
index 3cde07e..627ef44 100644
--- a/drivers/media/platform/qcom/camss/camss-csid.c
+++ b/drivers/media/platform/qcom/camss/camss-csid.c
@@ -219,7 +219,7 @@ static irqreturn_t csid_isr(int irq, void *dev)
  */
 static int csid_set_clock_rates(struct csid_device *csid)
 {
-   struct device *dev = to_device_index(csid, csid->id);
+   struct device *dev = csid->camss->dev;
u32 pixel_clock;
int i, j;
int ret;
@@ -232,7 +232,9 @@ static int csid_set_clock_rates(struct csid_device *csid)
struct camss_clock *clock = >clock[i];
 
if (!strcmp(clock->name, "csi0") ||
-   !strcmp(clock->name, "csi1")) {
+   !strcmp(clock->name, "csi1") ||
+   !strcmp(clock->name, "csi2") ||
+   !strcmp(clock->name, "csi3")) {
u8 bpp = csid_get_fmt_entry(
csid->fmt[MSM_CSIPHY_PAD_SINK].code)->bpp;
u8 num_lanes = csid->phy.lane_cnt;
@@ -291,8 +293,7 @@ static int csid_reset(struct csid_device *csid)
time = wait_for_completion_timeout(>reset_complete,
msecs_to_jiffies(CSID_RESET_TIMEOUT_MS));
if (!time) {
-   dev_err(to_device_index(csid, csid->id),
-   "CSID reset timeout\n");
+   dev_err(csid->camss->dev, "CSID reset timeout\n");
return -EIO;
}
 
@@ -309,7 +310,7 @@ static int csid_reset(struct csid_device *csid)
 static int csid_set_power(struct v4l2_subdev *sd, int on)
 {
struct csid_device *csid = v4l2_get_subdevdata(sd);
-   struct device *dev = to_device_index(csid, csid->id);
+   struct device *dev = csid->camss->dev;
int ret;
 
if (on) {
@@ -375,7 +376,7 @@ static int csid_set_stream(struct v4l2_subdev *sd, int 
enable)
 
ret = v4l2_ctrl_handler_setup(>ctrls);
if (ret < 0) {
-   dev_err(to_device_index(csid, csid->id),
+   dev_err(csid->camss->dev,
"could not sync v4l2 controls: %d\n", ret);
return ret;
}
@@ -796,15 +797,16 @@ static const struct v4l2_ctrl_ops csid_ctrl_ops = {
  *
  * Return 0 on success or a negative error code otherwise
  */
-int msm_csid_subdev_init(struct csid_device *csid,
+int msm_csid_subdev_init(struct camss *camss, struct csid_device *csid,
 const struct resources *res, u8 id)
 {
-   struct device *dev = to_device_index(csid, id);
+   struct device *dev = camss->dev;
struct platform_device *pdev = to_platform_device(dev);
struct resource *r;
int i, j;
int ret;
 
+   csid->camss = camss;
csid->id = id;
 
/* Memory */
@@ -1018,7 +1020,7 @@ int msm_csid_register_entity(struct csid_device *csid,
 {
struct v4l2_subdev *sd = >subdev;
struct media_pad *pads = csid->pads;
-   struct device *dev = to_device_index(csid, csid->id);
+   struct device *dev = csid->camss->dev;
int ret;
 
v4l2_subdev_init(sd, _v4l2_ops);
diff --git a/drivers/media/platform/qcom/camss/camss-csid.h 
b/drivers/media/platform/qcom/camss/camss-csid.h
index ae1d045..ed605fd 100644
--- a/drivers/media/platform/qcom/camss/camss-csid.h
+++ b/drivers/media/platform/qcom/camss/camss-csid.h
@@ -42,6 +42,7 @@ struct csid_phy_config {
 };
 
 struct csid_device {
+   struct camss *camss;
u8 id;
struct v4l2_subdev subdev;
struct media_pad pads[MSM_CSID_PADS_NUM];
@@ -61,7 +62,7 @@ struct csid_device {
 
 struct resources;
 
-int msm_csid_subdev_init(struct csid_device *csid,
+int msm_csid_subdev_init(struct camss *camss, struct csid_device *csid,

[PATCH v4 13/34] media: camss: vfe: Get line pointer as container of video_out

2018-07-25 Thread Todor Tomov
Simplify getting of the line pointer by using the container_of
macro instead of traversing media controller links.

Signed-off-by: Todor Tomov 
---
 drivers/media/platform/qcom/camss/camss-vfe.c | 38 +++
 1 file changed, 4 insertions(+), 34 deletions(-)

diff --git a/drivers/media/platform/qcom/camss/camss-vfe.c 
b/drivers/media/platform/qcom/camss/camss-vfe.c
index 51ad3f8..77167f1 100644
--- a/drivers/media/platform/qcom/camss/camss-vfe.c
+++ b/drivers/media/platform/qcom/camss/camss-vfe.c
@@ -2038,26 +2038,6 @@ static void vfe_put(struct vfe_device *vfe)
 }
 
 /*
- * vfe_video_pad_to_line - Get pointer to VFE line by media pad
- * @pad: Media pad
- *
- * Return pointer to vfe line structure
- */
-static struct vfe_line *vfe_video_pad_to_line(struct media_pad *pad)
-{
-   struct media_pad *vfe_pad;
-   struct v4l2_subdev *subdev;
-
-   vfe_pad = media_entity_remote_pad(pad);
-   if (vfe_pad == NULL)
-   return NULL;
-
-   subdev = media_entity_to_v4l2_subdev(vfe_pad->entity);
-
-   return container_of(subdev, struct vfe_line, subdev);
-}
-
-/*
  * vfe_queue_buffer - Add empty buffer
  * @vid: Video device structure
  * @buf: Buffer to be enqueued
@@ -2070,16 +2050,11 @@ static struct vfe_line *vfe_video_pad_to_line(struct 
media_pad *pad)
 static int vfe_queue_buffer(struct camss_video *vid,
struct camss_buffer *buf)
 {
-   struct vfe_device *vfe = >camss->vfe;
-   struct vfe_line *line;
+   struct vfe_line *line = container_of(vid, struct vfe_line, video_out);
+   struct vfe_device *vfe = to_vfe(line);
struct vfe_output *output;
unsigned long flags;
 
-   line = vfe_video_pad_to_line(>pad);
-   if (!line) {
-   dev_err(to_device(vfe), "Can not queue buffer\n");
-   return -1;
-   }
output = >output;
 
spin_lock_irqsave(>output_lock, flags);
@@ -2104,16 +2079,11 @@ static int vfe_queue_buffer(struct camss_video *vid,
 static int vfe_flush_buffers(struct camss_video *vid,
 enum vb2_buffer_state state)
 {
-   struct vfe_device *vfe = >camss->vfe;
-   struct vfe_line *line;
+   struct vfe_line *line = container_of(vid, struct vfe_line, video_out);
+   struct vfe_device *vfe = to_vfe(line);
struct vfe_output *output;
unsigned long flags;
 
-   line = vfe_video_pad_to_line(>pad);
-   if (!line) {
-   dev_err(to_device(vfe), "Can not flush buffers\n");
-   return -1;
-   }
output = >output;
 
spin_lock_irqsave(>output_lock, flags);
-- 
2.7.4



[PATCH v4 24/34] media: camss: vfe: Split to hardware dependent and independent parts

2018-07-25 Thread Todor Tomov
This will allow to add support for different hardware.

Signed-off-by: Todor Tomov 
---
 drivers/media/platform/qcom/camss/Makefile|1 +
 drivers/media/platform/qcom/camss/camss-vfe-4-1.c | 1006 +++
 drivers/media/platform/qcom/camss/camss-vfe.c | 1074 ++---
 drivers/media/platform/qcom/camss/camss-vfe.h |   73 +-
 4 files changed, 1169 insertions(+), 985 deletions(-)
 create mode 100644 drivers/media/platform/qcom/camss/camss-vfe-4-1.c

diff --git a/drivers/media/platform/qcom/camss/Makefile 
b/drivers/media/platform/qcom/camss/Makefile
index 36b9f7c..38dc56e 100644
--- a/drivers/media/platform/qcom/camss/Makefile
+++ b/drivers/media/platform/qcom/camss/Makefile
@@ -7,6 +7,7 @@ qcom-camss-objs += \
camss-csiphy-3ph-1-0.o \
camss-csiphy.o \
camss-ispif.o \
+   camss-vfe-4-1.o \
camss-vfe.o \
camss-video.o \
 
diff --git a/drivers/media/platform/qcom/camss/camss-vfe-4-1.c 
b/drivers/media/platform/qcom/camss/camss-vfe-4-1.c
new file mode 100644
index 000..070c0c3
--- /dev/null
+++ b/drivers/media/platform/qcom/camss/camss-vfe-4-1.c
@@ -0,0 +1,1006 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * camss-vfe-4-1.c
+ *
+ * Qualcomm MSM Camera Subsystem - VFE (Video Front End) Module v4.1
+ *
+ * Copyright (c) 2013-2015, The Linux Foundation. All rights reserved.
+ * Copyright (C) 2015-2018 Linaro Ltd.
+ */
+
+#include 
+#include 
+
+#include "camss-vfe.h"
+
+#define VFE_0_HW_VERSION   0x000
+
+#define VFE_0_GLOBAL_RESET_CMD 0x00c
+#define VFE_0_GLOBAL_RESET_CMD_COREBIT(0)
+#define VFE_0_GLOBAL_RESET_CMD_CAMIF   BIT(1)
+#define VFE_0_GLOBAL_RESET_CMD_BUS BIT(2)
+#define VFE_0_GLOBAL_RESET_CMD_BUS_BDG BIT(3)
+#define VFE_0_GLOBAL_RESET_CMD_REGISTERBIT(4)
+#define VFE_0_GLOBAL_RESET_CMD_TIMER   BIT(5)
+#define VFE_0_GLOBAL_RESET_CMD_PM  BIT(6)
+#define VFE_0_GLOBAL_RESET_CMD_BUS_MISRBIT(7)
+#define VFE_0_GLOBAL_RESET_CMD_TESTGEN BIT(8)
+
+#define VFE_0_MODULE_CFG   0x018
+#define VFE_0_MODULE_CFG_DEMUX BIT(2)
+#define VFE_0_MODULE_CFG_CHROMA_UPSAMPLE   BIT(3)
+#define VFE_0_MODULE_CFG_SCALE_ENC BIT(23)
+#define VFE_0_MODULE_CFG_CROP_ENC  BIT(27)
+
+#define VFE_0_CORE_CFG 0x01c
+#define VFE_0_CORE_CFG_PIXEL_PATTERN_YCBYCR0x4
+#define VFE_0_CORE_CFG_PIXEL_PATTERN_YCRYCB0x5
+#define VFE_0_CORE_CFG_PIXEL_PATTERN_CBYCRY0x6
+#define VFE_0_CORE_CFG_PIXEL_PATTERN_CRYCBY0x7
+
+#define VFE_0_IRQ_CMD  0x024
+#define VFE_0_IRQ_CMD_GLOBAL_CLEAR BIT(0)
+
+#define VFE_0_IRQ_MASK_0   0x028
+#define VFE_0_IRQ_MASK_0_CAMIF_SOF BIT(0)
+#define VFE_0_IRQ_MASK_0_CAMIF_EOF BIT(1)
+#define VFE_0_IRQ_MASK_0_RDIn_REG_UPDATE(n)BIT((n) + 5)
+#define VFE_0_IRQ_MASK_0_line_n_REG_UPDATE(n)  \
+   ((n) == VFE_LINE_PIX ? BIT(4) : VFE_0_IRQ_MASK_0_RDIn_REG_UPDATE(n))
+#define VFE_0_IRQ_MASK_0_IMAGE_MASTER_n_PING_PONG(n)   BIT((n) + 8)
+#define VFE_0_IRQ_MASK_0_IMAGE_COMPOSITE_DONE_n(n) BIT((n) + 25)
+#define VFE_0_IRQ_MASK_0_RESET_ACK BIT(31)
+#define VFE_0_IRQ_MASK_1   0x02c
+#define VFE_0_IRQ_MASK_1_CAMIF_ERROR   BIT(0)
+#define VFE_0_IRQ_MASK_1_VIOLATION BIT(7)
+#define VFE_0_IRQ_MASK_1_BUS_BDG_HALT_ACK  BIT(8)
+#define VFE_0_IRQ_MASK_1_IMAGE_MASTER_n_BUS_OVERFLOW(n)BIT((n) + 9)
+#define VFE_0_IRQ_MASK_1_RDIn_SOF(n)   BIT((n) + 29)
+
+#define VFE_0_IRQ_CLEAR_0  0x030
+#define VFE_0_IRQ_CLEAR_1  0x034
+
+#define VFE_0_IRQ_STATUS_0 0x038
+#define VFE_0_IRQ_STATUS_0_CAMIF_SOF   BIT(0)
+#define VFE_0_IRQ_STATUS_0_RDIn_REG_UPDATE(n)  BIT((n) + 5)
+#define VFE_0_IRQ_STATUS_0_line_n_REG_UPDATE(n)\
+   ((n) == VFE_LINE_PIX ? BIT(4) : VFE_0_IRQ_STATUS_0_RDIn_REG_UPDATE(n))
+#define VFE_0_IRQ_STATUS_0_IMAGE_MASTER_n_PING_PONG(n) BIT((n) + 8)
+#define VFE_0_IRQ_STATUS_0_IMAGE_COMPOSITE_DONE_n(n)   BIT((n) + 25)
+#define VFE_0_IRQ_STATUS_0_RESET_ACK   BIT(31)
+#define VFE_0_IRQ_STATUS_1 0x03c
+#define VFE_0_IRQ_STATUS_1_VIOLATION   BIT(7)
+#define VFE_0_IRQ_STATUS_1_BUS_BDG_HALT_ACKBIT(8)
+#define VFE_0_IRQ_STATUS_1_RDIn_SOF(n) BIT((n) + 29)
+
+#define VFE_0_IRQ_COMPOSITE_MASK_0 0x40
+#define VFE_0_VIOLATION_STATUS 0x48
+
+#define VFE_0_BUS_CMD  0x4c
+#define VFE_0_BUS_CMD_Mx_RLD_CMD(x)BIT(x)
+
+#define VFE_0_BUS_CFG  0x050
+
+#define VFE_0_BUS_XBAR_CFG_x(x)(0x58 + 0x4 * ((x) / 2))
+#define VFE_0_BUS_XBAR_CFG_x_M_PAIR_STREAM_EN  BIT(1)
+#define VFE_0_BUS_XBAR_CFG_x_M_PAIR_STREAM_SWAP_INTER_INTRA(0x3 <

[PATCH v4 33/34] media: doc: media/v4l-drivers: Update Qualcomm CAMSS driver document for 8x96

2018-07-25 Thread Todor Tomov
Update the document to describe the support of Camera Subsystem
on MSM8996/APQ8096.

Signed-off-by: Todor Tomov 
---
 Documentation/media/v4l-drivers/qcom_camss.rst |  93 +++---
 .../media/v4l-drivers/qcom_camss_8x96_graph.dot| 104 +
 2 files changed, 164 insertions(+), 33 deletions(-)
 create mode 100644 Documentation/media/v4l-drivers/qcom_camss_8x96_graph.dot

diff --git a/Documentation/media/v4l-drivers/qcom_camss.rst 
b/Documentation/media/v4l-drivers/qcom_camss.rst
index 9e66b7b..f27c8df 100644
--- a/Documentation/media/v4l-drivers/qcom_camss.rst
+++ b/Documentation/media/v4l-drivers/qcom_camss.rst
@@ -7,34 +7,34 @@ Introduction
 
 
 This file documents the Qualcomm Camera Subsystem driver located under
-drivers/media/platform/qcom/camss-8x16.
+drivers/media/platform/qcom/camss.
 
 The current version of the driver supports the Camera Subsystem found on
-Qualcomm MSM8916 and APQ8016 processors.
+Qualcomm MSM8916/APQ8016 and MSM8996/APQ8096 processors.
 
 The driver implements V4L2, Media controller and V4L2 subdev interfaces.
 Camera sensor using V4L2 subdev interface in the kernel is supported.
 
 The driver is implemented using as a reference the Qualcomm Camera Subsystem
-driver for Android as found in Code Aurora [#f1]_.
+driver for Android as found in Code Aurora [#f1]_ [#f2]_.
 
 
 Qualcomm Camera Subsystem hardware
 --
 
-The Camera Subsystem hardware found on 8x16 processors and supported by the
-driver consists of:
+The Camera Subsystem hardware found on 8x16 / 8x96 processors and supported by
+the driver consists of:
 
-- 2 CSIPHY modules. They handle the Physical layer of the CSI2 receivers.
+- 2 / 3 CSIPHY modules. They handle the Physical layer of the CSI2 receivers.
   A separate camera sensor can be connected to each of the CSIPHY module;
-- 2 CSID (CSI Decoder) modules. They handle the Protocol and Application layer
-  of the CSI2 receivers. A CSID can decode data stream from any of the CSIPHY.
-  Each CSID also contains a TG (Test Generator) block which can generate
+- 2 / 4 CSID (CSI Decoder) modules. They handle the Protocol and Application
+  layer of the CSI2 receivers. A CSID can decode data stream from any of the
+  CSIPHY. Each CSID also contains a TG (Test Generator) block which can 
generate
   artificial input data for test purposes;
 - ISPIF (ISP Interface) module. Handles the routing of the data streams from
   the CSIDs to the inputs of the VFE;
-- VFE (Video Front End) module. Contains a pipeline of image processing 
hardware
-  blocks. The VFE has different input interfaces. The PIX (Pixel) input
+- 1 / 2 VFE (Video Front End) module(s). Contain a pipeline of image processing
+  hardware blocks. The VFE has different input interfaces. The PIX (Pixel) 
input
   interface feeds the input data to the image processing pipeline. The image
   processing pipeline contains also a scale and crop module at the end. Three
   RDI (Raw Dump Interface) input interfaces bypass the image processing
@@ -49,18 +49,33 @@ The current version of the driver supports:
 
 - Input from camera sensor via CSIPHY;
 - Generation of test input data by the TG in CSID;
-- RDI interface of VFE - raw dump of the input data to memory.
+- RDI interface of VFE
 
-  Supported formats:
+  - Raw dump of the input data to memory.
 
-  - YUYV/UYVY/YVYU/VYUY (packed YUV 4:2:2 - V4L2_PIX_FMT_YUYV /
-V4L2_PIX_FMT_UYVY / V4L2_PIX_FMT_YVYU / V4L2_PIX_FMT_VYUY);
-  - MIPI RAW8 (8bit Bayer RAW - V4L2_PIX_FMT_SRGGB8 /
-V4L2_PIX_FMT_SGRBG8 / V4L2_PIX_FMT_SGBRG8 / V4L2_PIX_FMT_SBGGR8);
-  - MIPI RAW10 (10bit packed Bayer RAW - V4L2_PIX_FMT_SBGGR10P /
-V4L2_PIX_FMT_SGBRG10P / V4L2_PIX_FMT_SGRBG10P / V4L2_PIX_FMT_SRGGB10P);
-  - MIPI RAW12 (12bit packed Bayer RAW - V4L2_PIX_FMT_SRGGB12P /
-V4L2_PIX_FMT_SGBRG12P / V4L2_PIX_FMT_SGRBG12P / V4L2_PIX_FMT_SRGGB12P).
+Supported formats:
+
+- YUYV/UYVY/YVYU/VYUY (packed YUV 4:2:2 - V4L2_PIX_FMT_YUYV /
+  V4L2_PIX_FMT_UYVY / V4L2_PIX_FMT_YVYU / V4L2_PIX_FMT_VYUY);
+- MIPI RAW8 (8bit Bayer RAW - V4L2_PIX_FMT_SRGGB8 /
+  V4L2_PIX_FMT_SGRBG8 / V4L2_PIX_FMT_SGBRG8 / V4L2_PIX_FMT_SBGGR8);
+- MIPI RAW10 (10bit packed Bayer RAW - V4L2_PIX_FMT_SBGGR10P /
+  V4L2_PIX_FMT_SGBRG10P / V4L2_PIX_FMT_SGRBG10P / V4L2_PIX_FMT_SRGGB10P /
+  V4L2_PIX_FMT_Y10P);
+- MIPI RAW12 (12bit packed Bayer RAW - V4L2_PIX_FMT_SRGGB12P /
+  V4L2_PIX_FMT_SGBRG12P / V4L2_PIX_FMT_SGRBG12P / V4L2_PIX_FMT_SRGGB12P).
+- (8x96 only) MIPI RAW14 (14bit packed Bayer RAW - V4L2_PIX_FMT_SRGGB14P /
+  V4L2_PIX_FMT_SGBRG14P / V4L2_PIX_FMT_SGRBG14P / V4L2_PIX_FMT_SRGGB14P).
+
+  - (8x96 only) Format conversion of the input data.
+
+Supported input formats:
+
+- MIPI RAW10 (10bit packed Bayer RAW - V4L2_PIX_FMT_SBGGR10P / 
V4L2_PIX_FMT_Y10P).
+
+Supported output formats:
+
+- Plain16 RAW10 (10bit unpacked Bayer RAW - V4L2_PIX_FMT_SBGGR10 / 
V4L2_PIX_FMT_Y10

[PATCH v4 18/34] media: camss: Add basic runtime PM support

2018-07-25 Thread Todor Tomov
There is a PM domain for each of the VFE hardware modules. Add
support for basic runtime PM support to be able to control the
PM domains. When a PM domain needs to be powered on - a device
link is created. When a PM domain needs to be powered off -
its device link is removed. This allows separate and
independent control of the PM domains.

Suspend/Resume is still not supported.

Signed-off-by: Todor Tomov 
---
 drivers/media/platform/qcom/camss/camss-csid.c   | 13 -
 drivers/media/platform/qcom/camss/camss-csiphy.c | 15 +-
 drivers/media/platform/qcom/camss/camss-ispif.c  | 26 --
 drivers/media/platform/qcom/camss/camss-vfe.c| 17 +++
 drivers/media/platform/qcom/camss/camss.c| 63 
 drivers/media/platform/qcom/camss/camss.h| 11 +
 6 files changed, 139 insertions(+), 6 deletions(-)

diff --git a/drivers/media/platform/qcom/camss/camss-csid.c 
b/drivers/media/platform/qcom/camss/camss-csid.c
index 627ef44..3ba087f 100644
--- a/drivers/media/platform/qcom/camss/camss-csid.c
+++ b/drivers/media/platform/qcom/camss/camss-csid.c
@@ -13,6 +13,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -316,19 +317,27 @@ static int csid_set_power(struct v4l2_subdev *sd, int on)
if (on) {
u32 hw_version;
 
-   ret = regulator_enable(csid->vdda);
+   ret = pm_runtime_get_sync(dev);
if (ret < 0)
return ret;
 
+   ret = regulator_enable(csid->vdda);
+   if (ret < 0) {
+   pm_runtime_put_sync(dev);
+   return ret;
+   }
+
ret = csid_set_clock_rates(csid);
if (ret < 0) {
regulator_disable(csid->vdda);
+   pm_runtime_put_sync(dev);
return ret;
}
 
ret = camss_enable_clocks(csid->nclocks, csid->clock, dev);
if (ret < 0) {
regulator_disable(csid->vdda);
+   pm_runtime_put_sync(dev);
return ret;
}
 
@@ -339,6 +348,7 @@ static int csid_set_power(struct v4l2_subdev *sd, int on)
disable_irq(csid->irq);
camss_disable_clocks(csid->nclocks, csid->clock);
regulator_disable(csid->vdda);
+   pm_runtime_put_sync(dev);
return ret;
}
 
@@ -348,6 +358,7 @@ static int csid_set_power(struct v4l2_subdev *sd, int on)
disable_irq(csid->irq);
camss_disable_clocks(csid->nclocks, csid->clock);
ret = regulator_disable(csid->vdda);
+   pm_runtime_put_sync(dev);
}
 
return ret;
diff --git a/drivers/media/platform/qcom/camss/camss-csiphy.c 
b/drivers/media/platform/qcom/camss/camss-csiphy.c
index 0383e94..4aeaedb 100644
--- a/drivers/media/platform/qcom/camss/camss-csiphy.c
+++ b/drivers/media/platform/qcom/camss/camss-csiphy.c
@@ -13,6 +13,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -240,13 +241,21 @@ static int csiphy_set_power(struct v4l2_subdev *sd, int 
on)
u8 hw_version;
int ret;
 
-   ret = csiphy_set_clock_rates(csiphy);
+   ret = pm_runtime_get_sync(dev);
if (ret < 0)
return ret;
 
+   ret = csiphy_set_clock_rates(csiphy);
+   if (ret < 0) {
+   pm_runtime_put_sync(dev);
+   return ret;
+   }
+
ret = camss_enable_clocks(csiphy->nclocks, csiphy->clock, dev);
-   if (ret < 0)
+   if (ret < 0) {
+   pm_runtime_put_sync(dev);
return ret;
+   }
 
enable_irq(csiphy->irq);
 
@@ -259,6 +268,8 @@ static int csiphy_set_power(struct v4l2_subdev *sd, int on)
disable_irq(csiphy->irq);
 
camss_disable_clocks(csiphy->nclocks, csiphy->clock);
+
+   pm_runtime_put_sync(dev);
}
 
return 0;
diff --git a/drivers/media/platform/qcom/camss/camss-ispif.c 
b/drivers/media/platform/qcom/camss/camss-ispif.c
index ed50cc5..2c6c0d2 100644
--- a/drivers/media/platform/qcom/camss/camss-ispif.c
+++ b/drivers/media/platform/qcom/camss/camss-ispif.c
@@ -14,6 +14,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -169,6 +170,14 @@ static int ispif_reset(struct ispif_device *ispif)
u32 val;
int ret;
 
+   ret = camss_pm_domain_on(to_camss(ispif), PM_DOMAIN_VFE0);
+   if (ret < 0)
+   return ret;
+
+   ret = camss_pm_domain_on(to_camss(

[PATCH v4 01/34] doc-rst: Add packed Bayer raw14 pixel formats

2018-07-25 Thread Todor Tomov
From: Sakari Ailus 

These formats are compressed 14-bit raw bayer formats with four different
pixel orders. They are similar to 10-bit variants. The formats added by
this patch are

V4L2_PIX_FMT_SBGGR14P
V4L2_PIX_FMT_SGBRG14P
V4L2_PIX_FMT_SGRBG14P
V4L2_PIX_FMT_SRGGB14P

Signed-off-by: Sakari Ailus 
Acked-by: Hans Verkuil 
Signed-off-by: Todor Tomov 
---
 Documentation/media/uapi/v4l/pixfmt-rgb.rst  |   1 +
 Documentation/media/uapi/v4l/pixfmt-srggb14p.rst | 127 +++
 drivers/media/v4l2-core/v4l2-ioctl.c |   4 +
 include/uapi/linux/videodev2.h   |   5 +
 4 files changed, 137 insertions(+)
 create mode 100644 Documentation/media/uapi/v4l/pixfmt-srggb14p.rst

diff --git a/Documentation/media/uapi/v4l/pixfmt-rgb.rst 
b/Documentation/media/uapi/v4l/pixfmt-rgb.rst
index cf2ef7d..1f9a7e3 100644
--- a/Documentation/media/uapi/v4l/pixfmt-rgb.rst
+++ b/Documentation/media/uapi/v4l/pixfmt-rgb.rst
@@ -19,4 +19,5 @@ RGB Formats
 pixfmt-srggb10-ipu3
 pixfmt-srggb12
 pixfmt-srggb12p
+pixfmt-srggb14p
 pixfmt-srggb16
diff --git a/Documentation/media/uapi/v4l/pixfmt-srggb14p.rst 
b/Documentation/media/uapi/v4l/pixfmt-srggb14p.rst
new file mode 100644
index 000..88d20c0
--- /dev/null
+++ b/Documentation/media/uapi/v4l/pixfmt-srggb14p.rst
@@ -0,0 +1,127 @@
+.. -*- coding: utf-8; mode: rst -*-
+
+.. _V4L2-PIX-FMT-SRGGB14P:
+.. _v4l2-pix-fmt-sbggr14p:
+.. _v4l2-pix-fmt-sgbrg14p:
+.. _v4l2-pix-fmt-sgrbg14p:
+
+***
+V4L2_PIX_FMT_SRGGB14P ('pRCC'), V4L2_PIX_FMT_SGRBG14P ('pgCC'), 
V4L2_PIX_FMT_SGBRG14P ('pGCC'), V4L2_PIX_FMT_SBGGR14P ('pBCC'),
+***
+
+*man V4L2_PIX_FMT_SRGGB14P(2)*
+
+V4L2_PIX_FMT_SGRBG14P
+V4L2_PIX_FMT_SGBRG14P
+V4L2_PIX_FMT_SBGGR14P
+14-bit packed Bayer formats
+
+
+Description
+===
+
+These four pixel formats are packed raw sRGB / Bayer formats with 14
+bits per colour. Every four consecutive samples are packed into seven
+bytes. Each of the first four bytes contain the eight high order bits
+of the pixels, and the three following bytes contains the six least
+significants bits of each pixel, in the same order.
+
+Each n-pixel row contains n/2 green samples and n/2 blue or red samples,
+with alternating green-red and green-blue rows. They are conventionally
+described as GRGR... BGBG..., RGRG... GBGB..., etc. Below is an example
+of one of these formats:
+
+**Byte Order.**
+Each cell is one byte.
+
+
+
+.. flat-table::
+:header-rows:  0
+:stub-columns: 0
+:widths:   2 1 1 1 1 1 1 1
+
+
+-  .. row 1
+
+   -  start + 0:
+
+   -  B\ :sub:`00high`
+
+   -  G\ :sub:`01high`
+
+   -  B\ :sub:`02high`
+
+   -  G\ :sub:`03high`
+
+   -  G\ :sub:`01low bits 1--0`\ (bits 7--6)
+ B\ :sub:`00low bits 5--0`\ (bits 5--0)
+
+   -  R\ :sub:`02low bits 3--0`\ (bits 7--4)
+ G\ :sub:`01low bits 5--2`\ (bits 3--0)
+
+   -  G\ :sub:`03low bits 5--0`\ (bits 7--2)
+ R\ :sub:`02low bits 5--4`\ (bits 1--0)
+
+-  .. row 2
+
+   -  start + 7:
+
+   -  G\ :sub:`00high`
+
+   -  R\ :sub:`01high`
+
+   -  G\ :sub:`02high`
+
+   -  R\ :sub:`03high`
+
+   -  R\ :sub:`01low bits 1--0`\ (bits 7--6)
+ G\ :sub:`00low bits 5--0`\ (bits 5--0)
+
+   -  G\ :sub:`02low bits 3--0`\ (bits 7--4)
+ R\ :sub:`01low bits 5--2`\ (bits 3--0)
+
+   -  R\ :sub:`03low bits 5--0`\ (bits 7--2)
+ G\ :sub:`02low bits 5--4`\ (bits 1--0)
+
+-  .. row 3
+
+   -  start + 14
+
+   -  B\ :sub:`20high`
+
+   -  G\ :sub:`21high`
+
+   -  B\ :sub:`22high`
+
+   -  G\ :sub:`23high`
+
+   -  G\ :sub:`21low bits 1--0`\ (bits 7--6)
+ B\ :sub:`20low bits 5--0`\ (bits 5--0)
+
+   -  R\ :sub:`22low bits 3--0`\ (bits 7--4)
+ G\ :sub:`21low bits 5--2`\ (bits 3--0)
+
+   -  G\ :sub:`23low bits 5--0`\ (bits 7--2)
+ R\ :sub:`22low bits 5--4`\ (bits 1--0)
+
+-  .. row 4
+
+   -  start + 21
+
+   -  G\ :sub:`30high`
+
+   -  R\ :sub:`31high`
+
+   -  G\ :sub:`32high`
+
+   -  R\ :sub:`33high`
+
+   -  R\ :sub:`31low bits 1--0`\ (bits 7--6)
+ G\ :sub:`30low bits 5--0`\ (bits 5--0)
+
+   -  G\ :sub:`32low bits 3--0`\ (bits 7--4)
+ R\ :sub:`31low bits 5--2`\ (bits 3--0)
+
+   -  R\ :sub:`33low bits 5--0`\ (bits 7--2)
+ G\ :sub:`32low bits 5--4`\ (bits 1--0)
diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c 
b/drivers/media/v4l2-core/v4l2-ioctl.c
index 0167056..04e1231 100644
--- a/drivers/media/v4l2-core/v4l2-ioctl.c
+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
@@ -1259,6 +1259,10 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)
case V4L2_PIX_FMT_SGBRG12P: descr

[PATCH v4 02/34] media: v4l: Add new 2X8 10-bit grayscale media bus code

2018-07-25 Thread Todor Tomov
The code will be called MEDIA_BUS_FMT_Y10_2X8_PADHI_LE.
It is similar to MEDIA_BUS_FMT_SBGGR10_2X8_PADHI_LE
but MEDIA_BUS_FMT_Y10_2X8_PADHI_LE describes grayscale
data.

Signed-off-by: Todor Tomov 
---
 Documentation/media/uapi/v4l/subdev-formats.rst | 72 +
 include/uapi/linux/media-bus-format.h   |  3 +-
 2 files changed, 74 insertions(+), 1 deletion(-)

diff --git a/Documentation/media/uapi/v4l/subdev-formats.rst 
b/Documentation/media/uapi/v4l/subdev-formats.rst
index a4739f7..8e73fcf 100644
--- a/Documentation/media/uapi/v4l/subdev-formats.rst
+++ b/Documentation/media/uapi/v4l/subdev-formats.rst
@@ -4318,6 +4318,78 @@ the following codes.
   - y\ :sub:`2`
   - y\ :sub:`1`
   - y\ :sub:`0`
+* .. _MEDIA-BUS-FMT-Y10-2X8-PADHI_LE:
+
+  - MEDIA_BUS_FMT_Y10_2X8_PADHI_LE
+  - 0x202c
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  - y\ :sub:`7`
+  - y\ :sub:`6`
+  - y\ :sub:`5`
+  - y\ :sub:`4`
+  - y\ :sub:`3`
+  - y\ :sub:`2`
+  - y\ :sub:`1`
+  - y\ :sub:`0`
+* -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - y\ :sub:`9`
+  - y\ :sub:`8`
 * .. _MEDIA-BUS-FMT-UYVY10-2X10:
 
   - MEDIA_BUS_FMT_UYVY10_2X10
diff --git a/include/uapi/linux/media-bus-format.h 
b/include/uapi/linux/media-bus-format.h
index 9e35117..d6a5a3b 100644
--- a/include/uapi/linux/media-bus-format.h
+++ b/include/uapi/linux/media-bus-format.h
@@ -62,7 +62,7 @@
 #define MEDIA_BUS_FMT_RGB121212_1X36   0x1019
 #define MEDIA_BUS_FMT_RGB161616_1X48   0x101a
 
-/* YUV (including grey) - next is  0x202c */
+/* YUV (including grey) - next is  0x202d */
 #define MEDIA_BUS_FMT_Y8_1X8   0x2001
 #define MEDIA_BUS_FMT_UV8_1X8  0x2015
 #define MEDIA_BUS_FMT_UYVY8_1_5X8  0x2002
@@ -74,6 +74,7 @@
 #define MEDIA_BUS_FMT_YUYV8_2X80x2008
 #define MEDIA_BUS_FMT_YVYU8_2X80x2009
 #define MEDIA_BUS_FMT_Y10_1X10 0x200a
+#define MEDIA_BUS_FMT_Y10_2X8_PADHI_LE 0x202c
 #define MEDIA_BUS_FMT_UYVY10_2X10  0x2018
 #define MEDIA_BUS_FMT_VYUY10_2X10  0x2019
 #define MEDIA_BUS_FMT_YUYV10_2X10  0x200b
-- 
2.7.4



Re: [PATCH v3 35/35] media: v4l2-ioctl: Add format descriptions for packed Bayer raw14 pixel formats

2018-07-25 Thread Todor Tomov
Hi Sakari,

Thanks for review.

On 24.07.2018 15:52, Sakari Ailus wrote:
> Hi Todor,
> 
> On Mon, Jul 23, 2018 at 02:02:52PM +0300, Todor Tomov wrote:
>> This removes warning "Unknown pixelformat" for the following formats:
>> V4L2_PIX_FMT_SBGGR14P
>> V4L2_PIX_FMT_SGBRG14P
>> V4L2_PIX_FMT_SGRBG14P
>> V4L2_PIX_FMT_SRGGB14P
>>
>> CC: Sakari Ailus 
>> Signed-off-by: Todor Tomov 
>> ---
>>  drivers/media/v4l2-core/v4l2-ioctl.c | 4 
>>  1 file changed, 4 insertions(+)
>>
>> diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c 
>> b/drivers/media/v4l2-core/v4l2-ioctl.c
>> index 2e3b1f0..e8f7c89 100644
>> --- a/drivers/media/v4l2-core/v4l2-ioctl.c
>> +++ b/drivers/media/v4l2-core/v4l2-ioctl.c
>> @@ -1260,6 +1260,10 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)
>>  case V4L2_PIX_FMT_SGBRG12P: descr = "12-bit Bayer GBGB/RGRG 
>> Packed"; break;
>>  case V4L2_PIX_FMT_SGRBG12P: descr = "12-bit Bayer GRGR/BGBG 
>> Packed"; break;
>>  case V4L2_PIX_FMT_SRGGB12P: descr = "12-bit Bayer RGRG/GBGB 
>> Packed"; break;
>> +case V4L2_PIX_FMT_SBGGR14P: descr = "14-bit Bayer BGBG/GRGR 
>> Packed"; break;
>> +case V4L2_PIX_FMT_SGBRG14P: descr = "14-bit Bayer GBGB/RGRG 
>> Packed"; break;
>> +case V4L2_PIX_FMT_SGRBG14P: descr = "14-bit Bayer GRGR/BGBG 
>> Packed"; break;
>> +case V4L2_PIX_FMT_SRGGB14P: descr = "14-bit Bayer RGRG/GBGB 
>> Packed"; break;
>>  case V4L2_PIX_FMT_SBGGR16:  descr = "16-bit Bayer BGBG/GRGR"; break;
>>  case V4L2_PIX_FMT_SGBRG16:  descr = "16-bit Bayer GBGB/RGRG"; break;
>>  case V4L2_PIX_FMT_SGRBG16:  descr = "16-bit Bayer GRGR/BGBG"; break;
> 
> You could merge this to the patch that adds the format definitions. Or:

Yes. I think we are going to have v4 so I will merge it with the patch which 
adds
the format definitions.

> 
> Acked-by: Sakari Ailus 
> 
> And preferrably move it to earlier in the patchset where new formats are
> added.
> 

-- 
Best regards,
Todor Tomov


Re: [PATCH v3 17/35] media: camss: Add 8x96 resources

2018-07-25 Thread Todor Tomov
On 24.07.2018 15:21, Sakari Ailus wrote:
> Hi Todor,
> 
> On Mon, Jul 23, 2018 at 02:02:34PM +0300, Todor Tomov wrote:
> ...
>> @@ -61,7 +59,8 @@ struct ispif_device {
>>  struct mutex power_lock;
>>  struct ispif_intf_cmd_reg intf_cmd[MSM_ISPIF_VFE_NUM];
>>  struct mutex config_lock;
>> -struct ispif_line line[MSM_ISPIF_LINE_NUM];
>> +int line_num;
> 
> unsigned int?

Yes, thanks :)

> 
> I guess if there are only such changes then a patch on top of the current
> set might be more practical than a new version of the entire set.
> 

-- 
Best regards,
Todor Tomov


Re: [PATCH v3 18/35] media: camss: Add basic runtime PM support

2018-07-25 Thread Todor Tomov
Hi Sakari,

Thank you for review.

On 24.07.2018 15:49, Sakari Ailus wrote:
> Hi Todor,
> 
> On Mon, Jul 23, 2018 at 02:02:35PM +0300, Todor Tomov wrote:
>> There is a PM domain for each of the VFE hardware modules. Add
>> support for basic runtime PM support to be able to control the
>> PM domains. When a PM domain needs to be powered on - a device
>> link is created. When a PM domain needs to be powered off -
>> its device link is removed. This allows separate and
>> independent control of the PM domains.
>>
>> Suspend/Resume is still not supported.
>>
>> Signed-off-by: Todor Tomov 
>> ---
>>  drivers/media/platform/qcom/camss/camss-csid.c   |  4 ++
>>  drivers/media/platform/qcom/camss/camss-csiphy.c |  5 ++
>>  drivers/media/platform/qcom/camss/camss-ispif.c  | 19 ++-
>>  drivers/media/platform/qcom/camss/camss-vfe.c| 13 +
>>  drivers/media/platform/qcom/camss/camss.c| 63 
>> 
>>  drivers/media/platform/qcom/camss/camss.h| 11 +
>>  6 files changed, 113 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/media/platform/qcom/camss/camss-csid.c 
>> b/drivers/media/platform/qcom/camss/camss-csid.c
>> index 627ef44..ea2b0ba 100644
>> --- a/drivers/media/platform/qcom/camss/camss-csid.c
>> +++ b/drivers/media/platform/qcom/camss/camss-csid.c
>> @@ -13,6 +13,7 @@
>>  #include 
>>  #include 
>>  #include 
>> +#include 
>>  #include 
>>  #include 
>>  #include 
>> @@ -316,6 +317,8 @@ static int csid_set_power(struct v4l2_subdev *sd, int on)
>>  if (on) {
>>  u32 hw_version;
>>  
>> +pm_runtime_get_sync(dev);
>> +
>>  ret = regulator_enable(csid->vdda);
> 
> Shouldn't the regulator be enabled in the runtime_resume callback instead?

Ideally - yes, but it becomes more complex (different pipelines are possible
and we have only one callback) so (at least for now) I have left it as it is
and stated in the commit message that suspend/resume is still not supported.

> 
>>  if (ret < 0)
>>  return ret;
> 
> Note that you'll need pm_runtime_put() in in error handling here. Perhaps
> elsewhere, too.

Yes, I'll add it here and on all other places.

> 
> Can powering on the device (i.e. pm_runtime_get_sync() call)  fail?

I'd really like to say that it cannot fail :) at least the callback is
empty for now and cannot fail, but the logic in pm_runtime_get_sync()
is not that simple and I'm really not sure. I'll add checks in the code
in case it fails.

> 
>> @@ -348,6 +351,7 @@ static int csid_set_power(struct v4l2_subdev *sd, int on)
>>  disable_irq(csid->irq);
>>  camss_disable_clocks(csid->nclocks, csid->clock);
>>  ret = regulator_disable(csid->vdda);
>> +pm_runtime_put_sync(dev);
>>  }
>>  
>>  return ret;
>> diff --git a/drivers/media/platform/qcom/camss/camss-csiphy.c 
>> b/drivers/media/platform/qcom/camss/camss-csiphy.c
>> index 0383e94..2db78791 100644
>> --- a/drivers/media/platform/qcom/camss/camss-csiphy.c
>> +++ b/drivers/media/platform/qcom/camss/camss-csiphy.c
>> @@ -13,6 +13,7 @@
>>  #include 
>>  #include 
>>  #include 
>> +#include 
>>  #include 
>>  #include 
>>  #include 
>> @@ -240,6 +241,8 @@ static int csiphy_set_power(struct v4l2_subdev *sd, int 
>> on)
>>  u8 hw_version;
>>  int ret;
>>  
>> +pm_runtime_get_sync(dev);
>> +
>>  ret = csiphy_set_clock_rates(csiphy);
>>  if (ret < 0)
>>  return ret;
> 
> Like here.

Yes, I'll add it here too.

-- 
Best regards,
Todor Tomov


[PATCH v2] media: v4l: Add new 10-bit packed grayscale format

2018-05-08 Thread Todor Tomov
The new format will be called V4L2_PIX_FMT_Y10P.
It is similar to the V4L2_PIX_FMT_SBGGR10P family formats
but V4L2_PIX_FMT_Y10P is a grayscale format.

Signed-off-by: Todor Tomov <todor.to...@linaro.org>
---

v2:
- doc: improved bit-packed representation: added bit positions for LSB bits;
- doc: improved bit-packed representation: added table column widths.

 Documentation/media/uapi/v4l/pixfmt-y10p.rst | 33 
 Documentation/media/uapi/v4l/yuv-formats.rst |  1 +
 drivers/media/v4l2-core/v4l2-ioctl.c |  1 +
 include/uapi/linux/videodev2.h   |  1 +
 4 files changed, 36 insertions(+)
 create mode 100644 Documentation/media/uapi/v4l/pixfmt-y10p.rst

diff --git a/Documentation/media/uapi/v4l/pixfmt-y10p.rst 
b/Documentation/media/uapi/v4l/pixfmt-y10p.rst
new file mode 100644
index 000..13b5713
--- /dev/null
+++ b/Documentation/media/uapi/v4l/pixfmt-y10p.rst
@@ -0,0 +1,33 @@
+.. -*- coding: utf-8; mode: rst -*-
+
+.. _V4L2-PIX-FMT-Y10P:
+
+**
+V4L2_PIX_FMT_Y10P ('Y10P')
+**
+
+Grey-scale image as a MIPI RAW10 packed array
+
+
+Description
+===
+
+This is a packed grey-scale image format with a depth of 10 bits per
+pixel. Every four consecutive pixels are packed into 5 bytes. Each of
+the first 4 bytes contain the 8 high order bits of the pixels, and
+the 5th byte contains the 2 least significants bits of each pixel,
+in the same order.
+
+**Bit-packed representation.**
+
+.. flat-table::
+:header-rows:  0
+:stub-columns: 0
+:widths: 8 8 8 8 64
+
+* - Y'\ :sub:`00[9:2]`
+  - Y'\ :sub:`01[9:2]`
+  - Y'\ :sub:`02[9:2]`
+  - Y'\ :sub:`03[9:2]`
+  - Y'\ :sub:`03[1:0]`\ (bits 7--6) Y'\ :sub:`02[1:0]`\ (bits 5--4)
+   Y'\ :sub:`01[1:0]`\ (bits 3--2) Y'\ :sub:`00[1:0]`\ (bits 1--0)
diff --git a/Documentation/media/uapi/v4l/yuv-formats.rst 
b/Documentation/media/uapi/v4l/yuv-formats.rst
index 3334ea4..9ab0592 100644
--- a/Documentation/media/uapi/v4l/yuv-formats.rst
+++ b/Documentation/media/uapi/v4l/yuv-formats.rst
@@ -29,6 +29,7 @@ to brightness information.
 pixfmt-y10
 pixfmt-y12
 pixfmt-y10b
+pixfmt-y10p
 pixfmt-y16
 pixfmt-y16-be
 pixfmt-y8i
diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c 
b/drivers/media/v4l2-core/v4l2-ioctl.c
index de5d96d..dececea 100644
--- a/drivers/media/v4l2-core/v4l2-ioctl.c
+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
@@ -1147,6 +1147,7 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)
case V4L2_PIX_FMT_Y16:  descr = "16-bit Greyscale"; break;
case V4L2_PIX_FMT_Y16_BE:   descr = "16-bit Greyscale BE"; break;
case V4L2_PIX_FMT_Y10BPACK: descr = "10-bit Greyscale (Packed)"; 
break;
+   case V4L2_PIX_FMT_Y10P: descr = "10-bit Greyscale (MIPI 
Packed)"; break;
case V4L2_PIX_FMT_Y8I:  descr = "Interleaved 8-bit Greyscale"; 
break;
case V4L2_PIX_FMT_Y12I: descr = "Interleaved 12-bit Greyscale"; 
break;
case V4L2_PIX_FMT_Z16:  descr = "16-bit Depth"; break;
diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
index 600877b..b24ab720 100644
--- a/include/uapi/linux/videodev2.h
+++ b/include/uapi/linux/videodev2.h
@@ -522,6 +522,7 @@ struct v4l2_pix_format {
 
 /* Grey bit-packed formats */
 #define V4L2_PIX_FMT_Y10BPACKv4l2_fourcc('Y', '1', '0', 'B') /* 10  
Greyscale bit-packed */
+#define V4L2_PIX_FMT_Y10Pv4l2_fourcc('Y', '1', '0', 'P') /* 10  Greyscale, 
MIPI RAW10 packed */
 
 /* Palette formats */
 #define V4L2_PIX_FMT_PAL8v4l2_fourcc('P', 'A', 'L', '8') /*  8  8-bit 
palette */
-- 
2.7.4



Re: [PATCH 2/2] media: v4l: Add new 10-bit packed grayscale format

2018-05-08 Thread Todor Tomov
Hi Sakari,

On  7.05.2018 13:59, Sakari Ailus wrote:
> Hi Todor,
> 
> On Fri, Apr 27, 2018 at 02:40:39PM +0300, Todor Tomov wrote:
>> The new format will be called V4L2_PIX_FMT_Y10P.
>> It is similar to the V4L2_PIX_FMT_SBGGR10P family formats
>> but V4L2_PIX_FMT_Y10P is a grayscale format.
>>
>> Signed-off-by: Todor Tomov <todor.to...@linaro.org>
>> ---
>>  Documentation/media/uapi/v4l/pixfmt-y10p.rst | 31 
>> 
>>  Documentation/media/uapi/v4l/yuv-formats.rst |  1 +
>>  drivers/media/v4l2-core/v4l2-ioctl.c |  1 +
>>  include/uapi/linux/videodev2.h   |  1 +
>>  4 files changed, 34 insertions(+)
>>  create mode 100644 Documentation/media/uapi/v4l/pixfmt-y10p.rst
>>
>> diff --git a/Documentation/media/uapi/v4l/pixfmt-y10p.rst 
>> b/Documentation/media/uapi/v4l/pixfmt-y10p.rst
>> new file mode 100644
>> index 000..0018fe7
>> --- /dev/null
>> +++ b/Documentation/media/uapi/v4l/pixfmt-y10p.rst
>> @@ -0,0 +1,31 @@
>> +.. -*- coding: utf-8; mode: rst -*-
>> +
>> +.. _V4L2-PIX-FMT-Y10P:
>> +
>> +**
>> +V4L2_PIX_FMT_Y10P ('Y10P')
>> +**
>> +
>> +Grey-scale image as a MIPI RAW10 packed array
>> +
>> +
>> +Description
>> +===
>> +
>> +This is a packed grey-scale image format with a depth of 10 bits per
>> +pixel. Every four consecutive pixels are packed into 5 bytes. Each of
>> +the first 4 bytes contain the 8 high order bits of the pixels, and
>> +the 5th byte contains the 2 least significants bits of each pixel,
>> +in the same order.
>> +
>> +**Bit-packed representation.**
>> +
>> +.. flat-table::
>> +:header-rows:  0
>> +:stub-columns: 0
>> +
>> +* - Y'\ :sub:`00[9:2]`
>> +  - Y'\ :sub:`01[9:2]`
>> +  - Y'\ :sub:`02[9:2]`
>> +  - Y'\ :sub:`03[9:2]`
>> +  - Y'\ :sub:`03[1:0]`\ Y'\ :sub:`02[1:0]`\ Y'\ :sub:`01[1:0]`\ Y'\ 
>> :sub:`00[1:0]`
> 
> Could you add which exact bits the two LSBs of each pixel go to in the last
> byte, as in the 10-bit packed Bayer format documentation?

Thank you for review. I'll add and send v2.

Best regards,
Todor

> 
>> diff --git a/Documentation/media/uapi/v4l/yuv-formats.rst 
>> b/Documentation/media/uapi/v4l/yuv-formats.rst
>> index 3334ea4..9ab0592 100644
>> --- a/Documentation/media/uapi/v4l/yuv-formats.rst
>> +++ b/Documentation/media/uapi/v4l/yuv-formats.rst
>> @@ -29,6 +29,7 @@ to brightness information.
>>  pixfmt-y10
>>  pixfmt-y12
>>  pixfmt-y10b
>> +pixfmt-y10p
>>  pixfmt-y16
>>  pixfmt-y16-be
>>  pixfmt-y8i
>> diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c 
>> b/drivers/media/v4l2-core/v4l2-ioctl.c
>> index f48c505..bdf2399 100644
>> --- a/drivers/media/v4l2-core/v4l2-ioctl.c
>> +++ b/drivers/media/v4l2-core/v4l2-ioctl.c
>> @@ -1147,6 +1147,7 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)
>>  case V4L2_PIX_FMT_Y16:  descr = "16-bit Greyscale"; break;
>>  case V4L2_PIX_FMT_Y16_BE:   descr = "16-bit Greyscale BE"; break;
>>  case V4L2_PIX_FMT_Y10BPACK: descr = "10-bit Greyscale (Packed)"; 
>> break;
>> +case V4L2_PIX_FMT_Y10P: descr = "10-bit Greyscale (MIPI 
>> Packed)"; break;
>>  case V4L2_PIX_FMT_Y8I:  descr = "Interleaved 8-bit Greyscale"; 
>> break;
>>  case V4L2_PIX_FMT_Y12I: descr = "Interleaved 12-bit Greyscale"; 
>> break;
>>  case V4L2_PIX_FMT_Z16:  descr = "16-bit Depth"; break;
>> diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
>> index 600877b..b24ab720 100644
>> --- a/include/uapi/linux/videodev2.h
>> +++ b/include/uapi/linux/videodev2.h
>> @@ -522,6 +522,7 @@ struct v4l2_pix_format {
>>  
>>  /* Grey bit-packed formats */
>>  #define V4L2_PIX_FMT_Y10BPACKv4l2_fourcc('Y', '1', '0', 'B') /* 10  
>> Greyscale bit-packed */
>> +#define V4L2_PIX_FMT_Y10Pv4l2_fourcc('Y', '1', '0', 'P') /* 10  
>> Greyscale, MIPI RAW10 packed */
>>  
>>  /* Palette formats */
>>  #define V4L2_PIX_FMT_PAL8v4l2_fourcc('P', 'A', 'L', '8') /*  8  8-bit 
>> palette */
>> -- 
>> 2.7.4
>>
> 



[PATCH 1/2] media: v4l: Add new 2X8 10-bit grayscale media bus code

2018-04-27 Thread Todor Tomov
The code will be called MEDIA_BUS_FMT_Y10_2X8_PADHI_LE.
It is similar to MEDIA_BUS_FMT_SBGGR10_2X8_PADHI_LE
but MEDIA_BUS_FMT_Y10_2X8_PADHI_LE describes grayscale
data.

Signed-off-by: Todor Tomov <todor.to...@linaro.org>
---
 Documentation/media/uapi/v4l/subdev-formats.rst | 72 +
 include/uapi/linux/media-bus-format.h   |  3 +-
 2 files changed, 74 insertions(+), 1 deletion(-)

diff --git a/Documentation/media/uapi/v4l/subdev-formats.rst 
b/Documentation/media/uapi/v4l/subdev-formats.rst
index 9fcabe7..c4fb0bf 100644
--- a/Documentation/media/uapi/v4l/subdev-formats.rst
+++ b/Documentation/media/uapi/v4l/subdev-formats.rst
@@ -4315,6 +4315,78 @@ the following codes.
   - y\ :sub:`2`
   - y\ :sub:`1`
   - y\ :sub:`0`
+* .. _MEDIA-BUS-FMT-Y10-2X8-PADHI_LE:
+
+  - MEDIA_BUS_FMT_Y10_2X8_PADHI_LE
+  - 0x202c
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  - y\ :sub:`7`
+  - y\ :sub:`6`
+  - y\ :sub:`5`
+  - y\ :sub:`4`
+  - y\ :sub:`3`
+  - y\ :sub:`2`
+  - y\ :sub:`1`
+  - y\ :sub:`0`
+* -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  -
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - y\ :sub:`9`
+  - y\ :sub:`8`
 * .. _MEDIA-BUS-FMT-UYVY10-2X10:
 
   - MEDIA_BUS_FMT_UYVY10_2X10
diff --git a/include/uapi/linux/media-bus-format.h 
b/include/uapi/linux/media-bus-format.h
index 9e35117..d6a5a3b 100644
--- a/include/uapi/linux/media-bus-format.h
+++ b/include/uapi/linux/media-bus-format.h
@@ -62,7 +62,7 @@
 #define MEDIA_BUS_FMT_RGB121212_1X36   0x1019
 #define MEDIA_BUS_FMT_RGB161616_1X48   0x101a
 
-/* YUV (including grey) - next is  0x202c */
+/* YUV (including grey) - next is  0x202d */
 #define MEDIA_BUS_FMT_Y8_1X8   0x2001
 #define MEDIA_BUS_FMT_UV8_1X8  0x2015
 #define MEDIA_BUS_FMT_UYVY8_1_5X8  0x2002
@@ -74,6 +74,7 @@
 #define MEDIA_BUS_FMT_YUYV8_2X80x2008
 #define MEDIA_BUS_FMT_YVYU8_2X80x2009
 #define MEDIA_BUS_FMT_Y10_1X10 0x200a
+#define MEDIA_BUS_FMT_Y10_2X8_PADHI_LE 0x202c
 #define MEDIA_BUS_FMT_UYVY10_2X10  0x2018
 #define MEDIA_BUS_FMT_VYUY10_2X10  0x2019
 #define MEDIA_BUS_FMT_YUYV10_2X10  0x200b
-- 
2.7.4



[PATCH 2/2] media: v4l: Add new 10-bit packed grayscale format

2018-04-27 Thread Todor Tomov
The new format will be called V4L2_PIX_FMT_Y10P.
It is similar to the V4L2_PIX_FMT_SBGGR10P family formats
but V4L2_PIX_FMT_Y10P is a grayscale format.

Signed-off-by: Todor Tomov <todor.to...@linaro.org>
---
 Documentation/media/uapi/v4l/pixfmt-y10p.rst | 31 
 Documentation/media/uapi/v4l/yuv-formats.rst |  1 +
 drivers/media/v4l2-core/v4l2-ioctl.c |  1 +
 include/uapi/linux/videodev2.h   |  1 +
 4 files changed, 34 insertions(+)
 create mode 100644 Documentation/media/uapi/v4l/pixfmt-y10p.rst

diff --git a/Documentation/media/uapi/v4l/pixfmt-y10p.rst 
b/Documentation/media/uapi/v4l/pixfmt-y10p.rst
new file mode 100644
index 000..0018fe7
--- /dev/null
+++ b/Documentation/media/uapi/v4l/pixfmt-y10p.rst
@@ -0,0 +1,31 @@
+.. -*- coding: utf-8; mode: rst -*-
+
+.. _V4L2-PIX-FMT-Y10P:
+
+**
+V4L2_PIX_FMT_Y10P ('Y10P')
+**
+
+Grey-scale image as a MIPI RAW10 packed array
+
+
+Description
+===
+
+This is a packed grey-scale image format with a depth of 10 bits per
+pixel. Every four consecutive pixels are packed into 5 bytes. Each of
+the first 4 bytes contain the 8 high order bits of the pixels, and
+the 5th byte contains the 2 least significants bits of each pixel,
+in the same order.
+
+**Bit-packed representation.**
+
+.. flat-table::
+:header-rows:  0
+:stub-columns: 0
+
+* - Y'\ :sub:`00[9:2]`
+  - Y'\ :sub:`01[9:2]`
+  - Y'\ :sub:`02[9:2]`
+  - Y'\ :sub:`03[9:2]`
+  - Y'\ :sub:`03[1:0]`\ Y'\ :sub:`02[1:0]`\ Y'\ :sub:`01[1:0]`\ Y'\ 
:sub:`00[1:0]`
diff --git a/Documentation/media/uapi/v4l/yuv-formats.rst 
b/Documentation/media/uapi/v4l/yuv-formats.rst
index 3334ea4..9ab0592 100644
--- a/Documentation/media/uapi/v4l/yuv-formats.rst
+++ b/Documentation/media/uapi/v4l/yuv-formats.rst
@@ -29,6 +29,7 @@ to brightness information.
 pixfmt-y10
 pixfmt-y12
 pixfmt-y10b
+pixfmt-y10p
 pixfmt-y16
 pixfmt-y16-be
 pixfmt-y8i
diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c 
b/drivers/media/v4l2-core/v4l2-ioctl.c
index f48c505..bdf2399 100644
--- a/drivers/media/v4l2-core/v4l2-ioctl.c
+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
@@ -1147,6 +1147,7 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)
case V4L2_PIX_FMT_Y16:  descr = "16-bit Greyscale"; break;
case V4L2_PIX_FMT_Y16_BE:   descr = "16-bit Greyscale BE"; break;
case V4L2_PIX_FMT_Y10BPACK: descr = "10-bit Greyscale (Packed)"; 
break;
+   case V4L2_PIX_FMT_Y10P: descr = "10-bit Greyscale (MIPI 
Packed)"; break;
case V4L2_PIX_FMT_Y8I:  descr = "Interleaved 8-bit Greyscale"; 
break;
case V4L2_PIX_FMT_Y12I: descr = "Interleaved 12-bit Greyscale"; 
break;
case V4L2_PIX_FMT_Z16:  descr = "16-bit Depth"; break;
diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
index 600877b..b24ab720 100644
--- a/include/uapi/linux/videodev2.h
+++ b/include/uapi/linux/videodev2.h
@@ -522,6 +522,7 @@ struct v4l2_pix_format {
 
 /* Grey bit-packed formats */
 #define V4L2_PIX_FMT_Y10BPACKv4l2_fourcc('Y', '1', '0', 'B') /* 10  
Greyscale bit-packed */
+#define V4L2_PIX_FMT_Y10Pv4l2_fourcc('Y', '1', '0', 'P') /* 10  Greyscale, 
MIPI RAW10 packed */
 
 /* Palette formats */
 #define V4L2_PIX_FMT_PAL8v4l2_fourcc('P', 'A', 'L', '8') /*  8  8-bit 
palette */
-- 
2.7.4



[PATCH 0/2] Add new grayscale formats

2018-04-27 Thread Todor Tomov
The following two patches add one new media bus code and one new pixel format.
Both are for 10bit grayscale data. They will be used by the future version of
the QComm CAMSS driver when receiving the frame data from the OV7251 grayscale
camera sensor.

Todor Tomov (2):
  media: v4l: Add new 2X8 10-bit grayscale media bus code
  media: v4l: Add new 10-bit packed grayscale format

 Documentation/media/uapi/v4l/pixfmt-y10p.rst| 31 +++
 Documentation/media/uapi/v4l/subdev-formats.rst | 72 +
 Documentation/media/uapi/v4l/yuv-formats.rst|  1 +
 drivers/media/v4l2-core/v4l2-ioctl.c|  1 +
 include/uapi/linux/media-bus-format.h   |  3 +-
 include/uapi/linux/videodev2.h  |  1 +
 6 files changed, 108 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/media/uapi/v4l/pixfmt-y10p.rst

-- 
2.7.4



Re: [PATCH v4 2/2] media: Add a driver for the ov7251 camera sensor

2018-04-26 Thread Todor Tomov
On 26.04.2018 15:04, Sakari Ailus wrote:
> On Thu, Apr 26, 2018 at 10:16:56AM +0300, Sakari Ailus wrote:
>> On Thu, Apr 26, 2018 at 10:04:25AM +0300, Todor Tomov wrote:
>>> Hi Sakari,
>>>
>>> On 26.04.2018 09:50, Sakari Ailus wrote:
>>>> Hi Todor,
>>>>
>>>> On Wed, Apr 25, 2018 at 07:20:46PM +0300, Todor Tomov wrote:
>>>> ...
>>>>> +static int ov7251_write_reg(struct ov7251 *ov7251, u16 reg, u8 val)
>>>>> +{
>>>>> + u8 regbuf[3];
>>>>> + int ret;
>>>>> +
>>>>> + regbuf[0] = reg >> 8;
>>>>> + regbuf[1] = reg & 0xff;
>>>>> + regbuf[2] = val;
>>>>> +
>>>>> + ret = i2c_master_send(ov7251->i2c_client, regbuf, 3);
>>>>> + if (ret < 0) {
>>>>> + dev_err(ov7251->dev, "%s: write reg error %d: reg=%x, val=%x\n",
>>>>> + __func__, ret, reg, val);
>>>>> + return ret;
>>>>> + }
>>>>> +
>>>>> + return 0;
>>>>
>>>> How about:
>>>>
>>>>return ov7251_write_seq_regs(ov7251, reg, , 1);
>>>>
>>>> And put the function below ov2751_write_seq_regs().
>>>
>>> I'm not sure... It will calculate message length each time and then check
>>> that it is not greater than 5, which it is. Seems redundant.
>>>
>>>>
>>>>> +}
>>>>> +
>>>>> +static int ov7251_write_seq_regs(struct ov7251 *ov7251, u16 reg, u8 *val,
>>>>> +  u8 num)
>>>>> +{
>>>>> + const u8 maxregbuf = 5;
>>>>> + u8 regbuf[maxregbuf];
> 
> Apparently this leads to bad positive sparse warning. I'd fix it by:
> 
> diff --git a/drivers/media/i2c/ov7251.c b/drivers/media/i2c/ov7251.c
> index 3e2c0c03dfa9..d3ebb7529fca 100644
> --- a/drivers/media/i2c/ov7251.c
> +++ b/drivers/media/i2c/ov7251.c
> @@ -643,12 +643,11 @@ static int ov7251_write_reg(struct ov7251 *ov7251, u16 
> reg, u8 val)
>  static int ov7251_write_seq_regs(struct ov7251 *ov7251, u16 reg, u8 *val,
>  u8 num)
>  {
> -   const u8 maxregbuf = 5;
> -   u8 regbuf[maxregbuf];
> +   u8 regbuf[5];
> u8 nregbuf = sizeof(reg) + num * sizeof(*val);
> int ret = 0;
>  
> -   if (nregbuf > maxregbuf)
> +   if (nregbuf > sizeof(regbuf))
> return -EINVAL;
>  
> regbuf[0] = reg >> 8;
> 
> Let me know if you're happy with that; I can merge it to the original
> patch.

Yes, thanks.

> 
>>>>> + u8 nregbuf = sizeof(reg) + num * sizeof(*val);
>>>>> + int ret = 0;
>>>>> +
>>>>> + if (nregbuf > maxregbuf)
>>>>> + return -EINVAL;
>>>>> +
>>>>> + regbuf[0] = reg >> 8;
>>>>> + regbuf[1] = reg & 0xff;
>>>>> +
>>>>> + memcpy(regbuf + 2, val, num);
>>>>> +
>>>>> + ret = i2c_master_send(ov7251->i2c_client, regbuf, nregbuf);
>>>>> + if (ret < 0) {
>>>>> + dev_err(ov7251->dev, "%s: write seq regs error %d: first 
>>>>> reg=%x\n",
>>>>
>>>> This line is over 80... 
>>>
>>> Yes indeed. Somehow checkpatch does not report this line, I don't know why.
>>>
>>>>
>>>> If you're happy with these, I can make the changes, too; they're trivial.
>>>
>>> Only the second one? Thanks :)
>>
>> Works for me. I'd still think the overhead of managing the buffer is
>> irrelevant where to having an extra function to do essentially the same
>> thing is a source of maintenance and review work. Note that we're even now
>> spending time to discuss it. ;-)
>>
>> -- 
>> Kind regards,
>>
>> Sakari Ailus
>> e-mail: sakari.ai...@iki.fi
> 

-- 
Best regards,
Todor Tomov


Re: [PATCH v4 2/2] media: Add a driver for the ov7251 camera sensor

2018-04-26 Thread Todor Tomov
Hi Sakari,

On 26.04.2018 09:50, Sakari Ailus wrote:
> Hi Todor,
> 
> On Wed, Apr 25, 2018 at 07:20:46PM +0300, Todor Tomov wrote:
> ...
>> +static int ov7251_write_reg(struct ov7251 *ov7251, u16 reg, u8 val)
>> +{
>> +u8 regbuf[3];
>> +int ret;
>> +
>> +regbuf[0] = reg >> 8;
>> +regbuf[1] = reg & 0xff;
>> +regbuf[2] = val;
>> +
>> +ret = i2c_master_send(ov7251->i2c_client, regbuf, 3);
>> +if (ret < 0) {
>> +dev_err(ov7251->dev, "%s: write reg error %d: reg=%x, val=%x\n",
>> +__func__, ret, reg, val);
>> +return ret;
>> +}
>> +
>> +return 0;
> 
> How about:
> 
>   return ov7251_write_seq_regs(ov7251, reg, , 1);
> 
> And put the function below ov2751_write_seq_regs().

I'm not sure... It will calculate message length each time and then check
that it is not greater than 5, which it is. Seems redundant.

> 
>> +}
>> +
>> +static int ov7251_write_seq_regs(struct ov7251 *ov7251, u16 reg, u8 *val,
>> + u8 num)
>> +{
>> +const u8 maxregbuf = 5;
>> +u8 regbuf[maxregbuf];
>> +u8 nregbuf = sizeof(reg) + num * sizeof(*val);
>> +int ret = 0;
>> +
>> +if (nregbuf > maxregbuf)
>> +return -EINVAL;
>> +
>> +regbuf[0] = reg >> 8;
>> +regbuf[1] = reg & 0xff;
>> +
>> +memcpy(regbuf + 2, val, num);
>> +
>> +ret = i2c_master_send(ov7251->i2c_client, regbuf, nregbuf);
>> +if (ret < 0) {
>> +dev_err(ov7251->dev, "%s: write seq regs error %d: first 
>> reg=%x\n",
> 
> This line is over 80... 

Yes indeed. Somehow checkpatch does not report this line, I don't know why.

> 
> If you're happy with these, I can make the changes, too; they're trivial.

Only the second one? Thanks :)

> 
>> +__func__, ret, reg);
>> +return ret;
>> +}
>> +
>> +return 0;
>> +}
> 

-- 
Best regards,
Todor Tomov


[PATCH v4 0/2] Add support for ov7251 camera sensor

2018-04-25 Thread Todor Tomov
The ov7251 sensor is a 1/7.5-Inch B VGA (640x480) CMOS Digital Image
Sensor from Omnivision.

--

Version 4:
- remove OF dependency;
- use only stack memory in ov7251_write_seq_regs();
- use DIV_ROUND_UP to round up sleep interval after gpio config;
- minor style changes.

--

Version 3:
- DT binding: added that there shall be a single endpoint node in the port node;
- added a comment for regulator enable order;
- set exposure and gain with a single i2c transaction;
- caclulate sleep after gpio config from external clock frequency;
- use MEDIA_BUS_FMT_Y10_1X10 format code;
- lock for power state, controls, mode and start streaming;
- remove regulator_set_voltage();
- use probe_new();
- remove i2c_device_id table;
- change of_property_read_u32 to fwnode_property_read_u32;
- few corrections from checkpatch --strict.

--

Version 2:
- changed ov7251 node's name in DT binding example;
- SPDX licence identifier;
- better names for register value defines;
- remove power reference counting and leave a power state only;
- use v4l2_find_nearest_size() to find sensor mode by requested size;
- set ycbcr_enc, quantization and xfer_func in set_fmt;
- use struct fwnode_handle instead of struct device_node;
- add comment in driver about external clock value.

--

Todor Tomov (2):
  dt-bindings: media: Binding document for OV7251 camera sensor
  media: Add a driver for the ov7251 camera sensor

 .../devicetree/bindings/media/i2c/ov7251.txt   |   52 +
 drivers/media/i2c/Kconfig  |   12 +
 drivers/media/i2c/Makefile |1 +
 drivers/media/i2c/ov7251.c | 1503 
 4 files changed, 1568 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/i2c/ov7251.txt
 create mode 100644 drivers/media/i2c/ov7251.c

-- 
2.7.4



[PATCH v4 2/2] media: Add a driver for the ov7251 camera sensor

2018-04-25 Thread Todor Tomov
The ov7251 sensor is a 1/7.5-Inch B VGA (640x480) CMOS Digital Image
Sensor from Omnivision.

The driver supports the following modes:
- 640x480 30fps
- 640x480 60fps
- 640x480 90fps

Output format is 10bit B RAW - MEDIA_BUS_FMT_Y10_1X10.

The driver supports configuration via user controls for:
- exposure and gain;
- horizontal and vertical flip;
- test pattern.

Signed-off-by: Todor Tomov <todor.to...@linaro.org>
Reviewed-by: Jacopo Mondi <jac...@jmondi.org>
---
 drivers/media/i2c/Kconfig  |   12 +
 drivers/media/i2c/Makefile |1 +
 drivers/media/i2c/ov7251.c | 1503 
 3 files changed, 1516 insertions(+)
 create mode 100644 drivers/media/i2c/ov7251.c

diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index 541f0d28..3dd16c6 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -688,6 +688,18 @@ config VIDEO_OV5695
  To compile this driver as a module, choose M here: the
  module will be called ov5695.
 
+config VIDEO_OV7251
+   tristate "OmniVision OV7251 sensor support"
+   depends on I2C && VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API
+   depends on MEDIA_CAMERA_SUPPORT
+   select V4L2_FWNODE
+   help
+ This is a Video4Linux2 sensor-level driver for the OmniVision
+ OV7251 camera.
+
+ To compile this driver as a module, choose M here: the
+ module will be called ov7251.
+
 config VIDEO_OV772X
tristate "OmniVision OV772x sensor support"
depends on I2C && VIDEO_V4L2
diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile
index ea34aee..c8585b1 100644
--- a/drivers/media/i2c/Makefile
+++ b/drivers/media/i2c/Makefile
@@ -70,6 +70,7 @@ obj-$(CONFIG_VIDEO_OV5647) += ov5647.o
 obj-$(CONFIG_VIDEO_OV5670) += ov5670.o
 obj-$(CONFIG_VIDEO_OV5695) += ov5695.o
 obj-$(CONFIG_VIDEO_OV6650) += ov6650.o
+obj-$(CONFIG_VIDEO_OV7251) += ov7251.o
 obj-$(CONFIG_VIDEO_OV7640) += ov7640.o
 obj-$(CONFIG_VIDEO_OV7670) += ov7670.o
 obj-$(CONFIG_VIDEO_OV772X) += ov772x.o
diff --git a/drivers/media/i2c/ov7251.c b/drivers/media/i2c/ov7251.c
new file mode 100644
index 000..c05a9de
--- /dev/null
+++ b/drivers/media/i2c/ov7251.c
@@ -0,0 +1,1503 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Driver for the OV7251 camera sensor.
+ *
+ * Copyright (c) 2017-2018, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2017-2018, Linaro Ltd.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define OV7251_SC_MODE_SELECT  0x0100
+#define OV7251_SC_MODE_SELECT_SW_STANDBY   0x0
+#define OV7251_SC_MODE_SELECT_STREAMING0x1
+
+#define OV7251_CHIP_ID_HIGH0x300a
+#define OV7251_CHIP_ID_HIGH_BYTE   0x77
+#define OV7251_CHIP_ID_LOW 0x300b
+#define OV7251_CHIP_ID_LOW_BYTE0x50
+#define OV7251_SC_GP_IO_IN10x3029
+#define OV7251_AEC_EXPO_0  0x3500
+#define OV7251_AEC_EXPO_1  0x3501
+#define OV7251_AEC_EXPO_2  0x3502
+#define OV7251_AEC_AGC_ADJ_0   0x350a
+#define OV7251_AEC_AGC_ADJ_1   0x350b
+#define OV7251_TIMING_FORMAT1  0x3820
+#define OV7251_TIMING_FORMAT1_VFLIPBIT(2)
+#define OV7251_TIMING_FORMAT2  0x3821
+#define OV7251_TIMING_FORMAT2_MIRROR   BIT(2)
+#define OV7251_PRE_ISP_00  0x5e00
+#define OV7251_PRE_ISP_00_TEST_PATTERN BIT(7)
+
+struct reg_value {
+   u16 reg;
+   u8 val;
+};
+
+struct ov7251_mode_info {
+   u32 width;
+   u32 height;
+   const struct reg_value *data;
+   u32 data_size;
+   u32 pixel_clock;
+   u32 link_freq;
+   u16 exposure_max;
+   u16 exposure_def;
+   struct v4l2_fract timeperframe;
+};
+
+struct ov7251 {
+   struct i2c_client *i2c_client;
+   struct device *dev;
+   struct v4l2_subdev sd;
+   struct media_pad pad;
+   struct v4l2_fwnode_endpoint ep;
+   struct v4l2_mbus_framefmt fmt;
+   struct v4l2_rect crop;
+   struct clk *xclk;
+   u32 xclk_freq;
+
+   struct regulator *io_regulator;
+   struct regulator *core_regulator;
+   struct regulator *analog_regulator;
+
+   const struct ov7251_mode_info *current_mode;
+
+   struct v4l2_ctrl_handler ctrls;
+   struct v4l2_ctrl *pixel_clock;
+   struct v4l2_ctrl *link_freq;
+   struct v4l2_ctrl *exposure;
+   struct v4l2_ctrl *gain;
+
+   /* Cached register values */
+   u8 aec_pk_manual;
+   u8 pre_isp_00;
+   u8 timing_format1;
+   u8 timing_format2;
+
+   struct mutex lock; /* lock to protect power state, ctrls and mode */
+   bool power_on;
+
+   struct gpio_desc *enable_gpio;
+};
+
+static inline struct ov7251 *to_ov7251(struct v4l2_subdev *sd)
+{
+   return container_of(sd, struct ov7251, sd);
+}
+
+

[PATCH v4 1/2] dt-bindings: media: Binding document for OV7251 camera sensor

2018-04-25 Thread Todor Tomov
Add the document for ov7251 device tree binding.

CC: Rob Herring <r...@kernel.org>
CC: Mark Rutland <mark.rutl...@arm.com>
CC: devicet...@vger.kernel.org
Signed-off-by: Todor Tomov <todor.to...@linaro.org>
Reviewed-by: Rob Herring <r...@kernel.org>
---
 .../devicetree/bindings/media/i2c/ov7251.txt   | 52 ++
 1 file changed, 52 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/i2c/ov7251.txt

diff --git a/Documentation/devicetree/bindings/media/i2c/ov7251.txt 
b/Documentation/devicetree/bindings/media/i2c/ov7251.txt
new file mode 100644
index 000..8281151
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/i2c/ov7251.txt
@@ -0,0 +1,52 @@
+* Omnivision 1/7.5-Inch B VGA CMOS Digital Image Sensor
+
+The Omnivision OV7251 is a 1/7.5-Inch CMOS active pixel digital image sensor
+with an active array size of 640H x 480V. It is programmable through a serial
+I2C interface.
+
+Required Properties:
+- compatible: Value should be "ovti,ov7251".
+- clocks: Reference to the xclk clock.
+- clock-names: Should be "xclk".
+- clock-frequency: Frequency of the xclk clock.
+- enable-gpios: Chip enable GPIO. Polarity is GPIO_ACTIVE_HIGH. This 
corresponds
+  to the hardware pin XSHUTDOWN which is physically active low.
+- vdddo-supply: Chip digital IO regulator.
+- vdda-supply: Chip analog regulator.
+- vddd-supply: Chip digital core regulator.
+
+The device node shall contain one 'port' child node with a single 'endpoint'
+subnode for its digital output video port, in accordance with the video
+interface bindings defined in
+Documentation/devicetree/bindings/media/video-interfaces.txt.
+
+Example:
+
+{
+   ...
+
+   ov7251: camera-sensor@60 {
+   compatible = "ovti,ov7251";
+   reg = <0x60>;
+
+   enable-gpios = < 6 GPIO_ACTIVE_HIGH>;
+   pinctrl-names = "default";
+   pinctrl-0 = <_bw_default>;
+
+   clocks = < 200>;
+   clock-names = "xclk";
+   clock-frequency = <2400>;
+
+   vdddo-supply = <_dovdd_1v8>;
+   vdda-supply = <_avdd_2v8>;
+   vddd-supply = <_dvdd_1v2>;
+
+   port {
+   ov7251_ep: endpoint {
+   clock-lanes = <1>;
+   data-lanes = <0>;
+   remote-endpoint = <_ep>;
+   };
+   };
+   };
+   };
-- 
2.7.4



Re: [PATCH v3 2/2] media: Add a driver for the ov7251 camera sensor

2018-04-25 Thread Todor Tomov
Hi,

On 25.04.2018 13:54, Sakari Ailus wrote:
> Hi Todor,
> 
> Thanks for the update. Just a few minor comments below.

Thanks for the review again, Sakari.
I'm preparing the next version.

Best regards,
Todor


[PATCH v3 2/2] media: Add a driver for the ov7251 camera sensor

2018-04-24 Thread Todor Tomov
The ov7251 sensor is a 1/7.5-Inch B VGA (640x480) CMOS Digital Image
Sensor from Omnivision.

The driver supports the following modes:
- 640x480 30fps
- 640x480 60fps
- 640x480 90fps

Output format is 10bit B RAW - MEDIA_BUS_FMT_Y10_1X10.

The driver supports configuration via user controls for:
- exposure and gain;
- horizontal and vertical flip;
- test pattern.

Signed-off-by: Todor Tomov <todor.to...@linaro.org>
Reviewed-by: Jacopo Mondi <jac...@jmondi.org>
---
 drivers/media/i2c/Kconfig  |   13 +
 drivers/media/i2c/Makefile |1 +
 drivers/media/i2c/ov7251.c | 1501 
 3 files changed, 1515 insertions(+)
 create mode 100644 drivers/media/i2c/ov7251.c

diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index 541f0d28..1ff7aaf 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -688,6 +688,19 @@ config VIDEO_OV5695
  To compile this driver as a module, choose M here: the
  module will be called ov5695.
 
+config VIDEO_OV7251
+   tristate "OmniVision OV7251 sensor support"
+   depends on OF
+   depends on I2C && VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API
+   depends on MEDIA_CAMERA_SUPPORT
+   select V4L2_FWNODE
+   help
+ This is a Video4Linux2 sensor-level driver for the OmniVision
+ OV7251 camera.
+
+ To compile this driver as a module, choose M here: the
+ module will be called ov7251.
+
 config VIDEO_OV772X
tristate "OmniVision OV772x sensor support"
depends on I2C && VIDEO_V4L2
diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile
index ea34aee..c8585b1 100644
--- a/drivers/media/i2c/Makefile
+++ b/drivers/media/i2c/Makefile
@@ -70,6 +70,7 @@ obj-$(CONFIG_VIDEO_OV5647) += ov5647.o
 obj-$(CONFIG_VIDEO_OV5670) += ov5670.o
 obj-$(CONFIG_VIDEO_OV5695) += ov5695.o
 obj-$(CONFIG_VIDEO_OV6650) += ov6650.o
+obj-$(CONFIG_VIDEO_OV7251) += ov7251.o
 obj-$(CONFIG_VIDEO_OV7640) += ov7640.o
 obj-$(CONFIG_VIDEO_OV7670) += ov7670.o
 obj-$(CONFIG_VIDEO_OV772X) += ov772x.o
diff --git a/drivers/media/i2c/ov7251.c b/drivers/media/i2c/ov7251.c
new file mode 100644
index 000..69e70a0
--- /dev/null
+++ b/drivers/media/i2c/ov7251.c
@@ -0,0 +1,1501 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Driver for the OV7251 camera sensor.
+ *
+ * Copyright (c) 2017-2018, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2017-2018, Linaro Ltd.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define OV7251_SC_MODE_SELECT  0x0100
+#define OV7251_SC_MODE_SELECT_SW_STANDBY   0x0
+#define OV7251_SC_MODE_SELECT_STREAMING0x1
+
+#define OV7251_CHIP_ID_HIGH0x300a
+#define OV7251_CHIP_ID_HIGH_BYTE   0x77
+#define OV7251_CHIP_ID_LOW 0x300b
+#define OV7251_CHIP_ID_LOW_BYTE0x50
+#define OV7251_SC_GP_IO_IN10x3029
+#define OV7251_AEC_EXPO_0  0x3500
+#define OV7251_AEC_EXPO_1  0x3501
+#define OV7251_AEC_EXPO_2  0x3502
+#define OV7251_AEC_AGC_ADJ_0   0x350a
+#define OV7251_AEC_AGC_ADJ_1   0x350b
+#define OV7251_TIMING_FORMAT1  0x3820
+#define OV7251_TIMING_FORMAT1_VFLIPBIT(2)
+#define OV7251_TIMING_FORMAT2  0x3821
+#define OV7251_TIMING_FORMAT2_MIRROR   BIT(2)
+#define OV7251_PRE_ISP_00  0x5e00
+#define OV7251_PRE_ISP_00_TEST_PATTERN BIT(7)
+
+struct reg_value {
+   u16 reg;
+   u8 val;
+};
+
+struct ov7251_mode_info {
+   u32 width;
+   u32 height;
+   const struct reg_value *data;
+   u32 data_size;
+   u32 pixel_clock;
+   u32 link_freq;
+   u16 exposure_max;
+   u16 exposure_def;
+   struct v4l2_fract timeperframe;
+};
+
+struct ov7251 {
+   struct i2c_client *i2c_client;
+   struct device *dev;
+   struct v4l2_subdev sd;
+   struct media_pad pad;
+   struct v4l2_fwnode_endpoint ep;
+   struct v4l2_mbus_framefmt fmt;
+   struct v4l2_rect crop;
+   struct clk *xclk;
+   u32 xclk_freq;
+
+   struct regulator *io_regulator;
+   struct regulator *core_regulator;
+   struct regulator *analog_regulator;
+
+   const struct ov7251_mode_info *current_mode;
+
+   struct v4l2_ctrl_handler ctrls;
+   struct v4l2_ctrl *pixel_clock;
+   struct v4l2_ctrl *link_freq;
+   struct v4l2_ctrl *exposure;
+   struct v4l2_ctrl *gain;
+
+   /* Cached register values */
+   u8 aec_pk_manual;
+   u8 pre_isp_00;
+   u8 timing_format1;
+   u8 timing_format2;
+
+   struct mutex lock; /* lock to protect power state, ctrls and mode */
+   bool power_on;
+
+   struct gpio_desc *enable_gpio;
+};
+
+static inline struct ov7251 *to_ov7251(struct v4l2_subdev *sd)
+{
+   return container_of(sd,

[PATCH v3 0/2] Add support for ov7251 camera sensor

2018-04-24 Thread Todor Tomov
The ov7251 sensor is a 1/7.5-Inch B VGA (640x480) CMOS Digital Image
Sensor from Omnivision.

--

Version 3:
- DT binding: added that there shall be a single endpoint node in the port node;
- added a comment for regulator enable order;
- set exposure and gain with a single i2c transaction;
- caclulate sleep after gpio config from external clock frequency;
- use MEDIA_BUS_FMT_Y10_1X10 format code;
- lock for power state, controls, mode and start streaming;
- remove regulator_set_voltage();
- use probe_new();
- remove i2c_device_id table;
- change of_property_read_u32 to fwnode_property_read_u32;
- few corrections from checkpatch --strict.

--

Version 2:
- changed ov7251 node's name in DT binding example;
- SPDX licence identifier;
- better names for register value defines;
- remove power reference counting and leave a power state only;
- use v4l2_find_nearest_size() to find sensor mode by requested size;
- set ycbcr_enc, quantization and xfer_func in set_fmt;
- use struct fwnode_handle instead of struct device_node;
- add comment in driver about external clock value.

--

Todor Tomov (2):
  dt-bindings: media: Binding document for OV7251 camera sensor
  media: Add a driver for the ov7251 camera sensor

 .../devicetree/bindings/media/i2c/ov7251.txt   |   52 +
 drivers/media/i2c/Kconfig  |   13 +
 drivers/media/i2c/Makefile |1 +
 drivers/media/i2c/ov7251.c | 1501 
 4 files changed, 1567 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/i2c/ov7251.txt
 create mode 100644 drivers/media/i2c/ov7251.c

-- 
2.7.4



[PATCH v3 1/2] dt-bindings: media: Binding document for OV7251 camera sensor

2018-04-24 Thread Todor Tomov
Add the document for ov7251 device tree binding.

CC: Rob Herring <r...@kernel.org>
CC: Mark Rutland <mark.rutl...@arm.com>
CC: devicet...@vger.kernel.org
Signed-off-by: Todor Tomov <todor.to...@linaro.org>
Reviewed-by: Rob Herring <r...@kernel.org>
---
 .../devicetree/bindings/media/i2c/ov7251.txt   | 52 ++
 1 file changed, 52 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/i2c/ov7251.txt

diff --git a/Documentation/devicetree/bindings/media/i2c/ov7251.txt 
b/Documentation/devicetree/bindings/media/i2c/ov7251.txt
new file mode 100644
index 000..8281151
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/i2c/ov7251.txt
@@ -0,0 +1,52 @@
+* Omnivision 1/7.5-Inch B VGA CMOS Digital Image Sensor
+
+The Omnivision OV7251 is a 1/7.5-Inch CMOS active pixel digital image sensor
+with an active array size of 640H x 480V. It is programmable through a serial
+I2C interface.
+
+Required Properties:
+- compatible: Value should be "ovti,ov7251".
+- clocks: Reference to the xclk clock.
+- clock-names: Should be "xclk".
+- clock-frequency: Frequency of the xclk clock.
+- enable-gpios: Chip enable GPIO. Polarity is GPIO_ACTIVE_HIGH. This 
corresponds
+  to the hardware pin XSHUTDOWN which is physically active low.
+- vdddo-supply: Chip digital IO regulator.
+- vdda-supply: Chip analog regulator.
+- vddd-supply: Chip digital core regulator.
+
+The device node shall contain one 'port' child node with a single 'endpoint'
+subnode for its digital output video port, in accordance with the video
+interface bindings defined in
+Documentation/devicetree/bindings/media/video-interfaces.txt.
+
+Example:
+
+{
+   ...
+
+   ov7251: camera-sensor@60 {
+   compatible = "ovti,ov7251";
+   reg = <0x60>;
+
+   enable-gpios = < 6 GPIO_ACTIVE_HIGH>;
+   pinctrl-names = "default";
+   pinctrl-0 = <_bw_default>;
+
+   clocks = < 200>;
+   clock-names = "xclk";
+   clock-frequency = <2400>;
+
+   vdddo-supply = <_dovdd_1v8>;
+   vdda-supply = <_avdd_2v8>;
+   vddd-supply = <_dvdd_1v2>;
+
+   port {
+   ov7251_ep: endpoint {
+   clock-lanes = <1>;
+   data-lanes = <0>;
+   remote-endpoint = <_ep>;
+   };
+   };
+   };
+   };
-- 
2.7.4



Re: [PATCH v2 2/2] media: Add a driver for the ov7251 camera sensor

2018-04-24 Thread Todor Tomov
Hi Sakari,

On 17.04.2018 23:10, Sakari Ailus wrote:
> Hi Todor,
> 
> On Tue, Apr 17, 2018 at 06:32:07PM +0300, Todor Tomov wrote:
> ...
>>>> +static int ov7251_regulators_enable(struct ov7251 *ov7251)
>>>> +{
>>>> +  int ret;
>>>> +
>>>> +  ret = regulator_enable(ov7251->io_regulator);
>>>
>>> How about regulator_bulk_enable() here, and bulk_disable below?
>>
>> I'm not using the bulk API because usually there is a power up
>> sequence and intervals that must be followed. For this sensor
>> the only constraint is that core regulator must be enabled
>> after io regulator. But the bulk API doesn't guarantee the
>> order.
> 
> Could you add a comment explaining this? Otherwise it won't take long until
> someone "fixes" the code.

Sure :D
I'm adding a comment.

> 
> ...
> 
>>>> +static int ov7251_read_reg(struct ov7251 *ov7251, u16 reg, u8 *val)
>>>> +{
>>>> +  u8 regbuf[2];
>>>> +  int ret;
>>>> +
>>>> +  regbuf[0] = reg >> 8;
>>>> +  regbuf[1] = reg & 0xff;
>>>> +
>>>> +  ret = i2c_master_send(ov7251->i2c_client, regbuf, 2);
>>>> +  if (ret < 0) {
>>>> +  dev_err(ov7251->dev, "%s: write reg error %d: reg=%x\n",
>>>> +  __func__, ret, reg);
>>>> +  return ret;
>>>> +  }
>>>> +
>>>> +  ret = i2c_master_recv(ov7251->i2c_client, val, 1);
>>>> +  if (ret < 0) {
>>>> +  dev_err(ov7251->dev, "%s: read reg error %d: reg=%x\n",
>>>> +  __func__, ret, reg);
>>>> +  return ret;
>>>> +  }
>>>> +
>>>> +  return 0;
>>>> +}
>>>> +
>>>> +static int ov7251_set_exposure(struct ov7251 *ov7251, s32 exposure)
>>>> +{
>>>> +  int ret;
>>>> +
>>>> +  ret = ov7251_write_reg(ov7251, OV7251_AEC_EXPO_0,
>>>> + (exposure & 0xf000) >> 12);
>>>> +  if (ret < 0)
>>>> +  return ret;
>>>> +
>>>> +  ret = ov7251_write_reg(ov7251, OV7251_AEC_EXPO_1,
>>>> + (exposure & 0x0ff0) >> 4);
>>>> +  if (ret < 0)
>>>> +  return ret;
>>>> +
>>>> +  return ov7251_write_reg(ov7251, OV7251_AEC_EXPO_2,
>>>> +  (exposure & 0x000f) << 4);
>>>
>>> It's not a good idea to access multi-octet registers separately. Depending
>>> on the hardware implementation, the hardware could latch the value in the
>>> middle of an update. This is only an issue during streaming in practice
>>> though.
>>
>> Good point. The sensor has a group write functionality which can be used
>> to solve this but in general is intended
>> to apply a group of exposure and gain settings in the same frame. However
>> it seems to me that is not possible to use this functionality efficiently
>> with the currently available user controls. The group write is configured
>> using an id for a group of commands. So if we configure exposure and gain
>> separately (a group for each):
>> - if the driver uses same group id for exposure and gain, if both controls
>>   are received in one frame the second will overwrite the first (the
>>   first will not be applied);
>> - if the driver uses different group id for exposure and gain, it will not
>>   be possible for the user to change exposure and gain in the same frame
>>   (as some exposure algorithms do) and it will lead again to frames with
>>   "incorrect" brightness.
>>
>> To do this correctly we will have to extend the API to be able to apply
>> exposure and gain "atomically":
>> - a single user control which will set both exposure and gain and it will
>>   guarantee that they will be applied in the same frame;
>> - some kind of: begin, set exposure, set gain, end, launch -API
>>
>> What do you think?
>>
>> Actually, I'm a little bit surprised that I didn't find anything
>> like this already. And there are already a number of sensor drivers
>> which update more than one register to set exposure.
> 
> The latter of the two would be preferred as it isn't limited to exposure
> and gain only. Still, you could address the problem for this driver by
> simply writing the register in a single transaction.

Thanks for suggestion. I've tried the single transaction, I will send the
next version of the driver shortly.

-- 
Best regards,
Todor Tomov


Re: [PATCH v2 2/2] media: Add a driver for the ov7251 camera sensor

2018-04-17 Thread Todor Tomov
Hi Sakari,

Thank you for the review.

On 29.03.2018 14:51, Sakari Ailus wrote:
> Hi Todor,
> 
> Thanks for the patch. A few quick comments below...
> 
> On Fri, Mar 23, 2018 at 12:14:20PM +0800, Todor Tomov wrote:
>> The ov7251 sensor is a 1/7.5-Inch B VGA (640x480) CMOS Digital Image
>> Sensor from Omnivision.
>>
>> The driver supports the following modes:
>> - 640x480 30fps
>> - 640x480 60fps
>> - 640x480 90fps
>>
>> Output format is MIPI RAW 10.
>>
>> The driver supports configuration via user controls for:
>> - exposure and gain;
>> - horizontal and vertical flip;
>> - test pattern.
>>
>> Signed-off-by: Todor Tomov <todor.to...@linaro.org>
>> ---
>>  drivers/media/i2c/Kconfig  |   13 +
>>  drivers/media/i2c/Makefile |1 +
>>  drivers/media/i2c/ov7251.c | 1494 
>> 
>>  3 files changed, 1508 insertions(+)
>>  create mode 100644 drivers/media/i2c/ov7251.c
>>
>> diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
>> index 541f0d28..89aecb3 100644
>> --- a/drivers/media/i2c/Kconfig
>> +++ b/drivers/media/i2c/Kconfig
>> @@ -688,6 +688,19 @@ config VIDEO_OV5695
>>To compile this driver as a module, choose M here: the
>>module will be called ov5695.
>>  
>> +config VIDEO_OV7251
>> +tristate "OmniVision OV7251 sensor support"
>> +depends on OF
>> +depends on I2C && VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API
>> +depends on MEDIA_CAMERA_SUPPORT
>> +select V4L2_FWNODE
>> +---help---
>> +  This is a Video4Linux2 sensor-level driver for the OmniVision
>> +  OV7251 camera.
>> +
>> +  To compile this driver as a module, choose M here: the
>> +  module will be called ov7251.
>> +
>>  config VIDEO_OV772X
>>  tristate "OmniVision OV772x sensor support"
>>  depends on I2C && VIDEO_V4L2
>> diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile
>> index ea34aee..c8585b1 100644
>> --- a/drivers/media/i2c/Makefile
>> +++ b/drivers/media/i2c/Makefile
>> @@ -70,6 +70,7 @@ obj-$(CONFIG_VIDEO_OV5647) += ov5647.o
>>  obj-$(CONFIG_VIDEO_OV5670) += ov5670.o
>>  obj-$(CONFIG_VIDEO_OV5695) += ov5695.o
>>  obj-$(CONFIG_VIDEO_OV6650) += ov6650.o
>> +obj-$(CONFIG_VIDEO_OV7251) += ov7251.o
>>  obj-$(CONFIG_VIDEO_OV7640) += ov7640.o
>>  obj-$(CONFIG_VIDEO_OV7670) += ov7670.o
>>  obj-$(CONFIG_VIDEO_OV772X) += ov772x.o
>> diff --git a/drivers/media/i2c/ov7251.c b/drivers/media/i2c/ov7251.c
>> new file mode 100644
>> index 000..7b401a9
>> --- /dev/null
>> +++ b/drivers/media/i2c/ov7251.c
>> @@ -0,0 +1,1494 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +/*
>> + * Driver for the OV7251 camera sensor.
>> + *
>> + * Copyright (c) 2017-2018, The Linux Foundation. All rights reserved.
>> + * Copyright (c) 2017-2018, Linaro Ltd.
>> + */
>> +
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +
>> +#define OV7251_VOLTAGE_ANALOG   280
>> +#define OV7251_VOLTAGE_DIGITAL_CORE 150
>> +#define OV7251_VOLTAGE_DIGITAL_IO   180
>> +
>> +#define OV7251_SC_MODE_SELECT   0x0100
>> +#define OV7251_SC_MODE_SELECT_SW_STANDBY0x0
>> +#define OV7251_SC_MODE_SELECT_STREAMING 0x1
>> +
>> +#define OV7251_CHIP_ID_HIGH 0x300a
>> +#define OV7251_CHIP_ID_HIGH_BYTE0x77
>> +#define OV7251_CHIP_ID_LOW  0x300b
>> +#define OV7251_CHIP_ID_LOW_BYTE 0x50
>> +#define OV7251_SC_GP_IO_IN1 0x3029
>> +#define OV7251_AEC_EXPO_0   0x3500
>> +#define OV7251_AEC_EXPO_1   0x3501
>> +#define OV7251_AEC_EXPO_2   0x3502
>> +#define OV7251_AEC_AGC_ADJ_00x350a
>> +#define OV7251_AEC_AGC_ADJ_10x350b
>> +#define OV7251_TIMING_FORMAT1   0x3820
>> +#define OV7251_TIMING_FORMAT1_VFLIP BIT(2)
>> +#define OV7251_TIMING_FORMAT2   0x3821
>> +#define OV7251_TIMING_FORMAT2_MIRRORBIT(2)
>> +#define OV7251_PRE_ISP_00   0x5e00
>> +#define OV7251_PRE_ISP_00_TEST_PATTERN  BIT(7)
>> +
>> +struct reg_value {
>> +u16 reg;
>>

Re: [v2,2/2] media: Add a driver for the ov7251 camera sensor

2018-03-29 Thread Todor Tomov
Hi Sakari

On 29.03.2018 11:29, Sakari Ailus wrote:
> Hi Todor and Jacopo,
> 
> On Thu, Mar 29, 2018 at 10:50:10AM +0300, Todor Tomov wrote:
> ...
>>>> +static const struct of_device_id ov7251_of_match[] = {
>>>> +  { .compatible = "ovti,ov7251" },
>>>> +  { /* sentinel */ }
>>>> +};
>>>> +MODULE_DEVICE_TABLE(of, ov7251_of_match);
>>>> +
>>>> +static struct i2c_driver ov7251_i2c_driver = {
>>>> +  .driver = {
>>>> +  .of_match_table = of_match_ptr(ov7251_of_match),
>>>> +  .name  = "ov7251",
>>>> +  },
>>>> +  .probe  = ov7251_probe,
>>>> +  .remove = ov7251_remove,
>>>> +  .id_table = ov7251_id,
>>>
>>> As this driver depends on CONFIG_OF, I've been suggested to use probe_new 
>>> and
>>> get rid of i2c id_tables.
>>
>> Yes, I'll do that.
> 
> The proposal sounds good to me but rather than adding CONFIG_OF dependency,
> I'd instead suggest changing the of_property_read_u32 to
> fwnode_property_read_u32; then the driver may work on ACPI based systems as
> well. 

Ok.

> There's another change needed, too, which is not using of_match_ptr
> macro, but instead assigning the of_match_table unconditionally.

In that case the MODULE_DEVICE_TABLE(i2c, ...) is again not needed?
And matching will be again via of_match_table?

> 
> Up to you.
> 

Thank you for your help!
 
Best regards,
Todor Tomov


Re: [v2,2/2] media: Add a driver for the ov7251 camera sensor

2018-03-29 Thread Todor Tomov
Hi Jacopo,

Thank you for your prompt review.

On 23.03.2018 15:40, jacopo mondi wrote:
> Hi Todor,
>thanks for the patch.
> 
> When running checkpatch --strict I see a few warning you can easily
> close (braces indentation mostly, and one additional empty line at
> line 1048).

Thank you for pointing me to the --strict mode. There are a few CHECKs for
braces alignment for which the alignment is still better as it is now
I think. However there were also a few reasonable points and I have
updated the code according to them.

> 
> A few more nits below.
> 
> On Fri, Mar 23, 2018 at 12:14:20PM +0800, Todor Tomov wrote:
>> The ov7251 sensor is a 1/7.5-Inch B VGA (640x480) CMOS Digital Image
>> Sensor from Omnivision.
>>
>> The driver supports the following modes:
>> - 640x480 30fps
>> - 640x480 60fps
>> - 640x480 90fps
>>
>> Output format is MIPI RAW 10.
>>
>> The driver supports configuration via user controls for:
>> - exposure and gain;
>> - horizontal and vertical flip;
>> - test pattern.
>>
>> Signed-off-by: Todor Tomov <todor.to...@linaro.org>
>> ---
>>  drivers/media/i2c/Kconfig  |   13 +
>>  drivers/media/i2c/Makefile |1 +
>>  drivers/media/i2c/ov7251.c | 1494 
>> 
>>  3 files changed, 1508 insertions(+)
>>  create mode 100644 drivers/media/i2c/ov7251.c
>>
>> diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
>> index 541f0d28..89aecb3 100644
>> --- a/drivers/media/i2c/Kconfig
>> +++ b/drivers/media/i2c/Kconfig
>> @@ -688,6 +688,19 @@ config VIDEO_OV5695
>>To compile this driver as a module, choose M here: the
>>module will be called ov5695.
>>
>> +config VIDEO_OV7251
>> +tristate "OmniVision OV7251 sensor support"
>> +depends on OF
>> +depends on I2C && VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API
>> +depends on MEDIA_CAMERA_SUPPORT
>> +select V4L2_FWNODE
>> +---help---
>> +  This is a Video4Linux2 sensor-level driver for the OmniVision
>> +  OV7251 camera.
>> +
>> +  To compile this driver as a module, choose M here: the
>> +  module will be called ov7251.
>> +
>>  config VIDEO_OV772X
>>  tristate "OmniVision OV772x sensor support"
>>  depends on I2C && VIDEO_V4L2
>> diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile
>> index ea34aee..c8585b1 100644
>> --- a/drivers/media/i2c/Makefile
>> +++ b/drivers/media/i2c/Makefile
>> @@ -70,6 +70,7 @@ obj-$(CONFIG_VIDEO_OV5647) += ov5647.o
>>  obj-$(CONFIG_VIDEO_OV5670) += ov5670.o
>>  obj-$(CONFIG_VIDEO_OV5695) += ov5695.o
>>  obj-$(CONFIG_VIDEO_OV6650) += ov6650.o
>> +obj-$(CONFIG_VIDEO_OV7251) += ov7251.o
>>  obj-$(CONFIG_VIDEO_OV7640) += ov7640.o
>>  obj-$(CONFIG_VIDEO_OV7670) += ov7670.o
>>  obj-$(CONFIG_VIDEO_OV772X) += ov772x.o
>> diff --git a/drivers/media/i2c/ov7251.c b/drivers/media/i2c/ov7251.c
>> new file mode 100644
>> index 000..7b401a9
>> --- /dev/null
>> +++ b/drivers/media/i2c/ov7251.c
>> @@ -0,0 +1,1494 @@



>> +static int ov7251_s_power(struct v4l2_subdev *sd, int on)
>> +{
>> +struct ov7251 *ov7251 = to_ov7251(sd);
>> +int ret = 0;
>> +
>> +mutex_lock(>power_lock);
>> +
>> +/*
>> + * If the power state is modified from 0 to 1 or from 1 to 0,
>> + * update the power state.
>> + */
>> +if (ov7251->power_on == !on) {
> 
> if (ov7251->power_on == !!on) {
> mutex_unlock(>power_lock);
> return 0;
> }
> 
> And you can save one indentation level and remove ret initialization.
> 

Good hint, I'd rather save one indentation level by:

if (ov7251->power_on == !!on)
goto exit;

> 
>> +if (on) {
>> +ret = ov7251_set_power_on(ov7251);
>> +if (ret < 0)
>> +goto exit;
>> +
>> +ret = ov7251_set_register_array(ov7251,
>> +ov7251_global_init_setting,
>> +ARRAY_SIZE(ov7251_global_init_setting));
>> +if (ret < 0) {
>> +dev_err(ov7251->dev,
>> +"could not set init registers\n");
>> +ov7251_set_power_off(ov7251);
>> +goto exit;
>> +

[PATCH v2 0/2] Add support for ov7251 camera sensor

2018-03-22 Thread Todor Tomov
The ov7251 sensor is a 1/7.5-Inch B VGA (640x480) CMOS Digital Image
Sensor from Omnivision.

--

Version 2:
- changed ov7251 node's name in DT binding example;
- SPDX licence identifier;
- better names for register value defines;
- remove power reference counting and leave a power state only;
- use v4l2_find_nearest_size() to find sensor mode by requested size;
- set ycbcr_enc, quantization and xfer_func in set_fmt;
- use struct fwnode_handle instead of struct device_node;
- add comment in driver about external clock value.

--

Todor Tomov (2):
  dt-bindings: media: Binding document for OV7251 camera sensor
  media: Add a driver for the ov7251 camera sensor

 .../devicetree/bindings/media/i2c/ov7251.txt   |   51 +
 drivers/media/i2c/Kconfig  |   13 +
 drivers/media/i2c/Makefile |1 +
 drivers/media/i2c/ov7251.c | 1494 
 4 files changed, 1559 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/i2c/ov7251.txt
 create mode 100644 drivers/media/i2c/ov7251.c

-- 
2.7.4



[PATCH v2 1/2] dt-bindings: media: Binding document for OV7251 camera sensor

2018-03-22 Thread Todor Tomov
Add the document for ov7251 device tree binding.

CC: Rob Herring <r...@kernel.org>
CC: Mark Rutland <mark.rutl...@arm.com>
CC: devicet...@vger.kernel.org
Signed-off-by: Todor Tomov <todor.to...@linaro.org>
Reviewed-by: Rob Herring <r...@kernel.org>
---
 .../devicetree/bindings/media/i2c/ov7251.txt   | 51 ++
 1 file changed, 51 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/i2c/ov7251.txt

diff --git a/Documentation/devicetree/bindings/media/i2c/ov7251.txt 
b/Documentation/devicetree/bindings/media/i2c/ov7251.txt
new file mode 100644
index 000..4ee6888
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/i2c/ov7251.txt
@@ -0,0 +1,51 @@
+* Omnivision 1/7.5-Inch B VGA CMOS Digital Image Sensor
+
+The Omnivision OV7251 is a 1/7.5-Inch CMOS active pixel digital image sensor 
with
+an active array size of 640H x 480V. It is programmable through a serial I2C
+interface.
+
+Required Properties:
+- compatible: Value should be "ovti,ov7251".
+- clocks: Reference to the xclk clock.
+- clock-names: Should be "xclk".
+- clock-frequency: Frequency of the xclk clock.
+- enable-gpios: Chip enable GPIO. Polarity is GPIO_ACTIVE_HIGH. This 
corresponds
+  to the hardware pin XSHUTDOWN which is physically active low.
+- vdddo-supply: Chip digital IO regulator.
+- vdda-supply: Chip analog regulator.
+- vddd-supply: Chip digital core regulator.
+
+The device node must contain one 'port' child node for its digital output
+video port, in accordance with the video interface bindings defined in
+Documentation/devicetree/bindings/media/video-interfaces.txt.
+
+Example:
+
+{
+   ...
+
+   ov7251: camera-sensor@60 {
+   compatible = "ovti,ov7251";
+   reg = <0x60>;
+
+   enable-gpios = < 6 GPIO_ACTIVE_HIGH>;
+   pinctrl-names = "default";
+   pinctrl-0 = <_bw_default>;
+
+   clocks = < 200>;
+   clock-names = "xclk";
+   clock-frequency = <2400>;
+
+   vdddo-supply = <_dovdd_1v8>;
+   vdda-supply = <_avdd_2v8>;
+   vddd-supply = <_dvdd_1v2>;
+
+   port {
+   ov7251_ep: endpoint {
+   clock-lanes = <1>;
+   data-lanes = <0>;
+   remote-endpoint = <_ep>;
+   };
+   };
+   };
+   };
-- 
2.7.4



[PATCH v2 2/2] media: Add a driver for the ov7251 camera sensor

2018-03-22 Thread Todor Tomov
The ov7251 sensor is a 1/7.5-Inch B VGA (640x480) CMOS Digital Image
Sensor from Omnivision.

The driver supports the following modes:
- 640x480 30fps
- 640x480 60fps
- 640x480 90fps

Output format is MIPI RAW 10.

The driver supports configuration via user controls for:
- exposure and gain;
- horizontal and vertical flip;
- test pattern.

Signed-off-by: Todor Tomov <todor.to...@linaro.org>
---
 drivers/media/i2c/Kconfig  |   13 +
 drivers/media/i2c/Makefile |1 +
 drivers/media/i2c/ov7251.c | 1494 
 3 files changed, 1508 insertions(+)
 create mode 100644 drivers/media/i2c/ov7251.c

diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index 541f0d28..89aecb3 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -688,6 +688,19 @@ config VIDEO_OV5695
  To compile this driver as a module, choose M here: the
  module will be called ov5695.
 
+config VIDEO_OV7251
+   tristate "OmniVision OV7251 sensor support"
+   depends on OF
+   depends on I2C && VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API
+   depends on MEDIA_CAMERA_SUPPORT
+   select V4L2_FWNODE
+   ---help---
+ This is a Video4Linux2 sensor-level driver for the OmniVision
+ OV7251 camera.
+
+ To compile this driver as a module, choose M here: the
+ module will be called ov7251.
+
 config VIDEO_OV772X
tristate "OmniVision OV772x sensor support"
depends on I2C && VIDEO_V4L2
diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile
index ea34aee..c8585b1 100644
--- a/drivers/media/i2c/Makefile
+++ b/drivers/media/i2c/Makefile
@@ -70,6 +70,7 @@ obj-$(CONFIG_VIDEO_OV5647) += ov5647.o
 obj-$(CONFIG_VIDEO_OV5670) += ov5670.o
 obj-$(CONFIG_VIDEO_OV5695) += ov5695.o
 obj-$(CONFIG_VIDEO_OV6650) += ov6650.o
+obj-$(CONFIG_VIDEO_OV7251) += ov7251.o
 obj-$(CONFIG_VIDEO_OV7640) += ov7640.o
 obj-$(CONFIG_VIDEO_OV7670) += ov7670.o
 obj-$(CONFIG_VIDEO_OV772X) += ov772x.o
diff --git a/drivers/media/i2c/ov7251.c b/drivers/media/i2c/ov7251.c
new file mode 100644
index 000..7b401a9
--- /dev/null
+++ b/drivers/media/i2c/ov7251.c
@@ -0,0 +1,1494 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Driver for the OV7251 camera sensor.
+ *
+ * Copyright (c) 2017-2018, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2017-2018, Linaro Ltd.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define OV7251_VOLTAGE_ANALOG   280
+#define OV7251_VOLTAGE_DIGITAL_CORE 150
+#define OV7251_VOLTAGE_DIGITAL_IO   180
+
+#define OV7251_SC_MODE_SELECT  0x0100
+#define OV7251_SC_MODE_SELECT_SW_STANDBY   0x0
+#define OV7251_SC_MODE_SELECT_STREAMING0x1
+
+#define OV7251_CHIP_ID_HIGH0x300a
+#define OV7251_CHIP_ID_HIGH_BYTE   0x77
+#define OV7251_CHIP_ID_LOW 0x300b
+#define OV7251_CHIP_ID_LOW_BYTE0x50
+#define OV7251_SC_GP_IO_IN10x3029
+#define OV7251_AEC_EXPO_0  0x3500
+#define OV7251_AEC_EXPO_1  0x3501
+#define OV7251_AEC_EXPO_2  0x3502
+#define OV7251_AEC_AGC_ADJ_0   0x350a
+#define OV7251_AEC_AGC_ADJ_1   0x350b
+#define OV7251_TIMING_FORMAT1  0x3820
+#define OV7251_TIMING_FORMAT1_VFLIPBIT(2)
+#define OV7251_TIMING_FORMAT2  0x3821
+#define OV7251_TIMING_FORMAT2_MIRROR   BIT(2)
+#define OV7251_PRE_ISP_00  0x5e00
+#define OV7251_PRE_ISP_00_TEST_PATTERN BIT(7)
+
+struct reg_value {
+   u16 reg;
+   u8 val;
+};
+
+struct ov7251_mode_info {
+   u32 width;
+   u32 height;
+   const struct reg_value *data;
+   u32 data_size;
+   u32 pixel_clock;
+   u32 link_freq;
+   u16 exposure_max;
+   u16 exposure_def;
+   struct v4l2_fract timeperframe;
+};
+
+struct ov7251 {
+   struct i2c_client *i2c_client;
+   struct device *dev;
+   struct v4l2_subdev sd;
+   struct media_pad pad;
+   struct v4l2_fwnode_endpoint ep;
+   struct v4l2_mbus_framefmt fmt;
+   struct v4l2_rect crop;
+   struct clk *xclk;
+
+   struct regulator *io_regulator;
+   struct regulator *core_regulator;
+   struct regulator *analog_regulator;
+
+   const struct ov7251_mode_info *current_mode;
+
+   struct v4l2_ctrl_handler ctrls;
+   struct v4l2_ctrl *pixel_clock;
+   struct v4l2_ctrl *link_freq;
+   struct v4l2_ctrl *exposure;
+   struct v4l2_ctrl *gain;
+
+   /* Cached register values */
+   u8 aec_pk_manual;
+   u8 pre_isp_00;
+   u8 timing_format1;
+   u8 timing_format2;
+
+   struct mutex power_lock; /* lock to protect power state */
+   bool power_on;
+
+   struct gpio_desc *enable_gpio;
+};
+
+static inline struct ov7251 *t

[PATCH v2 0/2] Add support for ov7251 camera sensor

2018-03-22 Thread Todor Tomov
The ov7251 sensor is a 1/7.5-Inch B VGA (640x480) CMOS Digital Image
Sensor from Omnivision.

--

Version 2:
- changed ov7251 node's name in DT binding example;
- SPDX licence identifier;
- better names for register value defines;
- remove power reference counting and leave a power state only;
- use v4l2_find_nearest_size() to find sensor mode by requested size;
- set ycbcr_enc, quantization and xfer_func in set_fmt;
- use struct fwnode_handle instead of struct device_node;
- add comment in driver about external clock value.

--

Todor Tomov (2):
  dt-bindings: media: Binding document for OV7251 camera sensor
  media: Add a driver for the ov7251 camera sensor

 .../devicetree/bindings/media/i2c/ov7251.txt   |   51 +
 drivers/media/i2c/Kconfig  |   13 +
 drivers/media/i2c/Makefile |1 +
 drivers/media/i2c/ov7251.c | 1494 
 4 files changed, 1559 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/i2c/ov7251.txt
 create mode 100644 drivers/media/i2c/ov7251.c

-- 
2.7.4



[PATCH] media: ov5645: Use v4l2_find_nearest_size

2018-03-21 Thread Todor Tomov
Use v4l2_find_nearest_size instead of a driver specific function to find
nearest matching size.

Signed-off-by: Todor Tomov <todor.to...@linaro.org>
---

This depends on [1] from Sakari. Thank you, Sakari, this is nice.

[1] 
https://git.linuxtv.org/sailus/media_tree.git/commit/?h=v4l2-common-size=83fdb8a0ab43fc86c329f63f1052e6113871a965

 drivers/media/i2c/ov5645.c | 24 +---
 1 file changed, 5 insertions(+), 19 deletions(-)

diff --git a/drivers/media/i2c/ov5645.c b/drivers/media/i2c/ov5645.c
index d28845f..79db74c 100644
--- a/drivers/media/i2c/ov5645.c
+++ b/drivers/media/i2c/ov5645.c
@@ -959,23 +959,6 @@ __ov5645_get_pad_crop(struct ov5645 *ov5645, struct 
v4l2_subdev_pad_config *cfg,
}
 }
 
-static const struct ov5645_mode_info *
-ov5645_find_nearest_mode(unsigned int width, unsigned int height)
-{
-   int i;
-
-   for (i = ARRAY_SIZE(ov5645_mode_info_data) - 1; i >= 0; i--) {
-   if (ov5645_mode_info_data[i].width <= width &&
-   ov5645_mode_info_data[i].height <= height)
-   break;
-   }
-
-   if (i < 0)
-   i = 0;
-
-   return _mode_info_data[i];
-}
-
 static int ov5645_set_format(struct v4l2_subdev *sd,
 struct v4l2_subdev_pad_config *cfg,
 struct v4l2_subdev_format *format)
@@ -989,8 +972,11 @@ static int ov5645_set_format(struct v4l2_subdev *sd,
__crop = __ov5645_get_pad_crop(ov5645, cfg, format->pad,
format->which);
 
-   new_mode = ov5645_find_nearest_mode(format->format.width,
-   format->format.height);
+   new_mode = v4l2_find_nearest_size(ov5645_mode_info_data,
+  ARRAY_SIZE(ov5645_mode_info_data),
+  width, height,
+  format->format.width, format->format.height);
+
__crop->width = new_mode->width;
__crop->height = new_mode->height;
 
-- 
2.7.4



Re: [PATCH] media: ov5645: add missing of_node_put() in error path

2018-03-21 Thread Todor Tomov
Thank you Akinobu.

Acked-by: Todor Tomov <todor.to...@linaro.org>

On 20.03.2018 00:14, Akinobu Mita wrote:
> The device node obtained with of_graph_get_next_endpoint() should be
> released by calling of_node_put().  But it was not released when
> v4l2_fwnode_endpoint_parse() failed.
> 
> This change moves the of_node_put() call before the error check and
> fixes the issue.
> 
> Cc: Todor Tomov <todor.to...@linaro.org>
> Cc: Sakari Ailus <sakari.ai...@linux.intel.com>
> Cc: Mauro Carvalho Chehab <mche...@s-opensource.com>
> Signed-off-by: Akinobu Mita <akinobu.m...@gmail.com>
> ---
>  drivers/media/i2c/ov5645.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/media/i2c/ov5645.c b/drivers/media/i2c/ov5645.c
> index d28845f..a31fe18 100644
> --- a/drivers/media/i2c/ov5645.c
> +++ b/drivers/media/i2c/ov5645.c
> @@ -1131,13 +1131,14 @@ static int ov5645_probe(struct i2c_client *client,
>  
>   ret = v4l2_fwnode_endpoint_parse(of_fwnode_handle(endpoint),
>>ep);
> +
> + of_node_put(endpoint);
> +
>   if (ret < 0) {
>   dev_err(dev, "parsing endpoint node failed\n");
>   return ret;
>   }
>  
> - of_node_put(endpoint);
> -
>   if (ov5645->ep.bus_type != V4L2_MBUS_CSI2) {
>   dev_err(dev, "invalid bus type, must be CSI2\n");
>   return -EINVAL;
> 


Re: [PATCH 00/20] Add multiplexed media pads to support CSI-2 virtual channels

2018-03-16 Thread Todor Tomov
Hi Niklas,

On 16.03.2018 01:16, Niklas Söderlund wrote:
> Hi Todor,
> 
> On 2018-03-15 11:43:31 +0200, Todor Tomov wrote:
>> Hello,
>>
>> I'm trying to understand what is the current state of the multiple virtual
>> channel support in V4L2 and Media framework. This is the last activity
>> on this topic which I was able to find. Is anything new happened since
>> this RFC, is someone working on this or planing to work on?
> 
> I'm currently working on this but right now I'm focusing on driver 
> dependencies for my use-case, once that is done I will resume to push 
> more for the multiplexed stream support. I randomly push my latest work 
> to
> 
> git://git.ragnatech.se/linux v4l2/mux
> 
> But this is a unstable branch and contains some LOCAL patches to test my 
> work on Renesas platforms. But if you want to checkout my current status 
> that's the branch to check.
> 
> Out of curiosity what board or use-case are you interested in where 
> multiplexed streams would be useful for you?

Good to hear that you are still working on this :)
I'm working on QComm SoCs and I may need multiple virtual channel
support however the usecases are not clear yet. I'll be keeping an
eye on any activity from you then ;) or when I have more details
about my usecases I'll try to evaluate how they fit with this RFC.

Thank you.
Best regards,
Todor Tomov

> 
>>
>> Best regards,
>> Todor Tomov
>>
>> On 11.08.2017 12:56, Niklas Söderlund wrote:
>>> Hi,
>>>
>>> This series is a RFC for how I think one could add CSI-2 virtual channel 
>>> support to the V4L2 framework. The problem is that there is no way to in 
>>> the media framework describe and control links between subdevices which 
>>> carry more then one video stream, for example a CSI-2 bus which can have 
>>> 4 virtual channels carrying different video streams.
>>>
>>> This series adds a new pad flag which would indicate that a pad carries 
>>> multiplexed streams, adds a new s_stream() operation to the pad 
>>> operations structure which takes a new argument 'stream'. This new 
>>> s_stream() operation then is both pad and stream aware. It also extends 
>>> struct v4l2_mbus_frame_desc_entry with a new sub-struct to describe how 
>>> a CSI-2 link multiplexes virtual channels. I also include one 
>>> implementation based on Renesas R-Car which makes use of these patches 
>>> as I think they help with understanding but they have no impact on the 
>>> RFC feature itself.
>>>
>>> The idea is that on both sides of the multiplexed media link there are 
>>> one multiplexer subdevice and one demultiplexer subdevice. These two 
>>> subdevices can't do any format conversions, there sole purpose is to 
>>> (de)multiplex the CSI-2 link. If there is hardware which can do both 
>>> CSI-2 multiplexing and format conversions they can be modeled as two 
>>> subdevices from the same device driver and using the still pending 
>>> incremental async mechanism to connect the external pads. The reason 
>>> there is no format conversion is important as the multiplexed pads can't 
>>> have a format in the current V4L2 model, get/set_fmt are not aware of 
>>> streams.
>>>
>>> +--+  +--+
>>>  +---+  subdev 1   |  |  subdev 2   +---+
>>>   +--+ Pad 1 | |  | | Pad 3 +---+
>>>  +--++   +-+---+  +---+-+   ++--+
>>> || Muxed pad A +--+ Muxed pad B ||
>>>  +--++   +-+---+  +---+-+   ++--+
>>>   +--+ Pad 2 | |  | | Pad 4 +---+
>>>  +---+ |  | +---+
>>> +--+  +--+
>>>
>>> In the simple example above Pad 1 is routed to Pad 3 and Pad 2 to Pad 4, 
>>> and the video data for both of them travels the link between pad A and 
>>> B. One shortcoming of this RFC is that there currently are no way to 
>>> express to user-space which pad is routed to which stream of the 
>>> multiplexed link. But inside the kernel this is known and format 
>>> validation is done by comparing the format of Pad 1 to Pad 3 and Pad 2 
>>> to Pad 4 by the V4L2 framework. But it would be nice for the user to 
>>> also be able to get this information while setting up the MC graph in 
>>> user-space.
>>>
>>> Obviously there are thi

Re: [PATCH 00/20] Add multiplexed media pads to support CSI-2 virtual channels

2018-03-15 Thread Todor Tomov
Hello,

I'm trying to understand what is the current state of the multiple virtual
channel support in V4L2 and Media framework. This is the last activity
on this topic which I was able to find. Is anything new happened since
this RFC, is someone working on this or planing to work on?

Best regards,
Todor Tomov

On 11.08.2017 12:56, Niklas Söderlund wrote:
> Hi,
> 
> This series is a RFC for how I think one could add CSI-2 virtual channel 
> support to the V4L2 framework. The problem is that there is no way to in 
> the media framework describe and control links between subdevices which 
> carry more then one video stream, for example a CSI-2 bus which can have 
> 4 virtual channels carrying different video streams.
> 
> This series adds a new pad flag which would indicate that a pad carries 
> multiplexed streams, adds a new s_stream() operation to the pad 
> operations structure which takes a new argument 'stream'. This new 
> s_stream() operation then is both pad and stream aware. It also extends 
> struct v4l2_mbus_frame_desc_entry with a new sub-struct to describe how 
> a CSI-2 link multiplexes virtual channels. I also include one 
> implementation based on Renesas R-Car which makes use of these patches 
> as I think they help with understanding but they have no impact on the 
> RFC feature itself.
> 
> The idea is that on both sides of the multiplexed media link there are 
> one multiplexer subdevice and one demultiplexer subdevice. These two 
> subdevices can't do any format conversions, there sole purpose is to 
> (de)multiplex the CSI-2 link. If there is hardware which can do both 
> CSI-2 multiplexing and format conversions they can be modeled as two 
> subdevices from the same device driver and using the still pending 
> incremental async mechanism to connect the external pads. The reason 
> there is no format conversion is important as the multiplexed pads can't 
> have a format in the current V4L2 model, get/set_fmt are not aware of 
> streams.
> 
> +--+  +--+
>  +---+  subdev 1   |  |  subdev 2   +---+
>   +--+ Pad 1 | |  | | Pad 3 +---+
>  +--++   +-+---+  +---+-+   ++--+
> || Muxed pad A +--+ Muxed pad B ||
>  +--++   +-+---+  +---+-+   ++--+
>   +--+ Pad 2 | |  | | Pad 4 +---+
>  +---+ |  | +---+
> +--+  +--+
> 
> In the simple example above Pad 1 is routed to Pad 3 and Pad 2 to Pad 4, 
> and the video data for both of them travels the link between pad A and 
> B. One shortcoming of this RFC is that there currently are no way to 
> express to user-space which pad is routed to which stream of the 
> multiplexed link. But inside the kernel this is known and format 
> validation is done by comparing the format of Pad 1 to Pad 3 and Pad 2 
> to Pad 4 by the V4L2 framework. But it would be nice for the user to 
> also be able to get this information while setting up the MC graph in 
> user-space.
> 
> Obviously there are things that are not perfect in this RFC, one is the 
> above mentioned lack of user-space visibility of that Pad 1 is in fact 
> routed to Pad 3. Others are lack of Documentation/ work and I'm sure 
> there are error path shortcuts which are not fully thought out. One big 
> question is also if the s_stream() operation added to ops structure 
> should be a compliment to the existing ones in video and audio ops or 
> aim to replace the one in video ops. I'm also unsure of the CSI2 flag of 
> struct v4l2_mbus_frame_desc_entry don't really belong in struct 
> v4l2_mbus_frame_desc. And I'm sure there are lots of other stuff that's 
> why this is a RFC...
> 
> A big thanks to Laurent and Sakari for being really nice and taking time 
> helping me grasp all the possibilities and issues with this problem, all 
> cred to them and all blame to me for misunderstanding there guidance :-)
> 
> This series based on the latest R-Car CSI-2 and VIN patches which can be 
> found at [1], but that is a dependency only for the driver specific
> implementation which acts as an example of implementation. For the V4L2 
> framework patches the media-tree is the base.
> 
> 1. https://git.ragnatech.se/linux#rcar-vin-elinux-v12
> 
> Niklas Söderlund (20):
>   media.h: add MEDIA_PAD_FL_MUXED flag
>   v4l2-subdev.h: add pad and stream aware s_stream
>   v4l2-subdev.h: add CSI-2 bus description to struct
> v4l2_mbus_frame_desc_entry
>   v4l2-core: check that both pads in a link are muxed if one are
>   v4l2-core: verify all streams fo

Re: [PATCH] [media] ov5645: Move an error code assignment in ov5645_probe()

2018-03-15 Thread Todor Tomov
Hi,

On 15.03.2018 00:17, Sakari Ailus wrote:
> On Wed, Mar 14, 2018 at 10:15:43PM +0100, SF Markus Elfring wrote:
>> From: Markus Elfring <elfr...@users.sourceforge.net>
>> Date: Wed, 14 Mar 2018 22:02:52 +0100
>>
>> Move an assignment for a specific error code so that it is stored only once
>> in this function implementation.
>>
>> This issue was detected by using the Coccinelle software.
> 
> How?
> 
>>
>> Signed-off-by: Markus Elfring <elfr...@users.sourceforge.net>
>> ---
>>  drivers/media/i2c/ov5645.c | 6 +-
>>  1 file changed, 1 insertion(+), 5 deletions(-)
>>
>> diff --git a/drivers/media/i2c/ov5645.c b/drivers/media/i2c/ov5645.c
>> index d28845f7356f..374576380fd4 100644
>> --- a/drivers/media/i2c/ov5645.c
>> +++ b/drivers/media/i2c/ov5645.c
>> @@ -1284,13 +1284,11 @@ static int ov5645_probe(struct i2c_client *client,
>>  ret = ov5645_read_reg(ov5645, OV5645_CHIP_ID_HIGH, _id_high);
>>  if (ret < 0 || chip_id_high != OV5645_CHIP_ID_HIGH_BYTE) {
>>  dev_err(dev, "could not read ID high\n");
>> -ret = -ENODEV;
>>  goto power_down;
>>  }
>>  ret = ov5645_read_reg(ov5645, OV5645_CHIP_ID_LOW, _id_low);
>>  if (ret < 0 || chip_id_low != OV5645_CHIP_ID_LOW_BYTE) {
>>  dev_err(dev, "could not read ID low\n");
>> -ret = -ENODEV;
>>  goto power_down;
>>  }
>>  
>> @@ -1300,7 +1298,6 @@ static int ov5645_probe(struct i2c_client *client,
>>>aec_pk_manual);
>>  if (ret < 0) {
>>  dev_err(dev, "could not read AEC/AGC mode\n");
>> -ret = -ENODEV;
>>  goto power_down;
>>  }
>>  
>> @@ -1308,7 +1305,6 @@ static int ov5645_probe(struct i2c_client *client,
>>>timing_tc_reg20);
>>  if (ret < 0) {
>>  dev_err(dev, "could not read vflip value\n");
>> -ret = -ENODEV;
>>  goto power_down;
>>  }
>>  
>> @@ -1316,7 +1312,6 @@ static int ov5645_probe(struct i2c_client *client,
>>>timing_tc_reg21);
>>  if (ret < 0) {
>>  dev_err(dev, "could not read hflip value\n");
>> -ret = -ENODEV;
>>  goto power_down;
>>  }
>>  
>> @@ -1334,6 +1329,7 @@ static int ov5645_probe(struct i2c_client *client,
>>  
>>  power_down:
>>  ov5645_s_power(>sd, false);
>> +ret = -ENODEV;
> 
> I don't think this is where people would expect you to set the error code
> in general. It should rather take place before goto, not after it. That'd
> mean another variable, and I'm not convinced the result would improve the
> driver.

I agree with Sakari.

> 
>>  free_entity:
>>  media_entity_cleanup(>sd.entity);
>>  free_ctrl:
> 

-- 
Best regards,
Todor Tomov


Re: [PATCH v3] [media] Use common error handling code in 19 functions

2018-03-12 Thread Todor Tomov
Hi Markus,

Thank you for the patch.

On  9.03.2018 22:10, SF Markus Elfring wrote:
> From: Markus Elfring <elfr...@users.sourceforge.net>
> Date: Fri, 9 Mar 2018 21:00:12 +0100
> 
> Adjust jump targets so that a bit of exception handling can be better
> reused at the end of these functions.
> 
> This issue was partly detected by using the Coccinelle software.
> 
> Signed-off-by: Markus Elfring <elfr...@users.sourceforge.net>
> ---
> 
> v3:
> Laurent Pinchart and Todor Tomov requested a few adjustments.
> Updates were rebased on source files from Linux next-20180308.
> 
> v2:
> Hans Verkuil insisted on patch squashing. Thus several changes
> were recombined based on source files from Linux next-20180216.
> 
> The implementation of the function "tda8261_set_params" was improved
> after a notification by Christoph Böhmwalder on 2017-09-26.
> 
>  drivers/media/dvb-core/dmxdev.c| 16 
>  drivers/media/dvb-frontends/tda1004x.c | 20 ++
>  drivers/media/dvb-frontends/tda8261.c  | 19 ++
>  drivers/media/pci/bt8xx/dst.c  | 19 ++
>  drivers/media/pci/bt8xx/dst_ca.c   | 30 +++
>  drivers/media/pci/cx88/cx88-input.c| 17 +
>  drivers/media/platform/omap3isp/ispvideo.c | 28 ++
>  .../media/platform/qcom/camss-8x16/camss-csid.c| 19 +-
>  drivers/media/tuners/tuner-xc2028.c| 30 +++
>  drivers/media/usb/cpia2/cpia2_usb.c| 13 ---
>  drivers/media/usb/gspca/gspca.c| 17 +
>  drivers/media/usb/gspca/sn9c20x.c  | 17 +
>  drivers/media/usb/pvrusb2/pvrusb2-ioread.c | 10 +++--
>  drivers/media/usb/tm6000/tm6000-cards.c|  7 ++--
>  drivers/media/usb/tm6000/tm6000-dvb.c  | 11 --
>  drivers/media/usb/tm6000/tm6000-video.c| 13 ---
>  drivers/media/usb/ttusb-budget/dvb-ttusb-budget.c  | 13 +++
>  drivers/media/usb/ttusb-dec/ttusb_dec.c| 43 
> --
>  18 files changed, 171 insertions(+), 171 deletions(-)
> 



> diff --git a/drivers/media/platform/qcom/camss-8x16/camss-csid.c 
> b/drivers/media/platform/qcom/camss-8x16/camss-csid.c
> index 64df82817de3..5c790d8c1f80 100644
> --- a/drivers/media/platform/qcom/camss-8x16/camss-csid.c
> +++ b/drivers/media/platform/qcom/camss-8x16/camss-csid.c
> @@ -328,16 +328,12 @@ static int csid_set_power(struct v4l2_subdev *sd, int 
> on)
>   return ret;
>  
>   ret = csid_set_clock_rates(csid);
> - if (ret < 0) {
> - regulator_disable(csid->vdda);
> - return ret;
> - }
> + if (ret < 0)
> + goto disable_regulator;
>  
>   ret = camss_enable_clocks(csid->nclocks, csid->clock, dev);
> - if (ret < 0) {
> - regulator_disable(csid->vdda);
> - return ret;
> - }
> + if (ret < 0)
> + goto disable_regulator;
>  
>   enable_irq(csid->irq);
>  
> @@ -345,8 +341,7 @@ static int csid_set_power(struct v4l2_subdev *sd, int on)
>   if (ret < 0) {
>   disable_irq(csid->irq);
>   camss_disable_clocks(csid->nclocks, csid->clock);
> - regulator_disable(csid->vdda);
> - return ret;
> + goto disable_regulator;
>   }
>  
>   hw_version = readl_relaxed(csid->base + CAMSS_CSID_HW_VERSION);
> @@ -358,6 +353,10 @@ static int csid_set_power(struct v4l2_subdev *sd, int on)
>   }
>  
>   return ret;
> +
> +disable_regulator:
> + regulator_disable(csid->vdda);
> + return ret;
>  }
>  

For the QComm CAMSS part of the patch:
Acked-by: Todor Tomov <todor.to...@linaro.org>


-- 
Best regards,
Todor Tomov


Re: [PATCH v2] [media] Use common error handling code in 20 functions

2018-02-20 Thread Todor Tomov
Hi Markus,

Thank you for the patch.

On 19.02.2018 20:11, SF Markus Elfring wrote:
> From: Markus Elfring <elfr...@users.sourceforge.net>
> Date: Mon, 19 Feb 2018 18:50:40 +0100
> 
> Adjust jump targets so that a bit of exception handling can be better
> reused at the end of these functions.
> 
> This issue was partly detected by using the Coccinelle software.
> 
> Signed-off-by: Markus Elfring <elfr...@users.sourceforge.net>
> ---
> 
> v2:
> Hans Verkuil insisted on patch squashing. Thus several changes
> were recombined based on source files from Linux next-20180216.
> 
> The implementation of the function "tda8261_set_params" was improved
> after a notification by Christoph Böhmwalder on 2017-09-26.
> 
>  drivers/media/dvb-core/dmxdev.c| 16 
>  drivers/media/dvb-frontends/tda1004x.c | 20 ++
>  drivers/media/dvb-frontends/tda8261.c  | 19 ++
>  drivers/media/pci/bt8xx/dst.c  | 19 ++
>  drivers/media/pci/bt8xx/dst_ca.c   | 30 +++
>  drivers/media/pci/cx88/cx88-input.c| 17 +
>  drivers/media/platform/omap3isp/ispvideo.c | 29 +++
>  .../media/platform/qcom/camss-8x16/camss-csid.c| 20 +-
>  drivers/media/tuners/tuner-xc2028.c| 30 +++
>  drivers/media/usb/cpia2/cpia2_usb.c| 13 ---
>  drivers/media/usb/gspca/gspca.c| 17 +
>  drivers/media/usb/gspca/sn9c20x.c  | 17 +
>  drivers/media/usb/pvrusb2/pvrusb2-ioread.c | 10 +++--
>  drivers/media/usb/tm6000/tm6000-cards.c|  7 ++--
>  drivers/media/usb/tm6000/tm6000-dvb.c  | 11 --
>  drivers/media/usb/tm6000/tm6000-video.c| 13 ---
>  drivers/media/usb/ttusb-budget/dvb-ttusb-budget.c  | 13 +++
>  drivers/media/usb/ttusb-dec/ttusb_dec.c| 43 
> --
>  drivers/media/usb/uvc/uvc_v4l2.c   | 13 ---
>  19 files changed, 180 insertions(+), 177 deletions(-)
> 
> diff --git a/drivers/media/dvb-core/dmxdev.c b/drivers/media/dvb-core/dmxdev.c
> index 6d53af00190e..6a0411c91195 100644



> diff --git a/drivers/media/platform/qcom/camss-8x16/camss-csid.c 
> b/drivers/media/platform/qcom/camss-8x16/camss-csid.c
> index 64df82817de3..92d4dc6b4a66 100644
> --- a/drivers/media/platform/qcom/camss-8x16/camss-csid.c
> +++ b/drivers/media/platform/qcom/camss-8x16/camss-csid.c
> @@ -328,16 +328,12 @@ static int csid_set_power(struct v4l2_subdev *sd, int 
> on)
>   return ret;
>  
>   ret = csid_set_clock_rates(csid);
> - if (ret < 0) {
> - regulator_disable(csid->vdda);
> - return ret;
> - }
> + if (ret < 0)
> + goto disable_regulator;
>  
>   ret = camss_enable_clocks(csid->nclocks, csid->clock, dev);
> - if (ret < 0) {
> - regulator_disable(csid->vdda);
> - return ret;
> - }
> + if (ret < 0)
> + goto disable_regulator;
>  
>   enable_irq(csid->irq);
>  
> @@ -345,8 +341,7 @@ static int csid_set_power(struct v4l2_subdev *sd, int on)
>   if (ret < 0) {
>   disable_irq(csid->irq);
>   camss_disable_clocks(csid->nclocks, csid->clock);
> - regulator_disable(csid->vdda);
> - return ret;
> + goto disable_regulator;
>   }
>  
>   hw_version = readl_relaxed(csid->base + CAMSS_CSID_HW_VERSION);
> @@ -357,6 +352,11 @@ static int csid_set_power(struct v4l2_subdev *sd, int on)
>   ret = regulator_disable(csid->vdda);
>   }
>  
> + goto exit;

I think it will be cleaner if you remove the exit label and return here instead.

> +
> +disable_regulator:
> + regulator_disable(csid->vdda);
> +exit:
>   return ret;
>  }

-- 
Best regards,
Todor Tomov


Re: [PATCH 2/2] media: Add a driver for the ov7251 camera sensor

2018-02-19 Thread Todor Tomov
Hi Jacopo,

On 16.02.2018 12:05, jacopo mondi wrote:
> Hi Todor,
> thanks for the patch.
> 
> Is the datsheet for this sensor public? I failed to find any reference
> to it online, am I wrong?

Thank you for the review!
The datasheet is not public.

> 
> On Thu, Feb 08, 2018 at 10:53:38AM +0200, Todor Tomov wrote:
>> The ov7251 sensor is a 1/7.5-Inch B VGA (640x480) CMOS Digital Image
>> Sensor from Omnivision.
>>
>> The driver supports the following modes:
>> - 640x480 30fps
>> - 640x480 60fps
>> - 640x480 90fps
>>
>> Output format is MIPI RAW 10.
>>
>> The driver supports configuration via user controls for:
>> - exposure and gain;
>> - horizontal and vertical flip;
>> - test pattern.
>>
>> Signed-off-by: Todor Tomov <todor.to...@linaro.org>
>> ---
>>  drivers/media/i2c/Kconfig  |   13 +
>>  drivers/media/i2c/Makefile |1 +
>>  drivers/media/i2c/ov7251.c | 1523 
>> 
>>  3 files changed, 1537 insertions(+)
>>  create mode 100644 drivers/media/i2c/ov7251.c
>>
>> diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
>> index 9f18cd2..bfa9aab 100644
>> --- a/drivers/media/i2c/Kconfig
>> +++ b/drivers/media/i2c/Kconfig
>> @@ -645,6 +645,19 @@ config VIDEO_OV5670
>>To compile this driver as a module, choose M here: the
>>module will be called ov5670.
>>
>> +config VIDEO_OV7251
>> +tristate "OmniVision OV7251 sensor support"
>> +depends on OF
>> +depends on I2C && VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API
>> +depends on MEDIA_CAMERA_SUPPORT
>> +select V4L2_FWNODE
>> +---help---
>> +  This is a Video4Linux2 sensor-level driver for the OmniVision
>> +  OV7251 camera.
>> +
>> +  To compile this driver as a module, choose M here: the
>> +  module will be called ov7251.
>> +
>>  config VIDEO_OV7640
>>  tristate "OmniVision OV7640 sensor support"
>>  depends on I2C && VIDEO_V4L2
>> diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile
>> index c0f94cd..be6b3d3 100644
>> --- a/drivers/media/i2c/Makefile
>> +++ b/drivers/media/i2c/Makefile
>> @@ -66,6 +66,7 @@ obj-$(CONFIG_VIDEO_OV5645) += ov5645.o
>>  obj-$(CONFIG_VIDEO_OV5647) += ov5647.o
>>  obj-$(CONFIG_VIDEO_OV5670) += ov5670.o
>>  obj-$(CONFIG_VIDEO_OV6650) += ov6650.o
>> +obj-$(CONFIG_VIDEO_OV7251) += ov7251.o
>>  obj-$(CONFIG_VIDEO_OV7640) += ov7640.o
>>  obj-$(CONFIG_VIDEO_OV7670) += ov7670.o
>>  obj-$(CONFIG_VIDEO_OV7740) += ov7740.o
>> diff --git a/drivers/media/i2c/ov7251.c b/drivers/media/i2c/ov7251.c
>> new file mode 100644
>> index 000..f217177
>> --- /dev/null
>> +++ b/drivers/media/i2c/ov7251.c
>> @@ -0,0 +1,1523 @@
>> +/*
>> + * Driver for the OV7251 camera sensor.
>> + *
>> + * Copyright (c) 2017-2018, The Linux Foundation. All rights reserved.
>> + * Copyright (c) 2017-2018, Linaro Ltd.
>> + *
>> + * This program is free software; you can redistribute it and/or modify
>> + * it under the terms of the GNU General Public License version 2 and
>> + * only 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.
>> + */
> 
> Please use SPDX identifiers instead of the license text
> 
> // SPDX-License-Identifier: GPL-2.0
> 

Ok.

>> +
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +
>> +#define OV7251_VOLTAGE_ANALOG   280
>> +#define OV7251_VOLTAGE_DIGITAL_CORE 150
>> +#define OV7251_VOLTAGE_DIGITAL_IO   180
>> +
>> +#define OV7251_SC_MODE_SELECT   0x0100
>> +#define OV7251_SC_MODE_SELECT_SW_STANDBY0x0
>> +#define OV7251_SC_MODE_SELECT_STREAMING 0x1
>> +
>> +#define OV7251_CHIP_ID_HIGH 0x300a
>> +#define OV7251_CHIP_ID_HIGH_BYTE0x77
>> +#define OV7251_CHIP_ID_LOW  0x300b
>> +#define OV7251_CHIP_ID_LOW_BYTE 

[PATCH 2/2] media: ov5645: Improve mode finding function

2018-02-08 Thread Todor Tomov
Find the sensor mode by comparing the size of the requested image size
and the sensor mode's image size. The distance between image sizes is the
size in pixels of the non-overlapping regions between the requested size
and the frame-specified size. This logic is borrowed from et8ek8 sensor
driver.

Signed-off-by: Todor Tomov <todor.to...@linaro.org>
---
 drivers/media/i2c/ov5645.c | 24 +++-
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/drivers/media/i2c/ov5645.c b/drivers/media/i2c/ov5645.c
index 9755562..6d06c50 100644
--- a/drivers/media/i2c/ov5645.c
+++ b/drivers/media/i2c/ov5645.c
@@ -964,18 +964,24 @@ __ov5645_get_pad_crop(struct ov5645 *ov5645, struct 
v4l2_subdev_pad_config *cfg,
 static const struct ov5645_mode_info *
 ov5645_find_nearest_mode(unsigned int width, unsigned int height)
 {
-   int i;
+   unsigned int max_dist_match = (unsigned int) -1;
+   int i, n = 0;
 
-   for (i = ARRAY_SIZE(ov5645_mode_info_data) - 1; i >= 0; i--) {
-   if (ov5645_mode_info_data[i].width <= width &&
-   ov5645_mode_info_data[i].height <= height)
-   break;
+   for (i = 0; i < ARRAY_SIZE(ov5645_mode_info_data); i++) {
+   unsigned int dist = min(width, ov5645_mode_info_data[i].width)
+   * min(height, ov5645_mode_info_data[i].height);
+
+   dist = ov5645_mode_info_data[i].width *
+   ov5645_mode_info_data[i].height
++ width * height - 2 * dist;
+
+   if (dist < max_dist_match) {
+   n = i;
+   max_dist_match = dist;
+   }
}
 
-   if (i < 0)
-   i = 0;
-
-   return _mode_info_data[i];
+   return _mode_info_data[n];
 }
 
 static int ov5645_set_format(struct v4l2_subdev *sd,
-- 
2.7.4



[PATCH 1/2] media: ov5645: Fix write_reg return code

2018-02-08 Thread Todor Tomov
I2C transfer functions return number of successful operations (on success).

Do not return the received positive return code but instead return 0 on
success. The users of write_reg function already use this logic.

Signed-off-by: Todor Tomov <todor.to...@linaro.org>
---
 drivers/media/i2c/ov5645.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/media/i2c/ov5645.c b/drivers/media/i2c/ov5645.c
index d28845f..9755562 100644
--- a/drivers/media/i2c/ov5645.c
+++ b/drivers/media/i2c/ov5645.c
@@ -600,11 +600,13 @@ static int ov5645_write_reg(struct ov5645 *ov5645, u16 
reg, u8 val)
regbuf[2] = val;
 
ret = i2c_master_send(ov5645->i2c_client, regbuf, 3);
-   if (ret < 0)
+   if (ret < 0) {
dev_err(ov5645->dev, "%s: write reg error %d: reg=%x, val=%x\n",
__func__, ret, reg, val);
+   return ret;
+   }
 
-   return ret;
+   return 0;
 }
 
 static int ov5645_read_reg(struct ov5645 *ov5645, u16 reg, u8 *val)
-- 
2.7.4



[PATCH 2/2] media: Add a driver for the ov7251 camera sensor

2018-02-08 Thread Todor Tomov
The ov7251 sensor is a 1/7.5-Inch B VGA (640x480) CMOS Digital Image
Sensor from Omnivision.

The driver supports the following modes:
- 640x480 30fps
- 640x480 60fps
- 640x480 90fps

Output format is MIPI RAW 10.

The driver supports configuration via user controls for:
- exposure and gain;
- horizontal and vertical flip;
- test pattern.

Signed-off-by: Todor Tomov <todor.to...@linaro.org>
---
 drivers/media/i2c/Kconfig  |   13 +
 drivers/media/i2c/Makefile |1 +
 drivers/media/i2c/ov7251.c | 1523 
 3 files changed, 1537 insertions(+)
 create mode 100644 drivers/media/i2c/ov7251.c

diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index 9f18cd2..bfa9aab 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -645,6 +645,19 @@ config VIDEO_OV5670
  To compile this driver as a module, choose M here: the
  module will be called ov5670.
 
+config VIDEO_OV7251
+   tristate "OmniVision OV7251 sensor support"
+   depends on OF
+   depends on I2C && VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API
+   depends on MEDIA_CAMERA_SUPPORT
+   select V4L2_FWNODE
+   ---help---
+ This is a Video4Linux2 sensor-level driver for the OmniVision
+ OV7251 camera.
+
+ To compile this driver as a module, choose M here: the
+ module will be called ov7251.
+
 config VIDEO_OV7640
tristate "OmniVision OV7640 sensor support"
depends on I2C && VIDEO_V4L2
diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile
index c0f94cd..be6b3d3 100644
--- a/drivers/media/i2c/Makefile
+++ b/drivers/media/i2c/Makefile
@@ -66,6 +66,7 @@ obj-$(CONFIG_VIDEO_OV5645) += ov5645.o
 obj-$(CONFIG_VIDEO_OV5647) += ov5647.o
 obj-$(CONFIG_VIDEO_OV5670) += ov5670.o
 obj-$(CONFIG_VIDEO_OV6650) += ov6650.o
+obj-$(CONFIG_VIDEO_OV7251) += ov7251.o
 obj-$(CONFIG_VIDEO_OV7640) += ov7640.o
 obj-$(CONFIG_VIDEO_OV7670) += ov7670.o
 obj-$(CONFIG_VIDEO_OV7740) += ov7740.o
diff --git a/drivers/media/i2c/ov7251.c b/drivers/media/i2c/ov7251.c
new file mode 100644
index 000..f217177
--- /dev/null
+++ b/drivers/media/i2c/ov7251.c
@@ -0,0 +1,1523 @@
+/*
+ * Driver for the OV7251 camera sensor.
+ *
+ * Copyright (c) 2017-2018, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2017-2018, Linaro Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only 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 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define OV7251_VOLTAGE_ANALOG   280
+#define OV7251_VOLTAGE_DIGITAL_CORE 150
+#define OV7251_VOLTAGE_DIGITAL_IO   180
+
+#define OV7251_SC_MODE_SELECT  0x0100
+#define OV7251_SC_MODE_SELECT_SW_STANDBY   0x0
+#define OV7251_SC_MODE_SELECT_STREAMING0x1
+
+#define OV7251_CHIP_ID_HIGH0x300a
+#defineOV7251_CHIP_ID_HIGH_BYTE0x77
+#define OV7251_CHIP_ID_LOW 0x300b
+#defineOV7251_CHIP_ID_LOW_BYTE 0x50
+#define OV7251_SC_GP_IO_IN10x3029
+#define OV7251_AEC_EXPO_0  0x3500
+#define OV7251_AEC_EXPO_1  0x3501
+#define OV7251_AEC_EXPO_2  0x3502
+#define OV7251_AEC_AGC_ADJ_0   0x350a
+#define OV7251_AEC_AGC_ADJ_1   0x350b
+#define OV7251_TIMING_FORMAT1  0x3820
+#defineOV7251_SENSOR_VFLIP BIT(2)
+#define OV7251_TIMING_FORMAT2  0x3821
+#defineOV7251_SENSOR_MIRRORBIT(2)
+#define OV7251_PRE_ISP_00  0x5e00
+#defineOV7251_TEST_PATTERN_BAR_ENABLE  BIT(7)
+
+struct reg_value {
+   u16 reg;
+   u8 val;
+};
+
+struct ov7251_mode_info {
+   u32 width;
+   u32 height;
+   const struct reg_value *data;
+   u32 data_size;
+   u32 pixel_clock;
+   u32 link_freq;
+   u16 exposure_max;
+   u16 exposure_def;
+   struct v4l2_fract timeperframe;
+};
+
+struct ov7251 {
+   struct i2c_client *i2c_client;
+   struct device *dev;
+   struct v4l2_subdev sd;
+   struct media_pad pad;
+   struct v4l2_fwnode_endpoint ep;
+   struct v4l2_mbus_framefmt fmt;
+   struct v4l2_rect crop;
+   struct clk *xclk;
+
+   struct regulator *io_regulator;
+   struct regulator *core_regulator;
+   struct regulator *analog_regulator;
+
+   const struct ov7251_mode_info *curr

[PATCH 1/2] dt-bindings: media: Binding document for OV7251 camera sensor

2018-02-08 Thread Todor Tomov
Add the document for ov7251 device tree binding.

CC: Rob Herring <robh...@kernel.org>
CC: Mark Rutland <mark.rutl...@arm.com>
CC: devicet...@vger.kernel.org
Signed-off-by: Todor Tomov <todor.to...@linaro.org>
---
 .../devicetree/bindings/media/i2c/ov7251.txt   | 51 ++
 1 file changed, 51 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/i2c/ov7251.txt

diff --git a/Documentation/devicetree/bindings/media/i2c/ov7251.txt 
b/Documentation/devicetree/bindings/media/i2c/ov7251.txt
new file mode 100644
index 000..c807646
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/i2c/ov7251.txt
@@ -0,0 +1,51 @@
+* Omnivision 1/7.5-Inch B VGA CMOS Digital Image Sensor
+
+The Omnivision OV7251 is a 1/7.5-Inch CMOS active pixel digital image sensor 
with
+an active array size of 640H x 480V. It is programmable through a serial I2C
+interface.
+
+Required Properties:
+- compatible: Value should be "ovti,ov7251".
+- clocks: Reference to the xclk clock.
+- clock-names: Should be "xclk".
+- clock-frequency: Frequency of the xclk clock.
+- enable-gpios: Chip enable GPIO. Polarity is GPIO_ACTIVE_HIGH. This 
corresponds
+  to the hardware pin XSHUTDOWN which is physically active low.
+- vdddo-supply: Chip digital IO regulator.
+- vdda-supply: Chip analog regulator.
+- vddd-supply: Chip digital core regulator.
+
+The device node must contain one 'port' child node for its digital output
+video port, in accordance with the video interface bindings defined in
+Documentation/devicetree/bindings/media/video-interfaces.txt.
+
+Example:
+
+{
+   ...
+
+   ov7251: ov7251@60 {
+   compatible = "ovti,ov7251";
+   reg = <0x60>;
+
+   enable-gpios = < 6 GPIO_ACTIVE_HIGH>;
+   pinctrl-names = "default";
+   pinctrl-0 = <_bw_default>;
+
+   clocks = < 200>;
+   clock-names = "xclk";
+   clock-frequency = <2400>;
+
+   vdddo-supply = <_dovdd_1v8>;
+   vdda-supply = <_avdd_2v8>;
+   vddd-supply = <_dvdd_1v2>;
+
+   port {
+   ov7251_ep: endpoint {
+   clock-lanes = <1>;
+   data-lanes = <0>;
+   remote-endpoint = <_ep>;
+   };
+   };
+   };
+   };
-- 
2.7.4



Re: camss: camera controls missing on vfe interfaces

2017-11-20 Thread Todor Tomov
Hi Daniel,

Sorry for my late reply. This is actually an important question that you ask.

On 15.11.2017 21:31, Daniel Mack wrote:
> Todor et all,
> 
> Any hint on how to tackle this?
> 
> I can contribute patches, but I'd like to understand what the idea is.
> 
> 
> Thanks,
> Daniel
> 
> 
> On Thursday, October 26, 2017 06:11 PM, Daniel Mack wrote:
>> Hi Todor,
>>
>> When using the camss driver trough one of its /dev/videoX device nodes,
>> applications are currently unable to see the video controls the camera
>> sensor exposes.
>>
>> Same goes for other ioctls such as VIDIOC_ENUM_FMT, so the only valid
>> resolution setting for applications to use is the one that was
>> previously set through the media controller layer. Applications usually
>> query the available formats and then pick one using the standard V4L2
>> APIs, and many can't easily be forced to use a specific one.
>>
>> If I'm getting this right, could you explain what's the rationale here?
>> Is that simply a missing feature or was that approach chosen on purpose?
>>

It is not a missing feature, it is more of a missing userspace implementation.
When working with a media oriented device driver, the userspace has to
config the media pipeline too and if controls are exposed by the subdev nodes,
the userspace has to configure them on the subdev nodes.

As there weren't a lot of media oriented drivers there is no generic
implementation/support for this in the userspace (at least I'm not aware of
any). There have been discussions about adding such functionality in libv4l
so that applications which do not support media configuration can still
use these drivers. I'm not sure if decision for this was taken or not or
is it just that there was noone to actually do the work. Probably Laurent,
Mauro or Hans know more about what were the plans for this.

-- 
Best regards,
Todor Tomov


Re: [PATCH] [RFC] media: camss-vfe: always initialize reg at vfe_set_xbar_cfg()

2017-11-01 Thread Todor Tomov
On  1.11.2017 15:25, Mauro Carvalho Chehab wrote:
> Em Wed, 1 Nov 2017 15:09:36 +0200
> Todor Tomov <todor.to...@linaro.org> escreveu:
> 
>> On  1.11.2017 15:03, Mauro Carvalho Chehab wrote:
>>> Hi Todor,
>>>
>>> Em Wed, 1 Nov 2017 14:38:02 +0200
>>> Todor Tomov <todor.to...@linaro.org> escreveu:
>>>   
>>>> Hi Mauro,
>>>>
>>>> Thank you for pointing to this.
>>>>
>>>> On  1.11.2017 14:16, Mauro Carvalho Chehab wrote:  
>>>>> if output->wm_num is bigger than 1, the value for reg is
>>>> If output->wn_num equals 2, we handle all cases (i == 0, i == 1) and set 
>>>> reg properly.
>>>> If output->wn_num is bigger than 2, then reg will not be initialized. 
>>>> However this is something that "cannot happen" and because of this the 
>>>> case is not handled.
>>>>
>>>> So I think that there is nothing wrong really but we have to do something 
>>>> to remove the warning. I agree with your patch, it is technically not a 
>>>> right value for reg but any cases in which wm_num is bigger than 2 are not 
>>>> supported anyway and should not happen.  
>>>
>>> Thanks for your promptly answer. Well, if i is always at the [0..1] range,
>>> then I guess the enclosed patch is actually better.  
>>
>> I don't think that there is a lot of difference practically. If this one 
>> fixes the warning too, then it is fine for me. Thank you for working on this.
> 
> Yes, it fixes the warning. I guess the main advantage of version 2 is
> that, if it would ever be possible to have more than 2 outputs, it
> should be clearer that the logic at break need changes.
> 
> So, if ok for you, I'll stick with version 2. It would be great if
> you could give your ack on that.

Sure, and you can add:
Acked-by: Todor Tomov <todor.to...@linaro.org>

Thank you.
Todor


Re: [PATCH] [RFC] media: camss-vfe: always initialize reg at vfe_set_xbar_cfg()

2017-11-01 Thread Todor Tomov
On  1.11.2017 15:03, Mauro Carvalho Chehab wrote:
> Hi Todor,
> 
> Em Wed, 1 Nov 2017 14:38:02 +0200
> Todor Tomov <todor.to...@linaro.org> escreveu:
> 
>> Hi Mauro,
>>
>> Thank you for pointing to this.
>>
>> On  1.11.2017 14:16, Mauro Carvalho Chehab wrote:
>>> if output->wm_num is bigger than 1, the value for reg is  
>> If output->wn_num equals 2, we handle all cases (i == 0, i == 1) and set reg 
>> properly.
>> If output->wn_num is bigger than 2, then reg will not be initialized. 
>> However this is something that "cannot happen" and because of this the case 
>> is not handled.
>>
>> So I think that there is nothing wrong really but we have to do something to 
>> remove the warning. I agree with your patch, it is technically not a right 
>> value for reg but any cases in which wm_num is bigger than 2 are not 
>> supported anyway and should not happen.
> 
> Thanks for your promptly answer. Well, if i is always at the [0..1] range,
> then I guess the enclosed patch is actually better.

I don't think that there is a lot of difference practically. If this one fixes 
the warning too, then it is fine for me. Thank you for working on this.

Best regards,
Todor

> 
> 
> Thanks,
> Mauro
> 
> 
> [PATCH] media: camss-vfe: always initialize reg at vfe_set_xbar_cfg()
> 
> if output->wm_num is bigger than 2, the value for reg is
> not initialized, as warned by smatch:
>   drivers/media/platform/qcom/camss-8x16/camss-vfe.c:633 
> vfe_set_xbar_cfg() error: uninitialized symbol 'reg'.
>   drivers/media/platform/qcom/camss-8x16/camss-vfe.c:637 
> vfe_set_xbar_cfg() error: uninitialized symbol 'reg'.
> 
> That shouldn't happen in practice, so add a logic that will
> break the loop if i > 1, fixing the warnings.
> 
> Signed-off-by: Mauro Carvalho Chehab <mche...@s-opensource.com>
> 
> diff --git a/drivers/media/platform/qcom/camss-8x16/camss-vfe.c 
> b/drivers/media/platform/qcom/camss-8x16/camss-vfe.c
> index b22d2dfcd3c2..55232a912950 100644
> --- a/drivers/media/platform/qcom/camss-8x16/camss-vfe.c
> +++ b/drivers/media/platform/qcom/camss-8x16/camss-vfe.c
> @@ -622,6 +622,9 @@ static void vfe_set_xbar_cfg(struct vfe_device *vfe, 
> struct vfe_output *output,
>   reg = VFE_0_BUS_XBAR_CFG_x_M_PAIR_STREAM_EN;
>   if (p == V4L2_PIX_FMT_NV12 || p == V4L2_PIX_FMT_NV16)
>   reg |= 
> VFE_0_BUS_XBAR_CFG_x_M_PAIR_STREAM_SWAP_INTER_INTRA;
> + } else {
> + /* On current devices output->wm_num is always <= 2 */
> + break;
>   }
>  
>   if (output->wm_idx[i] % 2 == 1)
> 


Re: [PATCH] [RFC] media: camss-vfe: always initialize reg at vfe_set_xbar_cfg()

2017-11-01 Thread Todor Tomov
Hi Mauro,

Thank you for pointing to this.

On  1.11.2017 14:16, Mauro Carvalho Chehab wrote:
> if output->wm_num is bigger than 1, the value for reg is
If output->wn_num equals 2, we handle all cases (i == 0, i == 1) and set reg 
properly.
If output->wn_num is bigger than 2, then reg will not be initialized. However 
this is something that "cannot happen" and because of this the case is not 
handled.

So I think that there is nothing wrong really but we have to do something to 
remove the warning. I agree with your patch, it is technically not a right 
value for reg but any cases in which wm_num is bigger than 2 are not supported 
anyway and should not happen.

> not initialized, as warned by smatch:
>   drivers/media/platform/qcom/camss-8x16/camss-vfe.c:633 
> vfe_set_xbar_cfg() error: uninitialized symbol 'reg'.
>   drivers/media/platform/qcom/camss-8x16/camss-vfe.c:637 
> vfe_set_xbar_cfg() error: uninitialized symbol 'reg'.
> 
> I didn't check the logic into its details, but there is at least
> one point where wm_num is made equal to two. So, something
> seem broken.
> 
> For now, I just reset it to zero, and added a FIXME. Hopefully,
> the driver authors will know if this is OK, or if something else
> is needed there.
> 
> Signed-off-by: Mauro Carvalho Chehab <mche...@s-opensource.com>
> ---
>  drivers/media/platform/qcom/camss-8x16/camss-vfe.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/media/platform/qcom/camss-8x16/camss-vfe.c 
> b/drivers/media/platform/qcom/camss-8x16/camss-vfe.c
> index b22d2dfcd3c2..388431f747fa 100644
> --- a/drivers/media/platform/qcom/camss-8x16/camss-vfe.c
> +++ b/drivers/media/platform/qcom/camss-8x16/camss-vfe.c
> @@ -622,6 +622,8 @@ static void vfe_set_xbar_cfg(struct vfe_device *vfe, 
> struct vfe_output *output,
>   reg = VFE_0_BUS_XBAR_CFG_x_M_PAIR_STREAM_EN;
>   if (p == V4L2_PIX_FMT_NV12 || p == V4L2_PIX_FMT_NV16)
>   reg |= 
> VFE_0_BUS_XBAR_CFG_x_M_PAIR_STREAM_SWAP_INTER_INTRA;
> + } else {
> + reg = 0;/* FIXME: is it the right value for i > 
> 1? */
>   }
>  
>   if (output->wm_idx[i] % 2 == 1)
> 

-- 
Best regards,
Todor Tomov


Re: [PATCH v4 04/21] doc: media/v4l-drivers: Add Qualcomm Camera Subsystem driver document

2017-10-25 Thread Todor Tomov
Hi Daniel,

On 16.10.2017 18:01, Daniel Mack wrote:
> Hi,
> 
> On 28.08.2017 09:10, Todor Tomov wrote:
>> On 25.08.2017 17:10, Daniel Mack wrote:
>>> Could you explain how ISPIF, CSID and CSIPHY are related?
>>>
>>> I have a userspace test setup that works fine for USB webcams, but when
>>> operating on any of the video devices exposed by this driver, the
>>> lowlevel functions such as .s_power of the ISPIF, CSID, CSIPHY and the
>>> sensor driver layers aren't called into.
>>
>> Have you activated the media controller links? The s_power is called
>> when the subdev is part of a pipeline in which the video device node
>> is opened. You can see example configurations for the Qualcomm CAMSS
>> driver on:
>> https://github.com/96boards/documentation/blob/master/ConsumerEdition/DragonBoard-410c/Guides/CameraModule.md
>> This will probably answer most of your questions.
> 
> It did in fact, yes. Thanks again for the pointer.
> 
> I am however struggling getting a 4-lane OV13855 camera to work with
> this camss driver, and I'd be happy to hear about similar setups that work.
> 
> In short, here's what my setup looks like:
> 
> 1. I wrote a driver for the OV13855 sensor, based on the one for OV13858
> but with updated register values. It announces
> MEDIA_BUS_FMT_SBGGR10_1X10 as bus format which is what the sensor should
> be sending, if I understand the specs correctly.
> 
> 
> 2. The DTS snippet for the endpoint connection look like this:
> 
> _i2c6 {
>   cam0: ov13855@16 {
>   /* ... */
>   port {
>   cam0_ep: endpoint {
>   clock-lanes = <1>;
>   data-lanes = <0 2 3 4>;
>   remote-endpoint = <_ep>;
>   };
>   };
>   };
> };
> 
>  {
>   ports {
>   port@0 {
>   reg = <0>;
>   csiphy0_ep: endpoint {
>   clock-lanes = <1>;
>   data-lanes = <0 2 3 4>;
>   remote-endpoint = <_ep>;
>   };
>   };
>   };
> };
> 
> There are also no lane swaps or any intermediate components in hardware.
> We've checked the electrical bits many times, and that end seems alright.
> 
> 
> 3. The pads and links are set up like this:
> 
> # media-ctl -d /dev/media0 -l
> '"msm_csiphy0":1->"msm_csid0":0[1],"msm_csid0":1->"msm_ispif0":0[1],"msm_ispif0":1->"msm_vfe0_rdi0":0[1]'
> 
> # media-ctl -d /dev/media0 -V '"ov13855
> 1-0010":0[fmt:SBGGR10_1X10/4224x3136
> field:none],"msm_csiphy0":0[fmt:SBGGR10_1X10/4224x3136
> field:none],"msm_csid0":0[fmt:SBGGR10_1X10/4224x3136
> field:none],"msm_ispif0":0[fmt:SBGGR10_1X10/4224x3136
> field:none],"msm_vfe0_rdi0":0[fmt:SBGGR10_1X10/4224x3136 field:none]'
> 
> Both commands succeed.
> 
> 
> 4. When streaming is started, the power consumption of the device goes
> up, all necessary external clocks and voltages are provided and are
> stable, and I can see a continuous stream of data on all 4 MIPI lanes
> using an oscilloscope.
> 
> 
> 5. Capturing frames with the following yavta command doesn't work
> though. The task is mostly stuck in the buffer dequeing ioctl:
> 
> # yavta -B capture-mplane -c10 -I -n 5 -f SBGGR10P -s 4224x3136 /dev/video0
> 
> vfe_isr() does fire sometimes with VFE_0_IRQ_STATUS_1_RDIn_SOF(0) set,
> but very occasionally only, and the frames do not contain data.
> 
> FWIW, an ov6540 is connected to port 1 of the camss, and this sensor
> works fine.
> 
> I'd be grateful for any pointer about what I could investigate on.
>

Everything that you have described seems correct.

As you say that frames do not contain any data, do
VFE_0_IRQ_STATUS_0_IMAGE_MASTER_n_PING_PONG
fire at all or not?

Do you see any interrupts on the ISPIF? Which?

Could you please share what hardware setup you have - mezzanine and camera 
module.


-- 
Best regards,
Todor Tomov


Re: [PATCH] [media] ov5645: I2C address change

2017-10-09 Thread Todor Tomov
Hi Laurent :)

On  9.10.2017 15:52, Laurent Pinchart wrote:
> Hello,
> 
> On Monday, 9 October 2017 12:34:26 EEST Sakari Ailus wrote:
>> On Mon, Oct 09, 2017 at 11:36:01AM +0300, Todor Tomov wrote:
>>> On  4.10.2017 13:47, Laurent Pinchart wrote:
>>>> CC'ing the I2C mainling list and the I2C maintainer.
>>>>
>>>> On Wednesday, 4 October 2017 13:30:08 EEST Sakari Ailus wrote:
>>>>> On Mon, Oct 02, 2017 at 04:28:45PM +0300, Todor Tomov wrote:
>>>>>> As soon as the sensor is powered on, change the I2C address to the one
>>>>>> specified in DT. This allows to use multiple physical sensors
>>>>>> connected to the same I2C bus.
>>>>>>
>>>>>> Signed-off-by: Todor Tomov <todor.to...@linaro.org>
>>>>>
>>>>> The smiapp driver does something similar and I understand Laurent might
>>>>> be interested in such functionality as well.
>>>>>
>>>>> It'd be nice to handle this through the I²C framework instead and to
>>>>> define how the information is specified through DT. That way it could
>>>>> be made generic, to work with more devices than just this one.
>>>>>
>>>>> What do you think?
>>>
>>> Thank you for this suggestion.
>>>
>>> The way I have done it is to put the new I2C address in the DT and the
>>> driver programs the change using the original I2C address. The original
>>> I2C address is hardcoded in the driver. So maybe we can extend the DT
>>> binding and the I2C framework so that both addresses come from the DT and
>>> avoid hiding the original I2C address in the driver. This sounds good to
>>> me.
>>
>> Agreed.
>>
>> In this case the address is known but in general that's not the case it's
>> not that simple. There are register compatible devices that have different
>> addresses even if they're the same devices.
>>
>> It might be a good idea to make this explicit.
> 
> Yes, in the general case we need to specify the original address in DT, as 
> the 
> chip could have a non-fixed boot-up I2C address.
> 
> In many cases the value of the new I2C address doesn't matter much, as long 
> as 
> it's unique on the bus. I was thinking about implementing a dynamic allocator 
> for I2C addresses, but after discussing it with Wolfram we concluded that it 
> would probably not be a good idea. There could be other I2C devices on the 
> bus 
> that Linux isn't aware of, in which case the dynamic allocator could create 
> address conflicts. Specifying the new address in DT is likely a better idea, 
> even if it could feel a bit more of system configuration information than a 
> pure hardware description.
> 
>>> Then changing the address could be device specific and also this must be
>>> done right after power on so that there are no address conflicts. So I
>>> don't think that we can support this through the I2C framework only, the
>>> drivers that we want to do that will have to be expanded with this
>>> functionality. Or do you have any other idea?
>>
>> Yes, how the address is changed is always hardware specific. This would be
>> most conveniently done in driver's probe or PM runtime_resume functions.
> 
> This patch modifies client->addr directly, which I don't think is a good 
> idea. 
> I'd prefer making the I2C core aware of the address change through an 
> explicit 
> API call. This would allow catching I2C adress conflicts for instance.
> 
>> It could be as simple as providing an adapter specific mutex to serialise
>> address changes on the bus so that no two address changes are taking place
>> at the same time. Which is essentially the impliementation you had, only
>> the mutex would be for the I²C adapter, not the driver. An helper functions
>> for acquiring and releasing the mutex.
> 
> Why do you need to serialize address changes ?

Correct me if I'm wrong, but if you power on more than one device with the
same I2C address and issue a command to change it, then all devices will
recognize this command as addressed to them. The only solution (which I know
about) to avoid this is to serialize the power on and address change (as a 
whole!)
for these devices.

I think it would be better to move the mutex out of the driver - to avoid all
client drivers which will change I2C address to add a global variable mutex 
for this. We just have to find a better place for it :)

> 
>> I wonder what others think.
> 

-- 
Best regards,
Todor Tomov


Re: [PATCH] [media] ov5645: I2C address change

2017-10-09 Thread Todor Tomov
Hi Sakari,

On  4.10.2017 13:47, Laurent Pinchart wrote:
> CC'ing the I2C mainling list and the I2C maintainer.
> 
> On Wednesday, 4 October 2017 13:30:08 EEST Sakari Ailus wrote:
>> Hi Todor,
>>
>> On Mon, Oct 02, 2017 at 04:28:45PM +0300, Todor Tomov wrote:
>>> As soon as the sensor is powered on, change the I2C address to the one
>>> specified in DT. This allows to use multiple physical sensors connected
>>> to the same I2C bus.
>>>
>>> Signed-off-by: Todor Tomov <todor.to...@linaro.org>
>>
>> The smiapp driver does something similar and I understand Laurent might be
>> interested in such functionality as well.
>>
>> It'd be nice to handle this through the I²C framework instead and to define
>> how the information is specified through DT. That way it could be made
>> generic, to work with more devices than just this one.
>>
>> What do you think?

Thank you for this suggestion.

The way I have done it is to put the new I2C address in the DT and the driver
programs the change using the original I2C address. The original I2C address
is hardcoded in the driver. So maybe we can extend the DT binding and the I2C
framework so that both addresses come from the DT and avoid hiding the
original I2C address in the driver. This sounds good to me.

Then changing the address could be device specific and also this must be done
right after power on so that there are no address conflicts. So I don't think
that we can support this through the I2C framework only, the drivers that we
want to do that will have to be expanded with this functionality. Or do you
have any other idea?

Best regards,
Todor 

>>
>> Cc Laurent.
>>
>>> ---
>>>
>>>  drivers/media/i2c/ov5645.c | 42 
>>>  1 file changed, 42 insertions(+)
>>>
>>> diff --git a/drivers/media/i2c/ov5645.c b/drivers/media/i2c/ov5645.c
>>> index d28845f..8541109 100644
>>> --- a/drivers/media/i2c/ov5645.c
>>> +++ b/drivers/media/i2c/ov5645.c
>>> @@ -33,6 +33,7 @@
>>>  #include 
>>>  #include 
>>>  #include 
>>> +#include 
>>>  #include 
>>>  #include 
>>>  #include 
>>> @@ -42,6 +43,8 @@
>>>  #include 
>>>  #include 
>>>
>>> +static DEFINE_MUTEX(ov5645_lock);
>>> +
>>>  #define OV5645_VOLTAGE_ANALOG   280
>>>  #define OV5645_VOLTAGE_DIGITAL_CORE 150
>>>  #define OV5645_VOLTAGE_DIGITAL_IO   180
>>> @@ -590,6 +593,31 @@ static void ov5645_regulators_disable(struct ov5645
>>> *ov5645)
>>> dev_err(ov5645->dev, "io regulator disable failed\n");
>>>  }
>>>
>>> +static int ov5645_write_reg_to(struct ov5645 *ov5645, u16 reg, u8 val,
>>> +  u16 i2c_addr)
>>> +{
>>> +   u8 regbuf[3] = {
>>> +   reg >> 8,
>>> +   reg & 0xff,
>>> +   val
>>> +   };
>>> +   struct i2c_msg msgs = {
>>> +   .addr = i2c_addr,
>>> +   .flags = 0,
>>> +   .len = 3,
>>> +   .buf = regbuf
>>> +   };
>>> +   int ret;
>>> +
>>> +   ret = i2c_transfer(ov5645->i2c_client->adapter, , 1);
>>> +   if (ret < 0)
>>> +   dev_err(ov5645->dev,
>>> +   "%s: write reg error %d on addr 0x%x: reg=0x%x, 
>>> val=0x%x\n",
>>> +   __func__, ret, i2c_addr, reg, val);
>>> +
>>> +   return ret;
>>> +}
>>> +
>>>  static int ov5645_write_reg(struct ov5645 *ov5645, u16 reg, u8 val)
>>>  {
>>> u8 regbuf[3];
>>> @@ -729,10 +757,24 @@ static int ov5645_s_power(struct v4l2_subdev *sd,
>>> int on)
>>>  */
>>> if (ov5645->power_count == !on) {
>>> if (on) {
>>> +   mutex_lock(_lock);
>>> +
>>> ret = ov5645_set_power_on(ov5645);
>>> if (ret < 0)
>>> goto exit;
>>>
>>> +   ret = ov5645_write_reg_to(ov5645, 0x3100,
>>> +   ov5645->i2c_client->addr, 0x78);
>>> +   if (ret < 0) {
>>> +   dev_err(ov5645->dev,
>>> +   "could not change i2c address\n");
>>> +   ov5645_set_power_off(ov5645);
>>> +   mutex_unlock(_lock);
>>> +   goto exit;
>>> +   }
>>> +
>>> +   mutex_unlock(_lock);
>>> +
>>> ret = ov5645_set_register_array(ov5645,
>>> ov5645_global_init_setting,
>>> ARRAY_SIZE(ov5645_global_init_setting));
> 



Re: [PATCH] [media] ov5645: I2C address change (fwd)

2017-10-04 Thread Todor Tomov
Hello,

On  4.10.2017 12:06, Julia Lawall wrote:
> Hello,
> 
> It seems that an unlock is missing on line 764.

Yes, this is true. I'll add an unlock there. Thank you for noticing this.

Best regards,
Todor

> 
> julia
> 
> -- Forwarded message --
> Date: Wed, 4 Oct 2017 05:59:09 +0800
> From: kbuild test robot <fengguang...@intel.com>
> To: kbu...@01.org
> Cc: Julia Lawall <julia.law...@lip6.fr>
> Subject: Re: [PATCH] [media] ov5645: I2C address change
> 
> CC: kbuild-...@01.org
> In-Reply-To: <1506950925-13924-1-git-send-email-todor.to...@linaro.org>
> TO: Todor Tomov <todor.to...@linaro.org>
> CC: mche...@kernel.org, sakari.ai...@linux.intel.com, hansv...@cisco.com, 
> linux-media@vger.kernel.org, linux-ker...@vger.kernel.org, Todor Tomov 
> <todor.to...@linaro.org>
> CC: linux-media@vger.kernel.org, linux-ker...@vger.kernel.org, Todor Tomov 
> <todor.to...@linaro.org>
> 
> Hi Todor,
> 
> [auto build test WARNING on linuxtv-media/master]
> [also build test WARNING on v4.14-rc3 next-20170929]
> [if your patch is applied to the wrong git tree, please drop us a note to 
> help improve the system]
> 
> url:
> https://github.com/0day-ci/linux/commits/Todor-Tomov/ov5645-I2C-address-change/20171003-234231
> base:   git://linuxtv.org/media_tree.git master
> :: branch date: 6 hours ago
> :: commit date: 6 hours ago
> 
>>> drivers/media/i2c/ov5645.c:806:1-7: preceding lock on line 760
> 
> # 
> https://github.com/0day-ci/linux/commit/c222075023642217170e2ef95f48efef079f9bcd
> git remote add linux-review https://github.com/0day-ci/linux
> git remote update linux-review
> git checkout c222075023642217170e2ef95f48efef079f9bcd
> vim +806 drivers/media/i2c/ov5645.c
> 
> 9cae9722 Todor Tomov 2017-04-11  747
> 9cae9722 Todor Tomov 2017-04-11  748  static int ov5645_s_power(struct 
> v4l2_subdev *sd, int on)
> 9cae9722 Todor Tomov 2017-04-11  749  {
> 9cae9722 Todor Tomov 2017-04-11  750  struct ov5645 *ov5645 = 
> to_ov5645(sd);
> 9cae9722 Todor Tomov 2017-04-11  751  int ret = 0;
> 9cae9722 Todor Tomov 2017-04-11  752
> 9cae9722 Todor Tomov 2017-04-11  753      mutex_lock(>power_lock);
> 9cae9722 Todor Tomov 2017-04-11  754
> 9cae9722 Todor Tomov 2017-04-11  755  /* If the power count is 
> modified from 0 to != 0 or from != 0 to 0,
> 9cae9722 Todor Tomov 2017-04-11  756   * update the power state.
> 9cae9722 Todor Tomov 2017-04-11  757   */
> 9cae9722 Todor Tomov 2017-04-11  758  if (ov5645->power_count == !on) 
> {
> 9cae9722 Todor Tomov 2017-04-11  759  if (on) {
> c2220750 Todor Tomov 2017-10-02 @760  
> mutex_lock(_lock);
> c2220750 Todor Tomov 2017-10-02  761
> 9cae9722 Todor Tomov 2017-04-11  762  ret = 
> ov5645_set_power_on(ov5645);
> 9cae9722 Todor Tomov 2017-04-11  763  if (ret < 0)
> 9cae9722 Todor Tomov 2017-04-11  764  goto 
> exit;
> 9cae9722 Todor Tomov 2017-04-11  765
> c2220750 Todor Tomov 2017-10-02  766  ret = 
> ov5645_write_reg_to(ov5645, 0x3100,
> c2220750 Todor Tomov 2017-10-02  767      
> ov5645->i2c_client->addr, 0x78);
> c2220750 Todor Tomov 2017-10-02  768  if (ret < 0) {
> c2220750 Todor Tomov 2017-10-02  769      
> dev_err(ov5645->dev,
> c2220750 Todor Tomov 2017-10-02  770  
> "could not change i2c address\n");
> c2220750 Todor Tomov 2017-10-02  771      
> ov5645_set_power_off(ov5645);
> c2220750 Todor Tomov 2017-10-02  772  
> mutex_unlock(_lock);
> c2220750 Todor Tomov 2017-10-02  773  goto 
> exit;
> c2220750 Todor Tomov 2017-10-02  774  }
> c2220750 Todor Tomov 2017-10-02  775
> c2220750 Todor Tomov 2017-10-02  776  
> mutex_unlock(_lock);
> c2220750 Todor Tomov 2017-10-02  777
> 9cae9722 Todor Tomov 2017-04-11  778  ret = 
> ov5645_set_register_array(ov5645,
> 9cae9722 Todor Tomov 2017-04-11  779      
> ov5645_global_init_setting,
> 9cae9722 Todor Tomov 2017-04-11  780  
> ARRAY_SIZE(ov5645_global_init_setting));
> 9cae9722 Todor Tomov 2017-04-11  781      if (ret < 0) {
> 9cae9722 Todor Tomov 2017-04-11  782      
> dev_err(ov5645->dev,
> 9cae9722 Todor Tomov 2017-04-11 

[PATCH] [media] ov5645: I2C address change

2017-10-02 Thread Todor Tomov
As soon as the sensor is powered on, change the I2C address to the one
specified in DT. This allows to use multiple physical sensors connected
to the same I2C bus.

Signed-off-by: Todor Tomov <todor.to...@linaro.org>
---
 drivers/media/i2c/ov5645.c | 42 ++
 1 file changed, 42 insertions(+)

diff --git a/drivers/media/i2c/ov5645.c b/drivers/media/i2c/ov5645.c
index d28845f..8541109 100644
--- a/drivers/media/i2c/ov5645.c
+++ b/drivers/media/i2c/ov5645.c
@@ -33,6 +33,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -42,6 +43,8 @@
 #include 
 #include 
 
+static DEFINE_MUTEX(ov5645_lock);
+
 #define OV5645_VOLTAGE_ANALOG   280
 #define OV5645_VOLTAGE_DIGITAL_CORE 150
 #define OV5645_VOLTAGE_DIGITAL_IO   180
@@ -590,6 +593,31 @@ static void ov5645_regulators_disable(struct ov5645 
*ov5645)
dev_err(ov5645->dev, "io regulator disable failed\n");
 }
 
+static int ov5645_write_reg_to(struct ov5645 *ov5645, u16 reg, u8 val,
+  u16 i2c_addr)
+{
+   u8 regbuf[3] = {
+   reg >> 8,
+   reg & 0xff,
+   val
+   };
+   struct i2c_msg msgs = {
+   .addr = i2c_addr,
+   .flags = 0,
+   .len = 3,
+   .buf = regbuf
+   };
+   int ret;
+
+   ret = i2c_transfer(ov5645->i2c_client->adapter, , 1);
+   if (ret < 0)
+   dev_err(ov5645->dev,
+   "%s: write reg error %d on addr 0x%x: reg=0x%x, 
val=0x%x\n",
+   __func__, ret, i2c_addr, reg, val);
+
+   return ret;
+}
+
 static int ov5645_write_reg(struct ov5645 *ov5645, u16 reg, u8 val)
 {
u8 regbuf[3];
@@ -729,10 +757,24 @@ static int ov5645_s_power(struct v4l2_subdev *sd, int on)
 */
if (ov5645->power_count == !on) {
if (on) {
+   mutex_lock(_lock);
+
ret = ov5645_set_power_on(ov5645);
if (ret < 0)
goto exit;
 
+   ret = ov5645_write_reg_to(ov5645, 0x3100,
+   ov5645->i2c_client->addr, 0x78);
+   if (ret < 0) {
+   dev_err(ov5645->dev,
+   "could not change i2c address\n");
+   ov5645_set_power_off(ov5645);
+   mutex_unlock(_lock);
+   goto exit;
+   }
+
+   mutex_unlock(_lock);
+
ret = ov5645_set_register_array(ov5645,
ov5645_global_init_setting,
ARRAY_SIZE(ov5645_global_init_setting));
-- 
2.7.4



Re: [PATCH v4 12/21] camss: vfe: Format conversion support using PIX interface

2017-09-11 Thread Todor Tomov
Hi Geert,

On 10.09.2017 12:58, Geert Uytterhoeven wrote:
> Hi Todor,
> 
> On Tue, Aug 8, 2017 at 3:30 PM, Todor Tomov <todor.to...@linaro.org> wrote:
>> Use VFE PIX input interface and do format conversion in VFE.
>>
>> Supported input format is UYVY (single plane YUV 4:2:2) and
>> its different sample order variations.
>>
>> Supported output formats are:
>> - NV12/NV21 (two plane YUV 4:2:0)
>> - NV16/NV61 (two plane YUV 4:2:2)
>>
>> Signed-off-by: Todor Tomov <todor.to...@linaro.org>
> 
> This is now commit 9b5833f7b82f1431 upstream.
> 
>> @@ -355,6 +471,38 @@ static void vfe_bus_disconnect_wm_from_rdi(struct 
>> vfe_device *vfe, u8 wm,
>> vfe_reg_clr(vfe, VFE_0_BUS_XBAR_CFG_x(wm), reg);
>>  }
>>
>> +static void vfe_set_xbar_cfg(struct vfe_device *vfe, struct vfe_output 
>> *output,
>> +u8 enable)
>> +{
>> +   struct vfe_line *line = container_of(output, struct vfe_line, 
>> output);
>> +   u32 p = line->video_out.active_fmt.fmt.pix_mp.pixelformat;
>> +   u32 reg;
> 
> With gcc 4.1.2:
> 
> drivers/media/platform/qcom/camss-8x16/camss-vfe.c: In function
> ‘vfe_set_xbar_cfg’:
> drivers/media/platform/qcom/camss-8x16/camss-vfe.c:614: warning:
> ‘reg’ may be used uninitialized in this function
> 
> This is a false positive, as output->wm_num is always either 1 or 2, hence the
> index i can never have a value different from 0 or 1, and reg is thus always
> initialized.
> 
>> +   unsigned int i;
>> +
>> +   for (i = 0; i < output->wm_num; i++) {
>> +   if (i == 0) {
>> +   reg = VFE_0_BUS_XBAR_CFG_x_M_SINGLE_STREAM_SEL_LUMA 
>> <<
>> +   
>> VFE_0_BUS_XBAR_CFG_x_M_SINGLE_STREAM_SEL_SHIFT;
>> +   } else if (i == 1) {
>> +   reg = VFE_0_BUS_XBAR_CFG_x_M_PAIR_STREAM_EN;
>> +   if (p == V4L2_PIX_FMT_NV12 || p == V4L2_PIX_FMT_NV16)
>> +   reg |= 
>> VFE_0_BUS_XBAR_CFG_x_M_PAIR_STREAM_SWAP_INTER_INTRA;
>> +   }
> 
>> @@ -458,6 +728,10 @@ static void vfe_init_outputs(struct vfe_device *vfe)
>> output->buf[0] = NULL;
>> output->buf[1] = NULL;
>> INIT_LIST_HEAD(>pending_bufs);
>> +
>> +   output->wm_num = 1;
>> +   if (vfe->line[i].id == VFE_LINE_PIX)
>> +   output->wm_num = 2;
>> }
>>  }
>>
> 
>> --- a/drivers/media/platform/qcom/camss-8x16/camss-vfe.h
>> +++ b/drivers/media/platform/qcom/camss-8x16/camss-vfe.h
>> @@ -30,8 +30,9 @@
>>  #define MSM_VFE_PAD_SRC 1
>>  #define MSM_VFE_PADS_NUM 2
>>
>> -#define MSM_VFE_LINE_NUM 3
>> +#define MSM_VFE_LINE_NUM 4
>>  #define MSM_VFE_IMAGE_MASTERS_NUM 7
>> +#define MSM_VFE_COMPOSITE_IRQ_NUM 4
>>
>>  #define MSM_VFE_VFE0_UB_SIZE 1023
>>  #define MSM_VFE_VFE0_UB_SIZE_RDI (MSM_VFE_VFE0_UB_SIZE / 3)
>> @@ -51,11 +52,13 @@ enum vfe_line_id {
>> VFE_LINE_NONE = -1,
>> VFE_LINE_RDI0 = 0,
>> VFE_LINE_RDI1 = 1,
>> -   VFE_LINE_RDI2 = 2
>> +   VFE_LINE_RDI2 = 2,
>> +   VFE_LINE_PIX = 3
>>  };
>>
>>  struct vfe_output {
>> -   u8 wm_idx;
>> +   u8 wm_num;
>> +   u8 wm_idx[3];
> 
> However, wm_idx[] reserves space for 3 entries, while currently only 2 are
> needed. Why?
> 
> If this is meant to accommodate for a future extension, the false positive
> will become a real issue.

The third entry will be needed if we add any three planar pixel format support
to the driver. If this happens this will involve also changes in
vfe_set_xbar_cfg() to support it. It is fine to change wm_idx[3] to wm_idx[2]
until then. However this will not remove the false positive warning. I suppose
it is best to also change vfe_set_xbar_cfg() now so that there is no warning -
init reg to 0 in all cases?

> 
> Gr{oetje,eeting}s,
> 
> Geert
> 
> --
> Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- 
> ge...@linux-m68k.org
> 
> In personal conversations with technical people, I call myself a hacker. But
> when I'm talking to journalists I just say "programmer" or something like 
> that.
> -- Linus Torvalds
> 

-- 
Best regards,
Todor Tomov


Re: [PATCH][media-next] media: qcom: camss: Make function vfe_set_selection static

2017-08-29 Thread Todor Tomov
On 29.08.2017 13:21, Colin King wrote:
> From: Colin Ian King <colin.k...@canonical.com>
> 
> The function vfe_set_selection is local to the source and does
> not need to be in global scope, so make it static.
> 
> Cleans up sparse warning:
> warning: symbol 'vfe_set_selection' was not declared. Should it be static?
> 
> Signed-off-by: Colin Ian King <colin.k...@canonical.com>

Thank you!
Acked-by: Todor Tomov <todor.to...@linaro.org>

> ---
>  drivers/media/platform/qcom/camss-8x16/camss-vfe.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/media/platform/qcom/camss-8x16/camss-vfe.c 
> b/drivers/media/platform/qcom/camss-8x16/camss-vfe.c
> index b21b3c2dc77f..b22d2dfcd3c2 100644
> --- a/drivers/media/platform/qcom/camss-8x16/camss-vfe.c
> +++ b/drivers/media/platform/qcom/camss-8x16/camss-vfe.c
> @@ -2660,7 +2660,7 @@ static int vfe_get_selection(struct v4l2_subdev *sd,
>   *
>   * Return -EINVAL or zero on success
>   */
> -int vfe_set_selection(struct v4l2_subdev *sd,
> +static int vfe_set_selection(struct v4l2_subdev *sd,
>struct v4l2_subdev_pad_config *cfg,
>    struct v4l2_subdev_selection *sel)
>  {
> 

-- 
Best regards,
Todor Tomov


Re: [PATCH v4 04/21] doc: media/v4l-drivers: Add Qualcomm Camera Subsystem driver document

2017-08-28 Thread Todor Tomov
Hi Daniel,

On 25.08.2017 17:10, Daniel Mack wrote:
> Hi Todor,
> 
> Thanks a lot for working on the upstream support for this!
> 
> On 08/08/2017 03:30 PM, Todor Tomov wrote:
>> +The Camera Subsystem hardware found on 8x16 processors and supported by the
>> +driver consists of:
>> +
>> +- 2 CSIPHY modules. They handle the Physical layer of the CSI2 receivers.
>> +  A separate camera sensor can be connected to each of the CSIPHY module;
>> +- 2 CSID (CSI Decoder) modules. They handle the Protocol and Application 
>> layer
>> +  of the CSI2 receivers. A CSID can decode data stream from any of the 
>> CSIPHY.
>> +  Each CSID also contains a TG (Test Generator) block which can generate
>> +  artificial input data for test purposes;
>> +- ISPIF (ISP Interface) module. Handles the routing of the data streams from
>> +  the CSIDs to the inputs of the VFE;
>> +- VFE (Video Front End) module. Contains a pipeline of image processing 
>> hardware
>> +  blocks. The VFE has different input interfaces. The PIX input interface 
>> feeds
>> +  the input data to the image processing pipeline. Three RDI input 
>> interfaces
>> +  bypass the image processing pipeline. The VFE also contains the AXI bus
>> +  interface which writes the output data to memory.
> 
> [I'm based on the 4.9 Linaro downstream version of this code right now,
> but at a glance the driver version there looks very much identical to
> this one.]
> 
> Could you explain how ISPIF, CSID and CSIPHY are related?
> 
> I have a userspace test setup that works fine for USB webcams, but when
> operating on any of the video devices exposed by this driver, the
> lowlevel functions such as .s_power of the ISPIF, CSID, CSIPHY and the
> sensor driver layers aren't called into.

Have you activated the media controller links? The s_power is called
when the subdev is part of a pipeline in which the video device node
is opened. You can see example configurations for the Qualcomm CAMSS
driver on:
https://github.com/96boards/documentation/blob/master/ConsumerEdition/DragonBoard-410c/Guides/CameraModule.md
This will probably answer most of your questions.

> 
> The general setup seems to work fine though. The sensor is probed,
> camss_subdev_notifier_complete() is called, and the v4l2 subdevices
> exist. But the stream start is not propagated to the other layers, and
> I'm trying to understand why.
> 
> My DTS looks something like this right now, and the hardware is an
> APQ8016 board (Variscite DART SD410).
> 
>  {
>   cam0: ov5640@3c {
>   compatible = "ovti,ov5640";
>   reg = <0x3c>;
> 
>   // clocks, regulators, gpios etc are omitted
> 
>   port {
>   cam0_ep: endpoint {
>   clock-lanes = <1>;
>   data-lanes = <0 2>;
>   remote-endpoint = <_ep>;
>   };
>   };
>   };
> };
> 
>  {
>   ports {
>   port@0 {
>   reg = <0>;
>   csiphy0_ep: endpoint {
>   clock-lanes = <1>;
>   data-lanes = <0 1 2 3>;

As far as I know the OV5640 has a two data lane CSI2 interface so
this will probably look like:
data-lanes = <0 2>;

>   qcom,settle-cnt = <0xe>;
>   remote-endpoint = <_ep>;
>   };
>   };
>   };
> };
> 
> Also, which video device should be opened when accessing the cameras on
> each of the hardware ports? And what are the other two devices doing?
> 
> I'm sure I'm missing something trivial, but at least I can't find this
> information in the documentation.
> 
> 
> Thanks,
> Daniel
> 

-- 
Best regards,
Todor Tomov


[PATCH 1/2] doc: media/v4l-drivers/qcom_camss: Add abbreviations explanation

2017-08-18 Thread Todor Tomov
Add explanations for VFE's PIX and RDI interfaces.

Signed-off-by: Todor Tomov <todor.to...@linaro.org>
---
 Documentation/media/v4l-drivers/qcom_camss.rst | 11 ++-
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/Documentation/media/v4l-drivers/qcom_camss.rst 
b/Documentation/media/v4l-drivers/qcom_camss.rst
index 7ef632a..9e66b7b 100644
--- a/Documentation/media/v4l-drivers/qcom_camss.rst
+++ b/Documentation/media/v4l-drivers/qcom_camss.rst
@@ -34,11 +34,12 @@ driver consists of:
 - ISPIF (ISP Interface) module. Handles the routing of the data streams from
   the CSIDs to the inputs of the VFE;
 - VFE (Video Front End) module. Contains a pipeline of image processing 
hardware
-  blocks. The VFE has different input interfaces. The PIX input interface feeds
-  the input data to the image processing pipeline. The image processing 
pipeline
-  contains also a scale and crop module at the end. Three RDI input interfaces
-  bypass the image processing pipeline. The VFE also contains the AXI bus
-  interface which writes the output data to memory.
+  blocks. The VFE has different input interfaces. The PIX (Pixel) input
+  interface feeds the input data to the image processing pipeline. The image
+  processing pipeline contains also a scale and crop module at the end. Three
+  RDI (Raw Dump Interface) input interfaces bypass the image processing
+  pipeline. The VFE also contains the AXI bus interface which writes the output
+  data to memory.
 
 
 Supported functionality
-- 
2.7.4



[PATCH 2/2] media: camss: Add abbreviations explanation

2017-08-18 Thread Todor Tomov
Add abbreviations explanation at the top header blocks in source files.

Signed-off-by: Todor Tomov <todor.to...@linaro.org>
---
 drivers/media/platform/qcom/camss-8x16/camss-csid.c  | 2 +-
 drivers/media/platform/qcom/camss-8x16/camss-csid.h  | 2 +-
 drivers/media/platform/qcom/camss-8x16/camss-ispif.c | 2 +-
 drivers/media/platform/qcom/camss-8x16/camss-ispif.h | 2 +-
 drivers/media/platform/qcom/camss-8x16/camss-vfe.c   | 2 +-
 drivers/media/platform/qcom/camss-8x16/camss-vfe.h   | 2 +-
 6 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/media/platform/qcom/camss-8x16/camss-csid.c 
b/drivers/media/platform/qcom/camss-8x16/camss-csid.c
index 792c14a..64df828 100644
--- a/drivers/media/platform/qcom/camss-8x16/camss-csid.c
+++ b/drivers/media/platform/qcom/camss-8x16/camss-csid.c
@@ -1,7 +1,7 @@
 /*
  * camss-csid.c
  *
- * Qualcomm MSM Camera Subsystem - CSID Module
+ * Qualcomm MSM Camera Subsystem - CSID (CSI Decoder) Module
  *
  * Copyright (c) 2011-2015, The Linux Foundation. All rights reserved.
  * Copyright (C) 2015-2017 Linaro Ltd.
diff --git a/drivers/media/platform/qcom/camss-8x16/camss-csid.h 
b/drivers/media/platform/qcom/camss-8x16/camss-csid.h
index 4df7018..8682d30 100644
--- a/drivers/media/platform/qcom/camss-8x16/camss-csid.h
+++ b/drivers/media/platform/qcom/camss-8x16/camss-csid.h
@@ -1,7 +1,7 @@
 /*
  * camss-csid.h
  *
- * Qualcomm MSM Camera Subsystem - CSID Module
+ * Qualcomm MSM Camera Subsystem - CSID (CSI Decoder) Module
  *
  * Copyright (c) 2011-2014, The Linux Foundation. All rights reserved.
  * Copyright (C) 2015-2017 Linaro Ltd.
diff --git a/drivers/media/platform/qcom/camss-8x16/camss-ispif.c 
b/drivers/media/platform/qcom/camss-8x16/camss-ispif.c
index 54d1946..24da529 100644
--- a/drivers/media/platform/qcom/camss-8x16/camss-ispif.c
+++ b/drivers/media/platform/qcom/camss-8x16/camss-ispif.c
@@ -1,7 +1,7 @@
 /*
  * camss-ispif.c
  *
- * Qualcomm MSM Camera Subsystem - ISPIF Module
+ * Qualcomm MSM Camera Subsystem - ISPIF (ISP Interface) Module
  *
  * Copyright (c) 2013-2015, The Linux Foundation. All rights reserved.
  * Copyright (C) 2015-2017 Linaro Ltd.
diff --git a/drivers/media/platform/qcom/camss-8x16/camss-ispif.h 
b/drivers/media/platform/qcom/camss-8x16/camss-ispif.h
index 6659020..f668306 100644
--- a/drivers/media/platform/qcom/camss-8x16/camss-ispif.h
+++ b/drivers/media/platform/qcom/camss-8x16/camss-ispif.h
@@ -1,7 +1,7 @@
 /*
  * camss-ispif.h
  *
- * Qualcomm MSM Camera Subsystem - ISPIF Module
+ * Qualcomm MSM Camera Subsystem - ISPIF (ISP Interface) Module
  *
  * Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
  * Copyright (C) 2015-2017 Linaro Ltd.
diff --git a/drivers/media/platform/qcom/camss-8x16/camss-vfe.c 
b/drivers/media/platform/qcom/camss-8x16/camss-vfe.c
index 1c86b10..94d635e 100644
--- a/drivers/media/platform/qcom/camss-8x16/camss-vfe.c
+++ b/drivers/media/platform/qcom/camss-8x16/camss-vfe.c
@@ -1,7 +1,7 @@
 /*
  * camss-vfe.c
  *
- * Qualcomm MSM Camera Subsystem - VFE Module
+ * Qualcomm MSM Camera Subsystem - VFE (Video Front End) Module
  *
  * Copyright (c) 2013-2015, The Linux Foundation. All rights reserved.
  * Copyright (C) 2015-2017 Linaro Ltd.
diff --git a/drivers/media/platform/qcom/camss-8x16/camss-vfe.h 
b/drivers/media/platform/qcom/camss-8x16/camss-vfe.h
index 88c29d0..53d5b66 100644
--- a/drivers/media/platform/qcom/camss-8x16/camss-vfe.h
+++ b/drivers/media/platform/qcom/camss-8x16/camss-vfe.h
@@ -1,7 +1,7 @@
 /*
  * camss-vfe.h
  *
- * Qualcomm MSM Camera Subsystem - VFE Module
+ * Qualcomm MSM Camera Subsystem - VFE (Video Front End) Module
  *
  * Copyright (c) 2013-2015, The Linux Foundation. All rights reserved.
  * Copyright (C) 2015-2017 Linaro Ltd.
-- 
2.7.4



Re: [PATCH v4 04/21] doc: media/v4l-drivers: Add Qualcomm Camera Subsystem driver document

2017-08-18 Thread Todor Tomov
Hi Hans,

On 18.08.2017 10:45, Hans Verkuil wrote:
> Hi Todor,
> 
> A few small comments below:
> 
> On 08/08/2017 03:30 PM, Todor Tomov wrote:
>> Add a document to describe Qualcomm Camera Subsystem driver.
>>
>> Signed-off-by: Todor Tomov <todor.to...@linaro.org>
>> ---
>>  Documentation/media/v4l-drivers/qcom_camss.rst | 124 
>> +
>>  1 file changed, 124 insertions(+)
>>  create mode 100644 Documentation/media/v4l-drivers/qcom_camss.rst
>>
>> diff --git a/Documentation/media/v4l-drivers/qcom_camss.rst 
>> b/Documentation/media/v4l-drivers/qcom_camss.rst
>> new file mode 100644
>> index 000..4707ea7
>> --- /dev/null
>> +++ b/Documentation/media/v4l-drivers/qcom_camss.rst
>> @@ -0,0 +1,124 @@
>> +.. include:: 
>> +
>> +Qualcomm Camera Subsystem driver
>> +
>> +
>> +Introduction
>> +
>> +
>> +This file documents the Qualcomm Camera Subsystem driver located under
>> +drivers/media/platform/qcom/camss-8x16.
>> +
>> +The current version of the driver supports the Camera Subsystem found on
>> +Qualcomm MSM8916 and APQ8016 processors.
>> +
>> +The driver implements V4L2, Media controller and V4L2 subdev interfaces.
>> +Camera sensor using V4L2 subdev interface in the kernel is supported.
>> +
>> +The driver is implemented using as a reference the Qualcomm Camera Subsystem
>> +driver for Android as found in Code Aurora [#f1]_.
>> +
>> +
>> +Qualcomm Camera Subsystem hardware
>> +--
>> +
>> +The Camera Subsystem hardware found on 8x16 processors and supported by the
>> +driver consists of:
>> +
>> +- 2 CSIPHY modules. They handle the Physical layer of the CSI2 receivers.
>> +  A separate camera sensor can be connected to each of the CSIPHY module;
>> +- 2 CSID (CSI Decoder) modules. They handle the Protocol and Application 
>> layer
>> +  of the CSI2 receivers. A CSID can decode data stream from any of the 
>> CSIPHY.
>> +  Each CSID also contains a TG (Test Generator) block which can generate
>> +  artificial input data for test purposes;
>> +- ISPIF (ISP Interface) module. Handles the routing of the data streams from
>> +  the CSIDs to the inputs of the VFE;
>> +- VFE (Video Front End) module. Contains a pipeline of image processing 
>> hardware
>> +  blocks. The VFE has different input interfaces. The PIX input interface 
>> feeds
>> +  the input data to the image processing pipeline. Three RDI input 
>> interfaces
>> +  bypass the image processing pipeline. The VFE also contains the AXI bus
>> +  interface which writes the output data to memory.
> 
> Can you explain what PIX and RDI stand for?
> 
> I would also think it is a good idea to add a comment at the top of the 
> various
> subdev sources that say a bit more than just "CSID Module".
> 
> A simple "CSID (CSI Decoder) Module" is enough. Just so the reader knows what
> it is all about.
> 
> Otherwise I don't have any more comments about this series.
> 
> I don't need a v5 for this, if you can just post one patch for this 
> documentation
> and one patch improving the source comments as described above, then that's
> fine with me.

Thank you for the review again.
I'll post two additional patches to add explanations of the abbreviations.

> 
> Regards,
> 
>   Hans
> 
>> +
>> +
>> +Supported functionality
>> +---
>> +
>> +The current version of the driver supports:
>> +
>> +- input from camera sensor via CSIPHY;
>> +- generation of test input data by the TG in CSID;
>> +- raw dump of the input data to memory. RDI interface of VFE is supported.
>> +  PIX interface (ISP processing, statistics engines, resize/crop, format
>> +  conversion) is not supported in the current version;
>> +- concurrent and independent usage of two data inputs - could be camera 
>> sensors
>> +  and/or TG.
>> +
>> +
>> +Driver Architecture and Design
>> +--
>> +
>> +The driver implements the V4L2 subdev interface. With the goal to model the
>> +hardware links between the modules and to expose a clean, logical and usable
>> +interface, the driver is split into V4L2 sub-devices as follows:
>> +
>> +- 2 CSIPHY sub-devices - each CSIPHY is represented by a single sub-device;
>> +- 2 CSID sub-devices - each CSID is represented by a single sub-device;
>> +- 2 ISPIF sub-devices - ISPIF is represented by a number of s

[PATCH v4 00/21] Qualcomm 8x16 Camera Subsystem driver

2017-08-08 Thread Todor Tomov
)
test VIDIOC_G/S/ENUMINPUT: OK
test VIDIOC_G/S_AUDIO: OK (Not Supported)
Inputs: 1 Audio Inputs: 0 Tuners: 0

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

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

Test input 0:

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

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

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

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

Test input 0:

Streaming ioctls:
test read/write: OK
test MMAP: OK 
test USERPTR: OK (Not Supported)
test DMABUF: Cannot test, specify --expbuf-device


Total: 46, Succeeded: 46, Failed: 0, Warnings: 0

---

Sakari Ailus (1):
  v4l: Add packed Bayer raw12 pixel formats

Todor Tomov (20):
  dt-bindings: media: Binding document for Qualcomm Camera subsystem
driver
  MAINTAINERS: Add Qualcomm Camera subsystem driver
  doc: media/v4l-drivers: Add Qualcomm Camera Subsystem driver document
  media: camss: Add CSIPHY files
  media: camss: Add CSID files
  media: camss: Add ISPIF files
  media: camss: Add VFE files
  media: camss: Add files which handle the video device nodes
  media: camms: Add core files
  media: camss: Enable building
  camss: vfe: Format conversion support using PIX interface
  doc: media/v4l-drivers: Qualcomm Camera Subsystem - PIX Interface
  camss: vfe: Support for frame padding
  camss: vfe: Add interface for scaling
  camss: vfe: Configure scaler module in VFE
  camss: vfe: Add interface for cropping
  camss: vfe: Configure crop module in VFE
  doc: media/v4l-drivers: Qualcomm Camera Subsystem - Scale and crop
  camss: Use optimal clock frequency rates
  doc: media/v4l-drivers: Qualcomm Camera Subsystem - Media graph

 .../devicetree/bindings/media/qcom,camss.txt   |  197 ++
 Documentation/media/uapi/v4l/pixfmt-rgb.rst|1 +
 Documentation/media/uapi/v4l/pixfmt-srggb12p.rst   |  104 +
 Documentation/media/v4l-drivers/qcom_camss.rst |  155 +
 .../media/v4l-drivers/qcom_camss_graph.dot |   41 +
 MAINTAINERS|8 +
 drivers/media/platform/Kconfig |7 +
 drivers/media/platform/Makefile|2 +
 drivers/media/platform/qcom/camss-8x16/Makefile|   11 +
 .../media/platform/qcom/camss-8x16/camss-csid.c| 1092 +++
 .../media/platform/qcom/camss-8x16/camss-csid.h|   82 +
 .../media/platform/qcom/camss-8x16/camss-csiphy.c  |  890 ++
 .../media/platform/qcom/camss-8x16/camss-csiphy.h  |   77 +
 .../media/platform/qcom/camss-8x16/camss-ispif.c   | 1175 
 .../media/platform/qcom/camss-8x16/camss-ispif.h   |   85 +
 drivers/media/platform/qcom/camss-8x16/camss-vfe.c | 3088 
 drivers/media/platform/qcom/camss-8x16/camss-vfe.h |  123 +
 .../media/platform/qcom/camss-8x16/camss-video.c   |  860 ++
 .../media/platform/qcom/camss-8x16/camss-video.h   |   70 +
 drivers/media/platform/qcom/camss-8x16/camss.c |  746 +
 drivers/media/platform/qcom/camss-8x16/camss.h |  106 +
 drivers/media/v4l2-core/v4l2-ioctl.c   |   12 +-
 include/uapi/linux/videodev2.h |5 +
 23 files changed, 8933 insertions(+), 4 deletions(-)
 create mode 100644

[PATCH v4 04/21] doc: media/v4l-drivers: Add Qualcomm Camera Subsystem driver document

2017-08-08 Thread Todor Tomov
Add a document to describe Qualcomm Camera Subsystem driver.

Signed-off-by: Todor Tomov <todor.to...@linaro.org>
---
 Documentation/media/v4l-drivers/qcom_camss.rst | 124 +
 1 file changed, 124 insertions(+)
 create mode 100644 Documentation/media/v4l-drivers/qcom_camss.rst

diff --git a/Documentation/media/v4l-drivers/qcom_camss.rst 
b/Documentation/media/v4l-drivers/qcom_camss.rst
new file mode 100644
index 000..4707ea7
--- /dev/null
+++ b/Documentation/media/v4l-drivers/qcom_camss.rst
@@ -0,0 +1,124 @@
+.. include:: 
+
+Qualcomm Camera Subsystem driver
+
+
+Introduction
+
+
+This file documents the Qualcomm Camera Subsystem driver located under
+drivers/media/platform/qcom/camss-8x16.
+
+The current version of the driver supports the Camera Subsystem found on
+Qualcomm MSM8916 and APQ8016 processors.
+
+The driver implements V4L2, Media controller and V4L2 subdev interfaces.
+Camera sensor using V4L2 subdev interface in the kernel is supported.
+
+The driver is implemented using as a reference the Qualcomm Camera Subsystem
+driver for Android as found in Code Aurora [#f1]_.
+
+
+Qualcomm Camera Subsystem hardware
+--
+
+The Camera Subsystem hardware found on 8x16 processors and supported by the
+driver consists of:
+
+- 2 CSIPHY modules. They handle the Physical layer of the CSI2 receivers.
+  A separate camera sensor can be connected to each of the CSIPHY module;
+- 2 CSID (CSI Decoder) modules. They handle the Protocol and Application layer
+  of the CSI2 receivers. A CSID can decode data stream from any of the CSIPHY.
+  Each CSID also contains a TG (Test Generator) block which can generate
+  artificial input data for test purposes;
+- ISPIF (ISP Interface) module. Handles the routing of the data streams from
+  the CSIDs to the inputs of the VFE;
+- VFE (Video Front End) module. Contains a pipeline of image processing 
hardware
+  blocks. The VFE has different input interfaces. The PIX input interface feeds
+  the input data to the image processing pipeline. Three RDI input interfaces
+  bypass the image processing pipeline. The VFE also contains the AXI bus
+  interface which writes the output data to memory.
+
+
+Supported functionality
+---
+
+The current version of the driver supports:
+
+- input from camera sensor via CSIPHY;
+- generation of test input data by the TG in CSID;
+- raw dump of the input data to memory. RDI interface of VFE is supported.
+  PIX interface (ISP processing, statistics engines, resize/crop, format
+  conversion) is not supported in the current version;
+- concurrent and independent usage of two data inputs - could be camera sensors
+  and/or TG.
+
+
+Driver Architecture and Design
+--
+
+The driver implements the V4L2 subdev interface. With the goal to model the
+hardware links between the modules and to expose a clean, logical and usable
+interface, the driver is split into V4L2 sub-devices as follows:
+
+- 2 CSIPHY sub-devices - each CSIPHY is represented by a single sub-device;
+- 2 CSID sub-devices - each CSID is represented by a single sub-device;
+- 2 ISPIF sub-devices - ISPIF is represented by a number of sub-devices equal
+  to the number of CSID sub-devices;
+- 3 VFE sub-devices - VFE is represented by a number of sub-devices equal to
+  the number of RDI input interfaces.
+
+The considerations to split the driver in this particular way are as follows:
+
+- representing CSIPHY and CSID modules by a separate sub-device for each module
+  allows to model the hardware links between these modules;
+- representing VFE by a separate sub-devices for each RDI input interface 
allows
+  to use the three RDI interfaces concurently and independently as this is
+  supported by the hardware;
+- representing ISPIF by a number of sub-devices equal to the number of CSID
+  sub-devices allows to create linear media controller pipelines when using two
+  cameras simultaneously. This avoids branches in the pipelines which otherwise
+  will require a) userspace and b) media framework (e.g. power on/off
+  operations) to  make assumptions about the data flow from a sink pad to a
+  source pad on a single media entity.
+
+Each VFE sub-device is linked to a separate video device node.
+
+The complete list of the media entities (V4L2 sub-devices and video device
+nodes) is as follows:
+
+- msm_csiphy0
+- msm_csiphy1
+- msm_csid0
+- msm_csid1
+- msm_ispif0
+- msm_ispif1
+- msm_vfe0_rdi0
+- msm_vfe0_video0
+- msm_vfe0_rdi1
+- msm_vfe0_video1
+- msm_vfe0_rdi2
+- msm_vfe0_video2
+
+
+Implementation
+--
+
+Runtime configuration of the hardware (updating settings while streaming) is
+not required to implement the currently supported functionality. The complete
+configuration on each hardware module is applied on STREAMON ioctl based on
+the current active media links, formats and controls set.
+
+
+Documen

[PATCH v4 03/21] MAINTAINERS: Add Qualcomm Camera subsystem driver

2017-08-08 Thread Todor Tomov
Add an entry for Qualcomm Camera subsystem driver.

Signed-off-by: Todor Tomov <todor.to...@linaro.org>
---
 MAINTAINERS | 8 
 1 file changed, 8 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index bdde944..87d0c7f 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -10996,6 +10996,14 @@ W: 
http://wireless.kernel.org/en/users/Drivers/ath9k
 S: Supported
 F: drivers/net/wireless/ath/ath9k/
 
+QUALCOMM CAMERA SUBSYSTEM DRIVER
+M: Todor Tomov <todor.to...@linaro.org>
+L: linux-media@vger.kernel.org
+S: Maintained
+F: Documentation/devicetree/bindings/media/qcom,camss.txt
+F: Documentation/media/v4l-drivers/qcom_camss.rst
+F: drivers/media/platform/qcom/camss-8x16/
+
 QUALCOMM EMAC GIGABIT ETHERNET DRIVER
 M: Timur Tabi <ti...@codeaurora.org>
 L: net...@vger.kernel.org
-- 
2.7.4



[PATCH v4 07/21] media: camss: Add ISPIF files

2017-08-08 Thread Todor Tomov
These files control the ISPIF module which handles the routing of the data
streams from the CSIDs to the inputs of the VFE.

Signed-off-by: Todor Tomov <todor.to...@linaro.org>
---
 .../media/platform/qcom/camss-8x16/camss-ispif.c   | 1164 
 .../media/platform/qcom/camss-8x16/camss-ispif.h   |   85 ++
 2 files changed, 1249 insertions(+)
 create mode 100644 drivers/media/platform/qcom/camss-8x16/camss-ispif.c
 create mode 100644 drivers/media/platform/qcom/camss-8x16/camss-ispif.h

diff --git a/drivers/media/platform/qcom/camss-8x16/camss-ispif.c 
b/drivers/media/platform/qcom/camss-8x16/camss-ispif.c
new file mode 100644
index 000..b047811
--- /dev/null
+++ b/drivers/media/platform/qcom/camss-8x16/camss-ispif.c
@@ -0,0 +1,1164 @@
+/*
+ * camss-ispif.c
+ *
+ * Qualcomm MSM Camera Subsystem - ISPIF Module
+ *
+ * Copyright (c) 2013-2015, The Linux Foundation. All rights reserved.
+ * Copyright (C) 2015-2017 Linaro Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only 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 
+#include 
+#include 
+
+#include "camss-ispif.h"
+#include "camss.h"
+
+#define MSM_ISPIF_NAME "msm_ispif"
+
+#define ispif_line_array(ptr_line) \
+   ((const struct ispif_line (*)[]) &(ptr_line[-(ptr_line->id)]))
+
+#define to_ispif(ptr_line) \
+   container_of(ispif_line_array(ptr_line), struct ispif_device, ptr_line)
+
+#define ISPIF_RST_CMD_00x008
+#define ISPIF_RST_CMD_0_STROBED_RST_EN (1 << 0)
+#define ISPIF_RST_CMD_0_MISC_LOGIC_RST (1 << 1)
+#define ISPIF_RST_CMD_0_SW_REG_RST (1 << 2)
+#define ISPIF_RST_CMD_0_PIX_INTF_0_CSID_RST(1 << 3)
+#define ISPIF_RST_CMD_0_PIX_INTF_0_VFE_RST (1 << 4)
+#define ISPIF_RST_CMD_0_PIX_INTF_1_CSID_RST(1 << 5)
+#define ISPIF_RST_CMD_0_PIX_INTF_1_VFE_RST (1 << 6)
+#define ISPIF_RST_CMD_0_RDI_INTF_0_CSID_RST(1 << 7)
+#define ISPIF_RST_CMD_0_RDI_INTF_0_VFE_RST (1 << 8)
+#define ISPIF_RST_CMD_0_RDI_INTF_1_CSID_RST(1 << 9)
+#define ISPIF_RST_CMD_0_RDI_INTF_1_VFE_RST (1 << 10)
+#define ISPIF_RST_CMD_0_RDI_INTF_2_CSID_RST(1 << 11)
+#define ISPIF_RST_CMD_0_RDI_INTF_2_VFE_RST (1 << 12)
+#define ISPIF_RST_CMD_0_PIX_OUTPUT_0_MISR_RST  (1 << 16)
+#define ISPIF_RST_CMD_0_RDI_OUTPUT_0_MISR_RST  (1 << 17)
+#define ISPIF_RST_CMD_0_RDI_OUTPUT_1_MISR_RST  (1 << 18)
+#define ISPIF_RST_CMD_0_RDI_OUTPUT_2_MISR_RST  (1 << 19)
+#define ISPIF_IRQ_GLOBAL_CLEAR_CMD 0x01c
+#define ISPIF_VFE_m_CTRL_0(m)  (0x200 + 0x200 * (m))
+#define ISPIF_VFE_m_CTRL_0_PIX0_LINE_BUF_EN(1 << 6)
+#define ISPIF_VFE_m_IRQ_MASK_0(m)  (0x208 + 0x200 * (m))
+#define ISPIF_VFE_m_IRQ_MASK_0_PIX0_ENABLE 0x1249
+#define ISPIF_VFE_m_IRQ_MASK_0_PIX0_MASK   0x1fff
+#define ISPIF_VFE_m_IRQ_MASK_0_RDI0_ENABLE 0x02492000
+#define ISPIF_VFE_m_IRQ_MASK_0_RDI0_MASK   0x03ffe000
+#define ISPIF_VFE_m_IRQ_MASK_1(m)  (0x20c + 0x200 * (m))
+#define ISPIF_VFE_m_IRQ_MASK_1_PIX1_ENABLE 0x1249
+#define ISPIF_VFE_m_IRQ_MASK_1_PIX1_MASK   0x1fff
+#define ISPIF_VFE_m_IRQ_MASK_1_RDI1_ENABLE 0x02492000
+#define ISPIF_VFE_m_IRQ_MASK_1_RDI1_MASK   0x03ffe000
+#define ISPIF_VFE_m_IRQ_MASK_2(m)  (0x210 + 0x200 * (m))
+#define ISPIF_VFE_m_IRQ_MASK_2_RDI2_ENABLE 0x1249
+#define ISPIF_VFE_m_IRQ_MASK_2_RDI2_MASK   0x1fff
+#define ISPIF_VFE_m_IRQ_STATUS_0(m)(0x21c + 0x200 * (m))
+#define ISPIF_VFE_m_IRQ_STATUS_0_PIX0_OVERFLOW (1 << 12)
+#define ISPIF_VFE_m_IRQ_STATUS_0_RDI0_OVERFLOW (1 << 25)
+#define ISPIF_VFE_m_IRQ_STATUS_1(m)(0x220 + 0x200 * (m))
+#define ISPIF_VFE_m_IRQ_STATUS_1_PIX1_OVERFLOW (1 << 12)
+#define ISPIF_VFE_m_IRQ_STATUS_1_RDI1_OVERFLOW (1 << 25)
+#define ISPIF_VFE_m_IRQ_STATUS_2(m)(0x224 + 0x200 * (m))
+#define ISPIF_VFE_m_IRQ_STATUS_2_RDI2_OVERFLOW (1 << 12)
+#define ISPIF_VFE_m_IRQ_CLEAR_0(m) (0x230 + 0x200 * (m))
+#define ISPIF_VFE_m_IRQ_CLEAR_1(m) (0x234 + 0x200 * (m))
+#define ISPIF_VFE_m_IRQ_CLEAR_2(m) (0x238 + 0x200 * (m))
+#define ISPIF_VFE_m_INTF_INPUT_SEL(m)  (0x244 + 0x200 * (m))
+#define ISPIF_VFE_m_INTF_CMD_0(m)  (0x248 + 0x200 * (m))
+#define ISPIF_VFE_m_INTF_CMD_1(m)  (0x24c + 0x200 * (m))
+#define ISPIF_VFE_m_PIX_INTF_n_CID_MASK(m, n)  \
+   (0x254 + 0x200 * (m)

[PATCH v4 05/21] media: camss: Add CSIPHY files

2017-08-08 Thread Todor Tomov
These files control the CSIPHY modules which are responsible for the
physical layer of the CSI2 receivers.

Signed-off-by: Todor Tomov <todor.to...@linaro.org>
---
 .../media/platform/qcom/camss-8x16/camss-csiphy.c  | 823 +
 .../media/platform/qcom/camss-8x16/camss-csiphy.h  |  77 ++
 2 files changed, 900 insertions(+)
 create mode 100644 drivers/media/platform/qcom/camss-8x16/camss-csiphy.c
 create mode 100644 drivers/media/platform/qcom/camss-8x16/camss-csiphy.h

diff --git a/drivers/media/platform/qcom/camss-8x16/camss-csiphy.c 
b/drivers/media/platform/qcom/camss-8x16/camss-csiphy.c
new file mode 100644
index 000..ed03775
--- /dev/null
+++ b/drivers/media/platform/qcom/camss-8x16/camss-csiphy.c
@@ -0,0 +1,823 @@
+/*
+ * camss-csiphy.c
+ *
+ * Qualcomm MSM Camera Subsystem - CSIPHY Module
+ *
+ * Copyright (c) 2011-2015, The Linux Foundation. All rights reserved.
+ * Copyright (C) 2016-2017 Linaro Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only 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 
+#include 
+
+#include "camss-csiphy.h"
+#include "camss.h"
+
+#define MSM_CSIPHY_NAME "msm_csiphy"
+
+#define CAMSS_CSI_PHY_LNn_CFG2(n)  (0x004 + 0x40 * (n))
+#define CAMSS_CSI_PHY_LNn_CFG3(n)  (0x008 + 0x40 * (n))
+#define CAMSS_CSI_PHY_GLBL_RESET   0x140
+#define CAMSS_CSI_PHY_GLBL_PWR_CFG 0x144
+#define CAMSS_CSI_PHY_GLBL_IRQ_CMD 0x164
+#define CAMSS_CSI_PHY_HW_VERSION   0x188
+#define CAMSS_CSI_PHY_INTERRUPT_STATUSn(n) (0x18c + 0x4 * (n))
+#define CAMSS_CSI_PHY_INTERRUPT_MASKn(n)   (0x1ac + 0x4 * (n))
+#define CAMSS_CSI_PHY_INTERRUPT_CLEARn(n)  (0x1cc + 0x4 * (n))
+#define CAMSS_CSI_PHY_GLBL_T_INIT_CFG0 0x1ec
+#define CAMSS_CSI_PHY_T_WAKEUP_CFG00x1f4
+
+static const struct {
+   u32 code;
+   u8 bpp;
+} csiphy_formats[] = {
+   {
+   MEDIA_BUS_FMT_UYVY8_2X8,
+   8,
+   },
+   {
+   MEDIA_BUS_FMT_VYUY8_2X8,
+   8,
+   },
+   {
+   MEDIA_BUS_FMT_YUYV8_2X8,
+   8,
+   },
+   {
+   MEDIA_BUS_FMT_YVYU8_2X8,
+   8,
+   },
+   {
+   MEDIA_BUS_FMT_SBGGR8_1X8,
+   8,
+   },
+   {
+   MEDIA_BUS_FMT_SGBRG8_1X8,
+   8,
+   },
+   {
+   MEDIA_BUS_FMT_SGRBG8_1X8,
+   8,
+   },
+   {
+   MEDIA_BUS_FMT_SRGGB8_1X8,
+   8,
+   },
+   {
+   MEDIA_BUS_FMT_SBGGR10_1X10,
+   10,
+   },
+   {
+   MEDIA_BUS_FMT_SGBRG10_1X10,
+   10,
+   },
+   {
+   MEDIA_BUS_FMT_SGRBG10_1X10,
+   10,
+   },
+   {
+   MEDIA_BUS_FMT_SRGGB10_1X10,
+   10,
+   },
+   {
+   MEDIA_BUS_FMT_SBGGR12_1X12,
+   12,
+   },
+   {
+   MEDIA_BUS_FMT_SGBRG12_1X12,
+   12,
+   },
+   {
+   MEDIA_BUS_FMT_SGRBG12_1X12,
+   12,
+   },
+   {
+   MEDIA_BUS_FMT_SRGGB12_1X12,
+   12,
+   }
+};
+
+/*
+ * csiphy_get_bpp - map media bus format to bits per pixel
+ * @code: media bus format code
+ *
+ * Return number of bits per pixel
+ */
+static u8 csiphy_get_bpp(u32 code)
+{
+   unsigned int i;
+
+   for (i = 0; i < ARRAY_SIZE(csiphy_formats); i++)
+   if (code == csiphy_formats[i].code)
+   return csiphy_formats[i].bpp;
+
+   WARN(1, "Unknown format\n");
+
+   return csiphy_formats[0].bpp;
+}
+
+/*
+ * csiphy_isr - CSIPHY module interrupt handler
+ * @irq: Interrupt line
+ * @dev: CSIPHY device
+ *
+ * Return IRQ_HANDLED on success
+ */
+static irqreturn_t csiphy_isr(int irq, void *dev)
+{
+   struct csiphy_device *csiphy = dev;
+   u8 i;
+
+   for (i = 0; i < 8; i++) {
+   u8 val = readl_relaxed(csiphy->base +
+  CAMSS_CSI_PHY_INTERRUPT_STATUSn(i));
+   writel_relaxed(val, csiphy->base +
+  CAMSS_CSI_PHY_INTERRUPT_CLEARn(i));
+   writel_relaxed(0x1, csiphy->base + CAMSS_CSI_PHY_GLBL_IRQ_CMD);
+   writel_relaxed(0x0, csiphy->base + CAMSS_CSI_PHY_GLBL_IRQ_CMD);
+   writel_relaxed(0x0, csiphy->base +
+ 

[PATCH v4 06/21] media: camss: Add CSID files

2017-08-08 Thread Todor Tomov
These files control the CSID modules which handle the protocol and
application layer of the CSI2 receivers.

Signed-off-by: Todor Tomov <todor.to...@linaro.org>
---
 .../media/platform/qcom/camss-8x16/camss-csid.c| 1003 
 .../media/platform/qcom/camss-8x16/camss-csid.h|   82 ++
 2 files changed, 1085 insertions(+)
 create mode 100644 drivers/media/platform/qcom/camss-8x16/camss-csid.c
 create mode 100644 drivers/media/platform/qcom/camss-8x16/camss-csid.h

diff --git a/drivers/media/platform/qcom/camss-8x16/camss-csid.c 
b/drivers/media/platform/qcom/camss-8x16/camss-csid.c
new file mode 100644
index 000..5c09e83
--- /dev/null
+++ b/drivers/media/platform/qcom/camss-8x16/camss-csid.c
@@ -0,0 +1,1003 @@
+/*
+ * camss-csid.c
+ *
+ * Qualcomm MSM Camera Subsystem - CSID Module
+ *
+ * Copyright (c) 2011-2015, The Linux Foundation. All rights reserved.
+ * Copyright (C) 2015-2017 Linaro Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only 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 
+#include 
+#include 
+
+#include "camss-csid.h"
+#include "camss.h"
+
+#define MSM_CSID_NAME "msm_csid"
+
+#define CAMSS_CSID_HW_VERSION  0x0
+#define CAMSS_CSID_CORE_CTRL_0 0x004
+#define CAMSS_CSID_CORE_CTRL_1 0x008
+#define CAMSS_CSID_RST_CMD 0x00c
+#define CAMSS_CSID_CID_LUT_VC_n(n) (0x010 + 0x4 * (n))
+#define CAMSS_CSID_CID_n_CFG(n)(0x020 + 0x4 * (n))
+#define CAMSS_CSID_IRQ_CLEAR_CMD   0x060
+#define CAMSS_CSID_IRQ_MASK0x064
+#define CAMSS_CSID_IRQ_STATUS  0x068
+#define CAMSS_CSID_TG_CTRL 0x0a0
+#define CAMSS_CSID_TG_CTRL_DISABLE 0xa06436
+#define CAMSS_CSID_TG_CTRL_ENABLE  0xa06437
+#define CAMSS_CSID_TG_VC_CFG   0x0a4
+#define CAMSS_CSID_TG_VC_CFG_H_BLANKING0x3ff
+#define CAMSS_CSID_TG_VC_CFG_V_BLANKING0x7f
+#define CAMSS_CSID_TG_DT_n_CGG_0(n)(0x0ac + 0xc * (n))
+#define CAMSS_CSID_TG_DT_n_CGG_1(n)(0x0b0 + 0xc * (n))
+#define CAMSS_CSID_TG_DT_n_CGG_2(n)(0x0b4 + 0xc * (n))
+
+#define DATA_TYPE_EMBEDDED_DATA_8BIT   0x12
+#define DATA_TYPE_YUV422_8BIT  0x1e
+#define DATA_TYPE_RAW_6BIT 0x28
+#define DATA_TYPE_RAW_8BIT 0x2a
+#define DATA_TYPE_RAW_10BIT0x2b
+#define DATA_TYPE_RAW_12BIT0x2c
+
+#define DECODE_FORMAT_UNCOMPRESSED_6_BIT   0x0
+#define DECODE_FORMAT_UNCOMPRESSED_8_BIT   0x1
+#define DECODE_FORMAT_UNCOMPRESSED_10_BIT  0x2
+#define DECODE_FORMAT_UNCOMPRESSED_12_BIT  0x3
+
+#define CSID_RESET_TIMEOUT_MS 500
+
+struct csid_fmts {
+   u32 code;
+   u8 data_type;
+   u8 decode_format;
+   u8 bpp;
+};
+
+static const struct csid_fmts csid_input_fmts[] = {
+   {
+   MEDIA_BUS_FMT_UYVY8_2X8,
+   DATA_TYPE_YUV422_8BIT,
+   DECODE_FORMAT_UNCOMPRESSED_8_BIT,
+   16,
+   },
+   {
+   MEDIA_BUS_FMT_VYUY8_2X8,
+   DATA_TYPE_YUV422_8BIT,
+   DECODE_FORMAT_UNCOMPRESSED_8_BIT,
+   16,
+   },
+   {
+   MEDIA_BUS_FMT_YUYV8_2X8,
+   DATA_TYPE_YUV422_8BIT,
+   DECODE_FORMAT_UNCOMPRESSED_8_BIT,
+   16,
+   },
+   {
+   MEDIA_BUS_FMT_YVYU8_2X8,
+   DATA_TYPE_YUV422_8BIT,
+   DECODE_FORMAT_UNCOMPRESSED_8_BIT,
+   16,
+   },
+   {
+   MEDIA_BUS_FMT_SBGGR8_1X8,
+   DATA_TYPE_RAW_8BIT,
+   DECODE_FORMAT_UNCOMPRESSED_8_BIT,
+   8,
+   },
+   {
+   MEDIA_BUS_FMT_SGBRG8_1X8,
+   DATA_TYPE_RAW_8BIT,
+   DECODE_FORMAT_UNCOMPRESSED_8_BIT,
+   8,
+   },
+   {
+   MEDIA_BUS_FMT_SGRBG8_1X8,
+   DATA_TYPE_RAW_8BIT,
+   DECODE_FORMAT_UNCOMPRESSED_8_BIT,
+   8,
+   },
+   {
+   MEDIA_BUS_FMT_SRGGB8_1X8,
+   DATA_TYPE_RAW_8BIT,
+   DECODE_FORMAT_UNCOMPRESSED_8_BIT,
+   8,
+   },
+   {
+   MEDIA_BUS_FMT_SBGGR10_1X10,
+   DATA_TYPE_RAW_10BIT,
+   DECODE_FORMAT_UNCOMPRESSED_10_BIT,
+   10,
+   },
+   {
+   MEDIA_BUS_FMT_SGBRG10_1X10,
+   DATA_TYPE_RAW_10BIT,
+   DECODE_FORMAT_UNCOMPRESSED_10_BIT,
+   10,
+   },
+   {
+ 

[PATCH v4 01/21] v4l: Add packed Bayer raw12 pixel formats

2017-08-08 Thread Todor Tomov
From: Sakari Ailus 

These formats are compressed 12-bit raw bayer formats with four different
pixel orders. They are similar to 10-bit variants. The formats added by
this patch are

V4L2_PIX_FMT_SBGGR12P
V4L2_PIX_FMT_SGBRG12P
V4L2_PIX_FMT_SGRBG12P
V4L2_PIX_FMT_SRGGB12P

Signed-off-by: Sakari Ailus 
Acked-by: Hans Verkuil 
---
 Documentation/media/uapi/v4l/pixfmt-rgb.rst  |   1 +
 Documentation/media/uapi/v4l/pixfmt-srggb12p.rst | 104 +++
 drivers/media/v4l2-core/v4l2-ioctl.c |  12 ++-
 include/uapi/linux/videodev2.h   |   5 ++
 4 files changed, 118 insertions(+), 4 deletions(-)
 create mode 100644 Documentation/media/uapi/v4l/pixfmt-srggb12p.rst

diff --git a/Documentation/media/uapi/v4l/pixfmt-rgb.rst 
b/Documentation/media/uapi/v4l/pixfmt-rgb.rst
index b0f3513..4cc2719 100644
--- a/Documentation/media/uapi/v4l/pixfmt-rgb.rst
+++ b/Documentation/media/uapi/v4l/pixfmt-rgb.rst
@@ -17,4 +17,5 @@ RGB Formats
 pixfmt-srggb10alaw8
 pixfmt-srggb10dpcm8
 pixfmt-srggb12
+pixfmt-srggb12p
 pixfmt-srggb16
diff --git a/Documentation/media/uapi/v4l/pixfmt-srggb12p.rst 
b/Documentation/media/uapi/v4l/pixfmt-srggb12p.rst
new file mode 100644
index 000..c3c19f9e
--- /dev/null
+++ b/Documentation/media/uapi/v4l/pixfmt-srggb12p.rst
@@ -0,0 +1,104 @@
+.. -*- coding: utf-8; mode: rst -*-
+
+.. _V4L2-PIX-FMT-SRGGB12P:
+.. _v4l2-pix-fmt-sbggr12p:
+.. _v4l2-pix-fmt-sgbrg12p:
+.. _v4l2-pix-fmt-sgrbg12p:
+
+***
+V4L2_PIX_FMT_SRGGB12P ('pRAA'), V4L2_PIX_FMT_SGRBG12P ('pgAA'), 
V4L2_PIX_FMT_SGBRG12P ('pGAA'), V4L2_PIX_FMT_SBGGR12P ('pBAA'),
+***
+
+
+12-bit packed Bayer formats
+
+
+Description
+===
+
+These four pixel formats are packed raw sRGB / Bayer formats with 12
+bits per colour. Every two consecutive samples are packed into three
+bytes. Each of the first two bytes contain the 8 high order bits of
+the pixels, and the third byte contains the four least significants
+bits of each pixel, in the same order.
+
+Each n-pixel row contains n/2 green samples and n/2 blue or red
+samples, with alternating green-red and green-blue rows. They are
+conventionally described as GRGR... BGBG..., RGRG... GBGB..., etc.
+Below is an example of a small V4L2_PIX_FMT_SBGGR12P image:
+
+**Byte Order.**
+Each cell is one byte.
+
+
+
+.. flat-table::
+:header-rows:  0
+:stub-columns: 0
+:widths:   2 1 1 1 1 1 1
+
+
+-  .. row 1
+
+   -  start + 0:
+
+   -  B\ :sub:`00high`
+
+   -  G\ :sub:`01high`
+
+   -  G\ :sub:`01low`\ (bits 7--4) B\ :sub:`00low`\ (bits 3--0)
+
+   -  B\ :sub:`02high`
+
+   -  G\ :sub:`03high`
+
+   -  G\ :sub:`03low`\ (bits 7--4) B\ :sub:`02low`\ (bits 3--0)
+
+-  .. row 2
+
+   -  start + 6:
+
+   -  G\ :sub:`10high`
+
+   -  R\ :sub:`11high`
+
+   -  R\ :sub:`11low`\ (bits 7--4) G\ :sub:`10low`\ (bits 3--0)
+
+   -  G\ :sub:`12high`
+
+   -  R\ :sub:`13high`
+
+   -  R\ :sub:`13low`\ (bits 3--2) G\ :sub:`12low`\ (bits 3--0)
+
+-  .. row 3
+
+   -  start + 12:
+
+   -  B\ :sub:`20high`
+
+   -  G\ :sub:`21high`
+
+   -  G\ :sub:`21low`\ (bits 7--4) B\ :sub:`20low`\ (bits 3--0)
+
+   -  B\ :sub:`22high`
+
+   -  G\ :sub:`23high`
+
+   -  G\ :sub:`23low`\ (bits 7--4) B\ :sub:`22low`\ (bits 3--0)
+
+-  .. row 4
+
+   -  start + 18:
+
+   -  G\ :sub:`30high`
+
+   -  R\ :sub:`31high`
+
+   -  R\ :sub:`31low`\ (bits 7--4) G\ :sub:`30low`\ (bits 3--0)
+
+   -  G\ :sub:`32high`
+
+   -  R\ :sub:`33high`
+
+   -  R\ :sub:`33low`\ (bits 3--2) G\ :sub:`32low`\ (bits 3--0)
+
diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c 
b/drivers/media/v4l2-core/v4l2-ioctl.c
index cab63bb..b60a6b0 100644
--- a/drivers/media/v4l2-core/v4l2-ioctl.c
+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
@@ -1195,10 +1195,6 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)
case V4L2_PIX_FMT_SGBRG10:  descr = "10-bit Bayer GBGB/RGRG"; break;
case V4L2_PIX_FMT_SGRBG10:  descr = "10-bit Bayer GRGR/BGBG"; break;
case V4L2_PIX_FMT_SRGGB10:  descr = "10-bit Bayer RGRG/GBGB"; break;
-   case V4L2_PIX_FMT_SBGGR12:  descr = "12-bit Bayer BGBG/GRGR"; break;
-   case V4L2_PIX_FMT_SGBRG12:  descr = "12-bit Bayer GBGB/RGRG"; break;
-   case V4L2_PIX_FMT_SGRBG12:  descr = "12-bit Bayer GRGR/BGBG"; break;
-   case V4L2_PIX_FMT_SRGGB12:  descr = "12-bit Bayer RGRG/GBGB"; break;
case V4L2_PIX_FMT_SBGGR10P: descr = "10-bit Bayer BGBG/GRGR 
Packed"; break;
case V4L2_PIX_FMT_SGBRG10P: descr = "10-bit 

[PATCH v4 02/21] dt-bindings: media: Binding document for Qualcomm Camera subsystem driver

2017-08-08 Thread Todor Tomov
Add DT binding document for Qualcomm Camera subsystem driver.

CC: Rob Herring <robh...@kernel.org>
CC: devicet...@vger.kernel.org
Signed-off-by: Todor Tomov <todor.to...@linaro.org>
Acked-by: Rob Herring <r...@kernel.org>
---
 .../devicetree/bindings/media/qcom,camss.txt   | 197 +
 1 file changed, 197 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/qcom,camss.txt

diff --git a/Documentation/devicetree/bindings/media/qcom,camss.txt 
b/Documentation/devicetree/bindings/media/qcom,camss.txt
new file mode 100644
index 000..cadeceb
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/qcom,camss.txt
@@ -0,0 +1,197 @@
+Qualcomm Camera Subsystem
+
+* Properties
+
+- compatible:
+   Usage: required
+   Value type: 
+   Definition: Should contain:
+   - "qcom,msm8916-camss"
+- reg:
+   Usage: required
+   Value type: 
+   Definition: Register ranges as listed in the reg-names property.
+- reg-names:
+   Usage: required
+   Value type: 
+   Definition: Should contain the following entries:
+   - "csiphy0"
+   - "csiphy0_clk_mux"
+   - "csiphy1"
+   - "csiphy1_clk_mux"
+   - "csid0"
+   - "csid1"
+   - "ispif"
+   - "csi_clk_mux"
+   - "vfe0"
+- interrupts:
+   Usage: required
+   Value type: 
+   Definition: Interrupts as listed in the interrupt-names property.
+- interrupt-names:
+   Usage: required
+   Value type: 
+   Definition: Should contain the following entries:
+   - "csiphy0"
+   - "csiphy1"
+   - "csid0"
+   - "csid1"
+   - "ispif"
+   - "vfe0"
+- power-domains:
+   Usage: required
+   Value type: 
+   Definition: A phandle and power domain specifier pairs to the
+   power domain which is responsible for collapsing
+   and restoring power to the peripheral.
+- clocks:
+   Usage: required
+   Value type: 
+   Definition: A list of phandle and clock specifier pairs as listed
+   in clock-names property.
+- clock-names:
+   Usage: required
+   Value type: 
+   Definition: Should contain the following entries:
+- "camss_top_ahb"
+- "ispif_ahb"
+- "csiphy0_timer"
+- "csiphy1_timer"
+- "csi0_ahb"
+- "csi0"
+- "csi0_phy"
+- "csi0_pix"
+- "csi0_rdi"
+- "csi1_ahb"
+- "csi1"
+- "csi1_phy"
+- "csi1_pix"
+- "csi1_rdi"
+- "camss_ahb"
+- "camss_vfe_vfe"
+- "camss_csi_vfe"
+- "iface"
+- "bus"
+- vdda-supply:
+   Usage: required
+   Value type: 
+   Definition: A phandle to voltage supply for CSI2.
+- iommus:
+   Usage: required
+   Value type: 
+   Definition: A list of phandle and IOMMU specifier pairs.
+
+* Nodes
+
+- ports:
+   Usage: required
+   Definition: As described in video-interfaces.txt in same directory.
+   Properties:
+   - reg:
+   Usage: required
+   Value type: 
+   Definition: Selects CSI2 PHY interface - PHY0 or PHY1.
+   Endpoint node properties:
+   - clock-lanes:
+   Usage: required
+   Value type: 
+Definition: The physical clock lane index. The value
+must always be <1> as the physical clock
+lane is lane 1.
+   - data-lanes:
+   Usage: required
+   Value type: 
+Definition: An array of physical data lanes indexes.
+Position of an entry determines the logical
+lane number, while the value of an entry
+indicates physical lane index. Lane 
swapping
+is supported.
+
+* An Example
+
+   camss: camss@1b0 {
+   compatible = "qcom,msm8916-camss";
+   reg = <0x1b0ac00 0x200>,
+   <0x1b00030 0x4>,
+   <0x1b0b000 0x200>,
+   <0x1b00038 0x4>

[PATCH v4 08/21] media: camss: Add VFE files

2017-08-08 Thread Todor Tomov
These files control the VFE module. The VFE has different input
interfaces. The PIX input interface feeds the input data to an image
processing pipeline. Three RDI input interfaces bypass the image
processing pipeline. The VFE also contains the AXI bus interface which
writes the output data to memory.

RDI interfaces are supported in this version. PIX interface is not
supported.

Signed-off-by: Todor Tomov <todor.to...@linaro.org>
---
 drivers/media/platform/qcom/camss-8x16/camss-vfe.c | 1906 
 drivers/media/platform/qcom/camss-8x16/camss-vfe.h |  114 ++
 2 files changed, 2020 insertions(+)
 create mode 100644 drivers/media/platform/qcom/camss-8x16/camss-vfe.c
 create mode 100644 drivers/media/platform/qcom/camss-8x16/camss-vfe.h

diff --git a/drivers/media/platform/qcom/camss-8x16/camss-vfe.c 
b/drivers/media/platform/qcom/camss-8x16/camss-vfe.c
new file mode 100644
index 000..fe6b8ab
--- /dev/null
+++ b/drivers/media/platform/qcom/camss-8x16/camss-vfe.c
@@ -0,0 +1,1906 @@
+/*
+ * camss-vfe.c
+ *
+ * Qualcomm MSM Camera Subsystem - VFE Module
+ *
+ * Copyright (c) 2013-2015, The Linux Foundation. All rights reserved.
+ * Copyright (C) 2015-2017 Linaro Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only 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 
+#include 
+#include 
+#include 
+#include 
+
+#include "camss-vfe.h"
+#include "camss.h"
+
+#define MSM_VFE_NAME "msm_vfe"
+
+#define vfe_line_array(ptr_line)   \
+   ((const struct vfe_line (*)[]) &(ptr_line[-(ptr_line->id)]))
+
+#define to_vfe(ptr_line)   \
+   container_of(vfe_line_array(ptr_line), struct vfe_device, ptr_line)
+
+#define VFE_0_HW_VERSION   0x000
+
+#define VFE_0_GLOBAL_RESET_CMD 0x00c
+#define VFE_0_GLOBAL_RESET_CMD_CORE(1 << 0)
+#define VFE_0_GLOBAL_RESET_CMD_CAMIF   (1 << 1)
+#define VFE_0_GLOBAL_RESET_CMD_BUS (1 << 2)
+#define VFE_0_GLOBAL_RESET_CMD_BUS_BDG (1 << 3)
+#define VFE_0_GLOBAL_RESET_CMD_REGISTER(1 << 4)
+#define VFE_0_GLOBAL_RESET_CMD_TIMER   (1 << 5)
+#define VFE_0_GLOBAL_RESET_CMD_PM  (1 << 6)
+#define VFE_0_GLOBAL_RESET_CMD_BUS_MISR(1 << 7)
+#define VFE_0_GLOBAL_RESET_CMD_TESTGEN (1 << 8)
+
+#define VFE_0_IRQ_CMD  0x024
+#define VFE_0_IRQ_CMD_GLOBAL_CLEAR (1 << 0)
+
+#define VFE_0_IRQ_MASK_0   0x028
+#define VFE_0_IRQ_MASK_0_RDIn_REG_UPDATE(n)(1 << ((n) + 5))
+#define VFE_0_IRQ_MASK_0_IMAGE_MASTER_n_PING_PONG(n)   (1 << ((n) + 8))
+#define VFE_0_IRQ_MASK_0_RESET_ACK (1 << 31)
+#define VFE_0_IRQ_MASK_1   0x02c
+#define VFE_0_IRQ_MASK_1_VIOLATION (1 << 7)
+#define VFE_0_IRQ_MASK_1_BUS_BDG_HALT_ACK  (1 << 8)
+#define VFE_0_IRQ_MASK_1_IMAGE_MASTER_n_BUS_OVERFLOW(n)(1 << ((n) + 9))
+
+#define VFE_0_IRQ_CLEAR_0  0x030
+#define VFE_0_IRQ_CLEAR_1  0x034
+
+#define VFE_0_IRQ_STATUS_0 0x038
+#define VFE_0_IRQ_STATUS_0_RDIn_REG_UPDATE(n)  (1 << ((n) + 5))
+#define VFE_0_IRQ_STATUS_0_IMAGE_MASTER_n_PING_PONG(n) (1 << ((n) + 8))
+#define VFE_0_IRQ_STATUS_0_RESET_ACK   (1 << 31)
+#define VFE_0_IRQ_STATUS_1 0x03c
+#define VFE_0_IRQ_STATUS_1_VIOLATION   (1 << 7)
+#define VFE_0_IRQ_STATUS_1_BUS_BDG_HALT_ACK(1 << 8)
+
+#define VFE_0_VIOLATION_STATUS 0x48
+
+#define VFE_0_BUS_CMD  0x4c
+#define VFE_0_BUS_CMD_Mx_RLD_CMD(x)(1 << (x))
+
+#define VFE_0_BUS_CFG  0x050
+
+#define VFE_0_BUS_XBAR_CFG_x(x)(0x58 + 0x4 * ((x) / 2))
+#define VFE_0_BUS_XBAR_CFG_x_M_SINGLE_STREAM_SEL_SHIFT 8
+#define VFE_0_BUS_XBAR_CFG_x_M_SINGLE_STREAM_SEL_VAL_RDI0  5
+#define VFE_0_BUS_XBAR_CFG_x_M_SINGLE_STREAM_SEL_VAL_RDI1  6
+#define VFE_0_BUS_XBAR_CFG_x_M_SINGLE_STREAM_SEL_VAL_RDI2  7
+
+#define VFE_0_BUS_IMAGE_MASTER_n_WR_CFG(n) (0x06c + 0x24 * (n))
+#define VFE_0_BUS_IMAGE_MASTER_n_WR_CFG_WR_PATH_SHIFT  0
+#define VFE_0_BUS_IMAGE_MASTER_n_WR_CFG_FRM_BASED_SHIFT1
+#define VFE_0_BUS_IMAGE_MASTER_n_WR_PING_ADDR(n)   (0x070 + 0x24 * (n))
+#define VFE_0_BUS_IMAGE_MASTER_n_WR_PONG_ADDR(n)   (0x074 + 0x24 * (n))
+#define VFE_0_BUS_IMAGE_MASTER_n_WR_ADDR_CFG(n)(0x078 + 0x24 * 
(n))
+#define VFE_0_BUS_IMAGE_MASTER_n_WR_AD

[PATCH v4 10/21] media: camms: Add core files

2017-08-08 Thread Todor Tomov
These files implement the platform driver code.

Signed-off-by: Todor Tomov <todor.to...@linaro.org>
---
 drivers/media/platform/qcom/camss-8x16/camss.c | 699 +
 drivers/media/platform/qcom/camss-8x16/camss.h |  97 
 2 files changed, 796 insertions(+)
 create mode 100644 drivers/media/platform/qcom/camss-8x16/camss.c
 create mode 100644 drivers/media/platform/qcom/camss-8x16/camss.h

diff --git a/drivers/media/platform/qcom/camss-8x16/camss.c 
b/drivers/media/platform/qcom/camss-8x16/camss.c
new file mode 100644
index 000..2dee77a
--- /dev/null
+++ b/drivers/media/platform/qcom/camss-8x16/camss.c
@@ -0,0 +1,699 @@
+/*
+ * camss.c
+ *
+ * Qualcomm MSM Camera Subsystem - Core
+ *
+ * Copyright (c) 2015, The Linux Foundation. All rights reserved.
+ * Copyright (C) 2015-2017 Linaro Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only 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 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "camss.h"
+
+static const struct resources csiphy_res[] = {
+   /* CSIPHY0 */
+   {
+   .regulator = { NULL },
+   .clock = { "camss_top_ahb", "ispif_ahb",
+  "camss_ahb", "csiphy0_timer" },
+   .clock_rate = { 0, 0, 0, 2 },
+   .reg = { "csiphy0", "csiphy0_clk_mux" },
+   .interrupt = { "csiphy0" }
+   },
+
+   /* CSIPHY1 */
+   {
+   .regulator = { NULL },
+   .clock = { "camss_top_ahb", "ispif_ahb",
+  "camss_ahb", "csiphy1_timer" },
+   .clock_rate = { 0, 0, 0, 2 },
+   .reg = { "csiphy1", "csiphy1_clk_mux" },
+   .interrupt = { "csiphy1" }
+   }
+};
+
+static const struct resources csid_res[] = {
+   /* CSID0 */
+   {
+   .regulator = { "vdda" },
+   .clock = { "camss_top_ahb", "ispif_ahb",
+  "csi0_ahb", "camss_ahb",
+  "csi0", "csi0_phy", "csi0_pix", "csi0_rdi" },
+   .clock_rate = { 0, 0, 0, 0, 2, 0, 0, 0 },
+   .reg = { "csid0" },
+   .interrupt = { "csid0" }
+   },
+
+   /* CSID1 */
+   {
+   .regulator = { "vdda" },
+   .clock = { "camss_top_ahb", "ispif_ahb",
+  "csi1_ahb", "camss_ahb",
+  "csi1", "csi1_phy", "csi1_pix", "csi1_rdi" },
+   .clock_rate = { 0, 0, 0, 0, 2, 0, 0, 0 },
+   .reg = { "csid1" },
+   .interrupt = { "csid1" }
+   },
+};
+
+static const struct resources_ispif ispif_res = {
+   /* ISPIF */
+   .clock = { "camss_top_ahb", "camss_ahb", "ispif_ahb",
+  "csi0", "csi0_pix", "csi0_rdi",
+  "csi1", "csi1_pix", "csi1_rdi" },
+   .clock_for_reset = { "camss_vfe_vfe", "camss_csi_vfe" },
+   .reg = { "ispif", "csi_clk_mux" },
+   .interrupt = "ispif"
+
+};
+
+static const struct resources vfe_res = {
+   /* VFE0 */
+   .regulator = { NULL },
+   .clock = { "camss_top_ahb", "camss_vfe_vfe", "camss_csi_vfe",
+  "iface", "bus", "camss_ahb" },
+   .clock_rate = { 0, 32000, 0, 0, 0, 0, 0, 0 },
+   .reg = { "vfe0" },
+   .interrupt = { "vfe0" }
+};
+
+/*
+ * camss_enable_clocks - Enable multiple clocks
+ * @nclocks: Number of clocks in clock array
+ * @clock: Clock array
+ * @dev: Device
+ *
+ * Return 0 on success or a negative error code otherwise
+ */
+int camss_enable_clocks(int nclocks, struct clk **clock, struct device *dev)
+{
+   int ret;
+   int i;
+
+   for (i = 0; i < nclocks; i++) {
+   ret = clk_prepare_enable(clock[i]);
+   if (ret) {
+   dev_err(dev, "clock enable failed: %d\n", ret);
+   goto error;
+   

[PATCH v4 09/21] media: camss: Add files which handle the video device nodes

2017-08-08 Thread Todor Tomov
These files handle the video device nodes of the camss driver.

Signed-off-by: Todor Tomov <todor.to...@linaro.org>
---
 .../media/platform/qcom/camss-8x16/camss-video.c   | 681 +
 .../media/platform/qcom/camss-8x16/camss-video.h   |  64 ++
 2 files changed, 745 insertions(+)
 create mode 100644 drivers/media/platform/qcom/camss-8x16/camss-video.c
 create mode 100644 drivers/media/platform/qcom/camss-8x16/camss-video.h

diff --git a/drivers/media/platform/qcom/camss-8x16/camss-video.c 
b/drivers/media/platform/qcom/camss-8x16/camss-video.c
new file mode 100644
index 000..2e3f012
--- /dev/null
+++ b/drivers/media/platform/qcom/camss-8x16/camss-video.c
@@ -0,0 +1,681 @@
+/*
+ * camss-video.c
+ *
+ * Qualcomm MSM Camera Subsystem - V4L2 device node
+ *
+ * Copyright (c) 2013-2015, The Linux Foundation. All rights reserved.
+ * Copyright (C) 2015-2017 Linaro Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only 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 
+
+#include "camss-video.h"
+#include "camss.h"
+
+/*
+ * struct camss_format_info - ISP media bus format information
+ * @code: V4L2 media bus format code
+ * @pixelformat: V4L2 pixel format FCC identifier
+ * @bpp: Bits per pixel when stored in memory
+ */
+static const struct camss_format_info {
+   u32 code;
+   u32 pixelformat;
+   unsigned int bpp;
+} formats[] = {
+   { MEDIA_BUS_FMT_UYVY8_2X8, V4L2_PIX_FMT_UYVY, 16 },
+   { MEDIA_BUS_FMT_VYUY8_2X8, V4L2_PIX_FMT_VYUY, 16 },
+   { MEDIA_BUS_FMT_YUYV8_2X8, V4L2_PIX_FMT_YUYV, 16 },
+   { MEDIA_BUS_FMT_YVYU8_2X8, V4L2_PIX_FMT_YVYU, 16 },
+   { MEDIA_BUS_FMT_SBGGR8_1X8, V4L2_PIX_FMT_SBGGR8, 8 },
+   { MEDIA_BUS_FMT_SGBRG8_1X8, V4L2_PIX_FMT_SGBRG8, 8 },
+   { MEDIA_BUS_FMT_SGRBG8_1X8, V4L2_PIX_FMT_SGRBG8, 8 },
+   { MEDIA_BUS_FMT_SRGGB8_1X8, V4L2_PIX_FMT_SRGGB8, 8 },
+   { MEDIA_BUS_FMT_SBGGR10_1X10, V4L2_PIX_FMT_SBGGR10P, 10 },
+   { MEDIA_BUS_FMT_SGBRG10_1X10, V4L2_PIX_FMT_SGBRG10P, 10 },
+   { MEDIA_BUS_FMT_SGRBG10_1X10, V4L2_PIX_FMT_SGRBG10P, 10 },
+   { MEDIA_BUS_FMT_SRGGB10_1X10, V4L2_PIX_FMT_SRGGB10P, 10 },
+   { MEDIA_BUS_FMT_SBGGR12_1X12, V4L2_PIX_FMT_SBGGR12P, 12 },
+   { MEDIA_BUS_FMT_SGBRG12_1X12, V4L2_PIX_FMT_SGBRG12P, 12 },
+   { MEDIA_BUS_FMT_SGRBG12_1X12, V4L2_PIX_FMT_SGRBG12P, 12 },
+   { MEDIA_BUS_FMT_SRGGB12_1X12, V4L2_PIX_FMT_SRGGB12P, 12 }
+};
+
+/* 
-
+ * Helper functions
+ */
+
+/*
+ * video_mbus_to_pix_mp - Convert v4l2_mbus_framefmt to v4l2_pix_format_mplane
+ * @mbus: v4l2_mbus_framefmt format (input)
+ * @pix: v4l2_pix_format_mplane format (output)
+ *
+ * Fill the output pix structure with information from the input mbus format.
+ *
+ * Return 0 on success or a negative error code otherwise
+ */
+static unsigned int video_mbus_to_pix_mp(const struct v4l2_mbus_framefmt *mbus,
+struct v4l2_pix_format_mplane *pix)
+{
+   unsigned int i;
+   u32 bytesperline;
+
+   memset(pix, 0, sizeof(*pix));
+   v4l2_fill_pix_format_mplane(pix, mbus);
+
+   for (i = 0; i < ARRAY_SIZE(formats); ++i) {
+   if (formats[i].code == mbus->code)
+   break;
+   }
+
+   if (WARN_ON(i == ARRAY_SIZE(formats)))
+   return -EINVAL;
+
+   pix->pixelformat = formats[i].pixelformat;
+   pix->num_planes = 1;
+   bytesperline = pix->width * formats[i].bpp / 8;
+   bytesperline = ALIGN(bytesperline, 8);
+   pix->plane_fmt[0].bytesperline = bytesperline;
+   pix->plane_fmt[0].sizeimage = bytesperline * pix->height;
+
+   return 0;
+}
+
+static struct v4l2_subdev *video_remote_subdev(struct camss_video *video,
+  u32 *pad)
+{
+   struct media_pad *remote;
+
+   remote = media_entity_remote_pad(>pad);
+
+   if (!remote || !is_media_entity_v4l2_subdev(remote->entity))
+   return NULL;
+
+   if (pad)
+   *pad = remote->index;
+
+   return media_entity_to_v4l2_subdev(remote->entity);
+}
+
+static int video_get_subdev_format(struct camss_video *video,
+  struct v4l2_format *format)
+{
+   struct v4l2_subdev_format fmt;
+   struct v4l2_subdev *subdev;
+   u32 pad;
+   int ret;
+
+   subdev = video_remote_subdev(video, );
+   if (subdev =

[PATCH v4 13/21] doc: media/v4l-drivers: Qualcomm Camera Subsystem - PIX Interface

2017-08-08 Thread Todor Tomov
Update Qualcomm Camera Subsystem driver document for the PIX interface
and format conversion support.

Signed-off-by: Todor Tomov <todor.to...@linaro.org>
---
 Documentation/media/v4l-drivers/qcom_camss.rst | 46 --
 1 file changed, 36 insertions(+), 10 deletions(-)

diff --git a/Documentation/media/v4l-drivers/qcom_camss.rst 
b/Documentation/media/v4l-drivers/qcom_camss.rst
index 4707ea7..d888443 100644
--- a/Documentation/media/v4l-drivers/qcom_camss.rst
+++ b/Documentation/media/v4l-drivers/qcom_camss.rst
@@ -45,12 +45,36 @@ Supported functionality
 
 The current version of the driver supports:
 
-- input from camera sensor via CSIPHY;
-- generation of test input data by the TG in CSID;
-- raw dump of the input data to memory. RDI interface of VFE is supported.
-  PIX interface (ISP processing, statistics engines, resize/crop, format
-  conversion) is not supported in the current version;
-- concurrent and independent usage of two data inputs - could be camera sensors
+- Input from camera sensor via CSIPHY;
+- Generation of test input data by the TG in CSID;
+- RDI interface of VFE - raw dump of the input data to memory.
+
+  Supported formats:
+
+  - YUYV/UYVY/YVYU/VYUY (packed YUV 4:2:2 - V4L2_PIX_FMT_YUYV /
+V4L2_PIX_FMT_UYVY / V4L2_PIX_FMT_YVYU / V4L2_PIX_FMT_VYUY);
+  - MIPI RAW8 (8bit Bayer RAW - V4L2_PIX_FMT_SRGGB8 /
+V4L2_PIX_FMT_SGRBG8 / V4L2_PIX_FMT_SGBRG8 / V4L2_PIX_FMT_SBGGR8);
+  - MIPI RAW10 (10bit packed Bayer RAW - V4L2_PIX_FMT_SBGGR10P /
+V4L2_PIX_FMT_SGBRG10P / V4L2_PIX_FMT_SGRBG10P / V4L2_PIX_FMT_SRGGB10P);
+  - MIPI RAW12 (12bit packed Bayer RAW - V4L2_PIX_FMT_SRGGB12P /
+V4L2_PIX_FMT_SGBRG12P / V4L2_PIX_FMT_SGRBG12P / V4L2_PIX_FMT_SRGGB12P).
+
+- PIX interface of VFE
+
+  - Format conversion of the input data.
+
+Supported input formats:
+
+- YUYV/UYVY/YVYU/VYUY (packed YUV 4:2:2 - V4L2_PIX_FMT_YUYV /
+  V4L2_PIX_FMT_UYVY / V4L2_PIX_FMT_YVYU / V4L2_PIX_FMT_VYUY).
+
+Supported output formats:
+
+- NV12/NV21 (two plane YUV 4:2:0 - V4L2_PIX_FMT_NV12 / V4L2_PIX_FMT_NV21);
+- NV16/NV61 (two plane YUV 4:2:2 - V4L2_PIX_FMT_NV16 / V4L2_PIX_FMT_NV61).
+
+- Concurrent and independent usage of two data inputs - could be camera sensors
   and/or TG.
 
 
@@ -65,15 +89,15 @@ interface, the driver is split into V4L2 sub-devices as 
follows:
 - 2 CSID sub-devices - each CSID is represented by a single sub-device;
 - 2 ISPIF sub-devices - ISPIF is represented by a number of sub-devices equal
   to the number of CSID sub-devices;
-- 3 VFE sub-devices - VFE is represented by a number of sub-devices equal to
-  the number of RDI input interfaces.
+- 4 VFE sub-devices - VFE is represented by a number of sub-devices equal to
+  the number of the input interfaces (3 RDI and 1 PIX).
 
 The considerations to split the driver in this particular way are as follows:
 
 - representing CSIPHY and CSID modules by a separate sub-device for each module
   allows to model the hardware links between these modules;
-- representing VFE by a separate sub-devices for each RDI input interface 
allows
-  to use the three RDI interfaces concurently and independently as this is
+- representing VFE by a separate sub-devices for each input interface allows
+  to use the input interfaces concurently and independently as this is
   supported by the hardware;
 - representing ISPIF by a number of sub-devices equal to the number of CSID
   sub-devices allows to create linear media controller pipelines when using two
@@ -99,6 +123,8 @@ nodes) is as follows:
 - msm_vfe0_video1
 - msm_vfe0_rdi2
 - msm_vfe0_video2
+- msm_vfe0_pix
+- msm_vfe0_video3
 
 
 Implementation
-- 
2.7.4



[PATCH v4 12/21] camss: vfe: Format conversion support using PIX interface

2017-08-08 Thread Todor Tomov
Use VFE PIX input interface and do format conversion in VFE.

Supported input format is UYVY (single plane YUV 4:2:2) and
its different sample order variations.

Supported output formats are:
- NV12/NV21 (two plane YUV 4:2:0)
- NV16/NV61 (two plane YUV 4:2:2)

Signed-off-by: Todor Tomov <todor.to...@linaro.org>
---
 .../media/platform/qcom/camss-8x16/camss-ispif.c   |   2 +
 drivers/media/platform/qcom/camss-8x16/camss-vfe.c | 705 ++---
 drivers/media/platform/qcom/camss-8x16/camss-vfe.h |  13 +-
 .../media/platform/qcom/camss-8x16/camss-video.c   | 308 ++---
 .../media/platform/qcom/camss-8x16/camss-video.h   |   8 +-
 5 files changed, 879 insertions(+), 157 deletions(-)

diff --git a/drivers/media/platform/qcom/camss-8x16/camss-ispif.c 
b/drivers/media/platform/qcom/camss-8x16/camss-ispif.c
index b047811..31e00e5 100644
--- a/drivers/media/platform/qcom/camss-8x16/camss-ispif.c
+++ b/drivers/media/platform/qcom/camss-8x16/camss-ispif.c
@@ -1003,6 +1003,8 @@ static enum ispif_intf ispif_get_intf(enum vfe_line_id 
line_id)
return RDI1;
case (VFE_LINE_RDI2):
return RDI2;
+   case (VFE_LINE_PIX):
+   return PIX0;
default:
return RDI0;
}
diff --git a/drivers/media/platform/qcom/camss-8x16/camss-vfe.c 
b/drivers/media/platform/qcom/camss-8x16/camss-vfe.c
index fe6b8ab..44605e0 100644
--- a/drivers/media/platform/qcom/camss-8x16/camss-vfe.c
+++ b/drivers/media/platform/qcom/camss-8x16/camss-vfe.c
@@ -19,6 +19,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -52,29 +53,53 @@
 #define VFE_0_GLOBAL_RESET_CMD_BUS_MISR(1 << 7)
 #define VFE_0_GLOBAL_RESET_CMD_TESTGEN (1 << 8)
 
+#define VFE_0_MODULE_CFG   0x018
+#define VFE_0_MODULE_CFG_DEMUX (1 << 2)
+#define VFE_0_MODULE_CFG_CHROMA_UPSAMPLE   (1 << 3)
+#define VFE_0_MODULE_CFG_SCALE_ENC (1 << 23)
+
+#define VFE_0_CORE_CFG 0x01c
+#define VFE_0_CORE_CFG_PIXEL_PATTERN_YCBYCR0x4
+#define VFE_0_CORE_CFG_PIXEL_PATTERN_YCRYCB0x5
+#define VFE_0_CORE_CFG_PIXEL_PATTERN_CBYCRY0x6
+#define VFE_0_CORE_CFG_PIXEL_PATTERN_CRYCBY0x7
+
 #define VFE_0_IRQ_CMD  0x024
 #define VFE_0_IRQ_CMD_GLOBAL_CLEAR (1 << 0)
 
 #define VFE_0_IRQ_MASK_0   0x028
+#define VFE_0_IRQ_MASK_0_CAMIF_SOF (1 << 0)
+#define VFE_0_IRQ_MASK_0_CAMIF_EOF (1 << 1)
 #define VFE_0_IRQ_MASK_0_RDIn_REG_UPDATE(n)(1 << ((n) + 5))
+#define VFE_0_IRQ_MASK_0_line_n_REG_UPDATE(n)  \
+   ((n) == VFE_LINE_PIX ? (1 << 4) : VFE_0_IRQ_MASK_0_RDIn_REG_UPDATE(n))
 #define VFE_0_IRQ_MASK_0_IMAGE_MASTER_n_PING_PONG(n)   (1 << ((n) + 8))
+#define VFE_0_IRQ_MASK_0_IMAGE_COMPOSITE_DONE_n(n) (1 << ((n) + 25))
 #define VFE_0_IRQ_MASK_0_RESET_ACK (1 << 31)
 #define VFE_0_IRQ_MASK_1   0x02c
+#define VFE_0_IRQ_MASK_1_CAMIF_ERROR   (1 << 0)
 #define VFE_0_IRQ_MASK_1_VIOLATION (1 << 7)
 #define VFE_0_IRQ_MASK_1_BUS_BDG_HALT_ACK  (1 << 8)
 #define VFE_0_IRQ_MASK_1_IMAGE_MASTER_n_BUS_OVERFLOW(n)(1 << ((n) + 9))
+#define VFE_0_IRQ_MASK_1_RDIn_SOF(n)   (1 << ((n) + 29))
 
 #define VFE_0_IRQ_CLEAR_0  0x030
 #define VFE_0_IRQ_CLEAR_1  0x034
 
 #define VFE_0_IRQ_STATUS_0 0x038
+#define VFE_0_IRQ_STATUS_0_CAMIF_SOF   (1 << 0)
 #define VFE_0_IRQ_STATUS_0_RDIn_REG_UPDATE(n)  (1 << ((n) + 5))
+#define VFE_0_IRQ_STATUS_0_line_n_REG_UPDATE(n)\
+   ((n) == VFE_LINE_PIX ? (1 << 4) : VFE_0_IRQ_STATUS_0_RDIn_REG_UPDATE(n))
 #define VFE_0_IRQ_STATUS_0_IMAGE_MASTER_n_PING_PONG(n) (1 << ((n) + 8))
+#define VFE_0_IRQ_STATUS_0_IMAGE_COMPOSITE_DONE_n(n)   (1 << ((n) + 25))
 #define VFE_0_IRQ_STATUS_0_RESET_ACK   (1 << 31)
 #define VFE_0_IRQ_STATUS_1 0x03c
 #define VFE_0_IRQ_STATUS_1_VIOLATION   (1 << 7)
 #define VFE_0_IRQ_STATUS_1_BUS_BDG_HALT_ACK(1 << 8)
+#define VFE_0_IRQ_STATUS_1_RDIn_SOF(n) (1 << ((n) + 29))
 
+#define VFE_0_IRQ_COMPOSITE_MASK_0 0x40
 #define VFE_0_VIOLATION_STATUS 0x48
 
 #define VFE_0_BUS_CMD  0x4c
@@ -83,7 +108,10 @@
 #define VFE_0_BUS_CFG  0x050
 
 #define VFE_0_BUS_XBAR_CFG_x(x)(0x58 + 0x4 * ((x) / 2))
+#define VFE_0_BUS_XBAR_CFG_x_M_PAIR_STREAM_EN  (1 << 1)
+#define VFE_0_BUS_XBAR_CFG_x_M_PAIR_STREAM_SWAP_INTER_INTRA(0x3 << 4)
 #define VFE_0_BUS_XBAR_CFG_x_M_SINGLE_STREAM_SEL_SHIFT 8
+#define VFE_0_BUS_XBAR_CFG_x_M_SINGLE_STREAM_SEL_LUMA  0
 #define VFE_0_BUS_XBAR_CFG_x_M_SINGLE_STREAM_S

  1   2   3   >