Re: [PATCH v2 08/21] [media] imx: Add i.MX IPUv3 capture driver
Hi Philipp, On Sat, Oct 15, 2016 at 1:34 AM, Philipp Zabelwrote: > This driver uses the IDMAC module's double buffering feature to do the > processing of finished frames in the new frame acknowledge (NFACK) > interrupt handler while the next frame is already being captured. This > avoids a race condition between the end of frame interrupt and NFACK for > very short blanking intervals, but causes the driver to need at least > two buffers in flight. The last remaining frame will never be handed out > to userspace until a new one is queued. > It supports interlaced input and allows to translate between sequential > and interlaced field formats using the IDMAC scan order and interlace > offset parameters. > Currently the direct CSI -> SMFC -> IDMAC path is supported. > > Signed-off-by: Sascha Hauer > Signed-off-by: Marc Kleine-Budde > Signed-off-by: Philipp Zabel > --- > Changes since v1: > - Remove v4l2_media_subdev_prepare_stream and v4l2_media_subdev_s_stream, >subdevices will propagate s_stream calls to their upstream subdevices >themselves. > - Fix width/height to CSI output size > - Use colorspace provided by CSI output > - Implement enum/g/s/_input for v4l2-compliance > - Fix ipu_capture_g_parm to use the correct pad > --- > drivers/media/platform/imx/Kconfig |9 + > drivers/media/platform/imx/Makefile |1 + > drivers/media/platform/imx/imx-ipu-capture.c | 1015 > ++ > drivers/media/platform/imx/imx-ipu.h |9 + > drivers/media/platform/imx/imx-ipuv3-csi.c | 29 +- > 5 files changed, 1061 insertions(+), 2 deletions(-) > create mode 100644 drivers/media/platform/imx/imx-ipu-capture.c > > diff --git a/drivers/media/platform/imx/Kconfig > b/drivers/media/platform/imx/Kconfig > index a88c4f7..69e8648 100644 > --- a/drivers/media/platform/imx/Kconfig > +++ b/drivers/media/platform/imx/Kconfig > @@ -9,6 +9,15 @@ config MEDIA_IMX > config VIDEO_IMX_IPU_COMMON > tristate > > +config VIDEO_IMX_IPU_CAPTURE > + tristate "i.MX5/6 Video Capture driver" > + depends on IMX_IPUV3_CORE && VIDEO_V4L2_SUBDEV_API && MEDIA_IMX > + select VIDEOBUF2_DMA_CONTIG > + select VIDEO_IMX_IPU_COMMON > + select VIDEO_IMX_IPUV3 > + help > + This is a v4l2 video capture driver for the IPUv3 on i.MX5/6. > + > config VIDEO_IMX_IPU_CSI > tristate "i.MX5/6 CMOS Sensor Interface driver" > depends on VIDEO_DEV && IMX_IPUV3_CORE && MEDIA_IMX > diff --git a/drivers/media/platform/imx/Makefile > b/drivers/media/platform/imx/Makefile > index 82a3616..919eaa1 100644 > --- a/drivers/media/platform/imx/Makefile > +++ b/drivers/media/platform/imx/Makefile > @@ -1,3 +1,4 @@ > obj-$(CONFIG_MEDIA_IMX)+= imx-media.o > obj-$(CONFIG_VIDEO_IMX_IPU_COMMON) += imx-ipu.o > +obj-$(CONFIG_VIDEO_IMX_IPU_CAPTURE)+= imx-ipu-capture.o > obj-$(CONFIG_VIDEO_IMX_IPU_CSI)+= imx-ipuv3-csi.o > diff --git a/drivers/media/platform/imx/imx-ipu-capture.c > b/drivers/media/platform/imx/imx-ipu-capture.c > new file mode 100644 > index 000..1308c1e > --- /dev/null > +++ b/drivers/media/platform/imx/imx-ipu-capture.c > @@ -0,0 +1,1015 @@ > +/* > + * i.MX IPUv3 V4L2 Capture Driver > + * > + * Copyright (C) 2016, Pengutronix, Philipp Zabel > + * > + * Based on code > + * Copyright (C) 2006, Pengutronix, Sascha Hauer > + * Copyright (C) 2008, Guennadi Liakhovetski > + * Copyright (C) 2008, Paulius Zaleckas > + * Copyright (C) 2009, Darius Augulis > + * > + * This program is free software; you can redistribute it and/or modify > + * it under the terms of the GNU General Public License version 2 as > + * published by the Free Software Foundation. > + */ > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#include > +#include "imx-ipu.h" > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#define DRIVER_NAME "imx-ipuv3-capture" > + > +/* buffer for one video frame */ > +struct ipu_capture_buffer { > + struct vb2_v4l2_buffer vb; > + struct list_headqueue; > +}; > + > +struct ipu_capture { > + struct video_device vdev; > + > + struct device *dev; > + struct v4l2_fh fh; > + struct vb2_queuevb2_vidq; > + struct media_padpad; > + struct media_pipeline pipe; > + struct v4l2_format format; > + > + struct v4l2_subdev *csi_sd; > + struct ipu_smfc *smfc; > + struct ipuv3_channel
Re: [PATCH v2 08/21] [media] imx: Add i.MX IPUv3 capture driver
Hi Marek, On 19/10/16 20:25, Marek Vasut wrote: On 10/19/2016 06:22 PM, Jack Mitchell wrote: Hi Philipp, On 17/10/16 13:12, Philipp Zabel wrote: Hi Jack, Am Montag, den 17.10.2016, 12:32 +0100 schrieb Jack Mitchell: Hi Philipp, I'm looking at how I would enable a parallel greyscale camera using this set of drivers and am a little bit confused. Do you have an example somewhere of a devicetree with an input node. In your board device tree it should look somewhat like this: { sensor@48 { compatible = "aptina,mt9v032m"; /* ... */ port { cam_out: endpoint { remote-endpoint = <_in>; } }; }; }; /* * This is the input port node corresponding to the 'CSI0' pad group, * not necessarily the CSI0 port of IPU1 or IPU2. On i.MX6Q it's port@1 * of the mipi_ipu1_mux, on i.MX6DL it's port@4 of the ipu_csi0_mux, * the csi0 label is added in patch 13/21. */ { #address-cells = <1>; #size-cells = <0>; csi_in: endpoint@0 { bus-width = <8>; data-shift = <12>; hsync-active = <1>; vsync-active = <1>; pclk-sample = <1>; remote-endpoint = <_out>; }; }; I also have a further note below: [...] +if (raw && priv->smfc) { Thank you, I think I have something which is kind of right. (Apologies in advance for the formatting) diff --git a/arch/arm/boot/dts/imx6q-sabrelite.dts b/arch/arm/boot/dts/imx6q-sabrelite.dts index 66d10d8..90e6b92 100644 --- a/arch/arm/boot/dts/imx6q-sabrelite.dts +++ b/arch/arm/boot/dts/imx6q-sabrelite.dts @@ -52,3 +52,62 @@ { status = "okay"; }; + + { +sensor@10 { +compatible = "onsemi,ar0135"; +reg = <0x10>; + +pinctrl-names = "default"; +pinctrl-0 = <_ar0135>; + +reset-gpio = < 6 GPIO_ACTIVE_HIGH>; + +clocks = < IMX6QDL_CLK_CKO2>; +clock-names = "xclk"; + +xclk = <2400>; + +port { +parallel_camera_output: endpoint { +remote-endpoint = <_in_from_parallel_camera>; +}; +}; +}; +}; + + { +csi_in_from_parallel_camera: endpoint@0 { +bus-width = <8>; +data-shift = <12>; +hsync-active = <1>; +vsync-active = <1>; +pclk-sample = <1>; +remote-endpoint = <_camera_output>; +}; +}; + + { + +imx6q-sabrelite { + +pinctrl_ar0135: ar0135grp { +fsl,pins = < +MX6QDL_PAD_GPIO_6__GPIO1_IO06 0x8000 +MX6QDL_PAD_CSI0_DAT12__IPU1_CSI0_DATA120x8000 +MX6QDL_PAD_CSI0_DAT13__IPU1_CSI0_DATA130x8000 +MX6QDL_PAD_CSI0_DAT14__IPU1_CSI0_DATA140x8000 +MX6QDL_PAD_CSI0_DAT15__IPU1_CSI0_DATA150x8000 +MX6QDL_PAD_CSI0_DAT16__IPU1_CSI0_DATA160x8000 +MX6QDL_PAD_CSI0_DAT17__IPU1_CSI0_DATA170x8000 +MX6QDL_PAD_CSI0_DAT18__IPU1_CSI0_DATA180x8000 +MX6QDL_PAD_CSI0_DAT19__IPU1_CSI0_DATA190x8000 +MX6QDL_PAD_CSI0_PIXCLK__IPU1_CSI0_PIXCLK 0x8000 +MX6QDL_PAD_CSI0_MCLK__IPU1_CSI0_HSYNC 0x8000 +MX6QDL_PAD_CSI0_VSYNC__IPU1_CSI0_VSYNC 0x8000 +MX6QDL_PAD_CSI0_DATA_EN__IPU1_CSI0_DATA_EN 0x8000 +>; +}; +}; +}; However, I can't seem to link the entities together properly, am I missing something obvious? root@vicon:~# media-ctl -p Media controller API version 0.1.0 Media device information driver imx-media model i.MX IPUv3 serial bus info hw revision 0x0 driver version 0.0.0 Device topology - entity 1: IPU0 CSI0 (2 pads, 1 link) type V4L2 subdev subtype Unknown flags 0 pad0: Sink pad1: Source -> "imx-ipuv3-capture.0":0 [ENABLED] - entity 4: imx-ipuv3-capture.0 (1 pad, 1 link) type Node subtype V4L flags 0 device node name /dev/video0 pad0: Sink <- "IPU0 CSI0":1 [ENABLED] - entity 10: IPU0 CSI1 (2 pads, 1 link) type V4L2 subdev subtype Unknown flags 0 pad0: Sink pad1: Source -> "imx-ipuv3-capture.1":0 [ENABLED] - entity 13: imx-ipuv3-capture.1 (1 pad, 1 link) type Node subtype V4L flags 0 device node name /dev/video1 pad0: Sink <- "IPU0 CSI1":1 [ENABLED] - entity 19: IPU1 CSI0 (2 pads, 1 link) type V4L2 subdev subtype Unknown flags 0 pad0: Sink pad1: Source -> "imx-ipuv3-capture.0":0 [ENABLED] - entity 22: imx-ipuv3-capture.0 (1 pad, 1 link) type Node subtype V4L flags 0 device node name /dev/video2 pad0: Sink <- "IPU1 CSI0":1 [ENABLED] - entity 28: IPU1 CSI1 (2 pads, 1 link) type V4L2 subdev subtype Unknown flags 0 pad0: Sink pad1: Source -> "imx-ipuv3-capture.1":0 [ENABLED]
Re: [PATCH v2 08/21] [media] imx: Add i.MX IPUv3 capture driver
On 10/19/2016 06:22 PM, Jack Mitchell wrote: > Hi Philipp, > > On 17/10/16 13:12, Philipp Zabel wrote: >> Hi Jack, >> >> Am Montag, den 17.10.2016, 12:32 +0100 schrieb Jack Mitchell: >>> Hi Philipp, >>> >>> I'm looking at how I would enable a parallel greyscale camera using this >>> set of drivers and am a little bit confused. Do you have an example >>> somewhere of a devicetree with an input node. >> >> In your board device tree it should look somewhat like this: >> >> { >> sensor@48 { >> compatible = "aptina,mt9v032m"; >> /* ... */ >> >> port { >> cam_out: endpoint { >> remote-endpoint = <_in>; >> } >> }; >> }; >> }; >> >> /* >> * This is the input port node corresponding to the 'CSI0' pad group, >> * not necessarily the CSI0 port of IPU1 or IPU2. On i.MX6Q it's port@1 >> * of the mipi_ipu1_mux, on i.MX6DL it's port@4 of the ipu_csi0_mux, >> * the csi0 label is added in patch 13/21. >> */ >> { >> #address-cells = <1>; >> #size-cells = <0>; >> >> csi_in: endpoint@0 { >> bus-width = <8>; >> data-shift = <12>; >> hsync-active = <1>; >> vsync-active = <1>; >> pclk-sample = <1>; >> remote-endpoint = <_out>; >> }; >> }; >> >>> I also have a further note below: >> [...] +if (raw && priv->smfc) { >>> > > Thank you, I think I have something which is kind of right. > > (Apologies in advance for the formatting) > > diff --git a/arch/arm/boot/dts/imx6q-sabrelite.dts > b/arch/arm/boot/dts/imx6q-sabrelite.dts > index 66d10d8..90e6b92 100644 > --- a/arch/arm/boot/dts/imx6q-sabrelite.dts > +++ b/arch/arm/boot/dts/imx6q-sabrelite.dts > @@ -52,3 +52,62 @@ > { > status = "okay"; > }; > + > + { > +sensor@10 { > +compatible = "onsemi,ar0135"; > +reg = <0x10>; > + > +pinctrl-names = "default"; > +pinctrl-0 = <_ar0135>; > + > +reset-gpio = < 6 GPIO_ACTIVE_HIGH>; > + > +clocks = < IMX6QDL_CLK_CKO2>; > +clock-names = "xclk"; > + > +xclk = <2400>; > + > +port { > +parallel_camera_output: endpoint { > +remote-endpoint = <_in_from_parallel_camera>; > +}; > +}; > +}; > +}; > + > + { > +csi_in_from_parallel_camera: endpoint@0 { > +bus-width = <8>; > +data-shift = <12>; > +hsync-active = <1>; > +vsync-active = <1>; > +pclk-sample = <1>; > +remote-endpoint = <_camera_output>; > +}; > +}; > + > + { > + > +imx6q-sabrelite { > + > +pinctrl_ar0135: ar0135grp { > +fsl,pins = < > +MX6QDL_PAD_GPIO_6__GPIO1_IO06 0x8000 > +MX6QDL_PAD_CSI0_DAT12__IPU1_CSI0_DATA120x8000 > +MX6QDL_PAD_CSI0_DAT13__IPU1_CSI0_DATA130x8000 > +MX6QDL_PAD_CSI0_DAT14__IPU1_CSI0_DATA140x8000 > +MX6QDL_PAD_CSI0_DAT15__IPU1_CSI0_DATA150x8000 > +MX6QDL_PAD_CSI0_DAT16__IPU1_CSI0_DATA160x8000 > +MX6QDL_PAD_CSI0_DAT17__IPU1_CSI0_DATA170x8000 > +MX6QDL_PAD_CSI0_DAT18__IPU1_CSI0_DATA180x8000 > +MX6QDL_PAD_CSI0_DAT19__IPU1_CSI0_DATA190x8000 > +MX6QDL_PAD_CSI0_PIXCLK__IPU1_CSI0_PIXCLK 0x8000 > +MX6QDL_PAD_CSI0_MCLK__IPU1_CSI0_HSYNC 0x8000 > +MX6QDL_PAD_CSI0_VSYNC__IPU1_CSI0_VSYNC 0x8000 > +MX6QDL_PAD_CSI0_DATA_EN__IPU1_CSI0_DATA_EN 0x8000 > +>; > +}; > +}; > +}; > > > However, I can't seem to link the entities together properly, am I > missing something obvious? > > root@vicon:~# media-ctl -p > Media controller API version 0.1.0 > > Media device information > > driver imx-media > model i.MX IPUv3 > serial > bus info > hw revision 0x0 > driver version 0.0.0 > > Device topology > - entity 1: IPU0 CSI0 (2 pads, 1 link) > type V4L2 subdev subtype Unknown flags 0 > pad0: Sink > pad1: Source > -> "imx-ipuv3-capture.0":0 [ENABLED] > > - entity 4: imx-ipuv3-capture.0 (1 pad, 1 link) > type Node subtype V4L flags 0 > device node name /dev/video0 > pad0: Sink > <- "IPU0 CSI0":1 [ENABLED] > > - entity 10: IPU0 CSI1 (2 pads, 1 link) > type V4L2 subdev subtype Unknown flags 0 > pad0: Sink > pad1: Source > -> "imx-ipuv3-capture.1":0 [ENABLED] > > - entity 13: imx-ipuv3-capture.1 (1 pad, 1 link) > type Node subtype V4L flags 0 > device node name /dev/video1 > pad0: Sink > <- "IPU0 CSI1":1 [ENABLED] > > - entity 19: IPU1 CSI0 (2 pads, 1 link) > type V4L2 subdev subtype Unknown flags 0 > pad0: Sink > pad1: Source > -> "imx-ipuv3-capture.0":0 [ENABLED] > > - entity 22:
Re: [PATCH v2 08/21] [media] imx: Add i.MX IPUv3 capture driver
Hi Philipp, On 17/10/16 13:12, Philipp Zabel wrote: Hi Jack, Am Montag, den 17.10.2016, 12:32 +0100 schrieb Jack Mitchell: Hi Philipp, I'm looking at how I would enable a parallel greyscale camera using this set of drivers and am a little bit confused. Do you have an example somewhere of a devicetree with an input node. In your board device tree it should look somewhat like this: { sensor@48 { compatible = "aptina,mt9v032m"; /* ... */ port { cam_out: endpoint { remote-endpoint = <_in>; } }; }; }; /* * This is the input port node corresponding to the 'CSI0' pad group, * not necessarily the CSI0 port of IPU1 or IPU2. On i.MX6Q it's port@1 * of the mipi_ipu1_mux, on i.MX6DL it's port@4 of the ipu_csi0_mux, * the csi0 label is added in patch 13/21. */ { #address-cells = <1>; #size-cells = <0>; csi_in: endpoint@0 { bus-width = <8>; data-shift = <12>; hsync-active = <1>; vsync-active = <1>; pclk-sample = <1>; remote-endpoint = <_out>; }; }; I also have a further note below: [...] + if (raw && priv->smfc) { Thank you, I think I have something which is kind of right. (Apologies in advance for the formatting) diff --git a/arch/arm/boot/dts/imx6q-sabrelite.dts b/arch/arm/boot/dts/imx6q-sabrelite.dts index 66d10d8..90e6b92 100644 --- a/arch/arm/boot/dts/imx6q-sabrelite.dts +++ b/arch/arm/boot/dts/imx6q-sabrelite.dts @@ -52,3 +52,62 @@ { status = "okay"; }; + + { + sensor@10 { + compatible = "onsemi,ar0135"; + reg = <0x10>; + + pinctrl-names = "default"; + pinctrl-0 = <_ar0135>; + + reset-gpio = < 6 GPIO_ACTIVE_HIGH>; + + clocks = < IMX6QDL_CLK_CKO2>; + clock-names = "xclk"; + + xclk = <2400>; + + port { + parallel_camera_output: endpoint { + remote-endpoint = <_in_from_parallel_camera>; + }; + }; + }; +}; + + { + csi_in_from_parallel_camera: endpoint@0 { + bus-width = <8>; + data-shift = <12>; + hsync-active = <1>; + vsync-active = <1>; + pclk-sample = <1>; + remote-endpoint = <_camera_output>; + }; +}; + + { + +imx6q-sabrelite { + + pinctrl_ar0135: ar0135grp { + fsl,pins = < + MX6QDL_PAD_GPIO_6__GPIO1_IO06 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 + MX6QDL_PAD_CSI0_DATA_EN__IPU1_CSI0_DATA_EN 0x8000 + >; + }; + }; +}; However, I can't seem to link the entities together properly, am I missing something obvious? root@vicon:~# media-ctl -p Media controller API version 0.1.0 Media device information driver imx-media model i.MX IPUv3 serial bus info hw revision 0x0 driver version 0.0.0 Device topology - entity 1: IPU0 CSI0 (2 pads, 1 link) type V4L2 subdev subtype Unknown flags 0 pad0: Sink pad1: Source -> "imx-ipuv3-capture.0":0 [ENABLED] - entity 4: imx-ipuv3-capture.0 (1 pad, 1 link) type Node subtype V4L flags 0 device node name /dev/video0 pad0: Sink <- "IPU0 CSI0":1 [ENABLED] - entity 10: IPU0 CSI1 (2 pads, 1 link) type V4L2 subdev subtype Unknown flags 0 pad0: Sink pad1: Source -> "imx-ipuv3-capture.1":0 [ENABLED] - entity 13: imx-ipuv3-capture.1 (1 pad, 1 link) type Node subtype V4L flags 0 device node name /dev/video1 pad0: Sink <- "IPU0 CSI1":1 [ENABLED] -
Re: [PATCH v2 08/21] [media] imx: Add i.MX IPUv3 capture driver
Hi Jack, Am Montag, den 17.10.2016, 12:32 +0100 schrieb Jack Mitchell: > Hi Philipp, > > I'm looking at how I would enable a parallel greyscale camera using this > set of drivers and am a little bit confused. Do you have an example > somewhere of a devicetree with an input node. In your board device tree it should look somewhat like this: { sensor@48 { compatible = "aptina,mt9v032m"; /* ... */ port { cam_out: endpoint { remote-endpoint = <_in>; } }; }; }; /* * This is the input port node corresponding to the 'CSI0' pad group, * not necessarily the CSI0 port of IPU1 or IPU2. On i.MX6Q it's port@1 * of the mipi_ipu1_mux, on i.MX6DL it's port@4 of the ipu_csi0_mux, * the csi0 label is added in patch 13/21. */ { #address-cells = <1>; #size-cells = <0>; csi_in: endpoint@0 { bus-width = <8>; data-shift = <12>; hsync-active = <1>; vsync-active = <1>; pclk-sample = <1>; remote-endpoint = <_out>; }; }; > I also have a further note below: [...] > > + if (raw && priv->smfc) { > > How does this ever get used? If I were to set 1X8 greyscale it wouldn't > ever take this path, correct? Thank you, that is a leftover from stripping down the driver to the basics. I'll test with a grayscale camera and fix this in the next version. regards Philipp -- 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 v2 08/21] [media] imx: Add i.MX IPUv3 capture driver
On 17/10/16 12:35, Marek Vasut wrote: On 10/17/2016 01:32 PM, Jack Mitchell wrote: Hi Philipp, Hi, I'm looking at how I would enable a parallel greyscale camera using this set of drivers and am a little bit confused. Do you have an example somewhere of a devicetree with an input node. I also have a further note below: Which sensor do you use ? [...] One which has a driver yet to be written :) Initial prototype board has an onsemi ar0135 on the parallel interface. -- 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 v2 08/21] [media] imx: Add i.MX IPUv3 capture driver
On 10/17/2016 01:32 PM, Jack Mitchell wrote: > Hi Philipp, Hi, > I'm looking at how I would enable a parallel greyscale camera using this > set of drivers and am a little bit confused. Do you have an example > somewhere of a devicetree with an input node. I also have a further note > below: Which sensor do you use ? [...] -- Best regards, Marek Vasut -- 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 v2 08/21] [media] imx: Add i.MX IPUv3 capture driver
Hi Philipp, I'm looking at how I would enable a parallel greyscale camera using this set of drivers and am a little bit confused. Do you have an example somewhere of a devicetree with an input node. I also have a further note below: + +static int ipu_capture_start_streaming(struct vb2_queue *vq, unsigned int count) +{ + struct ipu_capture *priv = vb2_get_drv_priv(vq); + struct v4l2_subdev *csi_sd = priv->csi_sd; + u32 width = priv->format.fmt.pix.width; + u32 height = priv->format.fmt.pix.height; + struct device *dev = priv->dev; + int burstsize; + struct ipu_capture_buffer *buf; + int nfack_irq; + int ret; + const char *irq_name[2] = { "CSI0", "CSI1" }; + bool raw; + + ret = ipu_capture_get_resources(priv); + if (ret < 0) { + dev_err(dev, "Failed to get resources: %d\n", ret); + goto err_dequeue; + } + + ipu_cpmem_zero(priv->ipuch); + + nfack_irq = ipu_idmac_channel_irq(priv->ipu, priv->ipuch, + IPU_IRQ_NFACK); + ret = request_threaded_irq(nfack_irq, NULL, + ipu_capture_new_frame_handler, IRQF_ONESHOT, + irq_name[priv->id], priv); + if (ret) { + dev_err(dev, "Failed to request NFACK interrupt: %d\n", nfack_irq); + goto put_resources; + } + + dev_dbg(dev, "width: %d height: %d, %.4s\n", + width, height, (char *)>format.fmt.pix.pixelformat); + + ipu_cpmem_set_resolution(priv->ipuch, width, height); + + raw = false; + + if (raw && priv->smfc) { How does this ever get used? If I were to set 1X8 greyscale it wouldn't ever take this path, correct? + /* +* raw formats. We can only pass them through to memory +*/ + u32 fourcc = priv->format.fmt.pix.pixelformat; + int bytes; + + switch (fourcc) { + case V4L2_PIX_FMT_GREY: + bytes = 1; + break; + case V4L2_PIX_FMT_Y10: + case V4L2_PIX_FMT_Y16: + case V4L2_PIX_FMT_UYVY: + case V4L2_PIX_FMT_YUYV: + bytes = 2; + break; + } + + ipu_cpmem_set_stride(priv->ipuch, width * bytes); + ipu_cpmem_set_format_passthrough(priv->ipuch, bytes * 8); + /* +* According to table 37-727 (SMFC Burst Size), burstsize should +* be set to NBP[6:4] for PFS == 6. Unfortunately, with a 16-bit +* bus any value below 4 doesn't produce proper images. +*/ + burstsize = (64 / bytes) >> 3; + } else { + /* +* formats we understand, we can write it in any format not requiring +* colorspace conversion. +*/ + u32 fourcc = priv->format.fmt.pix.pixelformat; + + switch (fourcc) { + case V4L2_PIX_FMT_RGB32: + ipu_cpmem_set_stride(priv->ipuch, width * 4); + ipu_cpmem_set_fmt(priv->ipuch, fourcc); + break; + case V4L2_PIX_FMT_UYVY: + case V4L2_PIX_FMT_YUYV: + ipu_cpmem_set_stride(priv->ipuch, width * 2); + ipu_cpmem_set_yuv_interleaved(priv->ipuch, fourcc); + break; + case V4L2_PIX_FMT_YUV420: + case V4L2_PIX_FMT_YVU420: + case V4L2_PIX_FMT_NV12: + case V4L2_PIX_FMT_YUV422P: + ipu_cpmem_set_stride(priv->ipuch, width); + ipu_cpmem_set_fmt(priv->ipuch, fourcc); + ipu_cpmem_set_yuv_planar(priv->ipuch, fourcc, +width, height); + burstsize = 16; + break; + default: + dev_err(dev, "invalid color format: %4.4s\n", + (char *)); + ret = -EINVAL; + goto free_irq; + } + } + -- To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v2 08/21] [media] imx: Add i.MX IPUv3 capture driver
This driver uses the IDMAC module's double buffering feature to do the processing of finished frames in the new frame acknowledge (NFACK) interrupt handler while the next frame is already being captured. This avoids a race condition between the end of frame interrupt and NFACK for very short blanking intervals, but causes the driver to need at least two buffers in flight. The last remaining frame will never be handed out to userspace until a new one is queued. It supports interlaced input and allows to translate between sequential and interlaced field formats using the IDMAC scan order and interlace offset parameters. Currently the direct CSI -> SMFC -> IDMAC path is supported. Signed-off-by: Sascha HauerSigned-off-by: Marc Kleine-Budde Signed-off-by: Philipp Zabel --- Changes since v1: - Remove v4l2_media_subdev_prepare_stream and v4l2_media_subdev_s_stream, subdevices will propagate s_stream calls to their upstream subdevices themselves. - Fix width/height to CSI output size - Use colorspace provided by CSI output - Implement enum/g/s/_input for v4l2-compliance - Fix ipu_capture_g_parm to use the correct pad --- drivers/media/platform/imx/Kconfig |9 + drivers/media/platform/imx/Makefile |1 + drivers/media/platform/imx/imx-ipu-capture.c | 1015 ++ drivers/media/platform/imx/imx-ipu.h |9 + drivers/media/platform/imx/imx-ipuv3-csi.c | 29 +- 5 files changed, 1061 insertions(+), 2 deletions(-) create mode 100644 drivers/media/platform/imx/imx-ipu-capture.c diff --git a/drivers/media/platform/imx/Kconfig b/drivers/media/platform/imx/Kconfig index a88c4f7..69e8648 100644 --- a/drivers/media/platform/imx/Kconfig +++ b/drivers/media/platform/imx/Kconfig @@ -9,6 +9,15 @@ config MEDIA_IMX config VIDEO_IMX_IPU_COMMON tristate +config VIDEO_IMX_IPU_CAPTURE + tristate "i.MX5/6 Video Capture driver" + depends on IMX_IPUV3_CORE && VIDEO_V4L2_SUBDEV_API && MEDIA_IMX + select VIDEOBUF2_DMA_CONTIG + select VIDEO_IMX_IPU_COMMON + select VIDEO_IMX_IPUV3 + help + This is a v4l2 video capture driver for the IPUv3 on i.MX5/6. + config VIDEO_IMX_IPU_CSI tristate "i.MX5/6 CMOS Sensor Interface driver" depends on VIDEO_DEV && IMX_IPUV3_CORE && MEDIA_IMX diff --git a/drivers/media/platform/imx/Makefile b/drivers/media/platform/imx/Makefile index 82a3616..919eaa1 100644 --- a/drivers/media/platform/imx/Makefile +++ b/drivers/media/platform/imx/Makefile @@ -1,3 +1,4 @@ obj-$(CONFIG_MEDIA_IMX)+= imx-media.o obj-$(CONFIG_VIDEO_IMX_IPU_COMMON) += imx-ipu.o +obj-$(CONFIG_VIDEO_IMX_IPU_CAPTURE)+= imx-ipu-capture.o obj-$(CONFIG_VIDEO_IMX_IPU_CSI)+= imx-ipuv3-csi.o diff --git a/drivers/media/platform/imx/imx-ipu-capture.c b/drivers/media/platform/imx/imx-ipu-capture.c new file mode 100644 index 000..1308c1e --- /dev/null +++ b/drivers/media/platform/imx/imx-ipu-capture.c @@ -0,0 +1,1015 @@ +/* + * i.MX IPUv3 V4L2 Capture Driver + * + * Copyright (C) 2016, Pengutronix, Philipp Zabel + * + * Based on code + * Copyright (C) 2006, Pengutronix, Sascha Hauer + * Copyright (C) 2008, Guennadi Liakhovetski + * Copyright (C) 2008, Paulius Zaleckas + * Copyright (C) 2009, Darius Augulis + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include "imx-ipu.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define DRIVER_NAME "imx-ipuv3-capture" + +/* buffer for one video frame */ +struct ipu_capture_buffer { + struct vb2_v4l2_buffer vb; + struct list_headqueue; +}; + +struct ipu_capture { + struct video_device vdev; + + struct device *dev; + struct v4l2_fh fh; + struct vb2_queuevb2_vidq; + struct media_padpad; + struct media_pipeline pipe; + struct v4l2_format format; + + struct v4l2_subdev *csi_sd; + struct ipu_smfc *smfc; + struct ipuv3_channel*ipuch; + struct ipu_soc *ipu; + int id; + + spinlock_t lock; + struct mutexmutex; + + /* The currently active buffer, set by NFACK and cleared by EOF interrupt */ + struct ipu_capture_buffer *active; +