Re: i.mx6 camera interface (CSI) and mainline kernel

2016-06-02 Thread Steve Longerbeam
On 06/02/2016 06:55 AM, Hans Verkuil wrote:
>
> On 06/02/2016 03:29 PM, Tim Harvey wrote:
>> On Wed, Mar 9, 2016 at 4:12 PM, Steve Longerbeam
>>  wrote:
>>> On 03/09/2016 02:44 PM, Tim Harvey wrote:
>>>> On Tue, Mar 8, 2016 at 6:06 PM, Steve Longerbeam
>>>>  wrote:
>>>>> On 03/07/2016 08:19 AM, Tim Harvey wrote:
>>>> 
>>>>> Hi Tim, good to hear it works for you on the Ventana boards.
>>>>>
>>>>> I've just pushed some more commits to the mx6-media-staging branch that
>>>>> get the drivers/media/i2c/adv7180.c subdev working with the imx6 capture
>>>>> backend. Images look perfect when switching to UYVY8_2X8 mbus code instead
>>>>> of YUYV8_2X8. But I'm holding off on that change because this subdev is 
>>>>> used
>>>>> by Renesas targets and would likely corrupt captured images for those
>>>>> targets. But I believe UYVY is the correct transmit order according to the
>>>>> BT.656 standard.
>>>>>
>>>>> Another thing that should also be changed in drivers/media/i2c/adv7180.c
>>>>> is the field type. It should be V4L2_FIELD_SEQ_TB for NTSC and 
>>>>> V4L2_FIELD_SEQ_BT
>>>>> for PAL.
>>>>>
>>>>> Steve
>>>>>
>>>>>
>>>> Steve,
>>>>
>>>> with your latest patches, I'm crashing with an null-pointer-deref in
>>>> adv7180_set_pad_format. What is your kernel config for
>>>> CONFIG_MEDIA_CONTROLLER and CONFIG_VIDEO_V4L2_SUBDEV_API?
>>> Right, I thought I fixed that, I was passing a NULL pad_cfg for
>>> TRY_FORMAT, but that was fixed. Maybe you fetched a version
>>> of mx6-media-staging while I was in the middle of debugging?
>>> Try fetching again.
>>>
>>> I tried with both CONFIG_MEDIA_CONTROLLER and
>>> CONFIG_VIDEO_V4L2_SUBDEV_API enabled and both disabled, and
>>> I don't get the null deref in adv7180_set_pad_format.
>>>
>>>
>>>> Your tree contains about 16 or so patches on top of linux-media for
>>>> imx6 capture. Are you close to the point where you will be posting a
>>>> patch series? If so, please CC me for testing with the adv7180 sensor.
>>> I guess I can try posting a series again, but there will likely be 
>>> push-back from
>>> Pengutronix. They have their own video capture driver for imx6. Last I 
>>> heard (a while ago!)
>>> their version did not implement scaling, colorspace conversion, or image 
>>> rotation via
>>> the IC. Instead their driver sends raw camera frames directly to memory, 
>>> and image
>>> conversion is carried out by separate mem2mem device. Our capture driver 
>>> does
>>> image conversion (scaling, CSC, and rotation) natively using the IC 
>>> pre-processing channel.
>>> We also have a mem2mem device that does conversion using IC post-processing,
>>> which I have included in mx6-media-staging.
>>>
>>> Also IIRC they did some pretty slick stuff with a video bus multiplexer 
>>> subdev, which
>>> can multiplex video from different sensors either using the internal mux in 
>>> the SoC,
>>> or can control an external mux via gpio. Our driver only supports the 
>>> internal mux,
>>> and does it with a platform data function.
>>>
>>> But like I said, I don't what the latest status is of the Pengutronix video 
>>> capture support.
>>>
>>> Btw, I just pushed an update of mx6-media-staging that implements 
>>> vidioc_[gs]_selection.
>>>
>>> Steve
>>>
>>>
>> Steve,
>>
>> Some time has passed without any IMX6 CSI drivers or response from
>> Pengutronix and Hans has agreed to add either/both drivers to staging.
>> Do you have time to rebase and re-post your driver(s)? Maybe that will
>> get the ball rolling on this final huge missing feature for the IMX6
>> in mainline.
> Right. All that is needed is for someone to take the latest version, make it 
> compile
> in the media_tree in drivers/media/staging and post the patch (just take care 
> to keep
> the correct copyrights, Signed-off-by's etc.) and I'll be happy to take it. 
> This is
> exactly what staging is for. I think it will greatly increases the chances of 
> this
> code being improved for mainline. And I'm happy to take both drivers as well, 
> again,
> that's what staging is for.
>
> I've been thinking of doing this myself, but I just don't have the time.
>
> Ideally this is done by the authors, but if they don't have time either then 
> someone
> else can do this.
>

Hi Hans and Tim,

No problem, I will repost the patch-set this week. I've been meaning to,
just busy lately with other tasks.

Steve

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


Re: i.mx6 camera interface (CSI) and mainline kernel

2016-06-06 Thread Steve Longerbeam



On 06/02/2016 09:50 AM, Steve Longerbeam wrote:

On 06/02/2016 06:55 AM, Hans Verkuil wrote:

On 06/02/2016 03:29 PM, Tim Harvey wrote:

On Wed, Mar 9, 2016 at 4:12 PM, Steve Longerbeam
 wrote:

On 03/09/2016 02:44 PM, Tim Harvey wrote:

On Tue, Mar 8, 2016 at 6:06 PM, Steve Longerbeam
 wrote:

On 03/07/2016 08:19 AM, Tim Harvey wrote:



Hi Tim, good to hear it works for you on the Ventana boards.

I've just pushed some more commits to the mx6-media-staging branch that
get the drivers/media/i2c/adv7180.c subdev working with the imx6 capture
backend. Images look perfect when switching to UYVY8_2X8 mbus code instead
of YUYV8_2X8. But I'm holding off on that change because this subdev is used
by Renesas targets and would likely corrupt captured images for those
targets. But I believe UYVY is the correct transmit order according to the
BT.656 standard.

Another thing that should also be changed in drivers/media/i2c/adv7180.c
is the field type. It should be V4L2_FIELD_SEQ_TB for NTSC and V4L2_FIELD_SEQ_BT
for PAL.

Steve



Steve,

with your latest patches, I'm crashing with an null-pointer-deref in
adv7180_set_pad_format. What is your kernel config for
CONFIG_MEDIA_CONTROLLER and CONFIG_VIDEO_V4L2_SUBDEV_API?

Right, I thought I fixed that, I was passing a NULL pad_cfg for
TRY_FORMAT, but that was fixed. Maybe you fetched a version
of mx6-media-staging while I was in the middle of debugging?
Try fetching again.

I tried with both CONFIG_MEDIA_CONTROLLER and
CONFIG_VIDEO_V4L2_SUBDEV_API enabled and both disabled, and
I don't get the null deref in adv7180_set_pad_format.



Your tree contains about 16 or so patches on top of linux-media for
imx6 capture. Are you close to the point where you will be posting a
patch series? If so, please CC me for testing with the adv7180 sensor.

I guess I can try posting a series again, but there will likely be push-back 
from
Pengutronix. They have their own video capture driver for imx6. Last I heard (a 
while ago!)
their version did not implement scaling, colorspace conversion, or image 
rotation via
the IC. Instead their driver sends raw camera frames directly to memory, and 
image
conversion is carried out by separate mem2mem device. Our capture driver does
image conversion (scaling, CSC, and rotation) natively using the IC 
pre-processing channel.
We also have a mem2mem device that does conversion using IC post-processing,
which I have included in mx6-media-staging.

Also IIRC they did some pretty slick stuff with a video bus multiplexer subdev, 
which
can multiplex video from different sensors either using the internal mux in the 
SoC,
or can control an external mux via gpio. Our driver only supports the internal 
mux,
and does it with a platform data function.

But like I said, I don't what the latest status is of the Pengutronix video 
capture support.

Btw, I just pushed an update of mx6-media-staging that implements 
vidioc_[gs]_selection.

Steve



Steve,

Some time has passed without any IMX6 CSI drivers or response from
Pengutronix and Hans has agreed to add either/both drivers to staging.
Do you have time to rebase and re-post your driver(s)? Maybe that will
get the ball rolling on this final huge missing feature for the IMX6
in mainline.

Right. All that is needed is for someone to take the latest version, make it 
compile
in the media_tree in drivers/media/staging and post the patch (just take care 
to keep
the correct copyrights, Signed-off-by's etc.) and I'll be happy to take it. 
This is
exactly what staging is for. I think it will greatly increases the chances of 
this
code being improved for mainline. And I'm happy to take both drivers as well, 
again,
that's what staging is for.

I've been thinking of doing this myself, but I just don't have the time.

Ideally this is done by the authors, but if they don't have time either then 
someone
else can do this.


Hi Hans and Tim,

No problem, I will repost the patch-set this week. I've been meaning to,
just busy lately with other tasks.


Hi all, I need a few more days. I would like to bring in the video-switch
subdev from Pengutronix, which will replace the platform data set_video_mux
method. Also re-org the device-tree to better define all the possible 
hardware

connections, and split out mx6-encode.c into mx6-smfc and mx6-ic subdevs.
Once this is done we should have a better base for adding media control
later. I should have this done by end of this week.

Steve


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


Re: i.mx6 camera interface (CSI) and mainline kernel

2016-06-10 Thread Steve Longerbeam
On 06/10/2016 08:58 AM, Jack Mitchell wrote:
>
> 
>
>>
>> Hi all, I need a few more days. I would like to bring in the video-switch
>> subdev from Pengutronix, which will replace the platform data set_video_mux
>> method. Also re-org the device-tree to better define all the possible
>> hardware
>> connections, and split out mx6-encode.c into mx6-smfc and mx6-ic subdevs.
>> Once this is done we should have a better base for adding media control
>> later. I should have this done by end of this week.
>>
>> Steve
>>
>
> Hi Steve,
>
> Just a heads up that I've also tested and confirmed partially working support 
> on a sabrelite + mipi ov5640. The two gotchas I came across were 
> dma_allocations fail in the higher resolutions (4x1080p
> buffers), a limit may need to be upped somewhere, the code says it should be 
> able to handle up to 64MB? Secondly I can't get the 5MP resolution by default 
> as in ov5640_find_nearest_mode, the array
> ov5640_mode_info_data is hard coded to 0.

Hi Jack, the ov5640 native 5MP (2592x1944) mode is only available at 15 fps, but
the default framerate is 30. So to allow the 5MP mode, set to 15 fps beforehand
with a call to vidioc_s_parm.

>
> I gave your v2 branch a quick whirl also but it fails to compile.

Yes, the v2 branch is the WIP I mentioned above. Making good progress and
hope to have a patchset to post in a few days.


Steve

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


[PATCH 02/38] gpu: ipu-cpmem: Add ipu_cpmem_set_uv_offset()

2016-06-14 Thread Steve Longerbeam
Adds ipu_cpmem_set_uv_offset(), to set planar U/V offsets.

Signed-off-by: Steve Longerbeam 
---
 drivers/gpu/ipu-v3/ipu-cpmem.c | 7 +++
 include/video/imx-ipu-v3.h | 1 +
 2 files changed, 8 insertions(+)

diff --git a/drivers/gpu/ipu-v3/ipu-cpmem.c b/drivers/gpu/ipu-v3/ipu-cpmem.c
index 6494a4d..a36c35e 100644
--- a/drivers/gpu/ipu-v3/ipu-cpmem.c
+++ b/drivers/gpu/ipu-v3/ipu-cpmem.c
@@ -253,6 +253,13 @@ void ipu_cpmem_set_buffer(struct ipuv3_channel *ch, int 
bufnum, dma_addr_t buf)
 }
 EXPORT_SYMBOL_GPL(ipu_cpmem_set_buffer);
 
+void ipu_cpmem_set_uv_offset(struct ipuv3_channel *ch, u32 u_off, u32 v_off)
+{
+   ipu_ch_param_write_field(ch, IPU_FIELD_UBO, u_off / 8);
+   ipu_ch_param_write_field(ch, IPU_FIELD_VBO, v_off / 8);
+}
+EXPORT_SYMBOL_GPL(ipu_cpmem_set_uv_offset);
+
 void ipu_cpmem_interlaced_scan(struct ipuv3_channel *ch, int stride)
 {
ipu_ch_param_write_field(ch, IPU_FIELD_SO, 1);
diff --git a/include/video/imx-ipu-v3.h b/include/video/imx-ipu-v3.h
index 22662a1..904fd12 100644
--- a/include/video/imx-ipu-v3.h
+++ b/include/video/imx-ipu-v3.h
@@ -194,6 +194,7 @@ void ipu_cpmem_set_resolution(struct ipuv3_channel *ch, int 
xres, int yres);
 void ipu_cpmem_set_stride(struct ipuv3_channel *ch, int stride);
 void ipu_cpmem_set_high_priority(struct ipuv3_channel *ch);
 void ipu_cpmem_set_buffer(struct ipuv3_channel *ch, int bufnum, dma_addr_t 
buf);
+void ipu_cpmem_set_uv_offset(struct ipuv3_channel *ch, u32 u_off, u32 v_off);
 void ipu_cpmem_interlaced_scan(struct ipuv3_channel *ch, int stride);
 void ipu_cpmem_set_axi_id(struct ipuv3_channel *ch, u32 id);
 void ipu_cpmem_set_burstsize(struct ipuv3_channel *ch, int burstsize);
-- 
1.9.1

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


[PATCH 04/38] gpu: ipu-v3: Add ipu_get_num()

2016-06-14 Thread Steve Longerbeam
Adds of-alias id to ipu_soc and retrieve with ipu_get_num().

Signed-off-by: Steve Longerbeam 
---
 drivers/gpu/ipu-v3/ipu-common.c | 8 
 drivers/gpu/ipu-v3/ipu-prv.h| 1 +
 include/video/imx-ipu-v3.h  | 1 +
 3 files changed, 10 insertions(+)

diff --git a/drivers/gpu/ipu-v3/ipu-common.c b/drivers/gpu/ipu-v3/ipu-common.c
index 30dc115..49af121 100644
--- a/drivers/gpu/ipu-v3/ipu-common.c
+++ b/drivers/gpu/ipu-v3/ipu-common.c
@@ -45,6 +45,12 @@ static inline void ipu_cm_write(struct ipu_soc *ipu, u32 
value, unsigned offset)
writel(value, ipu->cm_reg + offset);
 }
 
+int ipu_get_num(struct ipu_soc *ipu)
+{
+   return ipu->id;
+}
+EXPORT_SYMBOL_GPL(ipu_get_num);
+
 void ipu_srm_dp_sync_update(struct ipu_soc *ipu)
 {
u32 val;
@@ -1220,6 +1226,7 @@ static int ipu_probe(struct platform_device *pdev)
 {
const struct of_device_id *of_id =
of_match_device(imx_ipu_dt_ids, &pdev->dev);
+   struct device_node *np = pdev->dev.of_node;
struct ipu_soc *ipu;
struct resource *res;
unsigned long ipu_base;
@@ -1248,6 +1255,7 @@ static int ipu_probe(struct platform_device *pdev)
ipu->channel[i].ipu = ipu;
ipu->devtype = devtype;
ipu->ipu_type = devtype->type;
+   ipu->id = of_alias_get_id(np, "ipu");
 
spin_lock_init(&ipu->lock);
mutex_init(&ipu->channel_lock);
diff --git a/drivers/gpu/ipu-v3/ipu-prv.h b/drivers/gpu/ipu-v3/ipu-prv.h
index 845f64c..02057d8 100644
--- a/drivers/gpu/ipu-v3/ipu-prv.h
+++ b/drivers/gpu/ipu-v3/ipu-prv.h
@@ -153,6 +153,7 @@ struct ipu_soc {
void __iomem*cm_reg;
void __iomem*idmac_reg;
 
+   int id;
int usecount;
 
struct clk  *clk;
diff --git a/include/video/imx-ipu-v3.h b/include/video/imx-ipu-v3.h
index 60540ead..b174f8a 100644
--- a/include/video/imx-ipu-v3.h
+++ b/include/video/imx-ipu-v3.h
@@ -148,6 +148,7 @@ int ipu_idmac_channel_irq(struct ipu_soc *ipu, struct 
ipuv3_channel *channel,
 /*
  * IPU Common functions
  */
+int ipu_get_num(struct ipu_soc *ipu);
 void ipu_set_csi_src_mux(struct ipu_soc *ipu, int csi_id, bool mipi_csi2);
 void ipu_set_ic_src_mux(struct ipu_soc *ipu, int csi_id, bool vdi);
 void ipu_dump(struct ipu_soc *ipu);
-- 
1.9.1

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


[PATCH 01/38] gpu: ipu-v3: Add Video Deinterlacer unit

2016-06-14 Thread Steve Longerbeam
Adds the Video Deinterlacer (VDIC) unit.

Signed-off-by: Steve Longerbeam 
---
 drivers/gpu/ipu-v3/Makefile |   2 +-
 drivers/gpu/ipu-v3/ipu-common.c |  11 ++
 drivers/gpu/ipu-v3/ipu-prv.h|   6 +
 drivers/gpu/ipu-v3/ipu-vdi.c| 266 
 include/video/imx-ipu-v3.h  |  27 
 5 files changed, 311 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/ipu-v3/ipu-vdi.c

diff --git a/drivers/gpu/ipu-v3/Makefile b/drivers/gpu/ipu-v3/Makefile
index 107ec23..aeba9dc 100644
--- a/drivers/gpu/ipu-v3/Makefile
+++ b/drivers/gpu/ipu-v3/Makefile
@@ -1,4 +1,4 @@
 obj-$(CONFIG_IMX_IPUV3_CORE) += imx-ipu-v3.o
 
 imx-ipu-v3-objs := ipu-common.o ipu-cpmem.o ipu-csi.o ipu-dc.o ipu-di.o \
-   ipu-dp.o ipu-dmfc.o ipu-ic.o ipu-smfc.o
+   ipu-dp.o ipu-dmfc.o ipu-ic.o ipu-smfc.o ipu-vdi.o
diff --git a/drivers/gpu/ipu-v3/ipu-common.c b/drivers/gpu/ipu-v3/ipu-common.c
index 99dcacf..30dc115 100644
--- a/drivers/gpu/ipu-v3/ipu-common.c
+++ b/drivers/gpu/ipu-v3/ipu-common.c
@@ -833,6 +833,14 @@ static int ipu_submodules_init(struct ipu_soc *ipu,
goto err_ic;
}
 
+   ret = ipu_vdi_init(ipu, dev, ipu_base + devtype->vdi_ofs,
+  IPU_CONF_VDI_EN | IPU_CONF_ISP_EN |
+  IPU_CONF_IC_INPUT);
+   if (ret) {
+   unit = "vdi";
+   goto err_vdi;
+   }
+
ret = ipu_di_init(ipu, dev, 0, ipu_base + devtype->disp0_ofs,
  IPU_CONF_DI0_EN, ipu_clk);
if (ret) {
@@ -887,6 +895,8 @@ err_dc:
 err_di_1:
ipu_di_exit(ipu, 0);
 err_di_0:
+   ipu_vdi_exit(ipu);
+err_vdi:
ipu_ic_exit(ipu);
 err_ic:
ipu_csi_exit(ipu, 1);
@@ -971,6 +981,7 @@ static void ipu_submodules_exit(struct ipu_soc *ipu)
ipu_dc_exit(ipu);
ipu_di_exit(ipu, 1);
ipu_di_exit(ipu, 0);
+   ipu_vdi_exit(ipu);
ipu_ic_exit(ipu);
ipu_csi_exit(ipu, 1);
ipu_csi_exit(ipu, 0);
diff --git a/drivers/gpu/ipu-v3/ipu-prv.h b/drivers/gpu/ipu-v3/ipu-prv.h
index bfb1e8a..845f64c 100644
--- a/drivers/gpu/ipu-v3/ipu-prv.h
+++ b/drivers/gpu/ipu-v3/ipu-prv.h
@@ -138,6 +138,7 @@ struct ipu_dc_priv;
 struct ipu_dmfc_priv;
 struct ipu_di;
 struct ipu_ic_priv;
+struct ipu_vdi;
 struct ipu_smfc_priv;
 
 struct ipu_devtype;
@@ -169,6 +170,7 @@ struct ipu_soc {
struct ipu_di   *di_priv[2];
struct ipu_csi  *csi_priv[2];
struct ipu_ic_priv  *ic_priv;
+   struct ipu_vdi  *vdi_priv;
struct ipu_smfc_priv*smfc_priv;
 };
 
@@ -199,6 +201,10 @@ int ipu_ic_init(struct ipu_soc *ipu, struct device *dev,
unsigned long base, unsigned long tpmem_base);
 void ipu_ic_exit(struct ipu_soc *ipu);
 
+int ipu_vdi_init(struct ipu_soc *ipu, struct device *dev,
+unsigned long base, u32 module);
+void ipu_vdi_exit(struct ipu_soc *ipu);
+
 int ipu_di_init(struct ipu_soc *ipu, struct device *dev, int id,
unsigned long base, u32 module, struct clk *ipu_clk);
 void ipu_di_exit(struct ipu_soc *ipu, int id);
diff --git a/drivers/gpu/ipu-v3/ipu-vdi.c b/drivers/gpu/ipu-v3/ipu-vdi.c
new file mode 100644
index 000..1303bcc
--- /dev/null
+++ b/drivers/gpu/ipu-v3/ipu-vdi.c
@@ -0,0 +1,266 @@
+/*
+ * Copyright (C) 2012 Mentor Graphics Inc.
+ * Copyright (C) 2005-2009 Freescale Semiconductor, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * This 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 "ipu-prv.h"
+
+struct ipu_vdi {
+   void __iomem *base;
+   u32 module;
+   spinlock_t lock;
+   int use_count;
+   struct ipu_soc *ipu;
+};
+
+
+/* VDI Register Offsets */
+#define VDI_FSIZE 0x
+#define VDI_C 0x0004
+
+/* VDI Register Fields */
+#define VDI_C_CH_420 (0 << 1)
+#define VDI_C_CH_422 (1 << 1)
+#define VDI_C_MOT_SEL_MASK   (0x3 << 2)
+#define VDI_C_MOT_SEL_FULL   (2 << 2)
+#define VDI_C_MOT_SEL_LOW(1 << 2)
+#define VDI_C_MOT_SEL_MED(0 << 2)
+#define VDI_C_BURST_SIZE1_4  (3 << 4)
+#define VDI_C_BURST_SIZE2_4  (3 << 8)
+#define VDI_C_BURST_SIZE3_4  (3 << 12)
+#define VDI_C_BURST_SIZE_MASK0xF
+#define VDI_C_BURST_SIZE1_OFFSET 4
+#define VDI_C_BURST_SIZE2_OFFSET 8
+#define VDI_C_BURST_SIZE3_OFFSET 12
+#define VDI_C_V

[PATCH 00/38] i.MX5/6 Video Capture

2016-06-14 Thread Steve Longerbeam
Tested on imx6q SabreAuto with ADV7180, and imx6q SabreSD with
mipi-csi2 OV5640. There is device-tree support also for imx6qdl
SabreLite, but that is not tested. Also, this driver should
theoretically work on i.MX5 targets, but that is also untested.

Not run through v4l2-compliance yet, but that is in my queue.


Philipp Zabel (2):
  ARM: dts: imx6qdl: Add mipi_ipu1/2 video muxes, mipi_csi, and their
connections
  media: imx: Add video switch

Steve Longerbeam (35):
  gpu: ipu-v3: Add Video Deinterlacer unit
  gpu: ipu-cpmem: Add ipu_cpmem_set_uv_offset()
  gpu: ipu-cpmem: Add ipu_cpmem_get_burstsize()
  gpu: ipu-v3: Add ipu_get_num()
  gpu: ipu-v3: Add IDMA channel linking support
  gpu: ipu-v3: Add ipu_set_vdi_src_mux()
  gpu: ipu-v3: Add VDI input IDMAC channels
  gpu: ipu-v3: Add ipu_csi_set_src()
  gpu: ipu-v3: Add ipu_ic_set_src()
  gpu: ipu-v3: set correct full sensor frame for PAL/NTSC
  gpu: ipu-v3: Fix CSI data format for 16-bit media bus formats
  gpu: ipu-v3: Fix IRT usage
  gpu: ipu-ic: Add complete image conversion support with tiling
  gpu: ipu-ic: allow multiple handles to ic
  gpu: ipu-v3: rename CSI client device
  ARM: dts: imx6qdl: Flesh out MIPI CSI2 receiver node
  ARM: dts: imx6-sabrelite: add video capture ports and connections
  ARM: dts: imx6-sabresd: add video capture ports and connections
  ARM: dts: imx6-sabreauto: create i2cmux for i2c3
  ARM: dts: imx6-sabreauto: add reset-gpios property for max7310
  ARM: dts: imx6-sabreauto: add pinctrl for gpt input capture
  ARM: dts: imx6-sabreauto: add video capture ports and connections
  ARM: dts: imx6qdl: add mem2mem device for sabre* boards
  gpio: pca953x: Add reset-gpios property
  clocksource/drivers/imx: add input capture support
  v4l: Add signal lock status to source change events
  media: Add camera interface driver for i.MX5/6
  media: imx: Add MIPI CSI-2 Receiver driver
  media: imx: Add support for MIPI CSI-2 OV5640
  media: imx: Add support for Parallel OV5642
  media: imx: Add support for ADV7180 Video Decoder
  media: adv7180: add power pin control
  media: adv7180: implement g_parm
  media: Add i.MX5/6 mem2mem driver
  ARM: imx_v6_v7_defconfig: Enable staging video4linux drivers

Suresh Dhandapani (1):
  gpu: ipu-v3: Fix CSI0 blur in NTSC format

 Documentation/DocBook/media/v4l/vidioc-dqevent.xml |   12 +-
 Documentation/devicetree/bindings/media/imx.txt|  449 ++
 Documentation/video4linux/imx_camera.txt   |  243 ++
 arch/arm/boot/dts/imx6dl-sabresd.dts   |   44 +
 arch/arm/boot/dts/imx6dl.dtsi  |  183 +
 arch/arm/boot/dts/imx6q-sabreauto.dts  |7 +
 arch/arm/boot/dts/imx6q-sabrelite.dts  |6 +
 arch/arm/boot/dts/imx6q-sabresd.dts|   22 +
 arch/arm/boot/dts/imx6q.dtsi   |  120 +
 arch/arm/boot/dts/imx6qdl-sabreauto.dtsi   |  166 +-
 arch/arm/boot/dts/imx6qdl-sabrelite.dtsi   |   95 +
 arch/arm/boot/dts/imx6qdl-sabresd.dtsi |  145 +-
 arch/arm/boot/dts/imx6qdl.dtsi |   13 +
 arch/arm/configs/imx_v6_v7_defconfig   |2 +
 drivers/clocksource/timer-imx-gpt.c|  463 ++-
 drivers/gpio/gpio-pca953x.c|   28 +
 drivers/gpu/ipu-v3/Makefile|2 +-
 drivers/gpu/ipu-v3/ipu-common.c|  155 +-
 drivers/gpu/ipu-v3/ipu-cpmem.c |   13 +
 drivers/gpu/ipu-v3/ipu-csi.c   |   36 +-
 drivers/gpu/ipu-v3/ipu-ic.c| 1769 +++-
 drivers/gpu/ipu-v3/ipu-prv.h   |7 +
 drivers/gpu/ipu-v3/ipu-vdi.c   |  266 ++
 drivers/media/i2c/adv7180.c|   73 +
 drivers/staging/media/Kconfig  |2 +
 drivers/staging/media/Makefile |1 +
 drivers/staging/media/imx/Kconfig  |   35 +
 drivers/staging/media/imx/Makefile |2 +
 drivers/staging/media/imx/capture/Kconfig  |   42 +
 drivers/staging/media/imx/capture/Makefile |   10 +
 drivers/staging/media/imx/capture/adv7180.c| 1533 +++
 drivers/staging/media/imx/capture/imx-camif.c  | 2496 +++
 drivers/staging/media/imx/capture/imx-camif.h  |  281 ++
 drivers/staging/media/imx/capture/imx-csi.c|  195 +
 drivers/staging/media/imx/capture/imx-ic-prpenc.c  |  660 +++
 drivers/staging/media/imx/capture/imx-of.c |  354 ++
 drivers/staging/media/imx/capture/imx-of.h |   18 +
 drivers/staging/media/imx/capture/imx-smfc.c   |  505 +++
 drivers/staging/media/imx/capture/imx-vdic.c   |  994 +
 .../staging/media/imx/capture/imx-video-switch.c   |  348 ++
 drivers/staging/media/imx/capture/mipi-csi2.c  |  373 ++
 drivers/staging/media/imx/capture/ov5640-mipi.c| 2318 +++
 drivers/staging/media/imx/capture/ov5642.c | 4333 
 drivers/staging

[PATCH 08/38] gpu: ipu-v3: Add ipu_csi_set_src()

2016-06-14 Thread Steve Longerbeam
Adds ipu_csi_set_src() which is just a wrapper around
ipu_set_csi_src_mux().

Signed-off-by: Steve Longerbeam 
---
 drivers/gpu/ipu-v3/ipu-csi.c | 8 
 include/video/imx-ipu-v3.h   | 1 +
 2 files changed, 9 insertions(+)

diff --git a/drivers/gpu/ipu-v3/ipu-csi.c b/drivers/gpu/ipu-v3/ipu-csi.c
index 06631ac..336dc06 100644
--- a/drivers/gpu/ipu-v3/ipu-csi.c
+++ b/drivers/gpu/ipu-v3/ipu-csi.c
@@ -609,6 +609,14 @@ int ipu_csi_set_skip_smfc(struct ipu_csi *csi, u32 skip,
 }
 EXPORT_SYMBOL_GPL(ipu_csi_set_skip_smfc);
 
+int ipu_csi_set_src(struct ipu_csi *csi, u32 vc, bool select_mipi_csi2)
+{
+   ipu_set_csi_src_mux(csi->ipu, csi->id, select_mipi_csi2);
+
+   return 0;
+}
+EXPORT_SYMBOL_GPL(ipu_csi_set_src);
+
 int ipu_csi_set_dest(struct ipu_csi *csi, enum ipu_csi_dest csi_dest)
 {
unsigned long flags;
diff --git a/include/video/imx-ipu-v3.h b/include/video/imx-ipu-v3.h
index 2302fc5..57b487d 100644
--- a/include/video/imx-ipu-v3.h
+++ b/include/video/imx-ipu-v3.h
@@ -301,6 +301,7 @@ int ipu_csi_set_mipi_datatype(struct ipu_csi *csi, u32 vc,
  struct v4l2_mbus_framefmt *mbus_fmt);
 int ipu_csi_set_skip_smfc(struct ipu_csi *csi, u32 skip,
  u32 max_ratio, u32 id);
+int ipu_csi_set_src(struct ipu_csi *csi, u32 vc, bool select_mipi_csi2);
 int ipu_csi_set_dest(struct ipu_csi *csi, enum ipu_csi_dest csi_dest);
 int ipu_csi_enable(struct ipu_csi *csi);
 int ipu_csi_disable(struct ipu_csi *csi);
-- 
1.9.1

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


[PATCH 18/38] ARM: dts: imx6qdl: Add mipi_ipu1/2 video muxes, mipi_csi, and their connections

2016-06-14 Thread Steve Longerbeam
From: Philipp Zabel 

This patch adds the device tree graph connecting the input multiplexers
to the IPU CSIs and the MIPI-CSI2 gasket on i.MX6.

On i.MX6Q/D two two-input multiplexers in front of IPU1 CSI0 and IPU2 CSI1
allow to select between CSI0/1 parallel input pads and the MIPI CSI-2 virtual
channels 0/3.

On i.MX6DL/S two five-input multiplexers in front of IPU1 CSI0 and IPU1 CSI1
allow to select between CSI0/1 parallel input pads and any of the four MIPI
CSI-2 virtual channels.

Signed-off-by: Philipp Zabel 
Signed-off-by: Steve Longerbeam 
---
 arch/arm/boot/dts/imx6dl.dtsi  | 183 +
 arch/arm/boot/dts/imx6q.dtsi   | 120 +++
 arch/arm/boot/dts/imx6qdl.dtsi |   6 ++
 3 files changed, 309 insertions(+)

diff --git a/arch/arm/boot/dts/imx6dl.dtsi b/arch/arm/boot/dts/imx6dl.dtsi
index 9a4c22c..8813df3 100644
--- a/arch/arm/boot/dts/imx6dl.dtsi
+++ b/arch/arm/boot/dts/imx6dl.dtsi
@@ -109,6 +109,118 @@
compatible = "fsl,imx-gpu-subsystem";
cores = <&gpu_2d>, <&gpu_3d>;
};
+
+   ipu1_csi0_mux: videomux@0 {
+   compatible = "imx-video-mux";
+   reg = <0x34 0x07>;
+   gpr = <&gpr>;
+   #address-cells = <1>;
+   #size-cells = <0>;
+   status = "disabled";
+
+   port@0 {
+   reg = <0>;
+
+   ipu1_csi0_mux_from_mipi_vc0: endpoint {
+   remote-endpoint = <&mipi_vc0_to_ipu1_csi0_mux>;
+   };
+   };
+
+   port@1 {
+   reg = <1>;
+
+   ipu1_csi0_mux_from_mipi_vc1: endpoint {
+   remote-endpoint = <&mipi_vc1_to_ipu1_csi0_mux>;
+   };
+   };
+
+   port@2 {
+   reg = <2>;
+
+   ipu1_csi0_mux_from_mipi_vc2: endpoint {
+   remote-endpoint = <&mipi_vc2_to_ipu1_csi0_mux>;
+   };
+   };
+
+   port@3 {
+   reg = <3>;
+
+   ipu1_csi0_mux_from_mipi_vc3: endpoint {
+   remote-endpoint = <&mipi_vc3_to_ipu1_csi0_mux>;
+   };
+   };
+
+   port@4 {
+   reg = <4>;
+
+   ipu1_csi0_mux_from_parallel_sensor: endpoint {
+   };
+   };
+
+   port@5 {
+   reg = <5>;
+
+   ipu1_csi0_mux_to_ipu1_csi0: endpoint {
+   remote-endpoint = 
<&ipu1_csi0_from_ipu1_csi0_mux>;
+   };
+   };
+   };
+
+   ipu1_csi1_mux: videomux@1 {
+   compatible = "imx-video-mux";
+   reg = <0x34 0x38>;
+   gpr = <&gpr>;
+   #address-cells = <1>;
+   #size-cells = <0>;
+   status = "disabled";
+
+   port@0 {
+   reg = <0>;
+
+   ipu1_csi1_mux_from_mipi_vc0: endpoint {
+   remote-endpoint = <&mipi_vc0_to_ipu1_csi1_mux>;
+   };
+   };
+
+   port@1 {
+   reg = <1>;
+
+   ipu1_csi1_mux_from_mipi_vc1: endpoint {
+   remote-endpoint = <&mipi_vc1_to_ipu1_csi1_mux>;
+   };
+   };
+
+   port@2 {
+   reg = <2>;
+
+   ipu1_csi1_mux_from_mipi_vc2: endpoint {
+   remote-endpoint = <&mipi_vc2_to_ipu1_csi1_mux>;
+   };
+   };
+
+   port@3 {
+   reg = <3>;
+
+   ipu1_csi1_mux_from_mipi_vc3: endpoint {
+   remote-endpoint = <&mipi_vc3_to_ipu1_csi1_mux>;
+   };
+   };
+
+   port@4 {
+   reg = <4>;
+
+   ipu1_csi1_mux_from_parallel_sensor: endpoint {
+   };
+   };
+
+   port@5 {
+   reg = <5>;
+
+   ipu1_csi1_mux_to_ipu1_csi1: endpoint {
+   remote-endpoint = 
<&ipu1_csi1_from_ipu1_csi1_mux>;
+   };
+   };
+   };
 };
 
 &gpt {
@@ -131,3 +243,74 @@
 &vpu {
compatible = "fsl,imx6dl-vpu", "cnm,coda960";
 };
+
+&

[PATCH 31/38] media: imx: Add video switch

2016-06-14 Thread Steve Longerbeam
From: Philipp Zabel 

This driver can handle SoC internal and extern video bus multiplexers,
controlled either by register bit fields or by GPIO.

Signed-off-by: Sascha Hauer 
Signed-off-by: Philipp Zabel 
Signed-off-by: Steve Longerbeam 
---
 drivers/staging/media/imx/capture/Kconfig  |   9 +
 drivers/staging/media/imx/capture/Makefile |   1 +
 .../staging/media/imx/capture/imx-video-switch.c   | 348 +
 3 files changed, 358 insertions(+)
 create mode 100644 drivers/staging/media/imx/capture/imx-video-switch.c

diff --git a/drivers/staging/media/imx/capture/Kconfig 
b/drivers/staging/media/imx/capture/Kconfig
index ac6fce0..ecd09abe 100644
--- a/drivers/staging/media/imx/capture/Kconfig
+++ b/drivers/staging/media/imx/capture/Kconfig
@@ -8,4 +8,13 @@ config IMX_MIPI_CSI2
  MIPI CSI-2 Receiver driver support. This driver is required
 for sensor drivers with a MIPI CSI2 interface.
 
+config IMX_VIDEO_SWITCH
+   tristate "i.MX5/6 Video Bus Multiplexer"
+   depends on VIDEO_IMX_CAMERA
+   default y
+   ---help---
+ This driver provides support for the i.MX5/6 internal video bus
+ multiplexer controlled by register bitfields as well as
+ external multiplexers controller by a GPIO.
+
 endmenu
diff --git a/drivers/staging/media/imx/capture/Makefile 
b/drivers/staging/media/imx/capture/Makefile
index 8961a4f..f17b199 100644
--- a/drivers/staging/media/imx/capture/Makefile
+++ b/drivers/staging/media/imx/capture/Makefile
@@ -4,3 +4,4 @@ imx-camera-objs := imx-camif.o imx-ic-prpenc.o imx-of.o \
 obj-$(CONFIG_VIDEO_IMX_CAMERA) += imx-camera.o
 obj-$(CONFIG_VIDEO_IMX_CAMERA) += imx-csi.o
 obj-$(CONFIG_IMX_MIPI_CSI2) += mipi-csi2.o
+obj-$(CONFIG_IMX_VIDEO_SWITCH) += imx-video-switch.o
diff --git a/drivers/staging/media/imx/capture/imx-video-switch.c 
b/drivers/staging/media/imx/capture/imx-video-switch.c
new file mode 100644
index 000..0c86679
--- /dev/null
+++ b/drivers/staging/media/imx/capture/imx-video-switch.c
@@ -0,0 +1,348 @@
+/*
+ * devicetree probed mediacontrol video multiplexer.
+ *
+ * Copyright (C) 2013 Sascha Hauer, Pengutronix
+ * Copyright (c) 2014-2016 Mentor Graphics Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ * This 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 
+
+struct vidsw {
+   struct device *dev;
+   struct v4l2_subdev subdev;
+#ifdef CONFIG_MEDIA_CONTROLLER
+   struct media_pad *pads;
+#endif
+   struct v4l2_mbus_framefmt *format_mbus;
+   struct v4l2_of_endpoint *endpoint;
+   struct regmap_field *field;
+   unsigned int gpio;
+   int output_pad;
+   int numpads;
+   int active;
+};
+
+#define to_vidsw(sd) container_of(sd, struct vidsw, subdev)
+
+static int vidsw_set_mux(struct vidsw *vidsw, int input_index)
+{
+   if (vidsw->active >= 0) {
+   if (vidsw->active == input_index)
+   return 0;
+   else
+   return -EBUSY;
+   }
+
+   vidsw->active = input_index;
+
+   dev_dbg(vidsw->dev, "setting %d active\n", vidsw->active);
+
+   if (vidsw->field)
+   regmap_field_write(vidsw->field, vidsw->active);
+   else if (gpio_is_valid(vidsw->gpio))
+   gpio_set_value(vidsw->gpio, vidsw->active);
+
+   return 0;
+}
+
+#ifdef CONFIG_MEDIA_CONTROLLER
+static int vidsw_link_setup(struct media_entity *entity,
+   const struct media_pad *local,
+   const struct media_pad *remote, u32 flags)
+{
+   struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
+   struct vidsw *vidsw = to_vidsw(sd);
+
+   dev_dbg(vidsw->dev, "link setup %s -> %s", remote->entity->name,
+   local->entity->name);
+
+   if (!(flags & MEDIA_LNK_FL_ENABLED)) {
+   if (local->index == vidsw->active) {
+   dev_dbg(vidsw->dev, "going inactive\n");
+   vidsw->active = -1;
+   }
+   return 0;
+   }
+
+   return vidsw_set_mux(vidsw, local->index);
+}
+
+static struct media_entity_operations vidsw_ops = {
+   .link_setup = vidsw_link_setup,
+};
+#endif
+
+static int vidsw_s_routing(struct v4l2_subdev *sd, u32 input,
+  u32 output, u32 config)
+{
+   struct vidsw *vidsw = contai

[PATCH 15/38] gpu: ipu-ic: allow multiple handles to ic

2016-06-14 Thread Steve Longerbeam
The image converter kernel API supports conversion contexts and
job queues, so we should allow more than one handle to the IC, so
that multiple users can add jobs to the queue.

Note however that users that control the IC manually (that do not
use the image converter APIs but setup the IC task by hand via calls
to ipu_ic_task_enable(), ipu_ic_enable(), etc.) must still be careful not
to share the IC handle with other threads. At this point, the only user
that still controls the IC manually is the i.mx capture driver. In that
case the capture driver only allows one open context to get a handle
to the IC at a time, so we should be ok there.

Signed-off-by: Steve Longerbeam 
---
 drivers/gpu/ipu-v3/ipu-ic.c | 25 +
 1 file changed, 1 insertion(+), 24 deletions(-)

diff --git a/drivers/gpu/ipu-v3/ipu-ic.c b/drivers/gpu/ipu-v3/ipu-ic.c
index f6a1125..51e34a1 100644
--- a/drivers/gpu/ipu-v3/ipu-ic.c
+++ b/drivers/gpu/ipu-v3/ipu-ic.c
@@ -342,7 +342,6 @@ struct ipu_ic {
enum ipu_color_space out_cs;
bool graphics;
bool rotation;
-   bool in_use;
 
struct image_converter cvt;
 
@@ -2380,38 +2379,16 @@ EXPORT_SYMBOL_GPL(ipu_ic_disable);
 struct ipu_ic *ipu_ic_get(struct ipu_soc *ipu, enum ipu_ic_task task)
 {
struct ipu_ic_priv *priv = ipu->ic_priv;
-   unsigned long flags;
-   struct ipu_ic *ic, *ret;
 
if (task >= IC_NUM_TASKS)
return ERR_PTR(-EINVAL);
 
-   ic = &priv->task[task];
-
-   spin_lock_irqsave(&priv->lock, flags);
-
-   if (ic->in_use) {
-   ret = ERR_PTR(-EBUSY);
-   goto unlock;
-   }
-
-   ic->in_use = true;
-   ret = ic;
-
-unlock:
-   spin_unlock_irqrestore(&priv->lock, flags);
-   return ret;
+   return &priv->task[task];
 }
 EXPORT_SYMBOL_GPL(ipu_ic_get);
 
 void ipu_ic_put(struct ipu_ic *ic)
 {
-   struct ipu_ic_priv *priv = ic->priv;
-   unsigned long flags;
-
-   spin_lock_irqsave(&priv->lock, flags);
-   ic->in_use = false;
-   spin_unlock_irqrestore(&priv->lock, flags);
 }
 EXPORT_SYMBOL_GPL(ipu_ic_put);
 
-- 
1.9.1

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


[PATCH 26/38] gpio: pca953x: Add reset-gpios property

2016-06-14 Thread Steve Longerbeam
Add optional reset-gpios property. If present, de-assert the
specified reset gpio pin to bring the chip out of reset.

Signed-off-by: Steve Longerbeam 
---
 drivers/gpio/gpio-pca953x.c | 28 
 1 file changed, 28 insertions(+)

diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c
index 5e3be32..475fa56 100644
--- a/drivers/gpio/gpio-pca953x.c
+++ b/drivers/gpio/gpio-pca953x.c
@@ -21,6 +21,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #define PCA953X_INPUT  0
 #define PCA953X_OUTPUT 1
@@ -111,6 +112,11 @@ struct pca953x_chip {
const char *const *names;
int chip_type;
unsigned long driver_data;
+
+#ifdef CONFIG_OF_GPIO
+   enum of_gpio_flags reset_gpio_flags;
+   int reset_gpio;
+#endif
 };
 
 static int pca953x_read_single(struct pca953x_chip *chip, int reg, u32 *val,
@@ -759,6 +765,28 @@ static int pca953x_probe(struct i2c_client *client,
} else {
chip->gpio_start = -1;
irq_base = 0;
+
+#ifdef CONFIG_OF_GPIO
+   /* see if we need to de-assert a reset pin */
+   ret = of_get_named_gpio_flags(client->dev.of_node,
+ "reset-gpios", 0,
+ &chip->reset_gpio_flags);
+   if (gpio_is_valid(ret)) {
+   chip->reset_gpio = ret;
+   ret = devm_gpio_request_one(&client->dev,
+   chip->reset_gpio,
+   GPIOF_DIR_OUT,
+   "pca953x_reset");
+   if (ret == 0) {
+   /* bring chip out of reset */
+   dev_info(&client->dev, "releasing reset\n");
+   gpio_set_value(chip->reset_gpio,
+  (chip->reset_gpio_flags ==
+   OF_GPIO_ACTIVE_LOW) ? 1 : 0);
+   }
+   } else if (ret == -EPROBE_DEFER)
+   return ret;
+#endif
}
 
chip->client = client;
-- 
1.9.1

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


[PATCH 27/38] clocksource/drivers/imx: add input capture support

2016-06-14 Thread Steve Longerbeam
This patch adds support for the input capture function in the
i.MX GPT. Output compare and input capture functions are mixed
in the same register block, so we need to modify the irq ack/enable/
disable primitives to not stomp on the other function.

The input capture API is modelled after request/free irq:

typedef void (*mxc_icap_handler_t)(int, void *, struct timespec *);

int mxc_request_input_capture(unsigned int chan,
  mxc_icap_handler_t handler,
  unsigned long capflags, void *dev_id);

- chan: the channel number being requested (0 or 1).

- handler: a callback when there is an input capture event. The
  handler is given the channel number, the dev_id, and a timespec
  marking the input capture event. The timespec is always reset at
  request time, that is, the first event after request will always
  have a timespec of 0, and will increase thereafter.

- capflags: IRQF_TRIGGER_RISING and/or IRQF_TRIGGER_FALLING. If
  both are specified, events will be triggered on both rising and
  falling edges of the input capture signal.

- dev_id: a context pointer given back to the handler.

void mxc_free_input_capture(unsigned int chan, void *dev_id);

This disables the given input capture channel in the GPT.

Signed-off-by: Steve Longerbeam 
---
 drivers/clocksource/timer-imx-gpt.c | 463 
 include/linux/mxc_icap.h|  20 ++
 2 files changed, 437 insertions(+), 46 deletions(-)
 create mode 100644 include/linux/mxc_icap.h

diff --git a/drivers/clocksource/timer-imx-gpt.c 
b/drivers/clocksource/timer-imx-gpt.c
index 99ec967..1f7f871 100644
--- a/drivers/clocksource/timer-imx-gpt.c
+++ b/drivers/clocksource/timer-imx-gpt.c
@@ -21,6 +21,7 @@
  * MA 02110-1301, USA.
  */
 
+#include 
 #include 
 #include 
 #include 
@@ -32,6 +33,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 #include 
 
 /*
@@ -65,16 +68,53 @@
 #define V2_TCTL_CLK_PER(2 << 6)
 #define V2_TCTL_CLK_OSC_DIV8   (5 << 6)
 #define V2_TCTL_FRR(1 << 9)
+#define V2_TCTL_IM1_BIT16
+#define V2_TCTL_IM2_BIT18
+#define V2_IM_DISABLE  0
+#define V2_IM_RISING   1
+#define V2_IM_FALLING  2
+#define V2_IM_BOTH 3
 #define V2_TCTL_24MEN  (1 << 10)
 #define V2_TPRER_PRE24M12
 #define V2_IR  0x0c
+#define V2_IR_OF1  (1 << 0)
+#define V2_IR_IF1  (1 << 3)
+#define V2_IR_IF2  (1 << 4)
 #define V2_TSTAT   0x08
 #define V2_TSTAT_OF1   (1 << 0)
+#define V2_TSTAT_IF1   (1 << 3)
+#define V2_TSTAT_IF2   (1 << 4)
 #define V2_TCN 0x24
 #define V2_TCMP0x10
+#define V2_TCAP1   0x1c
+#define V2_TCAP2   0x20
 
 #define V2_TIMER_RATE_OSC_DIV8 300
 
+struct imx_timer;
+
+struct icap_channel {
+   struct imx_timer *imxtm;
+
+   int chan;
+
+   u32 cnt_reg;
+   u32 irqen_bit;
+   u32 status_bit;
+   u32 mode_bit;
+
+   mxc_icap_handler_t handler;
+   void *dev_id;
+
+   struct timespec ts;
+   cycles_t last_cycles;
+   bool first_event;
+};
+
+/* FIXME, for now can't find icap unless it's statically allocated */
+static struct icap_channel icap_channel[2];
+static DEFINE_SPINLOCK(icap_lock);
+
 struct imx_timer {
enum imx_gpt_type type;
void __iomem *base;
@@ -90,12 +130,20 @@ struct imx_gpt_data {
int reg_tstat;
int reg_tcn;
int reg_tcmp;
-   void (*gpt_setup_tctl)(struct imx_timer *imxtm);
-   void (*gpt_irq_enable)(struct imx_timer *imxtm);
-   void (*gpt_irq_disable)(struct imx_timer *imxtm);
-   void (*gpt_irq_acknowledge)(struct imx_timer *imxtm);
+   void (*gpt_oc_setup_tctl)(struct imx_timer *imxtm);
+   void (*gpt_oc_irq_enable)(struct imx_timer *imxtm);
+   void (*gpt_oc_irq_disable)(struct imx_timer *imxtm);
+   void (*gpt_oc_irq_acknowledge)(struct imx_timer *imxtm);
+   bool (*gpt_is_oc_irq)(unsigned int tstat);
int (*set_next_event)(unsigned long evt,
  struct clock_event_device *ced);
+
+   void (*gpt_ic_irq_enable)(struct icap_channel *ic);
+   void (*gpt_ic_irq_disable)(struct icap_channel *ic);
+   void (*gpt_ic_irq_acknowledge)(struct icap_channel *ic);
+   bool (*gpt_is_ic_irq)(unsigned int tstat);
+   void (*gpt_ic_enable)(struct icap_channel *ic, unsigned int mode);
+   void (*gpt_ic_disable)(struct icap_channel *ic);
 };
 
 static inline struct imx_timer *to_imx_timer(struct clock_event_device *ced)
@@ -103,52 +151,144 @@ static inline struct imx_timer *to_imx_timer(struct 
clock_event_device *ced)
return container_of(ced, struct imx_timer, ced);
 }
 
-static void imx1_gpt_irq_disabl

[PATCH 23/38] ARM: dts: imx6-sabreauto: add pinctrl for gpt input capture

2016-06-14 Thread Steve Longerbeam
Add pinctrl groups for both GPT input capture channels.

Signed-off-by: Steve Longerbeam 
---
 arch/arm/boot/dts/imx6qdl-sabreauto.dtsi | 12 
 1 file changed, 12 insertions(+)

diff --git a/arch/arm/boot/dts/imx6qdl-sabreauto.dtsi 
b/arch/arm/boot/dts/imx6qdl-sabreauto.dtsi
index 81e3ab7..21af432 100644
--- a/arch/arm/boot/dts/imx6qdl-sabreauto.dtsi
+++ b/arch/arm/boot/dts/imx6qdl-sabreauto.dtsi
@@ -462,6 +462,18 @@
>;
};
 
+   pinctrl_gpt_input_capture0: gptinputcapture0grp {
+   fsl,pins = <
+   MX6QDL_PAD_SD1_DAT0__GPT_CAPTURE1   
0x8000
+   >;
+   };
+
+   pinctrl_gpt_input_capture1: gptinputcapture1grp {
+   fsl,pins = <
+   MX6QDL_PAD_SD1_DAT1__GPT_CAPTURE2   
0x8000
+   >;
+   };
+
pinctrl_spdif: spdifgrp {
fsl,pins = <
MX6QDL_PAD_KEY_COL3__SPDIF_IN 0x1b0b0
-- 
1.9.1

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


[PATCH 32/38] media: imx: Add support for MIPI CSI-2 OV5640

2016-06-14 Thread Steve Longerbeam
This driver is based on ov5640_mipi.c from Freescale imx_3.10.17_1.0.0_beta
branch, modified heavily for code cleanup and converted from int-device
to subdev.

Signed-off-by: Steve Longerbeam 
---
 drivers/staging/media/imx/capture/Kconfig   |8 +
 drivers/staging/media/imx/capture/Makefile  |1 +
 drivers/staging/media/imx/capture/ov5640-mipi.c | 2318 +++
 3 files changed, 2327 insertions(+)
 create mode 100644 drivers/staging/media/imx/capture/ov5640-mipi.c

diff --git a/drivers/staging/media/imx/capture/Kconfig 
b/drivers/staging/media/imx/capture/Kconfig
index ecd09abe..d4389d1 100644
--- a/drivers/staging/media/imx/capture/Kconfig
+++ b/drivers/staging/media/imx/capture/Kconfig
@@ -17,4 +17,12 @@ config IMX_VIDEO_SWITCH
  multiplexer controlled by register bitfields as well as
  external multiplexers controller by a GPIO.
 
+config IMX_CAMERA_OV5640_MIPI
+   tristate "OmniVision OV5640 MIPI CSI-2 camera support"
+   depends on VIDEO_IMX_CAMERA
+   select IMX_MIPI_CSI2
+   default y
+   ---help---
+ MIPI CSI-2 OV5640 Camera support.
+
 endmenu
diff --git a/drivers/staging/media/imx/capture/Makefile 
b/drivers/staging/media/imx/capture/Makefile
index f17b199..1ad4fd2 100644
--- a/drivers/staging/media/imx/capture/Makefile
+++ b/drivers/staging/media/imx/capture/Makefile
@@ -5,3 +5,4 @@ obj-$(CONFIG_VIDEO_IMX_CAMERA) += imx-camera.o
 obj-$(CONFIG_VIDEO_IMX_CAMERA) += imx-csi.o
 obj-$(CONFIG_IMX_MIPI_CSI2) += mipi-csi2.o
 obj-$(CONFIG_IMX_VIDEO_SWITCH) += imx-video-switch.o
+obj-$(CONFIG_IMX_CAMERA_OV5640_MIPI) += ov5640-mipi.o
diff --git a/drivers/staging/media/imx/capture/ov5640-mipi.c 
b/drivers/staging/media/imx/capture/ov5640-mipi.c
new file mode 100644
index 000..3c02b3b
--- /dev/null
+++ b/drivers/staging/media/imx/capture/ov5640-mipi.c
@@ -0,0 +1,2318 @@
+/*
+ * Copyright (c) 2014 Mentor Graphics Inc.
+ * Copyright (C) 2011-2013 Freescale Semiconductor, Inc. All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define OV5640_VOLTAGE_ANALOG   280
+#define OV5640_VOLTAGE_DIGITAL_CORE 150
+#define OV5640_VOLTAGE_DIGITAL_IO   180
+
+#define MIN_FPS 15
+#define MAX_FPS 30
+#define DEFAULT_FPS 30
+
+/* min/typical/max system clock (xclk) frequencies */
+#define OV5640_XCLK_MIN  600
+#define OV5640_XCLK_TYP 2400
+#define OV5640_XCLK_MAX 5400
+
+/* min/typical/max pixel clock (mclk) frequencies */
+#define OV5640_MCLK_MIN 4800
+#define OV5640_MCLK_TYP 4800
+#define OV5640_MCLK_MAX 9600
+
+#define OV5640_CHIP_ID  0x300A
+
+#define OV5640_MAX_CONTROLS 64
+
+enum ov5640_mode {
+   ov5640_mode_MIN = 0,
+   ov5640_mode_QCIF_176_144 = 0,
+   ov5640_mode_QVGA_320_240,
+   ov5640_mode_VGA_640_480,
+   ov5640_mode_NTSC_720_480,
+   ov5640_mode_PAL_720_576,
+   ov5640_mode_XGA_1024_768,
+   ov5640_mode_720P_1280_720,
+   ov5640_mode_1080P_1920_1080,
+   ov5640_mode_QSXGA_2592_1944,
+   ov5640_num_modes,
+   ov5640_mode_INIT = 0xff, /*only for sensor init*/
+};
+
+enum ov5640_frame_rate {
+   ov5640_15_fps,
+   ov5640_30_fps
+};
+
+static int ov5640_framerates[] = {
+   [ov5640_15_fps] = 15,
+   [ov5640_30_fps] = 30,
+};
+#define ov5640_num_framerates ARRAY_SIZE(ov5640_framerates)
+
+/* image size under 1280 * 960 are SUBSAMPLING
+ * image size upper 1280 * 960 are SCALING
+ */
+enum ov5640_downsize_mode {
+   SUBSAMPLING,
+   SCALING,
+};
+
+struct reg_value {
+   u16 reg_addr;
+   u8 val;
+   u8 mask;
+   u32 delay_ms;
+};
+
+struct ov5640_mode_info {
+   enum ov5640_mode mode;
+   enum ov5640_downsize_mode dn_mode;
+   u32 width;
+   u32 height;
+   struct reg_value *init_data_ptr;
+   u32 init_data_size;
+};
+
+struct ov5640_dev {
+   struct i2c_client *i2c_client;
+   struct device *dev;
+   struct v4l2_subdev sd;
+   struct v4l2_ctrl_handler ctrl_hdl;
+   struct v4l2_of_endpoint ep; /* the parsed DT endpoint info */
+   struct v4l2_mbus_framefmt fmt;
+   struct v4l2_captureparm streamcap;
+   struct clk *xclk; /* system clock to OV5640 */
+   int xclk_freq;/* requested xclk freq from devicetree */
+
+   enum ov5640_mode current_mode;
+   enum ov5640_frame_rate current_fr;
+
+   bool on;
+   bool awb_on;
+   bool agc_on;
+
+   /* cached control settings */
+   int ctrl_cache[OV5640_MAX_CONTROLS];
+
+   int reset_gpio;
+

[PATCH 25/38] ARM: dts: imx6qdl: add mem2mem device for sabre* boards

2016-06-14 Thread Steve Longerbeam
Enables ipu-mem2mem device on SabreAuto, SabreSD, and SabreLite
(also on ipu2 for quad).

Signed-off-by: Steve Longerbeam 
---
 arch/arm/boot/dts/imx6q-sabreauto.dts| 7 +++
 arch/arm/boot/dts/imx6q-sabrelite.dts| 6 ++
 arch/arm/boot/dts/imx6q-sabresd.dts  | 6 ++
 arch/arm/boot/dts/imx6qdl-sabreauto.dtsi | 6 ++
 arch/arm/boot/dts/imx6qdl-sabresd.dtsi   | 6 ++
 5 files changed, 31 insertions(+)

diff --git a/arch/arm/boot/dts/imx6q-sabreauto.dts 
b/arch/arm/boot/dts/imx6q-sabreauto.dts
index 334b924..6e79396 100644
--- a/arch/arm/boot/dts/imx6q-sabreauto.dts
+++ b/arch/arm/boot/dts/imx6q-sabreauto.dts
@@ -18,8 +18,15 @@
 / {
model = "Freescale i.MX6 Quad SABRE Automotive Board";
compatible = "fsl,imx6q-sabreauto", "fsl,imx6q";
+
+   ipum2m1: ipum2m@ipu2 {
+   compatible = "fsl,imx-video-mem2mem";
+   ipu = <&ipu2>;
+   status = "okay";
+   };
 };
 
+
 &sata {
status = "okay";
 };
diff --git a/arch/arm/boot/dts/imx6q-sabrelite.dts 
b/arch/arm/boot/dts/imx6q-sabrelite.dts
index 66d10d8..95fe618 100644
--- a/arch/arm/boot/dts/imx6q-sabrelite.dts
+++ b/arch/arm/boot/dts/imx6q-sabrelite.dts
@@ -47,6 +47,12 @@
 / {
model = "Freescale i.MX6 Quad SABRE Lite Board";
compatible = "fsl,imx6q-sabrelite", "fsl,imx6q";
+
+   ipum2m1: ipum2m@ipu2 {
+   compatible = "fsl,imx-video-mem2mem";
+   ipu = <&ipu2>;
+   status = "okay";
+   };
 };
 
 &sata {
diff --git a/arch/arm/boot/dts/imx6q-sabresd.dts 
b/arch/arm/boot/dts/imx6q-sabresd.dts
index ade6305..1156919 100644
--- a/arch/arm/boot/dts/imx6q-sabresd.dts
+++ b/arch/arm/boot/dts/imx6q-sabresd.dts
@@ -18,6 +18,12 @@
 / {
model = "Freescale i.MX6 Quad SABRE Smart Device Board";
compatible = "fsl,imx6q-sabresd", "fsl,imx6q";
+
+   ipum2m1: ipum2m@ipu2 {
+   compatible = "fsl,imx-video-mem2mem";
+   ipu = <&ipu2>;
+   status = "okay";
+   };
 };
 
 &sata {
diff --git a/arch/arm/boot/dts/imx6qdl-sabreauto.dtsi 
b/arch/arm/boot/dts/imx6qdl-sabreauto.dtsi
index f962f51..811059f 100644
--- a/arch/arm/boot/dts/imx6qdl-sabreauto.dtsi
+++ b/arch/arm/boot/dts/imx6qdl-sabreauto.dtsi
@@ -184,6 +184,12 @@
enable = <1>;
};
};
+
+   ipum2m0: ipum2m@ipu1 {
+   compatible = "fsl,imx-video-mem2mem";
+   ipu = <&ipu1>;
+   status = "okay";
+   };
 };
 
 &ipu1_csi0_from_ipu1_csi0_mux {
diff --git a/arch/arm/boot/dts/imx6qdl-sabresd.dtsi 
b/arch/arm/boot/dts/imx6qdl-sabresd.dtsi
index ce575e6..a67ad02 100644
--- a/arch/arm/boot/dts/imx6qdl-sabresd.dtsi
+++ b/arch/arm/boot/dts/imx6qdl-sabresd.dtsi
@@ -168,6 +168,12 @@
ports = <&ipu1_csi1>;
status = "okay";
};
+
+   ipum2m0: ipum2m@ipu1 {
+   compatible = "fsl,imx-video-mem2mem";
+   ipu = <&ipu1>;
+   status = "okay";
+   };
 };
 
 #ifdef __ENABLE_OV5642__
-- 
1.9.1

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


[PATCH 34/38] media: imx: Add support for ADV7180 Video Decoder

2016-06-14 Thread Steve Longerbeam
This driver is based on adv7180.c from Freescale imx_3.10.17_1.0.0_beta
branch, modified heavily for code cleanup and converted from int-device
to subdev.

Signed-off-by: Steve Longerbeam 
---
 drivers/staging/media/imx/capture/Kconfig   |7 +
 drivers/staging/media/imx/capture/Makefile  |1 +
 drivers/staging/media/imx/capture/adv7180.c | 1533 +++
 include/uapi/linux/v4l2-controls.h  |4 +
 include/uapi/media/Kbuild   |1 +
 include/uapi/media/adv718x.h|   42 +
 6 files changed, 1588 insertions(+)
 create mode 100644 drivers/staging/media/imx/capture/adv7180.c
 create mode 100644 include/uapi/media/adv718x.h

diff --git a/drivers/staging/media/imx/capture/Kconfig 
b/drivers/staging/media/imx/capture/Kconfig
index 42d87db..6897192 100644
--- a/drivers/staging/media/imx/capture/Kconfig
+++ b/drivers/staging/media/imx/capture/Kconfig
@@ -32,4 +32,11 @@ config IMX_CAMERA_OV5640_MIPI
---help---
  MIPI CSI-2 OV5640 Camera support.
 
+config IMX_CAMERA_ADV7180
+   tristate "Analog Devices ADV7180 Video Decoder support"
+   depends on VIDEO_IMX_CAMERA
+   default y
+   ---help---
+ Analog Devices ADV7180 Video Decoder support.
+
 endmenu
diff --git a/drivers/staging/media/imx/capture/Makefile 
b/drivers/staging/media/imx/capture/Makefile
index 07633be..c8f891a 100644
--- a/drivers/staging/media/imx/capture/Makefile
+++ b/drivers/staging/media/imx/capture/Makefile
@@ -7,3 +7,4 @@ obj-$(CONFIG_IMX_MIPI_CSI2) += mipi-csi2.o
 obj-$(CONFIG_IMX_VIDEO_SWITCH) += imx-video-switch.o
 obj-$(CONFIG_IMX_CAMERA_OV5640_MIPI) += ov5640-mipi.o
 obj-$(CONFIG_IMX_CAMERA_OV5642) += ov5642.o
+obj-$(CONFIG_IMX_CAMERA_ADV7180) += adv7180.o
diff --git a/drivers/staging/media/imx/capture/adv7180.c 
b/drivers/staging/media/imx/capture/adv7180.c
new file mode 100644
index 000..297c543
--- /dev/null
+++ b/drivers/staging/media/imx/capture/adv7180.c
@@ -0,0 +1,1533 @@
+/*
+ * Analog Device ADV7180 video decoder driver
+ *
+ * Copyright (c) 2012-2014 Mentor Graphics Inc.
+ * Copyright 2005-2012 Freescale Semiconductor, Inc. All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+struct adv7180_dev {
+   struct i2c_client *i2c_client;
+   struct device *dev;
+   struct v4l2_subdev sd;
+   struct v4l2_of_endpoint ep; /* the parsed DT endpoint info */
+   struct v4l2_ctrl_handler ctrl_hdl;
+   struct v4l2_mbus_framefmt fmt;
+   struct v4l2_captureparm streamcap;
+   int rev_id;
+   bool on;
+
+   bool locked; /* locked to signal */
+
+   struct regulator *dvddio;
+   struct regulator *dvdd;
+   struct regulator *avdd;
+   struct regulator *pvdd;
+   int pwdn_gpio;
+
+   v4l2_std_id std_id;
+
+   /* Standard index of ADV7180. */
+   int video_idx;
+
+   /* Current analog input mux */
+   int current_input;
+
+   struct mutex mutex;
+};
+
+static inline struct adv7180_dev *to_adv7180_dev(struct v4l2_subdev *sd)
+{
+   return container_of(sd, struct adv7180_dev, sd);
+}
+
+static inline struct adv7180_dev *ctrl_to_adv7180_dev(struct v4l2_ctrl *ctrl)
+{
+   return container_of(ctrl->handler, struct adv7180_dev, ctrl_hdl);
+}
+
+/*! List of input video formats supported. The video formats is corresponding
+ * with v4l2 id in video_fmt_t
+ */
+enum {
+   ADV7180_NTSC = 0,   /*!< Locked on (M) NTSC video signal. */
+   ADV7180_PAL,/*!< (B, G, H, I, N)PAL video signal. */
+};
+
+/*! Number of video standards supported (including 'not locked' signal). */
+#define ADV7180_STD_MAX(ADV7180_PAL + 1)
+
+/* video standard info */
+struct adv7180_std_info {
+   unsigned long width;
+   unsigned long height;
+   struct v4l2_standard std;
+};
+
+static struct adv7180_std_info adv7180_std[] = {
+   [ADV7180_NTSC] = {
+   .width = 720,
+   .height = 480,
+   .std = {
+   .id = V4L2_STD_NTSC,
+   .name = "NTSC",
+   .framelines = 525,
+   .frameperiod = {
+   .numerator = 1001,
+   .denominator = 3,
+   },
+   },
+   },
+   [ADV7180_PAL] = {
+   .width = 720,
+   .height = 576,
+   .std = {
+  

[PATCH 30/38] media: imx: Add MIPI CSI-2 Receiver driver

2016-06-14 Thread Steve Longerbeam
Adds MIPI CSI-2 Receiver subdev driver. This subdev is required
for sensors with a MIPI CSI2 interface.

Signed-off-by: Steve Longerbeam 
---
 drivers/staging/media/imx/capture/Kconfig |   8 +
 drivers/staging/media/imx/capture/Makefile|   1 +
 drivers/staging/media/imx/capture/mipi-csi2.c | 373 ++
 3 files changed, 382 insertions(+)
 create mode 100644 drivers/staging/media/imx/capture/mipi-csi2.c

diff --git a/drivers/staging/media/imx/capture/Kconfig 
b/drivers/staging/media/imx/capture/Kconfig
index ee2cbab..ac6fce0 100644
--- a/drivers/staging/media/imx/capture/Kconfig
+++ b/drivers/staging/media/imx/capture/Kconfig
@@ -1,3 +1,11 @@
 menu "i.MX5/6 Camera Sub devices"
 
+config IMX_MIPI_CSI2
+   tristate "MIPI CSI2 Receiver Driver"
+   depends on VIDEO_IMX_CAMERA
+   default y
+   ---help---
+ MIPI CSI-2 Receiver driver support. This driver is required
+for sensor drivers with a MIPI CSI2 interface.
+
 endmenu
diff --git a/drivers/staging/media/imx/capture/Makefile 
b/drivers/staging/media/imx/capture/Makefile
index 5c965f9..8961a4f 100644
--- a/drivers/staging/media/imx/capture/Makefile
+++ b/drivers/staging/media/imx/capture/Makefile
@@ -3,3 +3,4 @@ imx-camera-objs := imx-camif.o imx-ic-prpenc.o imx-of.o \
 
 obj-$(CONFIG_VIDEO_IMX_CAMERA) += imx-camera.o
 obj-$(CONFIG_VIDEO_IMX_CAMERA) += imx-csi.o
+obj-$(CONFIG_IMX_MIPI_CSI2) += mipi-csi2.o
diff --git a/drivers/staging/media/imx/capture/mipi-csi2.c 
b/drivers/staging/media/imx/capture/mipi-csi2.c
new file mode 100644
index 000..d0a8c10
--- /dev/null
+++ b/drivers/staging/media/imx/capture/mipi-csi2.c
@@ -0,0 +1,373 @@
+/*
+ * MIPI CSI-2 Receiver Subdev for Freescale i.MX5/6 SOC.
+ *
+ * Copyright (c) 2012-2014 Mentor Graphics Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+struct imxcsi2_dev {
+   struct device  *dev;
+   struct v4l2_subdev  sd;
+   struct clk *dphy_clk;
+   struct clk *cfg_clk;
+   struct clk *pix_clk; /* what is this? */
+   void __iomem   *base;
+   int intr1;
+   int intr2;
+   struct v4l2_of_bus_mipi_csi2 bus;
+   spinlock_t  lock;
+   boolon;
+};
+
+#define DEVICE_NAME "imx-mipi-csi2"
+
+/* Register offsets */
+#define CSI2_VERSION0x000
+#define CSI2_N_LANES0x004
+#define CSI2_PHY_SHUTDOWNZ  0x008
+#define CSI2_DPHY_RSTZ  0x00c
+#define CSI2_RESETN 0x010
+#define CSI2_PHY_STATE  0x014
+#define CSI2_DATA_IDS_1 0x018
+#define CSI2_DATA_IDS_2 0x01c
+#define CSI2_ERR1   0x020
+#define CSI2_ERR2   0x024
+#define CSI2_MSK1   0x028
+#define CSI2_MSK2   0x02c
+#define CSI2_PHY_TST_CTRL0  0x030
+#define CSI2_PHY_TST_CTRL1  0x034
+#define CSI2_SFT_RESET  0xf00
+
+static inline struct imxcsi2_dev *sd_to_dev(struct v4l2_subdev *sdev)
+{
+   return container_of(sdev, struct imxcsi2_dev, sd);
+}
+
+static inline u32 imxcsi2_read(struct imxcsi2_dev *csi2, unsigned int regoff)
+{
+   return readl(csi2->base + regoff);
+}
+
+static inline void imxcsi2_write(struct imxcsi2_dev *csi2, u32 val,
+unsigned int regoff)
+{
+   writel(val, csi2->base + regoff);
+}
+
+static void imxcsi2_set_lanes(struct imxcsi2_dev *csi2)
+{
+   int lanes = csi2->bus.num_data_lanes;
+   unsigned long flags;
+
+   spin_lock_irqsave(&csi2->lock, flags);
+
+   imxcsi2_write(csi2, lanes - 1, CSI2_N_LANES);
+
+   spin_unlock_irqrestore(&csi2->lock, flags);
+}
+
+static void __imxcsi2_enable(struct imxcsi2_dev *csi2, bool enable)
+{
+   if (enable) {
+   imxcsi2_write(csi2, 0x, CSI2_PHY_SHUTDOWNZ);
+   imxcsi2_write(csi2, 0x, CSI2_DPHY_RSTZ);
+   imxcsi2_write(csi2, 0x, CSI2_RESETN);
+   } else {
+   imxcsi2_write(csi2, 0x0, CSI2_PHY_SHUTDOWNZ);
+   imxcsi2_write(csi2, 0x0, CSI2_DPHY_RSTZ);
+   imxcsi2_write(csi2, 0x0, CSI2_RESETN);
+   }
+}
+
+static void imxcsi2_enable(struct imxcsi2_dev *csi2, bool enable)
+{
+   unsigned long flags;
+
+   spin_lock_irqsave(&csi2->lock, flags);
+   __imxcsi2_enable(csi2, enable);
+   spin_unlock_irqrestore(&csi2->lock, flags);
+}
+
+static void imxcsi2_reset(struct imxcsi2_dev

[PATCH 28/38] v4l: Add signal lock status to source change events

2016-06-14 Thread Steve Longerbeam
Add a signal lock status change to the source changes bitmask.
This indicates there was a signal lock or unlock event detected
at the input of a video decoder.

Signed-off-by: Steve Longerbeam 
---
 Documentation/DocBook/media/v4l/vidioc-dqevent.xml | 12 ++--
 include/uapi/linux/videodev2.h |  1 +
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/Documentation/DocBook/media/v4l/vidioc-dqevent.xml 
b/Documentation/DocBook/media/v4l/vidioc-dqevent.xml
index c9c3c77..7758ad7 100644
--- a/Documentation/DocBook/media/v4l/vidioc-dqevent.xml
+++ b/Documentation/DocBook/media/v4l/vidioc-dqevent.xml
@@ -233,8 +233,9 @@

  This event is triggered when a source parameter change is
   detected during runtime by the video device. It can be a
-  runtime resolution change triggered by a video decoder or the
-  format change happening on an input connector.
+  runtime resolution change or signal lock status change
+  triggered by a video decoder, or the format change happening
+  on an input connector.
   This event requires that the id
   matches the input index (when used with a video device node)
   or the pad index (when used with a subdevice node) from which
@@ -461,6 +462,13 @@
from a video decoder.

  
+ 
+   V4L2_EVENT_SRC_CH_LOCK_STATUS
+   0x0002
+   This event gets triggered when there is a signal lock or
+   unlock detected at the input of a video decoder.
+   
+ 

   
 
diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
index 8f95191..2eba5da 100644
--- a/include/uapi/linux/videodev2.h
+++ b/include/uapi/linux/videodev2.h
@@ -2076,6 +2076,7 @@ struct v4l2_event_frame_sync {
 };
 
 #define V4L2_EVENT_SRC_CH_RESOLUTION   (1 << 0)
+#define V4L2_EVENT_SRC_CH_LOCK_STATUS  (1 << 1)
 
 struct v4l2_event_src_change {
__u32 changes;
-- 
1.9.1

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


[PATCH 03/38] gpu: ipu-cpmem: Add ipu_cpmem_get_burstsize()

2016-06-14 Thread Steve Longerbeam
Adds ipu_cpmem_get_burstsize().

Signed-off-by: Steve Longerbeam 
---
 drivers/gpu/ipu-v3/ipu-cpmem.c | 6 ++
 include/video/imx-ipu-v3.h | 1 +
 2 files changed, 7 insertions(+)

diff --git a/drivers/gpu/ipu-v3/ipu-cpmem.c b/drivers/gpu/ipu-v3/ipu-cpmem.c
index a36c35e..fcb7dc8 100644
--- a/drivers/gpu/ipu-v3/ipu-cpmem.c
+++ b/drivers/gpu/ipu-v3/ipu-cpmem.c
@@ -275,6 +275,12 @@ void ipu_cpmem_set_axi_id(struct ipuv3_channel *ch, u32 id)
 }
 EXPORT_SYMBOL_GPL(ipu_cpmem_set_axi_id);
 
+int ipu_cpmem_get_burstsize(struct ipuv3_channel *ch)
+{
+   return ipu_ch_param_read_field(ch, IPU_FIELD_NPB) + 1;
+}
+EXPORT_SYMBOL_GPL(ipu_cpmem_get_burstsize);
+
 void ipu_cpmem_set_burstsize(struct ipuv3_channel *ch, int burstsize)
 {
ipu_ch_param_write_field(ch, IPU_FIELD_NPB, burstsize - 1);
diff --git a/include/video/imx-ipu-v3.h b/include/video/imx-ipu-v3.h
index 904fd12..60540ead 100644
--- a/include/video/imx-ipu-v3.h
+++ b/include/video/imx-ipu-v3.h
@@ -197,6 +197,7 @@ void ipu_cpmem_set_buffer(struct ipuv3_channel *ch, int 
bufnum, dma_addr_t buf);
 void ipu_cpmem_set_uv_offset(struct ipuv3_channel *ch, u32 u_off, u32 v_off);
 void ipu_cpmem_interlaced_scan(struct ipuv3_channel *ch, int stride);
 void ipu_cpmem_set_axi_id(struct ipuv3_channel *ch, u32 id);
+int ipu_cpmem_get_burstsize(struct ipuv3_channel *ch);
 void ipu_cpmem_set_burstsize(struct ipuv3_channel *ch, int burstsize);
 void ipu_cpmem_set_block_mode(struct ipuv3_channel *ch);
 void ipu_cpmem_set_rotation(struct ipuv3_channel *ch,
-- 
1.9.1

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


[PATCH 22/38] ARM: dts: imx6-sabreauto: add reset-gpios property for max7310

2016-06-14 Thread Steve Longerbeam
The reset pin to the port expander chip (MAX7310) is controlled by a gpio,
so define a reset-gpios property to control it.

Signed-off-by: Steve Longerbeam 
---
 arch/arm/boot/dts/imx6qdl-sabreauto.dtsi | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/arch/arm/boot/dts/imx6qdl-sabreauto.dtsi 
b/arch/arm/boot/dts/imx6qdl-sabreauto.dtsi
index 13f50e8..81e3ab7 100644
--- a/arch/arm/boot/dts/imx6qdl-sabreauto.dtsi
+++ b/arch/arm/boot/dts/imx6qdl-sabreauto.dtsi
@@ -129,6 +129,9 @@
reg = <0x30>;
gpio-controller;
#gpio-cells = <2>;
+   pinctrl-names = "default";  
+   pinctrl-0 = <&pinctrl_max7310>;
+   reset-gpios = <&gpio1 15 1>;
};
 
max7310_b: gpio@32 {
@@ -136,6 +139,9 @@
reg = <0x32>;
gpio-controller;
#gpio-cells = <2>;
+   pinctrl-names = "default";  
+   pinctrl-0 = <&pinctrl_max7310>;
+   reset-gpios = <&gpio1 15 1>;
};
 
max7310_c: gpio@34 {
@@ -143,6 +149,9 @@
reg = <0x34>;
gpio-controller;
#gpio-cells = <2>;
+   pinctrl-names = "default";  
+   pinctrl-0 = <&pinctrl_max7310>;
+   reset-gpios = <&gpio1 15 1>;
};
};
};
@@ -441,6 +450,12 @@
>;
};
 
+   pinctrl_max7310: max7310grp {
+   fsl,pins = <
+   MX6QDL_PAD_SD2_DAT0__GPIO1_IO15 0x8000
+   >;
+   };
+
pinctrl_pwm3: pwm1grp {
fsl,pins = <
MX6QDL_PAD_SD4_DAT1__PWM3_OUT   0x1b0b1
-- 
1.9.1

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


[PATCH 05/38] gpu: ipu-v3: Add IDMA channel linking support

2016-06-14 Thread Steve Longerbeam
Adds functions to link and unlink IDMAC source channels to sink
channels.

So far the following links are supported:

IPUV3_CHANNEL_IC_PRP_ENC_MEM -> IPUV3_CHANNEL_MEM_ROT_ENC
PUV3_CHANNEL_IC_PRP_VF_MEM   -> IPUV3_CHANNEL_MEM_ROT_VF
IPUV3_CHANNEL_IC_PP_MEM  -> IPUV3_CHANNEL_MEM_ROT_PP

More links can be added to the idmac_link_info[] array.

Signed-off-by: Steve Longerbeam 
---
 drivers/gpu/ipu-v3/ipu-common.c | 112 
 include/video/imx-ipu-v3.h  |   3 ++
 2 files changed, 115 insertions(+)

diff --git a/drivers/gpu/ipu-v3/ipu-common.c b/drivers/gpu/ipu-v3/ipu-common.c
index 49af121..6d1676e 100644
--- a/drivers/gpu/ipu-v3/ipu-common.c
+++ b/drivers/gpu/ipu-v3/ipu-common.c
@@ -730,6 +730,118 @@ void ipu_set_ic_src_mux(struct ipu_soc *ipu, int csi_id, 
bool vdi)
 }
 EXPORT_SYMBOL_GPL(ipu_set_ic_src_mux);
 
+
+/* IDMAC Channel Linking */
+
+struct idmac_link_reg_info {
+   int chno;
+   u32 reg;
+   int shift;
+   int bits;
+   u32 sel;
+};
+
+struct idmac_link_info {
+   struct idmac_link_reg_info src;
+   struct idmac_link_reg_info sink;
+};
+
+static const struct idmac_link_info idmac_link_info[] = {
+   {
+   .src  = { 20, IPU_FS_PROC_FLOW1,  0, 4, 7 },
+   .sink = { 45, IPU_FS_PROC_FLOW2,  0, 4, 1 },
+   }, {
+   .src =  { 21, IPU_FS_PROC_FLOW1,  8, 4, 8 },
+   .sink = { 46, IPU_FS_PROC_FLOW2,  4, 4, 1 },
+   }, {
+   .src =  { 22, IPU_FS_PROC_FLOW1, 16, 4, 5 },
+   .sink = { 47, IPU_FS_PROC_FLOW2, 12, 4, 3 },
+   },
+};
+
+static const struct idmac_link_info *find_idmac_link_info(
+   struct ipuv3_channel *src, struct ipuv3_channel *sink)
+{
+   int i;
+
+   for (i = 0; i < ARRAY_SIZE(idmac_link_info); i++) {
+   if (src->num == idmac_link_info[i].src.chno &&
+   sink->num == idmac_link_info[i].sink.chno)
+   return &idmac_link_info[i];
+   }
+
+   return NULL;
+}
+
+/*
+ * Links an IDMAC source channel to a sink channel.
+ */
+int ipu_idmac_link(struct ipuv3_channel *src, struct ipuv3_channel *sink)
+{
+   struct ipu_soc *ipu = src->ipu;
+   const struct idmac_link_info *link;
+   u32 src_reg, sink_reg, src_mask, sink_mask;
+   unsigned long flags;
+
+   link = find_idmac_link_info(src, sink);
+   if (!link)
+   return -EINVAL;
+
+   src_mask = ((1 << link->src.bits) - 1) << link->src.shift;
+   sink_mask = ((1 << link->sink.bits) - 1) << link->sink.shift;
+
+   spin_lock_irqsave(&ipu->lock, flags);
+
+   src_reg = ipu_cm_read(ipu, link->src.reg);
+   sink_reg = ipu_cm_read(ipu, link->sink.reg);
+
+   src_reg &= ~src_mask;
+   src_reg |= (link->src.sel << link->src.shift);
+
+   sink_reg &= ~sink_mask;
+   sink_reg |= (link->sink.sel << link->sink.shift);
+
+   ipu_cm_write(ipu, src_reg, link->src.reg);
+   ipu_cm_write(ipu, sink_reg, link->sink.reg);
+
+   spin_unlock_irqrestore(&ipu->lock, flags);
+   return 0;
+}
+EXPORT_SYMBOL_GPL(ipu_idmac_link);
+
+/*
+ * Unlinks IDMAC source and sink channels.
+ */
+int ipu_idmac_unlink(struct ipuv3_channel *src, struct ipuv3_channel *sink)
+{
+   struct ipu_soc *ipu = src->ipu;
+   const struct idmac_link_info *link;
+   u32 src_reg, sink_reg, src_mask, sink_mask;
+   unsigned long flags;
+
+   link = find_idmac_link_info(src, sink);
+   if (!link)
+   return -EINVAL;
+
+   src_mask = ((1 << link->src.bits) - 1) << link->src.shift;
+   sink_mask = ((1 << link->sink.bits) - 1) << link->sink.shift;
+
+   spin_lock_irqsave(&ipu->lock, flags);
+
+   src_reg = ipu_cm_read(ipu, link->src.reg);
+   sink_reg = ipu_cm_read(ipu, link->sink.reg);
+
+   src_reg &= ~src_mask;
+   sink_reg &= ~sink_mask;
+
+   ipu_cm_write(ipu, src_reg, link->src.reg);
+   ipu_cm_write(ipu, sink_reg, link->sink.reg);
+
+   spin_unlock_irqrestore(&ipu->lock, flags);
+   return 0;
+}
+EXPORT_SYMBOL_GPL(ipu_idmac_unlink);
+
 struct ipu_devtype {
const char *name;
unsigned long cm_ofs;
diff --git a/include/video/imx-ipu-v3.h b/include/video/imx-ipu-v3.h
index b174f8a..0a39c64 100644
--- a/include/video/imx-ipu-v3.h
+++ b/include/video/imx-ipu-v3.h
@@ -128,6 +128,7 @@ enum ipu_channel_irq {
 #define IPUV3_CHANNEL_ROT_VF_MEM   49
 #define IPUV3_CHANNEL_ROT_PP_MEM   50
 #define IPUV3_CHANNEL_MEM_BG_SYNC_ALPHA51
+#define IPUV3_NUM_CHANNELS 64
 
 int ipu_map_irq(struct ipu_soc *ipu, int irq);
 int ipu_idmac_channel_irq(struct ipu_soc *ipu, struct ipuv3_channel *channel,
@@ -171,6 +172,8 @@ int ipu_idmac_get_current_buffer(struct ipuv3_

[PATCH 38/38] ARM: imx_v6_v7_defconfig: Enable staging video4linux drivers

2016-06-14 Thread Steve Longerbeam
Enable imx v4l2 staging drivers. For video capture on
the SabreAuto, the ADV7180 video decoder also requires the
i2c-mux-gpio and the max7310 port expander.

Signed-off-by: Steve Longerbeam 
---
 arch/arm/configs/imx_v6_v7_defconfig | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/arm/configs/imx_v6_v7_defconfig 
b/arch/arm/configs/imx_v6_v7_defconfig
index 21339ce..8b1590a 100644
--- a/arch/arm/configs/imx_v6_v7_defconfig
+++ b/arch/arm/configs/imx_v6_v7_defconfig
@@ -327,6 +327,8 @@ CONFIG_FSL_EDMA=y
 CONFIG_IMX_SDMA=y
 CONFIG_MXS_DMA=y
 CONFIG_STAGING=y
+CONFIG_STAGING_MEDIA=y
+CONFIG_VIDEO_IMX=y
 # CONFIG_IOMMU_SUPPORT is not set
 CONFIG_IIO=y
 CONFIG_VF610_ADC=y
-- 
1.9.1

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


[PATCH 21/38] ARM: dts: imx6-sabreauto: create i2cmux for i2c3

2016-06-14 Thread Steve Longerbeam
The sabreauto uses a steering pin to select between the SDA signal on
i2c3 bus, and a data-in pin for an SPI NOR chip. Use i2cmux to control
this steering pin. Idle state of the i2cmux selects SPI NOR. This is not
a classic way to use i2cmux, since one side of the mux selects something
other than an i2c bus, but it works and is probably the cleanest
solution. Note that if one thread is attempting to access SPI NOR while
another thread is accessing i2c3, the SPI NOR access will fail since the
i2cmux has selected the SDA pin rather than SPI NOR data-in. This couldn't
be avoided in any case, the board is not designed to allow concurrent
i2c3 and SPI NOR functions (and the default device-tree does not enable
SPI NOR anyway).

Devices hanging off i2c3 should now be defined under i2cmux, so
that the steering pin can be properly controlled to access those
devices. The port expanders (MAX7310) are thus moved into i2cmux.

Signed-off-by: Steve Longerbeam 
---
 arch/arm/boot/dts/imx6qdl-sabreauto.dtsi | 65 +---
 1 file changed, 44 insertions(+), 21 deletions(-)

diff --git a/arch/arm/boot/dts/imx6qdl-sabreauto.dtsi 
b/arch/arm/boot/dts/imx6qdl-sabreauto.dtsi
index d354d40..13f50e8 100644
--- a/arch/arm/boot/dts/imx6qdl-sabreauto.dtsi
+++ b/arch/arm/boot/dts/imx6qdl-sabreauto.dtsi
@@ -108,6 +108,44 @@
default-brightness-level = <7>;
status = "okay";
};
+
+   i2cmux {
+   compatible = "i2c-mux-gpio";
+   #address-cells = <1>;
+   #size-cells = <0>;
+   pinctrl-names = "default";
+   pinctrl-0 = <&pinctrl_i2c3mux>;
+   mux-gpios = <&gpio5 4 0>;
+   i2c-parent = <&i2c3>;
+   idle-state = <0>;
+
+   i2c@1 {
+   #address-cells = <1>;
+   #size-cells = <0>;
+   reg = <1>;
+
+   max7310_a: gpio@30 {
+   compatible = "maxim,max7310";
+   reg = <0x30>;
+   gpio-controller;
+   #gpio-cells = <2>;
+   };
+
+   max7310_b: gpio@32 {
+   compatible = "maxim,max7310";
+   reg = <0x32>;
+   gpio-controller;
+   #gpio-cells = <2>;
+   };
+
+   max7310_c: gpio@34 {
+   compatible = "maxim,max7310";
+   reg = <0x34>;
+   gpio-controller;
+   #gpio-cells = <2>;
+   };
+   };
+   };
 };
 
 &clks {
@@ -290,27 +328,6 @@
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_i2c3>;
status = "okay";
-
-   max7310_a: gpio@30 {
-   compatible = "maxim,max7310";
-   reg = <0x30>;
-   gpio-controller;
-   #gpio-cells = <2>;
-   };
-
-   max7310_b: gpio@32 {
-   compatible = "maxim,max7310";
-   reg = <0x32>;
-   gpio-controller;
-   #gpio-cells = <2>;
-   };
-
-   max7310_c: gpio@34 {
-   compatible = "maxim,max7310";
-   reg = <0x34>;
-   gpio-controller;
-   #gpio-cells = <2>;
-   };
 };
 
 &iomuxc {
@@ -418,6 +435,12 @@
>;
};
 
+   pinctrl_i2c3mux: i2c3muxgrp {
+   fsl,pins = <
+   MX6QDL_PAD_EIM_A24__GPIO5_IO04 0x8000
+   >;
+   };
+
pinctrl_pwm3: pwm1grp {
fsl,pins = <
MX6QDL_PAD_SD4_DAT1__PWM3_OUT   0x1b0b1
-- 
1.9.1

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


[PATCH 17/38] ARM: dts: imx6qdl: Flesh out MIPI CSI2 receiver node

2016-06-14 Thread Steve Longerbeam
Add to the MIPI CSI2 receiver node: compatible string, interrupt sources,
clocks.

Signed-off-by: Steve Longerbeam 
---
 arch/arm/boot/dts/imx6qdl.dtsi | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/arch/arm/boot/dts/imx6qdl.dtsi b/arch/arm/boot/dts/imx6qdl.dtsi
index ed613eb..50499eb 100644
--- a/arch/arm/boot/dts/imx6qdl.dtsi
+++ b/arch/arm/boot/dts/imx6qdl.dtsi
@@ -1119,7 +1119,14 @@
};
 
mipi_csi: mipi@021dc000 {
+   compatible = "fsl,imx-mipi-csi2";
reg = <0x021dc000 0x4000>;
+   interrupts = <0 100 0x04>, <0 101 0x04>;
+   clocks = <&clks IMX6QDL_CLK_HSI_TX>,
+<&clks IMX6QDL_CLK_VIDEO_27M>,
+<&clks IMX6QDL_CLK_EIM_SEL>;
+   clock-names = "dphy_clk", "cfg_clk", "pix_clk";
+   status = "disabled";
};
 
mipi_dsi: mipi@021e {
-- 
1.9.1

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


[PATCH 14/38] gpu: ipu-ic: Add complete image conversion support with tiling

2016-06-14 Thread Steve Longerbeam
This patch implements complete image conversion support to ipu-ic,
with tiling to support scaling to and from images up to 4096x4096.
Image rotation is also supported.

The internal API is subsystem agnostic (no V4L2 dependency except
for the use of V4L2 fourcc pixel formats).

Callers prepare for image conversion by calling
ipu_image_convert_prepare(), which initializes the parameters of
the conversion. The caller passes in the ipu_ic task to use for
the conversion, the input and output image formats, a rotation mode,
and a completion callback and completion context pointer:

struct image_converter_ctx *
ipu_image_convert_prepare(struct ipu_ic *ic,
  struct ipu_image *in, struct ipu_image *out,
  enum ipu_rotate_mode rot_mode,
  image_converter_cb_t complete,
  void *complete_context);

The caller is given a new conversion context that must be passed to
the further APIs:

struct image_converter_run *
ipu_image_convert_run(struct image_converter_ctx *ctx,
  dma_addr_t in_phys, dma_addr_t out_phys);

This queues a new image conversion request to a run queue, and
starts the conversion immediately if the run queue is empty. Only
the physaddr's of the input and output image buffers are needed,
since the conversion context was created previously with
ipu_image_convert_prepare(). Returns a new run object pointer. When
the conversion completes, the run pointer is returned to the
completion callback.

void image_convert_abort(struct image_converter_ctx *ctx);

This will abort any active or pending conversions for this context.
Any currently active or pending runs belonging to this context are
returned via the completion callback with an error status.

void ipu_image_convert_unprepare(struct image_converter_ctx *ctx);

Unprepares the conversion context. Any active or pending runs will
be aborted by calling image_convert_abort().
---
 drivers/gpu/ipu-v3/ipu-ic.c | 1691 ++-
 include/video/imx-ipu-v3.h  |   57 +-
 2 files changed, 1736 insertions(+), 12 deletions(-)

diff --git a/drivers/gpu/ipu-v3/ipu-ic.c b/drivers/gpu/ipu-v3/ipu-ic.c
index 5329bfe..f6a1125 100644
--- a/drivers/gpu/ipu-v3/ipu-ic.c
+++ b/drivers/gpu/ipu-v3/ipu-ic.c
@@ -17,6 +17,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 #include "ipu-prv.h"
 
 /* IC Register Offsets */
@@ -82,6 +84,40 @@
 #define IC_IDMAC_3_PP_WIDTH_MASK(0x3ff << 20)
 #define IC_IDMAC_3_PP_WIDTH_OFFSET  20
 
+/*
+ * The IC Resizer has a restriction that the output frame from the
+ * resizer must be 1024 or less in both width (pixels) and height
+ * (lines).
+ *
+ * The image conversion support attempts to split up a conversion when
+ * the desired output (converted) frame resolution exceeds the IC resizer
+ * limit of 1024 in either dimension.
+ *
+ * If either dimension of the output frame exceeds the limit, the
+ * dimension is split into 1, 2, or 4 equal stripes, for a maximum
+ * of 4*4 or 16 tiles. A conversion is then carried out for each
+ * tile (but taking care to pass the full frame stride length to
+ * the DMA channel's parameter memory!). IDMA double-buffering is used
+ * to convert each tile back-to-back when possible (see note below
+ * when double_buffering boolean is set).
+ *
+ * Note that the input frame must be split up into the same number
+ * of tiles as the output frame.
+ */
+#define MAX_STRIPES_W4
+#define MAX_STRIPES_H4
+#define MAX_TILES (MAX_STRIPES_W * MAX_STRIPES_H)
+
+#define MIN_W 128
+#define MIN_H 128
+#define MAX_W 4096
+#define MAX_H 4096
+
+enum image_convert_type {
+   IMAGE_CONVERT_IN = 0,
+   IMAGE_CONVERT_OUT,
+};
+
 struct ic_task_regoffs {
u32 rsc;
u32 tpmem_csc[2];
@@ -96,6 +132,16 @@ struct ic_task_bitfields {
u32 ic_cmb_galpha_bit;
 };
 
+struct ic_task_channels {
+   int in;
+   int out;
+   int rot_in;
+   int rot_out;
+   int vdi_in_p;
+   int vdi_in;
+   int vdi_in_n;
+};
+
 static const struct ic_task_regoffs ic_task_reg[IC_NUM_TASKS] = {
[IC_TASK_ENCODER] = {
.rsc = IC_PRP_ENC_RSC,
@@ -138,12 +184,159 @@ static const struct ic_task_bitfields 
ic_task_bit[IC_NUM_TASKS] = {
},
 };
 
+static const struct ic_task_channels ic_task_ch[IC_NUM_TASKS] = {
+   [IC_TASK_ENCODER] = {
+   .out = IPUV3_CHANNEL_IC_PRP_ENC_MEM,
+   .rot_in = IPUV3_CHANNEL_MEM_ROT_ENC,
+   .rot_out = IPUV3_CHANNEL_ROT_ENC_MEM,
+   },
+   [IC_TASK_VIEWFINDER] = {
+   .in = IPUV3_CHANNEL_MEM_IC_PRP_VF,
+   .out = IPUV3_CHANNEL_IC_PRP_VF_MEM,
+   .rot_in = IPUV3_CHANNEL_MEM_ROT_VF,
+   .rot_out = IPUV3_CHANNEL_ROT_VF_MEM,
+   .vdi_in_p = IPUV3_CHANNEL_MEM_VDI_P,
+   .vdi_in = IPUV3_CHANNEL_MEM_VDI,
+   .vdi_in_n = IPUV3_CHANNEL_MEM_VDI_N,
+

[PATCH 24/38] ARM: dts: imx6-sabreauto: add video capture ports and connections

2016-06-14 Thread Steve Longerbeam
Defines the host video capture device node and the ADV7180 decoder
sensor. The host capture device connects to the ADV7180 via the
parallel-bus mux input on the ipu1_csi0_mux.

On the sabreauto, two analog video inputs are routed to the ADV7180,
composite on Ain1, and composite on Ain3. Those inputs are defined
via inputs and input-names under the endpoint node
ipu1_csi0_from_ipu1_csi0_mux. The ADV7180 power pin is via max7310_b
port expander.

Signed-off-by: Steve Longerbeam 
---
 arch/arm/boot/dts/imx6qdl-sabreauto.dtsi | 68 
 1 file changed, 68 insertions(+)

diff --git a/arch/arm/boot/dts/imx6qdl-sabreauto.dtsi 
b/arch/arm/boot/dts/imx6qdl-sabreauto.dtsi
index 21af432..f962f51 100644
--- a/arch/arm/boot/dts/imx6qdl-sabreauto.dtsi
+++ b/arch/arm/boot/dts/imx6qdl-sabreauto.dtsi
@@ -153,10 +153,54 @@
pinctrl-0 = <&pinctrl_max7310>;
reset-gpios = <&gpio1 15 1>;
};
+
+   camera: adv7180@21 {
+   compatible = "adi,adv7180";
+   reg = <0x21>;
+   pwdn-gpio = <&max7310_b 2 0>;
+   interrupt-parent = <&gpio1>;
+   interrupts = <27 0x8>;
+
+   port {
+   adv7180_to_ipu1_csi0_mux: endpoint {
+   remote-endpoint = 
<&ipu1_csi0_mux_from_parallel_sensor>;
+   bus-width = <8>;
+   };
+   };
+   };
+   };
+   };
+
+   ipucap0: ipucap0 {
+   compatible = "fsl,imx-video-capture";
+   #address-cells = <1>;
+   #size-cells = <0>;
+   pinctrl-names = "default";
+   pinctrl-0 = <&pinctrl_ipu1_csi0>;
+   ports = <&ipu1_csi0>;
+   status = "okay";
+
+   fim {
+   enable = <1>;
};
};
 };
 
+&ipu1_csi0_from_ipu1_csi0_mux {
+   bus-width = <8>;
+};
+
+&ipu1_csi0_mux_from_parallel_sensor {
+   remote-endpoint = <&adv7180_to_ipu1_csi0_mux>;
+   inputs = <0x00 0x02>;
+   input-names = "ADV7180 Composite on Ain1",
+   "ADV7180 Composite on Ain3";
+};
+
+&ipu1_csi0_mux {
+   status = "okay";
+};
+
 &clks {
assigned-clocks = <&clks IMX6QDL_PLL4_BYPASS_SRC>,
  <&clks IMX6QDL_PLL4_BYPASS>,
@@ -456,6 +500,30 @@
>;
};
 
+   pinctrl_ipu1_csi0: ipu1grp-csi0 {
+   fsl,pins = <
+   MX6QDL_PAD_CSI0_DAT4__IPU1_CSI0_DATA04   
0x8000
+   MX6QDL_PAD_CSI0_DAT5__IPU1_CSI0_DATA05   
0x8000
+   MX6QDL_PAD_CSI0_DAT6__IPU1_CSI0_DATA06   
0x8000
+   MX6QDL_PAD_CSI0_DAT7__IPU1_CSI0_DATA07   
0x8000
+   MX6QDL_PAD_CSI0_DAT8__IPU1_CSI0_DATA08   
0x8000
+   MX6QDL_PAD_CSI0_DAT9__IPU1_CSI0_DATA09   
0x8000
+   MX6QDL_PAD_CSI0_DAT10__IPU1_CSI0_DATA10  
0x8000
+   MX6QDL_PAD_CSI0_DAT11__IPU1_CSI0_DATA11  
0x8000
+   MX6QDL_PAD_CSI0_DAT12__IPU1_CSI0_DATA12  
0x8000
+   MX6QDL_PAD_CSI0_DAT13__IPU1_CSI0_DATA13  
0x8000
+   MX6QDL_PAD_CSI0_DAT14__IPU1_CSI0_DATA14  
0x8000
+   MX6QDL_PAD_CSI0_DAT15__IPU1_CSI0_DATA15  
0x8000
+   MX6QDL_PAD_CSI0_DAT16__IPU1_CSI0_DATA16  
0x8000
+   MX6QDL_PAD_CSI0_DAT17__IPU1_CSI0_DATA17  
0x8000
+   MX6QDL_PAD_CSI0_DAT18__IPU1_CSI0_DATA18  
0x8000
+   MX6QDL_PAD_CSI0_DAT19__IPU1_CSI0_DATA19  
0x8000
+   MX6QDL_PAD_CSI0_PIXCLK__IPU1_CSI0_PIXCLK 
0x8000
+   MX6QDL_PAD_CSI0_MCLK__IPU1_CSI0_HSYNC
0x8000
+   MX6QDL_PAD_CSI0_VSYNC__IPU1_CSI0_VSYNC   
0x8000
+   >;
+   };
+
pinctrl_pwm3: pwm1grp {
fsl,pins = <
MX6QDL_PAD_SD4_DAT1__PWM3_OUT   0x1b0b1
-- 
1.9.1

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


[PATCH 16/38] gpu: ipu-v3: rename CSI client device

2016-06-14 Thread Steve Longerbeam
Rename the CSI client device in the client_reg[] table to
"imx-ipuv3-csi".

Signed-off-by: Steve Longerbeam 
---
 drivers/gpu/ipu-v3/ipu-common.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/ipu-v3/ipu-common.c b/drivers/gpu/ipu-v3/ipu-common.c
index 374100e..bd6771b 100644
--- a/drivers/gpu/ipu-v3/ipu-common.c
+++ b/drivers/gpu/ipu-v3/ipu-common.c
@@ -1153,14 +1153,14 @@ static struct ipu_platform_reg client_reg[] = {
.dma[0] = IPUV3_CHANNEL_CSI0,
.dma[1] = -EINVAL,
},
-   .name = "imx-ipuv3-camera",
+   .name = "imx-ipuv3-csi",
}, {
.pdata = {
.csi = 1,
.dma[0] = IPUV3_CHANNEL_CSI1,
.dma[1] = -EINVAL,
},
-   .name = "imx-ipuv3-camera",
+   .name = "imx-ipuv3-csi",
}, {
.pdata = {
.di = 0,
-- 
1.9.1

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


[PATCH 35/38] media: adv7180: add power pin control

2016-06-14 Thread Steve Longerbeam
Some targets control the ADV7180 power pin via a gpio, so add
support for "pwdn-gpio" device node and pin control.

Signed-off-by: Steve Longerbeam 
---
 drivers/media/i2c/adv7180.c | 51 +
 1 file changed, 51 insertions(+)

diff --git a/drivers/media/i2c/adv7180.c b/drivers/media/i2c/adv7180.c
index b77b0a4..b3bb19f 100644
--- a/drivers/media/i2c/adv7180.c
+++ b/drivers/media/i2c/adv7180.c
@@ -26,6 +26,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -192,6 +193,7 @@ struct adv7180_state {
struct media_padpad;
struct mutexmutex; /* mutual excl. when accessing chip */
int irq;
+   int pwdn_gpio;
v4l2_std_id curr_norm;
boolpowered;
boolstreaming;
@@ -442,6 +444,19 @@ static int adv7180_g_std(struct v4l2_subdev *sd, 
v4l2_std_id *norm)
return 0;
 }
 
+static void adv7180_set_power_pin(struct adv7180_state *state, bool on)
+{
+   if (!gpio_is_valid(state->pwdn_gpio))
+   return;
+
+   if (on) {
+   gpio_set_value_cansleep(state->pwdn_gpio, 1);
+   usleep_range(5000, 5001);
+   } else {
+   gpio_set_value_cansleep(state->pwdn_gpio, 0);
+   }
+}
+
 static int adv7180_set_power(struct adv7180_state *state, bool on)
 {
u8 val;
@@ -1185,6 +1200,8 @@ static int init_device(struct adv7180_state *state)
 
mutex_lock(&state->mutex);
 
+   adv7180_set_power_pin(state, true);
+
adv7180_write(state, ADV7180_REG_PWR_MAN, ADV7180_PWR_MAN_RES);
usleep_range(5000, 1);
 
@@ -1232,6 +1249,34 @@ out_unlock:
return ret;
 }
 
+static int adv7180_of_parse(struct adv7180_state *state)
+{
+   struct i2c_client *client = state->client;
+   struct device_node *np = client->dev.of_node;
+   int ret;
+
+   ret = of_get_named_gpio(np, "pwdn-gpio", 0);
+
+   if (gpio_is_valid(ret)) {
+   state->pwdn_gpio = ret;
+   ret = devm_gpio_request_one(&client->dev,
+   state->pwdn_gpio,
+   GPIOF_OUT_INIT_HIGH,
+   "adv7180_pwdn");
+   if (ret < 0) {
+   v4l_err(client, "request for power pin failed\n");
+   return ret;
+   }
+   } else {
+   if (ret == -EPROBE_DEFER)
+   return ret;
+   /* assume a power-down gpio is not required */
+   state->pwdn_gpio = -1;
+   }
+
+   return 0;
+}
+
 static int adv7180_probe(struct i2c_client *client,
 const struct i2c_device_id *id)
 {
@@ -1254,6 +1299,10 @@ static int adv7180_probe(struct i2c_client *client,
state->field = V4L2_FIELD_INTERLACED;
state->chip_info = (struct adv7180_chip_info *)id->driver_data;
 
+   ret = adv7180_of_parse(state);
+   if (ret)
+   return ret;
+
if (state->chip_info->flags & ADV7180_FLAG_MIPI_CSI2) {
state->csi_client = i2c_new_dummy(client->adapter,
ADV7180_DEFAULT_CSI_I2C_ADDR);
@@ -1345,6 +1394,8 @@ static int adv7180_remove(struct i2c_client *client)
if (state->chip_info->flags & ADV7180_FLAG_MIPI_CSI2)
i2c_unregister_device(state->csi_client);
 
+   adv7180_set_power_pin(state, false);
+
mutex_destroy(&state->mutex);
 
return 0;
-- 
1.9.1

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


[PATCH 20/38] ARM: dts: imx6-sabresd: add video capture ports and connections

2016-06-14 Thread Steve Longerbeam
Defines the host ipu-capture device node and two camera sensors:
parallel-bus OV5642 and MIPI CSI-2 OV5640.

The host capture device connects to the OV5642 via the parallel-bus
mux input on the ipu1_csi0_mux.

The host capture device connects to the OV5640 via the MIPI CSI-2
receiver (directly on virtual channel 1 to ipu1_csi1 on imx6q, and
indirectly via the ipu1_csi1_mux on imx6dl).

Signed-off-by: Steve Longerbeam 
---
 arch/arm/boot/dts/imx6dl-sabresd.dts   |  44 +++
 arch/arm/boot/dts/imx6q-sabresd.dts|  16 
 arch/arm/boot/dts/imx6qdl-sabresd.dtsi | 139 -
 3 files changed, 198 insertions(+), 1 deletion(-)

diff --git a/arch/arm/boot/dts/imx6dl-sabresd.dts 
b/arch/arm/boot/dts/imx6dl-sabresd.dts
index 1e45f2f..0a4bfc2 100644
--- a/arch/arm/boot/dts/imx6dl-sabresd.dts
+++ b/arch/arm/boot/dts/imx6dl-sabresd.dts
@@ -15,3 +15,47 @@
model = "Freescale i.MX6 DualLite SABRE Smart Device Board";
compatible = "fsl,imx6dl-sabresd", "fsl,imx6dl";
 };
+
+&ipu1_csi1_from_ipu1_csi1_mux {
+   data-lanes = <0 1>;
+   clock-lanes = <2>;
+};
+
+&ipu1_csi1_mux {
+   status = "okay";
+};
+
+/*
+ * if the OV5642 sensor is enabled, the ipu1_csi0_mux is also enabled,
+ * but we don't want to find the OV5640 through ipu1_csi0_mux path to the
+ * mipi-csi2 receiver, so shutdown the link to the mipi-csi2 receiver at
+ * all virtual channels.
+*/
+#ifdef __ENABLE_OV5642__
+&ipu1_csi0_mux_from_mipi_vc0 {
+   remote-endpoint = <>;
+};
+&ipu1_csi0_mux_from_mipi_vc1 {
+   remote-endpoint = <>;
+};
+&ipu1_csi0_mux_from_mipi_vc2 {
+   remote-endpoint = <>;
+};
+&ipu1_csi0_mux_from_mipi_vc3 {
+   remote-endpoint = <>;
+};
+#endif
+
+/*
+ * shutdown links to mipi-csi2 channels 0,2,3 through ipu1_csi1_mux. The
+ * OV5640 is on VC1, so it must be found only on that ipu1_csi1_mux input.
+ */
+&ipu1_csi1_mux_from_mipi_vc0 {
+   remote-endpoint = <>;
+};
+&ipu1_csi1_mux_from_mipi_vc2 {
+   remote-endpoint = <>;
+};
+&ipu1_csi1_mux_from_mipi_vc3 {
+   remote-endpoint = <>;
+};
diff --git a/arch/arm/boot/dts/imx6q-sabresd.dts 
b/arch/arm/boot/dts/imx6q-sabresd.dts
index 9cbdfe7..ade6305 100644
--- a/arch/arm/boot/dts/imx6q-sabresd.dts
+++ b/arch/arm/boot/dts/imx6q-sabresd.dts
@@ -23,3 +23,19 @@
 &sata {
status = "okay";
 };
+
+&ipu1_csi1_from_mipi_vc1 {
+   data-lanes = <0 1>;
+   clock-lanes = <2>;
+};
+
+/*
+ * if the OV5642 sensor is enabled, the ipu1_csi0_mux is also enabled,
+ * but we don't want to find the OV5640 through ipu1_csi0_mux path, so
+ * shutdown the link to the mipi-csi2 receiver.
+*/
+#ifdef __ENABLE_OV5642__
+&ipu1_csi0_mux_from_mipi_vc0 {
+   remote-endpoint = <>;
+};
+#endif
diff --git a/arch/arm/boot/dts/imx6qdl-sabresd.dtsi 
b/arch/arm/boot/dts/imx6qdl-sabresd.dtsi
index 5248e7b..ce575e6 100644
--- a/arch/arm/boot/dts/imx6qdl-sabresd.dtsi
+++ b/arch/arm/boot/dts/imx6qdl-sabresd.dtsi
@@ -10,6 +10,10 @@
  * http://www.gnu.org/copyleft/gpl.html
  */
 
+/* Uncomment to enable parallel interface OV5642 on i2c1 and port csi0 */
+/* #define __ENABLE_OV5642__ */
+
+#include 
 #include 
 #include 
 
@@ -144,6 +148,54 @@
};
};
};
+
+#ifdef __ENABLE_OV5642__
+   ipucap0: ipucap@0 {
+   compatible = "fsl,imx-video-capture";
+   #address-cells = <1>;
+   #size-cells = <0>;
+   pinctrl-names = "default";
+   pinctrl-0 = <&pinctrl_ipu1_csi0>;
+   ports = <&ipu1_csi0>;
+   status = "okay";
+   };
+#endif
+
+   ipucap1: ipucap@1 {
+   compatible = "fsl,imx-video-capture";
+   #address-cells = <1>;
+   #size-cells = <0>;
+   ports = <&ipu1_csi1>;
+   status = "okay";
+   };
+};
+
+#ifdef __ENABLE_OV5642__
+&ipu1_csi0_from_ipu1_csi0_mux {
+   bus-width = <8>;
+   data-shift = <12>; /* Lines 19:12 used */
+   hsync-active = <1>;
+   vsync-active = <1>;
+};
+
+&ipu1_csi0_mux_from_parallel_sensor {
+   remote-endpoint = <&ov5642_to_ipu1_csi0_mux>;
+};
+
+&ipu1_csi0_mux {
+   status = "okay";
+};
+#endif
+
+&mipi_csi {
+   status = "okay";
+};
+
+/* Incoming port from sensor */
+&mipi_csi_from_mipi_sensor {
+   remote-endpoint = <&ov5640_to_mipi_csi>;
+   data-lanes = <0 1>;
+   clock-lanes = <2>;
 };
 
 &audmux {
@@ -214,7 +266,34 @@
0x8014 /* 4:FN_DMICCDAT */
0x /* 5:Default */
>;
-   };
+   };
+
+#ifde

[PATCH 37/38] media: Add i.MX5/6 mem2mem driver

2016-06-14 Thread Steve Longerbeam
Adds a V4L2 mem2mem driver for i.MX5/6 SoC. Uses the IPU IC image
converter (post-processor task) to perform scaling, rotation, and
color space conversion.

Signed-off-by: Steve Longerbeam 
---
 Documentation/devicetree/bindings/media/imx.txt |   25 +-
 drivers/staging/media/imx/Kconfig   |   12 +
 drivers/staging/media/imx/Makefile  |1 +
 drivers/staging/media/imx/m2m/Makefile  |1 +
 drivers/staging/media/imx/m2m/imx-m2m.c | 1049 +++
 5 files changed, 1087 insertions(+), 1 deletion(-)
 create mode 100644 drivers/staging/media/imx/m2m/Makefile
 create mode 100644 drivers/staging/media/imx/m2m/imx-m2m.c

diff --git a/Documentation/devicetree/bindings/media/imx.txt 
b/Documentation/devicetree/bindings/media/imx.txt
index 1f2ca4b..12ef06c 100644
--- a/Documentation/devicetree/bindings/media/imx.txt
+++ b/Documentation/devicetree/bindings/media/imx.txt
@@ -1,4 +1,27 @@
-Freescale i.MX Video Capture
+Freescale i.MX Video Capture, Mem2Mem
+
+Video Mem2Mem node
+--
+
+This is the imx video mem2mem device node. The mem2mem node is an IPU
+client and uses the register-level primitives of the IPU, so it does
+not require reg or interrupt properties. Only a compatible property
+and the ipu phandle is required.
+
+Required properties:
+- compatible   : "fsl,imx-video-mem2mem";
+- ipu   : the ipu phandle;
+
+Example:
+
+/ {
+   ipum2m0: ipum2m@ipu1 {
+   compatible = "fsl,imx-video-mem2mem";
+   ipu = <&ipu1>;
+   status = "okay";
+   };
+};
+
 
 Video Capture node
 --
diff --git a/drivers/staging/media/imx/Kconfig 
b/drivers/staging/media/imx/Kconfig
index 65e1645..3305daa 100644
--- a/drivers/staging/media/imx/Kconfig
+++ b/drivers/staging/media/imx/Kconfig
@@ -21,3 +21,15 @@ config VIDEO_IMX_CAMERA
 if VIDEO_IMX_CAMERA
 source "drivers/staging/media/imx/capture/Kconfig"
 endif
+
+config VIDEO_IMX_M2M
+   tristate "i.MX5/6 Mem2Mem driver"
+   depends on VIDEO_IMX && VIDEO_DEV
+   select VIDEOBUF2_DMA_CONTIG
+   select V4L2_MEM2MEM_DEV
+   default y
+   ---help---
+ Use the IPU IC Post-processor on the i.MX5/6 SoC for mem2mem
+ processing of buffers. Operations include scaling, rotation,
+ and color space conversion. The driver implements tiling to
+ support scaling up to 4096x4096.
diff --git a/drivers/staging/media/imx/Makefile 
b/drivers/staging/media/imx/Makefile
index 7c97629..b9e31d8 100644
--- a/drivers/staging/media/imx/Makefile
+++ b/drivers/staging/media/imx/Makefile
@@ -1 +1,2 @@
 obj-$(CONFIG_VIDEO_IMX_CAMERA) += capture/
+obj-$(CONFIG_VIDEO_IMX_M2M) += m2m/
diff --git a/drivers/staging/media/imx/m2m/Makefile 
b/drivers/staging/media/imx/m2m/Makefile
new file mode 100644
index 000..287d258
--- /dev/null
+++ b/drivers/staging/media/imx/m2m/Makefile
@@ -0,0 +1 @@
+obj-$(CONFIG_VIDEO_IMX_M2M) += imx-m2m.o
diff --git a/drivers/staging/media/imx/m2m/imx-m2m.c 
b/drivers/staging/media/imx/m2m/imx-m2m.c
new file mode 100644
index 000..599f20e
--- /dev/null
+++ b/drivers/staging/media/imx/m2m/imx-m2m.c
@@ -0,0 +1,1049 @@
+/*
+ * This is a mem2mem driver for the Freescale i.MX5/6 SOC. It carries out
+ * color-space conversion, downsizing, resizing, and rotation transformations
+ * on input buffers using the IPU Image Converter's Post-Processing task.
+ *
+ * Based on mem2mem_testdev.c by Pawel Osciak.
+ *
+ * Copyright (c) 2012-2013 Mentor Graphics Inc.
+ * Steve Longerbeam 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+MODULE_DESCRIPTION("i.MX5/6 Post-Processing mem2mem device");
+MODULE_AUTHOR("Steve Longerbeam ");
+MODULE_LICENSE("GPL");
+MODULE_VERSION("0.1");
+
+static int instrument;
+module_param(instrument, int, 0);
+MODULE_PARM_DESC(instrument, "1 = enable conversion time measurement");
+
+/* Flags that indicate a format can be used for capture/output */
+#define MEM2MEM_CAPTURE BIT(0)
+#define MEM2MEM_OUTPUT  BIT(1)
+
+#define MEM2MEM_NAME   "imx-m2m"
+
+/* Per queue */
+#define MEM2MEM_DEF_NUM_BUFS   VIDEO_MAX_FRAME
+/* In bytes, per queue */
+#define MEM2MEM_VID_MEM_LIMIT  SZ_256M
+
+#define dprintk(dev, fmt, arg...) \
+   v4l2_dbg(1, 1, &dev->v4l2_dev, "%s: " fmt, __func__, ## arg)
+
+struct m2mx_ctx;
+
+struct m2mx_dev {
+   struct v4l2_device  v4l2_dev;
+   struct video_device *vfd;
+   struct device   *

[PATCH 36/38] media: adv7180: implement g_parm

2016-06-14 Thread Steve Longerbeam
Implement g_parm to return the current standard's frame period.

Signed-off-by: Steve Longerbeam 
---
 drivers/media/i2c/adv7180.c | 22 ++
 1 file changed, 22 insertions(+)

diff --git a/drivers/media/i2c/adv7180.c b/drivers/media/i2c/adv7180.c
index b3bb19f..9e40632 100644
--- a/drivers/media/i2c/adv7180.c
+++ b/drivers/media/i2c/adv7180.c
@@ -740,6 +740,27 @@ static int adv7180_g_mbus_config(struct v4l2_subdev *sd,
return 0;
 }
 
+static int adv7180_g_parm(struct v4l2_subdev *sd, struct v4l2_streamparm *a)
+{
+   struct adv7180_state *state = to_state(sd);
+   struct v4l2_captureparm *cparm = &a->parm.capture;
+
+   if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
+   return -EINVAL;
+
+   memset(a, 0, sizeof(*a));
+   a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+   if (state->curr_norm & V4L2_STD_525_60) {
+   cparm->timeperframe.numerator = 1001;
+   cparm->timeperframe.denominator = 3;
+   } else {
+   cparm->timeperframe.numerator = 1;
+   cparm->timeperframe.denominator = 25;
+   }
+
+   return 0;
+}
+
 static int adv7180_cropcap(struct v4l2_subdev *sd, struct v4l2_cropcap 
*cropcap)
 {
struct adv7180_state *state = to_state(sd);
@@ -798,6 +819,7 @@ static int adv7180_subscribe_event(struct v4l2_subdev *sd,
 static const struct v4l2_subdev_video_ops adv7180_video_ops = {
.s_std = adv7180_s_std,
.g_std = adv7180_g_std,
+   .g_parm = adv7180_g_parm,
.querystd = adv7180_querystd,
.g_input_status = adv7180_g_input_status,
.s_routing = adv7180_s_routing,
-- 
1.9.1

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


[PATCH 19/38] ARM: dts: imx6-sabrelite: add video capture ports and connections

2016-06-14 Thread Steve Longerbeam
Defines the host video capture device node and an OV5642 camera sensor
node on i2c2. The host capture device connects to the OV5642 via the
parallel-bus mux input on the ipu1_csi0_mux.

Note there is a pin conflict with GPIO6. This pin functions as a power
input pin to the OV5642, but ENET requires it to wake-up the ARM cores
on normal RX and TX packet done events (see 6261c4c8). So by default,
capture is disabled, enable by uncommenting __OV5642_CAPTURE__ macro.
Ethernet will still work just not quite as well.

Signed-off-by: Steve Longerbeam 
---
 arch/arm/boot/dts/imx6qdl-sabrelite.dtsi | 95 
 1 file changed, 95 insertions(+)

diff --git a/arch/arm/boot/dts/imx6qdl-sabrelite.dtsi 
b/arch/arm/boot/dts/imx6qdl-sabrelite.dtsi
index c47fe6c..9709183 100644
--- a/arch/arm/boot/dts/imx6qdl-sabrelite.dtsi
+++ b/arch/arm/boot/dts/imx6qdl-sabrelite.dtsi
@@ -39,9 +39,20 @@
  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  * OTHER DEALINGS IN THE SOFTWARE.
  */
+
+#include 
 #include 
 #include 
 
+/*
+ * Uncomment the following macro to enable OV5642 video capture
+ * support. There is a pin conflict for GPIO6 between ENET wake-up
+ * interrupt function and power-down pin function for the OV5642.
+ * ENET will still work when enabling OV5642 capture, just not
+ * quite as well.
+ */
+/* #define __OV5642_CAPTURE__ */
+
 / {
chosen {
stdout-path = &uart2;
@@ -218,8 +229,37 @@
};
};
};
+
+#ifdef __OV5642_CAPTURE__
+   ipucap0: ipucap@0 {
+   compatible = "fsl,imx-video-capture";
+   #address-cells = <1>;
+   #size-cells = <0>;
+   pinctrl-names = "default";
+   pinctrl-0 = <&pinctrl_ipu1_csi0>;
+   ports = <&ipu1_csi0>;
+   status = "okay";
+   };
+#endif
+};
+
+#ifdef __OV5642_CAPTURE__
+&ipu1_csi0_from_ipu1_csi0_mux {
+   bus-width = <8>;
+   data-shift = <12>; /* Lines 19:12 used */
+   hsync-active = <1>;
+   vync-active = <1>;
 };
 
+&ipu1_csi0_mux_from_parallel_sensor {
+   remote-endpoint = <&ov5642_to_ipu1_csi0_mux>;
+};
+
+&ipu1_csi0_mux {
+   status = "okay";
+};
+#endif
+   
 &audmux {
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_audmux>;
@@ -271,8 +311,11 @@
txd1-skew-ps = <0>;
txd2-skew-ps = <0>;
txd3-skew-ps = <0>;
+#ifndef __OV5642_CAPTURE__
interrupts-extended = <&gpio1 6 IRQ_TYPE_LEVEL_HIGH>,
  <&intc 0 119 IRQ_TYPE_LEVEL_HIGH>;
+
+#endif
status = "okay";
 };
 
@@ -301,6 +344,30 @@
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_i2c2>;
status = "okay";
+
+#ifdef __OV5642_CAPTURE__
+   camera: ov5642@3c {
+   compatible = "ovti,ov5642";
+   pinctrl-names = "default";
+   pinctrl-0 = <&pinctrl_ov5642>;
+   clocks = <&clks IMX6QDL_CLK_CKO2>;
+   clock-names = "xclk";
+   reg = <0x3c>;
+   xclk = <2400>;
+   reset-gpios = <&gpio1 8 0>;
+   pwdn-gpios = <&gpio1 6 0>;
+   gp-gpios = <&gpio1 16 0>;
+
+   port {
+   ov5642_to_ipu1_csi0_mux: endpoint {
+   remote-endpoint = 
<&ipu1_csi0_mux_from_parallel_sensor>;
+   bus-width = <8>;
+   hsync-active = <1>;
+   vsync-active = <1>;
+   };
+   };
+   };
+#endif
 };
 
 &i2c3 {
@@ -373,7 +440,9 @@
MX6QDL_PAD_RGMII_RX_CTL__RGMII_RX_CTL   0x1b0b0
/* Phy reset */
MX6QDL_PAD_EIM_D23__GPIO3_IO23  0x000b0
+#ifndef __OV5642_CAPTURE__
MX6QDL_PAD_GPIO_6__ENET_IRQ 0x000b1
+#endif
>;
};
 
@@ -448,6 +517,32 @@
>;
};
 
+   pinctrl_ipu1_csi0: ipu1grp-csi0 {
+   fsl,pins = <
+   MX6QDL_PAD_CSI0_DAT12__IPU1_CSI0_DATA12
0x8000
+   MX6QDL_PAD_CSI0_DAT13__IPU1_CSI0_DATA13
0x8000
+   MX6QDL_PAD_CSI0_DAT14__IPU1_CSI0_DATA14
0x8000
+   MX6QDL_PAD_CSI0_DAT15__IPU1_CSI0_DATA15
0x8000
+   MX6QDL_PAD_CSI0_DAT16__IPU1_CSI0_DATA16
0

[PATCH 13/38] gpu: ipu-v3: Fix IRT usage

2016-06-14 Thread Steve Longerbeam
There can be multiple IC tasks using the IRT, so the IRT needs
a separate use counter. Create a private ipu_irt_enable() to
enable the IRT module when any IC task requires rotation, and
ipu_irt_disable() when a task no longer needs the IRT.

Signed-off-by: Steve Longerbeam 
---
 drivers/gpu/ipu-v3/ipu-ic.c | 43 ++-
 1 file changed, 34 insertions(+), 9 deletions(-)

diff --git a/drivers/gpu/ipu-v3/ipu-ic.c b/drivers/gpu/ipu-v3/ipu-ic.c
index f306a9c..5329bfe 100644
--- a/drivers/gpu/ipu-v3/ipu-ic.c
+++ b/drivers/gpu/ipu-v3/ipu-ic.c
@@ -160,6 +160,7 @@ struct ipu_ic_priv {
spinlock_t lock;
struct ipu_soc *ipu;
int use_count;
+   int irt_use_count;
struct ipu_ic task[IC_NUM_TASKS];
 };
 
@@ -379,8 +380,6 @@ void ipu_ic_task_disable(struct ipu_ic *ic)
 
ipu_ic_write(ic, ic_conf, IC_CONF);
 
-   ic->rotation = ic->graphics = false;
-
spin_unlock_irqrestore(&priv->lock, flags);
 }
 EXPORT_SYMBOL_GPL(ipu_ic_task_disable);
@@ -639,22 +638,44 @@ int ipu_ic_set_src(struct ipu_ic *ic, int csi_id, bool 
vdi)
 }
 EXPORT_SYMBOL_GPL(ipu_ic_set_src);
 
+static void ipu_irt_enable(struct ipu_ic *ic)
+{
+   struct ipu_ic_priv *priv = ic->priv;
+
+   if (!priv->irt_use_count)
+   ipu_module_enable(priv->ipu, IPU_CONF_ROT_EN);
+
+   priv->irt_use_count++;
+}
+
+static void ipu_irt_disable(struct ipu_ic *ic)
+{
+   struct ipu_ic_priv *priv = ic->priv;
+
+   priv->irt_use_count--;
+
+   if (!priv->irt_use_count)
+   ipu_module_disable(priv->ipu, IPU_CONF_ROT_EN);
+
+   if (priv->irt_use_count < 0)
+   priv->irt_use_count = 0;
+}
+
 int ipu_ic_enable(struct ipu_ic *ic)
 {
struct ipu_ic_priv *priv = ic->priv;
unsigned long flags;
-   u32 module = IPU_CONF_IC_EN;
 
spin_lock_irqsave(&priv->lock, flags);
 
-   if (ic->rotation)
-   module |= IPU_CONF_ROT_EN;
-
if (!priv->use_count)
-   ipu_module_enable(priv->ipu, module);
+   ipu_module_enable(priv->ipu, IPU_CONF_IC_EN);
 
priv->use_count++;
 
+   if (ic->rotation)
+   ipu_irt_enable(ic);
+
spin_unlock_irqrestore(&priv->lock, flags);
 
return 0;
@@ -665,18 +686,22 @@ int ipu_ic_disable(struct ipu_ic *ic)
 {
struct ipu_ic_priv *priv = ic->priv;
unsigned long flags;
-   u32 module = IPU_CONF_IC_EN | IPU_CONF_ROT_EN;
 
spin_lock_irqsave(&priv->lock, flags);
 
priv->use_count--;
 
if (!priv->use_count)
-   ipu_module_disable(priv->ipu, module);
+   ipu_module_disable(priv->ipu, IPU_CONF_IC_EN);
 
if (priv->use_count < 0)
priv->use_count = 0;
 
+   if (ic->rotation)
+   ipu_irt_disable(ic);
+
+   ic->rotation = ic->graphics = false;
+
spin_unlock_irqrestore(&priv->lock, flags);
 
return 0;
-- 
1.9.1

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


[PATCH 06/38] gpu: ipu-v3: Add ipu_set_vdi_src_mux()

2016-06-14 Thread Steve Longerbeam
Adds ipu_set_vdi_src_mux() that selects the VDIC input
(from CSI or memory).

Signed-off-by: Steve Longerbeam 
---
 drivers/gpu/ipu-v3/ipu-common.c | 20 
 include/video/imx-ipu-v3.h  |  1 +
 2 files changed, 21 insertions(+)

diff --git a/drivers/gpu/ipu-v3/ipu-common.c b/drivers/gpu/ipu-v3/ipu-common.c
index 6d1676e..374100e 100644
--- a/drivers/gpu/ipu-v3/ipu-common.c
+++ b/drivers/gpu/ipu-v3/ipu-common.c
@@ -730,6 +730,26 @@ void ipu_set_ic_src_mux(struct ipu_soc *ipu, int csi_id, 
bool vdi)
 }
 EXPORT_SYMBOL_GPL(ipu_set_ic_src_mux);
 
+/*
+ * Set the source for the VDIC. Selects either from CSI[01] or memory.
+ */
+void ipu_set_vdi_src_mux(struct ipu_soc *ipu, bool csi)
+{
+   unsigned long flags;
+   u32 val;
+
+   spin_lock_irqsave(&ipu->lock, flags);
+
+   val = ipu_cm_read(ipu, IPU_FS_PROC_FLOW1);
+   val &= ~(0x3 << 28);
+   if (csi)
+   val |= (0x01 << 28);
+   ipu_cm_write(ipu, val, IPU_FS_PROC_FLOW1);
+
+   spin_unlock_irqrestore(&ipu->lock, flags);
+}
+EXPORT_SYMBOL_GPL(ipu_set_vdi_src_mux);
+
 
 /* IDMAC Channel Linking */
 
diff --git a/include/video/imx-ipu-v3.h b/include/video/imx-ipu-v3.h
index 0a39c64..586979e 100644
--- a/include/video/imx-ipu-v3.h
+++ b/include/video/imx-ipu-v3.h
@@ -152,6 +152,7 @@ int ipu_idmac_channel_irq(struct ipu_soc *ipu, struct 
ipuv3_channel *channel,
 int ipu_get_num(struct ipu_soc *ipu);
 void ipu_set_csi_src_mux(struct ipu_soc *ipu, int csi_id, bool mipi_csi2);
 void ipu_set_ic_src_mux(struct ipu_soc *ipu, int csi_id, bool vdi);
+void ipu_set_vdi_src_mux(struct ipu_soc *ipu, bool csi);
 void ipu_dump(struct ipu_soc *ipu);
 
 /*
-- 
1.9.1

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


[PATCH 07/38] gpu: ipu-v3: Add VDI input IDMAC channels

2016-06-14 Thread Steve Longerbeam
Adds the VDIC field input IDMAC channels. These channels
transfer fields F(n-1), F(n), and F(N+1) from memory to
the VDIC (channels 8, 9, 10 respectively).

Signed-off-by: Steve Longerbeam 
---
 include/video/imx-ipu-v3.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/include/video/imx-ipu-v3.h b/include/video/imx-ipu-v3.h
index 586979e..2302fc5 100644
--- a/include/video/imx-ipu-v3.h
+++ b/include/video/imx-ipu-v3.h
@@ -107,6 +107,9 @@ enum ipu_channel_irq {
 #define IPUV3_CHANNEL_CSI2  2
 #define IPUV3_CHANNEL_CSI3  3
 #define IPUV3_CHANNEL_VDI_MEM_IC_VF 5
+#define IPUV3_CHANNEL_MEM_VDI_P 8
+#define IPUV3_CHANNEL_MEM_VDI   9
+#define IPUV3_CHANNEL_MEM_VDI_N10
 #define IPUV3_CHANNEL_MEM_IC_PP11
 #define IPUV3_CHANNEL_MEM_IC_PRP_VF12
 #define IPUV3_CHANNEL_G_MEM_IC_PRP_VF  14
-- 
1.9.1

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


[PATCH 11/38] gpu: ipu-v3: Fix CSI data format for 16-bit media bus formats

2016-06-14 Thread Steve Longerbeam
The CSI data format was being programmed incorrectly for the
1x16 media bus formats. The CSI data format for 16-bit must
be bayer/generic (CSI_SENS_CONF_DATA_FMT_BAYER).

Suggested-by: Carsten Resch 
Signed-off-by: Steve Longerbeam 
---
 drivers/gpu/ipu-v3/ipu-csi.c | 6 +-
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/drivers/gpu/ipu-v3/ipu-csi.c b/drivers/gpu/ipu-v3/ipu-csi.c
index 07c7091..0eac28c 100644
--- a/drivers/gpu/ipu-v3/ipu-csi.c
+++ b/drivers/gpu/ipu-v3/ipu-csi.c
@@ -258,12 +258,8 @@ static int mbus_code_to_bus_cfg(struct ipu_csi_bus_config 
*cfg, u32 mbus_code)
cfg->data_width = IPU_CSI_DATA_WIDTH_8;
break;
case MEDIA_BUS_FMT_UYVY8_1X16:
-   cfg->data_fmt = CSI_SENS_CONF_DATA_FMT_YUV422_UYVY;
-   cfg->mipi_dt = MIPI_DT_YUV422;
-   cfg->data_width = IPU_CSI_DATA_WIDTH_16;
-   break;
case MEDIA_BUS_FMT_YUYV8_1X16:
-   cfg->data_fmt = CSI_SENS_CONF_DATA_FMT_YUV422_YUYV;
+   cfg->data_fmt = CSI_SENS_CONF_DATA_FMT_BAYER;
cfg->mipi_dt = MIPI_DT_YUV422;
cfg->data_width = IPU_CSI_DATA_WIDTH_16;
break;
-- 
1.9.1

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


[PATCH 09/38] gpu: ipu-v3: Add ipu_ic_set_src()

2016-06-14 Thread Steve Longerbeam
Adds ipu_ic_set_src() which is just aa wrapper around
ipu_set_ic_src_mux().

Signed-off-by: Steve Longerbeam 
---
 drivers/gpu/ipu-v3/ipu-ic.c | 10 ++
 include/video/imx-ipu-v3.h  |  1 +
 2 files changed, 11 insertions(+)

diff --git a/drivers/gpu/ipu-v3/ipu-ic.c b/drivers/gpu/ipu-v3/ipu-ic.c
index 1dcb96c..f306a9c 100644
--- a/drivers/gpu/ipu-v3/ipu-ic.c
+++ b/drivers/gpu/ipu-v3/ipu-ic.c
@@ -629,6 +629,16 @@ unlock:
 }
 EXPORT_SYMBOL_GPL(ipu_ic_task_idma_init);
 
+int ipu_ic_set_src(struct ipu_ic *ic, int csi_id, bool vdi)
+{
+   struct ipu_ic_priv *priv = ic->priv;
+
+   ipu_set_ic_src_mux(priv->ipu, csi_id, vdi);
+
+   return 0;
+}
+EXPORT_SYMBOL_GPL(ipu_ic_set_src);
+
 int ipu_ic_enable(struct ipu_ic *ic)
 {
struct ipu_ic_priv *priv = ic->priv;
diff --git a/include/video/imx-ipu-v3.h b/include/video/imx-ipu-v3.h
index 57b487d..8f77ddb 100644
--- a/include/video/imx-ipu-v3.h
+++ b/include/video/imx-ipu-v3.h
@@ -334,6 +334,7 @@ void ipu_ic_task_disable(struct ipu_ic *ic);
 int ipu_ic_task_idma_init(struct ipu_ic *ic, struct ipuv3_channel *channel,
  u32 width, u32 height, int burst_size,
  enum ipu_rotate_mode rot);
+int ipu_ic_set_src(struct ipu_ic *ic, int csi_id, bool vdi);
 int ipu_ic_enable(struct ipu_ic *ic);
 int ipu_ic_disable(struct ipu_ic *ic);
 struct ipu_ic *ipu_ic_get(struct ipu_soc *ipu, enum ipu_ic_task task);
-- 
1.9.1

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


[PATCH 10/38] gpu: ipu-v3: set correct full sensor frame for PAL/NTSC

2016-06-14 Thread Steve Longerbeam
Set the sensor full frame based on whether the passed in mbus_fmt
is 720x480 (NTSC) or 720x576 (PAL).

Signed-off-by: Steve Longerbeam 
---
 drivers/gpu/ipu-v3/ipu-csi.c | 20 +---
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/ipu-v3/ipu-csi.c b/drivers/gpu/ipu-v3/ipu-csi.c
index 336dc06..07c7091 100644
--- a/drivers/gpu/ipu-v3/ipu-csi.c
+++ b/drivers/gpu/ipu-v3/ipu-csi.c
@@ -365,10 +365,14 @@ int ipu_csi_init_interface(struct ipu_csi *csi,
 {
struct ipu_csi_bus_config cfg;
unsigned long flags;
-   u32 data = 0;
+   u32 width, height, data = 0;
 
fill_csi_bus_cfg(&cfg, mbus_cfg, mbus_fmt);
 
+   /* set default sensor frame width and height */
+   width = mbus_fmt->width;
+   height = mbus_fmt->height;
+
/* Set the CSI_SENS_CONF register remaining fields */
data |= cfg.data_width << CSI_SENS_CONF_DATA_WIDTH_SHIFT |
cfg.data_fmt << CSI_SENS_CONF_DATA_FMT_SHIFT |
@@ -386,11 +390,6 @@ int ipu_csi_init_interface(struct ipu_csi *csi,
 
ipu_csi_write(csi, data, CSI_SENS_CONF);
 
-   /* Setup sensor frame size */
-   ipu_csi_write(csi,
- (mbus_fmt->width - 1) | ((mbus_fmt->height - 1) << 16),
- CSI_SENS_FRM_SIZE);
-
/* Set CCIR registers */
 
switch (cfg.clk_mode) {
@@ -408,11 +407,12 @@ int ipu_csi_init_interface(struct ipu_csi *csi,
 * Field1BlankEnd = 0x7, Field1BlankStart = 0x3,
 * Field1ActiveEnd = 0x5, Field1ActiveStart = 0x1
 */
+   height = 625; /* framelines for PAL */
+
ipu_csi_write(csi, 0x40596 | CSI_CCIR_ERR_DET_EN,
  CSI_CCIR_CODE_1);
ipu_csi_write(csi, 0xD07DF, CSI_CCIR_CODE_2);
ipu_csi_write(csi, 0xFF, CSI_CCIR_CODE_3);
-
} else if (mbus_fmt->width == 720 && mbus_fmt->height == 480) {
/*
 * NTSC case
@@ -422,6 +422,8 @@ int ipu_csi_init_interface(struct ipu_csi *csi,
 * Field1BlankEnd = 0x6, Field1BlankStart = 0x2,
 * Field1ActiveEnd = 0x4, Field1ActiveStart = 0
 */
+   height = 525; /* framelines for NTSC */
+
ipu_csi_write(csi, 0xD07DF | CSI_CCIR_ERR_DET_EN,
  CSI_CCIR_CODE_1);
ipu_csi_write(csi, 0x40596, CSI_CCIR_CODE_2);
@@ -447,6 +449,10 @@ int ipu_csi_init_interface(struct ipu_csi *csi,
break;
}
 
+   /* Setup sensor frame size */
+   ipu_csi_write(csi, (width - 1) | ((height - 1) << 16),
+ CSI_SENS_FRM_SIZE);
+
dev_dbg(csi->ipu->dev, "CSI_SENS_CONF = 0x%08X\n",
ipu_csi_read(csi, CSI_SENS_CONF));
dev_dbg(csi->ipu->dev, "CSI_ACT_FRM_SIZE = 0x%08X\n",
-- 
1.9.1

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


[PATCH 12/38] gpu: ipu-v3: Fix CSI0 blur in NTSC format

2016-06-14 Thread Steve Longerbeam
From: Suresh Dhandapani 

This patch will change the register IPU_CSI0_CCIR_CODE_2 value from
0x40596 to 0x405A6. The change is related to the Start of field 1
first blanking line command bit[5-3] for NTSC format only. This
change is dependent with ADV chip where the NEWAVMODE is set to 0
in register 0x31. Setting NEWAVMODE to "0" in ADV means "EAV/SAV
codes generated to suit analog devices encoders".

Signed-off-by: Suresh Dhandapani 
---
 drivers/gpu/ipu-v3/ipu-csi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/ipu-v3/ipu-csi.c b/drivers/gpu/ipu-v3/ipu-csi.c
index 0eac28c..ec81958 100644
--- a/drivers/gpu/ipu-v3/ipu-csi.c
+++ b/drivers/gpu/ipu-v3/ipu-csi.c
@@ -422,7 +422,7 @@ int ipu_csi_init_interface(struct ipu_csi *csi,
 
ipu_csi_write(csi, 0xD07DF | CSI_CCIR_ERR_DET_EN,
  CSI_CCIR_CODE_1);
-   ipu_csi_write(csi, 0x40596, CSI_CCIR_CODE_2);
+   ipu_csi_write(csi, 0x405A6, CSI_CCIR_CODE_2);
ipu_csi_write(csi, 0xFF, CSI_CCIR_CODE_3);
} else {
dev_err(csi->ipu->dev,
-- 
1.9.1

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


Re: [PATCH 35/38] media: adv7180: add power pin control

2016-06-15 Thread Steve Longerbeam
Hi Lars,

On 06/15/2016 09:05 AM, Lars-Peter Clausen wrote:
> On 06/15/2016 12:49 AM, Steve Longerbeam wrote:
>> +usleep_range(5000, 5001);
> That's kind of not how usleep_range() (the emphasis is on range) is supposed
> to be used. You typically dont care too much about the upper limit here so
> something like maybe 1 is more appropriate.

Good point, I fixed this as well as all other instances of
usleep_range() in the patch set.

>
>> +static int adv7180_of_parse(struct adv7180_state *state)
>> +{
>> +struct i2c_client *client = state->client;
>> +struct device_node *np = client->dev.of_node;
>> +int ret;
>> +
>> +ret = of_get_named_gpio(np, "pwdn-gpio", 0);
>> +
>> +if (gpio_is_valid(ret)) {
>> +state->pwdn_gpio = ret;
>> +ret = devm_gpio_request_one(&client->dev,
>> +state->pwdn_gpio,
>> +GPIOF_OUT_INIT_HIGH,
>> +"adv7180_pwdn");
>
> This should use the new GPIO descriptor API. That will also make the code
> devicetree independent. Otherwise patch looks OK.

Thanks for the heads-up. I converted to gpiod here, and in all other
patches in the set that were using the deprecated API. Also took the
time to review the active low/high flags in the device tree, and made
sure they are correct and are using the explicit flags GPIO_ACTIVE_*.

The changes are in a new branch mx6-media-staging-v2.1 in my fork
on github (g...@github.com:slongerbeam/mediatree.git).

Retested on SabreSD and SabreAuto, still working as before.

Steve

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


Re: [PATCH 00/38] i.MX5/6 Video Capture

2016-06-15 Thread Steve Longerbeam
Hi Jack,

On 06/15/2016 03:43 AM, Jack Mitchell wrote:
> 
> Trying to use a user pointer rather than mmap also fails and causes a kernel 
> splat.
>

Hmm, I've tested userptr with the mem2mem driver, but maybe never
with video capture. I tried "v4l2-ctl -d/dev/video0 --stream-user=8" but
that returns "VIDIOC_QBUF: failed: Invalid argument", haven't tracked
down why (could be a bug in v4l2-ctl). Can you share the splat?


> Apart from that and a few v4l2-compliance tests failing which you already 
> mentioned, it seems to work OK. I'll try and do some more testing and see if 
> I can come back with some more feedback.

Thanks!


Steve

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


Re: [PATCH 00/38] i.MX5/6 Video Capture

2016-06-16 Thread Steve Longerbeam
On 06/16/2016 02:49 AM, Jack Mitchell wrote:
>
> On 16/06/16 02:37, Steve Longerbeam wrote:
>> Hi Jack,
>>
>> On 06/15/2016 03:43 AM, Jack Mitchell wrote:
>>> 
>>> Trying to use a user pointer rather than mmap also fails and causes a 
>>> kernel splat.
>>>
>>
>> Hmm, I've tested userptr with the mem2mem driver, but maybe never
>> with video capture. I tried "v4l2-ctl -d/dev/video0 --stream-user=8" but
>> that returns "VIDIOC_QBUF: failed: Invalid argument", haven't tracked
>> down why (could be a bug in v4l2-ctl). Can you share the splat?
>>
>
> On re-checking the splat was the same v4l_cropcap that was mentioned before 
> so I don't think it's related. The error I get back is:
>
> VIDIOC_QBUF error 22, Invalid argument
>
> I'm using the example program the the v4l2 docs [1].

I found the cause at least in my case. After enabling dynamic debug in
videobuf2-dma-contig.c, "v4l2-ctl -d/dev/video0 --stream-user=8" gives
me

[  468.826046] user data must be aligned to 64 bytes



But even getting past that alignment issue, I've only tested userptr (in mem2mem
driver) by giving the driver a user address of a mmap'ed kernel contiguous
buffer. A true discontiguous user buffer may not work, the IPU DMA does not
support scatter-gather.

Steve

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


Re: [PATCH 00/38] i.MX5/6 Video Capture

2016-06-17 Thread Steve Longerbeam



On 06/17/2016 12:10 AM, Hans Verkuil wrote:

On 06/16/2016 07:02 PM, Steve Longerbeam wrote:

On 06/16/2016 02:49 AM, Jack Mitchell wrote:

On 16/06/16 02:37, Steve Longerbeam wrote:

Hi Jack,

On 06/15/2016 03:43 AM, Jack Mitchell wrote:


Trying to use a user pointer rather than mmap also fails and causes a kernel 
splat.


Hmm, I've tested userptr with the mem2mem driver, but maybe never
with video capture. I tried "v4l2-ctl -d/dev/video0 --stream-user=8" but
that returns "VIDIOC_QBUF: failed: Invalid argument", haven't tracked
down why (could be a bug in v4l2-ctl). Can you share the splat?


On re-checking the splat was the same v4l_cropcap that was mentioned before so 
I don't think it's related. The error I get back is:

VIDIOC_QBUF error 22, Invalid argument

I'm using the example program the the v4l2 docs [1].

I found the cause at least in my case. After enabling dynamic debug in
videobuf2-dma-contig.c, "v4l2-ctl -d/dev/video0 --stream-user=8" gives
me

[  468.826046] user data must be aligned to 64 bytes



But even getting past that alignment issue, I've only tested userptr (in mem2mem
driver) by giving the driver a user address of a mmap'ed kernel contiguous
buffer. A true discontiguous user buffer may not work, the IPU DMA does not
support scatter-gather.

I don't think VB2_USERPTR should be enabled in this case due to the DMA 
limitations.
It won't allow you to use malloc()ed memory and the hack that allows you to pass
contiguous memory is superseded by the DMABUF mode.


Hi Hans, yes, I was going to suggest that. I will remove USERPTR
from both capture and mem2mem io_modes flags. Although I can
see where userptr support is still useful, that is for legacy middleware
that are still using mmap'ed userptrs and have not yet converted to
passing around dmabuf fd's.

But I've been perplexed for while on this, why vb2_dc_get_userptr() 
resorts to
scatter-gather (when the given user buffer is found not to have valid 
pfn's).

Shouldn't it be assumed that driver users of the vb2 dma-contig allocator
only support contiguous dma as the name implies? Maybe the issue is that
users that set VB2_USERPTR are implying they support scatter/gather, but
users of vb2-dma-contig could also be implying they do not, and would be
using vb2-dma-sg if that were the case.

Steve

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


tchellRe: [19/38] ARM: dts: imx6-sabrelite: add video capture ports and connections

2016-06-17 Thread Steve Longerbeam



On 06/17/2016 08:18 AM, Gary Bisson wrote:

Steve, All,

On Thu, Jun 16, 2016 at 10:32:31AM +0200, Gary Bisson wrote:

Steve, All,

On Tue, Jun 14, 2016 at 03:49:15PM -0700, Steve Longerbeam wrote:

Defines the host video capture device node and an OV5642 camera sensor
node on i2c2. The host capture device connects to the OV5642 via the
parallel-bus mux input on the ipu1_csi0_mux.

Note there is a pin conflict with GPIO6. This pin functions as a power
input pin to the OV5642, but ENET requires it to wake-up the ARM cores
on normal RX and TX packet done events (see 6261c4c8). So by default,
capture is disabled, enable by uncommenting __OV5642_CAPTURE__ macro.
Ethernet will still work just not quite as well.

Actually the following patch fixes this issue and has already been
applied on Shawn's tree:
https://patchwork.kernel.org/patch/9153523/

Also, this follow-up patch declared the HW workaround for SabreLite:
https://patchwork.kernel.org/patch/9153525/

So ideally, once those two patches land on your base tree, you could get
rid of the #define and remove the HW workaround declaration.

Finally, I'll test the series on Sabre-Lite this week.

I've applied this series on top of Shawn tree (for-next branch) in order
not to worry about the GPIO6 workaround.

Although the camera seems to get enumerated properly, I can't seem to
get anything from it. See log:
http://pastebin.com/xnw1ujUq


Hi Gary, the driver does not implement vidioc_cropcap, it has
switched to the new selection APIs and v4l2src should be using
vidioc_g_selection instead of vidioc_cropcap.



In your cover letter, you said that you have not run through
v4l2-compliance. How have you tested the capture?


I use v4l2-ctl, and have used v4l2src in the past, but that was before
switching to the selection APIs. Try the attached hack that adds
vidioc_cropcap back in, and see how far you get on SabreLite with
v4l2src. I tried  the following on SabreAuto:

gst-launch-1.0 v4l2src io_mode=4 ! 
"video/x-raw,format=RGB16,width=640,height=480" ! fbdevsink




Also, why isn't the OV5640 MIPI camera declared on the SabreLite device
tree?


See Jack Mitchell's patch at http://ix.io/TTg. Thanks Jack! I will work on
incorporating it.


Steve


diff --git a/drivers/staging/media/imx/capture/imx-camif.c b/drivers/staging/media/imx/capture/imx-camif.c
index 9c247e0..2c51bc7 100644
--- a/drivers/staging/media/imx/capture/imx-camif.c
+++ b/drivers/staging/media/imx/capture/imx-camif.c
@@ -1561,6 +1561,23 @@ static int vidioc_s_parm(struct file *file, void *fh,
 	return v4l2_subdev_call(dev->sensor->sd, video, s_parm, a);
 }
 
+static int vidioc_cropcap(struct file *file, void *priv,
+			  struct v4l2_cropcap *cropcap)
+{
+	struct imxcam_ctx *ctx = file2ctx(file);
+	struct imxcam_dev *dev = ctx->dev;
+
+	if (cropcap->type != V4L2_BUF_TYPE_VIDEO_CAPTURE &&
+	cropcap->type != V4L2_BUF_TYPE_VIDEO_OVERLAY)
+		return -EINVAL;
+
+	cropcap->bounds = dev->crop_bounds;
+	cropcap->defrect = dev->crop_defrect;
+	cropcap->pixelaspect.numerator = 1;
+	cropcap->pixelaspect.denominator = 1;
+	return 0;
+}
+
 static int vidioc_g_selection(struct file *file, void *priv,
 			  struct v4l2_selection *sel)
 {
@@ -1794,6 +1811,7 @@ static const struct v4l2_ioctl_ops imxcam_ioctl_ops = {
 	.vidioc_g_parm  = vidioc_g_parm,
 	.vidioc_s_parm  = vidioc_s_parm,
 
+	.vidioc_cropcap		= vidioc_cropcap,
 	.vidioc_g_selection = vidioc_g_selection,
 	.vidioc_s_selection = vidioc_s_selection,
 


Re: [19/38] ARM: dts: imx6-sabrelite: add video capture ports and connections

2016-06-17 Thread Steve Longerbeam



On 06/17/2016 08:18 AM, Gary Bisson wrote:

Steve, All,

On Thu, Jun 16, 2016 at 10:32:31AM +0200, Gary Bisson wrote:

Steve, All,

On Tue, Jun 14, 2016 at 03:49:15PM -0700, Steve Longerbeam wrote:

Defines the host video capture device node and an OV5642 camera sensor
node on i2c2. The host capture device connects to the OV5642 via the
parallel-bus mux input on the ipu1_csi0_mux.

Note there is a pin conflict with GPIO6. This pin functions as a power
input pin to the OV5642, but ENET requires it to wake-up the ARM cores
on normal RX and TX packet done events (see 6261c4c8). So by default,
capture is disabled, enable by uncommenting __OV5642_CAPTURE__ macro.
Ethernet will still work just not quite as well.

Actually the following patch fixes this issue and has already been
applied on Shawn's tree:
https://patchwork.kernel.org/patch/9153523/

Also, this follow-up patch declared the HW workaround for SabreLite:
https://patchwork.kernel.org/patch/9153525/

So ideally, once those two patches land on your base tree, you could get
rid of the #define and remove the HW workaround declaration.

Finally, I'll test the series on Sabre-Lite this week.

I've applied this series on top of Shawn tree (for-next branch) in order
not to worry about the GPIO6 workaround.

Although the camera seems to get enumerated properly, I can't seem to
get anything from it. See log:
http://pastebin.com/xnw1ujUq


Hi Gary, the driver does not implement vidioc_cropcap, it has
switched to the new selection APIs and v4l2src should be using
vidioc_g_selection instead of vidioc_cropcap.



In your cover letter, you said that you have not run through
v4l2-compliance. How have you tested the capture?


I use v4l2-ctl, and have used v4l2src in the past, but that was before
switching to the selection APIs. Try the attached hack that adds
vidioc_cropcap back in, and see how far you get on SabreLite with
v4l2src. I tried  the following on SabreAuto:

gst-launch-1.0 v4l2src io_mode=4 ! 
"video/x-raw,format=RGB16,width=640,height=480" ! fbdevsink




Also, why isn't the OV5640 MIPI camera declared on the SabreLite device
tree?


See Jack Mitchell's patch at http://ix.io/TTg. Thanks Jack! I will work on
incorporating it.


Steve



diff --git a/drivers/staging/media/imx/capture/imx-camif.c b/drivers/staging/media/imx/capture/imx-camif.c
index 9c247e0..2c51bc7 100644
--- a/drivers/staging/media/imx/capture/imx-camif.c
+++ b/drivers/staging/media/imx/capture/imx-camif.c
@@ -1561,6 +1561,23 @@ static int vidioc_s_parm(struct file *file, void *fh,
 	return v4l2_subdev_call(dev->sensor->sd, video, s_parm, a);
 }
 
+static int vidioc_cropcap(struct file *file, void *priv,
+			  struct v4l2_cropcap *cropcap)
+{
+	struct imxcam_ctx *ctx = file2ctx(file);
+	struct imxcam_dev *dev = ctx->dev;
+
+	if (cropcap->type != V4L2_BUF_TYPE_VIDEO_CAPTURE &&
+	cropcap->type != V4L2_BUF_TYPE_VIDEO_OVERLAY)
+		return -EINVAL;
+
+	cropcap->bounds = dev->crop_bounds;
+	cropcap->defrect = dev->crop_defrect;
+	cropcap->pixelaspect.numerator = 1;
+	cropcap->pixelaspect.denominator = 1;
+	return 0;
+}
+
 static int vidioc_g_selection(struct file *file, void *priv,
 			  struct v4l2_selection *sel)
 {
@@ -1794,6 +1811,7 @@ static const struct v4l2_ioctl_ops imxcam_ioctl_ops = {
 	.vidioc_g_parm  = vidioc_g_parm,
 	.vidioc_s_parm  = vidioc_s_parm,
 
+	.vidioc_cropcap		= vidioc_cropcap,
 	.vidioc_g_selection = vidioc_g_selection,
 	.vidioc_s_selection = vidioc_s_selection,
 



Re: [PATCH 31/38] media: imx: Add video switch

2016-06-17 Thread Steve Longerbeam

On 06/16/2016 09:13 AM, Ian Arkver wrote:
For me this fails when I try to enable both video muxes (mx6dl, though 
mx6q should be the same).


I get a sysfs duplicate name failure for 34.videomux. I realise 
passing the GPR13 register offset and a bitfield mask as a tuple in 
the reg value of the of_node is handy, but how should we account for 
multiple devices with the same name and address?


A quick and dirty hack would be to have of_get_reg_field do something 
like


field->reg = reg_bit_mask[0] & 0xff;

and then use values in the DT that differ in the bits masked off, but 
there must be a nicer way.


Trace below, fyi. This is from the v2 patches posted here, not your 
v2.1 tree.




Hi Ian,

Thanks for catching this. I found a simple and clean solution to this
problem: just rename the video-mux node from "videomux" to
"ipu[12]_csi[01]_mux". It makes the subdev names more descriptive
anyway. I've applied that change to my mx6-media-staging-v2.1
branch.

Steve

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


Re: [PATCH 34/38] media: imx: Add support for ADV7180 Video Decoder

2016-06-17 Thread Steve Longerbeam



On 06/16/2016 04:33 AM, Lars-Peter Clausen wrote:

On 06/15/2016 12:49 AM, Steve Longerbeam wrote:

This driver is based on adv7180.c from Freescale imx_3.10.17_1.0.0_beta
branch, modified heavily for code cleanup and converted from int-device
to subdev.

We already have a driver for the adv7180 upstream, also using the subdev
API. Is there anything that can be done with this new driver that can't be
done with the other one. And if it is are there any blockers that would
prevent us from adding the missing features to the upstream adv7180?

I know that the driver in the Freescale tree used to have bits that made it
specially tailored to the iMX6. But these bits seem to be mostly gone in
this version of the driver.

I'm slightly concerned about the conflicting nature of these drivers. Both
attach to the same device ID/DT compatible string and register slightly
different userspace ABIs. I'd like to avoid ending up in a situation where
we have dependencies on both ABIs and can no longer converge.


Hi Lars,

Yes, it's been my plan all along to bring the upstream adv7180 subdev
up to speed, and then remove the one included in this patch set.
The issues I see so far with the upstream driver:

- It is not auto-detecting changes to the analog input signal, such as
  loss/regain of signal lock and video standard changes. This probably
  is because interrupts are not working. I haven't debugged that further.

- The media bus format code is not right, it should be UYVY, not YUYV. But
  I'm reluctant to make that mbus code change because there are other
  users of this driver and that will likely corrupt images on the other
  targets. But I believe UYVY is the correct order according to bt.656
  standard, someone correct me if I am wrong.

- The field type should be either V4L2_FIELD_SEQ_BT or V4L2_FIELD_SEQ_TB,
  since the adv7180 transmits one complete field followed by the other.

There could be other issues. There are also the ov564x subdevs that 
really need
to be cleaned-up and moved to drivers/media/i2c (they are also based on 
old FSL
intdev drivers but with more stuff in there that probably doesn't make 
sense, such
as those really big register tables that are likely filled with reset 
default values and

were generated by doing an i2c dump at reset).

This work will take some time, so the question is, should we delay that 
work to

after an initial merge.

Steve

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


Re: [19/38] ARM: dts: imx6-sabrelite: add video capture ports and connections

2016-06-21 Thread Steve Longerbeam
On 06/20/2016 03:44 AM, Jack Mitchell wrote:
>
>
> On 20/06/16 11:16, Gary Bisson wrote:
>> Jack, All,
>>
>> On Mon, Jun 20, 2016 at 10:44:44AM +0100, Jack Mitchell wrote:
>>> 
 I've tried that patch have a some comments:
 - When applied, no capture shows up any more, instead I have two m2m
   v4l2 devices [1].
 - OV5640 Mipi is assigned the same address as OV5642, therefore both
>>>
>>> Yes, I only have one device attached in my scenario.
>>
>> Thanks for confirming.
>>
   can't work at the same time right now. There's a register in the
   camera that allows to modify its I2C address, see this patch [2].
 - How is the mclk working in this patch? It should be using the PWM3
>>>
>>> As mentioned I have an eCon sensor board [1] which generates it's own clock
>>> on the board and as such I don't need the PWM signal, just the two GPIOs.
>>
>> Oh ok, thanks I didn't this sensor board was different than ours [1].
>>
>> But in your patch, you specifically disable pwm3, what's the reason for
>> it?
>
> Yes, it uses the GPIO on the PWM3 pin (beats me why...) so I had to 
> specifically disable it to stop the pin muxing clash.
>

Hi Jack, in your patch, the PWM3 pin (which is SD1_DAT1 operating as GPIO1_IO17)
is being used as the power-down pin for your OV5640 board.

Anyway, I didn't realize this was a different camera from the boundary-devices
module (https://boundarydevices.com/product/nit6x_5mp_mipi/).

I would like to add support in the DT for the BD module, but I am unable to 
test/debug
as I don't have one. I'm wondering if someone could lend me one, along with the
schematics. I have the OV5642 parallel interface module for the SabreLite, so 
I'd love
to get my hands on the OV5640 mipi module as that would allow testing of 
multiple
camera capture which I've never been able to do before.

In the meantime I am going to omit support for this module in the sabrelite DT 
(there's
also the problem of the i2c bus address conflict on the same i2c2 bus with the 
ov5642).

Or if someone can add support for the BD module later that would be great.


Steve

>>
   output to generate a ~22MHz clock. I would expect the use of a
   pwm-clock node [3].

 Also another remark on both OV5642 and OV5640 patches, is it recommended
 to use 0x8000 pin muxing value? This leaves it to the bootloader to
>>>
>>> I also wondered about this, but didn't know if the pinmux driver did this
>>> based on the define name? I tried it both ways and it worked so I just left
>>> it as it was.
>>
>> Actually my phrasing is wrong, the muxing is ok. Yes depending on the
>> name a pin will be muxed to one function or another. The problem is the
>> pad configuration (pull-up, pull-down etc..). I am not surprised that it
>> works, because the bootloader should properly set those. But it would be
>> safer IMO not to rely on it.
>
> Ah ok, makes sense.
>
>>
>> Regards,
>> Gary
>>
>> [1] https://boundarydevices.com/product/nit6x_5mp_mipi/
>>

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


Re: [PATCH 00/38] i.MX5/6 Video Capture

2016-07-01 Thread Steve Longerbeam

Hi Tim,

Pardon late reply, I'm on vacation. See below...


On 06/28/2016 11:54 AM, Tim Harvey wrote:

On Tue, Jun 14, 2016 at 3:48 PM, Steve Longerbeam  wrote:

Tested on imx6q SabreAuto with ADV7180, and imx6q SabreSD with
mipi-csi2 OV5640. There is device-tree support also for imx6qdl
SabreLite, but that is not tested. Also, this driver should
theoretically work on i.MX5 targets, but that is also untested.

Not run through v4l2-compliance yet, but that is in my queue.



Steve,

I've tested this series successfully with a Gateworks Ventana GW5300
which has an IMX6Q and an adv7180 attached to IPU2_CSI1.

First of all, a big 'thank you' for taking the time to rebase and
re-submit this series!

However based on the lack of feedback of the individual patches as
well as the fact they touch varied subsystems I think we are going to
have better luck getting this functionality accepted if you broke it
into separate series.

Here are my thoughts:


   gpu: ipu-v3: Add Video Deinterlacer unit
   gpu: ipu-cpmem: Add ipu_cpmem_set_uv_offset()
   gpu: ipu-cpmem: Add ipu_cpmem_get_burstsize()
   gpu: ipu-v3: Add ipu_get_num()
   gpu: ipu-v3: Add IDMA channel linking support
   gpu: ipu-v3: Add ipu_set_vdi_src_mux()
   gpu: ipu-v3: Add VDI input IDMAC channels
   gpu: ipu-v3: Add ipu_csi_set_src()
   gpu: ipu-v3: Add ipu_ic_set_src()
   gpu: ipu-v3: set correct full sensor frame for PAL/NTSC
   gpu: ipu-v3: Fix CSI data format for 16-bit media bus formats
   gpu: ipu-v3: Fix IRT usage
   gpu: ipu-v3: Fix CSI0 blur in NTSC format
   gpu: ipu-ic: Add complete image conversion support with tiling
   gpu: ipu-ic: allow multiple handles to ic
   gpu: ipu-v3: rename CSI client device

These are all enhancements to the ipu-v3 driver shared by DRM and
maintained by Philipp Zabel and there is no way to 'stage' them.


Just a note here, all these patches to ipu-v3 driver are to the
capture units, and should have no effect on DRM.


Philipp, these have bee submitted previously with little to no changes
or feedback - can we get sign-off or comment on these from you?

Next I would submit the set of drivers that depend on the above into
staging as Hans has said he would accept those (assuming the deps are
accepted). Also, you should submit the drivers first in your series,
then the imx6q.dtsi/imx6qdl.dtsi patches following such as:


   media: imx: Add MIPI CSI-2 Receiver driver
   media: Add camera interface driver for i.MX5/6
   media: Add i.MX5/6 mem2mem driver
   media: imx: Add video switch
   ARM: imx_v6_v7_defconfig: Enable staging video4linux drivers
   ARM: dts: imx6qdl: Add mipi_ipu1/2 video muxes, mipi_csi, and their 
connections
   ARM: dts: imx6qdl: Flesh out MIPI CSI2 receiver node
   ARM: dts: imx6qdl: add mem2mem device for sabre* boards


Ok I will reorder the patches.


I think this last one should add the mem2mem nodes to imx6q.dtsi and
imx6dl.dtsi to be useable by all boards with IPUs right?


Yeah, I'll move the mem2mem nodes to imx6qdl.dtsi and imx6q.dtsi.



After this we have a platform that many imx6 boards with capture
devices can build on.

In parallel, you have a couple of other dependencies before saber*
boards have full capture support that need to through other trees:


   gpio: pca953x: Add reset-gpios property

This should be submitted through the linux-gpio list/subsystem.


I've really got a lot on my plate, I'd appreciate if someone else
could help me out with that.




   clocksource/drivers/imx: add input capture support

Not sure what path this one goes through but it looks to me this patch
adds a feature that only some boards may require (input-capture).


Well, the input-capture support should be usable by any imx6 based
target, and not just for v4l2 subsystem.




   media: imx: Add support for MIPI CSI-2 OV5640
   media: imx: Add support for Parallel OV5642

shouldn't these be subdev drivers?


Well, they _are_ subdev drivers. I guess you mean they should be
moved to drivers/media/i2c? Agreed, at some point they need some
cleaning up and probably consolidated into a single subdev and moved
there.


  Perhaps the can make it into
staging at least in the form you have them now.


   v4l: Add signal lock status to source change events
   media: imx: Add support for ADV7180 Video Decoder

These should be dropped (the 1st is a dependency of the 2nd) and
instead we should be using the subdev driver. I believe you have this
working, and I have been somewhat successful with some of your patches
as well although I still have a 'rolling image' and do not appear to
be getting signal detect interrupts after the first one (which is
likely causing the rolling).


Tim, I've started a new branch 'adv718x' in my mediatree github fork
and moved all the patches to drivers/media/i2c/adv7180.c there. Note
the first commit in that branch!

As I'm currently on vacation and away from the h/w I won't be able to test
this branch 

Re: [PATCH 28/38] v4l: Add signal lock status to source change events

2016-07-01 Thread Steve Longerbeam



On 07/01/2016 12:24 AM, Hans Verkuil wrote:

On 06/15/2016 12:49 AM, Steve Longerbeam wrote:

Add a signal lock status change to the source changes bitmask.
This indicates there was a signal lock or unlock event detected
at the input of a video decoder.

Signed-off-by: Steve Longerbeam 
---
  Documentation/DocBook/media/v4l/vidioc-dqevent.xml | 12 ++--
  include/uapi/linux/videodev2.h |  1 +
  2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/Documentation/DocBook/media/v4l/vidioc-dqevent.xml 
b/Documentation/DocBook/media/v4l/vidioc-dqevent.xml
index c9c3c77..7758ad7 100644
--- a/Documentation/DocBook/media/v4l/vidioc-dqevent.xml
+++ b/Documentation/DocBook/media/v4l/vidioc-dqevent.xml
@@ -233,8 +233,9 @@

  This event is triggered when a source parameter change is
   detected during runtime by the video device. It can be a
-  runtime resolution change triggered by a video decoder or the
-  format change happening on an input connector.
+  runtime resolution change or signal lock status change
+  triggered by a video decoder, or the format change happening
+  on an input connector.
   This event requires that the id
   matches the input index (when used with a video device node)
   or the pad index (when used with a subdevice node) from which
@@ -461,6 +462,13 @@
from a video decoder.

  
+ 
+   V4L2_EVENT_SRC_CH_LOCK_STATUS
+   0x0002
+   This event gets triggered when there is a signal lock or
+   unlock detected at the input of a video decoder.
+   
+ 

I'm not entirely sure I like this. Typically losing lock means that this event
is triggered with the V4L2_EVENT_SRC_CH_RESOLUTION flag set, and userspace has
to check the new timings etc., which will fail if there is no lock anymore.

This information is also available through ENUMINPUT.

I would need to know more about why you think this is needed, because I don't
see what this adds.


Hi Hans,

At least on the ADV718x, a source resolution change (from an 
autodetected video
standard change) and a signal lock status change are distinct events. 
For example
there can be a temporary loss of input signal lock without a change in 
detected

input video standard/resolution.

Steve

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


[PATCH 00/28] i.MX5/6 Video Capture, v2

2016-07-06 Thread Steve Longerbeam
Philipp Zabel (2):
  media: imx: Add video switch
  ARM: dts: imx6qdl: Add mipi_ipu1/2 video muxes, mipi_csi, and their
connections

Steve Longerbeam (25):
  gpu: ipu-v3: Add Video Deinterlacer unit
  gpu: ipu-cpmem: Add ipu_cpmem_set_uv_offset()
  gpu: ipu-cpmem: Add ipu_cpmem_get_burstsize()
  gpu: ipu-v3: Add ipu_get_num()
  gpu: ipu-v3: Add IDMA channel linking support
  gpu: ipu-v3: Add ipu_set_vdi_src_mux()
  gpu: ipu-v3: Add VDI input IDMAC channels
  gpu: ipu-v3: Add ipu_csi_set_src()
  gpu: ipu-v3: Add ipu_ic_set_src()
  gpu: ipu-v3: set correct full sensor frame for PAL/NTSC
  gpu: ipu-v3: Fix CSI data format for 16-bit media bus formats
  gpu: ipu-v3: Fix IRT usage
  gpu: ipu-ic: Add complete image conversion support with tiling
  gpu: ipu-ic: allow multiple handles to ic
  gpu: ipu-v3: rename CSI client device
  gpio: pca953x: Add optional reset gpio control
  clocksource/drivers/imx: add input capture support
  media: Add i.MX5/6 camera interface driver
  media: imx: Add MIPI CSI-2 Receiver driver
  media: imx: Add support for MIPI CSI-2 OV5640
  media: imx: Add support for Parallel OV5642
  media: Add i.MX5/6 mem2mem driver
  ARM: dts: imx6qdl: Flesh out MIPI CSI2 receiver node
  ARM: dts: imx6qdl: add mem2mem devices
  ARM: imx_v6_v7_defconfig: Enable staging video4linux drivers

Suresh Dhandapani (1):
  gpu: ipu-v3: Fix CSI0 blur in NTSC format

 Documentation/devicetree/bindings/media/imx.txt|  449 ++
 Documentation/video4linux/imx_camera.txt   |  243 ++
 arch/arm/boot/dts/imx6dl.dtsi  |  183 +
 arch/arm/boot/dts/imx6q.dtsi   |  127 +
 arch/arm/boot/dts/imx6qdl.dtsi |   19 +
 arch/arm/configs/imx_v6_v7_defconfig   |2 +
 drivers/clocksource/timer-imx-gpt.c|  463 ++-
 drivers/gpio/gpio-pca953x.c|   18 +
 drivers/gpu/ipu-v3/Makefile|2 +-
 drivers/gpu/ipu-v3/ipu-common.c|  155 +-
 drivers/gpu/ipu-v3/ipu-cpmem.c |   13 +
 drivers/gpu/ipu-v3/ipu-csi.c   |   36 +-
 drivers/gpu/ipu-v3/ipu-ic.c| 1769 +++-
 drivers/gpu/ipu-v3/ipu-prv.h   |7 +
 drivers/gpu/ipu-v3/ipu-vdi.c   |  266 ++
 drivers/staging/media/Kconfig  |2 +
 drivers/staging/media/Makefile |1 +
 drivers/staging/media/imx/Kconfig  |   35 +
 drivers/staging/media/imx/Makefile |2 +
 drivers/staging/media/imx/capture/Kconfig  |   35 +
 drivers/staging/media/imx/capture/Makefile |9 +
 drivers/staging/media/imx/capture/imx-camif.c  | 2326 +++
 drivers/staging/media/imx/capture/imx-camif.h  |  270 ++
 drivers/staging/media/imx/capture/imx-csi.c|  195 +
 drivers/staging/media/imx/capture/imx-ic-prpenc.c  |  661 +++
 drivers/staging/media/imx/capture/imx-of.c |  354 ++
 drivers/staging/media/imx/capture/imx-of.h |   18 +
 drivers/staging/media/imx/capture/imx-smfc.c   |  506 +++
 drivers/staging/media/imx/capture/imx-vdic.c   |  995 +
 .../staging/media/imx/capture/imx-video-switch.c   |  347 ++
 drivers/staging/media/imx/capture/mipi-csi2.c  |  373 ++
 drivers/staging/media/imx/capture/ov5640-mipi.c| 2303 +++
 drivers/staging/media/imx/capture/ov5642.c | 4309 
 drivers/staging/media/imx/m2m/Makefile |1 +
 drivers/staging/media/imx/m2m/imx-m2m.c| 1049 +
 include/linux/mxc_icap.h   |   20 +
 include/media/imx.h|   15 +
 include/uapi/Kbuild|1 +
 include/uapi/linux/v4l2-controls.h |4 +
 include/uapi/media/Kbuild  |2 +
 include/uapi/media/imx.h   |   22 +
 include/video/imx-ipu-v3.h |   96 +-
 42 files changed, 17596 insertions(+), 107 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/media/imx.txt
 create mode 100644 Documentation/video4linux/imx_camera.txt
 create mode 100644 drivers/gpu/ipu-v3/ipu-vdi.c
 create mode 100644 drivers/staging/media/imx/Kconfig
 create mode 100644 drivers/staging/media/imx/Makefile
 create mode 100644 drivers/staging/media/imx/capture/Kconfig
 create mode 100644 drivers/staging/media/imx/capture/Makefile
 create mode 100644 drivers/staging/media/imx/capture/imx-camif.c
 create mode 100644 drivers/staging/media/imx/capture/imx-camif.h
 create mode 100644 drivers/staging/media/imx/capture/imx-csi.c
 create mode 100644 drivers/staging/media/imx/capture/imx-ic-prpenc.c
 create mode 100644 drivers/staging/media/imx/capture/imx-of.c
 create mode 100644 drivers/staging/media/imx/capture/imx-of.h
 create mode 100644 drivers/staging/media/imx/capture/imx-smfc.c
 create mode 100644 drivers/staging/media/imx

[PATCH 01/28] gpu: ipu-v3: Add Video Deinterlacer unit

2016-07-06 Thread Steve Longerbeam
Adds the Video Deinterlacer (VDIC) unit.

Signed-off-by: Steve Longerbeam 
---
 drivers/gpu/ipu-v3/Makefile |   2 +-
 drivers/gpu/ipu-v3/ipu-common.c |  11 ++
 drivers/gpu/ipu-v3/ipu-prv.h|   6 +
 drivers/gpu/ipu-v3/ipu-vdi.c| 266 
 include/video/imx-ipu-v3.h  |  27 
 5 files changed, 311 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/ipu-v3/ipu-vdi.c

diff --git a/drivers/gpu/ipu-v3/Makefile b/drivers/gpu/ipu-v3/Makefile
index 107ec23..aeba9dc 100644
--- a/drivers/gpu/ipu-v3/Makefile
+++ b/drivers/gpu/ipu-v3/Makefile
@@ -1,4 +1,4 @@
 obj-$(CONFIG_IMX_IPUV3_CORE) += imx-ipu-v3.o
 
 imx-ipu-v3-objs := ipu-common.o ipu-cpmem.o ipu-csi.o ipu-dc.o ipu-di.o \
-   ipu-dp.o ipu-dmfc.o ipu-ic.o ipu-smfc.o
+   ipu-dp.o ipu-dmfc.o ipu-ic.o ipu-smfc.o ipu-vdi.o
diff --git a/drivers/gpu/ipu-v3/ipu-common.c b/drivers/gpu/ipu-v3/ipu-common.c
index 99dcacf..30dc115 100644
--- a/drivers/gpu/ipu-v3/ipu-common.c
+++ b/drivers/gpu/ipu-v3/ipu-common.c
@@ -833,6 +833,14 @@ static int ipu_submodules_init(struct ipu_soc *ipu,
goto err_ic;
}
 
+   ret = ipu_vdi_init(ipu, dev, ipu_base + devtype->vdi_ofs,
+  IPU_CONF_VDI_EN | IPU_CONF_ISP_EN |
+  IPU_CONF_IC_INPUT);
+   if (ret) {
+   unit = "vdi";
+   goto err_vdi;
+   }
+
ret = ipu_di_init(ipu, dev, 0, ipu_base + devtype->disp0_ofs,
  IPU_CONF_DI0_EN, ipu_clk);
if (ret) {
@@ -887,6 +895,8 @@ err_dc:
 err_di_1:
ipu_di_exit(ipu, 0);
 err_di_0:
+   ipu_vdi_exit(ipu);
+err_vdi:
ipu_ic_exit(ipu);
 err_ic:
ipu_csi_exit(ipu, 1);
@@ -971,6 +981,7 @@ static void ipu_submodules_exit(struct ipu_soc *ipu)
ipu_dc_exit(ipu);
ipu_di_exit(ipu, 1);
ipu_di_exit(ipu, 0);
+   ipu_vdi_exit(ipu);
ipu_ic_exit(ipu);
ipu_csi_exit(ipu, 1);
ipu_csi_exit(ipu, 0);
diff --git a/drivers/gpu/ipu-v3/ipu-prv.h b/drivers/gpu/ipu-v3/ipu-prv.h
index bfb1e8a..845f64c 100644
--- a/drivers/gpu/ipu-v3/ipu-prv.h
+++ b/drivers/gpu/ipu-v3/ipu-prv.h
@@ -138,6 +138,7 @@ struct ipu_dc_priv;
 struct ipu_dmfc_priv;
 struct ipu_di;
 struct ipu_ic_priv;
+struct ipu_vdi;
 struct ipu_smfc_priv;
 
 struct ipu_devtype;
@@ -169,6 +170,7 @@ struct ipu_soc {
struct ipu_di   *di_priv[2];
struct ipu_csi  *csi_priv[2];
struct ipu_ic_priv  *ic_priv;
+   struct ipu_vdi  *vdi_priv;
struct ipu_smfc_priv*smfc_priv;
 };
 
@@ -199,6 +201,10 @@ int ipu_ic_init(struct ipu_soc *ipu, struct device *dev,
unsigned long base, unsigned long tpmem_base);
 void ipu_ic_exit(struct ipu_soc *ipu);
 
+int ipu_vdi_init(struct ipu_soc *ipu, struct device *dev,
+unsigned long base, u32 module);
+void ipu_vdi_exit(struct ipu_soc *ipu);
+
 int ipu_di_init(struct ipu_soc *ipu, struct device *dev, int id,
unsigned long base, u32 module, struct clk *ipu_clk);
 void ipu_di_exit(struct ipu_soc *ipu, int id);
diff --git a/drivers/gpu/ipu-v3/ipu-vdi.c b/drivers/gpu/ipu-v3/ipu-vdi.c
new file mode 100644
index 000..1303bcc
--- /dev/null
+++ b/drivers/gpu/ipu-v3/ipu-vdi.c
@@ -0,0 +1,266 @@
+/*
+ * Copyright (C) 2012 Mentor Graphics Inc.
+ * Copyright (C) 2005-2009 Freescale Semiconductor, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * This 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 "ipu-prv.h"
+
+struct ipu_vdi {
+   void __iomem *base;
+   u32 module;
+   spinlock_t lock;
+   int use_count;
+   struct ipu_soc *ipu;
+};
+
+
+/* VDI Register Offsets */
+#define VDI_FSIZE 0x
+#define VDI_C 0x0004
+
+/* VDI Register Fields */
+#define VDI_C_CH_420 (0 << 1)
+#define VDI_C_CH_422 (1 << 1)
+#define VDI_C_MOT_SEL_MASK   (0x3 << 2)
+#define VDI_C_MOT_SEL_FULL   (2 << 2)
+#define VDI_C_MOT_SEL_LOW(1 << 2)
+#define VDI_C_MOT_SEL_MED(0 << 2)
+#define VDI_C_BURST_SIZE1_4  (3 << 4)
+#define VDI_C_BURST_SIZE2_4  (3 << 8)
+#define VDI_C_BURST_SIZE3_4  (3 << 12)
+#define VDI_C_BURST_SIZE_MASK0xF
+#define VDI_C_BURST_SIZE1_OFFSET 4
+#define VDI_C_BURST_SIZE2_OFFSET 8
+#define VDI_C_BURST_SIZE3_OFFSET 12
+#define VDI_C_V

[PATCH 08/28] gpu: ipu-v3: Add ipu_csi_set_src()

2016-07-06 Thread Steve Longerbeam
Adds ipu_csi_set_src() which is just a wrapper around
ipu_set_csi_src_mux().

Signed-off-by: Steve Longerbeam 
---
 drivers/gpu/ipu-v3/ipu-csi.c | 8 
 include/video/imx-ipu-v3.h   | 1 +
 2 files changed, 9 insertions(+)

diff --git a/drivers/gpu/ipu-v3/ipu-csi.c b/drivers/gpu/ipu-v3/ipu-csi.c
index 06631ac..336dc06 100644
--- a/drivers/gpu/ipu-v3/ipu-csi.c
+++ b/drivers/gpu/ipu-v3/ipu-csi.c
@@ -609,6 +609,14 @@ int ipu_csi_set_skip_smfc(struct ipu_csi *csi, u32 skip,
 }
 EXPORT_SYMBOL_GPL(ipu_csi_set_skip_smfc);
 
+int ipu_csi_set_src(struct ipu_csi *csi, u32 vc, bool select_mipi_csi2)
+{
+   ipu_set_csi_src_mux(csi->ipu, csi->id, select_mipi_csi2);
+
+   return 0;
+}
+EXPORT_SYMBOL_GPL(ipu_csi_set_src);
+
 int ipu_csi_set_dest(struct ipu_csi *csi, enum ipu_csi_dest csi_dest)
 {
unsigned long flags;
diff --git a/include/video/imx-ipu-v3.h b/include/video/imx-ipu-v3.h
index 2302fc5..57b487d 100644
--- a/include/video/imx-ipu-v3.h
+++ b/include/video/imx-ipu-v3.h
@@ -301,6 +301,7 @@ int ipu_csi_set_mipi_datatype(struct ipu_csi *csi, u32 vc,
  struct v4l2_mbus_framefmt *mbus_fmt);
 int ipu_csi_set_skip_smfc(struct ipu_csi *csi, u32 skip,
  u32 max_ratio, u32 id);
+int ipu_csi_set_src(struct ipu_csi *csi, u32 vc, bool select_mipi_csi2);
 int ipu_csi_set_dest(struct ipu_csi *csi, enum ipu_csi_dest csi_dest);
 int ipu_csi_enable(struct ipu_csi *csi);
 int ipu_csi_disable(struct ipu_csi *csi);
-- 
1.9.1

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


[PATCH 09/28] gpu: ipu-v3: Add ipu_ic_set_src()

2016-07-06 Thread Steve Longerbeam
Adds ipu_ic_set_src() which is just aa wrapper around
ipu_set_ic_src_mux().

Signed-off-by: Steve Longerbeam 
---
 drivers/gpu/ipu-v3/ipu-ic.c | 10 ++
 include/video/imx-ipu-v3.h  |  1 +
 2 files changed, 11 insertions(+)

diff --git a/drivers/gpu/ipu-v3/ipu-ic.c b/drivers/gpu/ipu-v3/ipu-ic.c
index 1dcb96c..f306a9c 100644
--- a/drivers/gpu/ipu-v3/ipu-ic.c
+++ b/drivers/gpu/ipu-v3/ipu-ic.c
@@ -629,6 +629,16 @@ unlock:
 }
 EXPORT_SYMBOL_GPL(ipu_ic_task_idma_init);
 
+int ipu_ic_set_src(struct ipu_ic *ic, int csi_id, bool vdi)
+{
+   struct ipu_ic_priv *priv = ic->priv;
+
+   ipu_set_ic_src_mux(priv->ipu, csi_id, vdi);
+
+   return 0;
+}
+EXPORT_SYMBOL_GPL(ipu_ic_set_src);
+
 int ipu_ic_enable(struct ipu_ic *ic)
 {
struct ipu_ic_priv *priv = ic->priv;
diff --git a/include/video/imx-ipu-v3.h b/include/video/imx-ipu-v3.h
index 57b487d..8f77ddb 100644
--- a/include/video/imx-ipu-v3.h
+++ b/include/video/imx-ipu-v3.h
@@ -334,6 +334,7 @@ void ipu_ic_task_disable(struct ipu_ic *ic);
 int ipu_ic_task_idma_init(struct ipu_ic *ic, struct ipuv3_channel *channel,
  u32 width, u32 height, int burst_size,
  enum ipu_rotate_mode rot);
+int ipu_ic_set_src(struct ipu_ic *ic, int csi_id, bool vdi);
 int ipu_ic_enable(struct ipu_ic *ic);
 int ipu_ic_disable(struct ipu_ic *ic);
 struct ipu_ic *ipu_ic_get(struct ipu_soc *ipu, enum ipu_ic_task task);
-- 
1.9.1

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


[PATCH 04/28] gpu: ipu-v3: Add ipu_get_num()

2016-07-06 Thread Steve Longerbeam
Adds of-alias id to ipu_soc and retrieve with ipu_get_num().

Signed-off-by: Steve Longerbeam 
---
 drivers/gpu/ipu-v3/ipu-common.c | 8 
 drivers/gpu/ipu-v3/ipu-prv.h| 1 +
 include/video/imx-ipu-v3.h  | 1 +
 3 files changed, 10 insertions(+)

diff --git a/drivers/gpu/ipu-v3/ipu-common.c b/drivers/gpu/ipu-v3/ipu-common.c
index 30dc115..49af121 100644
--- a/drivers/gpu/ipu-v3/ipu-common.c
+++ b/drivers/gpu/ipu-v3/ipu-common.c
@@ -45,6 +45,12 @@ static inline void ipu_cm_write(struct ipu_soc *ipu, u32 
value, unsigned offset)
writel(value, ipu->cm_reg + offset);
 }
 
+int ipu_get_num(struct ipu_soc *ipu)
+{
+   return ipu->id;
+}
+EXPORT_SYMBOL_GPL(ipu_get_num);
+
 void ipu_srm_dp_sync_update(struct ipu_soc *ipu)
 {
u32 val;
@@ -1220,6 +1226,7 @@ static int ipu_probe(struct platform_device *pdev)
 {
const struct of_device_id *of_id =
of_match_device(imx_ipu_dt_ids, &pdev->dev);
+   struct device_node *np = pdev->dev.of_node;
struct ipu_soc *ipu;
struct resource *res;
unsigned long ipu_base;
@@ -1248,6 +1255,7 @@ static int ipu_probe(struct platform_device *pdev)
ipu->channel[i].ipu = ipu;
ipu->devtype = devtype;
ipu->ipu_type = devtype->type;
+   ipu->id = of_alias_get_id(np, "ipu");
 
spin_lock_init(&ipu->lock);
mutex_init(&ipu->channel_lock);
diff --git a/drivers/gpu/ipu-v3/ipu-prv.h b/drivers/gpu/ipu-v3/ipu-prv.h
index 845f64c..02057d8 100644
--- a/drivers/gpu/ipu-v3/ipu-prv.h
+++ b/drivers/gpu/ipu-v3/ipu-prv.h
@@ -153,6 +153,7 @@ struct ipu_soc {
void __iomem*cm_reg;
void __iomem*idmac_reg;
 
+   int id;
int usecount;
 
struct clk  *clk;
diff --git a/include/video/imx-ipu-v3.h b/include/video/imx-ipu-v3.h
index 60540ead..b174f8a 100644
--- a/include/video/imx-ipu-v3.h
+++ b/include/video/imx-ipu-v3.h
@@ -148,6 +148,7 @@ int ipu_idmac_channel_irq(struct ipu_soc *ipu, struct 
ipuv3_channel *channel,
 /*
  * IPU Common functions
  */
+int ipu_get_num(struct ipu_soc *ipu);
 void ipu_set_csi_src_mux(struct ipu_soc *ipu, int csi_id, bool mipi_csi2);
 void ipu_set_ic_src_mux(struct ipu_soc *ipu, int csi_id, bool vdi);
 void ipu_dump(struct ipu_soc *ipu);
-- 
1.9.1

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


[PATCH 10/28] gpu: ipu-v3: set correct full sensor frame for PAL/NTSC

2016-07-06 Thread Steve Longerbeam
Set the sensor full frame based on whether the passed in mbus_fmt
is 720x480 (NTSC) or 720x576 (PAL).

Signed-off-by: Steve Longerbeam 
---
 drivers/gpu/ipu-v3/ipu-csi.c | 20 +---
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/ipu-v3/ipu-csi.c b/drivers/gpu/ipu-v3/ipu-csi.c
index 336dc06..07c7091 100644
--- a/drivers/gpu/ipu-v3/ipu-csi.c
+++ b/drivers/gpu/ipu-v3/ipu-csi.c
@@ -365,10 +365,14 @@ int ipu_csi_init_interface(struct ipu_csi *csi,
 {
struct ipu_csi_bus_config cfg;
unsigned long flags;
-   u32 data = 0;
+   u32 width, height, data = 0;
 
fill_csi_bus_cfg(&cfg, mbus_cfg, mbus_fmt);
 
+   /* set default sensor frame width and height */
+   width = mbus_fmt->width;
+   height = mbus_fmt->height;
+
/* Set the CSI_SENS_CONF register remaining fields */
data |= cfg.data_width << CSI_SENS_CONF_DATA_WIDTH_SHIFT |
cfg.data_fmt << CSI_SENS_CONF_DATA_FMT_SHIFT |
@@ -386,11 +390,6 @@ int ipu_csi_init_interface(struct ipu_csi *csi,
 
ipu_csi_write(csi, data, CSI_SENS_CONF);
 
-   /* Setup sensor frame size */
-   ipu_csi_write(csi,
- (mbus_fmt->width - 1) | ((mbus_fmt->height - 1) << 16),
- CSI_SENS_FRM_SIZE);
-
/* Set CCIR registers */
 
switch (cfg.clk_mode) {
@@ -408,11 +407,12 @@ int ipu_csi_init_interface(struct ipu_csi *csi,
 * Field1BlankEnd = 0x7, Field1BlankStart = 0x3,
 * Field1ActiveEnd = 0x5, Field1ActiveStart = 0x1
 */
+   height = 625; /* framelines for PAL */
+
ipu_csi_write(csi, 0x40596 | CSI_CCIR_ERR_DET_EN,
  CSI_CCIR_CODE_1);
ipu_csi_write(csi, 0xD07DF, CSI_CCIR_CODE_2);
ipu_csi_write(csi, 0xFF, CSI_CCIR_CODE_3);
-
} else if (mbus_fmt->width == 720 && mbus_fmt->height == 480) {
/*
 * NTSC case
@@ -422,6 +422,8 @@ int ipu_csi_init_interface(struct ipu_csi *csi,
 * Field1BlankEnd = 0x6, Field1BlankStart = 0x2,
 * Field1ActiveEnd = 0x4, Field1ActiveStart = 0
 */
+   height = 525; /* framelines for NTSC */
+
ipu_csi_write(csi, 0xD07DF | CSI_CCIR_ERR_DET_EN,
  CSI_CCIR_CODE_1);
ipu_csi_write(csi, 0x40596, CSI_CCIR_CODE_2);
@@ -447,6 +449,10 @@ int ipu_csi_init_interface(struct ipu_csi *csi,
break;
}
 
+   /* Setup sensor frame size */
+   ipu_csi_write(csi, (width - 1) | ((height - 1) << 16),
+ CSI_SENS_FRM_SIZE);
+
dev_dbg(csi->ipu->dev, "CSI_SENS_CONF = 0x%08X\n",
ipu_csi_read(csi, CSI_SENS_CONF));
dev_dbg(csi->ipu->dev, "CSI_ACT_FRM_SIZE = 0x%08X\n",
-- 
1.9.1

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


[PATCH 16/28] gpu: ipu-v3: rename CSI client device

2016-07-06 Thread Steve Longerbeam
Rename the CSI client device in the client_reg[] table to
"imx-ipuv3-csi".

Signed-off-by: Steve Longerbeam 
---
 drivers/gpu/ipu-v3/ipu-common.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/ipu-v3/ipu-common.c b/drivers/gpu/ipu-v3/ipu-common.c
index 374100e..bd6771b 100644
--- a/drivers/gpu/ipu-v3/ipu-common.c
+++ b/drivers/gpu/ipu-v3/ipu-common.c
@@ -1153,14 +1153,14 @@ static struct ipu_platform_reg client_reg[] = {
.dma[0] = IPUV3_CHANNEL_CSI0,
.dma[1] = -EINVAL,
},
-   .name = "imx-ipuv3-camera",
+   .name = "imx-ipuv3-csi",
}, {
.pdata = {
.csi = 1,
.dma[0] = IPUV3_CHANNEL_CSI1,
.dma[1] = -EINVAL,
},
-   .name = "imx-ipuv3-camera",
+   .name = "imx-ipuv3-csi",
}, {
.pdata = {
.di = 0,
-- 
1.9.1

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


[PATCH 13/28] gpu: ipu-v3: Fix IRT usage

2016-07-06 Thread Steve Longerbeam
There can be multiple IC tasks using the IRT, so the IRT needs
a separate use counter. Create a private ipu_irt_enable() to
enable the IRT module when any IC task requires rotation, and
ipu_irt_disable() when a task no longer needs the IRT.

Signed-off-by: Steve Longerbeam 
---
 drivers/gpu/ipu-v3/ipu-ic.c | 43 ++-
 1 file changed, 34 insertions(+), 9 deletions(-)

diff --git a/drivers/gpu/ipu-v3/ipu-ic.c b/drivers/gpu/ipu-v3/ipu-ic.c
index f306a9c..5329bfe 100644
--- a/drivers/gpu/ipu-v3/ipu-ic.c
+++ b/drivers/gpu/ipu-v3/ipu-ic.c
@@ -160,6 +160,7 @@ struct ipu_ic_priv {
spinlock_t lock;
struct ipu_soc *ipu;
int use_count;
+   int irt_use_count;
struct ipu_ic task[IC_NUM_TASKS];
 };
 
@@ -379,8 +380,6 @@ void ipu_ic_task_disable(struct ipu_ic *ic)
 
ipu_ic_write(ic, ic_conf, IC_CONF);
 
-   ic->rotation = ic->graphics = false;
-
spin_unlock_irqrestore(&priv->lock, flags);
 }
 EXPORT_SYMBOL_GPL(ipu_ic_task_disable);
@@ -639,22 +638,44 @@ int ipu_ic_set_src(struct ipu_ic *ic, int csi_id, bool 
vdi)
 }
 EXPORT_SYMBOL_GPL(ipu_ic_set_src);
 
+static void ipu_irt_enable(struct ipu_ic *ic)
+{
+   struct ipu_ic_priv *priv = ic->priv;
+
+   if (!priv->irt_use_count)
+   ipu_module_enable(priv->ipu, IPU_CONF_ROT_EN);
+
+   priv->irt_use_count++;
+}
+
+static void ipu_irt_disable(struct ipu_ic *ic)
+{
+   struct ipu_ic_priv *priv = ic->priv;
+
+   priv->irt_use_count--;
+
+   if (!priv->irt_use_count)
+   ipu_module_disable(priv->ipu, IPU_CONF_ROT_EN);
+
+   if (priv->irt_use_count < 0)
+   priv->irt_use_count = 0;
+}
+
 int ipu_ic_enable(struct ipu_ic *ic)
 {
struct ipu_ic_priv *priv = ic->priv;
unsigned long flags;
-   u32 module = IPU_CONF_IC_EN;
 
spin_lock_irqsave(&priv->lock, flags);
 
-   if (ic->rotation)
-   module |= IPU_CONF_ROT_EN;
-
if (!priv->use_count)
-   ipu_module_enable(priv->ipu, module);
+   ipu_module_enable(priv->ipu, IPU_CONF_IC_EN);
 
priv->use_count++;
 
+   if (ic->rotation)
+   ipu_irt_enable(ic);
+
spin_unlock_irqrestore(&priv->lock, flags);
 
return 0;
@@ -665,18 +686,22 @@ int ipu_ic_disable(struct ipu_ic *ic)
 {
struct ipu_ic_priv *priv = ic->priv;
unsigned long flags;
-   u32 module = IPU_CONF_IC_EN | IPU_CONF_ROT_EN;
 
spin_lock_irqsave(&priv->lock, flags);
 
priv->use_count--;
 
if (!priv->use_count)
-   ipu_module_disable(priv->ipu, module);
+   ipu_module_disable(priv->ipu, IPU_CONF_IC_EN);
 
if (priv->use_count < 0)
priv->use_count = 0;
 
+   if (ic->rotation)
+   ipu_irt_disable(ic);
+
+   ic->rotation = ic->graphics = false;
+
spin_unlock_irqrestore(&priv->lock, flags);
 
return 0;
-- 
1.9.1

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


[PATCH 12/28] gpu: ipu-v3: Fix CSI0 blur in NTSC format

2016-07-06 Thread Steve Longerbeam
From: Suresh Dhandapani 

This patch will change the register IPU_CSI0_CCIR_CODE_2 value from
0x40596 to 0x405A6. The change is related to the Start of field 1
first blanking line command bit[5-3] for NTSC format only. This
change is dependent with ADV chip where the NEWAVMODE is set to 0
in register 0x31. Setting NEWAVMODE to "0" in ADV means "EAV/SAV
codes generated to suit analog devices encoders".

Signed-off-by: Suresh Dhandapani 
---
 drivers/gpu/ipu-v3/ipu-csi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/ipu-v3/ipu-csi.c b/drivers/gpu/ipu-v3/ipu-csi.c
index 0eac28c..ec81958 100644
--- a/drivers/gpu/ipu-v3/ipu-csi.c
+++ b/drivers/gpu/ipu-v3/ipu-csi.c
@@ -422,7 +422,7 @@ int ipu_csi_init_interface(struct ipu_csi *csi,
 
ipu_csi_write(csi, 0xD07DF | CSI_CCIR_ERR_DET_EN,
  CSI_CCIR_CODE_1);
-   ipu_csi_write(csi, 0x40596, CSI_CCIR_CODE_2);
+   ipu_csi_write(csi, 0x405A6, CSI_CCIR_CODE_2);
ipu_csi_write(csi, 0xFF, CSI_CCIR_CODE_3);
} else {
dev_err(csi->ipu->dev,
-- 
1.9.1

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


[PATCH 05/28] gpu: ipu-v3: Add IDMA channel linking support

2016-07-06 Thread Steve Longerbeam
Adds functions to link and unlink IDMAC source channels to sink
channels.

So far the following links are supported:

IPUV3_CHANNEL_IC_PRP_ENC_MEM -> IPUV3_CHANNEL_MEM_ROT_ENC
PUV3_CHANNEL_IC_PRP_VF_MEM   -> IPUV3_CHANNEL_MEM_ROT_VF
IPUV3_CHANNEL_IC_PP_MEM  -> IPUV3_CHANNEL_MEM_ROT_PP

More links can be added to the idmac_link_info[] array.

Signed-off-by: Steve Longerbeam 
---
 drivers/gpu/ipu-v3/ipu-common.c | 112 
 include/video/imx-ipu-v3.h  |   3 ++
 2 files changed, 115 insertions(+)

diff --git a/drivers/gpu/ipu-v3/ipu-common.c b/drivers/gpu/ipu-v3/ipu-common.c
index 49af121..6d1676e 100644
--- a/drivers/gpu/ipu-v3/ipu-common.c
+++ b/drivers/gpu/ipu-v3/ipu-common.c
@@ -730,6 +730,118 @@ void ipu_set_ic_src_mux(struct ipu_soc *ipu, int csi_id, 
bool vdi)
 }
 EXPORT_SYMBOL_GPL(ipu_set_ic_src_mux);
 
+
+/* IDMAC Channel Linking */
+
+struct idmac_link_reg_info {
+   int chno;
+   u32 reg;
+   int shift;
+   int bits;
+   u32 sel;
+};
+
+struct idmac_link_info {
+   struct idmac_link_reg_info src;
+   struct idmac_link_reg_info sink;
+};
+
+static const struct idmac_link_info idmac_link_info[] = {
+   {
+   .src  = { 20, IPU_FS_PROC_FLOW1,  0, 4, 7 },
+   .sink = { 45, IPU_FS_PROC_FLOW2,  0, 4, 1 },
+   }, {
+   .src =  { 21, IPU_FS_PROC_FLOW1,  8, 4, 8 },
+   .sink = { 46, IPU_FS_PROC_FLOW2,  4, 4, 1 },
+   }, {
+   .src =  { 22, IPU_FS_PROC_FLOW1, 16, 4, 5 },
+   .sink = { 47, IPU_FS_PROC_FLOW2, 12, 4, 3 },
+   },
+};
+
+static const struct idmac_link_info *find_idmac_link_info(
+   struct ipuv3_channel *src, struct ipuv3_channel *sink)
+{
+   int i;
+
+   for (i = 0; i < ARRAY_SIZE(idmac_link_info); i++) {
+   if (src->num == idmac_link_info[i].src.chno &&
+   sink->num == idmac_link_info[i].sink.chno)
+   return &idmac_link_info[i];
+   }
+
+   return NULL;
+}
+
+/*
+ * Links an IDMAC source channel to a sink channel.
+ */
+int ipu_idmac_link(struct ipuv3_channel *src, struct ipuv3_channel *sink)
+{
+   struct ipu_soc *ipu = src->ipu;
+   const struct idmac_link_info *link;
+   u32 src_reg, sink_reg, src_mask, sink_mask;
+   unsigned long flags;
+
+   link = find_idmac_link_info(src, sink);
+   if (!link)
+   return -EINVAL;
+
+   src_mask = ((1 << link->src.bits) - 1) << link->src.shift;
+   sink_mask = ((1 << link->sink.bits) - 1) << link->sink.shift;
+
+   spin_lock_irqsave(&ipu->lock, flags);
+
+   src_reg = ipu_cm_read(ipu, link->src.reg);
+   sink_reg = ipu_cm_read(ipu, link->sink.reg);
+
+   src_reg &= ~src_mask;
+   src_reg |= (link->src.sel << link->src.shift);
+
+   sink_reg &= ~sink_mask;
+   sink_reg |= (link->sink.sel << link->sink.shift);
+
+   ipu_cm_write(ipu, src_reg, link->src.reg);
+   ipu_cm_write(ipu, sink_reg, link->sink.reg);
+
+   spin_unlock_irqrestore(&ipu->lock, flags);
+   return 0;
+}
+EXPORT_SYMBOL_GPL(ipu_idmac_link);
+
+/*
+ * Unlinks IDMAC source and sink channels.
+ */
+int ipu_idmac_unlink(struct ipuv3_channel *src, struct ipuv3_channel *sink)
+{
+   struct ipu_soc *ipu = src->ipu;
+   const struct idmac_link_info *link;
+   u32 src_reg, sink_reg, src_mask, sink_mask;
+   unsigned long flags;
+
+   link = find_idmac_link_info(src, sink);
+   if (!link)
+   return -EINVAL;
+
+   src_mask = ((1 << link->src.bits) - 1) << link->src.shift;
+   sink_mask = ((1 << link->sink.bits) - 1) << link->sink.shift;
+
+   spin_lock_irqsave(&ipu->lock, flags);
+
+   src_reg = ipu_cm_read(ipu, link->src.reg);
+   sink_reg = ipu_cm_read(ipu, link->sink.reg);
+
+   src_reg &= ~src_mask;
+   sink_reg &= ~sink_mask;
+
+   ipu_cm_write(ipu, src_reg, link->src.reg);
+   ipu_cm_write(ipu, sink_reg, link->sink.reg);
+
+   spin_unlock_irqrestore(&ipu->lock, flags);
+   return 0;
+}
+EXPORT_SYMBOL_GPL(ipu_idmac_unlink);
+
 struct ipu_devtype {
const char *name;
unsigned long cm_ofs;
diff --git a/include/video/imx-ipu-v3.h b/include/video/imx-ipu-v3.h
index b174f8a..0a39c64 100644
--- a/include/video/imx-ipu-v3.h
+++ b/include/video/imx-ipu-v3.h
@@ -128,6 +128,7 @@ enum ipu_channel_irq {
 #define IPUV3_CHANNEL_ROT_VF_MEM   49
 #define IPUV3_CHANNEL_ROT_PP_MEM   50
 #define IPUV3_CHANNEL_MEM_BG_SYNC_ALPHA51
+#define IPUV3_NUM_CHANNELS 64
 
 int ipu_map_irq(struct ipu_soc *ipu, int irq);
 int ipu_idmac_channel_irq(struct ipu_soc *ipu, struct ipuv3_channel *channel,
@@ -171,6 +172,8 @@ int ipu_idmac_get_current_buffer(struct ipuv3_

[PATCH 17/28] gpio: pca953x: Add optional reset gpio control

2016-07-06 Thread Steve Longerbeam
Add optional reset-gpios pin control. If present, de-assert the
specified reset gpio pin to bring the chip out of reset.

Signed-off-by: Steve Longerbeam 
---
 drivers/gpio/gpio-pca953x.c | 18 ++
 1 file changed, 18 insertions(+)

diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c
index 5e3be32..8698815 100644
--- a/drivers/gpio/gpio-pca953x.c
+++ b/drivers/gpio/gpio-pca953x.c
@@ -21,6 +21,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #define PCA953X_INPUT  0
 #define PCA953X_OUTPUT 1
@@ -111,6 +112,8 @@ struct pca953x_chip {
const char *const *names;
int chip_type;
unsigned long driver_data;
+
+   struct gpio_desc *reset_gpio;
 };
 
 static int pca953x_read_single(struct pca953x_chip *chip, int reg, u32 *val,
@@ -759,6 +762,21 @@ static int pca953x_probe(struct i2c_client *client,
} else {
chip->gpio_start = -1;
irq_base = 0;
+
+   /* see if we need to de-assert a reset pin */
+   chip->reset_gpio = devm_gpiod_get_optional(&client->dev,
+  "reset",
+  GPIOD_OUT_LOW);
+   if (IS_ERR(chip->reset_gpio)) {
+   dev_err(&client->dev, "request for reset pin failed\n");
+   return PTR_ERR(chip->reset_gpio);
+   }
+
+   if (chip->reset_gpio) {
+   /* bring chip out of reset */
+   dev_info(&client->dev, "releasing reset\n");
+   gpiod_set_value(chip->reset_gpio, 0);
+   }
}
 
chip->client = client;
-- 
1.9.1

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


[PATCH 07/28] gpu: ipu-v3: Add VDI input IDMAC channels

2016-07-06 Thread Steve Longerbeam
Adds the VDIC field input IDMAC channels. These channels
transfer fields F(n-1), F(n), and F(N+1) from memory to
the VDIC (channels 8, 9, 10 respectively).

Signed-off-by: Steve Longerbeam 
---
 include/video/imx-ipu-v3.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/include/video/imx-ipu-v3.h b/include/video/imx-ipu-v3.h
index 586979e..2302fc5 100644
--- a/include/video/imx-ipu-v3.h
+++ b/include/video/imx-ipu-v3.h
@@ -107,6 +107,9 @@ enum ipu_channel_irq {
 #define IPUV3_CHANNEL_CSI2  2
 #define IPUV3_CHANNEL_CSI3  3
 #define IPUV3_CHANNEL_VDI_MEM_IC_VF 5
+#define IPUV3_CHANNEL_MEM_VDI_P 8
+#define IPUV3_CHANNEL_MEM_VDI   9
+#define IPUV3_CHANNEL_MEM_VDI_N10
 #define IPUV3_CHANNEL_MEM_IC_PP11
 #define IPUV3_CHANNEL_MEM_IC_PRP_VF12
 #define IPUV3_CHANNEL_G_MEM_IC_PRP_VF  14
-- 
1.9.1

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


[PATCH 14/28] gpu: ipu-ic: Add complete image conversion support with tiling

2016-07-06 Thread Steve Longerbeam
This patch implements complete image conversion support to ipu-ic,
with tiling to support scaling to and from images up to 4096x4096.
Image rotation is also supported.

The internal API is subsystem agnostic (no V4L2 dependency except
for the use of V4L2 fourcc pixel formats).

Callers prepare for image conversion by calling
ipu_image_convert_prepare(), which initializes the parameters of
the conversion. The caller passes in the ipu_ic task to use for
the conversion, the input and output image formats, a rotation mode,
and a completion callback and completion context pointer:

struct image_converter_ctx *
ipu_image_convert_prepare(struct ipu_ic *ic,
  struct ipu_image *in, struct ipu_image *out,
  enum ipu_rotate_mode rot_mode,
  image_converter_cb_t complete,
  void *complete_context);

The caller is given a new conversion context that must be passed to
the further APIs:

struct image_converter_run *
ipu_image_convert_run(struct image_converter_ctx *ctx,
  dma_addr_t in_phys, dma_addr_t out_phys);

This queues a new image conversion request to a run queue, and
starts the conversion immediately if the run queue is empty. Only
the physaddr's of the input and output image buffers are needed,
since the conversion context was created previously with
ipu_image_convert_prepare(). Returns a new run object pointer. When
the conversion completes, the run pointer is returned to the
completion callback.

void image_convert_abort(struct image_converter_ctx *ctx);

This will abort any active or pending conversions for this context.
Any currently active or pending runs belonging to this context are
returned via the completion callback with an error status.

void ipu_image_convert_unprepare(struct image_converter_ctx *ctx);

Unprepares the conversion context. Any active or pending runs will
be aborted by calling image_convert_abort().
---
 drivers/gpu/ipu-v3/ipu-ic.c | 1691 ++-
 include/video/imx-ipu-v3.h  |   57 +-
 2 files changed, 1736 insertions(+), 12 deletions(-)

diff --git a/drivers/gpu/ipu-v3/ipu-ic.c b/drivers/gpu/ipu-v3/ipu-ic.c
index 5329bfe..f6a1125 100644
--- a/drivers/gpu/ipu-v3/ipu-ic.c
+++ b/drivers/gpu/ipu-v3/ipu-ic.c
@@ -17,6 +17,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 #include "ipu-prv.h"
 
 /* IC Register Offsets */
@@ -82,6 +84,40 @@
 #define IC_IDMAC_3_PP_WIDTH_MASK(0x3ff << 20)
 #define IC_IDMAC_3_PP_WIDTH_OFFSET  20
 
+/*
+ * The IC Resizer has a restriction that the output frame from the
+ * resizer must be 1024 or less in both width (pixels) and height
+ * (lines).
+ *
+ * The image conversion support attempts to split up a conversion when
+ * the desired output (converted) frame resolution exceeds the IC resizer
+ * limit of 1024 in either dimension.
+ *
+ * If either dimension of the output frame exceeds the limit, the
+ * dimension is split into 1, 2, or 4 equal stripes, for a maximum
+ * of 4*4 or 16 tiles. A conversion is then carried out for each
+ * tile (but taking care to pass the full frame stride length to
+ * the DMA channel's parameter memory!). IDMA double-buffering is used
+ * to convert each tile back-to-back when possible (see note below
+ * when double_buffering boolean is set).
+ *
+ * Note that the input frame must be split up into the same number
+ * of tiles as the output frame.
+ */
+#define MAX_STRIPES_W4
+#define MAX_STRIPES_H4
+#define MAX_TILES (MAX_STRIPES_W * MAX_STRIPES_H)
+
+#define MIN_W 128
+#define MIN_H 128
+#define MAX_W 4096
+#define MAX_H 4096
+
+enum image_convert_type {
+   IMAGE_CONVERT_IN = 0,
+   IMAGE_CONVERT_OUT,
+};
+
 struct ic_task_regoffs {
u32 rsc;
u32 tpmem_csc[2];
@@ -96,6 +132,16 @@ struct ic_task_bitfields {
u32 ic_cmb_galpha_bit;
 };
 
+struct ic_task_channels {
+   int in;
+   int out;
+   int rot_in;
+   int rot_out;
+   int vdi_in_p;
+   int vdi_in;
+   int vdi_in_n;
+};
+
 static const struct ic_task_regoffs ic_task_reg[IC_NUM_TASKS] = {
[IC_TASK_ENCODER] = {
.rsc = IC_PRP_ENC_RSC,
@@ -138,12 +184,159 @@ static const struct ic_task_bitfields 
ic_task_bit[IC_NUM_TASKS] = {
},
 };
 
+static const struct ic_task_channels ic_task_ch[IC_NUM_TASKS] = {
+   [IC_TASK_ENCODER] = {
+   .out = IPUV3_CHANNEL_IC_PRP_ENC_MEM,
+   .rot_in = IPUV3_CHANNEL_MEM_ROT_ENC,
+   .rot_out = IPUV3_CHANNEL_ROT_ENC_MEM,
+   },
+   [IC_TASK_VIEWFINDER] = {
+   .in = IPUV3_CHANNEL_MEM_IC_PRP_VF,
+   .out = IPUV3_CHANNEL_IC_PRP_VF_MEM,
+   .rot_in = IPUV3_CHANNEL_MEM_ROT_VF,
+   .rot_out = IPUV3_CHANNEL_ROT_VF_MEM,
+   .vdi_in_p = IPUV3_CHANNEL_MEM_VDI_P,
+   .vdi_in = IPUV3_CHANNEL_MEM_VDI,
+   .vdi_in_n = IPUV3_CHANNEL_MEM_VDI_N,
+

[PATCH 21/28] media: imx: Add video switch

2016-07-06 Thread Steve Longerbeam
From: Philipp Zabel 

This driver can handle SoC internal and extern video bus multiplexers,
controlled either by register bit fields or by GPIO.

Signed-off-by: Sascha Hauer 
Signed-off-by: Philipp Zabel 
Signed-off-by: Steve Longerbeam 
---
 drivers/staging/media/imx/capture/Kconfig  |   9 +
 drivers/staging/media/imx/capture/Makefile |   1 +
 .../staging/media/imx/capture/imx-video-switch.c   | 347 +
 3 files changed, 357 insertions(+)
 create mode 100644 drivers/staging/media/imx/capture/imx-video-switch.c

diff --git a/drivers/staging/media/imx/capture/Kconfig 
b/drivers/staging/media/imx/capture/Kconfig
index ac6fce0..1a64011 100644
--- a/drivers/staging/media/imx/capture/Kconfig
+++ b/drivers/staging/media/imx/capture/Kconfig
@@ -8,4 +8,13 @@ config IMX_MIPI_CSI2
  MIPI CSI-2 Receiver driver support. This driver is required
 for sensor drivers with a MIPI CSI2 interface.
 
+config IMX_VIDEO_SWITCH
+   tristate "i.MX5/6 Video Bus Multiplexer"
+   depends on GPIOLIB && VIDEO_IMX_CAMERA
+   default y
+   ---help---
+ This driver provides support for the i.MX5/6 internal video bus
+ multiplexer controlled by register bitfields as well as
+ external multiplexers controller by a GPIO.
+
 endmenu
diff --git a/drivers/staging/media/imx/capture/Makefile 
b/drivers/staging/media/imx/capture/Makefile
index 8961a4f..f17b199 100644
--- a/drivers/staging/media/imx/capture/Makefile
+++ b/drivers/staging/media/imx/capture/Makefile
@@ -4,3 +4,4 @@ imx-camera-objs := imx-camif.o imx-ic-prpenc.o imx-of.o \
 obj-$(CONFIG_VIDEO_IMX_CAMERA) += imx-camera.o
 obj-$(CONFIG_VIDEO_IMX_CAMERA) += imx-csi.o
 obj-$(CONFIG_IMX_MIPI_CSI2) += mipi-csi2.o
+obj-$(CONFIG_IMX_VIDEO_SWITCH) += imx-video-switch.o
diff --git a/drivers/staging/media/imx/capture/imx-video-switch.c 
b/drivers/staging/media/imx/capture/imx-video-switch.c
new file mode 100644
index 000..365616c
--- /dev/null
+++ b/drivers/staging/media/imx/capture/imx-video-switch.c
@@ -0,0 +1,347 @@
+/*
+ * devicetree probed mediacontrol video multiplexer.
+ *
+ * Copyright (C) 2013 Sascha Hauer, Pengutronix
+ * Copyright (c) 2014-2016 Mentor Graphics Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ * This 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 
+
+struct vidsw {
+   struct device *dev;
+   struct v4l2_subdev subdev;
+#ifdef CONFIG_MEDIA_CONTROLLER
+   struct media_pad *pads;
+#endif
+   struct v4l2_mbus_framefmt *format_mbus;
+   struct v4l2_of_endpoint *endpoint;
+   struct regmap_field *field;
+   struct gpio_desc *gpio;
+   int output_pad;
+   int numpads;
+   int active;
+};
+
+#define to_vidsw(sd) container_of(sd, struct vidsw, subdev)
+
+static int vidsw_set_mux(struct vidsw *vidsw, int input_index)
+{
+   if (vidsw->active >= 0) {
+   if (vidsw->active == input_index)
+   return 0;
+   else
+   return -EBUSY;
+   }
+
+   vidsw->active = input_index;
+
+   dev_dbg(vidsw->dev, "setting %d active\n", vidsw->active);
+
+   if (vidsw->field)
+   regmap_field_write(vidsw->field, vidsw->active);
+   else if (vidsw->gpio)
+   gpiod_set_value(vidsw->gpio, vidsw->active);
+
+   return 0;
+}
+
+#ifdef CONFIG_MEDIA_CONTROLLER
+static int vidsw_link_setup(struct media_entity *entity,
+   const struct media_pad *local,
+   const struct media_pad *remote, u32 flags)
+{
+   struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
+   struct vidsw *vidsw = to_vidsw(sd);
+
+   dev_dbg(vidsw->dev, "link setup %s -> %s", remote->entity->name,
+   local->entity->name);
+
+   if (!(flags & MEDIA_LNK_FL_ENABLED)) {
+   if (local->index == vidsw->active) {
+   dev_dbg(vidsw->dev, "going inactive\n");
+   vidsw->active = -1;
+   }
+   return 0;
+   }
+
+   return vidsw_set_mux(vidsw, local->index);
+}
+
+static struct media_entity_operations vidsw_ops = {
+   .link_setup = vidsw_link_setup,
+};
+#endif
+
+static int vidsw_s_routing(struct v4l2_subdev *sd, u32 input,
+  u32 output, u32 config)
+{
+   struct vidsw *vidsw = conta

[PATCH 24/28] media: Add i.MX5/6 mem2mem driver

2016-07-06 Thread Steve Longerbeam
Adds a V4L2 mem2mem driver for i.MX5/6 SoC. Uses the IPU IC image
converter (post-processor task) to perform scaling, rotation, and
color space conversion.

Signed-off-by: Steve Longerbeam 
---
 Documentation/devicetree/bindings/media/imx.txt |   25 +-
 drivers/staging/media/imx/Kconfig   |   12 +
 drivers/staging/media/imx/Makefile  |1 +
 drivers/staging/media/imx/m2m/Makefile  |1 +
 drivers/staging/media/imx/m2m/imx-m2m.c | 1049 +++
 5 files changed, 1087 insertions(+), 1 deletion(-)
 create mode 100644 drivers/staging/media/imx/m2m/Makefile
 create mode 100644 drivers/staging/media/imx/m2m/imx-m2m.c

diff --git a/Documentation/devicetree/bindings/media/imx.txt 
b/Documentation/devicetree/bindings/media/imx.txt
index 5a89b51..67d3817 100644
--- a/Documentation/devicetree/bindings/media/imx.txt
+++ b/Documentation/devicetree/bindings/media/imx.txt
@@ -1,4 +1,27 @@
-Freescale i.MX Video Capture
+Freescale i.MX Video Capture, Mem2Mem
+
+Video Mem2Mem node
+--
+
+This is the imx video mem2mem device node. The mem2mem node is an IPU
+client and uses the register-level primitives of the IPU, so it does
+not require reg or interrupt properties. Only a compatible property
+and the ipu phandle is required.
+
+Required properties:
+- compatible   : "fsl,imx-video-mem2mem";
+- ipu   : the ipu phandle;
+
+Example:
+
+/ {
+   ipum2m0: ipum2m@ipu1 {
+   compatible = "fsl,imx-video-mem2mem";
+   ipu = <&ipu1>;
+   status = "okay";
+   };
+};
+
 
 Video Capture node
 --
diff --git a/drivers/staging/media/imx/Kconfig 
b/drivers/staging/media/imx/Kconfig
index 65e1645..3305daa 100644
--- a/drivers/staging/media/imx/Kconfig
+++ b/drivers/staging/media/imx/Kconfig
@@ -21,3 +21,15 @@ config VIDEO_IMX_CAMERA
 if VIDEO_IMX_CAMERA
 source "drivers/staging/media/imx/capture/Kconfig"
 endif
+
+config VIDEO_IMX_M2M
+   tristate "i.MX5/6 Mem2Mem driver"
+   depends on VIDEO_IMX && VIDEO_DEV
+   select VIDEOBUF2_DMA_CONTIG
+   select V4L2_MEM2MEM_DEV
+   default y
+   ---help---
+ Use the IPU IC Post-processor on the i.MX5/6 SoC for mem2mem
+ processing of buffers. Operations include scaling, rotation,
+ and color space conversion. The driver implements tiling to
+ support scaling up to 4096x4096.
diff --git a/drivers/staging/media/imx/Makefile 
b/drivers/staging/media/imx/Makefile
index 7c97629..b9e31d8 100644
--- a/drivers/staging/media/imx/Makefile
+++ b/drivers/staging/media/imx/Makefile
@@ -1 +1,2 @@
 obj-$(CONFIG_VIDEO_IMX_CAMERA) += capture/
+obj-$(CONFIG_VIDEO_IMX_M2M) += m2m/
diff --git a/drivers/staging/media/imx/m2m/Makefile 
b/drivers/staging/media/imx/m2m/Makefile
new file mode 100644
index 000..287d258
--- /dev/null
+++ b/drivers/staging/media/imx/m2m/Makefile
@@ -0,0 +1 @@
+obj-$(CONFIG_VIDEO_IMX_M2M) += imx-m2m.o
diff --git a/drivers/staging/media/imx/m2m/imx-m2m.c 
b/drivers/staging/media/imx/m2m/imx-m2m.c
new file mode 100644
index 000..66b49ff
--- /dev/null
+++ b/drivers/staging/media/imx/m2m/imx-m2m.c
@@ -0,0 +1,1049 @@
+/*
+ * This is a mem2mem driver for the Freescale i.MX5/6 SOC. It carries out
+ * color-space conversion, downsizing, resizing, and rotation transformations
+ * on input buffers using the IPU Image Converter's Post-Processing task.
+ *
+ * Based on mem2mem_testdev.c by Pawel Osciak.
+ *
+ * Copyright (c) 2012-2013 Mentor Graphics Inc.
+ * Steve Longerbeam 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+MODULE_DESCRIPTION("i.MX5/6 Post-Processing mem2mem device");
+MODULE_AUTHOR("Steve Longerbeam ");
+MODULE_LICENSE("GPL");
+MODULE_VERSION("0.1");
+
+static int instrument;
+module_param(instrument, int, 0);
+MODULE_PARM_DESC(instrument, "1 = enable conversion time measurement");
+
+/* Flags that indicate a format can be used for capture/output */
+#define MEM2MEM_CAPTURE BIT(0)
+#define MEM2MEM_OUTPUT  BIT(1)
+
+#define MEM2MEM_NAME   "imx-m2m"
+
+/* Per queue */
+#define MEM2MEM_DEF_NUM_BUFS   VIDEO_MAX_FRAME
+/* In bytes, per queue */
+#define MEM2MEM_VID_MEM_LIMIT  SZ_256M
+
+#define dprintk(dev, fmt, arg...) \
+   v4l2_dbg(1, 1, &dev->v4l2_dev, "%s: " fmt, __func__, ## arg)
+
+struct m2mx_ctx;
+
+struct m2mx_dev {
+   struct v4l2_device  v4l2_dev;
+   struct video_device *vfd;
+   struct device   *

[PATCH 22/28] media: imx: Add support for MIPI CSI-2 OV5640

2016-07-06 Thread Steve Longerbeam
This driver is based on ov5640_mipi.c from Freescale imx_3.10.17_1.0.0_beta
branch, modified heavily for code cleanup and converted from int-device
to subdev.

Signed-off-by: Steve Longerbeam 
---
 drivers/staging/media/imx/capture/Kconfig   |8 +
 drivers/staging/media/imx/capture/Makefile  |1 +
 drivers/staging/media/imx/capture/ov5640-mipi.c | 2303 +++
 3 files changed, 2312 insertions(+)
 create mode 100644 drivers/staging/media/imx/capture/ov5640-mipi.c

diff --git a/drivers/staging/media/imx/capture/Kconfig 
b/drivers/staging/media/imx/capture/Kconfig
index 1a64011..13d7231 100644
--- a/drivers/staging/media/imx/capture/Kconfig
+++ b/drivers/staging/media/imx/capture/Kconfig
@@ -17,4 +17,12 @@ config IMX_VIDEO_SWITCH
  multiplexer controlled by register bitfields as well as
  external multiplexers controller by a GPIO.
 
+config IMX_CAMERA_OV5640_MIPI
+   tristate "OmniVision OV5640 MIPI CSI-2 camera support"
+   depends on GPIOLIB && VIDEO_IMX_CAMERA
+   select IMX_MIPI_CSI2
+   default y
+   ---help---
+ MIPI CSI-2 OV5640 Camera support.
+
 endmenu
diff --git a/drivers/staging/media/imx/capture/Makefile 
b/drivers/staging/media/imx/capture/Makefile
index f17b199..1ad4fd2 100644
--- a/drivers/staging/media/imx/capture/Makefile
+++ b/drivers/staging/media/imx/capture/Makefile
@@ -5,3 +5,4 @@ obj-$(CONFIG_VIDEO_IMX_CAMERA) += imx-camera.o
 obj-$(CONFIG_VIDEO_IMX_CAMERA) += imx-csi.o
 obj-$(CONFIG_IMX_MIPI_CSI2) += mipi-csi2.o
 obj-$(CONFIG_IMX_VIDEO_SWITCH) += imx-video-switch.o
+obj-$(CONFIG_IMX_CAMERA_OV5640_MIPI) += ov5640-mipi.o
diff --git a/drivers/staging/media/imx/capture/ov5640-mipi.c 
b/drivers/staging/media/imx/capture/ov5640-mipi.c
new file mode 100644
index 000..acc6353
--- /dev/null
+++ b/drivers/staging/media/imx/capture/ov5640-mipi.c
@@ -0,0 +1,2303 @@
+/*
+ * Copyright (c) 2014 Mentor Graphics Inc.
+ * Copyright (C) 2011-2013 Freescale Semiconductor, Inc. All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define OV5640_VOLTAGE_ANALOG   280
+#define OV5640_VOLTAGE_DIGITAL_CORE 150
+#define OV5640_VOLTAGE_DIGITAL_IO   180
+
+#define MIN_FPS 15
+#define MAX_FPS 30
+#define DEFAULT_FPS 30
+
+/* min/typical/max system clock (xclk) frequencies */
+#define OV5640_XCLK_MIN  600
+#define OV5640_XCLK_TYP 2400
+#define OV5640_XCLK_MAX 5400
+
+/* min/typical/max pixel clock (mclk) frequencies */
+#define OV5640_MCLK_MIN 4800
+#define OV5640_MCLK_TYP 4800
+#define OV5640_MCLK_MAX 9600
+
+#define OV5640_CHIP_ID  0x300A
+
+#define OV5640_MAX_CONTROLS 64
+
+enum ov5640_mode {
+   ov5640_mode_MIN = 0,
+   ov5640_mode_QCIF_176_144 = 0,
+   ov5640_mode_QVGA_320_240,
+   ov5640_mode_VGA_640_480,
+   ov5640_mode_NTSC_720_480,
+   ov5640_mode_PAL_720_576,
+   ov5640_mode_XGA_1024_768,
+   ov5640_mode_720P_1280_720,
+   ov5640_mode_1080P_1920_1080,
+   ov5640_mode_QSXGA_2592_1944,
+   ov5640_num_modes,
+   ov5640_mode_INIT = 0xff, /*only for sensor init*/
+};
+
+enum ov5640_frame_rate {
+   ov5640_15_fps,
+   ov5640_30_fps
+};
+
+static int ov5640_framerates[] = {
+   [ov5640_15_fps] = 15,
+   [ov5640_30_fps] = 30,
+};
+#define ov5640_num_framerates ARRAY_SIZE(ov5640_framerates)
+
+/* image size under 1280 * 960 are SUBSAMPLING
+ * image size upper 1280 * 960 are SCALING
+ */
+enum ov5640_downsize_mode {
+   SUBSAMPLING,
+   SCALING,
+};
+
+struct reg_value {
+   u16 reg_addr;
+   u8 val;
+   u8 mask;
+   u32 delay_ms;
+};
+
+struct ov5640_mode_info {
+   enum ov5640_mode mode;
+   enum ov5640_downsize_mode dn_mode;
+   u32 width;
+   u32 height;
+   struct reg_value *init_data_ptr;
+   u32 init_data_size;
+};
+
+struct ov5640_dev {
+   struct i2c_client *i2c_client;
+   struct device *dev;
+   struct v4l2_subdev sd;
+   struct v4l2_ctrl_handler ctrl_hdl;
+   struct v4l2_of_endpoint ep; /* the parsed DT endpoint info */
+   struct v4l2_mbus_framefmt fmt;
+   struct v4l2_captureparm streamcap;
+   struct clk *xclk; /* system clock to OV5640 */
+   int xclk_freq;/* requested xclk freq from devicetree */
+
+   enum ov5640_mode current_mode;
+   enum ov5640_frame_rate current_fr;
+
+   bool on;
+   bool awb_on;
+   bool agc_on;
+
+   /* cached control settings */
+   int ctrl_cache[OV5640_MAX_CONTROLS];
+
+   struct gpi

[PATCH 06/28] gpu: ipu-v3: Add ipu_set_vdi_src_mux()

2016-07-06 Thread Steve Longerbeam
Adds ipu_set_vdi_src_mux() that selects the VDIC input
(from CSI or memory).

Signed-off-by: Steve Longerbeam 
---
 drivers/gpu/ipu-v3/ipu-common.c | 20 
 include/video/imx-ipu-v3.h  |  1 +
 2 files changed, 21 insertions(+)

diff --git a/drivers/gpu/ipu-v3/ipu-common.c b/drivers/gpu/ipu-v3/ipu-common.c
index 6d1676e..374100e 100644
--- a/drivers/gpu/ipu-v3/ipu-common.c
+++ b/drivers/gpu/ipu-v3/ipu-common.c
@@ -730,6 +730,26 @@ void ipu_set_ic_src_mux(struct ipu_soc *ipu, int csi_id, 
bool vdi)
 }
 EXPORT_SYMBOL_GPL(ipu_set_ic_src_mux);
 
+/*
+ * Set the source for the VDIC. Selects either from CSI[01] or memory.
+ */
+void ipu_set_vdi_src_mux(struct ipu_soc *ipu, bool csi)
+{
+   unsigned long flags;
+   u32 val;
+
+   spin_lock_irqsave(&ipu->lock, flags);
+
+   val = ipu_cm_read(ipu, IPU_FS_PROC_FLOW1);
+   val &= ~(0x3 << 28);
+   if (csi)
+   val |= (0x01 << 28);
+   ipu_cm_write(ipu, val, IPU_FS_PROC_FLOW1);
+
+   spin_unlock_irqrestore(&ipu->lock, flags);
+}
+EXPORT_SYMBOL_GPL(ipu_set_vdi_src_mux);
+
 
 /* IDMAC Channel Linking */
 
diff --git a/include/video/imx-ipu-v3.h b/include/video/imx-ipu-v3.h
index 0a39c64..586979e 100644
--- a/include/video/imx-ipu-v3.h
+++ b/include/video/imx-ipu-v3.h
@@ -152,6 +152,7 @@ int ipu_idmac_channel_irq(struct ipu_soc *ipu, struct 
ipuv3_channel *channel,
 int ipu_get_num(struct ipu_soc *ipu);
 void ipu_set_csi_src_mux(struct ipu_soc *ipu, int csi_id, bool mipi_csi2);
 void ipu_set_ic_src_mux(struct ipu_soc *ipu, int csi_id, bool vdi);
+void ipu_set_vdi_src_mux(struct ipu_soc *ipu, bool csi);
 void ipu_dump(struct ipu_soc *ipu);
 
 /*
-- 
1.9.1

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


[PATCH 25/28] ARM: dts: imx6qdl: Flesh out MIPI CSI2 receiver node

2016-07-06 Thread Steve Longerbeam
Add to the MIPI CSI2 receiver node: compatible string, interrupt sources,
clocks.

Signed-off-by: Steve Longerbeam 
---
 arch/arm/boot/dts/imx6qdl.dtsi | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/arch/arm/boot/dts/imx6qdl.dtsi b/arch/arm/boot/dts/imx6qdl.dtsi
index ed613eb..50499eb 100644
--- a/arch/arm/boot/dts/imx6qdl.dtsi
+++ b/arch/arm/boot/dts/imx6qdl.dtsi
@@ -1119,7 +1119,14 @@
};
 
mipi_csi: mipi@021dc000 {
+   compatible = "fsl,imx-mipi-csi2";
reg = <0x021dc000 0x4000>;
+   interrupts = <0 100 0x04>, <0 101 0x04>;
+   clocks = <&clks IMX6QDL_CLK_HSI_TX>,
+<&clks IMX6QDL_CLK_VIDEO_27M>,
+<&clks IMX6QDL_CLK_EIM_SEL>;
+   clock-names = "dphy_clk", "cfg_clk", "pix_clk";
+   status = "disabled";
};
 
mipi_dsi: mipi@021e {
-- 
1.9.1

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


[PATCH 26/28] ARM: dts: imx6qdl: Add mipi_ipu1/2 video muxes, mipi_csi, and their connections

2016-07-06 Thread Steve Longerbeam
From: Philipp Zabel 

This patch adds the device tree graph connecting the input multiplexers
to the IPU CSIs and the MIPI-CSI2 gasket on i.MX6.

On i.MX6Q/D two two-input multiplexers in front of IPU1 CSI0 and IPU2 CSI1
allow to select between CSI0/1 parallel input pads and the MIPI CSI-2 virtual
channels 0/3.

On i.MX6DL/S two five-input multiplexers in front of IPU1 CSI0 and IPU1 CSI1
allow to select between CSI0/1 parallel input pads and any of the four MIPI
CSI-2 virtual channels.

Signed-off-by: Philipp Zabel 
Signed-off-by: Steve Longerbeam 
---
 arch/arm/boot/dts/imx6dl.dtsi  | 183 +
 arch/arm/boot/dts/imx6q.dtsi   | 120 +++
 arch/arm/boot/dts/imx6qdl.dtsi |   6 ++
 3 files changed, 309 insertions(+)

diff --git a/arch/arm/boot/dts/imx6dl.dtsi b/arch/arm/boot/dts/imx6dl.dtsi
index 9a4c22c..41ef065 100644
--- a/arch/arm/boot/dts/imx6dl.dtsi
+++ b/arch/arm/boot/dts/imx6dl.dtsi
@@ -109,6 +109,118 @@
compatible = "fsl,imx-gpu-subsystem";
cores = <&gpu_2d>, <&gpu_3d>;
};
+
+   ipu1_csi0_mux: ipu1_csi0_mux@34 {
+   compatible = "imx-video-mux";
+   reg = <0x34 0x07>;
+   gpr = <&gpr>;
+   #address-cells = <1>;
+   #size-cells = <0>;
+   status = "disabled";
+
+   port@0 {
+   reg = <0>;
+
+   ipu1_csi0_mux_from_mipi_vc0: endpoint {
+   remote-endpoint = <&mipi_vc0_to_ipu1_csi0_mux>;
+   };
+   };
+
+   port@1 {
+   reg = <1>;
+
+   ipu1_csi0_mux_from_mipi_vc1: endpoint {
+   remote-endpoint = <&mipi_vc1_to_ipu1_csi0_mux>;
+   };
+   };
+
+   port@2 {
+   reg = <2>;
+
+   ipu1_csi0_mux_from_mipi_vc2: endpoint {
+   remote-endpoint = <&mipi_vc2_to_ipu1_csi0_mux>;
+   };
+   };
+
+   port@3 {
+   reg = <3>;
+
+   ipu1_csi0_mux_from_mipi_vc3: endpoint {
+   remote-endpoint = <&mipi_vc3_to_ipu1_csi0_mux>;
+   };
+   };
+
+   port@4 {
+   reg = <4>;
+
+   ipu1_csi0_mux_from_parallel_sensor: endpoint {
+   };
+   };
+
+   port@5 {
+   reg = <5>;
+
+   ipu1_csi0_mux_to_ipu1_csi0: endpoint {
+   remote-endpoint = 
<&ipu1_csi0_from_ipu1_csi0_mux>;
+   };
+   };
+   };
+
+   ipu1_csi1_mux: ipu1_csi1_mux@34 {
+   compatible = "imx-video-mux";
+   reg = <0x34 0x38>;
+   gpr = <&gpr>;
+   #address-cells = <1>;
+   #size-cells = <0>;
+   status = "disabled";
+
+   port@0 {
+   reg = <0>;
+
+   ipu1_csi1_mux_from_mipi_vc0: endpoint {
+   remote-endpoint = <&mipi_vc0_to_ipu1_csi1_mux>;
+   };
+   };
+
+   port@1 {
+   reg = <1>;
+
+   ipu1_csi1_mux_from_mipi_vc1: endpoint {
+   remote-endpoint = <&mipi_vc1_to_ipu1_csi1_mux>;
+   };
+   };
+
+   port@2 {
+   reg = <2>;
+
+   ipu1_csi1_mux_from_mipi_vc2: endpoint {
+   remote-endpoint = <&mipi_vc2_to_ipu1_csi1_mux>;
+   };
+   };
+
+   port@3 {
+   reg = <3>;
+
+   ipu1_csi1_mux_from_mipi_vc3: endpoint {
+   remote-endpoint = <&mipi_vc3_to_ipu1_csi1_mux>;
+   };
+   };
+
+   port@4 {
+   reg = <4>;
+
+   ipu1_csi1_mux_from_parallel_sensor: endpoint {
+   };
+   };
+
+   port@5 {
+   reg = <5>;
+
+   ipu1_csi1_mux_to_ipu1_csi1: endpoint {
+   remote-endpoint = 
<&ipu1_csi1_from_ipu1_csi1_mux>;
+   };
+   };
+   };
 };
 
 &gpt {
@@ -131,3 +243,74 @@
 &vpu {
compatible = "fsl,imx6dl-vpu", "cnm,coda960";
 };
+
+&

[PATCH 11/28] gpu: ipu-v3: Fix CSI data format for 16-bit media bus formats

2016-07-06 Thread Steve Longerbeam
The CSI data format was being programmed incorrectly for the
1x16 media bus formats. The CSI data format for 16-bit must
be bayer/generic (CSI_SENS_CONF_DATA_FMT_BAYER).

Suggested-by: Carsten Resch 
Signed-off-by: Steve Longerbeam 
---
 drivers/gpu/ipu-v3/ipu-csi.c | 6 +-
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/drivers/gpu/ipu-v3/ipu-csi.c b/drivers/gpu/ipu-v3/ipu-csi.c
index 07c7091..0eac28c 100644
--- a/drivers/gpu/ipu-v3/ipu-csi.c
+++ b/drivers/gpu/ipu-v3/ipu-csi.c
@@ -258,12 +258,8 @@ static int mbus_code_to_bus_cfg(struct ipu_csi_bus_config 
*cfg, u32 mbus_code)
cfg->data_width = IPU_CSI_DATA_WIDTH_8;
break;
case MEDIA_BUS_FMT_UYVY8_1X16:
-   cfg->data_fmt = CSI_SENS_CONF_DATA_FMT_YUV422_UYVY;
-   cfg->mipi_dt = MIPI_DT_YUV422;
-   cfg->data_width = IPU_CSI_DATA_WIDTH_16;
-   break;
case MEDIA_BUS_FMT_YUYV8_1X16:
-   cfg->data_fmt = CSI_SENS_CONF_DATA_FMT_YUV422_YUYV;
+   cfg->data_fmt = CSI_SENS_CONF_DATA_FMT_BAYER;
cfg->mipi_dt = MIPI_DT_YUV422;
cfg->data_width = IPU_CSI_DATA_WIDTH_16;
break;
-- 
1.9.1

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


[PATCH 20/28] media: imx: Add MIPI CSI-2 Receiver driver

2016-07-06 Thread Steve Longerbeam
Adds MIPI CSI-2 Receiver subdev driver. This subdev is required
for sensors with a MIPI CSI2 interface.

Signed-off-by: Steve Longerbeam 
---
 drivers/staging/media/imx/capture/Kconfig |   8 +
 drivers/staging/media/imx/capture/Makefile|   1 +
 drivers/staging/media/imx/capture/mipi-csi2.c | 373 ++
 3 files changed, 382 insertions(+)
 create mode 100644 drivers/staging/media/imx/capture/mipi-csi2.c

diff --git a/drivers/staging/media/imx/capture/Kconfig 
b/drivers/staging/media/imx/capture/Kconfig
index ee2cbab..ac6fce0 100644
--- a/drivers/staging/media/imx/capture/Kconfig
+++ b/drivers/staging/media/imx/capture/Kconfig
@@ -1,3 +1,11 @@
 menu "i.MX5/6 Camera Sub devices"
 
+config IMX_MIPI_CSI2
+   tristate "MIPI CSI2 Receiver Driver"
+   depends on VIDEO_IMX_CAMERA
+   default y
+   ---help---
+ MIPI CSI-2 Receiver driver support. This driver is required
+for sensor drivers with a MIPI CSI2 interface.
+
 endmenu
diff --git a/drivers/staging/media/imx/capture/Makefile 
b/drivers/staging/media/imx/capture/Makefile
index 5c965f9..8961a4f 100644
--- a/drivers/staging/media/imx/capture/Makefile
+++ b/drivers/staging/media/imx/capture/Makefile
@@ -3,3 +3,4 @@ imx-camera-objs := imx-camif.o imx-ic-prpenc.o imx-of.o \
 
 obj-$(CONFIG_VIDEO_IMX_CAMERA) += imx-camera.o
 obj-$(CONFIG_VIDEO_IMX_CAMERA) += imx-csi.o
+obj-$(CONFIG_IMX_MIPI_CSI2) += mipi-csi2.o
diff --git a/drivers/staging/media/imx/capture/mipi-csi2.c 
b/drivers/staging/media/imx/capture/mipi-csi2.c
new file mode 100644
index 000..8e03c1f
--- /dev/null
+++ b/drivers/staging/media/imx/capture/mipi-csi2.c
@@ -0,0 +1,373 @@
+/*
+ * MIPI CSI-2 Receiver Subdev for Freescale i.MX5/6 SOC.
+ *
+ * Copyright (c) 2012-2014 Mentor Graphics Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+struct imxcsi2_dev {
+   struct device  *dev;
+   struct v4l2_subdev  sd;
+   struct clk *dphy_clk;
+   struct clk *cfg_clk;
+   struct clk *pix_clk; /* what is this? */
+   void __iomem   *base;
+   int intr1;
+   int intr2;
+   struct v4l2_of_bus_mipi_csi2 bus;
+   spinlock_t  lock;
+   boolon;
+};
+
+#define DEVICE_NAME "imx-mipi-csi2"
+
+/* Register offsets */
+#define CSI2_VERSION0x000
+#define CSI2_N_LANES0x004
+#define CSI2_PHY_SHUTDOWNZ  0x008
+#define CSI2_DPHY_RSTZ  0x00c
+#define CSI2_RESETN 0x010
+#define CSI2_PHY_STATE  0x014
+#define CSI2_DATA_IDS_1 0x018
+#define CSI2_DATA_IDS_2 0x01c
+#define CSI2_ERR1   0x020
+#define CSI2_ERR2   0x024
+#define CSI2_MSK1   0x028
+#define CSI2_MSK2   0x02c
+#define CSI2_PHY_TST_CTRL0  0x030
+#define CSI2_PHY_TST_CTRL1  0x034
+#define CSI2_SFT_RESET  0xf00
+
+static inline struct imxcsi2_dev *sd_to_dev(struct v4l2_subdev *sdev)
+{
+   return container_of(sdev, struct imxcsi2_dev, sd);
+}
+
+static inline u32 imxcsi2_read(struct imxcsi2_dev *csi2, unsigned int regoff)
+{
+   return readl(csi2->base + regoff);
+}
+
+static inline void imxcsi2_write(struct imxcsi2_dev *csi2, u32 val,
+unsigned int regoff)
+{
+   writel(val, csi2->base + regoff);
+}
+
+static void imxcsi2_set_lanes(struct imxcsi2_dev *csi2)
+{
+   int lanes = csi2->bus.num_data_lanes;
+   unsigned long flags;
+
+   spin_lock_irqsave(&csi2->lock, flags);
+
+   imxcsi2_write(csi2, lanes - 1, CSI2_N_LANES);
+
+   spin_unlock_irqrestore(&csi2->lock, flags);
+}
+
+static void __imxcsi2_enable(struct imxcsi2_dev *csi2, bool enable)
+{
+   if (enable) {
+   imxcsi2_write(csi2, 0x, CSI2_PHY_SHUTDOWNZ);
+   imxcsi2_write(csi2, 0x, CSI2_DPHY_RSTZ);
+   imxcsi2_write(csi2, 0x, CSI2_RESETN);
+   } else {
+   imxcsi2_write(csi2, 0x0, CSI2_PHY_SHUTDOWNZ);
+   imxcsi2_write(csi2, 0x0, CSI2_DPHY_RSTZ);
+   imxcsi2_write(csi2, 0x0, CSI2_RESETN);
+   }
+}
+
+static void imxcsi2_enable(struct imxcsi2_dev *csi2, bool enable)
+{
+   unsigned long flags;
+
+   spin_lock_irqsave(&csi2->lock, flags);
+   __imxcsi2_enable(csi2, enable);
+   spin_unlock_irqrestore(&csi2->lock, flags);
+}
+
+static void imxcsi2_reset(struct imxcsi2_dev

[PATCH 02/28] gpu: ipu-cpmem: Add ipu_cpmem_set_uv_offset()

2016-07-06 Thread Steve Longerbeam
Adds ipu_cpmem_set_uv_offset(), to set planar U/V offsets.

Signed-off-by: Steve Longerbeam 
---
 drivers/gpu/ipu-v3/ipu-cpmem.c | 7 +++
 include/video/imx-ipu-v3.h | 1 +
 2 files changed, 8 insertions(+)

diff --git a/drivers/gpu/ipu-v3/ipu-cpmem.c b/drivers/gpu/ipu-v3/ipu-cpmem.c
index 6494a4d..a36c35e 100644
--- a/drivers/gpu/ipu-v3/ipu-cpmem.c
+++ b/drivers/gpu/ipu-v3/ipu-cpmem.c
@@ -253,6 +253,13 @@ void ipu_cpmem_set_buffer(struct ipuv3_channel *ch, int 
bufnum, dma_addr_t buf)
 }
 EXPORT_SYMBOL_GPL(ipu_cpmem_set_buffer);
 
+void ipu_cpmem_set_uv_offset(struct ipuv3_channel *ch, u32 u_off, u32 v_off)
+{
+   ipu_ch_param_write_field(ch, IPU_FIELD_UBO, u_off / 8);
+   ipu_ch_param_write_field(ch, IPU_FIELD_VBO, v_off / 8);
+}
+EXPORT_SYMBOL_GPL(ipu_cpmem_set_uv_offset);
+
 void ipu_cpmem_interlaced_scan(struct ipuv3_channel *ch, int stride)
 {
ipu_ch_param_write_field(ch, IPU_FIELD_SO, 1);
diff --git a/include/video/imx-ipu-v3.h b/include/video/imx-ipu-v3.h
index 22662a1..904fd12 100644
--- a/include/video/imx-ipu-v3.h
+++ b/include/video/imx-ipu-v3.h
@@ -194,6 +194,7 @@ void ipu_cpmem_set_resolution(struct ipuv3_channel *ch, int 
xres, int yres);
 void ipu_cpmem_set_stride(struct ipuv3_channel *ch, int stride);
 void ipu_cpmem_set_high_priority(struct ipuv3_channel *ch);
 void ipu_cpmem_set_buffer(struct ipuv3_channel *ch, int bufnum, dma_addr_t 
buf);
+void ipu_cpmem_set_uv_offset(struct ipuv3_channel *ch, u32 u_off, u32 v_off);
 void ipu_cpmem_interlaced_scan(struct ipuv3_channel *ch, int stride);
 void ipu_cpmem_set_axi_id(struct ipuv3_channel *ch, u32 id);
 void ipu_cpmem_set_burstsize(struct ipuv3_channel *ch, int burstsize);
-- 
1.9.1

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


[PATCH 03/28] gpu: ipu-cpmem: Add ipu_cpmem_get_burstsize()

2016-07-06 Thread Steve Longerbeam
Adds ipu_cpmem_get_burstsize().

Signed-off-by: Steve Longerbeam 
---
 drivers/gpu/ipu-v3/ipu-cpmem.c | 6 ++
 include/video/imx-ipu-v3.h | 1 +
 2 files changed, 7 insertions(+)

diff --git a/drivers/gpu/ipu-v3/ipu-cpmem.c b/drivers/gpu/ipu-v3/ipu-cpmem.c
index a36c35e..fcb7dc8 100644
--- a/drivers/gpu/ipu-v3/ipu-cpmem.c
+++ b/drivers/gpu/ipu-v3/ipu-cpmem.c
@@ -275,6 +275,12 @@ void ipu_cpmem_set_axi_id(struct ipuv3_channel *ch, u32 id)
 }
 EXPORT_SYMBOL_GPL(ipu_cpmem_set_axi_id);
 
+int ipu_cpmem_get_burstsize(struct ipuv3_channel *ch)
+{
+   return ipu_ch_param_read_field(ch, IPU_FIELD_NPB) + 1;
+}
+EXPORT_SYMBOL_GPL(ipu_cpmem_get_burstsize);
+
 void ipu_cpmem_set_burstsize(struct ipuv3_channel *ch, int burstsize)
 {
ipu_ch_param_write_field(ch, IPU_FIELD_NPB, burstsize - 1);
diff --git a/include/video/imx-ipu-v3.h b/include/video/imx-ipu-v3.h
index 904fd12..60540ead 100644
--- a/include/video/imx-ipu-v3.h
+++ b/include/video/imx-ipu-v3.h
@@ -197,6 +197,7 @@ void ipu_cpmem_set_buffer(struct ipuv3_channel *ch, int 
bufnum, dma_addr_t buf);
 void ipu_cpmem_set_uv_offset(struct ipuv3_channel *ch, u32 u_off, u32 v_off);
 void ipu_cpmem_interlaced_scan(struct ipuv3_channel *ch, int stride);
 void ipu_cpmem_set_axi_id(struct ipuv3_channel *ch, u32 id);
+int ipu_cpmem_get_burstsize(struct ipuv3_channel *ch);
 void ipu_cpmem_set_burstsize(struct ipuv3_channel *ch, int burstsize);
 void ipu_cpmem_set_block_mode(struct ipuv3_channel *ch);
 void ipu_cpmem_set_rotation(struct ipuv3_channel *ch,
-- 
1.9.1

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


[PATCH 18/28] clocksource/drivers/imx: add input capture support

2016-07-06 Thread Steve Longerbeam
This patch adds support for the input capture function in the
i.MX GPT. Output compare and input capture functions are mixed
in the same register block, so we need to modify the irq ack/enable/
disable primitives to not stomp on the other function.

The input capture API is modelled after request/free irq:

typedef void (*mxc_icap_handler_t)(int, void *, struct timespec *);

int mxc_request_input_capture(unsigned int chan,
  mxc_icap_handler_t handler,
  unsigned long capflags, void *dev_id);

- chan: the channel number being requested (0 or 1).

- handler: a callback when there is an input capture event. The
  handler is given the channel number, the dev_id, and a timespec
  marking the input capture event. The timespec is always reset at
  request time, that is, the first event after request will always
  have a timespec of 0, and will increase thereafter.

- capflags: IRQF_TRIGGER_RISING and/or IRQF_TRIGGER_FALLING. If
  both are specified, events will be triggered on both rising and
  falling edges of the input capture signal.

- dev_id: a context pointer given back to the handler.

void mxc_free_input_capture(unsigned int chan, void *dev_id);

This disables the given input capture channel in the GPT.

Signed-off-by: Steve Longerbeam 
---
 drivers/clocksource/timer-imx-gpt.c | 463 
 include/linux/mxc_icap.h|  20 ++
 2 files changed, 437 insertions(+), 46 deletions(-)
 create mode 100644 include/linux/mxc_icap.h

diff --git a/drivers/clocksource/timer-imx-gpt.c 
b/drivers/clocksource/timer-imx-gpt.c
index 99ec967..1f7f871 100644
--- a/drivers/clocksource/timer-imx-gpt.c
+++ b/drivers/clocksource/timer-imx-gpt.c
@@ -21,6 +21,7 @@
  * MA 02110-1301, USA.
  */
 
+#include 
 #include 
 #include 
 #include 
@@ -32,6 +33,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 #include 
 
 /*
@@ -65,16 +68,53 @@
 #define V2_TCTL_CLK_PER(2 << 6)
 #define V2_TCTL_CLK_OSC_DIV8   (5 << 6)
 #define V2_TCTL_FRR(1 << 9)
+#define V2_TCTL_IM1_BIT16
+#define V2_TCTL_IM2_BIT18
+#define V2_IM_DISABLE  0
+#define V2_IM_RISING   1
+#define V2_IM_FALLING  2
+#define V2_IM_BOTH 3
 #define V2_TCTL_24MEN  (1 << 10)
 #define V2_TPRER_PRE24M12
 #define V2_IR  0x0c
+#define V2_IR_OF1  (1 << 0)
+#define V2_IR_IF1  (1 << 3)
+#define V2_IR_IF2  (1 << 4)
 #define V2_TSTAT   0x08
 #define V2_TSTAT_OF1   (1 << 0)
+#define V2_TSTAT_IF1   (1 << 3)
+#define V2_TSTAT_IF2   (1 << 4)
 #define V2_TCN 0x24
 #define V2_TCMP0x10
+#define V2_TCAP1   0x1c
+#define V2_TCAP2   0x20
 
 #define V2_TIMER_RATE_OSC_DIV8 300
 
+struct imx_timer;
+
+struct icap_channel {
+   struct imx_timer *imxtm;
+
+   int chan;
+
+   u32 cnt_reg;
+   u32 irqen_bit;
+   u32 status_bit;
+   u32 mode_bit;
+
+   mxc_icap_handler_t handler;
+   void *dev_id;
+
+   struct timespec ts;
+   cycles_t last_cycles;
+   bool first_event;
+};
+
+/* FIXME, for now can't find icap unless it's statically allocated */
+static struct icap_channel icap_channel[2];
+static DEFINE_SPINLOCK(icap_lock);
+
 struct imx_timer {
enum imx_gpt_type type;
void __iomem *base;
@@ -90,12 +130,20 @@ struct imx_gpt_data {
int reg_tstat;
int reg_tcn;
int reg_tcmp;
-   void (*gpt_setup_tctl)(struct imx_timer *imxtm);
-   void (*gpt_irq_enable)(struct imx_timer *imxtm);
-   void (*gpt_irq_disable)(struct imx_timer *imxtm);
-   void (*gpt_irq_acknowledge)(struct imx_timer *imxtm);
+   void (*gpt_oc_setup_tctl)(struct imx_timer *imxtm);
+   void (*gpt_oc_irq_enable)(struct imx_timer *imxtm);
+   void (*gpt_oc_irq_disable)(struct imx_timer *imxtm);
+   void (*gpt_oc_irq_acknowledge)(struct imx_timer *imxtm);
+   bool (*gpt_is_oc_irq)(unsigned int tstat);
int (*set_next_event)(unsigned long evt,
  struct clock_event_device *ced);
+
+   void (*gpt_ic_irq_enable)(struct icap_channel *ic);
+   void (*gpt_ic_irq_disable)(struct icap_channel *ic);
+   void (*gpt_ic_irq_acknowledge)(struct icap_channel *ic);
+   bool (*gpt_is_ic_irq)(unsigned int tstat);
+   void (*gpt_ic_enable)(struct icap_channel *ic, unsigned int mode);
+   void (*gpt_ic_disable)(struct icap_channel *ic);
 };
 
 static inline struct imx_timer *to_imx_timer(struct clock_event_device *ced)
@@ -103,52 +151,144 @@ static inline struct imx_timer *to_imx_timer(struct 
clock_event_device *ced)
return container_of(ced, struct imx_timer, ced);
 }
 
-static void imx1_gpt_irq_disabl

Re: [PATCH v4 3/8] media: adv7180: add support for NEWAVMODE

2016-11-14 Thread Steve Longerbeam



On 11/14/2016 03:28 AM, Hans Verkuil wrote:

On 08/03/2016 08:03 PM, Steve Longerbeam wrote:

Parse the optional v4l2 endpoint DT node. If the bus type is
V4L2_MBUS_BT656 and the endpoint node specifies "newavmode",
configure the BT.656 bus in NEWAVMODE.

Signed-off-by: Steve Longerbeam 

---

v4: no changes
v3:
- the newavmode endpoint property is now private to adv7180.
---
  .../devicetree/bindings/media/i2c/adv7180.txt  |  4 ++
  drivers/media/i2c/adv7180.c| 46 --
  2 files changed, 47 insertions(+), 3 deletions(-)

diff --git a/Documentation/devicetree/bindings/media/i2c/adv7180.txt 
b/Documentation/devicetree/bindings/media/i2c/adv7180.txt
index 0d50115..6c175d2 100644
--- a/Documentation/devicetree/bindings/media/i2c/adv7180.txt
+++ b/Documentation/devicetree/bindings/media/i2c/adv7180.txt
@@ -15,6 +15,10 @@ Required Properties :
"adi,adv7282"
"adi,adv7282-m"
  
+Optional Endpoint Properties :

+- newavmode: a boolean property to indicate the BT.656 bus is operating
+  in Analog Device's NEWAVMODE. Valid for BT.656 busses only.

This is too vague.

Based on the ADV7280/ADV7281/ADV7282/ADV7283 Hardware Reference Manual I
would say something like this:

- newavmode: a boolean property to indicate the BT.656 bus is operating
   in Analog Device's NEWAVMODE. Valid for BT.656 busses only. When enabled
   the generated EAV/SAV codes are suitable for Analog Devices encoders.
   Otherwise these codes are setup according to 
   See bit 4 of user sub map register 0x31 in the Hardware Reference Manual.

I may have asked this before, but do you actually have hardware that needs
this? If so, it may be useful to give it as an example and explain why it
is needed.

If not, then I wonder if this cannot be dropped until we DO see hardware
that needs it.


Hi Hans, thanks for reviewing this, but at least for imx6, I don't
need this patch anymore.

Recently I dug deeper into the current bt.656 programming in
adv7180.c. The driver manually configures the bus to have 21
blank lines in odd fields, and 22 blank lines in even fields (via
NVEND register) for NTSC.

That leaves 525 - (21 +22) = 482 active lines in NTSC.

After configuring the imx6 host bridge to crop those extra 2 lines,
it is capturing good 720x480 NTSC images now.

So I no longer need this patch to enable NEWAVMODE.

However I still see some issues.

First, adv7180.c attempts to enable  BT.656-4 mode, but according
to the datasheet, that cannot be enabled without first enabling
NEWAVMODE. So the attempt to enable BT.656-4 mode is a no-op,
it is currently doing nothing. So I suggest removing that attempt.

Second, it is wrong for the host bridge to have to make an assumption
about cropping for a sensor. The adv7180 needs to communicate to
hosts about the number of field blanking lines it has configured, maybe
via get_selection. I.e., report full sensor frame via get_fmt, and 720x482
via get_selection.


Steve

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


Re: [PATCH v4 7/8] v4l: Add signal lock status to source change events

2016-11-14 Thread Steve Longerbeam



On 11/14/2016 03:36 AM, Hans Verkuil wrote:

On 08/03/2016 08:03 PM, Steve Longerbeam wrote:

Add a signal lock status change to the source changes bitmask.
This indicates there was a signal lock or unlock event detected
at the input of a video decoder.

Signed-off-by: Steve Longerbeam 
Cc: Mauro Carvalho Chehab 

---

v4:
- converted to rst from DocBook

v3: no changes
v2: no changes
---
  Documentation/media/uapi/v4l/vidioc-dqevent.rst | 9 +
  Documentation/media/videodev2.h.rst.exceptions  | 1 +
  include/uapi/linux/videodev2.h  | 1 +
  3 files changed, 11 insertions(+)

diff --git a/Documentation/media/uapi/v4l/vidioc-dqevent.rst 
b/Documentation/media/uapi/v4l/vidioc-dqevent.rst
index 73c0d5b..7d8a053 100644
--- a/Documentation/media/uapi/v4l/vidioc-dqevent.rst
+++ b/Documentation/media/uapi/v4l/vidioc-dqevent.rst
@@ -564,6 +564,15 @@ call.
  an input. This can come from an input connector or from a video
  decoder.
  
+-  .. row 2

+
+   -  ``V4L2_EVENT_SRC_CH_LOCK_STATUS``
+
+   -  0x0002
+
+   -  This event gets triggered when there is a signal lock or
+ unlock detected at the input of a video decoder.
+
  
  Return Value

  
diff --git a/Documentation/media/videodev2.h.rst.exceptions 
b/Documentation/media/videodev2.h.rst.exceptions
index 9bb9a6c..f412cc8 100644
--- a/Documentation/media/videodev2.h.rst.exceptions
+++ b/Documentation/media/videodev2.h.rst.exceptions
@@ -453,6 +453,7 @@ replace define V4L2_EVENT_CTRL_CH_FLAGS ctrl-changes-flags
  replace define V4L2_EVENT_CTRL_CH_RANGE ctrl-changes-flags
  
  replace define V4L2_EVENT_SRC_CH_RESOLUTION src-changes-flags

+replace define V4L2_EVENT_SRC_CH_LOCK_STATUS src-changes-flags
  
  replace define V4L2_EVENT_MD_FL_HAVE_FRAME_SEQ v4l2-event-motion-det
  
diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h

index 724f43e..08a153f 100644
--- a/include/uapi/linux/videodev2.h
+++ b/include/uapi/linux/videodev2.h
@@ -2078,6 +2078,7 @@ struct v4l2_event_frame_sync {
  };
  
  #define V4L2_EVENT_SRC_CH_RESOLUTION		(1 << 0)

+#define V4L2_EVENT_SRC_CH_LOCK_STATUS  (1 << 1)
  
  struct v4l2_event_src_change {

__u32 changes;


Quoting from an old (July) conversation about this:


I'm not entirely sure I like this. Typically losing lock means that this event
is triggered with the V4L2_EVENT_SRC_CH_RESOLUTION flag set, and userspace has
to check the new timings etc., which will fail if there is no lock anymore.

This information is also available through ENUMINPUT.

I would need to know more about why you think this is needed, because I don't
see what this adds.

Hi Hans,

At least on the ADV718x, a source resolution change (from an
autodetected video
standard change) and a signal lock status change are distinct events.
For example
there can be a temporary loss of input signal lock without a change in
detected
input video standard/resolution.

OK, but what can the application do with that event? If the glitch didn't
affect the video, then it is pointless.


Hi Hans, that's just it, for i.mx6 it does affect video. On i.mx6 a 
temporary

loss of signal from the adv7180 often results in a "split image", or rolling
image from captured frame to the next, and the only way to recover
from this failure is to restart the pipeline (stream off -- stream on). So
the application needs to be informed of this temporary loss of signal
event in order to restart streaming.




If the lock is lost, then normally you loose video as well. If not, then
applications are not interested in the event.


Yes, the lost lock causes a temporary or permanent loss of video,
but with no other indications from the adv7180 (such as a detected
video standard change). And on i.mx6, the lost lock often (actually
usually) causes a split or rolling image.

Steve

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


Re: [PATCH v4 7/8] v4l: Add signal lock status to source change events

2016-11-14 Thread Steve Longerbeam



On 11/14/2016 11:19 AM, Steve Longerbeam wrote:



On 11/14/2016 03:36 AM, Hans Verkuil wrote:

On 08/03/2016 08:03 PM, Steve Longerbeam wrote:

Add a signal lock status change to the source changes bitmask.
This indicates there was a signal lock or unlock event detected
at the input of a video decoder.

Signed-off-by: Steve Longerbeam 
Cc: Mauro Carvalho Chehab 

---

v4:
- converted to rst from DocBook

v3: no changes
v2: no changes
---
  Documentation/media/uapi/v4l/vidioc-dqevent.rst | 9 +
  Documentation/media/videodev2.h.rst.exceptions  | 1 +
  include/uapi/linux/videodev2.h  | 1 +
  3 files changed, 11 insertions(+)

diff --git a/Documentation/media/uapi/v4l/vidioc-dqevent.rst 
b/Documentation/media/uapi/v4l/vidioc-dqevent.rst

index 73c0d5b..7d8a053 100644
--- a/Documentation/media/uapi/v4l/vidioc-dqevent.rst
+++ b/Documentation/media/uapi/v4l/vidioc-dqevent.rst
@@ -564,6 +564,15 @@ call.
an input. This can come from an input connector or from a video
decoder.
  +-  .. row 2
+
+   -  ``V4L2_EVENT_SRC_CH_LOCK_STATUS``
+
+   -  0x0002
+
+   -  This event gets triggered when there is a signal lock or
+  unlock detected at the input of a video decoder.
+
Return Value
  
diff --git a/Documentation/media/videodev2.h.rst.exceptions 
b/Documentation/media/videodev2.h.rst.exceptions

index 9bb9a6c..f412cc8 100644
--- a/Documentation/media/videodev2.h.rst.exceptions
+++ b/Documentation/media/videodev2.h.rst.exceptions
@@ -453,6 +453,7 @@ replace define V4L2_EVENT_CTRL_CH_FLAGS 
ctrl-changes-flags

  replace define V4L2_EVENT_CTRL_CH_RANGE ctrl-changes-flags
replace define V4L2_EVENT_SRC_CH_RESOLUTION src-changes-flags
+replace define V4L2_EVENT_SRC_CH_LOCK_STATUS src-changes-flags
replace define V4L2_EVENT_MD_FL_HAVE_FRAME_SEQ 
v4l2-event-motion-det
  diff --git a/include/uapi/linux/videodev2.h 
b/include/uapi/linux/videodev2.h

index 724f43e..08a153f 100644
--- a/include/uapi/linux/videodev2.h
+++ b/include/uapi/linux/videodev2.h
@@ -2078,6 +2078,7 @@ struct v4l2_event_frame_sync {
  };
#define V4L2_EVENT_SRC_CH_RESOLUTION(1 << 0)
+#define V4L2_EVENT_SRC_CH_LOCK_STATUS(1 << 1)
struct v4l2_event_src_change {
  __u32 changes;


Quoting from an old (July) conversation about this:

I'm not entirely sure I like this. Typically losing lock means 
that this event
is triggered with the V4L2_EVENT_SRC_CH_RESOLUTION flag set, and 
userspace has
to check the new timings etc., which will fail if there is no lock 
anymore.


This information is also available through ENUMINPUT.

I would need to know more about why you think this is needed, 
because I don't

see what this adds.

Hi Hans,

At least on the ADV718x, a source resolution change (from an
autodetected video
standard change) and a signal lock status change are distinct events.
For example
there can be a temporary loss of input signal lock without a change in
detected
input video standard/resolution.
OK, but what can the application do with that event? If the glitch 
didn't

affect the video, then it is pointless.


Hi Hans, that's just it, for i.mx6 it does affect video. On i.mx6 a 
temporary
loss of signal from the adv7180 often results in a "split image", or 
rolling

image from captured frame to the next, and the only way to recover
from this failure is to restart the pipeline (stream off -- stream 
on). So

the application needs to be informed of this temporary loss of signal
event in order to restart streaming.




If the lock is lost, then normally you loose video as well. If not, then
applications are not interested in the event.


Yes, the lost lock causes a temporary or permanent loss of video,
but with no other indications from the adv7180 (such as a detected
video standard change). And on i.mx6, the lost lock often (actually
usually) causes a split or rolling image.



Also it seems the sequence of actions from the application due to a
SRC_CH_LOCK_STATUS event would be in line with the action due to
SRC_CH_RESOLUTION. In other words for SRC_CH_RESOLUTION,
the app requests an update on the detected video standard via
QUERYSTD, and for SRC_CH_LOCK_STATUS, it requests an update
on input status (ENUMINPUTS).

Steve

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


[PATCH 15/28] gpu: ipu-ic: allow multiple handles to ic

2016-07-06 Thread Steve Longerbeam
The image converter kernel API supports conversion contexts and
job queues, so we should allow more than one handle to the IC, so
that multiple users can add jobs to the queue.

Note however that users that control the IC manually (that do not
use the image converter APIs but setup the IC task by hand via calls
to ipu_ic_task_enable(), ipu_ic_enable(), etc.) must still be careful not
to share the IC handle with other threads. At this point, the only user
that still controls the IC manually is the i.mx capture driver. In that
case the capture driver only allows one open context to get a handle
to the IC at a time, so we should be ok there.

Signed-off-by: Steve Longerbeam 
---
 drivers/gpu/ipu-v3/ipu-ic.c | 25 +
 1 file changed, 1 insertion(+), 24 deletions(-)

diff --git a/drivers/gpu/ipu-v3/ipu-ic.c b/drivers/gpu/ipu-v3/ipu-ic.c
index f6a1125..51e34a1 100644
--- a/drivers/gpu/ipu-v3/ipu-ic.c
+++ b/drivers/gpu/ipu-v3/ipu-ic.c
@@ -342,7 +342,6 @@ struct ipu_ic {
enum ipu_color_space out_cs;
bool graphics;
bool rotation;
-   bool in_use;
 
struct image_converter cvt;
 
@@ -2380,38 +2379,16 @@ EXPORT_SYMBOL_GPL(ipu_ic_disable);
 struct ipu_ic *ipu_ic_get(struct ipu_soc *ipu, enum ipu_ic_task task)
 {
struct ipu_ic_priv *priv = ipu->ic_priv;
-   unsigned long flags;
-   struct ipu_ic *ic, *ret;
 
if (task >= IC_NUM_TASKS)
return ERR_PTR(-EINVAL);
 
-   ic = &priv->task[task];
-
-   spin_lock_irqsave(&priv->lock, flags);
-
-   if (ic->in_use) {
-   ret = ERR_PTR(-EBUSY);
-   goto unlock;
-   }
-
-   ic->in_use = true;
-   ret = ic;
-
-unlock:
-   spin_unlock_irqrestore(&priv->lock, flags);
-   return ret;
+   return &priv->task[task];
 }
 EXPORT_SYMBOL_GPL(ipu_ic_get);
 
 void ipu_ic_put(struct ipu_ic *ic)
 {
-   struct ipu_ic_priv *priv = ic->priv;
-   unsigned long flags;
-
-   spin_lock_irqsave(&priv->lock, flags);
-   ic->in_use = false;
-   spin_unlock_irqrestore(&priv->lock, flags);
 }
 EXPORT_SYMBOL_GPL(ipu_ic_put);
 
-- 
1.9.1

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


[PATCH 27/28] ARM: dts: imx6qdl: add mem2mem devices

2016-07-06 Thread Steve Longerbeam
Enables ipu-mem2mem devices on imx6qdl.

Signed-off-by: Steve Longerbeam 
---
 arch/arm/boot/dts/imx6q.dtsi   | 7 +++
 arch/arm/boot/dts/imx6qdl.dtsi | 6 ++
 2 files changed, 13 insertions(+)

diff --git a/arch/arm/boot/dts/imx6q.dtsi b/arch/arm/boot/dts/imx6q.dtsi
index 9b9fc91..b81d262 100644
--- a/arch/arm/boot/dts/imx6q.dtsi
+++ b/arch/arm/boot/dts/imx6q.dtsi
@@ -204,6 +204,13 @@
};
};
};
+
+
+   ipum2m1: ipum2m@ipu2 {
+   compatible = "fsl,imx-video-mem2mem";
+   ipu = <&ipu2>;
+   status = "okay";
+   };
};
 
display-subsystem {
diff --git a/arch/arm/boot/dts/imx6qdl.dtsi b/arch/arm/boot/dts/imx6qdl.dtsi
index 838d1d5..ec0be0e 100644
--- a/arch/arm/boot/dts/imx6qdl.dtsi
+++ b/arch/arm/boot/dts/imx6qdl.dtsi
@@ -1288,5 +1288,11 @@
};
};
};
+
+   ipum2m0: ipum2m@ipu1 {
+   compatible = "fsl,imx-video-mem2mem";
+   ipu = <&ipu1>;
+   status = "okay";
+   };
};
 };
-- 
1.9.1

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


[PATCH 28/28] ARM: imx_v6_v7_defconfig: Enable staging video4linux drivers

2016-07-06 Thread Steve Longerbeam
Enable imx v4l2 staging drivers. For video capture on
the SabreAuto, the ADV7180 video decoder also requires the
i2c-mux-gpio and the max7310 port expander.

Signed-off-by: Steve Longerbeam 
---
 arch/arm/configs/imx_v6_v7_defconfig | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/arm/configs/imx_v6_v7_defconfig 
b/arch/arm/configs/imx_v6_v7_defconfig
index 21339ce..8b1590a 100644
--- a/arch/arm/configs/imx_v6_v7_defconfig
+++ b/arch/arm/configs/imx_v6_v7_defconfig
@@ -327,6 +327,8 @@ CONFIG_FSL_EDMA=y
 CONFIG_IMX_SDMA=y
 CONFIG_MXS_DMA=y
 CONFIG_STAGING=y
+CONFIG_STAGING_MEDIA=y
+CONFIG_VIDEO_IMX=y
 # CONFIG_IOMMU_SUPPORT is not set
 CONFIG_IIO=y
 CONFIG_VF610_ADC=y
-- 
1.9.1

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


[PATCH 11/11] media: adv7180: fix field type

2016-07-06 Thread Steve Longerbeam
The ADV7180 and ADV7182 transmit whole fields, bottom field followed
by top (or vice-versa, depending on detected video standard). So
for chips that do not have support for explicitly setting the field
mode, set the field mode to SEQ_BT for PAL, and SEQ_TB for NTSC (there
seems to be conflicting info on field order of PAL vs NTSC, so follow
what is in adv7183.c).

Signed-off-by: Steve Longerbeam 
---
 drivers/media/i2c/adv7180.c | 18 +++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/drivers/media/i2c/adv7180.c b/drivers/media/i2c/adv7180.c
index 4c2623f..c12fca7 100644
--- a/drivers/media/i2c/adv7180.c
+++ b/drivers/media/i2c/adv7180.c
@@ -743,10 +743,17 @@ static int adv7180_set_pad_format(struct v4l2_subdev *sd,
switch (format->format.field) {
case V4L2_FIELD_NONE:
if (!(state->chip_info->flags & ADV7180_FLAG_I2P))
-   format->format.field = V4L2_FIELD_INTERLACED;
+   format->format.field =
+   (state->curr_norm & V4L2_STD_525_60) ?
+   V4L2_FIELD_SEQ_TB : V4L2_FIELD_SEQ_BT;
break;
default:
-   format->format.field = V4L2_FIELD_INTERLACED;
+   if (state->chip_info->flags & ADV7180_FLAG_I2P)
+   format->format.field = V4L2_FIELD_INTERLACED;
+   else
+   format->format.field =
+   (state->curr_norm & V4L2_STD_525_60) ?
+   V4L2_FIELD_SEQ_TB : V4L2_FIELD_SEQ_BT;
break;
}
 
@@ -1416,9 +1423,14 @@ static int adv7180_probe(struct i2c_client *client,
return -ENOMEM;
 
state->client = client;
-   state->field = V4L2_FIELD_INTERLACED;
state->chip_info = (struct adv7180_chip_info *)id->driver_data;
 
+   if (state->chip_info->flags & ADV7180_FLAG_I2P)
+   state->field = V4L2_FIELD_INTERLACED;
+   else
+   state->field = (state->curr_norm & V4L2_STD_525_60) ?
+   V4L2_FIELD_SEQ_TB : V4L2_FIELD_SEQ_BT;
+
ret = adv7180_of_parse(state);
if (ret)
return ret;
-- 
1.9.1

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


[PATCH 02/11] Revert "[media] adv7180: fix broken standards handling"

2016-07-06 Thread Steve Longerbeam
Autodetect was likely broken only because access to the
interrupt registers were broken, so there were no standard
change interrupts. After fixing that, and reverting this,
autodetect seems to work just fine on an i.mx6q SabreAuto.

This reverts commit 937feeed3f0ae8a0389d5732f6db63dd912acd99.
---
 drivers/media/i2c/adv7180.c | 118 ++--
 1 file changed, 38 insertions(+), 80 deletions(-)

diff --git a/drivers/media/i2c/adv7180.c b/drivers/media/i2c/adv7180.c
index 95cbc85..967303a 100644
--- a/drivers/media/i2c/adv7180.c
+++ b/drivers/media/i2c/adv7180.c
@@ -26,9 +26,8 @@
 #include 
 #include 
 #include 
-#include 
 #include 
-#include 
+#include 
 #include 
 #include 
 #include 
@@ -193,8 +192,8 @@ struct adv7180_state {
struct mutexmutex; /* mutual excl. when accessing chip */
int irq;
v4l2_std_id curr_norm;
+   boolautodetect;
boolpowered;
-   boolstreaming;
u8  input;
 
struct i2c_client   *client;
@@ -339,26 +338,12 @@ static int adv7180_querystd(struct v4l2_subdev *sd, 
v4l2_std_id *std)
if (err)
return err;
 
-   if (state->streaming) {
-   err = -EBUSY;
-   goto unlock;
-   }
-
-   err = adv7180_set_video_standard(state,
-   ADV7180_STD_AD_PAL_BG_NTSC_J_SECAM);
-   if (err)
-   goto unlock;
-
-   msleep(100);
-   __adv7180_status(state, NULL, std);
-
-   err = v4l2_std_to_adv7180(state->curr_norm);
-   if (err < 0)
-   goto unlock;
-
-   err = adv7180_set_video_standard(state, err);
+   /* when we are interrupt driven we know the state */
+   if (!state->autodetect || state->irq > 0)
+   *std = state->curr_norm;
+   else
+   err = __adv7180_status(state, NULL, std);
 
-unlock:
mutex_unlock(&state->mutex);
return err;
 }
@@ -402,13 +387,23 @@ static int adv7180_program_std(struct adv7180_state 
*state)
 {
int ret;
 
-   ret = v4l2_std_to_adv7180(state->curr_norm);
-   if (ret < 0)
-   return ret;
+   if (state->autodetect) {
+   ret = adv7180_set_video_standard(state,
+   ADV7180_STD_AD_PAL_BG_NTSC_J_SECAM);
+   if (ret < 0)
+   return ret;
+
+   __adv7180_status(state, NULL, &state->curr_norm);
+   } else {
+   ret = v4l2_std_to_adv7180(state->curr_norm);
+   if (ret < 0)
+   return ret;
+
+   ret = adv7180_set_video_standard(state, ret);
+   if (ret < 0)
+   return ret;
+   }
 
-   ret = adv7180_set_video_standard(state, ret);
-   if (ret < 0)
-   return ret;
return 0;
 }
 
@@ -420,12 +415,18 @@ static int adv7180_s_std(struct v4l2_subdev *sd, 
v4l2_std_id std)
if (ret)
return ret;
 
-   /* Make sure we can support this std */
-   ret = v4l2_std_to_adv7180(std);
-   if (ret < 0)
-   goto out;
+   /* all standards -> autodetect */
+   if (std == V4L2_STD_ALL) {
+   state->autodetect = true;
+   } else {
+   /* Make sure we can support this std */
+   ret = v4l2_std_to_adv7180(std);
+   if (ret < 0)
+   goto out;
 
-   state->curr_norm = std;
+   state->curr_norm = std;
+   state->autodetect = false;
+   }
 
ret = adv7180_program_std(state);
 out:
@@ -746,40 +747,6 @@ static int adv7180_g_tvnorms(struct v4l2_subdev *sd, 
v4l2_std_id *norm)
return 0;
 }
 
-static int adv7180_s_stream(struct v4l2_subdev *sd, int enable)
-{
-   struct adv7180_state *state = to_state(sd);
-   int ret;
-
-   /* It's always safe to stop streaming, no need to take the lock */
-   if (!enable) {
-   state->streaming = enable;
-   return 0;
-   }
-
-   /* Must wait until querystd released the lock */
-   ret = mutex_lock_interruptible(&state->mutex);
-   if (ret)
-   return ret;
-   state->streaming = enable;
-   mutex_unlock(&state->mutex);
-   return 0;
-}
-
-static int adv7180_subscribe_event(struct v4l2_subdev *sd,
-  struct v4l2_fh *fh,
-  struct v4l2_event_subscription *sub)
-{
-   switch (sub->type) {
-   case V4L2_EVENT_SOURCE_CHANGE:
-   return v4l2_src_change_event_subdev_subscribe(sd, fh, sub);
-   case V4L2_EVENT_CTRL:
-   return v4l2_ctrl_subdev_subscribe_event(sd, fh, sub);
-   default:
-   return -EINVAL;
-   }
-}
-
 static const struct v4l2_subdev_video_ops adv7180_video_ops = {
.s_std = adv7180_s_std,
   

[PATCH 08/11] adv7180: send V4L2_EVENT_SOURCE_CHANGE on std change

2016-07-06 Thread Steve Longerbeam
Subscribe to the V4L2_EVENT_SOURCE_CHANGE event and send
V4L2_EVENT_SRC_CH_RESOLUTION in the interrupt handler on a
detected standard change.

Signed-off-by: Steve Longerbeam 
---
 drivers/media/i2c/adv7180.c | 33 ++---
 1 file changed, 30 insertions(+), 3 deletions(-)

diff --git a/drivers/media/i2c/adv7180.c b/drivers/media/i2c/adv7180.c
index 427695d..f76a0e7 100644
--- a/drivers/media/i2c/adv7180.c
+++ b/drivers/media/i2c/adv7180.c
@@ -28,6 +28,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -824,6 +825,20 @@ static int adv7180_g_tvnorms(struct v4l2_subdev *sd, 
v4l2_std_id *norm)
return 0;
 }
 
+static int adv7180_subscribe_event(struct v4l2_subdev *sd,
+  struct v4l2_fh *fh,
+  struct v4l2_event_subscription *sub)
+{
+   switch (sub->type) {
+   case V4L2_EVENT_SOURCE_CHANGE:
+   return v4l2_src_change_event_subdev_subscribe(sd, fh, sub);
+   case V4L2_EVENT_CTRL:
+   return v4l2_ctrl_subdev_subscribe_event(sd, fh, sub);
+   default:
+   return -EINVAL;
+   }
+}
+
 static const struct v4l2_subdev_video_ops adv7180_video_ops = {
.s_std = adv7180_s_std,
.g_std = adv7180_g_std,
@@ -838,6 +853,8 @@ static const struct v4l2_subdev_video_ops adv7180_video_ops 
= {
 
 static const struct v4l2_subdev_core_ops adv7180_core_ops = {
.s_power = adv7180_s_power,
+   .subscribe_event = adv7180_subscribe_event,
+   .unsubscribe_event = v4l2_event_subdev_unsubscribe,
 };
 
 static const struct v4l2_subdev_pad_ops adv7180_pad_ops = {
@@ -862,8 +879,18 @@ static irqreturn_t adv7180_irq(int irq, void *devid)
/* clear */
adv7180_write(state, ADV7180_REG_ICR3, isr3);
 
-   if (isr3 & ADV7180_IRQ3_AD_CHANGE && state->autodetect)
-   __adv7180_status(state, NULL, &state->curr_norm);
+   if (isr3 & ADV7180_IRQ3_AD_CHANGE) {
+   static const struct v4l2_event src_ch = {
+   .type = V4L2_EVENT_SOURCE_CHANGE,
+   .u.src_change.changes = V4L2_EVENT_SRC_CH_RESOLUTION,
+   };
+
+   v4l2_subdev_notify_event(&state->sd, &src_ch);
+
+   if (state->autodetect)
+   __adv7180_status(state, NULL, &state->curr_norm);
+   }
+
mutex_unlock(&state->mutex);
 
return IRQ_HANDLED;
@@ -1403,7 +1430,7 @@ static int adv7180_probe(struct i2c_client *client,
state->input = 0;
sd = &state->sd;
v4l2_i2c_subdev_init(sd, client, &adv7180_ops);
-   sd->flags = V4L2_SUBDEV_FL_HAS_DEVNODE;
+   sd->flags = V4L2_SUBDEV_FL_HAS_DEVNODE | V4L2_SUBDEV_FL_HAS_EVENTS;
 
ret = adv7180_init_controls(state);
if (ret)
-- 
1.9.1

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


[PATCH 10/11] media: adv7180: enable lock/unlock interrupts

2016-07-06 Thread Steve Longerbeam
Enable the SD lock/unlock interrupts and send V4L2_EVENT_SRC_CH_LOCK_STATUS
in the interrupt handler on a detected lock/unlock. Keep track of current
input lock status with state->curr_status.

Signed-off-by: Steve Longerbeam 
---
 drivers/media/i2c/adv7180.c | 35 +++
 1 file changed, 27 insertions(+), 8 deletions(-)

diff --git a/drivers/media/i2c/adv7180.c b/drivers/media/i2c/adv7180.c
index f76a0e7..4c2623f 100644
--- a/drivers/media/i2c/adv7180.c
+++ b/drivers/media/i2c/adv7180.c
@@ -216,6 +216,7 @@ struct adv7180_state {
int irq;
struct gpio_desc*pwdn_gpio;
v4l2_std_id curr_norm;
+   u32 curr_status; /* lock status */
boolautodetect;
boolbt656_4; /* use bt.656-4 standard for NTSC */
boolpowered;
@@ -422,7 +423,12 @@ static int adv7180_g_input_status(struct v4l2_subdev *sd, 
u32 *status)
if (ret)
return ret;
 
-   ret = __adv7180_status(state, status, NULL);
+   /* when we are interrupt driven we know the input lock status */
+   if (!state->autodetect || state->irq > 0)
+   *status = state->curr_status;
+   else
+   ret = __adv7180_status(state, status, NULL);
+
mutex_unlock(&state->mutex);
return ret;
 }
@@ -437,7 +443,7 @@ static int adv7180_program_std(struct adv7180_state *state)
if (ret < 0)
return ret;
 
-   __adv7180_status(state, NULL, &state->curr_norm);
+   __adv7180_status(state, &state->curr_status, &state->curr_norm);
} else {
ret = v4l2_std_to_adv7180(state->curr_norm);
if (ret < 0)
@@ -872,23 +878,34 @@ static const struct v4l2_subdev_ops adv7180_ops = {
 static irqreturn_t adv7180_irq(int irq, void *devid)
 {
struct adv7180_state *state = devid;
-   u8 isr3;
+   u8 isr1, isr3;
 
mutex_lock(&state->mutex);
+   isr1 = adv7180_read(state, ADV7180_REG_ISR1);
isr3 = adv7180_read(state, ADV7180_REG_ISR3);
/* clear */
+   adv7180_write(state, ADV7180_REG_ICR1, isr1);
adv7180_write(state, ADV7180_REG_ICR3, isr3);
 
-   if (isr3 & ADV7180_IRQ3_AD_CHANGE) {
-   static const struct v4l2_event src_ch = {
+   if ((isr3 & ADV7180_IRQ3_AD_CHANGE) ||
+   (isr1 & (ADV7180_IRQ1_LOCK | ADV7180_IRQ1_UNLOCK))) {
+   static struct v4l2_event src_ch = {
.type = V4L2_EVENT_SOURCE_CHANGE,
-   .u.src_change.changes = V4L2_EVENT_SRC_CH_RESOLUTION,
};
 
+   if (isr3 & ADV7180_IRQ3_AD_CHANGE)
+   src_ch.u.src_change.changes |=
+   V4L2_EVENT_SRC_CH_RESOLUTION;
+
+   if (isr1 & (ADV7180_IRQ1_LOCK | ADV7180_IRQ1_UNLOCK))
+   src_ch.u.src_change.changes |=
+   V4L2_EVENT_SRC_CH_LOCK_STATUS;
+
v4l2_subdev_notify_event(&state->sd, &src_ch);
 
if (state->autodetect)
-   __adv7180_status(state, NULL, &state->curr_norm);
+   __adv7180_status(state, &state->curr_status,
+&state->curr_norm);
}
 
mutex_unlock(&state->mutex);
@@ -1335,7 +1352,9 @@ static int init_device(struct adv7180_state *state)
if (ret < 0)
goto out_unlock;
 
-   ret = adv7180_write(state, ADV7180_REG_IMR1, 0);
+   /* enable lock/unlock interrupts */
+   ret = adv7180_write(state, ADV7180_REG_IMR1,
+   ADV7180_IRQ1_LOCK | ADV7180_IRQ1_UNLOCK);
if (ret < 0)
goto out_unlock;
 
-- 
1.9.1

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


[PATCH 07/11] media: adv7180: change mbus format to UYVY

2016-07-06 Thread Steve Longerbeam
Change the media bus format from YUYV8_2X8 to UYVY8_2X8. Colors
now look correct when capturing with the i.mx6 backend. The other
option is to set the SWPC bit in register 0x27 to swap the Cr and Cb
output samples.

Signed-off-by: Steve Longerbeam 
---
 drivers/media/i2c/adv7180.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/i2c/adv7180.c b/drivers/media/i2c/adv7180.c
index fff887c..427695d 100644
--- a/drivers/media/i2c/adv7180.c
+++ b/drivers/media/i2c/adv7180.c
@@ -654,7 +654,7 @@ static int adv7180_enum_mbus_code(struct v4l2_subdev *sd,
if (code->index != 0)
return -EINVAL;
 
-   code->code = MEDIA_BUS_FMT_YUYV8_2X8;
+   code->code = MEDIA_BUS_FMT_UYVY8_2X8;
 
return 0;
 }
@@ -664,7 +664,7 @@ static int adv7180_mbus_fmt(struct v4l2_subdev *sd,
 {
struct adv7180_state *state = to_state(sd);
 
-   fmt->code = MEDIA_BUS_FMT_YUYV8_2X8;
+   fmt->code = MEDIA_BUS_FMT_UYVY8_2X8;
fmt->colorspace = V4L2_COLORSPACE_SMPTE170M;
fmt->width = 720;
fmt->height = state->curr_norm & V4L2_STD_525_60 ? 480 : 576;
-- 
1.9.1

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


[PATCH 00/11] adv7180 subdev fixes

2016-07-06 Thread Steve Longerbeam
Steve Longerbeam (11):
  media: adv7180: Fix broken interrupt register access
  Revert "[media] adv7180: fix broken standards handling"
  media: adv7180: add power pin control
  media: adv7180: implement g_parm
  media: adv7180: init chip with AD recommended register settings
  media: adv7180: add bt.656-4 OF property
  media: adv7180: change mbus format to UYVY
  adv7180: send V4L2_EVENT_SOURCE_CHANGE on std change
  v4l: Add signal lock status to source change events
  media: adv7180: enable lock/unlock interrupts
  media: adv7180: fix field type

 Documentation/DocBook/media/v4l/vidioc-dqevent.xml |  12 +-
 drivers/media/i2c/Kconfig  |   2 +-
 drivers/media/i2c/adv7180.c| 409 +++--
 include/uapi/linux/videodev2.h |   1 +
 4 files changed, 308 insertions(+), 116 deletions(-)

-- 
1.9.1

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


[PATCH 05/11] media: adv7180: init chip with AD recommended register settings

2016-07-06 Thread Steve Longerbeam
Define and load register tables that conform to Analog Device's
recommended register settings. It loads the default single-ended
CVBS on Ain1 configuration for both ADV7180 and ADV7182 chips.

New register addresses have been defined for the tables. Those new
defines are also used in existing locations where hard-coded addresses
were used.

Note this patch also enables NEWAVMODE, which is also recommended by
Analog Devices. This will likely break any current backends using this
subdev that are expecting different or manually configured AV codes.

Note also that bt.656-4 support has been removed in this patch, but it
will be brought back in a subsequent patch.

Signed-off-by: Steve Longerbeam 
---
 drivers/media/i2c/adv7180.c | 168 ++--
 1 file changed, 130 insertions(+), 38 deletions(-)

diff --git a/drivers/media/i2c/adv7180.c b/drivers/media/i2c/adv7180.c
index 42816d4..92e2f37 100644
--- a/drivers/media/i2c/adv7180.c
+++ b/drivers/media/i2c/adv7180.c
@@ -56,10 +56,11 @@
 
 #define ADV7182_REG_INPUT_VIDSEL   0x0002
 
+#define ADV7180_REG_OUTPUT_CONTROL 0x0003
 #define ADV7180_REG_EXTENDED_OUTPUT_CONTROL0x0004
 #define ADV7180_EXTENDED_OUTPUT_CONTROL_NTSCDIS0xC5
 
-#define ADV7180_REG_AUTODETECT_ENABLE  0x07
+#define ADV7180_REG_AUTODETECT_ENABLE  0x0007
 #define ADV7180_AUTODETECT_DEFAULT 0x7f
 /* Contrast */
 #define ADV7180_REG_CON0x0008  /*Unsigned */
@@ -100,6 +101,20 @@
 #define ADV7180_REG_IDENT 0x0011
 #define ADV7180_ID_7180 0x18
 
+#define ADV7180_REG_STATUS30x0013
+#define ADV7180_REG_ANALOG_CLAMP_CTL   0x0014
+#define ADV7180_REG_SHAP_FILTER_CTL_1  0x0017
+#define ADV7180_REG_CTRL_2 0x001d
+#define ADV7180_REG_VSYNC_FIELD_CTL_1  0x0031
+#define ADV7180_REG_MANUAL_WIN_CTL_1   0x003d
+#define ADV7180_REG_MANUAL_WIN_CTL_2   0x003e
+#define ADV7180_REG_MANUAL_WIN_CTL_3   0x003f
+#define ADV7180_REG_LOCK_CNT   0x0051
+#define ADV7180_REG_CVBS_TRIM  0x0052
+#define ADV7180_REG_CLAMP_ADJ  0x005a
+#define ADV7180_REG_RES_CIR0x005f
+#define ADV7180_REG_DIFF_MODE  0x0060
+
 #define ADV7180_REG_ICONF1 0x2040
 #define ADV7180_ICONF1_ACTIVE_LOW  0x01
 #define ADV7180_ICONF1_PSYNC_ONLY  0x10
@@ -129,9 +144,15 @@
 #define ADV7180_REG_VPP_SLAVE_ADDR 0xFD
 #define ADV7180_REG_CSI_SLAVE_ADDR 0xFE
 
-#define ADV7180_REG_FLCONTROL 0x40e0
+#define ADV7180_REG_ACE_CTRL1  0x4080
+#define ADV7180_REG_ACE_CTRL5  0x4084
+#define ADV7180_REG_FLCONTROL  0x40e0
 #define ADV7180_FLCONTROL_FL_ENABLE 0x1
 
+#define ADV7180_REG_RST_CLAMP  0x809c
+#define ADV7180_REG_AGC_ADJ1   0x80b6
+#define ADV7180_REG_AGC_ADJ2   0x80c0
+
 #define ADV7180_CSI_REG_PWRDN  0x00
 #define ADV7180_CSI_PWRDN  0x80
 
@@ -209,6 +230,11 @@ struct adv7180_state {
struct adv7180_state,   \
ctrl_hdl)->sd)
 
+struct adv7180_reg_tbl_t {
+   unsigned int reg;
+   unsigned int val;
+};
+
 static int adv7180_select_page(struct adv7180_state *state, unsigned int page)
 {
if (state->register_page != page) {
@@ -235,6 +261,20 @@ static int adv7180_read(struct adv7180_state *state, 
unsigned int reg)
return i2c_smbus_read_byte_data(state->client, reg & 0xff);
 }
 
+static int adv7180_load_reg_tbl(struct adv7180_state *state,
+   const struct adv7180_reg_tbl_t *tbl, int n)
+{
+   int ret, i;
+
+   for (i = 0; i < n; i++) {
+   ret = adv7180_write(state, tbl[i].reg, tbl[i].val);
+   if (ret)
+   return ret;
+   }
+
+   return 0;
+}
+
 static int adv7180_csi_write(struct adv7180_state *state, unsigned int reg,
unsigned int value)
 {
@@ -828,19 +868,36 @@ static irqreturn_t adv7180_irq(int irq, void *devid)
return IRQ_HANDLED;
 }
 
+/*
+ * This register table conforms to Analog Device's Register Settings
+ * Recommendation for the ADV7180. It configures single-ended CVBS
+ * input on Ain1, and enables NEWAVMODE.
+ */
+static const struct adv7180_reg_tbl_t adv7180_single_ended_cvbs[] = {
+   /* Set analog mux for CVBS on Ain1 */
+   { ADV7180_REG_INPUT_CONTROL, 0x00 },
+   /* ADI Required Write: Reset Clamp Circuitry */
+   { ADV7180_REG_ANALOG_CLAMP_CTL, 0x30 },
+   /* Enable SFL Output */
+   { ADV7180_REG_EXTENDED_OUTPUT_CONTROL, 0x57 },
+   /* Select SH1 Chroma Shaping Filter */
+   { ADV7180_REG_SHAP_FILTER_CTL_1, 0x41 },
+   /* Enable NEWAVMODE */
+   { ADV7180_REG_VSYNC_FIELD_CTL_1, 0x02 },
+   /* ADI Required Write: optimize windowing function Step 1,2,3 */
+   { ADV7180_REG_MANUAL_WIN_CTL_1, 0xA2 },
+   { ADV7180_REG_MANUAL_WIN_CTL_2, 0x6A },
+   { ADV7180_

[PATCH 01/11] media: adv7180: Fix broken interrupt register access

2016-07-06 Thread Steve Longerbeam
Access to the interrupt page registers has been broken since
at least 3999e5d01da74f1a22afbb0b61b3992fea301478. That commit
forgot to add the inerrupt page number to the register defines.

Signed-off-by: Steve Longerbeam 
---
 drivers/media/i2c/adv7180.c | 18 +-
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/media/i2c/adv7180.c b/drivers/media/i2c/adv7180.c
index b77b0a4..95cbc85 100644
--- a/drivers/media/i2c/adv7180.c
+++ b/drivers/media/i2c/adv7180.c
@@ -100,7 +100,7 @@
 #define ADV7180_REG_IDENT 0x0011
 #define ADV7180_ID_7180 0x18
 
-#define ADV7180_REG_ICONF1 0x0040
+#define ADV7180_REG_ICONF1 0x2040
 #define ADV7180_ICONF1_ACTIVE_LOW  0x01
 #define ADV7180_ICONF1_PSYNC_ONLY  0x10
 #define ADV7180_ICONF1_ACTIVE_TO_CLR   0xC0
@@ -113,15 +113,15 @@
 
 #define ADV7180_IRQ1_LOCK  0x01
 #define ADV7180_IRQ1_UNLOCK0x02
-#define ADV7180_REG_ISR1   0x0042
-#define ADV7180_REG_ICR1   0x0043
-#define ADV7180_REG_IMR1   0x0044
-#define ADV7180_REG_IMR2   0x0048
+#define ADV7180_REG_ISR1   0x2042
+#define ADV7180_REG_ICR1   0x2043
+#define ADV7180_REG_IMR1   0x2044
+#define ADV7180_REG_IMR2   0x2048
 #define ADV7180_IRQ3_AD_CHANGE 0x08
-#define ADV7180_REG_ISR3   0x004A
-#define ADV7180_REG_ICR3   0x004B
-#define ADV7180_REG_IMR3   0x004C
-#define ADV7180_REG_IMR4   0x50
+#define ADV7180_REG_ISR3   0x204A
+#define ADV7180_REG_ICR3   0x204B
+#define ADV7180_REG_IMR3   0x204C
+#define ADV7180_REG_IMR4   0x2050
 
 #define ADV7180_REG_NTSC_V_BIT_END 0x00E6
 #define ADV7180_NTSC_V_BIT_END_MANUAL_NVEND0x4F
-- 
1.9.1

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


[PATCH 04/11] media: adv7180: implement g_parm

2016-07-06 Thread Steve Longerbeam
Implement g_parm to return the current standard's frame period.

Signed-off-by: Steve Longerbeam 
---
 drivers/media/i2c/adv7180.c | 22 ++
 1 file changed, 22 insertions(+)

diff --git a/drivers/media/i2c/adv7180.c b/drivers/media/i2c/adv7180.c
index 38e5161..42816d4 100644
--- a/drivers/media/i2c/adv7180.c
+++ b/drivers/media/i2c/adv7180.c
@@ -741,6 +741,27 @@ static int adv7180_g_mbus_config(struct v4l2_subdev *sd,
return 0;
 }
 
+static int adv7180_g_parm(struct v4l2_subdev *sd, struct v4l2_streamparm *a)
+{
+   struct adv7180_state *state = to_state(sd);
+   struct v4l2_captureparm *cparm = &a->parm.capture;
+
+   if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
+   return -EINVAL;
+
+   memset(a, 0, sizeof(*a));
+   a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+   if (state->curr_norm & V4L2_STD_525_60) {
+   cparm->timeperframe.numerator = 1001;
+   cparm->timeperframe.denominator = 3;
+   } else {
+   cparm->timeperframe.numerator = 1;
+   cparm->timeperframe.denominator = 25;
+   }
+
+   return 0;
+}
+
 static int adv7180_cropcap(struct v4l2_subdev *sd, struct v4l2_cropcap 
*cropcap)
 {
struct adv7180_state *state = to_state(sd);
@@ -765,6 +786,7 @@ static int adv7180_g_tvnorms(struct v4l2_subdev *sd, 
v4l2_std_id *norm)
 static const struct v4l2_subdev_video_ops adv7180_video_ops = {
.s_std = adv7180_s_std,
.g_std = adv7180_g_std,
+   .g_parm = adv7180_g_parm,
.querystd = adv7180_querystd,
.g_input_status = adv7180_g_input_status,
.s_routing = adv7180_s_routing,
-- 
1.9.1

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


[PATCH 09/11] v4l: Add signal lock status to source change events

2016-07-06 Thread Steve Longerbeam
Add a signal lock status change to the source changes bitmask.
This indicates there was a signal lock or unlock event detected
at the input of a video decoder.

Signed-off-by: Steve Longerbeam 
---
 Documentation/DocBook/media/v4l/vidioc-dqevent.xml | 12 ++--
 include/uapi/linux/videodev2.h |  1 +
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/Documentation/DocBook/media/v4l/vidioc-dqevent.xml 
b/Documentation/DocBook/media/v4l/vidioc-dqevent.xml
index c9c3c77..7758ad7 100644
--- a/Documentation/DocBook/media/v4l/vidioc-dqevent.xml
+++ b/Documentation/DocBook/media/v4l/vidioc-dqevent.xml
@@ -233,8 +233,9 @@

  This event is triggered when a source parameter change is
   detected during runtime by the video device. It can be a
-  runtime resolution change triggered by a video decoder or the
-  format change happening on an input connector.
+  runtime resolution change or signal lock status change
+  triggered by a video decoder, or the format change happening
+  on an input connector.
   This event requires that the id
   matches the input index (when used with a video device node)
   or the pad index (when used with a subdevice node) from which
@@ -461,6 +462,13 @@
from a video decoder.

  
+ 
+   V4L2_EVENT_SRC_CH_LOCK_STATUS
+   0x0002
+   This event gets triggered when there is a signal lock or
+   unlock detected at the input of a video decoder.
+   
+ 

   
 
diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
index 724f43e..08a153f 100644
--- a/include/uapi/linux/videodev2.h
+++ b/include/uapi/linux/videodev2.h
@@ -2078,6 +2078,7 @@ struct v4l2_event_frame_sync {
 };
 
 #define V4L2_EVENT_SRC_CH_RESOLUTION   (1 << 0)
+#define V4L2_EVENT_SRC_CH_LOCK_STATUS  (1 << 1)
 
 struct v4l2_event_src_change {
__u32 changes;
-- 
1.9.1

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


[PATCH 03/11] media: adv7180: add power pin control

2016-07-06 Thread Steve Longerbeam
Some targets control the ADV7180 power pin via a gpio, so add
support for "pwdn-gpio" pin control.

Signed-off-by: Steve Longerbeam 
---
 drivers/media/i2c/Kconfig   |  2 +-
 drivers/media/i2c/adv7180.c | 37 +
 2 files changed, 38 insertions(+), 1 deletion(-)

diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index 993dc50..80d39f6 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -187,7 +187,7 @@ comment "Video decoders"
 
 config VIDEO_ADV7180
tristate "Analog Devices ADV7180 decoder"
-   depends on VIDEO_V4L2 && I2C && VIDEO_V4L2_SUBDEV_API
+   depends on GPIOLIB && VIDEO_V4L2 && I2C && VIDEO_V4L2_SUBDEV_API
---help---
  Support for the Analog Devices ADV7180 video decoder.
 
diff --git a/drivers/media/i2c/adv7180.c b/drivers/media/i2c/adv7180.c
index 967303a..38e5161 100644
--- a/drivers/media/i2c/adv7180.c
+++ b/drivers/media/i2c/adv7180.c
@@ -26,6 +26,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -191,6 +192,7 @@ struct adv7180_state {
struct media_padpad;
struct mutexmutex; /* mutual excl. when accessing chip */
int irq;
+   struct gpio_desc*pwdn_gpio;
v4l2_std_id curr_norm;
boolautodetect;
boolpowered;
@@ -443,6 +445,19 @@ static int adv7180_g_std(struct v4l2_subdev *sd, 
v4l2_std_id *norm)
return 0;
 }
 
+static void adv7180_set_power_pin(struct adv7180_state *state, bool on)
+{
+   if (!state->pwdn_gpio)
+   return;
+
+   if (on) {
+   gpiod_set_value_cansleep(state->pwdn_gpio, 0);
+   usleep_range(5000, 1);
+   } else {
+   gpiod_set_value_cansleep(state->pwdn_gpio, 1);
+   }
+}
+
 static int adv7180_set_power(struct adv7180_state *state, bool on)
 {
u8 val;
@@ -1143,6 +1158,8 @@ static int init_device(struct adv7180_state *state)
 
mutex_lock(&state->mutex);
 
+   adv7180_set_power_pin(state, true);
+
adv7180_write(state, ADV7180_REG_PWR_MAN, ADV7180_PWR_MAN_RES);
usleep_range(5000, 1);
 
@@ -1190,6 +1207,20 @@ out_unlock:
return ret;
 }
 
+static int adv7180_of_parse(struct adv7180_state *state)
+{
+   struct i2c_client *client = state->client;
+
+   state->pwdn_gpio = devm_gpiod_get_optional(&client->dev, "pwdn",
+  GPIOD_OUT_HIGH);
+   if (IS_ERR(state->pwdn_gpio)) {
+   v4l_err(client, "request for power pin failed\n");
+   return PTR_ERR(state->pwdn_gpio);
+   }
+
+   return 0;
+}
+
 static int adv7180_probe(struct i2c_client *client,
 const struct i2c_device_id *id)
 {
@@ -1212,6 +1243,10 @@ static int adv7180_probe(struct i2c_client *client,
state->field = V4L2_FIELD_INTERLACED;
state->chip_info = (struct adv7180_chip_info *)id->driver_data;
 
+   ret = adv7180_of_parse(state);
+   if (ret)
+   return ret;
+
if (state->chip_info->flags & ADV7180_FLAG_MIPI_CSI2) {
state->csi_client = i2c_new_dummy(client->adapter,
ADV7180_DEFAULT_CSI_I2C_ADDR);
@@ -1303,6 +1338,8 @@ static int adv7180_remove(struct i2c_client *client)
if (state->chip_info->flags & ADV7180_FLAG_MIPI_CSI2)
i2c_unregister_device(state->csi_client);
 
+   adv7180_set_power_pin(state, false);
+
mutex_destroy(&state->mutex);
 
return 0;
-- 
1.9.1

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


[PATCH 06/11] media: adv7180: add bt.656-4 OF property

2016-07-06 Thread Steve Longerbeam
Add a device tree boolean property "bt656-4" to allow setting
the ITU-R BT.656-4 compatible bit.

Signed-off-by: Steve Longerbeam 
---
 drivers/media/i2c/adv7180.c | 18 +-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/drivers/media/i2c/adv7180.c b/drivers/media/i2c/adv7180.c
index 92e2f37..fff887c 100644
--- a/drivers/media/i2c/adv7180.c
+++ b/drivers/media/i2c/adv7180.c
@@ -58,7 +58,7 @@
 
 #define ADV7180_REG_OUTPUT_CONTROL 0x0003
 #define ADV7180_REG_EXTENDED_OUTPUT_CONTROL0x0004
-#define ADV7180_EXTENDED_OUTPUT_CONTROL_NTSCDIS0xC5
+#define ADV7180_EXTENDED_OUTPUT_CONTROL_BT656_40x80
 
 #define ADV7180_REG_AUTODETECT_ENABLE  0x0007
 #define ADV7180_AUTODETECT_DEFAULT 0x7f
@@ -216,6 +216,7 @@ struct adv7180_state {
struct gpio_desc*pwdn_gpio;
v4l2_std_id curr_norm;
boolautodetect;
+   boolbt656_4; /* use bt.656-4 standard for NTSC */
boolpowered;
u8  input;
 
@@ -1281,6 +1282,17 @@ static int init_device(struct adv7180_state *state)
if (ret)
goto out_unlock;
 
+   if (state->bt656_4) {
+   ret = adv7180_read(state, ADV7180_REG_EXTENDED_OUTPUT_CONTROL);
+   if (ret < 0)
+   goto out_unlock;
+   ret |= ADV7180_EXTENDED_OUTPUT_CONTROL_BT656_4;
+   ret = adv7180_write(state, ADV7180_REG_EXTENDED_OUTPUT_CONTROL,
+   ret);
+   if (ret < 0)
+   goto out_unlock;
+   }
+
ret = adv7180_program_std(state);
if (ret)
goto out_unlock;
@@ -1332,6 +1344,10 @@ static int adv7180_of_parse(struct adv7180_state *state)
return PTR_ERR(state->pwdn_gpio);
}
 
+   /* select ITU-R BT.656-4 compatible? */
+   if (of_property_read_bool(client->dev.of_node, "bt656-4"))
+   state->bt656_4 = true;
+
return 0;
 }
 
-- 
1.9.1

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


[PATCH 6/6] ARM: dts: imx6-sabreauto: add video capture devices and connections

2016-07-06 Thread Steve Longerbeam
Defines the host video capture device node and the ADV7180 decoder
sensor. The host capture device connects to the ADV7180 via the
parallel-bus mux input on the ipu1_csi0_mux.

On the sabreauto, two analog video inputs are routed to the ADV7180,
composite on Ain1, and composite on Ain3. Those inputs are defined
via inputs and input-names under the endpoint node
ipu1_csi0_from_ipu1_csi0_mux. The ADV7180 power pin is via max7310_b
port expander.

Signed-off-by: Steve Longerbeam 
---
 arch/arm/boot/dts/imx6qdl-sabreauto.dtsi | 68 
 1 file changed, 68 insertions(+)

diff --git a/arch/arm/boot/dts/imx6qdl-sabreauto.dtsi 
b/arch/arm/boot/dts/imx6qdl-sabreauto.dtsi
index 737bb54..ec952b1 100644
--- a/arch/arm/boot/dts/imx6qdl-sabreauto.dtsi
+++ b/arch/arm/boot/dts/imx6qdl-sabreauto.dtsi
@@ -147,10 +147,54 @@
gpio-controller;
#gpio-cells = <2>;
};
+
+   camera: adv7180@21 {
+   compatible = "adi,adv7180";
+   reg = <0x21>;
+   pwdn-gpios = <&max7310_b 2 GPIO_ACTIVE_LOW>;
+   interrupt-parent = <&gpio1>;
+   interrupts = <27 0x8>;
+
+   port {
+   adv7180_to_ipu1_csi0_mux: endpoint {
+   remote-endpoint = 
<&ipu1_csi0_mux_from_parallel_sensor>;
+   bus-width = <8>;
+   };
+   };
+   };
+   };
+   };
+
+   ipucap0: ipucap0 {
+   compatible = "fsl,imx-video-capture";
+   #address-cells = <1>;
+   #size-cells = <0>;
+   pinctrl-names = "default";
+   pinctrl-0 = <&pinctrl_ipu1_csi0>;
+   ports = <&ipu1_csi0>;
+   status = "okay";
+
+   fim {
+   enable = <1>;
};
};
 };
 
+&ipu1_csi0_from_ipu1_csi0_mux {
+   bus-width = <8>;
+};
+
+&ipu1_csi0_mux_from_parallel_sensor {
+   remote-endpoint = <&adv7180_to_ipu1_csi0_mux>;
+   inputs = <0x00 0x02>;
+   input-names = "ADV7180 Composite on Ain1",
+   "ADV7180 Composite on Ain3";
+};
+
+&ipu1_csi0_mux {
+   status = "okay";
+};
+
 &clks {
assigned-clocks = <&clks IMX6QDL_PLL4_BYPASS_SRC>,
  <&clks IMX6QDL_PLL4_BYPASS>,
@@ -450,6 +494,30 @@
>;
};
 
+   pinctrl_ipu1_csi0: ipu1grp-csi0 {
+   fsl,pins = <
+   MX6QDL_PAD_CSI0_DAT4__IPU1_CSI0_DATA04   
0x8000
+   MX6QDL_PAD_CSI0_DAT5__IPU1_CSI0_DATA05   
0x8000
+   MX6QDL_PAD_CSI0_DAT6__IPU1_CSI0_DATA06   
0x8000
+   MX6QDL_PAD_CSI0_DAT7__IPU1_CSI0_DATA07   
0x8000
+   MX6QDL_PAD_CSI0_DAT8__IPU1_CSI0_DATA08   
0x8000
+   MX6QDL_PAD_CSI0_DAT9__IPU1_CSI0_DATA09   
0x8000
+   MX6QDL_PAD_CSI0_DAT10__IPU1_CSI0_DATA10  
0x8000
+   MX6QDL_PAD_CSI0_DAT11__IPU1_CSI0_DATA11  
0x8000
+   MX6QDL_PAD_CSI0_DAT12__IPU1_CSI0_DATA12  
0x8000
+   MX6QDL_PAD_CSI0_DAT13__IPU1_CSI0_DATA13  
0x8000
+   MX6QDL_PAD_CSI0_DAT14__IPU1_CSI0_DATA14  
0x8000
+   MX6QDL_PAD_CSI0_DAT15__IPU1_CSI0_DATA15  
0x8000
+   MX6QDL_PAD_CSI0_DAT16__IPU1_CSI0_DATA16  
0x8000
+   MX6QDL_PAD_CSI0_DAT17__IPU1_CSI0_DATA17  
0x8000
+   MX6QDL_PAD_CSI0_DAT18__IPU1_CSI0_DATA18  
0x8000
+   MX6QDL_PAD_CSI0_DAT19__IPU1_CSI0_DATA19  
0x8000
+   MX6QDL_PAD_CSI0_PIXCLK__IPU1_CSI0_PIXCLK 
0x8000
+   MX6QDL_PAD_CSI0_MCLK__IPU1_CSI0_HSYNC
0x8000
+   MX6QDL_PAD_CSI0_VSYNC__IPU1_CSI0_VSYNC   
0x8000
+   >;
+   };
+
pinctrl_pwm3: pwm1grp {
fsl,pins = <
MX6QDL_PAD_SD4_DAT1__PWM3_OUT   0x1b0b1
-- 
1.9.1

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


[PATCH 5/6] ARM: dts: imx6-sabreauto: add pinctrl for gpt input capture

2016-07-06 Thread Steve Longerbeam
Add pinctrl groups for both GPT input capture channels.

Signed-off-by: Steve Longerbeam 
---
 arch/arm/boot/dts/imx6qdl-sabreauto.dtsi | 12 
 1 file changed, 12 insertions(+)

diff --git a/arch/arm/boot/dts/imx6qdl-sabreauto.dtsi 
b/arch/arm/boot/dts/imx6qdl-sabreauto.dtsi
index 3f12d74..737bb54 100644
--- a/arch/arm/boot/dts/imx6qdl-sabreauto.dtsi
+++ b/arch/arm/boot/dts/imx6qdl-sabreauto.dtsi
@@ -456,6 +456,18 @@
>;
};
 
+   pinctrl_gpt_input_capture0: gptinputcapture0grp {
+   fsl,pins = <
+   MX6QDL_PAD_SD1_DAT0__GPT_CAPTURE1   
0x8000
+   >;
+   };
+
+   pinctrl_gpt_input_capture1: gptinputcapture1grp {
+   fsl,pins = <
+   MX6QDL_PAD_SD1_DAT1__GPT_CAPTURE2   
0x8000
+   >;
+   };
+
pinctrl_spdif: spdifgrp {
fsl,pins = <
MX6QDL_PAD_KEY_COL3__SPDIF_IN 0x1b0b0
-- 
1.9.1

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


[PATCH 0/6] ARM: dts: imx6-sabre*: add video capture nodes

2016-07-06 Thread Steve Longerbeam
Steve Longerbeam (6):
  ARM: dts: imx6-sabrelite: add video capture devices and connections
  ARM: dts: imx6-sabresd: add video capture devices and connections
  ARM: dts: imx6-sabreauto: create i2cmux for i2c3
  ARM: dts: imx6-sabreauto: add reset-gpios property for max7310_b
  ARM: dts: imx6-sabreauto: add pinctrl for gpt input capture
  ARM: dts: imx6-sabreauto: add video capture devices and connections

 arch/arm/boot/dts/imx6dl-sabresd.dts |  42 +
 arch/arm/boot/dts/imx6q-sabresd.dts  |  14 +++
 arch/arm/boot/dts/imx6qdl-sabreauto.dtsi | 154 ++-
 arch/arm/boot/dts/imx6qdl-sabrelite.dtsi |  95 +++
 arch/arm/boot/dts/imx6qdl-sabresd.dtsi   | 130 +-
 5 files changed, 413 insertions(+), 22 deletions(-)

-- 
1.9.1

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


[PATCH 3/6] ARM: dts: imx6-sabreauto: create i2cmux for i2c3

2016-07-06 Thread Steve Longerbeam
The sabreauto uses a steering pin to select between the SDA signal on
i2c3 bus, and a data-in pin for an SPI NOR chip. Use i2cmux to control
this steering pin. Idle state of the i2cmux selects SPI NOR. This is not
a classic way to use i2cmux, since one side of the mux selects something
other than an i2c bus, but it works and is probably the cleanest
solution. Note that if one thread is attempting to access SPI NOR while
another thread is accessing i2c3, the SPI NOR access will fail since the
i2cmux has selected the SDA pin rather than SPI NOR data-in. This couldn't
be avoided in any case, the board is not designed to allow concurrent
i2c3 and SPI NOR functions (and the default device-tree does not enable
SPI NOR anyway).

Devices hanging off i2c3 should now be defined under i2cmux, so
that the steering pin can be properly controlled to access those
devices. The port expanders (MAX7310) are thus moved into i2cmux.

Signed-off-by: Steve Longerbeam 
---
 arch/arm/boot/dts/imx6qdl-sabreauto.dtsi | 65 +---
 1 file changed, 44 insertions(+), 21 deletions(-)

diff --git a/arch/arm/boot/dts/imx6qdl-sabreauto.dtsi 
b/arch/arm/boot/dts/imx6qdl-sabreauto.dtsi
index d354d40..13f50e8 100644
--- a/arch/arm/boot/dts/imx6qdl-sabreauto.dtsi
+++ b/arch/arm/boot/dts/imx6qdl-sabreauto.dtsi
@@ -108,6 +108,44 @@
default-brightness-level = <7>;
status = "okay";
};
+
+   i2cmux {
+   compatible = "i2c-mux-gpio";
+   #address-cells = <1>;
+   #size-cells = <0>;
+   pinctrl-names = "default";
+   pinctrl-0 = <&pinctrl_i2c3mux>;
+   mux-gpios = <&gpio5 4 0>;
+   i2c-parent = <&i2c3>;
+   idle-state = <0>;
+
+   i2c@1 {
+   #address-cells = <1>;
+   #size-cells = <0>;
+   reg = <1>;
+
+   max7310_a: gpio@30 {
+   compatible = "maxim,max7310";
+   reg = <0x30>;
+   gpio-controller;
+   #gpio-cells = <2>;
+   };
+
+   max7310_b: gpio@32 {
+   compatible = "maxim,max7310";
+   reg = <0x32>;
+   gpio-controller;
+   #gpio-cells = <2>;
+   };
+
+   max7310_c: gpio@34 {
+   compatible = "maxim,max7310";
+   reg = <0x34>;
+   gpio-controller;
+   #gpio-cells = <2>;
+   };
+   };
+   };
 };
 
 &clks {
@@ -290,27 +328,6 @@
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_i2c3>;
status = "okay";
-
-   max7310_a: gpio@30 {
-   compatible = "maxim,max7310";
-   reg = <0x30>;
-   gpio-controller;
-   #gpio-cells = <2>;
-   };
-
-   max7310_b: gpio@32 {
-   compatible = "maxim,max7310";
-   reg = <0x32>;
-   gpio-controller;
-   #gpio-cells = <2>;
-   };
-
-   max7310_c: gpio@34 {
-   compatible = "maxim,max7310";
-   reg = <0x34>;
-   gpio-controller;
-   #gpio-cells = <2>;
-   };
 };
 
 &iomuxc {
@@ -418,6 +435,12 @@
>;
};
 
+   pinctrl_i2c3mux: i2c3muxgrp {
+   fsl,pins = <
+   MX6QDL_PAD_EIM_A24__GPIO5_IO04 0x8000
+   >;
+   };
+
pinctrl_pwm3: pwm1grp {
fsl,pins = <
MX6QDL_PAD_SD4_DAT1__PWM3_OUT   0x1b0b1
-- 
1.9.1

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


[PATCH 1/6] ARM: dts: imx6-sabrelite: add video capture devices and connections

2016-07-06 Thread Steve Longerbeam
Defines the host video capture device and the OV5642 parallel-bus sensor.
The host capture device connects to the OV5642 via the parallel-bus mux
input on the ipu1_csi0_mux.

Note there is a pin conflict with GPIO6. This pin functions as a power
input pin to the OV5642, but ENET requires it to wake-up the ARM cores
on normal RX and TX packet done events (see 6261c4c8). So by default,
capture from the OV5642 is disabled, enable by uncommenting __ENABLE_OV5642__
macro. Ethernet will still work just not quite as well.

Signed-off-by: Steve Longerbeam 
---
 arch/arm/boot/dts/imx6qdl-sabrelite.dtsi | 95 
 1 file changed, 95 insertions(+)

diff --git a/arch/arm/boot/dts/imx6qdl-sabrelite.dtsi 
b/arch/arm/boot/dts/imx6qdl-sabrelite.dtsi
index c47fe6c..2ad3a03 100644
--- a/arch/arm/boot/dts/imx6qdl-sabrelite.dtsi
+++ b/arch/arm/boot/dts/imx6qdl-sabrelite.dtsi
@@ -39,9 +39,20 @@
  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  * OTHER DEALINGS IN THE SOFTWARE.
  */
+
+#include 
 #include 
 #include 
 
+/*
+ * Uncomment the following macro to enable OV5642 video capture
+ * support. There is a pin conflict for GPIO6 between ENET wake-up
+ * interrupt function and power-down pin function for the OV5642.
+ * ENET will still work when enabling OV5642 capture, just not
+ * quite as well.
+ */
+/* #define __ENABLE_OV5642__ */
+
 / {
chosen {
stdout-path = &uart2;
@@ -218,7 +229,36 @@
};
};
};
+
+#ifdef __ENABLE_OV5642__
+   ipucap0: ipucap@0 {
+   compatible = "fsl,imx-video-capture";
+   #address-cells = <1>;
+   #size-cells = <0>;
+   pinctrl-names = "default";
+   pinctrl-0 = <&pinctrl_ipu1_csi0>;
+   ports = <&ipu1_csi0>;
+   status = "okay";
+   };
+#endif
+};
+
+#ifdef __ENABLE_OV5642__
+&ipu1_csi0_from_ipu1_csi0_mux {
+   bus-width = <8>;
+   data-shift = <12>; /* Lines 19:12 used */
+   hsync-active = <1>;
+   vync-active = <1>;
+};
+
+&ipu1_csi0_mux_from_parallel_sensor {
+   remote-endpoint = <&ov5642_to_ipu1_csi0_mux>;
+};
+
+&ipu1_csi0_mux {
+   status = "okay";
 };
+#endif
 
 &audmux {
pinctrl-names = "default";
@@ -271,8 +311,11 @@
txd1-skew-ps = <0>;
txd2-skew-ps = <0>;
txd3-skew-ps = <0>;
+#ifndef __ENABLE_OV5642__
interrupts-extended = <&gpio1 6 IRQ_TYPE_LEVEL_HIGH>,
  <&intc 0 119 IRQ_TYPE_LEVEL_HIGH>;
+
+#endif
status = "okay";
 };
 
@@ -301,6 +344,30 @@
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_i2c2>;
status = "okay";
+
+#ifdef __ENABLE_OV5642__
+   camera: ov5642@3c {
+   compatible = "ovti,ov5642";
+   pinctrl-names = "default";
+   pinctrl-0 = <&pinctrl_ov5642>;
+   clocks = <&clks IMX6QDL_CLK_CKO2>;
+   clock-names = "xclk";
+   reg = <0x3c>;
+   xclk = <2400>;
+   reset-gpios = <&gpio1 8 GPIO_ACTIVE_LOW>;
+   pwdn-gpios = <&gpio1 6 GPIO_ACTIVE_HIGH>;
+   gp-gpios = <&gpio1 16 GPIO_ACTIVE_HIGH>;
+
+   port {
+   ov5642_to_ipu1_csi0_mux: endpoint {
+   remote-endpoint = 
<&ipu1_csi0_mux_from_parallel_sensor>;
+   bus-width = <8>;
+   hsync-active = <1>;
+   vsync-active = <1>;
+   };
+   };
+   };
+#endif
 };
 
 &i2c3 {
@@ -373,7 +440,9 @@
MX6QDL_PAD_RGMII_RX_CTL__RGMII_RX_CTL   0x1b0b0
/* Phy reset */
MX6QDL_PAD_EIM_D23__GPIO3_IO23  0x000b0
+#ifndef __ENABLE_OV5642__
MX6QDL_PAD_GPIO_6__ENET_IRQ 0x000b1
+#endif
>;
};
 
@@ -448,6 +517,32 @@
>;
};
 
+   pinctrl_ov5642: ov5642grp {
+   fsl,pins = <
+   MX6QDL_PAD_SD1_DAT0__GPIO1_IO16 0x8000
+   MX6QDL_PAD_GPIO_6__GPIO1_IO06   0x8000
+   MX6QDL_PAD_GPIO_8__GPIO1_IO08   0x8000
+   MX6QDL_PAD_GPIO_3__CCM_CLKO20x8000
+   >;
+   };
+
+   pinctrl_ipu1_csi0: ipu1grp-csi0 {
+   fsl,pins =

[PATCH 2/6] ARM: dts: imx6-sabresd: add video capture devices and connections

2016-07-06 Thread Steve Longerbeam
Defines two host video capture devices and two camera sensors:
parallel-bus OV5642 and MIPI CSI-2 OV5640.

One host capture device connects to the OV5642 via the parallel-bus
mux input on the ipu1_csi0_mux.

The other host capture device connects to the OV5640 via the MIPI CSI-2
receiver (directly on virtual channel 1 to ipu1_csi1 on imx6q, and
indirectly via the ipu1_csi1_mux on imx6dl).

Signed-off-by: Steve Longerbeam 
---
 arch/arm/boot/dts/imx6dl-sabresd.dts   |  42 +++
 arch/arm/boot/dts/imx6q-sabresd.dts|  14 
 arch/arm/boot/dts/imx6qdl-sabresd.dtsi | 130 -
 3 files changed, 185 insertions(+), 1 deletion(-)

diff --git a/arch/arm/boot/dts/imx6dl-sabresd.dts 
b/arch/arm/boot/dts/imx6dl-sabresd.dts
index 1e45f2f..04ec884 100644
--- a/arch/arm/boot/dts/imx6dl-sabresd.dts
+++ b/arch/arm/boot/dts/imx6dl-sabresd.dts
@@ -15,3 +15,45 @@
model = "Freescale i.MX6 DualLite SABRE Smart Device Board";
compatible = "fsl,imx6dl-sabresd", "fsl,imx6dl";
 };
+
+&ipu1_csi1_from_ipu1_csi1_mux {
+   data-lanes = <0 1>;
+   clock-lanes = <2>;
+};
+
+&ipu1_csi1_mux {
+   status = "okay";
+};
+
+/*
+ * when the OV5642 sensor is enabled, the ipu1_csi0_mux is also enabled,
+ * but we don't want to find the OV5640 through ipu1_csi0_mux path to the
+ * mipi-csi2 receiver, so shutdown the link to the mipi-csi2 receiver at
+ * all virtual channels.
+*/
+&ipu1_csi0_mux_from_mipi_vc0 {
+   remote-endpoint = <>;
+};
+&ipu1_csi0_mux_from_mipi_vc1 {
+   remote-endpoint = <>;
+};
+&ipu1_csi0_mux_from_mipi_vc2 {
+   remote-endpoint = <>;
+};
+&ipu1_csi0_mux_from_mipi_vc3 {
+   remote-endpoint = <>;
+};
+
+/*
+ * shutdown links to mipi-csi2 channels 0,2,3 through ipu1_csi1_mux. The
+ * OV5640 is on VC1, so it must be found only on that ipu1_csi1_mux input.
+ */
+&ipu1_csi1_mux_from_mipi_vc0 {
+   remote-endpoint = <>;
+};
+&ipu1_csi1_mux_from_mipi_vc2 {
+   remote-endpoint = <>;
+};
+&ipu1_csi1_mux_from_mipi_vc3 {
+   remote-endpoint = <>;
+};
diff --git a/arch/arm/boot/dts/imx6q-sabresd.dts 
b/arch/arm/boot/dts/imx6q-sabresd.dts
index 9cbdfe7..03ae085 100644
--- a/arch/arm/boot/dts/imx6q-sabresd.dts
+++ b/arch/arm/boot/dts/imx6q-sabresd.dts
@@ -23,3 +23,17 @@
 &sata {
status = "okay";
 };
+
+&ipu1_csi1_from_mipi_vc1 {
+   data-lanes = <0 1>;
+   clock-lanes = <2>;
+};
+
+/*
+ * when the OV5642 sensor is enabled, the ipu1_csi0_mux is also enabled,
+ * but we don't want to find the OV5640 through ipu1_csi0_mux path, so
+ * shutdown the link to the mipi-csi2 receiver.
+*/
+&ipu1_csi0_mux_from_mipi_vc0 {
+   remote-endpoint = <>;
+};
diff --git a/arch/arm/boot/dts/imx6qdl-sabresd.dtsi 
b/arch/arm/boot/dts/imx6qdl-sabresd.dtsi
index 5248e7b..3d39d4c 100644
--- a/arch/arm/boot/dts/imx6qdl-sabresd.dtsi
+++ b/arch/arm/boot/dts/imx6qdl-sabresd.dtsi
@@ -10,6 +10,7 @@
  * http://www.gnu.org/copyleft/gpl.html
  */
 
+#include 
 #include 
 #include 
 
@@ -144,6 +145,50 @@
};
};
};
+
+   ipucap0: ipucap@0 {
+   compatible = "fsl,imx-video-capture";
+   #address-cells = <1>;
+   #size-cells = <0>;
+   pinctrl-names = "default";
+   pinctrl-0 = <&pinctrl_ipu1_csi0>;
+   ports = <&ipu1_csi0>;
+   status = "okay";
+   };
+
+   ipucap1: ipucap@1 {
+   compatible = "fsl,imx-video-capture";
+   #address-cells = <1>;
+   #size-cells = <0>;
+   ports = <&ipu1_csi1>;
+   status = "okay";
+   };
+};
+
+&ipu1_csi0_from_ipu1_csi0_mux {
+   bus-width = <8>;
+   data-shift = <12>; /* Lines 19:12 used */
+   hsync-active = <1>;
+   vsync-active = <1>;
+};
+
+&ipu1_csi0_mux_from_parallel_sensor {
+   remote-endpoint = <&ov5642_to_ipu1_csi0_mux>;
+};
+
+&ipu1_csi0_mux {
+   status = "okay";
+};
+
+&mipi_csi {
+   status = "okay";
+};
+
+/* Incoming port from sensor */
+&mipi_csi_from_mipi_sensor {
+   remote-endpoint = <&ov5640_to_mipi_csi>;
+   data-lanes = <0 1>;
+   clock-lanes = <2>;
 };
 
 &audmux {
@@ -214,7 +259,32 @@
0x8014 /* 4:FN_DMICCDAT */
0x /* 5:Default */
>;
-   };
+   };
+
+   camera: ov5642@3c {
+   compatible = "ovti,ov5642";
+   pinctrl-names = "default";
+   pinctrl-0 = <&pinctrl_ov5642>;
+   clocks = <&clks IMX6QDL_CLK_CKO>;
+   

[PATCH 4/6] ARM: dts: imx6-sabreauto: add reset-gpios property for max7310_b

2016-07-06 Thread Steve Longerbeam
The reset pin to the port expander chip (MAX7310) is controlled by a gpio,
so define a reset-gpios property to control it. There are three MAX7310's
on the SabreAuto CPU card (max7310_[abc]), but all use the same pin for
their reset. Since all can't acquire the same pin, assign it to max7310_b,
that chip is needed by more functions (usb and adv7180).

Signed-off-by: Steve Longerbeam 
---
 arch/arm/boot/dts/imx6qdl-sabreauto.dtsi | 9 +
 1 file changed, 9 insertions(+)

diff --git a/arch/arm/boot/dts/imx6qdl-sabreauto.dtsi 
b/arch/arm/boot/dts/imx6qdl-sabreauto.dtsi
index 13f50e8..3f12d74 100644
--- a/arch/arm/boot/dts/imx6qdl-sabreauto.dtsi
+++ b/arch/arm/boot/dts/imx6qdl-sabreauto.dtsi
@@ -136,6 +136,9 @@
reg = <0x32>;
gpio-controller;
#gpio-cells = <2>;
+   pinctrl-names = "default";  
+   pinctrl-0 = <&pinctrl_max7310>;
+   reset-gpios = <&gpio1 15 GPIO_ACTIVE_LOW>;
};
 
max7310_c: gpio@34 {
@@ -441,6 +444,12 @@
>;
};
 
+   pinctrl_max7310: max7310grp {
+   fsl,pins = <
+   MX6QDL_PAD_SD2_DAT0__GPIO1_IO15 0x8000
+   >;
+   };
+
pinctrl_pwm3: pwm1grp {
fsl,pins = <
MX6QDL_PAD_SD4_DAT1__PWM3_OUT   0x1b0b1
-- 
1.9.1

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


<    1   2   3   4   5   6   7   8   9   10   >