Re: [v3,3/4] remoteproc: st: add da to va support

2017-02-08 Thread Hugues FRUCHET
On 01/31/2017 01:35 PM, Loic PALLARDY wrote:
> ST remoteproc driver needs to provide information about
> carveout memory region to allow remoteproc core to load
> firmware and access trace buffer.
>
> Signed-off-by: Loic Pallardy <loic.palla...@st.com>

Acked-and-tested-by: Hugues Fruchet <hugues.fruc...@st.com>

Tested on B2260 ST Platform with st-delta video decoder V4L2 kernel 
driver 
(http://www.mail-archive.com/linux-media@vger.kernel.org/msg107644.html).

> ---
> Changes since V2:
> - fix checkpatch --strict warning
> ---
>  drivers/remoteproc/st_remoteproc.c | 43 
> --
>  1 file changed, 37 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/remoteproc/st_remoteproc.c 
> b/drivers/remoteproc/st_remoteproc.c
> index f1e9339..80f8118 100644
> --- a/drivers/remoteproc/st_remoteproc.c
> +++ b/drivers/remoteproc/st_remoteproc.c
> @@ -21,6 +21,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -53,6 +54,10 @@ struct st_rproc {
>   struct mbox_chan*mbox_chan[ST_RPROC_MAX_VRING * MBOX_MAX];
>   struct mbox_client mbox_client_vq0;
>   struct mbox_client mbox_client_vq1;
> + phys_addr_t mem_phys;
> + phys_addr_t mem_reloc;
> + void *mem_region;
> + size_t mem_size;
>  };
>
>  static void st_rproc_mbox_callback(struct device *dev, u32 msg)
> @@ -157,10 +162,23 @@ static int st_rproc_stop(struct rproc *rproc)
>   return sw_err ?: pwr_err;
>  }
>
> +static void *st_proc_da_to_va(struct rproc *rproc, u64 da, int len)
> +{
> + struct st_rproc *ddata = rproc->priv;
> + int offset;
> +
> + offset = da - ddata->mem_reloc;
> + if (offset < 0 || offset + len > ddata->mem_size)
> + return NULL;
> +
> + return ddata->mem_region + offset;
> +}
> +
>  static struct rproc_ops st_rproc_ops = {
>   .kick   = st_rproc_kick,
>   .start  = st_rproc_start,
>   .stop   = st_rproc_stop,
> + .da_to_va   = st_proc_da_to_va,
>  };
>
>  /*
> @@ -208,7 +226,8 @@ static int st_rproc_parse_dt(struct platform_device *pdev)
>   struct device *dev = >dev;
>   struct rproc *rproc = platform_get_drvdata(pdev);
>   struct st_rproc *ddata = rproc->priv;
> - struct device_node *np = dev->of_node;
> + struct device_node *np = dev->of_node, *node;
> + struct resource res;
>   int err;
>
>   if (ddata->config->sw_reset) {
> @@ -252,10 +271,24 @@ static int st_rproc_parse_dt(struct platform_device 
> *pdev)
>   return -EINVAL;
>   }
>
> - err = of_reserved_mem_device_init(dev);
> - if (err) {
> - dev_err(dev, "Failed to obtain shared memory\n");
> + node = of_parse_phandle(np, "memory-region", 0);
> + if (!node) {
> + dev_err(dev, "No memory-region specified\n");
> + return -EINVAL;
> + }
> +
> + err = of_address_to_resource(node, 0, );
> + if (err)
>   return err;
> +
> + ddata->mem_phys = res.start;
> + ddata->mem_reloc = res.start;
> + ddata->mem_size = resource_size();
> + ddata->mem_region = devm_ioremap_wc(dev, ddata->mem_phys, 
> ddata->mem_size);
> + if (!ddata->mem_region) {
> + dev_err(dev, "Unable to map memory region: %pa+%zx\n",
> + , ddata->mem_size);
> + return -EBUSY;
>   }
>
>   err = clk_prepare(ddata->clk);
> @@ -385,8 +418,6 @@ static int st_rproc_remove(struct platform_device *pdev)
>
>   clk_disable_unprepare(ddata->clk);
>
> - of_reserved_mem_device_release(>dev);
> -
>   for (i = 0; i < ST_RPROC_MAX_VRING * MBOX_MAX; i++)
>   mbox_free_channel(ddata->mbox_chan[i]);
>
>

Re: [v3, 4/4] remoteproc: core: don't allocate carveout if pa or da are defined

2017-02-08 Thread Hugues FRUCHET


On 01/31/2017 01:35 PM, Loic PALLARDY wrote:
> Remoteproc doesn't check if firmware requests fixed
> addresses for carveout regions.
> Current assumption is that platform specific driver is in
> charge of coprocessor specific memory region allocation and
> remoteproc core doesn't have to handle them.
> If a da or a pa is specified in firmware resource table, remoteproc
> core doesn't have to perform any allocation.
> Access to carveout will be done thanks to rproc_da_to_pa function,
> which will provide virtual address on carveout region allocated
> by platform specific driver.
>
> Signed-off-by: Loic Pallardy <loic.palla...@st.com>

Acked-and-tested-by: Hugues Fruchet <hugues.fruc...@st.com>

Tested on B2260 ST Platform with st-delta video decoder V4L2 kernel 
driver 
(http://www.mail-archive.com/linux-media@vger.kernel.org/msg107644.html).

> ---
> No change since V1
>
>  drivers/remoteproc/remoteproc_core.c | 5 +
>  1 file changed, 5 insertions(+)
>
> diff --git a/drivers/remoteproc/remoteproc_core.c 
> b/drivers/remoteproc/remoteproc_core.c
> index 90b05c7..dd63ceed 100644
> --- a/drivers/remoteproc/remoteproc_core.c
> +++ b/drivers/remoteproc/remoteproc_core.c
> @@ -622,6 +622,11 @@ static int rproc_handle_carveout(struct rproc *rproc,
>   dev_dbg(dev, "carveout rsc: name: %s, da 0x%x, pa 0x%x, len 0x%x, flags 
> 0x%x\n",
>   rsc->name, rsc->da, rsc->pa, rsc->len, rsc->flags);
>
> + if (rsc->pa != FW_RSC_ADDR_ANY || rsc->da != FW_RSC_ADDR_ANY) {
> + dev_dbg(dev, "carveout already allocated by low level 
> driver\n");
> + return 0;
> + }
> +
>   carveout = kzalloc(sizeof(*carveout), GFP_KERNEL);
>   if (!carveout)
>   return -ENOMEM;
>
>

Re: [PATCH v2 0/6] virtio_rpmsg: make rpmsg channel configurable

2017-02-08 Thread Hugues FRUCHET
Acked-and-tested-by: Hugues Fruchet <hugues.fruc...@st.com>

Tested on B2260 ST Platform with st-delta video decoder V4L2 kernel 
driver 
(http://www.mail-archive.com/linux-media@vger.kernel.org/msg107644.html).


On 01/31/2017 01:51 PM, Loic Pallardy wrote:
> This goal of this series is to offer more flexibility for virtio_rpmsg
> communication link configuration.
>
> It should be possible to tune rpmsg buffer size per Rpmsg link, to provide
> selected configuration to coprocessor, to take into account coprocessor
> specificities like memory region.
>
> This series introduces an optional virtio rpmsg configuration structure, which
> will be managed as an extension of struct fw_rsc_vdev present in coprocessor 
> firmware
> resource table.
> Structure access is possible thanks to virtio get and set API.
> This structure contains the different information to tune the link between the
> host and the coprocessor.
>
> Patch "rpmsg: virtio_rpmsg_bus: fix sg_set_buf() when addr is not a valid
> kernel address" has the same goal as Wendy's RFC [1]. I don't have tested
> Wendy's series with level driver buffer allocation.
>
> Last patch "rpmsg: virtio_rpmsg: set buffer configuration to virtio" has a
> dependency with remoteproc subdevice boot sequence as coprocessor resource
> table must be updated before coprocessor start. See [2]
>
> [1] http://www.spinics.net/lists/linux-remoteproc/msg00852.html
> [2] http://www.spinics.net/lists/linux-remoteproc/msg00826.html
>
> ---
> Changes from v1:
> - No more dependency with [2]. Coprocessor firmware should wait for first kick
> indicating virtio rpmsg link ready before accessing resource table 
> information.
> - Correct issues reported by Suman
> - Fix warnings found by checkpatch with --strict option
>
>
> Loic Pallardy (6):
>   rpmsg: virtio_rpmsg: set rpmsg_buf_size customizable
>   rpmsg: virtio_rpmsg_bus: fix sg_set_buf() when addr is not a valid
> kernel address
>   include: virtio_rpmsg: add virtio rpmsg configuration structure
>   rpmsg: virtio_rpmsg: get buffer configuration from virtio
>   rpmsg: virtio_rpmsg: don't allocate buffer if provided by low level
> driver
>   rpmsg: virtio_rpmsg: set buffer configuration to virtio
>
>  drivers/rpmsg/virtio_rpmsg_bus.c   | 176 
> +++--
>  include/linux/rpmsg/virtio_rpmsg.h |  32 +++
>  2 files changed, 179 insertions(+), 29 deletions(-)
>  create mode 100644 include/linux/rpmsg/virtio_rpmsg.h
>


[PATCH v1 4/8] ARM: dts: stm32: Enable DCMI camera interface on STM32F429-EVAL board

2017-03-29 Thread Hugues Fruchet
Signed-off-by: Hugues Fruchet <hugues.fruc...@st.com>
---
 arch/arm/boot/dts/stm32429i-eval.dts | 9 +
 1 file changed, 9 insertions(+)

diff --git a/arch/arm/boot/dts/stm32429i-eval.dts 
b/arch/arm/boot/dts/stm32429i-eval.dts
index 3c99466..87733d3 100644
--- a/arch/arm/boot/dts/stm32429i-eval.dts
+++ b/arch/arm/boot/dts/stm32429i-eval.dts
@@ -141,6 +141,15 @@
clock-frequency = <2500>;
 };
 
+ {
+   status = "okay";
+
+   port {
+   dcmi_0: endpoint@0 {
+   };
+   };
+};
+
  {
pinctrl-0 = <_pins>;
pinctrl-names = "default";
-- 
1.9.1



[PATCH v1 8/8] ARM: configs: stm32: DCMI + OV2640 camera support

2017-03-29 Thread Hugues Fruchet
Enable DCMI camera interface and OV2640 camera sensor drivers.

Signed-off-by: Hugues Fruchet <hugues.fruc...@st.com>
---
 arch/arm/configs/stm32_defconfig | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/arch/arm/configs/stm32_defconfig b/arch/arm/configs/stm32_defconfig
index 84adc88..3f2e4ce 100644
--- a/arch/arm/configs/stm32_defconfig
+++ b/arch/arm/configs/stm32_defconfig
@@ -53,6 +53,13 @@ CONFIG_GPIO_STMPE=y
 CONFIG_MFD_STMPE=y
 CONFIG_REGULATOR_FIXED_VOLTAGE=y
 # CONFIG_USB_SUPPORT is not set
+CONFIG_VIDEO_V4L2=y
+CONFIG_MEDIA_SUBDRV_AUTOSELECT=n
+CONFIG_V4L_PLATFORM_DRIVERS=y
+CONFIG_MEDIA_SUPPORT=y
+CONFIG_MEDIA_CAMERA_SUPPORT=y
+CONFIG_VIDEO_STM32_DCMI=y
+CONFIG_VIDEO_OV2640=y
 CONFIG_NEW_LEDS=y
 CONFIG_LEDS_CLASS=y
 CONFIG_LEDS_GPIO=y
-- 
1.9.1



[PATCH v1 1/8] dt-bindings: Document STM32 DCMI bindings

2017-03-29 Thread Hugues Fruchet
This adds documentation of device tree bindings for the STM32 DCMI
(Digital Camera Memory Interface).

Signed-off-by: Hugues Fruchet <hugues.fruc...@st.com>
---
 .../devicetree/bindings/media/st,stm32-dcmi.txt| 77 ++
 1 file changed, 77 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/st,stm32-dcmi.txt

diff --git a/Documentation/devicetree/bindings/media/st,stm32-dcmi.txt 
b/Documentation/devicetree/bindings/media/st,stm32-dcmi.txt
new file mode 100644
index 000..f0dc709
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/st,stm32-dcmi.txt
@@ -0,0 +1,77 @@
+STMicroelectronics STM32 Digital Camera Memory Interface (DCMI)
+
+Required properties:
+- compatible: "st,stm32-dcmi"
+- reg: physical base address and length of the registers set for the device;
+- interrupts: should contain IRQ line for the DCMI;
+- clocks: list of clock specifiers, corresponding to entries in
+  the clock-names property;
+- clock-names: must contain "mclk", which is the DCMI peripherial clock.
+- resets: Reference to a reset controller
+- reset-names: see Documentation/devicetree/bindings/reset/st,stm32-rcc.txt
+
+DCMI supports a single port node with parallel bus. It should contain one
+'port' child node with child 'endpoint' node. Please refer to the bindings
+defined in Documentation/devicetree/bindings/media/video-interfaces.txt.
+
+Example:
+
+Device node example
+---
+   dcmi: dcmi@5005 {
+   compatible = "st,stm32-dcmi";
+   reg = <0x5005 0x400>;
+   interrupts = <78>;
+   resets = < STM32F4_AHB2_RESET(DCMI)>;
+   clocks = < 0 STM32F4_AHB2_CLOCK(DCMI)>;
+   clock-names = "mclk";
+   pinctrl-names = "default";
+   pinctrl-0 = <_pins>;
+   dmas = < 1 1 0x414 0x3>;
+   dma-names = "tx";
+   status = "disabled";
+   };
+
+Board setup example
+---
+
+ {
+   status = "okay";
+
+   port {
+   dcmi_0: endpoint@0 {
+   remote-endpoint = <_0>;
+   bus-width = <8>;
+   hsync-active = <0>;
+   vsync-active = <0>;
+   pclk-sample = <1>;
+   };
+   };
+};
+
+{
+   [...]
+   i2c@0 {
+   ov2640: camera@30 {
+   compatible = "ovti,ov2640";
+   reg = <0x30>;
+   resetb-gpios = < 2 GPIO_ACTIVE_HIGH>;
+   pwdn-gpios = < 0 GPIO_ACTIVE_LOW>;
+   clocks = <_ext_camera>;
+   clock-names = "xvclk";
+   status = "okay";
+
+   port {
+   ov2640_0: endpoint {
+   remote-endpoint = <_0>;
+   };
+   };
+   };
+   };
+
+   clk_ext_camera: clk-ext-camera {
+   #clock-cells = <0>;
+   compatible = "fixed-clock";
+   clock-frequency = <2400>;
+   };
+}
-- 
1.9.1



[PATCH v1 5/8] ARM: dts: stm32: Enable stmpe1600 gpio expandor of STM32F429-EVAL board

2017-03-29 Thread Hugues Fruchet
Signed-off-by: Hugues Fruchet <hugues.fruc...@st.com>
---
 arch/arm/boot/dts/stm32429i-eval.dts | 17 +
 1 file changed, 17 insertions(+)

diff --git a/arch/arm/boot/dts/stm32429i-eval.dts 
b/arch/arm/boot/dts/stm32429i-eval.dts
index 87733d3..7ffcf07 100644
--- a/arch/arm/boot/dts/stm32429i-eval.dts
+++ b/arch/arm/boot/dts/stm32429i-eval.dts
@@ -154,6 +154,23 @@
pinctrl-0 = <_pins>;
pinctrl-names = "default";
status = "okay";
+
+   stmpe1600: stmpe1600@42 {
+   compatible = "st,stmpe1600";
+   reg = <0x42>;
+   irq-gpio = < 8 0>;
+   irq-trigger = <3>;
+   interrupts = <8 3>;
+   interrupt-parent = <>;
+   interrupt-controller;
+   wakeup-source;
+
+   stmpegpio: stmpe_gpio {
+   compatible = "st,stmpe-gpio";
+   gpio-controller;
+   #gpio-cells = <2>;
+   };
+   };
 };
 
  {
-- 
1.9.1



[PATCH v1 3/8] ARM: dts: stm32: Enable DCMI support on STM32F429 MCU

2017-03-29 Thread Hugues Fruchet
Signed-off-by: Hugues Fruchet <hugues.fruc...@st.com>
---
 arch/arm/boot/dts/stm32f429.dtsi | 37 +
 1 file changed, 37 insertions(+)

diff --git a/arch/arm/boot/dts/stm32f429.dtsi b/arch/arm/boot/dts/stm32f429.dtsi
index ee0da97..e1ff978 100644
--- a/arch/arm/boot/dts/stm32f429.dtsi
+++ b/arch/arm/boot/dts/stm32f429.dtsi
@@ -736,6 +736,29 @@
slew-rate = <3>;
};
};
+
+   dcmi_pins: dcmi_pins@0 {
+   pins {
+   pinmux = 
,
+
,
+
,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+;
+   bias-disable;
+   drive-push-pull;
+   slew-rate = <3>;
+   };
+   };
};
 
rcc: rcc@40023810 {
@@ -805,6 +828,20 @@
status = "disabled";
};
 
+   dcmi: dcmi@5005 {
+   compatible = "st,stm32-dcmi";
+   reg = <0x5005 0x400>;
+   interrupts = <78>;
+   resets = < STM32F4_AHB2_RESET(DCMI)>;
+   clocks = < 0 STM32F4_AHB2_CLOCK(DCMI)>;
+   clock-names = "mclk";
+   pinctrl-names = "default";
+   pinctrl-0 = <_pins>;
+   dmas = < 1 1 0x414 0x3>;
+   dma-names = "tx";
+   status = "disabled";
+   };
+
rng: rng@50060800 {
compatible = "st,stm32-rng";
reg = <0x50060800 0x400>;
-- 
1.9.1



[PATCH v2 8/8] ARM: configs: stm32: DCMI + OV2640 camera support

2017-03-30 Thread Hugues Fruchet
Enable DCMI camera interface and OV2640 camera sensor drivers.

Signed-off-by: Hugues Fruchet <hugues.fruc...@st.com>
---
 arch/arm/configs/stm32_defconfig | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/arch/arm/configs/stm32_defconfig b/arch/arm/configs/stm32_defconfig
index 84adc88..3f2e4ce 100644
--- a/arch/arm/configs/stm32_defconfig
+++ b/arch/arm/configs/stm32_defconfig
@@ -53,6 +53,13 @@ CONFIG_GPIO_STMPE=y
 CONFIG_MFD_STMPE=y
 CONFIG_REGULATOR_FIXED_VOLTAGE=y
 # CONFIG_USB_SUPPORT is not set
+CONFIG_VIDEO_V4L2=y
+CONFIG_MEDIA_SUBDRV_AUTOSELECT=n
+CONFIG_V4L_PLATFORM_DRIVERS=y
+CONFIG_MEDIA_SUPPORT=y
+CONFIG_MEDIA_CAMERA_SUPPORT=y
+CONFIG_VIDEO_STM32_DCMI=y
+CONFIG_VIDEO_OV2640=y
 CONFIG_NEW_LEDS=y
 CONFIG_LEDS_CLASS=y
 CONFIG_LEDS_GPIO=y
-- 
1.9.1



[PATCH v2 4/8] ARM: dts: stm32: Enable DCMI camera interface on STM32F429-EVAL board

2017-03-30 Thread Hugues Fruchet
Enable DCMI camera interface on STM32F429-EVAL board.

Signed-off-by: Hugues Fruchet <hugues.fruc...@st.com>
---
 arch/arm/boot/dts/stm32429i-eval.dts | 9 +
 1 file changed, 9 insertions(+)

diff --git a/arch/arm/boot/dts/stm32429i-eval.dts 
b/arch/arm/boot/dts/stm32429i-eval.dts
index 3c99466..87733d3 100644
--- a/arch/arm/boot/dts/stm32429i-eval.dts
+++ b/arch/arm/boot/dts/stm32429i-eval.dts
@@ -141,6 +141,15 @@
clock-frequency = <2500>;
 };
 
+ {
+   status = "okay";
+
+   port {
+   dcmi_0: endpoint@0 {
+   };
+   };
+};
+
  {
pinctrl-0 = <_pins>;
pinctrl-names = "default";
-- 
1.9.1



[PATCH v2 3/8] ARM: dts: stm32: Enable DCMI support on STM32F429 MCU

2017-03-30 Thread Hugues Fruchet
Signed-off-by: Hugues Fruchet <hugues.fruc...@st.com>
---
 arch/arm/boot/dts/stm32f429.dtsi | 37 +
 1 file changed, 37 insertions(+)

diff --git a/arch/arm/boot/dts/stm32f429.dtsi b/arch/arm/boot/dts/stm32f429.dtsi
index ee0da97..e1ff978 100644
--- a/arch/arm/boot/dts/stm32f429.dtsi
+++ b/arch/arm/boot/dts/stm32f429.dtsi
@@ -736,6 +736,29 @@
slew-rate = <3>;
};
};
+
+   dcmi_pins: dcmi_pins@0 {
+   pins {
+   pinmux = 
,
+
,
+
,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+;
+   bias-disable;
+   drive-push-pull;
+   slew-rate = <3>;
+   };
+   };
};
 
rcc: rcc@40023810 {
@@ -805,6 +828,20 @@
status = "disabled";
};
 
+   dcmi: dcmi@5005 {
+   compatible = "st,stm32-dcmi";
+   reg = <0x5005 0x400>;
+   interrupts = <78>;
+   resets = < STM32F4_AHB2_RESET(DCMI)>;
+   clocks = < 0 STM32F4_AHB2_CLOCK(DCMI)>;
+   clock-names = "mclk";
+   pinctrl-names = "default";
+   pinctrl-0 = <_pins>;
+   dmas = < 1 1 0x414 0x3>;
+   dma-names = "tx";
+   status = "disabled";
+   };
+
rng: rng@50060800 {
compatible = "st,stm32-rng";
reg = <0x50060800 0x400>;
-- 
1.9.1



[PATCH v2 2/8] [media] stm32-dcmi: STM32 DCMI camera interface driver

2017-03-30 Thread Hugues Fruchet
This V4L2 subdev driver enables Digital Camera Memory Interface (DCMI)
of STMicroelectronics STM32 SoC series.

Signed-off-by: Yannick Fertre <yannick.fer...@st.com>
Signed-off-by: Hugues Fruchet <hugues.fruc...@st.com>
---
 drivers/media/platform/Kconfig|   12 +
 drivers/media/platform/Makefile   |2 +
 drivers/media/platform/stm32/Makefile |1 +
 drivers/media/platform/stm32/stm32-dcmi.c | 1417 +
 4 files changed, 1432 insertions(+)
 create mode 100644 drivers/media/platform/stm32/Makefile
 create mode 100644 drivers/media/platform/stm32/stm32-dcmi.c

diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig
index ab0bb48..3421965 100644
--- a/drivers/media/platform/Kconfig
+++ b/drivers/media/platform/Kconfig
@@ -114,6 +114,18 @@ config VIDEO_S3C_CAMIF
  To compile this driver as a module, choose M here: the module
  will be called s3c-camif.
 
+config VIDEO_STM32_DCMI
+   tristate "Digital Camera Memory Interface (DCMI) support"
+   depends on VIDEO_V4L2 && OF && HAS_DMA
+   depends on ARCH_STM32 || COMPILE_TEST
+   select VIDEOBUF2_DMA_CONTIG
+   ---help---
+ This module makes the STM32 Digital Camera Memory Interface (DCMI)
+ available as a v4l2 device.
+
+ To compile this driver as a module, choose M here: the module
+ will be called stm32-dcmi.
+
 source "drivers/media/platform/soc_camera/Kconfig"
 source "drivers/media/platform/exynos4-is/Kconfig"
 source "drivers/media/platform/am437x/Kconfig"
diff --git a/drivers/media/platform/Makefile b/drivers/media/platform/Makefile
index 8959f6e..d747715 100644
--- a/drivers/media/platform/Makefile
+++ b/drivers/media/platform/Makefile
@@ -64,6 +64,8 @@ obj-$(CONFIG_VIDEO_RCAR_VIN)  += rcar-vin/
 
 obj-$(CONFIG_VIDEO_ATMEL_ISC)  += atmel/
 
+obj-$(CONFIG_VIDEO_STM32_DCMI) += stm32/
+
 ccflags-y += -I$(srctree)/drivers/media/i2c
 
 obj-$(CONFIG_VIDEO_MEDIATEK_VPU)   += mtk-vpu/
diff --git a/drivers/media/platform/stm32/Makefile 
b/drivers/media/platform/stm32/Makefile
new file mode 100644
index 000..9b606a7
--- /dev/null
+++ b/drivers/media/platform/stm32/Makefile
@@ -0,0 +1 @@
+obj-$(CONFIG_VIDEO_STM32_DCMI) += stm32-dcmi.o
diff --git a/drivers/media/platform/stm32/stm32-dcmi.c 
b/drivers/media/platform/stm32/stm32-dcmi.c
new file mode 100644
index 000..cd22835
--- /dev/null
+++ b/drivers/media/platform/stm32/stm32-dcmi.c
@@ -0,0 +1,1417 @@
+/*
+ * Driver for STM32 Digital Camera Memory Interface
+ *
+ * Copyright (C) STMicroelectronics SA 2017
+ * Authors: Yannick Fertre <yannick.fer...@st.com>
+ *  Hugues Fruchet <hugues.fruc...@st.com>
+ *  for STMicroelectronics.
+ * License terms:  GNU General Public License (GPL), version 2
+ *
+ * This driver is based on atmel_isi.c
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define DRV_NAME "stm32-dcmi"
+
+/* Registers offset for DCMI */
+#define DCMI_CR0x00 /* Control Register */
+#define DCMI_SR0x04 /* Status Register */
+#define DCMI_RIS   0x08 /* Raw Interrupt Status register */
+#define DCMI_IER   0x0C /* Interrupt Enable Register */
+#define DCMI_MIS   0x10 /* Masked Interrupt Status register */
+#define DCMI_ICR   0x14 /* Interrupt Clear Register */
+#define DCMI_ESCR  0x18 /* Embedded Synchronization Code Register */
+#define DCMI_ESUR  0x1C /* Embedded Synchronization Unmask Register */
+#define DCMI_CWSTRT0x20 /* Crop Window STaRT */
+#define DCMI_CWSIZE0x24 /* Crop Window SIZE */
+#define DCMI_DR0x28 /* Data Register */
+#define DCMI_IDR   0x2C /* IDentifier Register */
+
+/* Bits definition for control register (DCMI_CR) */
+#define CR_CAPTURE BIT(0)
+#define CR_CM  BIT(1)
+#define CR_CROPBIT(2)
+#define CR_JPEGBIT(3)
+#define CR_ESS BIT(4)
+#define CR_PCKPOL  BIT(5)
+#define CR_HSPOL   BIT(6)
+#define CR_VSPOL   BIT(7)
+#define CR_FCRC_0  BIT(8)
+#define CR_FCRC_1  BIT(9)
+#define CR_EDM_0   BIT(10)
+#define CR_EDM_1   BIT(11)
+#define CR_ENABLE  BIT(14)
+
+/* Bits definition for status register (DCMI_SR) */
+#define SR_HSYNC   BIT(0)
+#define SR_VSYNC   BIT(1)
+#define SR_FNE BIT(2)
+
+/*
+ * Bits definition for interrupt registers
+ * (DCMI_RIS, DCMI_IER, DCMI_MIS, DCMI_ICR)
+ */
+#define IT_FRAME   BIT(0)
+#define IT_OVR BIT(1)
+#define IT_ERR BIT(2)
+#define IT_VSYNC   BIT(3)
+#define IT_LINEBIT(4)
+
+enum state {
+   STOPPED = 0,
+   RUNNING,
+   STOPPING,
+};
+
+#define MAX_BUS_W

[PATCH v2 6/8] ARM: dts: stm32: Enable OV2640 camera support of STM32F429-EVAL board

2017-03-30 Thread Hugues Fruchet
Enable OV2640 camera support of STM32F429-EVAL board.

Signed-off-by: Hugues Fruchet <hugues.fruc...@st.com>
---
 arch/arm/boot/dts/stm32429i-eval.dts | 30 ++
 1 file changed, 30 insertions(+)

diff --git a/arch/arm/boot/dts/stm32429i-eval.dts 
b/arch/arm/boot/dts/stm32429i-eval.dts
index 7ffcf07..b7d127c 100644
--- a/arch/arm/boot/dts/stm32429i-eval.dts
+++ b/arch/arm/boot/dts/stm32429i-eval.dts
@@ -48,6 +48,7 @@
 /dts-v1/;
 #include "stm32f429.dtsi"
 #include 
+#include 
 
 / {
model = "STMicroelectronics STM32429i-EVAL board";
@@ -66,6 +67,14 @@
serial0 = 
};
 
+   clocks {
+   clk_ext_camera: clk-ext-camera {
+   #clock-cells = <0>;
+   compatible = "fixed-clock";
+   clock-frequency = <2400>;
+   };
+   };
+
soc {
dma-ranges = <0xc000 0x0 0x1000>;
};
@@ -146,6 +155,11 @@
 
port {
dcmi_0: endpoint@0 {
+   remote-endpoint = <_0>;
+   bus-width = <8>;
+   hsync-active = <0>;
+   vsync-active = <0>;
+   pclk-sample = <1>;
};
};
 };
@@ -155,6 +169,22 @@
pinctrl-names = "default";
status = "okay";
 
+   ov2640: camera@30 {
+   compatible = "ovti,ov2640";
+   reg = <0x30>;
+   resetb-gpios = < 2 GPIO_ACTIVE_HIGH>;
+   pwdn-gpios = < 0 GPIO_ACTIVE_LOW>;
+   clocks = <_ext_camera>;
+   clock-names = "xvclk";
+   status = "okay";
+
+   port {
+   ov2640_0: endpoint {
+   remote-endpoint = <_0>;
+   };
+   };
+   };
+
stmpe1600: stmpe1600@42 {
compatible = "st,stmpe1600";
reg = <0x42>;
-- 
1.9.1



[PATCH v2 0/8] Add support for DCMI camera interface of STMicroelectronics STM32 SoC series

2017-03-30 Thread Hugues Fruchet
This patchset introduces a basic support for Digital Camera Memory Interface
(DCMI) of STMicroelectronics STM32 SoC series.

This first basic support implements RGB565 & YUV frame grabbing.
Cropping and JPEG support will be added later on.

This has been tested on STM324x9I-EVAL evaluation board embedding
an OV2640 camera sensor.

This driver depends on:
  - [PATCHv6 00/14] atmel-isi/ov7670/ov2640: convert to standalone drivers 
http://www.spinics.net/lists/linux-media/msg113480.html

===
= history =
===
version 2:
  - Fix a Kbuild warning in probe:
http://www.mail-archive.com/linux-media@vger.kernel.org/msg110678.html
  - Fix a warning in dcmi_queue_setup()
  - dt-bindings: warn on sensor signals level inversion in board example
  - Typos fixing

version 1:
  - Initial submission

===
= v4l2-compliance =
===
Below is the v4l2-compliance report for this current version of the DCMI camera 
interface.
v4l2-compliance has been built from v4l-utils-1.12.3.

v4l2-compliance SHA   : f5f45e17ee98a0ebad7836ade2b34ceec909d751

Driver Info:
Driver name   : stm32-dcmi
Card type : STM32 Digital Camera Memory Int
Bus info  : platform:dcmi
Driver version: 4.11.0
Capabilities  : 0x8521
Video Capture
Read/Write
Streaming
Extended Pix Format
Device Capabilities
Device Caps   : 0x0521
Video Capture
Read/Write
Streaming
Extended Pix Format

Compliance test for device /dev/video0 (not using libv4l2):

Required ioctls:
test VIDIOC_QUERYCAP: OK

Allow for multiple opens:
test second video open: OK
test VIDIOC_QUERYCAP: OK
test VIDIOC_G/S_PRIORITY: OK
test for unlimited opens: OK

Debug ioctls:
test VIDIOC_DBG_G/S_REGISTER: OK (Not Supported)
test VIDIOC_LOG_STATUS: OK

Input ioctls:
test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported)
test VIDIOC_G/S_FREQUENCY: OK (Not Supported)
test VIDIOC_S_HW_FREQ_SEEK: OK (Not Supported)
test VIDIOC_ENUMAUDIO: OK (Not Supported)
test VIDIOC_G/S/ENUMINPUT: OK
test VIDIOC_G/S_AUDIO: OK (Not Supported)
Inputs: 1 Audio Inputs: 0 Tuners: 0

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

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

Test input 0:

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

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

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

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

Test input 0:

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


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

Hugues Fruchet (8):
  dt-bindings: Document STM32 DCMI bindings
  [media] stm32-dcmi: STM32 DCMI camera interface driver
  ARM: dts: stm32: Enable DCMI support on STM32F429 MCU
  ARM: dts: stm32: Enable DCMI camera interface on STM32F429-EVAL board
  ARM: dts: stm32: Enable STMPE1600 gpio expander of STM32F429-EVAL
board
  ARM: dts: stm32: Enable OV2640 camera support of STM32F429-EVAL board
  ARM: configs: stm32: STMPE1600 GPIO expander
  ARM: configs: stm32: DCMI + OV2640 camera support

 .../devicetree/bindings/media/st,s

[PATCH v2 1/8] dt-bindings: Document STM32 DCMI bindings

2017-03-30 Thread Hugues Fruchet
This adds documentation of device tree bindings for the STM32 DCMI
(Digital Camera Memory Interface).

Signed-off-by: Hugues Fruchet <hugues.fruc...@st.com>
---
 .../devicetree/bindings/media/st,stm32-dcmi.txt| 85 ++
 1 file changed, 85 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/st,stm32-dcmi.txt

diff --git a/Documentation/devicetree/bindings/media/st,stm32-dcmi.txt 
b/Documentation/devicetree/bindings/media/st,stm32-dcmi.txt
new file mode 100644
index 000..8180f63
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/st,stm32-dcmi.txt
@@ -0,0 +1,85 @@
+STMicroelectronics STM32 Digital Camera Memory Interface (DCMI)
+
+Required properties:
+- compatible: "st,stm32-dcmi"
+- reg: physical base address and length of the registers set for the device
+- interrupts: should contain IRQ line for the DCMI
+- clocks: list of clock specifiers, corresponding to entries in
+  the clock-names property
+- clock-names: must contain "mclk", which is the DCMI peripherial clock
+- resets: reference to a reset controller
+- reset-names: see Documentation/devicetree/bindings/reset/st,stm32-rcc.txt
+
+DCMI supports a single port node with parallel bus. It should contain one
+'port' child node with child 'endpoint' node. Please refer to the bindings
+defined in Documentation/devicetree/bindings/media/video-interfaces.txt.
+
+Example:
+
+Device node example
+---
+   dcmi: dcmi@5005 {
+   compatible = "st,stm32-dcmi";
+   reg = <0x5005 0x400>;
+   interrupts = <78>;
+   resets = < STM32F4_AHB2_RESET(DCMI)>;
+   clocks = < 0 STM32F4_AHB2_CLOCK(DCMI)>;
+   clock-names = "mclk";
+   pinctrl-names = "default";
+   pinctrl-0 = <_pins>;
+   dmas = < 1 1 0x414 0x3>;
+   dma-names = "tx";
+   status = "disabled";
+   };
+
+Board setup example
+---
+This example is extracted from STM32F429-EVAL board devicetree.
+Please note that on this board, the camera sensor reset & power-down
+line level are inverted (so reset is active high and power-down is
+active low).
+
+/ {
+   [...]
+   clocks {
+   clk_ext_camera: clk-ext-camera {
+   #clock-cells = <0>;
+   compatible = "fixed-clock";
+   clock-frequency = <2400>;
+   };
+   };
+   [...]
+};
+
+ {
+   status = "okay";
+
+   port {
+   dcmi_0: endpoint@0 {
+   remote-endpoint = <_0>;
+   bus-width = <8>;
+   hsync-active = <0>;
+   vsync-active = <0>;
+   pclk-sample = <1>;
+   };
+   };
+};
+
+@1 {
+   [...]
+   ov2640: camera@30 {
+   compatible = "ovti,ov2640";
+   reg = <0x30>;
+   resetb-gpios = < 2 GPIO_ACTIVE_HIGH>;
+   pwdn-gpios = < 0 GPIO_ACTIVE_LOW>;
+   clocks = <_ext_camera>;
+   clock-names = "xvclk";
+   status = "okay";
+
+   port {
+   ov2640_0: endpoint {
+   remote-endpoint = <_0>;
+   };
+   };
+   };
+};
-- 
1.9.1



[PATCH v2 7/8] ARM: configs: stm32: STMPE1600 GPIO expander

2017-03-30 Thread Hugues Fruchet
Enable STMPE1600 GPIO expander.

Signed-off-by: Hugues Fruchet <hugues.fruc...@st.com>
---
 arch/arm/configs/stm32_defconfig | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/arm/configs/stm32_defconfig b/arch/arm/configs/stm32_defconfig
index a9d8e3c..84adc88 100644
--- a/arch/arm/configs/stm32_defconfig
+++ b/arch/arm/configs/stm32_defconfig
@@ -49,6 +49,8 @@ CONFIG_SERIAL_STM32_CONSOLE=y
 # CONFIG_HW_RANDOM is not set
 # CONFIG_HWMON is not set
 CONFIG_REGULATOR=y
+CONFIG_GPIO_STMPE=y
+CONFIG_MFD_STMPE=y
 CONFIG_REGULATOR_FIXED_VOLTAGE=y
 # CONFIG_USB_SUPPORT is not set
 CONFIG_NEW_LEDS=y
-- 
1.9.1



[PATCH v2 5/8] ARM: dts: stm32: Enable STMPE1600 gpio expander of STM32F429-EVAL board

2017-03-30 Thread Hugues Fruchet
Enable STMPE1600 gpio expander of STM32F429-EVAL board.

Signed-off-by: Hugues Fruchet <hugues.fruc...@st.com>
---
 arch/arm/boot/dts/stm32429i-eval.dts | 17 +
 1 file changed, 17 insertions(+)

diff --git a/arch/arm/boot/dts/stm32429i-eval.dts 
b/arch/arm/boot/dts/stm32429i-eval.dts
index 87733d3..7ffcf07 100644
--- a/arch/arm/boot/dts/stm32429i-eval.dts
+++ b/arch/arm/boot/dts/stm32429i-eval.dts
@@ -154,6 +154,23 @@
pinctrl-0 = <_pins>;
pinctrl-names = "default";
status = "okay";
+
+   stmpe1600: stmpe1600@42 {
+   compatible = "st,stmpe1600";
+   reg = <0x42>;
+   irq-gpio = < 8 0>;
+   irq-trigger = <3>;
+   interrupts = <8 3>;
+   interrupt-parent = <>;
+   interrupt-controller;
+   wakeup-source;
+
+   stmpegpio: stmpe_gpio {
+   compatible = "st,stmpe-gpio";
+   gpio-controller;
+   #gpio-cells = <2>;
+   };
+   };
 };
 
  {
-- 
1.9.1



[PATCH v1 2/8] [media] stm32-dcmi: STM32 DCMI camera interface driver

2017-03-29 Thread Hugues Fruchet
This V4L2 subdev driver enables Digital Camera Memory Interface (DCMI)
of STMicroelectronics STM32 SoC series.

Signed-off-by: Yannick Fertre <yannick.fer...@st.com>
Signed-off-by: Hugues Fruchet <hugues.fruc...@st.com>
---
 drivers/media/platform/Kconfig|   12 +
 drivers/media/platform/Makefile   |2 +
 drivers/media/platform/stm32/Makefile |1 +
 drivers/media/platform/stm32/stm32-dcmi.c | 1417 +
 4 files changed, 1432 insertions(+)
 create mode 100644 drivers/media/platform/stm32/Makefile
 create mode 100644 drivers/media/platform/stm32/stm32-dcmi.c

diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig
index ab0bb48..3421965 100644
--- a/drivers/media/platform/Kconfig
+++ b/drivers/media/platform/Kconfig
@@ -114,6 +114,18 @@ config VIDEO_S3C_CAMIF
  To compile this driver as a module, choose M here: the module
  will be called s3c-camif.
 
+config VIDEO_STM32_DCMI
+   tristate "Digital Camera Memory Interface (DCMI) support"
+   depends on VIDEO_V4L2 && OF && HAS_DMA
+   depends on ARCH_STM32 || COMPILE_TEST
+   select VIDEOBUF2_DMA_CONTIG
+   ---help---
+ This module makes the STM32 Digital Camera Memory Interface (DCMI)
+ available as a v4l2 device.
+
+ To compile this driver as a module, choose M here: the module
+ will be called stm32-dcmi.
+
 source "drivers/media/platform/soc_camera/Kconfig"
 source "drivers/media/platform/exynos4-is/Kconfig"
 source "drivers/media/platform/am437x/Kconfig"
diff --git a/drivers/media/platform/Makefile b/drivers/media/platform/Makefile
index 8959f6e..d747715 100644
--- a/drivers/media/platform/Makefile
+++ b/drivers/media/platform/Makefile
@@ -64,6 +64,8 @@ obj-$(CONFIG_VIDEO_RCAR_VIN)  += rcar-vin/
 
 obj-$(CONFIG_VIDEO_ATMEL_ISC)  += atmel/
 
+obj-$(CONFIG_VIDEO_STM32_DCMI) += stm32/
+
 ccflags-y += -I$(srctree)/drivers/media/i2c
 
 obj-$(CONFIG_VIDEO_MEDIATEK_VPU)   += mtk-vpu/
diff --git a/drivers/media/platform/stm32/Makefile 
b/drivers/media/platform/stm32/Makefile
new file mode 100644
index 000..9b606a7
--- /dev/null
+++ b/drivers/media/platform/stm32/Makefile
@@ -0,0 +1 @@
+obj-$(CONFIG_VIDEO_STM32_DCMI) += stm32-dcmi.o
diff --git a/drivers/media/platform/stm32/stm32-dcmi.c 
b/drivers/media/platform/stm32/stm32-dcmi.c
new file mode 100644
index 000..2f0286b
--- /dev/null
+++ b/drivers/media/platform/stm32/stm32-dcmi.c
@@ -0,0 +1,1417 @@
+/*
+ * Driver for STM32 Digital Camera Memory Interface
+ *
+ * Copyright (C) STMicroelectronics SA 2017
+ * Authors: Yannick Fertre <yannick.fer...@st.com>
+ *  Hugues Fruchet <hugues.fruc...@st.com>
+ *  for STMicroelectronics.
+ * License terms:  GNU General Public License (GPL), version 2
+ *
+ * This driver is based on atmel_isi.c
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define DRV_NAME "stm32-dcmi"
+
+/* Registers offset for DCMI */
+#define DCMI_CR0x00 /* Control Register */
+#define DCMI_SR0x04 /* Status Register */
+#define DCMI_RIS   0x08 /* Raw Interrupt Status register */
+#define DCMI_IER   0x0C /* Interrupt Enable Register */
+#define DCMI_MIS   0x10 /* Masked Interrupt Status register */
+#define DCMI_ICR   0x14 /* Interrupt Clear Register */
+#define DCMI_ESCR  0x18 /* Embedded Synchronization Code Register */
+#define DCMI_ESUR  0x1C /* Embedded Synchronization Unmask Register */
+#define DCMI_CWSTRT0x20 /* Crop Window STaRT */
+#define DCMI_CWSIZE0x24 /* Crop Window SIZE */
+#define DCMI_DR0x28 /* Data Register */
+#define DCMI_IDR   0x2c /* IDentifier Register */
+
+/* Bits definition for control register (DCMI_CR) */
+#define CR_CAPTURE BIT(0)
+#define CR_CM  BIT(1)
+#define CR_CROPBIT(2)
+#define CR_JPEGBIT(3)
+#define CR_ESS BIT(4)
+#define CR_PCKPOL  BIT(5)
+#define CR_HSPOL   BIT(6)
+#define CR_VSPOL   BIT(7)
+#define CR_FCRC_0  BIT(8)
+#define CR_FCRC_1  BIT(9)
+#define CR_EDM_0   BIT(10)
+#define CR_EDM_1   BIT(11)
+#define CR_ENABLE  BIT(14)
+
+/* Bits definition for status register (DCMI_SR) */
+#define SR_HSYNC   BIT(0)
+#define SR_VSYNC   BIT(1)
+#define SR_FNE BIT(2)
+
+/*
+ * Bits definition for interrupt registers
+ * (DCMI_RIS, DCMI_IER, DCMI_MIS, DCMI_ICR)
+ */
+#define IT_FRAME   BIT(0)
+#define IT_OVR BIT(1)
+#define IT_ERR BIT(2)
+#define IT_VSYNC   BIT(3)
+#define IT_LINEBIT(4)
+
+enum state {
+   STOPPED = 0,
+   RUNNING,
+   STOPPING,
+};
+
+#define MAX_BUS_W

[PATCH v1 0/8] Add support for DCMI camera interface of STMicroelectronics STM32 SoC series

2017-03-29 Thread Hugues Fruchet
This patchset introduces a basic support for Digital Camera Memory Interface
(DCMI) of STMicroelectronics STM32 SoC series.

This first basic support implements RGB565 & YUV frame grabbing.
Cropping and JPEG support will be added later on.

This has been tested on STM324x9I-EVAL evaluation board embedding
an OV2640 camera sensor.

This driver depends on:
  - [PATCHv6 00/14] atmel-isi/ov7670/ov2640: convert to standalone drivers 
http://www.spinics.net/lists/linux-media/msg113480.html

===
= history =
===
version 1:
  - Initial submission

===
= v4l2-compliance =
===
Below is the v4l2-compliance report for this current version of the DCMI camera 
interface.
v4l2-compliance has been built from v4l-utils-1.12.3.

v4l2-compliance SHA   : f5f45e17ee98a0ebad7836ade2b34ceec909d751

Driver Info:
Driver name   : stm32-dcmi
Card type : STM32 Digital Camera Memory Int
Bus info  : platform:dcmi
Driver version: 4.11.0
Capabilities  : 0x8521
Video Capture
Read/Write
Streaming
Extended Pix Format
Device Capabilities
Device Caps   : 0x0521
Video Capture
Read/Write
Streaming
Extended Pix Format

Compliance test for device /dev/video0 (not using libv4l2):

Required ioctls:
test VIDIOC_QUERYCAP: OK

Allow for multiple opens:
test second video open: OK
test VIDIOC_QUERYCAP: OK
test VIDIOC_G/S_PRIORITY: OK
test for unlimited opens: OK

Debug ioctls:
test VIDIOC_DBG_G/S_REGISTER: OK (Not Supported)
test VIDIOC_LOG_STATUS: OK

Input ioctls:
test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported)
test VIDIOC_G/S_FREQUENCY: OK (Not Supported)
test VIDIOC_S_HW_FREQ_SEEK: OK (Not Supported)
test VIDIOC_ENUMAUDIO: OK (Not Supported)
test VIDIOC_G/S/ENUMINPUT: OK
test VIDIOC_G/S_AUDIO: OK (Not Supported)
Inputs: 1 Audio Inputs: 0 Tuners: 0

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

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

Test input 0:

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

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

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

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

Test input 0:

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


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

Hugues Fruchet (8):
  dt-bindings: Document STM32 DCMI bindings
  [media] stm32-dcmi: STM32 DCMI camera interface driver
  ARM: dts: stm32: Enable DCMI support on STM32F429 MCU
  ARM: dts: stm32: Enable DCMI camera interface on STM32F429-EVAL board
  ARM: dts: stm32: Enable stmpe1600 gpio expandor of STM32F429-EVAL
board
  ARM: dts: stm32: Enable ov2640 camera support of STM32F429-EVAL board
  ARM: configs: stm32: stmpe 1600 GPIO expandor
  ARM: configs: stm32: DCMI + OV2640 camera support

 .../devicetree/bindings/media/st,stm32-dcmi.txt|   77 ++
 arch/arm/boot/dts/stm32429i-eval.dts   |   56 +
 arch/arm/boot/dts/stm32f429.dtsi   |   37 +
 arch/arm/configs/stm32_defconfig   |9 +
 drivers/media/platform/Kco

[PATCH v1 6/8] ARM: dts: stm32: Enable ov2640 camera support of STM32F429-EVAL board

2017-03-29 Thread Hugues Fruchet
Signed-off-by: Hugues Fruchet <hugues.fruc...@st.com>
---
 arch/arm/boot/dts/stm32429i-eval.dts | 30 ++
 1 file changed, 30 insertions(+)

diff --git a/arch/arm/boot/dts/stm32429i-eval.dts 
b/arch/arm/boot/dts/stm32429i-eval.dts
index 7ffcf07..b7d127c 100644
--- a/arch/arm/boot/dts/stm32429i-eval.dts
+++ b/arch/arm/boot/dts/stm32429i-eval.dts
@@ -48,6 +48,7 @@
 /dts-v1/;
 #include "stm32f429.dtsi"
 #include 
+#include 
 
 / {
model = "STMicroelectronics STM32429i-EVAL board";
@@ -66,6 +67,14 @@
serial0 = 
};
 
+   clocks {
+   clk_ext_camera: clk-ext-camera {
+   #clock-cells = <0>;
+   compatible = "fixed-clock";
+   clock-frequency = <2400>;
+   };
+   };
+
soc {
dma-ranges = <0xc000 0x0 0x1000>;
};
@@ -146,6 +155,11 @@
 
port {
dcmi_0: endpoint@0 {
+   remote-endpoint = <_0>;
+   bus-width = <8>;
+   hsync-active = <0>;
+   vsync-active = <0>;
+   pclk-sample = <1>;
};
};
 };
@@ -155,6 +169,22 @@
pinctrl-names = "default";
status = "okay";
 
+   ov2640: camera@30 {
+   compatible = "ovti,ov2640";
+   reg = <0x30>;
+   resetb-gpios = < 2 GPIO_ACTIVE_HIGH>;
+   pwdn-gpios = < 0 GPIO_ACTIVE_LOW>;
+   clocks = <_ext_camera>;
+   clock-names = "xvclk";
+   status = "okay";
+
+   port {
+   ov2640_0: endpoint {
+   remote-endpoint = <_0>;
+   };
+   };
+   };
+
stmpe1600: stmpe1600@42 {
compatible = "st,stmpe1600";
reg = <0x42>;
-- 
1.9.1



[PATCH v1 7/8] ARM: configs: stm32: stmpe 1600 GPIO expandor

2017-03-29 Thread Hugues Fruchet
Enable STMPE1600 GPIO expandor.

Signed-off-by: Hugues Fruchet <hugues.fruc...@st.com>
---
 arch/arm/configs/stm32_defconfig | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/arm/configs/stm32_defconfig b/arch/arm/configs/stm32_defconfig
index a9d8e3c..84adc88 100644
--- a/arch/arm/configs/stm32_defconfig
+++ b/arch/arm/configs/stm32_defconfig
@@ -49,6 +49,8 @@ CONFIG_SERIAL_STM32_CONSOLE=y
 # CONFIG_HW_RANDOM is not set
 # CONFIG_HWMON is not set
 CONFIG_REGULATOR=y
+CONFIG_GPIO_STMPE=y
+CONFIG_MFD_STMPE=y
 CONFIG_REGULATOR_FIXED_VOLTAGE=y
 # CONFIG_USB_SUPPORT is not set
 CONFIG_NEW_LEDS=y
-- 
1.9.1



[PATCH] mfd: stmpe: Fix bit clearing on STMPE1600

2017-03-31 Thread Hugues Fruchet
GPIO bits clearing on pins assigned to STMPE1600
had no effects due to missing "clear registers"
settings within stmpe1600_regs[].
STMPE1600 does not have dedicated "clear registers",
but single "set/clear registers", hence stmpe1600_regs[]
"clear registers" (STMPE_IDX_GPCR_XXX) must be set to
same value as "set registers" (STMPE_IDX_GPSR_XXX), ie
STMPE1600_REG_GPSR_XXX.

Signed-off-by: Hugues Fruchet <hugues.fruc...@st.com>
---
 drivers/mfd/stmpe.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/mfd/stmpe.c b/drivers/mfd/stmpe.c
index b0c7bcd..566caca 100644
--- a/drivers/mfd/stmpe.c
+++ b/drivers/mfd/stmpe.c
@@ -568,6 +568,8 @@ static int stmpe811_get_altfunc(struct stmpe *stmpe, enum 
stmpe_block block)
[STMPE_IDX_GPMR_CSB]= STMPE1600_REG_GPMR_MSB,
[STMPE_IDX_GPSR_LSB]= STMPE1600_REG_GPSR_LSB,
[STMPE_IDX_GPSR_CSB]= STMPE1600_REG_GPSR_MSB,
+   [STMPE_IDX_GPCR_LSB]= STMPE1600_REG_GPSR_LSB,
+   [STMPE_IDX_GPCR_CSB]= STMPE1600_REG_GPSR_MSB,
[STMPE_IDX_GPDR_LSB]= STMPE1600_REG_GPDR_LSB,
[STMPE_IDX_GPDR_CSB]= STMPE1600_REG_GPDR_MSB,
[STMPE_IDX_IEGPIOR_LSB] = STMPE1600_REG_IEGPIOR_LSB,
-- 
1.9.1



[PATCH v1] checkpatch: test missing initial blank line in block comment

2017-04-03 Thread Hugues Fruchet
Hi checkpatch maintainers,

here is a patch tentative to raise a warning when multiple line block comments
are not starting with empty blank comment:

Warn when block comments are not starting with blank comment:
/* multiple lines
 * block comment,
 * => warning
 */

/*
 * multiple lines
 * block comment,
 * => no warning
 */

Exception made for networking files where rule is the
exact opposite.


* sample output:

$ scripts/checkpatch.pl -f drivers/media/v4l2-core/* | grep empty -A2
WARNING: Block comments starts with an empty /*
#393: FILE: drivers/media/v4l2-core/v4l2-compat-ioctl32.c:393:
+   /* For MMAP, driver might've set up the offset, so copy it back.
--
WARNING: Block comments starts with an empty /*
#661: FILE: drivers/media/v4l2-core/v4l2-ctrls.c:661:
+   /* The MPEG controls are applicable to all codec controls
--
+   /* Add immediately at the end of the list if the list is empty, or if
+  the last element in the list has a lower ID.
[...]


* sample output in drivers/net/ (non-regression check):

$ scripts/checkpatch.pl -f drivers/net/*/* | grep empty -A2
WARNING: networking block comments don't use an empty /* line, use /* Comment...
#39: FILE: drivers/net/appletalk/cops.c:39:
+/*
--
WARNING: networking block comments don't use an empty /* line, use /* Comment...
#45: FILE: drivers/net/appletalk/cops.c:45:
+/*
--
[...]

Hugues Fruchet (1):
  checkpatch: test missing initial blank line in block comment

 scripts/checkpatch.pl | 11 +++
 1 file changed, 11 insertions(+)

-- 
1.9.1



[PATCH v1] checkpatch: test missing initial blank line in block comment

2017-04-03 Thread Hugues Fruchet
Warn when block comments are not starting with blank comment:

/* multiple lines
 * block comment,
 * => warning
 */

/*
 * multiple lines
 * block comment,
 * => no warning
 */

Exception made for networking files where rule is the
exact opposite.

Signed-off-by: Hugues Fruchet <hugues.fruc...@st.com>
---
 scripts/checkpatch.pl | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index baa3c7b..8754c9d 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -3000,6 +3000,17 @@ sub process {
 "networking block comments don't use an empty /* 
line, use /* Comment...\n" . $hereprev);
}
 
+# Block comment styles
+# Missing initial /*
+   if ($realfile !~ m@^(drivers/net/|net/)@ && #networking 
exception
+   $prevrawline =~ /^\+[ \t]\/\**.+[ \t]/ &&   #start with 
/*...
+   $prevrawline !~ /^\+.*\/\*.*\*\/[ \t]*/ &&  #no inline 
/*...*/
+   $rawline =~ /^\+[ \t]*\*/ &&
+   $realline > 2) {
+   WARN("BLOCK_COMMENT_STYLE",
+"Block comments starts with an empty /*\n" . 
$hereprev);
+   }
+
 # Block comments use * on subsequent lines
if ($prevline =~ /$;[ \t]*$/ && #ends in comment
$prevrawline =~ /^\+.*?\/\*/ && #starting /*
-- 
1.9.1



Re: [PATCH v1] checkpatch: test missing initial blank line in block comment

2017-04-05 Thread Hugues FRUCHET
Hi Joe, thanks for reviewing,

I have run the command you advice on the entire kernel code, modifying 
the script to only match the newly introduced check case.
There was 14389 hits, quite huge, so I cannot 100% certify that there 
are no false positives, but I have checked the output carefully and 
found 2 limit cases:

1) space character placed just after "/*"
WARNING: Block comments starts with an empty /*
#330: FILE: arch/alpha/kernel/core_irongate.c:330:
+   /*
+* Check for within the AGP aperture...
=> 146 hits (grep -c -n -E "\/\* $" /tmp/check.txt)

2) // style comment followed by pointer dereference
WARNING: Block comments starts with an empty /*
#426: FILE: drivers/media/dvb-core/dvb_ca_en50221.c:426:
+   // success
+   *tupleType = _tupleType;
=> 4 hits

Anyway this reveal comment style related issues, so I would say that we 
can keep script as it is, what do you think about ?

Here is the count detail by first level of directories within kernel:

$ grep FILE /tmp/check.txt | grep -c "FILE: drivers/"
8859
$ grep FILE /tmp/check.txt | grep -c "FILE: arch/"
2306
$ grep FILE /tmp/check.txt | grep -c "FILE: fs/"
1136
$ grep FILE /tmp/check.txt | grep -c "FILE: sound/"
810
$ grep FILE /tmp/check.txt | grep -c "FILE: include/"
669
$ grep FILE /tmp/check.txt | grep -c "FILE: kernel/"
143
$ grep FILE /tmp/check.txt | grep -c "FILE: security/"
112
$ grep FILE /tmp/check.txt | grep -c "FILE: lib/"
91
$ grep FILE /tmp/check.txt | grep -c "FILE: tools/"
81
$ grep FILE /tmp/check.txt | grep -c "FILE: crypto/"
54
$ grep FILE /tmp/check.txt | grep -c "FILE: scripts/"
44
$ grep FILE /tmp/check.txt | grep -c "FILE: mm/"
35
$ grep FILE /tmp/check.txt | grep -c "FILE: block/"
27
$ grep FILE /tmp/check.txt | grep -c "FILE: virt/"
8
$ grep FILE /tmp/check.txt | grep -c "FILE: samples/"
5
$ grep FILE /tmp/check.txt | grep -c "FILE: ipc/"
5
$ grep FILE /tmp/check.txt | grep -c "FILE: certs/"
1

The complete output is there for reference: 
http://paste.ubuntu.com/24319042/


Best regards,
Hugues.

On 04/03/2017 09:06 PM, Joe Perches wrote:
> On Mon, 2017-04-03 at 10:08 +0200, Hugues Fruchet wrote:
>> Warn when block comments are not starting with blank comment:
>>
>> /* multiple lines
>>  * block comment,
>>  * => warning
>>  */
>>
>> /*
>>  * multiple lines
>>  * block comment,
>>  * => no warning
>>  */
>>
>> Exception made for networking files where rule is the
>> exact opposite.
>
> I recall there was some reason I didn't do this
> when adding the block comment code, but I don't
> recall what it was.  Perhaps it was the initial
> line of files.
>
> Maybe your $realline > 2 test fixes it.  Maybe not.
> Dunno.
>
> If you run this against the entire kernel code
> using a unique test type and not BLOCK_COMMENT_STYLE
> are there any false positives?
>
> Maybe test with something like:
>
> $ git ls-files -- "*.[ch]" | \
>   xargs --max-args 20 ./scripts/checkpatch.pl -f --types=
>


Re: [PATCH v1] checkpatch: test missing initial blank line in block comment

2017-04-05 Thread Hugues FRUCHET


On 04/05/2017 10:35 AM, Joe Perches wrote:
> On Wed, 2017-04-05 at 08:23 +0000, Hugues FRUCHET wrote:
>> Hi Joe, thanks for reviewing,
>
> Hello Hugues
>
>> I have run the command you advice on the entire kernel code, modifying
>> the script to only match the newly introduced check case.
>> There was 14389 hits, quite huge, so I cannot 100% certify that there
>> are no false positives, but I have checked the output carefully and
>> found 2 limit cases:
>>
>> 1) space character placed just after "/*"
>> WARNING: Block comments starts with an empty /*
>> #330: FILE: arch/alpha/kernel/core_irongate.c:330:
>> +/*
>> + * Check for within the AGP aperture...
>> => 146 hits (grep -c -n -E "\/\* $" /tmp/check.txt)
>>
>> 2) // style comment followed by pointer dereference
>> WARNING: Block comments starts with an empty /*
>> #426: FILE: drivers/media/dvb-core/dvb_ca_en50221.c:426:
>> +// success
>> +*tupleType = _tupleType;
>> => 4 hits
>>
>> Anyway this reveal comment style related issues, so I would say that we
>> can keep script as it is, what do you think about ?
>
> Glancing at the output, there is also the comment
> in a multiline macro case:
>
> WARNING: Block comments starts with an empty /*
> #354: FILE: arch/mips/include/asm/processor.h:354:
> + /*  \
> +  * Other stuff associated with the process  \
>
> Dunno how common that is, but maybe the test
> should be changed to avoid those.
>

Here is a proposal that remove this macro case:

# Missing initial /*
if ($realfile !~ m@^(drivers/net/|net/)@ && #networking exception
 $prevrawline =~ /^\+[ \t]\/\**.+[ \t]/ &&  #start with /*...
 $prevrawline !~ /^\+.*\/\*.*\*\/[ \t]*/ && #no inline /*...*/
+   $prevrawline !~ /^\+[ \t]\/\*+[ \t]+\\$/ &
<

[PATCH v3 7/8] ARM: configs: stm32: STMPE1600 GPIO expander

2017-04-04 Thread Hugues Fruchet
Enable STMPE1600 GPIO expander.

Signed-off-by: Hugues Fruchet <hugues.fruc...@st.com>
---
 arch/arm/configs/stm32_defconfig | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/arm/configs/stm32_defconfig b/arch/arm/configs/stm32_defconfig
index a9d8e3c..84adc88 100644
--- a/arch/arm/configs/stm32_defconfig
+++ b/arch/arm/configs/stm32_defconfig
@@ -49,6 +49,8 @@ CONFIG_SERIAL_STM32_CONSOLE=y
 # CONFIG_HW_RANDOM is not set
 # CONFIG_HWMON is not set
 CONFIG_REGULATOR=y
+CONFIG_GPIO_STMPE=y
+CONFIG_MFD_STMPE=y
 CONFIG_REGULATOR_FIXED_VOLTAGE=y
 # CONFIG_USB_SUPPORT is not set
 CONFIG_NEW_LEDS=y
-- 
1.9.1



[PATCH v3 3/8] ARM: dts: stm32: Enable DCMI support on STM32F429 MCU

2017-04-04 Thread Hugues Fruchet
Signed-off-by: Hugues Fruchet <hugues.fruc...@st.com>
---
 arch/arm/boot/dts/stm32f429.dtsi | 37 +
 1 file changed, 37 insertions(+)

diff --git a/arch/arm/boot/dts/stm32f429.dtsi b/arch/arm/boot/dts/stm32f429.dtsi
index ee0da97..e1ff978 100644
--- a/arch/arm/boot/dts/stm32f429.dtsi
+++ b/arch/arm/boot/dts/stm32f429.dtsi
@@ -736,6 +736,29 @@
slew-rate = <3>;
};
};
+
+   dcmi_pins: dcmi_pins@0 {
+   pins {
+   pinmux = 
,
+
,
+
,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+;
+   bias-disable;
+   drive-push-pull;
+   slew-rate = <3>;
+   };
+   };
};
 
rcc: rcc@40023810 {
@@ -805,6 +828,20 @@
status = "disabled";
};
 
+   dcmi: dcmi@5005 {
+   compatible = "st,stm32-dcmi";
+   reg = <0x5005 0x400>;
+   interrupts = <78>;
+   resets = < STM32F4_AHB2_RESET(DCMI)>;
+   clocks = < 0 STM32F4_AHB2_CLOCK(DCMI)>;
+   clock-names = "mclk";
+   pinctrl-names = "default";
+   pinctrl-0 = <_pins>;
+   dmas = < 1 1 0x414 0x3>;
+   dma-names = "tx";
+   status = "disabled";
+   };
+
rng: rng@50060800 {
compatible = "st,stm32-rng";
reg = <0x50060800 0x400>;
-- 
1.9.1



[PATCH v3 2/8] [media] stm32-dcmi: STM32 DCMI camera interface driver

2017-04-04 Thread Hugues Fruchet
This V4L2 subdev driver enables Digital Camera Memory Interface (DCMI)
of STMicroelectronics STM32 SoC series.

Reviewed-by: Hans Verkuil <hans.verk...@cisco.com>
Signed-off-by: Yannick Fertre <yannick.fer...@st.com>
Signed-off-by: Hugues Fruchet <hugues.fruc...@st.com>
---
 drivers/media/platform/Kconfig|   12 +
 drivers/media/platform/Makefile   |2 +
 drivers/media/platform/stm32/Makefile |1 +
 drivers/media/platform/stm32/stm32-dcmi.c | 1419 +
 4 files changed, 1434 insertions(+)
 create mode 100644 drivers/media/platform/stm32/Makefile
 create mode 100644 drivers/media/platform/stm32/stm32-dcmi.c

diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig
index ab0bb48..3421965 100644
--- a/drivers/media/platform/Kconfig
+++ b/drivers/media/platform/Kconfig
@@ -114,6 +114,18 @@ config VIDEO_S3C_CAMIF
  To compile this driver as a module, choose M here: the module
  will be called s3c-camif.
 
+config VIDEO_STM32_DCMI
+   tristate "Digital Camera Memory Interface (DCMI) support"
+   depends on VIDEO_V4L2 && OF && HAS_DMA
+   depends on ARCH_STM32 || COMPILE_TEST
+   select VIDEOBUF2_DMA_CONTIG
+   ---help---
+ This module makes the STM32 Digital Camera Memory Interface (DCMI)
+ available as a v4l2 device.
+
+ To compile this driver as a module, choose M here: the module
+ will be called stm32-dcmi.
+
 source "drivers/media/platform/soc_camera/Kconfig"
 source "drivers/media/platform/exynos4-is/Kconfig"
 source "drivers/media/platform/am437x/Kconfig"
diff --git a/drivers/media/platform/Makefile b/drivers/media/platform/Makefile
index 8959f6e..d747715 100644
--- a/drivers/media/platform/Makefile
+++ b/drivers/media/platform/Makefile
@@ -64,6 +64,8 @@ obj-$(CONFIG_VIDEO_RCAR_VIN)  += rcar-vin/
 
 obj-$(CONFIG_VIDEO_ATMEL_ISC)  += atmel/
 
+obj-$(CONFIG_VIDEO_STM32_DCMI) += stm32/
+
 ccflags-y += -I$(srctree)/drivers/media/i2c
 
 obj-$(CONFIG_VIDEO_MEDIATEK_VPU)   += mtk-vpu/
diff --git a/drivers/media/platform/stm32/Makefile 
b/drivers/media/platform/stm32/Makefile
new file mode 100644
index 000..9b606a7
--- /dev/null
+++ b/drivers/media/platform/stm32/Makefile
@@ -0,0 +1 @@
+obj-$(CONFIG_VIDEO_STM32_DCMI) += stm32-dcmi.o
diff --git a/drivers/media/platform/stm32/stm32-dcmi.c 
b/drivers/media/platform/stm32/stm32-dcmi.c
new file mode 100644
index 000..d437702
--- /dev/null
+++ b/drivers/media/platform/stm32/stm32-dcmi.c
@@ -0,0 +1,1419 @@
+/*
+ * Driver for STM32 Digital Camera Memory Interface
+ *
+ * Copyright (C) STMicroelectronics SA 2017
+ * Authors: Yannick Fertre <yannick.fer...@st.com>
+ *  Hugues Fruchet <hugues.fruc...@st.com>
+ *  for STMicroelectronics.
+ * License terms:  GNU General Public License (GPL), version 2
+ *
+ * This driver is based on atmel_isi.c
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define DRV_NAME "stm32-dcmi"
+
+/* Registers offset for DCMI */
+#define DCMI_CR0x00 /* Control Register */
+#define DCMI_SR0x04 /* Status Register */
+#define DCMI_RIS   0x08 /* Raw Interrupt Status register */
+#define DCMI_IER   0x0C /* Interrupt Enable Register */
+#define DCMI_MIS   0x10 /* Masked Interrupt Status register */
+#define DCMI_ICR   0x14 /* Interrupt Clear Register */
+#define DCMI_ESCR  0x18 /* Embedded Synchronization Code Register */
+#define DCMI_ESUR  0x1C /* Embedded Synchronization Unmask Register */
+#define DCMI_CWSTRT0x20 /* Crop Window STaRT */
+#define DCMI_CWSIZE0x24 /* Crop Window SIZE */
+#define DCMI_DR0x28 /* Data Register */
+#define DCMI_IDR   0x2C /* IDentifier Register */
+
+/* Bits definition for control register (DCMI_CR) */
+#define CR_CAPTURE BIT(0)
+#define CR_CM  BIT(1)
+#define CR_CROPBIT(2)
+#define CR_JPEGBIT(3)
+#define CR_ESS BIT(4)
+#define CR_PCKPOL  BIT(5)
+#define CR_HSPOL   BIT(6)
+#define CR_VSPOL   BIT(7)
+#define CR_FCRC_0  BIT(8)
+#define CR_FCRC_1  BIT(9)
+#define CR_EDM_0   BIT(10)
+#define CR_EDM_1   BIT(11)
+#define CR_ENABLE  BIT(14)
+
+/* Bits definition for status register (DCMI_SR) */
+#define SR_HSYNC   BIT(0)
+#define SR_VSYNC   BIT(1)
+#define SR_FNE BIT(2)
+
+/*
+ * Bits definition for interrupt registers
+ * (DCMI_RIS, DCMI_IER, DCMI_MIS, DCMI_ICR)
+ */
+#define IT_FRAME   BIT(0)
+#define IT_OVR BIT(1)
+#define IT_ERR BIT(2)
+#define IT_VSYNC   BIT(3)
+#define IT_LINEBIT(4)
+
+enum state {
+   STOPPED = 0,
+ 

Re: [PATCH v2 1/8] dt-bindings: Document STM32 DCMI bindings

2017-04-04 Thread Hugues FRUCHET
Thanks Rob for review, find answers below.

On 04/03/2017 06:23 PM, Rob Herring wrote:
> On Thu, Mar 30, 2017 at 05:27:40PM +0200, Hugues Fruchet wrote:
>> This adds documentation of device tree bindings for the STM32 DCMI
>> (Digital Camera Memory Interface).
>>
>> Signed-off-by: Hugues Fruchet <hugues.fruc...@st.com>
>> ---
>>  .../devicetree/bindings/media/st,stm32-dcmi.txt| 85 
>> ++
>>  1 file changed, 85 insertions(+)
>>  create mode 100644 Documentation/devicetree/bindings/media/st,stm32-dcmi.txt
>>
>> diff --git a/Documentation/devicetree/bindings/media/st,stm32-dcmi.txt 
>> b/Documentation/devicetree/bindings/media/st,stm32-dcmi.txt
>> new file mode 100644
>> index 000..8180f63
>> --- /dev/null
>> +++ b/Documentation/devicetree/bindings/media/st,stm32-dcmi.txt
>> @@ -0,0 +1,85 @@
>> +STMicroelectronics STM32 Digital Camera Memory Interface (DCMI)
>> +
>> +Required properties:
>> +- compatible: "st,stm32-dcmi"
>
> Same block and same errata on all stm32 variants?

Yes, it is the same IP block on all stm32 variants.

>
>> +- reg: physical base address and length of the registers set for the device
>> +- interrupts: should contain IRQ line for the DCMI
>> +- clocks: list of clock specifiers, corresponding to entries in
>> +  the clock-names property
>> +- clock-names: must contain "mclk", which is the DCMI peripherial clock
>> +- resets: reference to a reset controller
>> +- reset-names: see Documentation/devicetree/bindings/reset/st,stm32-rcc.txt
>> +
>> +DCMI supports a single port node with parallel bus. It should contain one
>> +'port' child node with child 'endpoint' node. Please refer to the bindings
>> +defined in Documentation/devicetree/bindings/media/video-interfaces.txt.
>> +
>> +Example:
>> +
>> +Device node example
>> +---
>> +dcmi: dcmi@5005 {
>> +compatible = "st,stm32-dcmi";
>> +reg = <0x5005 0x400>;
>> +interrupts = <78>;
>> +resets = < STM32F4_AHB2_RESET(DCMI)>;
>> +clocks = < 0 STM32F4_AHB2_CLOCK(DCMI)>;
>> +clock-names = "mclk";
>
>> +pinctrl-names = "default";
>> +pinctrl-0 = <_pins>;
>
> Not documented.

Fixed in v3.

>
>> +dmas = < 1 1 0x414 0x3>;
>> +dma-names = "tx";
>
> Not documented.

Fixed in v3.

>
>> +status = "disabled";
>
> Drop status from examples.

Fixed in v3.

>
>> +};
>> +
>> +Board setup example
>
> Please don't split examples. That's just source level details and not
> part of the ABI.

Fixed in v3.

>
>> +---
>> +This example is extracted from STM32F429-EVAL board devicetree.
>> +Please note that on this board, the camera sensor reset & power-down
>> +line level are inverted (so reset is active high and power-down is
>> +active low).
>> +
>> +/ {
>> +[...]
>> +clocks {
>> +clk_ext_camera: clk-ext-camera {
>> +#clock-cells = <0>;
>> +compatible = "fixed-clock";
>> +clock-frequency = <2400>;
>> +};
>> +};
>> +[...]
>> +};
>> +
>> + {
>> +status = "okay";
>> +
>> +port {
>> +dcmi_0: endpoint@0 {
>> +remote-endpoint = <_0>;
>> +bus-width = <8>;
>> +hsync-active = <0>;
>> +vsync-active = <0>;
>> +pclk-sample = <1>;
>> +};
>> +};
>> +};
>> +
>> +@1 {
>> +[...]
>> +ov2640: camera@30 {
>> +compatible = "ovti,ov2640";
>> +reg = <0x30>;
>> +resetb-gpios = < 2 GPIO_ACTIVE_HIGH>;
>> +pwdn-gpios = < 0 GPIO_ACTIVE_LOW>;
>> +clocks = <_ext_camera>;
>> +clock-names = "xvclk";
>> +status = "okay";
>> +
>> +port {
>> +ov2640_0: endpoint {
>> +remote-endpoint = <_0>;
>> +};
>> +};
>> +};
>> +};
>> --
>> 1.9.1
>>


[PATCH v3 6/8] ARM: dts: stm32: Enable OV2640 camera support of STM32F429-EVAL board

2017-04-04 Thread Hugues Fruchet
Enable OV2640 camera support of STM32F429-EVAL board.

Signed-off-by: Hugues Fruchet <hugues.fruc...@st.com>
---
 arch/arm/boot/dts/stm32429i-eval.dts | 30 ++
 1 file changed, 30 insertions(+)

diff --git a/arch/arm/boot/dts/stm32429i-eval.dts 
b/arch/arm/boot/dts/stm32429i-eval.dts
index 7ffcf07..b7d127c 100644
--- a/arch/arm/boot/dts/stm32429i-eval.dts
+++ b/arch/arm/boot/dts/stm32429i-eval.dts
@@ -48,6 +48,7 @@
 /dts-v1/;
 #include "stm32f429.dtsi"
 #include 
+#include 
 
 / {
model = "STMicroelectronics STM32429i-EVAL board";
@@ -66,6 +67,14 @@
serial0 = 
};
 
+   clocks {
+   clk_ext_camera: clk-ext-camera {
+   #clock-cells = <0>;
+   compatible = "fixed-clock";
+   clock-frequency = <2400>;
+   };
+   };
+
soc {
dma-ranges = <0xc000 0x0 0x1000>;
};
@@ -146,6 +155,11 @@
 
port {
dcmi_0: endpoint@0 {
+   remote-endpoint = <_0>;
+   bus-width = <8>;
+   hsync-active = <0>;
+   vsync-active = <0>;
+   pclk-sample = <1>;
};
};
 };
@@ -155,6 +169,22 @@
pinctrl-names = "default";
status = "okay";
 
+   ov2640: camera@30 {
+   compatible = "ovti,ov2640";
+   reg = <0x30>;
+   resetb-gpios = < 2 GPIO_ACTIVE_HIGH>;
+   pwdn-gpios = < 0 GPIO_ACTIVE_LOW>;
+   clocks = <_ext_camera>;
+   clock-names = "xvclk";
+   status = "okay";
+
+   port {
+   ov2640_0: endpoint {
+   remote-endpoint = <_0>;
+   };
+   };
+   };
+
stmpe1600: stmpe1600@42 {
compatible = "st,stmpe1600";
reg = <0x42>;
-- 
1.9.1



[PATCH v3 5/8] ARM: dts: stm32: Enable STMPE1600 gpio expander of STM32F429-EVAL board

2017-04-04 Thread Hugues Fruchet
Enable STMPE1600 gpio expander of STM32F429-EVAL board.

Signed-off-by: Hugues Fruchet <hugues.fruc...@st.com>
---
 arch/arm/boot/dts/stm32429i-eval.dts | 17 +
 1 file changed, 17 insertions(+)

diff --git a/arch/arm/boot/dts/stm32429i-eval.dts 
b/arch/arm/boot/dts/stm32429i-eval.dts
index 87733d3..7ffcf07 100644
--- a/arch/arm/boot/dts/stm32429i-eval.dts
+++ b/arch/arm/boot/dts/stm32429i-eval.dts
@@ -154,6 +154,23 @@
pinctrl-0 = <_pins>;
pinctrl-names = "default";
status = "okay";
+
+   stmpe1600: stmpe1600@42 {
+   compatible = "st,stmpe1600";
+   reg = <0x42>;
+   irq-gpio = < 8 0>;
+   irq-trigger = <3>;
+   interrupts = <8 3>;
+   interrupt-parent = <>;
+   interrupt-controller;
+   wakeup-source;
+
+   stmpegpio: stmpe_gpio {
+   compatible = "st,stmpe-gpio";
+   gpio-controller;
+   #gpio-cells = <2>;
+   };
+   };
 };
 
  {
-- 
1.9.1



[PATCH v3 8/8] ARM: configs: stm32: DCMI + OV2640 camera support

2017-04-04 Thread Hugues Fruchet
Enable DCMI camera interface and OV2640 camera sensor drivers.

Signed-off-by: Hugues Fruchet <hugues.fruc...@st.com>
---
 arch/arm/configs/stm32_defconfig | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/arch/arm/configs/stm32_defconfig b/arch/arm/configs/stm32_defconfig
index 84adc88..3f2e4ce 100644
--- a/arch/arm/configs/stm32_defconfig
+++ b/arch/arm/configs/stm32_defconfig
@@ -53,6 +53,13 @@ CONFIG_GPIO_STMPE=y
 CONFIG_MFD_STMPE=y
 CONFIG_REGULATOR_FIXED_VOLTAGE=y
 # CONFIG_USB_SUPPORT is not set
+CONFIG_VIDEO_V4L2=y
+CONFIG_MEDIA_SUBDRV_AUTOSELECT=n
+CONFIG_V4L_PLATFORM_DRIVERS=y
+CONFIG_MEDIA_SUPPORT=y
+CONFIG_MEDIA_CAMERA_SUPPORT=y
+CONFIG_VIDEO_STM32_DCMI=y
+CONFIG_VIDEO_OV2640=y
 CONFIG_NEW_LEDS=y
 CONFIG_LEDS_CLASS=y
 CONFIG_LEDS_GPIO=y
-- 
1.9.1



[PATCH v3 1/8] dt-bindings: Document STM32 DCMI bindings

2017-04-04 Thread Hugues Fruchet
This adds documentation of device tree bindings for the STM32 DCMI
(Digital Camera Memory Interface).

Signed-off-by: Hugues Fruchet <hugues.fruc...@st.com>
---
 .../devicetree/bindings/media/st,stm32-dcmi.txt| 46 ++
 1 file changed, 46 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/st,stm32-dcmi.txt

diff --git a/Documentation/devicetree/bindings/media/st,stm32-dcmi.txt 
b/Documentation/devicetree/bindings/media/st,stm32-dcmi.txt
new file mode 100644
index 000..c0f6f4b
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/st,stm32-dcmi.txt
@@ -0,0 +1,46 @@
+STMicroelectronics STM32 Digital Camera Memory Interface (DCMI)
+
+Required properties:
+- compatible: "st,stm32-dcmi"
+- reg: physical base address and length of the registers set for the device
+- interrupts: should contain IRQ line for the DCMI
+- resets: reference to a reset controller,
+  see Documentation/devicetree/bindings/reset/st,stm32-rcc.txt
+- clocks: list of clock specifiers, corresponding to entries in
+  the clock-names property
+- clock-names: must contain "mclk", which is the DCMI peripherial clock
+- pinctrl: the pincontrol settings to configure muxing properly
+   for pins that connect to DCMI device.
+   See Documentation/devicetree/bindings/pinctrl/st,stm32-pinctrl.txt.
+- dmas: phandle to DMA controller node,
+see Documentation/devicetree/bindings/dma/stm32-dma.txt
+- dma-names: must contain "tx", which is the transmit channel from DCMI to DMA
+
+DCMI supports a single port node with parallel bus. It should contain one
+'port' child node with child 'endpoint' node. Please refer to the bindings
+defined in Documentation/devicetree/bindings/media/video-interfaces.txt.
+
+Example:
+
+   dcmi: dcmi@5005 {
+   compatible = "st,stm32-dcmi";
+   reg = <0x5005 0x400>;
+   interrupts = <78>;
+   resets = < STM32F4_AHB2_RESET(DCMI)>;
+   clocks = < 0 STM32F4_AHB2_CLOCK(DCMI)>;
+   clock-names = "mclk";
+   pinctrl-names = "default";
+   pinctrl-0 = <_pins>;
+   dmas = < 1 1 0x414 0x3>;
+   dma-names = "tx";
+   port {
+   dcmi_0: endpoint@0 {
+   remote-endpoint = <...>;
+   bus-width = <8>;
+   hsync-active = <0>;
+   vsync-active = <0>;
+   pclk-sample = <1>;
+   };
+   };
+   };
+
-- 
1.9.1



[PATCH v3 4/8] ARM: dts: stm32: Enable DCMI camera interface on STM32F429-EVAL board

2017-04-04 Thread Hugues Fruchet
Enable DCMI camera interface on STM32F429-EVAL board.

Signed-off-by: Hugues Fruchet <hugues.fruc...@st.com>
---
 arch/arm/boot/dts/stm32429i-eval.dts | 9 +
 1 file changed, 9 insertions(+)

diff --git a/arch/arm/boot/dts/stm32429i-eval.dts 
b/arch/arm/boot/dts/stm32429i-eval.dts
index 3c99466..87733d3 100644
--- a/arch/arm/boot/dts/stm32429i-eval.dts
+++ b/arch/arm/boot/dts/stm32429i-eval.dts
@@ -141,6 +141,15 @@
clock-frequency = <2500>;
 };
 
+ {
+   status = "okay";
+
+   port {
+   dcmi_0: endpoint@0 {
+   };
+   };
+};
+
  {
pinctrl-0 = <_pins>;
pinctrl-names = "default";
-- 
1.9.1



[PATCH v3 0/8] Add support for DCMI camera interface of STMicroelectronics STM32 SoC series

2017-04-04 Thread Hugues Fruchet
This patchset introduces a basic support for Digital Camera Memory Interface
(DCMI) of STMicroelectronics STM32 SoC series.

This first basic support implements RGB565 & YUV frame grabbing.
Cropping and JPEG support will be added later on.

This has been tested on STM324x9I-EVAL evaluation board embedding
an OV2640 camera sensor.

This driver depends on:
  - [PATCHv6 00/14] atmel-isi/ov7670/ov2640: convert to standalone drivers 
http://www.spinics.net/lists/linux-media/msg113480.html

===
= history =
===
version 3:
  - stm32-dcmi: Add "Reviewed-by: Hans Verkuil <hans.verk...@cisco.com>"
  - dt-bindings: Fix remarks from Rob Herring:
http://www.mail-archive.com/linux-media@vger.kernel.org/msg110956.html

version 2:
  - Fix a Kbuild warning in probe:
http://www.mail-archive.com/linux-media@vger.kernel.org/msg110678.html
  - Fix a warning in dcmi_queue_setup()
  - dt-bindings: warn on sensor signals level inversion in board example
  - Typos fixing

version 1:
  - Initial submission

===
= v4l2-compliance =
===
Below is the v4l2-compliance report for this current version of the DCMI camera 
interface.
v4l2-compliance has been built from v4l-utils-1.12.3.

v4l2-compliance SHA   : f5f45e17ee98a0ebad7836ade2b34ceec909d751

Driver Info:
Driver name   : stm32-dcmi
Card type : STM32 Digital Camera Memory Int
Bus info  : platform:dcmi
Driver version: 4.11.0
Capabilities  : 0x8521
Video Capture
Read/Write
Streaming
Extended Pix Format
Device Capabilities
Device Caps   : 0x0521
Video Capture
Read/Write
Streaming
Extended Pix Format

Compliance test for device /dev/video0 (not using libv4l2):

Required ioctls:
test VIDIOC_QUERYCAP: OK

Allow for multiple opens:
test second video open: OK
test VIDIOC_QUERYCAP: OK
test VIDIOC_G/S_PRIORITY: OK
test for unlimited opens: OK

Debug ioctls:
test VIDIOC_DBG_G/S_REGISTER: OK (Not Supported)
test VIDIOC_LOG_STATUS: OK

Input ioctls:
test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported)
test VIDIOC_G/S_FREQUENCY: OK (Not Supported)
test VIDIOC_S_HW_FREQ_SEEK: OK (Not Supported)
test VIDIOC_ENUMAUDIO: OK (Not Supported)
test VIDIOC_G/S/ENUMINPUT: OK
test VIDIOC_G/S_AUDIO: OK (Not Supported)
Inputs: 1 Audio Inputs: 0 Tuners: 0

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

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

Test input 0:

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

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

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

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

Test input 0:

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


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

Hugues Fruchet (8):
  dt-bindings: Document STM32 DCMI bindings
  [media] stm32-dcmi: STM32 DCMI camera interface driver
  ARM: dts: stm32: Enable DCMI support on STM32F429 MCU
  ARM: dts: stm32: Enable DCMI camera interface on STM32F429-EVAL board
  ARM: dts: stm32: Enable STMPE1600 gpio expander of STM32F429-

Re: [PATCH v1] checkpatch: test missing initial blank line in block comment

2017-04-07 Thread Hugues FRUCHET
Hi Joe,

here is the output with the last version of the script: 
https://paste.ubuntu.com/24333124/

Differences are on the macro cases and the //foo \ *bar, no more warned.

BR,
Hugues.

On 04/05/2017 03:26 PM, Hugues Fruchet wrote:
>
>
> On 04/05/2017 11:55 AM, Joe Perches wrote:
>> On Wed, 2017-04-05 at 09:43 +, Hugues FRUCHET wrote:
>>>
>>> On 04/05/2017 10:35 AM, Joe Perches wrote:
>>>> On Wed, 2017-04-05 at 08:23 +, Hugues FRUCHET wrote:
>>>>> Hi Joe, thanks for reviewing,
>>>>
>>>> Hello Hugues
>>>>
>>>>> I have run the command you advice on the entire kernel code, modifying
>>>>> the script to only match the newly introduced check case.
>>>>> There was 14389 hits, quite huge, so I cannot 100% certify that there
>>>>> are no false positives, but I have checked the output carefully and
>>>>> found 2 limit cases:
>>>>>
>>>>> 1) space character placed just after "/*"
>>>>> WARNING: Block comments starts with an empty /*
>>>>> #330: FILE: arch/alpha/kernel/core_irongate.c:330:
>>>>> +/*
>>>>> + * Check for within the AGP aperture...
>>>>> => 146 hits (grep -c -n -E "\/\* $" /tmp/check.txt)
>>>>>
>>>>> 2) // style comment followed by pointer dereference
>>>>> WARNING: Block comments starts with an empty /*
>>>>> #426: FILE: drivers/media/dvb-core/dvb_ca_en50221.c:426:
>>>>> +// success
>>>>> +*tupleType = _tupleType;
>>>>> => 4 hits
>>>>>
>>>>> Anyway this reveal comment style related issues, so I would say
>>>>> that we
>>>>> can keep script as it is, what do you think about ?
>>>>
>>>> Glancing at the output, there is also the comment
>>>> in a multiline macro case:
>>>>
>>>> WARNING: Block comments starts with an empty /*
>>>> #354: FILE: arch/mips/include/asm/processor.h:354:
>>>> +/*\
>>>> + * Other stuff associated with the process\
>>>>
>>>> Dunno how common that is, but maybe the test
>>>> should be changed to avoid those.
>>>>
>>>
>>> Here is a proposal that remove this macro case:Per
>>>
>>> # Missing initial /*
>>> if ($realfile !~ m@^(drivers/net/|net/)@ &&#networking exception
>>>  $prevrawline =~ /^\+[ \t]\/\**.+[ \t]/ &&#start with /*...
>>>  $prevrawline !~ /^\+.*\/\*.*\*\/[ \t]*/ &&#no inline /*...*/
>>> +   $prevrawline !~ /^\+[ \t]\/\*+[ \t]+\\$/ &
<

Re: [PATCH v1] checkpatch: test missing initial blank line in block comment

2017-04-05 Thread Hugues FRUCHET


On 04/05/2017 11:55 AM, Joe Perches wrote:
> On Wed, 2017-04-05 at 09:43 +0000, Hugues FRUCHET wrote:
>>
>> On 04/05/2017 10:35 AM, Joe Perches wrote:
>>> On Wed, 2017-04-05 at 08:23 +, Hugues FRUCHET wrote:
>>>> Hi Joe, thanks for reviewing,
>>>
>>> Hello Hugues
>>>
>>>> I have run the command you advice on the entire kernel code, modifying
>>>> the script to only match the newly introduced check case.
>>>> There was 14389 hits, quite huge, so I cannot 100% certify that there
>>>> are no false positives, but I have checked the output carefully and
>>>> found 2 limit cases:
>>>>
>>>> 1) space character placed just after "/*"
>>>> WARNING: Block comments starts with an empty /*
>>>> #330: FILE: arch/alpha/kernel/core_irongate.c:330:
>>>> +  /*
>>>> +   * Check for within the AGP aperture...
>>>> => 146 hits (grep -c -n -E "\/\* $" /tmp/check.txt)
>>>>
>>>> 2) // style comment followed by pointer dereference
>>>> WARNING: Block comments starts with an empty /*
>>>> #426: FILE: drivers/media/dvb-core/dvb_ca_en50221.c:426:
>>>> +  // success
>>>> +  *tupleType = _tupleType;
>>>> => 4 hits
>>>>
>>>> Anyway this reveal comment style related issues, so I would say that we
>>>> can keep script as it is, what do you think about ?
>>>
>>> Glancing at the output, there is also the comment
>>> in a multiline macro case:
>>>
>>> WARNING: Block comments starts with an empty /*
>>> #354: FILE: arch/mips/include/asm/processor.h:354:
>>> +   /*  \
>>> +* Other stuff associated with the process  \
>>>
>>> Dunno how common that is, but maybe the test
>>> should be changed to avoid those.
>>>
>>
>> Here is a proposal that remove this macro case:Per
>>
>> # Missing initial /*
>> if ($realfile !~ m@^(drivers/net/|net/)@ &&  #networking exception
>>  $prevrawline =~ /^\+[ \t]\/\**.+[ \t]/ &&   #start with /*...
>>  $prevrawline !~ /^\+.*\/\*.*\*\/[ \t]*/ &&  #no inline /*...*/
>> +   $prevrawline !~ /^\+[ \t]\/\*+[ \t]+\\$/ &
<

[PATCH v4 6/8] ARM: dts: stm32: Enable OV2640 camera support of STM32F429-EVAL board

2017-04-20 Thread Hugues Fruchet
Enable OV2640 camera support of STM32F429-EVAL board.

Signed-off-by: Hugues Fruchet <hugues.fruc...@st.com>
---
 arch/arm/boot/dts/stm32429i-eval.dts | 30 ++
 1 file changed, 30 insertions(+)

diff --git a/arch/arm/boot/dts/stm32429i-eval.dts 
b/arch/arm/boot/dts/stm32429i-eval.dts
index 2bb8a0f..95c33b1 100644
--- a/arch/arm/boot/dts/stm32429i-eval.dts
+++ b/arch/arm/boot/dts/stm32429i-eval.dts
@@ -48,6 +48,7 @@
 /dts-v1/;
 #include "stm32f429.dtsi"
 #include 
+#include 
 
 / {
model = "STMicroelectronics STM32429i-EVAL board";
@@ -66,6 +67,14 @@
serial0 = 
};
 
+   clocks {
+   clk_ext_camera: clk-ext-camera {
+   #clock-cells = <0>;
+   compatible = "fixed-clock";
+   clock-frequency = <2400>;
+   };
+   };
+
soc {
dma-ranges = <0xc000 0x0 0x1000>;
};
@@ -146,6 +155,11 @@
 
port {
dcmi_0: endpoint {
+   remote-endpoint = <_0>;
+   bus-width = <8>;
+   hsync-active = <0>;
+   vsync-active = <0>;
+   pclk-sample = <1>;
};
};
 };
@@ -155,6 +169,22 @@
pinctrl-names = "default";
status = "okay";
 
+   ov2640: camera@30 {
+   compatible = "ovti,ov2640";
+   reg = <0x30>;
+   resetb-gpios = < 2 GPIO_ACTIVE_HIGH>;
+   pwdn-gpios = < 0 GPIO_ACTIVE_LOW>;
+   clocks = <_ext_camera>;
+   clock-names = "xvclk";
+   status = "okay";
+
+   port {
+   ov2640_0: endpoint {
+   remote-endpoint = <_0>;
+   };
+   };
+   };
+
stmpe1600: stmpe1600@42 {
compatible = "st,stmpe1600";
reg = <0x42>;
-- 
1.9.1



[PATCH v4 1/8] dt-bindings: Document STM32 DCMI bindings

2017-04-20 Thread Hugues Fruchet
This adds documentation of device tree bindings for the STM32 DCMI
(Digital Camera Memory Interface).

Acked-by: Rob Herring <r...@kernel.org>
Signed-off-by: Hugues Fruchet <hugues.fruc...@st.com>
---
 .../devicetree/bindings/media/st,stm32-dcmi.txt| 46 ++
 1 file changed, 46 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/st,stm32-dcmi.txt

diff --git a/Documentation/devicetree/bindings/media/st,stm32-dcmi.txt 
b/Documentation/devicetree/bindings/media/st,stm32-dcmi.txt
new file mode 100644
index 000..f8baf65
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/st,stm32-dcmi.txt
@@ -0,0 +1,46 @@
+STMicroelectronics STM32 Digital Camera Memory Interface (DCMI)
+
+Required properties:
+- compatible: "st,stm32-dcmi"
+- reg: physical base address and length of the registers set for the device
+- interrupts: should contain IRQ line for the DCMI
+- resets: reference to a reset controller,
+  see Documentation/devicetree/bindings/reset/st,stm32-rcc.txt
+- clocks: list of clock specifiers, corresponding to entries in
+  the clock-names property
+- clock-names: must contain "mclk", which is the DCMI peripherial clock
+- pinctrl: the pincontrol settings to configure muxing properly
+   for pins that connect to DCMI device.
+   See Documentation/devicetree/bindings/pinctrl/st,stm32-pinctrl.txt.
+- dmas: phandle to DMA controller node,
+see Documentation/devicetree/bindings/dma/stm32-dma.txt
+- dma-names: must contain "tx", which is the transmit channel from DCMI to DMA
+
+DCMI supports a single port node with parallel bus. It should contain one
+'port' child node with child 'endpoint' node. Please refer to the bindings
+defined in Documentation/devicetree/bindings/media/video-interfaces.txt.
+
+Example:
+
+   dcmi: dcmi@5005 {
+   compatible = "st,stm32-dcmi";
+   reg = <0x5005 0x400>;
+   interrupts = <78>;
+   resets = < STM32F4_AHB2_RESET(DCMI)>;
+   clocks = < 0 STM32F4_AHB2_CLOCK(DCMI)>;
+   clock-names = "mclk";
+   pinctrl-names = "default";
+   pinctrl-0 = <_pins>;
+   dmas = < 1 1 0x414 0x3>;
+   dma-names = "tx";
+   port {
+   dcmi_0: endpoint {
+   remote-endpoint = <...>;
+   bus-width = <8>;
+   hsync-active = <0>;
+   vsync-active = <0>;
+   pclk-sample = <1>;
+   };
+   };
+   };
+
-- 
1.9.1



[PATCH v4 7/8] ARM: configs: stm32: STMPE1600 GPIO expander

2017-04-20 Thread Hugues Fruchet
Enable STMPE1600 GPIO expander.

Signed-off-by: Hugues Fruchet <hugues.fruc...@st.com>
---
 arch/arm/configs/stm32_defconfig | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/arm/configs/stm32_defconfig b/arch/arm/configs/stm32_defconfig
index a9d8e3c..84adc88 100644
--- a/arch/arm/configs/stm32_defconfig
+++ b/arch/arm/configs/stm32_defconfig
@@ -49,6 +49,8 @@ CONFIG_SERIAL_STM32_CONSOLE=y
 # CONFIG_HW_RANDOM is not set
 # CONFIG_HWMON is not set
 CONFIG_REGULATOR=y
+CONFIG_GPIO_STMPE=y
+CONFIG_MFD_STMPE=y
 CONFIG_REGULATOR_FIXED_VOLTAGE=y
 # CONFIG_USB_SUPPORT is not set
 CONFIG_NEW_LEDS=y
-- 
1.9.1



[PATCH v4 2/8] [media] stm32-dcmi: STM32 DCMI camera interface driver

2017-04-20 Thread Hugues Fruchet
This V4L2 subdev driver enables Digital Camera Memory Interface (DCMI)
of STMicroelectronics STM32 SoC series.

Reviewed-by: Hans Verkuil <hans.verk...@cisco.com>
Signed-off-by: Yannick Fertre <yannick.fer...@st.com>
Signed-off-by: Hugues Fruchet <hugues.fruc...@st.com>
---
 drivers/media/platform/Kconfig|   12 +
 drivers/media/platform/Makefile   |2 +
 drivers/media/platform/stm32/Makefile |1 +
 drivers/media/platform/stm32/stm32-dcmi.c | 1419 +
 4 files changed, 1434 insertions(+)
 create mode 100644 drivers/media/platform/stm32/Makefile
 create mode 100644 drivers/media/platform/stm32/stm32-dcmi.c

diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig
index ac026ee..de6e18b 100644
--- a/drivers/media/platform/Kconfig
+++ b/drivers/media/platform/Kconfig
@@ -114,6 +114,18 @@ config VIDEO_S3C_CAMIF
  To compile this driver as a module, choose M here: the module
  will be called s3c-camif.
 
+config VIDEO_STM32_DCMI
+   tristate "Digital Camera Memory Interface (DCMI) support"
+   depends on VIDEO_V4L2 && OF && HAS_DMA
+   depends on ARCH_STM32 || COMPILE_TEST
+   select VIDEOBUF2_DMA_CONTIG
+   ---help---
+ This module makes the STM32 Digital Camera Memory Interface (DCMI)
+ available as a v4l2 device.
+
+ To compile this driver as a module, choose M here: the module
+ will be called stm32-dcmi.
+
 source "drivers/media/platform/soc_camera/Kconfig"
 source "drivers/media/platform/exynos4-is/Kconfig"
 source "drivers/media/platform/am437x/Kconfig"
diff --git a/drivers/media/platform/Makefile b/drivers/media/platform/Makefile
index 63303d6..231f3c2 100644
--- a/drivers/media/platform/Makefile
+++ b/drivers/media/platform/Makefile
@@ -68,6 +68,8 @@ obj-$(CONFIG_VIDEO_RCAR_VIN)  += rcar-vin/
 obj-$(CONFIG_VIDEO_ATMEL_ISC)  += atmel/
 obj-$(CONFIG_VIDEO_ATMEL_ISI)  += atmel/
 
+obj-$(CONFIG_VIDEO_STM32_DCMI) += stm32/
+
 ccflags-y += -I$(srctree)/drivers/media/i2c
 
 obj-$(CONFIG_VIDEO_MEDIATEK_VPU)   += mtk-vpu/
diff --git a/drivers/media/platform/stm32/Makefile 
b/drivers/media/platform/stm32/Makefile
new file mode 100644
index 000..9b606a7
--- /dev/null
+++ b/drivers/media/platform/stm32/Makefile
@@ -0,0 +1 @@
+obj-$(CONFIG_VIDEO_STM32_DCMI) += stm32-dcmi.o
diff --git a/drivers/media/platform/stm32/stm32-dcmi.c 
b/drivers/media/platform/stm32/stm32-dcmi.c
new file mode 100644
index 000..0ed3bd9
--- /dev/null
+++ b/drivers/media/platform/stm32/stm32-dcmi.c
@@ -0,0 +1,1419 @@
+/*
+ * Driver for STM32 Digital Camera Memory Interface
+ *
+ * Copyright (C) STMicroelectronics SA 2017
+ * Authors: Yannick Fertre <yannick.fer...@st.com>
+ *  Hugues Fruchet <hugues.fruc...@st.com>
+ *  for STMicroelectronics.
+ * License terms:  GNU General Public License (GPL), version 2
+ *
+ * This driver is based on atmel_isi.c
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define DRV_NAME "stm32-dcmi"
+
+/* Registers offset for DCMI */
+#define DCMI_CR0x00 /* Control Register */
+#define DCMI_SR0x04 /* Status Register */
+#define DCMI_RIS   0x08 /* Raw Interrupt Status register */
+#define DCMI_IER   0x0C /* Interrupt Enable Register */
+#define DCMI_MIS   0x10 /* Masked Interrupt Status register */
+#define DCMI_ICR   0x14 /* Interrupt Clear Register */
+#define DCMI_ESCR  0x18 /* Embedded Synchronization Code Register */
+#define DCMI_ESUR  0x1C /* Embedded Synchronization Unmask Register */
+#define DCMI_CWSTRT0x20 /* Crop Window STaRT */
+#define DCMI_CWSIZE0x24 /* Crop Window SIZE */
+#define DCMI_DR0x28 /* Data Register */
+#define DCMI_IDR   0x2C /* IDentifier Register */
+
+/* Bits definition for control register (DCMI_CR) */
+#define CR_CAPTURE BIT(0)
+#define CR_CM  BIT(1)
+#define CR_CROPBIT(2)
+#define CR_JPEGBIT(3)
+#define CR_ESS BIT(4)
+#define CR_PCKPOL  BIT(5)
+#define CR_HSPOL   BIT(6)
+#define CR_VSPOL   BIT(7)
+#define CR_FCRC_0  BIT(8)
+#define CR_FCRC_1  BIT(9)
+#define CR_EDM_0   BIT(10)
+#define CR_EDM_1   BIT(11)
+#define CR_ENABLE  BIT(14)
+
+/* Bits definition for status register (DCMI_SR) */
+#define SR_HSYNC   BIT(0)
+#define SR_VSYNC   BIT(1)
+#define SR_FNE BIT(2)
+
+/*
+ * Bits definition for interrupt registers
+ * (DCMI_RIS, DCMI_IER, DCMI_MIS, DCMI_ICR)
+ */
+#define IT_FRAME   BIT(0)
+#define IT_OVR BIT(1)
+#define IT_ERR BIT(2)
+#define IT_VSYNC   BIT(3)
+#define IT_LINE 

[PATCH v4 0/8] Add support for DCMI camera interface of STMicroelectronics STM32 SoC series

2017-04-20 Thread Hugues Fruchet
t DMABUF: Cannot test, specify --expbuf-device

Stream using all formats:
test MMAP for Format YUYV, Frame Size 176x144:
Stride 352, Field None: OK  
test MMAP for Format YUYV, Frame Size 320x240:
Stride 640, Field None: OK  
test MMAP for Format UYVY, Frame Size 176x144:
Stride 352, Field None: OK  
test MMAP for Format UYVY, Frame Size 320x240:
Stride 640, Field None: OK  
test MMAP for Format RGBP, Frame Size 176x144:
Stride 352, Field None: OK  
test MMAP for Format RGBP, Frame Size 320x240:
Stride 640, Field None: OK  

Total: 52, Succeeded: 52, Failed: 0, Warnings: 0

Hugues Fruchet (8):
  dt-bindings: Document STM32 DCMI bindings
  [media] stm32-dcmi: STM32 DCMI camera interface driver
  ARM: dts: stm32: Enable DCMI support on STM32F429 MCU
  ARM: dts: stm32: Enable DCMI camera interface on STM32F429-EVAL board
  ARM: dts: stm32: Enable STMPE1600 gpio expander of STM32F429-EVAL
board
  ARM: dts: stm32: Enable OV2640 camera support of STM32F429-EVAL board
  ARM: configs: stm32: STMPE1600 GPIO expander
  ARM: configs: stm32: DCMI + OV2640 camera support

 .../devicetree/bindings/media/st,stm32-dcmi.txt|   46 +
 arch/arm/boot/dts/stm32429i-eval.dts   |   56 +
 arch/arm/boot/dts/stm32f429.dtsi   |   37 +
 arch/arm/configs/stm32_defconfig   |9 +
 drivers/media/platform/Kconfig |   12 +
 drivers/media/platform/Makefile|2 +
 drivers/media/platform/stm32/Makefile  |1 +
 drivers/media/platform/stm32/stm32-dcmi.c  | 1419 
 8 files changed, 1582 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/st,stm32-dcmi.txt
 create mode 100644 drivers/media/platform/stm32/Makefile
 create mode 100644 drivers/media/platform/stm32/stm32-dcmi.c

-- 
1.9.1



[PATCH v4 3/8] ARM: dts: stm32: Enable DCMI support on STM32F429 MCU

2017-04-20 Thread Hugues Fruchet
Enable DCMI camera interface on STM32F429 MCU.

Signed-off-by: Hugues Fruchet <hugues.fruc...@st.com>
---
 arch/arm/boot/dts/stm32f429.dtsi | 37 +
 1 file changed, 37 insertions(+)

diff --git a/arch/arm/boot/dts/stm32f429.dtsi b/arch/arm/boot/dts/stm32f429.dtsi
index ee0da97..e1ff978 100644
--- a/arch/arm/boot/dts/stm32f429.dtsi
+++ b/arch/arm/boot/dts/stm32f429.dtsi
@@ -736,6 +736,29 @@
slew-rate = <3>;
};
};
+
+   dcmi_pins: dcmi_pins@0 {
+   pins {
+   pinmux = 
,
+
,
+
,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+,
+;
+   bias-disable;
+   drive-push-pull;
+   slew-rate = <3>;
+   };
+   };
};
 
rcc: rcc@40023810 {
@@ -805,6 +828,20 @@
status = "disabled";
};
 
+   dcmi: dcmi@5005 {
+   compatible = "st,stm32-dcmi";
+   reg = <0x5005 0x400>;
+   interrupts = <78>;
+   resets = < STM32F4_AHB2_RESET(DCMI)>;
+   clocks = < 0 STM32F4_AHB2_CLOCK(DCMI)>;
+   clock-names = "mclk";
+   pinctrl-names = "default";
+   pinctrl-0 = <_pins>;
+   dmas = < 1 1 0x414 0x3>;
+   dma-names = "tx";
+   status = "disabled";
+   };
+
rng: rng@50060800 {
compatible = "st,stm32-rng";
reg = <0x50060800 0x400>;
-- 
1.9.1



[PATCH v4 5/8] ARM: dts: stm32: Enable STMPE1600 gpio expander of STM32F429-EVAL board

2017-04-20 Thread Hugues Fruchet
Enable STMPE1600 gpio expander of STM32F429-EVAL board.

Signed-off-by: Hugues Fruchet <hugues.fruc...@st.com>
---
 arch/arm/boot/dts/stm32429i-eval.dts | 17 +
 1 file changed, 17 insertions(+)

diff --git a/arch/arm/boot/dts/stm32429i-eval.dts 
b/arch/arm/boot/dts/stm32429i-eval.dts
index 617f2f7..2bb8a0f 100644
--- a/arch/arm/boot/dts/stm32429i-eval.dts
+++ b/arch/arm/boot/dts/stm32429i-eval.dts
@@ -154,6 +154,23 @@
pinctrl-0 = <_pins>;
pinctrl-names = "default";
status = "okay";
+
+   stmpe1600: stmpe1600@42 {
+   compatible = "st,stmpe1600";
+   reg = <0x42>;
+   irq-gpio = < 8 0>;
+   irq-trigger = <3>;
+   interrupts = <8 3>;
+   interrupt-parent = <>;
+   interrupt-controller;
+   wakeup-source;
+
+   stmpegpio: stmpe_gpio {
+   compatible = "st,stmpe-gpio";
+   gpio-controller;
+   #gpio-cells = <2>;
+   };
+   };
 };
 
  {
-- 
1.9.1



[PATCH v4 4/8] ARM: dts: stm32: Enable DCMI camera interface on STM32F429-EVAL board

2017-04-20 Thread Hugues Fruchet
Enable DCMI camera interface on STM32F429-EVAL board.

Signed-off-by: Hugues Fruchet <hugues.fruc...@st.com>
---
 arch/arm/boot/dts/stm32429i-eval.dts | 9 +
 1 file changed, 9 insertions(+)

diff --git a/arch/arm/boot/dts/stm32429i-eval.dts 
b/arch/arm/boot/dts/stm32429i-eval.dts
index 3c99466..617f2f7 100644
--- a/arch/arm/boot/dts/stm32429i-eval.dts
+++ b/arch/arm/boot/dts/stm32429i-eval.dts
@@ -141,6 +141,15 @@
clock-frequency = <2500>;
 };
 
+ {
+   status = "okay";
+
+   port {
+   dcmi_0: endpoint {
+   };
+   };
+};
+
  {
pinctrl-0 = <_pins>;
pinctrl-names = "default";
-- 
1.9.1



[PATCH v4 8/8] ARM: configs: stm32: DCMI + OV2640 camera support

2017-04-20 Thread Hugues Fruchet
Enable DCMI camera interface and OV2640 camera sensor drivers.

Signed-off-by: Hugues Fruchet <hugues.fruc...@st.com>
---
 arch/arm/configs/stm32_defconfig | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/arch/arm/configs/stm32_defconfig b/arch/arm/configs/stm32_defconfig
index 84adc88..3f2e4ce 100644
--- a/arch/arm/configs/stm32_defconfig
+++ b/arch/arm/configs/stm32_defconfig
@@ -53,6 +53,13 @@ CONFIG_GPIO_STMPE=y
 CONFIG_MFD_STMPE=y
 CONFIG_REGULATOR_FIXED_VOLTAGE=y
 # CONFIG_USB_SUPPORT is not set
+CONFIG_VIDEO_V4L2=y
+CONFIG_MEDIA_SUBDRV_AUTOSELECT=n
+CONFIG_V4L_PLATFORM_DRIVERS=y
+CONFIG_MEDIA_SUPPORT=y
+CONFIG_MEDIA_CAMERA_SUPPORT=y
+CONFIG_VIDEO_STM32_DCMI=y
+CONFIG_VIDEO_OV2640=y
 CONFIG_NEW_LEDS=y
 CONFIG_LEDS_CLASS=y
 CONFIG_LEDS_GPIO=y
-- 
1.9.1



Re: [PATCH v3 0/8] Add support for DCMI camera interface of STMicroelectronics STM32 SoC series

2017-04-20 Thread Hugues FRUCHET
Hi Hans,

v4 has been sent with "v4l2-compliance -s -f" report provided in cover 
letter. Bindings acked by Rob.

http://www.mail-archive.com/linux-media@vger.kernel.org/msg111743.html

BR,
Hugues.

On 04/10/2017 10:55 AM, Hans Verkuil wrote:
> On 04/04/2017 05:44 PM, Hugues Fruchet wrote:
>> This patchset introduces a basic support for Digital Camera Memory Interface
>> (DCMI) of STMicroelectronics STM32 SoC series.
>>
>> This first basic support implements RGB565 & YUV frame grabbing.
>> Cropping and JPEG support will be added later on.
>>
>> This has been tested on STM324x9I-EVAL evaluation board embedding
>> an OV2640 camera sensor.
>>
>> This driver depends on:
>>   - [PATCHv6 00/14] atmel-isi/ov7670/ov2640: convert to standalone drivers 
>> http://www.spinics.net/lists/linux-media/msg113480.html
>>
>> ===
>> = history =
>> ===
>> version 3:
>>   - stm32-dcmi: Add "Reviewed-by: Hans Verkuil <hans.verk...@cisco.com>"
>>   - dt-bindings: Fix remarks from Rob Herring:
>> http://www.mail-archive.com/linux-media@vger.kernel.org/msg110956.html
>>
>> version 2:
>>   - Fix a Kbuild warning in probe:
>> http://www.mail-archive.com/linux-media@vger.kernel.org/msg110678.html
>>   - Fix a warning in dcmi_queue_setup()
>>   - dt-bindings: warn on sensor signals level inversion in board example
>>   - Typos fixing
>>
>> version 1:
>>   - Initial submission
>>
>> ===
>> = v4l2-compliance =
>> ===
>> Below is the v4l2-compliance report for this current version of the DCMI 
>> camera interface.
>> v4l2-compliance has been built from v4l-utils-1.12.3.
>
> Please test with 'v4l2-compliance -s -f' as well and mail me the output of
> that test.
>
> Once you have the Acks for the DT/bindings patches just let me know and I'll
> make a pull request.
>
> Regards,
>
>   Hans
>
>>
>> v4l2-compliance SHA   : f5f45e17ee98a0ebad7836ade2b34ceec909d751
>>
>> Driver Info:
>> Driver name   : stm32-dcmi
>> Card type : STM32 Digital Camera Memory Int
>> Bus info  : platform:dcmi
>> Driver version: 4.11.0
>> Capabilities  : 0x8521
>> Video Capture
>> Read/Write
>> Streaming
>> Extended Pix Format
>> Device Capabilities
>> Device Caps   : 0x0521
>> Video Capture
>> Read/Write
>> Streaming
>> Extended Pix Format
>>
>> Compliance test for device /dev/video0 (not using libv4l2):
>>
>> Required ioctls:
>> test VIDIOC_QUERYCAP: OK
>>
>> Allow for multiple opens:
>> test second video open: OK
>> test VIDIOC_QUERYCAP: OK
>> test VIDIOC_G/S_PRIORITY: OK
>> test for unlimited opens: OK
>>
>> Debug ioctls:
>> test VIDIOC_DBG_G/S_REGISTER: OK (Not Supported)
>> test VIDIOC_LOG_STATUS: OK
>>
>> Input ioctls:
>> test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported)
>> test VIDIOC_G/S_FREQUENCY: OK (Not Supported)
>> test VIDIOC_S_HW_FREQ_SEEK: OK (Not Supported)
>> test VIDIOC_ENUMAUDIO: OK (Not Supported)
>> test VIDIOC_G/S/ENUMINPUT: OK
>> test VIDIOC_G/S_AUDIO: OK (Not Supported)
>> Inputs: 1 Audio Inputs: 0 Tuners: 0
>>
>> Output ioctls:
>> test VIDIOC_G/S_MODULATOR: OK (Not Supported)
>> test VIDIOC_G/S_FREQUENCY: OK (Not Supported)
>> test VIDIOC_ENUMAUDOUT: OK (Not Supported)
>> test VIDIOC_G/S/ENUMOUTPUT: OK (Not Supported)
>> test VIDIOC_G/S_AUDOUT: OK (Not Supported)
>> Outputs: 0 Audio Outputs: 0 Modulators: 0
>>
>> Input/Output configuration ioctls:
>> test VIDIOC_ENUM/G/S/QUERY_STD: OK (Not Supported)
>> test VIDIOC_ENUM/G/S/QUERY_DV_TIMINGS: OK (Not Supported)
>> test VIDIOC_DV_TIMINGS_CAP: OK (Not Supported)
>> test VIDIOC_G/S_EDID: OK (Not Supported)
>>
>> Test input 0:
>>
>> Control ioctls:
>> test VIDIOC_QUERY_EXT_CTRL/QUERYMENU: OK
>> test VIDIOC_QUERYCTRL: OK
>> test VIDIOC_G/S_CTRL: OK
>> test VIDIOC_G/S/TRY_EXT_CTRLS: OK
>> test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: OK
>> test VIDIOC_G/S_JPE

Re: [PATCH] st-delta: constify vb2_ops structures

2017-07-07 Thread Hugues FRUCHET
Acked-by: Hugues Fruchet <hugues.fruc...@st.com>

On 07/06/2017 10:14 PM, Gustavo A. R. Silva wrote:
> Check for vb2_ops structures that are only stored in the ops field of a
> vb2_queue structure. That field is declared const, so vb2_ops structures
> that have this property can be declared as const also.
> 
> This issue was detected using Coccinelle and the following semantic patch:
> 
> @r disable optional_qualifier@
> identifier i;
> position p;
> @@
> static struct vb2_ops i@p = { ... };
> 
> @ok@
> identifier r.i;
> struct vb2_queue e;
> position p;
> @@
> e.ops = @p;
> 
> @bad@
> position p != {r.p,ok.p};
> identifier r.i;
> struct vb2_ops e;
> @@
> e@i@p
> 
> @depends on !bad disable optional_qualifier@
> identifier r.i;
> @@
> static
> +const
> struct vb2_ops i = { ... };
> 
> Signed-off-by: Gustavo A. R. Silva <garsi...@embeddedor.com>
> ---
>   drivers/media/platform/sti/delta/delta-v4l2.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/media/platform/sti/delta/delta-v4l2.c 
> b/drivers/media/platform/sti/delta/delta-v4l2.c
> index c6f2e24..ff9850e 100644
> --- a/drivers/media/platform/sti/delta/delta-v4l2.c
> +++ b/drivers/media/platform/sti/delta/delta-v4l2.c
> @@ -1574,7 +1574,7 @@ static void delta_vb2_frame_stop_streaming(struct 
> vb2_queue *q)
>   }
>   
>   /* VB2 queue ops */
> -static struct vb2_ops delta_vb2_au_ops = {
> +static const struct vb2_ops delta_vb2_au_ops = {
>   .queue_setup = delta_vb2_au_queue_setup,
>   .buf_prepare = delta_vb2_au_prepare,
>   .buf_queue = delta_vb2_au_queue,
> @@ -1584,7 +1584,7 @@ static struct vb2_ops delta_vb2_au_ops = {
>   .stop_streaming = delta_vb2_au_stop_streaming,
>   };
>   
> -static struct vb2_ops delta_vb2_frame_ops = {
> +static const struct vb2_ops delta_vb2_frame_ops = {
>   .queue_setup = delta_vb2_frame_queue_setup,
>   .buf_prepare = delta_vb2_frame_prepare,
>   .buf_finish = delta_vb2_frame_finish,
> 

Re: [PATCH] stm32-dcmi: constify vb2_ops structure

2017-07-07 Thread Hugues FRUCHET
Acked-by: Hugues Fruchet <hugues.fruc...@st.com>

On 07/06/2017 10:05 PM, Gustavo A. R. Silva wrote:
> Check for vb2_ops structures that are only stored in the ops field of a
> vb2_queue structure. That field is declared const, so vb2_ops structures
> that have this property can be declared as const also.
> 
> This issue was detected using Coccinelle and the following semantic patch:
> 
> @r disable optional_qualifier@
> identifier i;
> position p;
> @@
> static struct vb2_ops i@p = { ... };
> 
> @ok@
> identifier r.i;
> struct vb2_queue e;
> position p;
> @@
> e.ops = @p;
> 
> @bad@
> position p != {r.p,ok.p};
> identifier r.i;
> struct vb2_ops e;
> @@
> e@i@p
> 
> @depends on !bad disable optional_qualifier@
> identifier r.i;
> @@
> static
> +const
> struct vb2_ops i = { ... };
> 
> Signed-off-by: Gustavo A. R. Silva <garsi...@embeddedor.com>
> ---
>   drivers/media/platform/stm32/stm32-dcmi.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/media/platform/stm32/stm32-dcmi.c 
> b/drivers/media/platform/stm32/stm32-dcmi.c
> index 83d32a5..24ef888 100644
> --- a/drivers/media/platform/stm32/stm32-dcmi.c
> +++ b/drivers/media/platform/stm32/stm32-dcmi.c
> @@ -662,7 +662,7 @@ static void dcmi_stop_streaming(struct vb2_queue *vq)
>   dcmi->errors_count, dcmi->buffers_count);
>   }
>   
> -static struct vb2_ops dcmi_video_qops = {
> +static const struct vb2_ops dcmi_video_qops = {
>   .queue_setup= dcmi_queue_setup,
>   .buf_init   = dcmi_buf_init,
>   .buf_prepare= dcmi_buf_prepare,
> 

Re: [PATCH v2 0/7] [PATCH v2 0/7] Add support of OV9655 camera

2017-07-18 Thread Hugues FRUCHET


On 07/18/2017 02:17 PM, H. Nikolaus Schaller wrote:
> Hi,
> 
>> Am 18.07.2017 um 13:59 schrieb Hans Verkuil <hverk...@xs4all.nl>:
>>
>> On 12/07/17 22:01, Sylwester Nawrocki wrote:
>>> Hi Hugues,
>>>
>>> On 07/03/2017 11:16 AM, Hugues Fruchet wrote:
>>>> This patchset enables OV9655 camera support.
>>>>
>>>> OV9655 support has been tested using STM32F4DIS-CAM extension board
>>>> plugged on connector P1 of STM32F746G-DISCO board.
>>>> Due to lack of OV9650/52 hardware support, the modified related code
>>>> could not have been checked for non-regression.
>>>>
>>>> First patches upgrade current support of OV9650/52 to prepare then
>>>> introduction of OV9655 variant patch.
>>>> Because of OV9655 register set slightly different from OV9650/9652,
>>>> not all of the driver features are supported (controls). Supported
>>>> resolutions are limited to VGA, QVGA, QQVGA.
>>>> Supported format is limited to RGB565.
>>>> Controls are limited to color bar test pattern for test purpose.
>>>
>>> I appreciate your efforts towards making a common driver but IMO it would be
>>> better to create a separate driver for the OV9655 sensor.  The original 
>>> driver
>>> is 1576 lines of code, your patch set adds half of that (816).  There are
>>> significant differences in the feature set of both sensors, there are
>>> differences in the register layout.  I would go for a separate driver, we
>>> would then have code easier to follow and wouldn't need to worry about 
>>> possible
>>> regressions.  I'm afraid I have lost the camera module and won't be able
>>> to test the patch set against regressions.
>>>
>>> IMHO from maintenance POV it's better to make a separate driver. In the end
>>> of the day we wouldn't be adding much more code than it is being done now.
>>
>> I agree. We do not have great experiences in the past with trying to support
>> multiple variants in a single driver (unless the diffs are truly small).
> 
> Well,
> IMHO the diffs in ov965x are smaller (but untestable because nobody seems
> to have an ov9650/52 board) than within the bq27xxx chips, but I can dig out
> an old pdata based separate ov9655 driver and extend that to become DT 
> compatible.
> 
> I had abandoned that separate approach in favour of extending the ov965x 
> driver.
> 
> Have to discuss with Hugues how to proceed.
> 
> BR and thanks,
> Nikolaus
> 

As Sylwester and Hans, I'm also in flavour of a separate driver, the 
fact that register set seems similar but in fact is not and that we 
cannot test for non-regression of 9650/52 are killer for me to continue 
on a single driver.
We can now restart from a new fresh state of the art sensor driver 
getting rid of legacy (pdata, old gpio, etc...).

BR,
Hugues.

Re: [PATCH v2 3/7] [media] ov9650: add device tree support

2017-07-18 Thread Hugues FRUCHET
Hi Sakari, thks for review.

On 07/09/2017 01:06 AM, Sakari Ailus wrote:
> Hi Hugues,
> 
> On Mon, Jul 03, 2017 at 11:16:04AM +0200, Hugues Fruchet wrote:
>> Allows use of device tree configuration data.
>> If no device tree data is there, configuration is taken from platform data.
>> In order to keep GPIOs configuration compatible between both way of doing,
>> GPIOs are switched to descriptor-based interface.
>>
>> Signed-off-by: H. Nikolaus Schaller <h...@goldelico.com>
>> Signed-off-by: Hugues Fruchet <hugues.fruc...@st.com>
>> ---
>>   drivers/media/i2c/Kconfig  |  2 +-
>>   drivers/media/i2c/ov9650.c | 77 
>> ++
>>   2 files changed, 59 insertions(+), 20 deletions(-)
>>
>> diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
>> index 121b3b5..168115c 100644
>> --- a/drivers/media/i2c/Kconfig
>> +++ b/drivers/media/i2c/Kconfig
>> @@ -615,7 +615,7 @@ config VIDEO_OV7670
>>   
>>   config VIDEO_OV9650
>>  tristate "OmniVision OV9650/OV9652 sensor support"
>> -depends on I2C && VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API
>> +depends on GPIOLIB && I2C && VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API
>>  ---help---
>>This is a V4L2 sensor-level driver for the Omnivision
>>OV9650 and OV9652 camera sensors.
>> diff --git a/drivers/media/i2c/ov9650.c b/drivers/media/i2c/ov9650.c
>> index 1e4e99e..7e9a902 100644
>> --- a/drivers/media/i2c/ov9650.c
>> +++ b/drivers/media/i2c/ov9650.c
>> @@ -11,12 +11,14 @@
>>* 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 
>> @@ -249,9 +251,10 @@ struct ov965x {
>>  struct v4l2_subdev sd;
>>  struct media_pad pad;
>>  enum v4l2_mbus_type bus_type;
>> -int gpios[NUM_GPIOS];
>> +struct gpio_desc *gpios[NUM_GPIOS];
>>  /* External master clock frequency */
>>  unsigned long mclk_frequency;
>> +struct clk *clk;
>>   
>>  /* Protects the struct fields below */
>>  struct mutex lock;
>> @@ -511,10 +514,10 @@ static int ov965x_set_color_matrix(struct ov965x 
>> *ov965x)
>>  return 0;
>>   }
>>   
>> -static void ov965x_gpio_set(int gpio, int val)
>> +static void ov965x_gpio_set(struct gpio_desc *gpio, int val)
>>   {
>> -if (gpio_is_valid(gpio))
>> -gpio_set_value(gpio, val);
>> +if (gpio)
>> +gpiod_set_value_cansleep(gpio, val);
> 
> gpiod_set_value_cansleep() can manage with NULL gpio parameter, no need to
> check it.

done

> 
>>   }
>>   
>>   static void __ov965x_set_power(struct ov965x *ov965x, int on)
>> @@ -1406,24 +1409,28 @@ static int ov965x_configure_gpios(struct ov965x 
>> *ov965x,
>>const struct ov9650_platform_data *pdata)
>>   {
>>  int ret, i;
>> +int gpios[NUM_GPIOS];
>>   
>> -ov965x->gpios[GPIO_PWDN] = pdata->gpio_pwdn;
>> -ov965x->gpios[GPIO_RST]  = pdata->gpio_reset;
>> +gpios[GPIO_PWDN] = pdata->gpio_pwdn;
>> +gpios[GPIO_RST]  = pdata->gpio_reset;
>>   
>> -for (i = 0; i < ARRAY_SIZE(ov965x->gpios); i++) {
>> -int gpio = ov965x->gpios[i];
>> +for (i = 0; i < ARRAY_SIZE(gpios); i++) {
>> +int gpio = gpios[i];
>>   
>>  if (!gpio_is_valid(gpio))
>>  continue;
>>  ret = devm_gpio_request_one(>client->dev, gpio,
>> -GPIOF_OUT_INIT_HIGH, "OV965X");
>> -if (ret < 0)
>> +GPIOF_OUT_INIT_HIGH, DRIVER_NAME);
> 
> DRIVER_NAME is different from "OV965X". Is this an intended change?

Yes it was to unify namings around a single DRIVER_NAME definition.

> 
>> +if (ret < 0) {
>> +dev_err(>client->dev,
>> +"Failed to request gpio%d (%d)\n", gpio, ret);
>>  return ret;
>> +}
>>  v4l2_dbg(1, debug, >sd, "set gpio %d to 1\n", gpio);
>>   
>>  gpio_set_value(gpio, 1);
&g

Re: [PATCH v2 0/7] Add support of OV9655 camera

2017-07-20 Thread Hugues FRUCHET


On 07/20/2017 10:37 AM, H. Nikolaus Schaller wrote:
> Hi,
> 
>> Am 18.07.2017 um 21:52 schrieb Sakari Ailus <sakari.ai...@iki.fi>:
>>
>> On Tue, Jul 18, 2017 at 12:53:12PM +, Hugues FRUCHET wrote:
>>>
>>>
>>> On 07/18/2017 02:17 PM, H. Nikolaus Schaller wrote:
>>>> Hi,
>>>>
>>>>> Am 18.07.2017 um 13:59 schrieb Hans Verkuil <hverk...@xs4all.nl>:
>>>>>
>>>>> On 12/07/17 22:01, Sylwester Nawrocki wrote:
>>>>>> Hi Hugues,
>>>>>>
>>>>>> On 07/03/2017 11:16 AM, Hugues Fruchet wrote:
>>>>>>> This patchset enables OV9655 camera support.
>>>>>>>
>>>>>>> OV9655 support has been tested using STM32F4DIS-CAM extension board
>>>>>>> plugged on connector P1 of STM32F746G-DISCO board.
>>>>>>> Due to lack of OV9650/52 hardware support, the modified related code
>>>>>>> could not have been checked for non-regression.
>>>>>>>
>>>>>>> First patches upgrade current support of OV9650/52 to prepare then
>>>>>>> introduction of OV9655 variant patch.
>>>>>>> Because of OV9655 register set slightly different from OV9650/9652,
>>>>>>> not all of the driver features are supported (controls). Supported
>>>>>>> resolutions are limited to VGA, QVGA, QQVGA.
>>>>>>> Supported format is limited to RGB565.
>>>>>>> Controls are limited to color bar test pattern for test purpose.
>>>>>>
>>>>>> I appreciate your efforts towards making a common driver but IMO it 
>>>>>> would be
>>>>>> better to create a separate driver for the OV9655 sensor.  The original 
>>>>>> driver
>>>>>> is 1576 lines of code, your patch set adds half of that (816).  There are
>>>>>> significant differences in the feature set of both sensors, there are
>>>>>> differences in the register layout.  I would go for a separate driver, we
>>>>>> would then have code easier to follow and wouldn't need to worry about 
>>>>>> possible
>>>>>> regressions.  I'm afraid I have lost the camera module and won't be able
>>>>>> to test the patch set against regressions.
>>>>>>
>>>>>> IMHO from maintenance POV it's better to make a separate driver. In the 
>>>>>> end
>>>>>> of the day we wouldn't be adding much more code than it is being done 
>>>>>> now.
>>>>>
>>>>> I agree. We do not have great experiences in the past with trying to 
>>>>> support
>>>>> multiple variants in a single driver (unless the diffs are truly small).
>>>>
>>>> Well,
>>>> IMHO the diffs in ov965x are smaller (but untestable because nobody seems
>>>> to have an ov9650/52 board) than within the bq27xxx chips, but I can dig 
>>>> out
>>>> an old pdata based separate ov9655 driver and extend that to become DT 
>>>> compatible.
>>>>
>>>> I had abandoned that separate approach in favour of extending the ov965x 
>>>> driver.
>>>>
>>>> Have to discuss with Hugues how to proceed.
>>>>
>>>> BR and thanks,
>>>> Nikolaus
>>>>
>>>
>>> As Sylwester and Hans, I'm also in flavour of a separate driver, the
>>> fact that register set seems similar but in fact is not and that we
>>> cannot test for non-regression of 9650/52 are killer for me to continue
>>> on a single driver.
>>> We can now restart from a new fresh state of the art sensor driver
>>> getting rid of legacy (pdata, old gpio, etc...).
>>
>> Agreed. I bet the result will look cleaner indeed although this wasn't one
>> of the complex drivers.
> 
> I finally managed to find the bug why mplayer did select-timeout on the GTA04.
> Was a bug in pinmux setup of the GTA04 for the omap3isp.
> 
> And I have resurrected our years old 3.12 camera driver, which was based on 
> the
> MT9P031 code. It was already separate from ov9650/52.
> 
> I have extended it to support DT by including some parts of Hugues' work.
> 
> It still needs some cleanup and discussion but will be a simple patch (one
> for ov9655.c + Kconfig + Makefile) and one for bindings (I hope it includes
> all your comments).
> 
> I will post v1 in the next days.
> 
> BR,
> Nikolaus
> 

Thanks Nikolaus,

I was ready to push the new version in new file ov9655.c with all 
comments included, but as my version is very minimal and I suspect that 
yours is more complete, let's merge things together.
Can I consider that you now take ownership of this driver upstream ?
If so I'll send to you my current patchset so you can compare, 
double-check review comments and add missing support on your side 
(RGB565 and VGA/QVGA resolution matter on my side).

Thanks again Nikolaus for this work,

BR,
Hugues.

[PATCH v1 5/5] [media] stm32-dcmi: g_/s_selection crop support

2017-07-28 Thread Hugues Fruchet
Implements g_/s_selection crop support by using DCMI crop
hardware feature.
User can first get the maximum supported resolution of the sensor
by calling g_selection(V4L2_SEL_TGT_CROP_BOUNDS).
Then user call to s_selection(V4L2_SEL_TGT_CROP) will reset sensor
to its maximum resolution and crop request is saved for later usage
in s_fmt().
Next call to s_fmt() will check if sensor can do frame size request
with crop request. If sensor supports only discrete frame sizes,
the frame size which is larger than user request is selected in
order to be able to match the crop request. Then s_fmt() resolution
user request is adjusted to match crop request resolution.

Signed-off-by: Hugues Fruchet <hugues.fruc...@st.com>
---
 drivers/media/platform/stm32/stm32-dcmi.c | 367 +-
 1 file changed, 363 insertions(+), 4 deletions(-)

diff --git a/drivers/media/platform/stm32/stm32-dcmi.c 
b/drivers/media/platform/stm32/stm32-dcmi.c
index 2be56b6..f1fb0b3 100644
--- a/drivers/media/platform/stm32/stm32-dcmi.c
+++ b/drivers/media/platform/stm32/stm32-dcmi.c
@@ -33,6 +33,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #define DRV_NAME "stm32-dcmi"
@@ -107,6 +108,11 @@ struct dcmi_format {
u8  bpp;
 };
 
+struct dcmi_framesize {
+   u32 width;
+   u32 height;
+};
+
 struct dcmi_buf {
struct vb2_v4l2_buffer  vb;
boolprepared;
@@ -131,10 +137,16 @@ struct stm32_dcmi {
struct v4l2_async_notifier  notifier;
struct dcmi_graph_entityentity;
struct v4l2_format  fmt;
+   struct v4l2_rectcrop;
+   booldo_crop;
 
const struct dcmi_format**sd_formats;
unsigned intnb_of_sd_formats;
const struct dcmi_format*sd_format;
+   struct dcmi_framesize   *sd_framesizes;
+   unsigned intnb_of_sd_framesizes;
+   struct dcmi_framesize   sd_framesize;
+   struct v4l2_rectsd_bounds;
 
/* Protect this data structure */
struct mutexlock;
@@ -325,6 +337,28 @@ static int dcmi_start_capture(struct stm32_dcmi *dcmi)
return 0;
 }
 
+static void dcmi_set_crop(struct stm32_dcmi *dcmi)
+{
+   u32 size, start;
+
+   /* Crop resolution */
+   size = ((dcmi->crop.height - 1) << 16) |
+   ((dcmi->crop.width << 1) - 1);
+   reg_write(dcmi->regs, DCMI_CWSIZE, size);
+
+   /* Crop start point */
+   start = ((dcmi->crop.top) << 16) |
+((dcmi->crop.left << 1));
+   reg_write(dcmi->regs, DCMI_CWSTRT, start);
+
+   dev_dbg(dcmi->dev, "Cropping to %ux%u@%u:%u\n",
+   dcmi->crop.width, dcmi->crop.height,
+   dcmi->crop.left, dcmi->crop.top);
+
+   /* Enable crop */
+   reg_set(dcmi->regs, DCMI_CR, CR_CROP);
+}
+
 static irqreturn_t dcmi_irq_thread(int irq, void *arg)
 {
struct stm32_dcmi *dcmi = arg;
@@ -540,6 +574,10 @@ static int dcmi_start_streaming(struct vb2_queue *vq, 
unsigned int count)
 
reg_write(dcmi->regs, DCMI_CR, val);
 
+   /* Set crop */
+   if (dcmi->do_crop)
+   dcmi_set_crop(dcmi);
+
/* Enable dcmi */
reg_set(dcmi->regs, DCMI_CR, CR_ENABLE);
 
@@ -697,10 +735,37 @@ static const struct dcmi_format 
*find_format_by_fourcc(struct stm32_dcmi *dcmi,
return NULL;
 }
 
+static void __find_outer_frame_size(struct stm32_dcmi *dcmi,
+   struct v4l2_pix_format *pix,
+   struct dcmi_framesize *framesize)
+{
+   struct dcmi_framesize *match = NULL;
+   unsigned int i;
+   unsigned int min_err = UINT_MAX;
+
+   for (i = 0; i < dcmi->nb_of_sd_framesizes; i++) {
+   struct dcmi_framesize *fsize = >sd_framesizes[i];
+   int w_err = (fsize->width - pix->width);
+   int h_err = (fsize->height - pix->height);
+   int err = w_err + h_err;
+
+   if ((w_err >= 0) && (h_err >= 0) && (err < min_err)) {
+   min_err = err;
+   match = fsize;
+   }
+   }
+   if (!match)
+   match = >sd_framesizes[0];
+
+   *framesize = *match;
+}
+
 static int dcmi_try_fmt(struct stm32_dcmi *dcmi, struct v4l2_format *f,
-   const struct dcmi_format **sd_format)
+   const struct dcmi_format **sd_format,
+   struct dcmi_framesize *sd_framesize)
 {
const struct dcmi_format *sd_fmt;
+   struct dcmi_framesize sd_fsize;
struct v4l2_pix_format *pix = >fmt.pix;
struct v4l2_subdev_pad_config pad_cfg;
struct v4l2_subdev_format format

[PATCH v1 3/5] [media] stm32-dcmi: cleanup variable/fields namings

2017-07-28 Thread Hugues Fruchet
Uniformize "pixfmt" variables to "pix".
Change "current_fmt" & "dcmi_fmt" variables to variables
with "sd_" prefix to explicitly refer to subdev format.

Signed-off-by: Hugues Fruchet <hugues.fruc...@st.com>
---
 drivers/media/platform/stm32/stm32-dcmi.c | 103 --
 1 file changed, 54 insertions(+), 49 deletions(-)

diff --git a/drivers/media/platform/stm32/stm32-dcmi.c 
b/drivers/media/platform/stm32/stm32-dcmi.c
index 526e354..4733d1f 100644
--- a/drivers/media/platform/stm32/stm32-dcmi.c
+++ b/drivers/media/platform/stm32/stm32-dcmi.c
@@ -132,9 +132,9 @@ struct stm32_dcmi {
struct dcmi_graph_entityentity;
struct v4l2_format  fmt;
 
-   const struct dcmi_format**user_formats;
-   unsigned intnum_user_formats;
-   const struct dcmi_format*current_fmt;
+   const struct dcmi_format**sd_formats;
+   unsigned intnb_of_sd_formats;
+   const struct dcmi_format*sd_format;
 
/* Protect this data structure */
struct mutexlock;
@@ -684,12 +684,12 @@ static int dcmi_g_fmt_vid_cap(struct file *file, void 
*priv,
 static const struct dcmi_format *find_format_by_fourcc(struct stm32_dcmi *dcmi,
   unsigned int fourcc)
 {
-   unsigned int num_formats = dcmi->num_user_formats;
+   unsigned int num_formats = dcmi->nb_of_sd_formats;
const struct dcmi_format *fmt;
unsigned int i;
 
for (i = 0; i < num_formats; i++) {
-   fmt = dcmi->user_formats[i];
+   fmt = dcmi->sd_formats[i];
if (fmt->fourcc == fourcc)
return fmt;
}
@@ -698,40 +698,42 @@ static const struct dcmi_format 
*find_format_by_fourcc(struct stm32_dcmi *dcmi,
 }
 
 static int dcmi_try_fmt(struct stm32_dcmi *dcmi, struct v4l2_format *f,
-   const struct dcmi_format **current_fmt)
+   const struct dcmi_format **sd_format)
 {
-   const struct dcmi_format *dcmi_fmt;
-   struct v4l2_pix_format *pixfmt = >fmt.pix;
+   const struct dcmi_format *sd_fmt;
+   struct v4l2_pix_format *pix = >fmt.pix;
struct v4l2_subdev_pad_config pad_cfg;
struct v4l2_subdev_format format = {
.which = V4L2_SUBDEV_FORMAT_TRY,
};
int ret;
 
-   dcmi_fmt = find_format_by_fourcc(dcmi, pixfmt->pixelformat);
-   if (!dcmi_fmt) {
-   dcmi_fmt = dcmi->user_formats[dcmi->num_user_formats - 1];
-   pixfmt->pixelformat = dcmi_fmt->fourcc;
+   sd_fmt = find_format_by_fourcc(dcmi, pix->pixelformat);
+   if (!sd_fmt) {
+   sd_fmt = dcmi->sd_formats[dcmi->nb_of_sd_formats - 1];
+   pix->pixelformat = sd_fmt->fourcc;
}
 
/* Limit to hardware capabilities */
-   pixfmt->width = clamp(pixfmt->width, MIN_WIDTH, MAX_WIDTH);
-   pixfmt->height = clamp(pixfmt->height, MIN_HEIGHT, MAX_HEIGHT);
+   pix->width = clamp(pix->width, MIN_WIDTH, MAX_WIDTH);
+   pix->height = clamp(pix->height, MIN_HEIGHT, MAX_HEIGHT);
 
-   v4l2_fill_mbus_format(, pixfmt, dcmi_fmt->mbus_code);
+   v4l2_fill_mbus_format(, pix, sd_fmt->mbus_code);
ret = v4l2_subdev_call(dcmi->entity.subdev, pad, set_fmt,
   _cfg, );
if (ret < 0)
return ret;
 
-   v4l2_fill_pix_format(pixfmt, );
+   /* Update pix regarding to what sensor can do */
+   v4l2_fill_pix_format(pix, );
 
-   pixfmt->field = V4L2_FIELD_NONE;
-   pixfmt->bytesperline = pixfmt->width * dcmi_fmt->bpp;
-   pixfmt->sizeimage = pixfmt->bytesperline * pixfmt->height;
 
-   if (current_fmt)
-   *current_fmt = dcmi_fmt;
+   pix->field = V4L2_FIELD_NONE;
+   pix->bytesperline = pix->width * sd_fmt->bpp;
+   pix->sizeimage = pix->bytesperline * pix->height;
+
+   if (sd_format)
+   *sd_format = sd_fmt;
 
return 0;
 }
@@ -741,22 +743,25 @@ static int dcmi_set_fmt(struct stm32_dcmi *dcmi, struct 
v4l2_format *f)
struct v4l2_subdev_format format = {
.which = V4L2_SUBDEV_FORMAT_ACTIVE,
};
-   const struct dcmi_format *current_fmt;
+   const struct dcmi_format *sd_format;
+   struct v4l2_mbus_framefmt *mf = 
+   struct v4l2_pix_format *pix = >fmt.pix;
int ret;
 
-   ret = dcmi_try_fmt(dcmi, f, _fmt);
+   ret = dcmi_try_fmt(dcmi, f, _format);
if (ret)
return ret;
 
-   v4l2_fill_mbus_format(, >fmt.pix,
- current_fmt->mbus_code);
+   /* pix to mbus format */
+   v4l2_fill_mbus_format(mf, pix,
+

[PATCH v1 1/5] [media] stm32-dcmi: catch dma submission error

2017-07-28 Thread Hugues Fruchet
Test cookie return by dmaengine_submit() and return error if any.

Signed-off-by: Hugues Fruchet <hugues.fruc...@st.com>
---
 drivers/media/platform/stm32/stm32-dcmi.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/media/platform/stm32/stm32-dcmi.c 
b/drivers/media/platform/stm32/stm32-dcmi.c
index 24ef888..716b3db 100644
--- a/drivers/media/platform/stm32/stm32-dcmi.c
+++ b/drivers/media/platform/stm32/stm32-dcmi.c
@@ -295,6 +295,10 @@ static int dcmi_start_dma(struct stm32_dcmi *dcmi,
 
/* Push current DMA transaction in the pending queue */
dcmi->dma_cookie = dmaengine_submit(desc);
+   if (dma_submit_error(dcmi->dma_cookie)) {
+   dev_err(dcmi->dev, "%s: DMA submission failed\n", __func__);
+   return -ENXIO;
+   }
 
dma_async_issue_pending(dcmi->dma_chan);
 
-- 
1.9.1



[PATCH v1 0/5] STM32 DCMI camera interface crop support

2017-07-28 Thread Hugues Fruchet
input 0:

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

Stream using all formats:
test MMAP for Format RGBP, Frame Size 160x120:
Crop 160x120@0x0, Stride 320, Field None: OK
Crop 0x0@0x0, Stride 320, Field None, SelTest: OK
Crop 160x120@0x0, Stride 320, Field None, SelTest: OK
test MMAP for Format RGBP, Frame Size 160x120:
Crop 160x120@0x0, Stride 320, Field None: OK
test MMAP for Format RGBP, Frame Size 160x120:
Crop 160x120@0x0, Stride 320, Field None: OK

Total: 51, Succeeded: 50, Failed: 1, Warnings: 0


Hugues Fruchet (5):
  [media] stm32-dcmi: catch dma submission error
  [media] stm32-dcmi: revisit control register handling
  [media] stm32-dcmi: cleanup variable/fields namings
  [media] stm32-dcmi: set default format at open()
  [media] stm32-dcmi: g_/s_selection crop support

 drivers/media/platform/stm32/stm32-dcmi.c | 527 +-
 1 file changed, 448 insertions(+), 79 deletions(-)

-- 
1.9.1



[PATCH v1 2/5] [media] stm32-dcmi: revisit control register handling

2017-07-28 Thread Hugues Fruchet
Simplify bits handling of DCMI_CR register.

Signed-off-by: Hugues Fruchet <hugues.fruc...@st.com>
---
 drivers/media/platform/stm32/stm32-dcmi.c | 14 --
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/drivers/media/platform/stm32/stm32-dcmi.c 
b/drivers/media/platform/stm32/stm32-dcmi.c
index 716b3db..526e354 100644
--- a/drivers/media/platform/stm32/stm32-dcmi.c
+++ b/drivers/media/platform/stm32/stm32-dcmi.c
@@ -490,7 +490,7 @@ static int dcmi_start_streaming(struct vb2_queue *vq, 
unsigned int count)
 {
struct stm32_dcmi *dcmi = vb2_get_drv_priv(vq);
struct dcmi_buf *buf, *node;
-   u32 val;
+   u32 val = 0;
int ret;
 
ret = clk_enable(dcmi->mclk);
@@ -510,22 +510,16 @@ static int dcmi_start_streaming(struct vb2_queue *vq, 
unsigned int count)
 
spin_lock_irq(>irqlock);
 
-   val = reg_read(dcmi->regs, DCMI_CR);
-
-   val &= ~(CR_PCKPOL | CR_HSPOL | CR_VSPOL |
-CR_EDM_0 | CR_EDM_1 | CR_FCRC_0 |
-CR_FCRC_1 | CR_JPEG | CR_ESS);
-
/* Set bus width */
switch (dcmi->bus.bus_width) {
case 14:
-   val &= CR_EDM_0 + CR_EDM_1;
+   val |= CR_EDM_0 | CR_EDM_1;
break;
case 12:
-   val &= CR_EDM_1;
+   val |= CR_EDM_1;
break;
case 10:
-   val &= CR_EDM_0;
+   val |= CR_EDM_0;
break;
default:
/* Set bus width to 8 bits by default */
-- 
1.9.1



[PATCH v1 4/5] [media] stm32-dcmi: set default format at open()

2017-07-28 Thread Hugues Fruchet
Ensure that we start with default pixel format and resolution
when opening a new instance.

Signed-off-by: Hugues Fruchet <hugues.fruc...@st.com>
---
 drivers/media/platform/stm32/stm32-dcmi.c | 49 ++-
 1 file changed, 28 insertions(+), 21 deletions(-)

diff --git a/drivers/media/platform/stm32/stm32-dcmi.c 
b/drivers/media/platform/stm32/stm32-dcmi.c
index 4733d1f..2be56b6 100644
--- a/drivers/media/platform/stm32/stm32-dcmi.c
+++ b/drivers/media/platform/stm32/stm32-dcmi.c
@@ -890,6 +890,28 @@ static int dcmi_enum_frameintervals(struct file *file, 
void *fh,
return 0;
 }
 
+static int dcmi_set_default_fmt(struct stm32_dcmi *dcmi)
+{
+   struct v4l2_format f = {
+   .type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
+   .fmt.pix = {
+   .width  = CIF_WIDTH,
+   .height = CIF_HEIGHT,
+   .field  = V4L2_FIELD_NONE,
+   .pixelformat= dcmi->sd_formats[0]->fourcc,
+   },
+   };
+   int ret;
+
+   ret = dcmi_try_fmt(dcmi, , NULL);
+   if (ret)
+   return ret;
+   dcmi->sd_format = dcmi->sd_formats[0];
+   dcmi->fmt = f;
+
+   return 0;
+}
+
 static const struct of_device_id stm32_dcmi_of_match[] = {
{ .compatible = "st,stm32-dcmi"},
{ /* end node */ },
@@ -916,7 +938,13 @@ static int dcmi_open(struct file *file)
if (ret < 0 && ret != -ENOIOCTLCMD)
goto fh_rel;
 
+   ret = dcmi_set_default_fmt(dcmi);
+   if (ret)
+   goto power_off;
+
ret = dcmi_set_fmt(dcmi, >fmt);
+
+power_off:
if (ret)
v4l2_subdev_call(sd, core, s_power, 0);
 fh_rel:
@@ -991,27 +1019,6 @@ static int dcmi_release(struct file *file)
.read   = vb2_fop_read,
 };
 
-static int dcmi_set_default_fmt(struct stm32_dcmi *dcmi)
-{
-   struct v4l2_format f = {
-   .type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
-   .fmt.pix = {
-   .width  = CIF_WIDTH,
-   .height = CIF_HEIGHT,
-   .field  = V4L2_FIELD_NONE,
-   .pixelformat= dcmi->sd_formats[0]->fourcc,
-   },
-   };
-   int ret;
-
-   ret = dcmi_try_fmt(dcmi, , NULL);
-   if (ret)
-   return ret;
-   dcmi->sd_format = dcmi->sd_formats[0];
-   dcmi->fmt = f;
-   return 0;
-}
-
 static const struct dcmi_format dcmi_formats[] = {
{
.fourcc = V4L2_PIX_FMT_RGB565,
-- 
1.9.1



[PATCH v1 1/2] [media] ov9650: fix coding style

2017-07-21 Thread Hugues Fruchet
Fix a bunch of coding style issues detected
by checkpatch --strict.

Signed-off-by: Hugues Fruchet <hugues.fruc...@st.com>
---
 drivers/media/i2c/ov9650.c | 59 ++
 1 file changed, 33 insertions(+), 26 deletions(-)

diff --git a/drivers/media/i2c/ov9650.c b/drivers/media/i2c/ov9650.c
index 2de2fbb..e8dea28 100644
--- a/drivers/media/i2c/ov9650.c
+++ b/drivers/media/i2c/ov9650.c
@@ -484,6 +484,7 @@ static int ov965x_set_default_gamma_curve(struct ov965x 
*ov965x)
 
for (i = 0; i < ARRAY_SIZE(gamma_curve); i++) {
int ret = ov965x_write(ov965x->client, addr, gamma_curve[i]);
+
if (ret < 0)
return ret;
addr++;
@@ -503,6 +504,7 @@ static int ov965x_set_color_matrix(struct ov965x *ov965x)
 
for (i = 0; i < ARRAY_SIZE(mtx); i++) {
int ret = ov965x_write(ov965x->client, addr, mtx[i]);
+
if (ret < 0)
return ret;
addr++;
@@ -611,7 +613,7 @@ static int ov965x_set_banding_filter(struct ov965x *ov965x, 
int value)
}
if (value == V4L2_CID_POWER_LINE_FREQUENCY_DISABLED)
return 0;
-   if (WARN_ON(ov965x->fiv == NULL))
+   if (WARN_ON(!ov965x->fiv))
return -EINVAL;
/* Set minimal exposure time for 50/60 HZ lighting */
if (value == V4L2_CID_POWER_LINE_FREQUENCY_50HZ)
@@ -999,44 +1001,47 @@ static int ov965x_initialize_controls(struct ov965x 
*ov965x)
 
/* Auto/manual white balance */
ctrls->auto_wb = v4l2_ctrl_new_std(hdl, ops,
-   V4L2_CID_AUTO_WHITE_BALANCE,
-   0, 1, 1, 1);
+  V4L2_CID_AUTO_WHITE_BALANCE,
+  0, 1, 1, 1);
ctrls->blue_balance = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_BLUE_BALANCE,
0, 0xff, 1, 0x80);
ctrls->red_balance = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_RED_BALANCE,
-   0, 0xff, 1, 0x80);
+  0, 0xff, 1, 0x80);
/* Auto/manual exposure */
-   ctrls->auto_exp = v4l2_ctrl_new_std_menu(hdl, ops,
-   V4L2_CID_EXPOSURE_AUTO,
-   V4L2_EXPOSURE_MANUAL, 0, V4L2_EXPOSURE_AUTO);
+   ctrls->auto_exp =
+   v4l2_ctrl_new_std_menu(hdl, ops,
+  V4L2_CID_EXPOSURE_AUTO,
+  V4L2_EXPOSURE_MANUAL, 0,
+  V4L2_EXPOSURE_AUTO);
/* Exposure time, in 100 us units. min/max is updated dynamically. */
ctrls->exposure = v4l2_ctrl_new_std(hdl, ops,
-   V4L2_CID_EXPOSURE_ABSOLUTE,
-   2, 1500, 1, 500);
+   V4L2_CID_EXPOSURE_ABSOLUTE,
+   2, 1500, 1, 500);
/* Auto/manual gain */
ctrls->auto_gain = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_AUTOGAIN,
-   0, 1, 1, 1);
+0, 1, 1, 1);
ctrls->gain = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_GAIN,
-   16, 64 * (16 + 15), 1, 64 * 16);
+   16, 64 * (16 + 15), 1, 64 * 16);
 
ctrls->saturation = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_SATURATION,
-   -2, 2, 1, 0);
+ -2, 2, 1, 0);
ctrls->brightness = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_BRIGHTNESS,
-   -3, 3, 1, 0);
+ -3, 3, 1, 0);
ctrls->sharpness = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_SHARPNESS,
-   0, 32, 1, 6);
+0, 32, 1, 6);
 
ctrls->hflip = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_HFLIP, 0, 1, 1, 0);
ctrls->vflip = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_VFLIP, 0, 1, 1, 0);
 
-   ctrls->light_freq = v4l2_ctrl_new_std_menu(hdl, ops,
-   V4L2_CID_POWER_LINE_FREQUENCY,
-   V4L2_CID_POWER_LINE_FREQUENCY_60HZ, ~0x7,
-   V4L2_CID_POWER_LINE_FREQUENCY_50HZ);
+   ctrls->light_freq =
+   v4l2_ctrl_new_std_menu(hdl, ops,
+  V4L2_CID_POWER_LINE_FREQUENCY,
+  V4L2_CID_POWER_LINE_FREQUENCY_60HZ, ~0x7,
+  V4L2_CID_POWER_LINE_FREQUENCY_50HZ);
 
v4l2_ctrl_new_std_menu_items(hdl, ops, V4L2_CID_TEST_PA

[PATCH v1 0/2] OV9650 code cleanup

2017-07-21 Thread Hugues Fruchet
Here is a bunch of small fixes found when upstreaming
the OV9655 sensor driver based on OV9650 driver:
- Fix coding style (checkpatch --strict)
- Fix missing mutex_destroy, see 
http://www.mail-archive.com/linux-media@vger.kernel.org/msg115245.html

Hugues Fruchet (2):
  [media] ov9650: fix coding style
  [media] ov9655: fix missing mutex_destroy()

 drivers/media/i2c/ov9650.c | 67 +++---
 1 file changed, 39 insertions(+), 28 deletions(-)

-- 
1.9.1



[PATCH v1 2/2] [media] ov9655: fix missing mutex_destroy()

2017-07-21 Thread Hugues Fruchet
Fix missing mutex_destroy() when probe fails and
when driver is removed.

Signed-off-by: Hugues Fruchet <hugues.fruc...@st.com>
---
 drivers/media/i2c/ov9650.c | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/media/i2c/ov9650.c b/drivers/media/i2c/ov9650.c
index e8dea28..6ffb460 100644
--- a/drivers/media/i2c/ov9650.c
+++ b/drivers/media/i2c/ov9650.c
@@ -1505,13 +1505,13 @@ static int ov965x_probe(struct i2c_client *client,
 
ret = ov965x_configure_gpios(ov965x, pdata);
if (ret < 0)
-   return ret;
+   goto err_mutex;
 
ov965x->pad.flags = MEDIA_PAD_FL_SOURCE;
sd->entity.function = MEDIA_ENT_F_CAM_SENSOR;
ret = media_entity_pads_init(>entity, 1, >pad);
if (ret < 0)
-   return ret;
+   goto err_mutex;
 
ret = ov965x_initialize_controls(ov965x);
if (ret < 0)
@@ -1537,16 +1537,20 @@ static int ov965x_probe(struct i2c_client *client,
v4l2_ctrl_handler_free(sd->ctrl_handler);
 err_me:
media_entity_cleanup(>entity);
+err_mutex:
+   mutex_destroy(>lock);
return ret;
 }
 
 static int ov965x_remove(struct i2c_client *client)
 {
struct v4l2_subdev *sd = i2c_get_clientdata(client);
+   struct ov965x *ov965x = to_ov965x(sd);
 
v4l2_async_unregister_subdev(sd);
v4l2_ctrl_handler_free(sd->ctrl_handler);
media_entity_cleanup(>entity);
+   mutex_destroy(>lock);
 
return 0;
 }
-- 
1.9.1



[PATCH v2 7/7] [media] ov9650: add analog power supply and clock gating

2017-07-03 Thread Hugues Fruchet
Add optional analog power supply and clock gating.

Signed-off-by: H. Nikolaus Schaller <h...@goldelico.com>
Signed-off-by: Hugues Fruchet <hugues.fruc...@st.com>
---
 drivers/media/i2c/ov9650.c | 26 ++
 1 file changed, 26 insertions(+)

diff --git a/drivers/media/i2c/ov9650.c b/drivers/media/i2c/ov9650.c
index 9ff0782..56b1eb3 100644
--- a/drivers/media/i2c/ov9650.c
+++ b/drivers/media/i2c/ov9650.c
@@ -29,6 +29,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -374,6 +375,7 @@ struct ov965x {
/* External master clock frequency */
unsigned long mclk_frequency;
struct clk *clk;
+   struct regulator *avdd;
 
/* Protects the struct fields below */
struct mutex lock;
@@ -943,13 +945,31 @@ static void ov965x_gpio_set(struct gpio_desc *gpio, int 
val)
 
 static void __ov965x_set_power(struct ov965x *ov965x, int on)
 {
+   int ret;
+
if (on) {
+   /* Bring up the power supply */
+   ret = regulator_enable(ov965x->avdd);
+   if (ret)
+   dev_warn(>client->dev,
+"Failed to enable analog power (%d)\n", ret);
+   msleep(25);
+   /* Enable clock */
+   ret = clk_prepare_enable(ov965x->clk);
+   if (ret)
+   dev_warn(>client->dev,
+"Failed to enable clock (%d)\n", ret);
+   msleep(25);
+
ov965x_gpio_set(ov965x->gpios[GPIO_PWDN], 0);
ov965x_gpio_set(ov965x->gpios[GPIO_RST], 0);
msleep(25);
} else {
ov965x_gpio_set(ov965x->gpios[GPIO_RST], 1);
ov965x_gpio_set(ov965x->gpios[GPIO_PWDN], 1);
+
+   clk_disable_unprepare(ov965x->clk);
+   regulator_disable(ov965x->avdd);
}
 
ov965x->streaming = 0;
@@ -1969,6 +1989,12 @@ static int ov965x_probe(struct i2c_client *client,
devm_gpiod_get_optional(>dev, "pwdn",
GPIOD_OUT_HIGH);
 
+   ov965x->avdd = devm_regulator_get(>dev, "avdd");
+   if (IS_ERR(ov965x->avdd)) {
+   dev_err(>dev, "Could not get analog 
regulator\n");
+   return PTR_ERR(ov965x->avdd);
+   }
+
ov965x->clk = devm_clk_get(>dev, NULL);
if (IS_ERR(ov965x->clk)) {
dev_err(>dev, "Could not get clock\n");
-- 
1.9.1



Re: [PATCH v1 0/6] Add support of OV9655 camera

2017-07-03 Thread Hugues FRUCHET
Hi Nikolaus,
Could you enable V4L2 UAPI traces ? Something like:
echo 0xFF >  /sys/devices/platform/soc/./video4linux/video2/dev_debug

you will see then in kernel dmesg the V4L2 calls and their 
parameters/return values.

BR,
Hugues.

On 07/01/2017 11:00 PM, H. Nikolaus Schaller wrote:
> Hi,
> 
> Firstly, it turned out that we also must have V4L2_CID_PIXEL_RATE for 
> omap3isp compatibility
> (see 
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?=0bc77f3f06fcf2ca7b7fad782d70926cd4d235f1
>  ).
> 
> And secondly, I have tried to add some SXGA config and it looks good by 
> oscilloscope:
> - XCLK ca. 24 MHz
> - PCLK ca. 12 MHz
> - HREF ca. 15.6 kHz negative going impulses
> - VSYNC ca. 15 Hz (fps) positive going impulses
> - D8 data line shows changing 0/1 patterns which depend on light falling in 
> camera lens
> 
> But mplayer still shows a green screen and reports v4l2: select timeout.
> 
> I assume we should see a at least scrambled image but not a green screen,
> even if sync position and polarity or data format would not be correctly
> set up.
> 
> This time the omap3isp is fully initialized and does a register dump:
> 
>> root@letux:~# ./camera-demo sxga
>> Camera: /dev/v4l-subdev8
>> Setting mode sxga
>> media-ctl -r
>> media-ctl -l '"ov965x":0 -> "OMAP3 ISP CCDC":0[1]'
>> media-ctl -l '"OMAP3 ISP CCDC":1 -> "OMAP3 ISP CCDC output":0[1]'
>> media-ctl -V '"ov965x":0 [UYVY2X8 1280x1024]'
>> media-ctl -V '"OMAP3 ISP CCDC":0 [UYVY2X8 1280x1024]'
>> media-ctl -V '"OMAP3 ISP CCDC":1 [UYVY 1280x1024]'
>> ### starting mplayer in sxga mode ###
>> mplayer tv:// -vf rotate=2 -tv 
>> driver=v4l2:device=/dev/video2:outfmt=uyvy:width=1280:height=1024:fps=15 -vo 
>> x11
> 
> NOTE: /dev/video2 is $(media-ctl -e "OMAP3 ISP CCDC output")
> 
>> MPlayer2 2.0-728-g2c378c7-4+b1 (C) 2000-2012 MPlayer Team
>>
>> Playing tv://.
>> Detected file format: TV
>> Selected driver: v4l2
>>   name: Video 4 Linux 2 input
>>   author: Martin Olschewski 
>>   comment: first try, more to come ;-)
>> v4l2: ioctl get standard failed: Invalid argument
> 
> ^^^ does not look harmful
> 
>> Selected device: OMAP3 ISP CCDC output
>>   Capabilities:  video capture  video output  streaming
>>   supported norms:
>>   inputs: 0 = camera;
>>   Current input: 0
>>   Current format: unknown (0x0)
>> tv.c: norm_from_string(pal): Bogus norm parameter, setting default.
>> v4l2: ioctl enum norm failed: Inappropriate ioctl for device
> 
> ^^^ does not look harmful
> 
>> Error: Cannot set norm!
>> Selected input hasn't got a tuner!
> 
> ^^^ does not look harmful
> 
>> v4l2: ioctl set mute failed: Inappropriate ioctl for device
>> v4l2: ioctl query control failed: Inappropriate ioctl for device
>> v4l2: ioctl query control failed: Inappropriate ioctl for device
>> v4l2: ioctl query control failed: Inappropriate ioctl for device
>> v4l2: ioctl query control failed: Inappropriate ioctl for device
> 
> ^^^ does not look harmful
> 
>> [  558.848815] configuring for 1280(2560)x1024
>> [  558.854003] omap3isp 480bc000.isp: -CCDC Register 
>> dump-
>> [  558.863983] omap3isp 480bc000.isp: ###CCDC PCR=0x
>> [  558.870880] omap3isp 480bc000.isp: ###CCDC SYN_MODE=0x00071704
>> [  558.877227] omap3isp 480bc000.isp: ###CCDC HD_VD_WID=0x
>> [  558.884613] omap3isp 480bc000.isp: ###CCDC PIX_LINES=0x
>> [  558.891876] omap3isp 480bc000.isp: ###CCDC HORZ_INFO=0x04ff
>> [  558.898132] omap3isp 480bc000.isp: ###CCDC VERT_START=0x
>> [  558.905700] omap3isp 480bc000.isp: ###CCDC VERT_LINES=0x03ff
>> [  558.913421] omap3isp 480bc000.isp: ###CCDC CULLING=0x00ff
>> [  558.920471] omap3isp 480bc000.isp: ###CCDC HSIZE_OFF=0x0a00
>> [  558.926727] omap3isp 480bc000.isp: ###CCDC SDOFST=0x
>> [  558.933929] omap3isp 480bc000.isp: ###CCDC SDR_ADDR=0x4000
>> [  558.940948] omap3isp 480bc000.isp: ###CCDC CLAMP=0x0010
>> [  558.946990] omap3isp 480bc000.isp: ###CCDC DCSUB=0x
>> [  558.953948] omap3isp 480bc000.isp: ###CCDC COLPTN=0xbb11bb11
>> [  558.960845] omap3isp 480bc000.isp: ###CCDC BLKCMP=0x
>> [  558.966888] omap3isp 480bc000.isp: ###CCDC FPC=0x
>> [  558.973724] omap3isp 480bc000.isp: ###CCDC FPC_ADDR=0x
>> [  558.982757] omap3isp 480bc000.isp: ###CCDC VDINT=0x03fe02aa
>> [  558.988769] omap3isp 480bc000.isp: ###CCDC ALAW=0x0004
>> [  558.995483] omap3isp 480bc000.isp: ###CCDC REC656IF=0x
>> [  559.002380] omap3isp 480bc000.isp: ###CCDC CFG=0x8800
>> [  559.008056] omap3isp 480bc000.isp: ###CCDC FMTCFG=0x
>> [  559.014892] omap3isp 480bc000.isp: ###CCDC FMT_HORZ=0x
>> [  559.021697] omap3isp 480bc000.isp: ###CCDC FMT_VERT=0x
>> [  559.027954] omap3isp 480bc000.isp: ###CCDC PRGEVEN0=0x
>> [  559.034912] omap3isp 480bc000.isp: ###CCDC PRGEVEN1=0x
>> [  559.041748] omap3isp 480bc000.isp: ###CCDC PRGODD0=0x
>> [  559.047790] omap3isp 

[PATCH v2 6/7] [media] ov9650: add support of OV9655 variant

2017-07-03 Thread Hugues Fruchet
Add a first support of OV9655 variant.
Because of register set slightly different from OV9650/9652,
not all of the driver features are supported (controls).
Supported resolutions are limited to VGA, QVGA, QQVGA.
Supported format is limited to RGB565.
Controls are limited to color bar test pattern for test purpose.

Signed-off-by: H. Nikolaus Schaller <h...@goldelico.com>
Signed-off-by: Hugues Fruchet <hugues.fruc...@st.com>
---
 drivers/media/i2c/Kconfig  |   4 +-
 drivers/media/i2c/ov9650.c | 487 ++---
 2 files changed, 457 insertions(+), 34 deletions(-)

diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index 168115c..0f7542f 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -614,11 +614,11 @@ config VIDEO_OV7670
  controller.
 
 config VIDEO_OV9650
-   tristate "OmniVision OV9650/OV9652 sensor support"
+   tristate "OmniVision OV9650/OV9652/OV9655 sensor support"
depends on GPIOLIB && I2C && VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API
---help---
  This is a V4L2 sensor-level driver for the Omnivision
- OV9650 and OV9652 camera sensors.
+ OV9650 and OV9652 and OV9655 camera sensors.
 
 config VIDEO_OV13858
tristate "OmniVision OV13858 sensor support"
diff --git a/drivers/media/i2c/ov9650.c b/drivers/media/i2c/ov9650.c
index 50397e6..9ff0782 100644
--- a/drivers/media/i2c/ov9650.c
+++ b/drivers/media/i2c/ov9650.c
@@ -1,5 +1,5 @@
 /*
- * Omnivision OV9650/OV9652 CMOS Image Sensor driver
+ * Omnivision OV9650/OV9652/OV9655 CMOS Image Sensor driver
  *
  * Copyright (C) 2013, Sylwester Nawrocki <sylvester.nawro...@gmail.com>
  *
@@ -7,6 +7,15 @@
  * by Vladimir Fonov.
  * Copyright (c) 2010, Vladimir Fonov
  *
+ *
+ * Copyright (C) STMicroelectronics SA 2017
+ * Author: Hugues Fruchet <hugues.fruc...@st.com> for STMicroelectronics.
+ *
+ * OV9655 initial support based on a driver written by H. Nikolaus Schaller:
+ *   
http://git.goldelico.com/?p=gta04-kernel.git;a=shortlog;h=refs/heads/work/hns/video/ov9655
+ * OV9655 registers sequence from STM32CubeF7 embedded software, see:
+ *   
https://developer.mbed.org/teams/ST/code/BSP_DISCO_F746NG/file/e1d9da7fe856/Drivers/BSP/Components/ov9655/ov9655.c
+ *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 as
  * published by the Free Software Foundation.
@@ -58,14 +67,21 @@
 #define REG_PID0x0a/* Product ID MSB */
 #define REG_VER0x0b/* Product ID LSB */
 #define REG_COM3   0x0c
-#define  COM3_SWAP 0x40
+#define  COM3_COLORBAR 0x80
+#define  COM3_RGB565   0x00
+#define  COM3_SWAP 0x40/* Doesn't work in RGB */
+#define  COM3_RESETB   0x08
 #define  COM3_VARIOPIXEL1  0x04
+#define  OV9655_SINGLEFRAME0x01
 #define REG_COM4   0x0d/* Vario Pixels  */
 #define  COM4_VARIOPIXEL2  0x80
+#define  OV9655_TRISTATE   /* seems to have a different function */
 #define REG_COM5   0x0e/* System clock options */
 #define  COM5_SLAVE_MODE   0x10
-#define  COM5_SYSTEMCLOCK48MHZ 0x80
+#define  COM5_SYSTEMCLOCK48MHZ 0x80/* not on OV9655 */
+#define  OV9655_EXPOSURESTEP   0x01
 #define REG_COM6   0x0f/* HREF & ADBLC options */
+#define  COM6_BLC_OPTICAL  0x40/* Optical black */
 #define REG_AECH   0x10/* Exposure value, AEC[9:2] */
 #define REG_CLKRC  0x11/* Clock control */
 #define  CLK_EXT   0x40/* Use external clock directly */
@@ -74,13 +90,18 @@
 #define  COM7_RESET0x80
 #define  COM7_FMT_MASK 0x38
 #define  COM7_FMT_VGA  0x40
-#define COM7_FMT_CIF   0x20
+#define  COM7_FMT_CIF  0x20
 #define  COM7_FMT_QVGA 0x10
 #define  COM7_FMT_QCIF 0x08
-#define COM7_RGB   0x04
-#define COM7_YUV   0x00
-#define COM7_BAYER 0x01
-#define COM7_PBAYER0x05
+#define  COM7_RGB  0x04
+#define  COM7_YUV  0x00
+#define  COM7_BAYER0x01
+#define  COM7_PBAYER   0x05
+#define  OV9655_COM7_VGA   0x60
+#define  OV9655_COM7_RAWRGB0x00/* different format encoding */
+#define  OV9655_COM7_RAWRGBINT 0x01
+#define  OV9655_COM7_YUV   0x02
+#define  OV9655_COM7_RGB   0x03
 #define REG_COM8   0x13/* AGC/AEC options */
 #define  COM8_FASTAEC  0x80/* Enable fast AGC/AEC */
 #define  COM8_AECSTEP  0x40/* Unlimited AEC step size */
@@ -89,14 +110,23 @@
 #define  COM8_AWB  0x02/* White balance enable */
 #define  COM8_AEC  0x01/* Auto exposure enable */
 #define REG_COM9  

[PATCH v2 5/7] [media] ov9650: add multiple variant support

2017-07-03 Thread Hugues Fruchet
Ops support and registers set can now be different
from a variant to another.

Signed-off-by: Hugues Fruchet <hugues.fruc...@st.com>
---
 drivers/media/i2c/ov9650.c | 156 -
 1 file changed, 99 insertions(+), 57 deletions(-)

diff --git a/drivers/media/i2c/ov9650.c b/drivers/media/i2c/ov9650.c
index db96698..50397e6 100644
--- a/drivers/media/i2c/ov9650.c
+++ b/drivers/media/i2c/ov9650.c
@@ -38,7 +38,7 @@
 module_param(debug, int, 0644);
 MODULE_PARM_DESC(debug, "Debug level (0-2)");
 
-#define DRIVER_NAME "OV9650"
+#define DRIVER_NAME "ov965x"
 
 /*
  * OV9650/OV9652 register definitions
@@ -239,6 +239,13 @@ struct ov965x_framesize {
const struct i2c_rv *regs;
 };
 
+struct ov965x_pixfmt {
+   u32 code;
+   u32 colorspace;
+   /* REG_TSLB value, only bits [3:2] may be set. */
+   u8 tslb_reg;
+};
+
 struct ov965x_interval {
struct v4l2_fract interval;
/* Maximum resolution for this interval */
@@ -257,6 +264,21 @@ struct ov965x {
struct media_pad pad;
enum v4l2_mbus_type bus_type;
struct gpio_desc *gpios[NUM_GPIOS];
+
+   /* Variant specific regs and ops */
+   const struct i2c_rv *init_regs;
+   const struct ov965x_framesize *framesizes;
+   unsigned int nb_of_framesizes;
+   const struct ov965x_pixfmt *formats;
+   unsigned int nb_of_formats;
+   const struct ov965x_interval *intervals;
+   unsigned int nb_of_intervals;
+   int (*initialize_controls)(struct ov965x *ov965x);
+   int (*set_frame_interval)(struct ov965x *ov965x,
+ struct v4l2_subdev_frame_interval *fi);
+   void (*update_exposure_ctrl)(struct ov965x *ov965x);
+   int (*set_params)(struct ov965x *ov965x);
+
/* External master clock frequency */
unsigned long mclk_frequency;
struct clk *clk;
@@ -416,13 +438,6 @@ struct ov965x {
},
 };
 
-struct ov965x_pixfmt {
-   u32 code;
-   u32 colorspace;
-   /* REG_TSLB value, only bits [3:2] may be set. */
-   u8 tslb_reg;
-};
-
 static const struct ov965x_pixfmt ov965x_formats[] = {
{ MEDIA_BUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_JPEG, 0x00},
{ MEDIA_BUS_FMT_YVYU8_2X8, V4L2_COLORSPACE_JPEG, 0x04},
@@ -576,7 +591,7 @@ static int ov965x_s_power(struct v4l2_subdev *sd, int on)
__ov965x_set_power(ov965x, on);
if (on) {
ret = ov965x_write_array(client,
-ov965x_init_regs);
+ov965x->init_regs);
ov965x->apply_frame_fmt = 1;
ov965x->ctrls.update = 1;
}
@@ -1090,12 +1105,13 @@ static int ov965x_initialize_controls(struct ov965x 
*ov965x)
 /*
  * V4L2 subdev video and pad level operations
  */
-static void ov965x_get_default_format(struct v4l2_mbus_framefmt *mf)
+static void ov965x_get_default_format(struct ov965x *ov965x,
+ struct v4l2_mbus_framefmt *mf)
 {
-   mf->width = ov965x_framesizes[0].width;
-   mf->height = ov965x_framesizes[0].height;
-   mf->colorspace = ov965x_formats[0].colorspace;
-   mf->code = ov965x_formats[0].code;
+   mf->width = ov965x->framesizes[0].width;
+   mf->height = ov965x->framesizes[0].height;
+   mf->colorspace = ov965x->formats[0].colorspace;
+   mf->code = ov965x->formats[0].code;
mf->field = V4L2_FIELD_NONE;
 }
 
@@ -1103,10 +1119,12 @@ static int ov965x_enum_mbus_code(struct v4l2_subdev *sd,
 struct v4l2_subdev_pad_config *cfg,
 struct v4l2_subdev_mbus_code_enum *code)
 {
-   if (code->index >= ARRAY_SIZE(ov965x_formats))
+   struct ov965x *ov965x = to_ov965x(sd);
+
+   if (code->index >= ov965x->nb_of_formats)
return -EINVAL;
 
-   code->code = ov965x_formats[code->index].code;
+   code->code = ov965x->formats[code->index].code;
return 0;
 }
 
@@ -1114,22 +1132,22 @@ static int ov965x_enum_frame_sizes(struct v4l2_subdev 
*sd,
   struct v4l2_subdev_pad_config *cfg,
   struct v4l2_subdev_frame_size_enum *fse)
 {
-   int i = ARRAY_SIZE(ov965x_formats);
+   struct ov965x *ov965x = to_ov965x(sd);
+   int i = ov965x->nb_of_formats;
 
-   if (fse->index >= ARRAY_SIZE(ov965x_framesizes))
+   if (fse->index >= ov965x->nb_of_framesizes)
return -EINVAL;
 
while (--i)
-   if (fse->code == ov965x_formats[i].code)
+   if (fse->code == ov965x->formats[i].code)
break;
 
-   fse->code = ov965x_formats[i].code;
+   fse->code = ov965x->formats

[PATCH v2 3/7] [media] ov9650: add device tree support

2017-07-03 Thread Hugues Fruchet
Allows use of device tree configuration data.
If no device tree data is there, configuration is taken from platform data.
In order to keep GPIOs configuration compatible between both way of doing,
GPIOs are switched to descriptor-based interface.

Signed-off-by: H. Nikolaus Schaller <h...@goldelico.com>
Signed-off-by: Hugues Fruchet <hugues.fruc...@st.com>
---
 drivers/media/i2c/Kconfig  |  2 +-
 drivers/media/i2c/ov9650.c | 77 ++
 2 files changed, 59 insertions(+), 20 deletions(-)

diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index 121b3b5..168115c 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -615,7 +615,7 @@ config VIDEO_OV7670
 
 config VIDEO_OV9650
tristate "OmniVision OV9650/OV9652 sensor support"
-   depends on I2C && VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API
+   depends on GPIOLIB && I2C && VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API
---help---
  This is a V4L2 sensor-level driver for the Omnivision
  OV9650 and OV9652 camera sensors.
diff --git a/drivers/media/i2c/ov9650.c b/drivers/media/i2c/ov9650.c
index 1e4e99e..7e9a902 100644
--- a/drivers/media/i2c/ov9650.c
+++ b/drivers/media/i2c/ov9650.c
@@ -11,12 +11,14 @@
  * 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 
@@ -249,9 +251,10 @@ struct ov965x {
struct v4l2_subdev sd;
struct media_pad pad;
enum v4l2_mbus_type bus_type;
-   int gpios[NUM_GPIOS];
+   struct gpio_desc *gpios[NUM_GPIOS];
/* External master clock frequency */
unsigned long mclk_frequency;
+   struct clk *clk;
 
/* Protects the struct fields below */
struct mutex lock;
@@ -511,10 +514,10 @@ static int ov965x_set_color_matrix(struct ov965x *ov965x)
return 0;
 }
 
-static void ov965x_gpio_set(int gpio, int val)
+static void ov965x_gpio_set(struct gpio_desc *gpio, int val)
 {
-   if (gpio_is_valid(gpio))
-   gpio_set_value(gpio, val);
+   if (gpio)
+   gpiod_set_value_cansleep(gpio, val);
 }
 
 static void __ov965x_set_power(struct ov965x *ov965x, int on)
@@ -1406,24 +1409,28 @@ static int ov965x_configure_gpios(struct ov965x *ov965x,
  const struct ov9650_platform_data *pdata)
 {
int ret, i;
+   int gpios[NUM_GPIOS];
 
-   ov965x->gpios[GPIO_PWDN] = pdata->gpio_pwdn;
-   ov965x->gpios[GPIO_RST]  = pdata->gpio_reset;
+   gpios[GPIO_PWDN] = pdata->gpio_pwdn;
+   gpios[GPIO_RST]  = pdata->gpio_reset;
 
-   for (i = 0; i < ARRAY_SIZE(ov965x->gpios); i++) {
-   int gpio = ov965x->gpios[i];
+   for (i = 0; i < ARRAY_SIZE(gpios); i++) {
+   int gpio = gpios[i];
 
if (!gpio_is_valid(gpio))
continue;
ret = devm_gpio_request_one(>client->dev, gpio,
-   GPIOF_OUT_INIT_HIGH, "OV965X");
-   if (ret < 0)
+   GPIOF_OUT_INIT_HIGH, DRIVER_NAME);
+   if (ret < 0) {
+   dev_err(>client->dev,
+   "Failed to request gpio%d (%d)\n", gpio, ret);
return ret;
+   }
v4l2_dbg(1, debug, >sd, "set gpio %d to 1\n", gpio);
 
gpio_set_value(gpio, 1);
gpio_export(gpio, 0);
-   ov965x->gpios[i] = gpio;
+   ov965x->gpios[i] = gpio_to_desc(gpio);
}
 
return 0;
@@ -1469,14 +1476,10 @@ static int ov965x_probe(struct i2c_client *client,
struct v4l2_subdev *sd;
struct ov965x *ov965x;
int ret;
+   struct device_node *np = client->dev.of_node;
 
-   if (pdata == NULL) {
-   dev_err(>dev, "platform data not specified\n");
-   return -EINVAL;
-   }
-
-   if (pdata->mclk_frequency == 0) {
-   dev_err(>dev, "MCLK frequency not specified\n");
+   if (!pdata && !np) {
+   dev_err(>dev, "Platform data or device tree data must 
be provided\n");
return -EINVAL;
}
 
@@ -1486,7 +1489,35 @@ static int ov965x_probe(struct i2c_client *client,
 
mutex_init(>lock);
ov965x->client = client;
-   ov965x->mclk_frequency = pdata->mclk_frequency;
+   mutex_init(>lock);
+
+   if (np) {
+   /* Device tree */
+   ov965x->gpios[GPIO_RST] =
+   devm_gpiod_get_optional(>dev, "resetb",
+

[PATCH v2 2/7] [media] ov9650: switch i2c device id to lower case

2017-07-03 Thread Hugues Fruchet
Switch i2c device id to lower case as it is
done for other omnivision cameras.

Signed-off-by: Hugues Fruchet <hugues.fruc...@st.com>
---
 drivers/media/i2c/ov9650.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/i2c/ov9650.c b/drivers/media/i2c/ov9650.c
index 2de2fbb..1e4e99e 100644
--- a/drivers/media/i2c/ov9650.c
+++ b/drivers/media/i2c/ov9650.c
@@ -1545,8 +1545,8 @@ static int ov965x_remove(struct i2c_client *client)
 }
 
 static const struct i2c_device_id ov965x_id[] = {
-   { "OV9650", 0 },
-   { "OV9652", 0 },
+   { "ov9650", 0 },
+   { "ov9652", 0 },
{ /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(i2c, ov965x_id);
-- 
1.9.1



[PATCH v2 1/7] DT bindings: add bindings for ov965x camera module

2017-07-03 Thread Hugues Fruchet
From: "H. Nikolaus Schaller" <h...@goldelico.com>

This adds documentation of device tree bindings
for the OV965X family camera sensor module.

Signed-off-by: H. Nikolaus Schaller <h...@goldelico.com>
Signed-off-by: Hugues Fruchet <hugues.fruc...@st.com>
---
 .../devicetree/bindings/media/i2c/ov965x.txt   | 45 ++
 1 file changed, 45 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/i2c/ov965x.txt

diff --git a/Documentation/devicetree/bindings/media/i2c/ov965x.txt 
b/Documentation/devicetree/bindings/media/i2c/ov965x.txt
new file mode 100644
index 000..4ceb727
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/i2c/ov965x.txt
@@ -0,0 +1,45 @@
+* Omnivision OV9650/9652/9655 CMOS sensor
+
+The Omnivision OV965x sensor support multiple resolutions output, such as
+CIF, SVGA, UXGA. It also can support YUV422/420, RGB565/555 or raw RGB
+output format.
+
+Required Properties:
+- compatible: should be one of
+   "ovti,ov9650"
+   "ovti,ov9652"
+   "ovti,ov9655"
+- clocks: reference to the mclk input clock.
+
+Optional Properties:
+- resetb-gpios: reference to the GPIO connected to the RESETB pin, if any,
+   polarity is active low.
+- pwdn-gpios: reference to the GPIO connected to the PWDN pin, if any,
+   polarity is active high.
+- avdd-supply: reference to the analog power supply regulator connected
+   to the AVDD pin, if any.
+- dvdd-supply: reference to the digital power supply regulator connected
+   to the DVDD pin, if any.
+- dovdd-supply: reference to the digital I/O power supply regulator
+   connected to the DOVDD pin, if any.
+
+The device node must contain one 'port' child node for its digital output
+video port, in accordance with the video interface bindings defined in
+Documentation/devicetree/bindings/media/video-interfaces.txt.
+
+Example:
+
+ {
+   ov9655: camera@30 {
+   compatible = "ovti,ov9655";
+   reg = <0x30>;
+   pwdn-gpios = < 13 GPIO_ACTIVE_HIGH>;
+   clocks = <_ext_camera>;
+
+   port {
+   ov9655: endpoint {
+   remote-endpoint = <_0>;
+   };
+   };
+   };
+};
-- 
1.9.1



[PATCH v2 0/7] [PATCH v2 0/7] Add support of OV9655 camera

2017-07-03 Thread Hugues Fruchet
This patchset enables OV9655 camera support.

OV9655 support has been tested using STM32F4DIS-CAM extension board
plugged on connector P1 of STM32F746G-DISCO board.
Due to lack of OV9650/52 hardware support, the modified related code
could not have been checked for non-regression.

First patches upgrade current support of OV9650/52 to prepare then
introduction of OV9655 variant patch.
Because of OV9655 register set slightly different from OV9650/9652,
not all of the driver features are supported (controls). Supported
resolutions are limited to VGA, QVGA, QQVGA.
Supported format is limited to RGB565.
Controls are limited to color bar test pattern for test purpose.

OV9655 initial support is based on a driver written by H. Nikolaus Schaller [1].
OV9655 registers sequences come from STM32CubeF7 embedded software [2].

[1] 
http://git.goldelico.com/?p=gta04-kernel.git;a=shortlog;h=refs/heads/work/hns/video/ov9655
[2] 
https://developer.mbed.org/teams/ST/code/BSP_DISCO_F746NG/file/e1d9da7fe856/Drivers/BSP/Components/ov9655/ov9655.c

===
= history =
===
version 2:
  - Remove some unneeded semicolons (kbuild test robot):
  http://www.mail-archive.com/linux-media@vger.kernel.org/msg114616.html
  - Remove patch [media] ov9650: select the nearest higher resolution:
it is up to the application to find the best matching resolution
using ENUM_FRAMESIZES/S_FMT/S_SELECTION (S_CROP), see
  http://www.mail-archive.com/linux-media@vger.kernel.org/msg114667.html
  - dt-bindings: Fix remarks from Rob Herring about polarity:
  http://www.mail-archive.com/linux-media@vger.kernel.org/msg114705.html
  - dt-bindings: Add optional regulators avdd, dvdd, dovdd:
  http://www.mail-archive.com/linux-media@vger.kernel.org/msg114785.html
  - fix missing semicolons in if condition:
  http://www.mail-archive.com/linux-media@vger.kernel.org/msg114611.html
  - move ov965x_pixfmt relocation in right patch:
  http://www.mail-archive.com/linux-media@vger.kernel.org/msg114849.html
  - revisit OV965x renaming to ov965x for device id names and DT compatible 
strings,
drop of_device_id .data device identification
  http://www.mail-archive.com/linux-media@vger.kernel.org/msg114635.html
  http://www.mail-archive.com/linux-media@vger.kernel.org/msg114738.html
  - Add analog power supply and clock gating, needed for GTA04 platform:
  http://www.mail-archive.com/linux-media@vger.kernel.org/msg114519.html

version 1:
  - Initial submission.

H. Nikolaus Schaller (1):
  DT bindings: add bindings for ov965x camera module

Hugues Fruchet (6):
  [media] ov9650: switch i2c device id to lower case
  [media] ov9650: add device tree support
  [media] ov9650: use write_array() for resolution sequences
  [media] ov9650: add multiple variant support
  [media] ov9650: add support of OV9655 variant
  [media] ov9650: add analog power supply and clock gating

 .../devicetree/bindings/media/i2c/ov965x.txt   |  45 ++
 drivers/media/i2c/Kconfig  |   6 +-
 drivers/media/i2c/ov9650.c | 816 +
 3 files changed, 736 insertions(+), 131 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/media/i2c/ov965x.txt

-- 
1.9.1



[PATCH v2 4/7] [media] ov9650: use write_array() for resolution sequences

2017-07-03 Thread Hugues Fruchet
Align resolution sequences on initialization sequence using
i2c_rv structure NULL terminated .This add flexibility
on resolution sequence size.
Document resolution related registers by using corresponding
define instead of hexa address/value.

Signed-off-by: Hugues Fruchet <hugues.fruc...@st.com>
---
 drivers/media/i2c/ov9650.c | 88 +++---
 1 file changed, 59 insertions(+), 29 deletions(-)

diff --git a/drivers/media/i2c/ov9650.c b/drivers/media/i2c/ov9650.c
index 7e9a902..db96698 100644
--- a/drivers/media/i2c/ov9650.c
+++ b/drivers/media/i2c/ov9650.c
@@ -227,11 +227,16 @@ struct ov965x_ctrls {
u8 update;
 };
 
+struct i2c_rv {
+   u8 addr;
+   u8 value;
+};
+
 struct ov965x_framesize {
u16 width;
u16 height;
u16 max_exp_lines;
-   const u8 *regs;
+   const struct i2c_rv *regs;
 };
 
 struct ov965x_interval {
@@ -280,11 +285,6 @@ struct ov965x {
u8 apply_frame_fmt;
 };
 
-struct i2c_rv {
-   u8 addr;
-   u8 value;
-};
-
 static const struct i2c_rv ov965x_init_regs[] = {
{ REG_COM2, 0x10 }, /* Set soft sleep mode */
{ REG_COM5, 0x00 }, /* System clock options */
@@ -342,30 +342,59 @@ struct i2c_rv {
{ REG_NULL, 0 }
 };
 
-#define NUM_FMT_REGS 14
-/*
- * COM7,  COM3,  COM4, HSTART, HSTOP, HREF, VSTART, VSTOP, VREF,
- * EXHCH, EXHCL, ADC,  OCOM,   OFON
- */
-static const u8 frame_size_reg_addr[NUM_FMT_REGS] = {
-   0x12, 0x0c, 0x0d, 0x17, 0x18, 0x32, 0x19, 0x1a, 0x03,
-   0x2a, 0x2b, 0x37, 0x38, 0x39,
-};
-
-static const u8 ov965x_sxga_regs[NUM_FMT_REGS] = {
-   0x00, 0x00, 0x00, 0x1e, 0xbe, 0xbf, 0x01, 0x81, 0x12,
-   0x10, 0x34, 0x81, 0x93, 0x51,
+static const struct i2c_rv ov965x_sxga_regs[] = {
+   { REG_COM7, 0x00 },
+   { REG_COM3, 0x00 },
+   { REG_COM4, 0x00 },
+   { REG_HSTART, 0x1e },
+   { REG_HSTOP, 0xbe },
+   { 0x32, 0xbf },
+   { REG_VSTART, 0x01 },
+   { REG_VSTOP, 0x81 },
+   { REG_VREF, 0x12 },
+   { REG_EXHCH, 0x10 },
+   { REG_EXHCL, 0x34 },
+   { REG_ADC, 0x81 },
+   { REG_ACOM, 0x93 },
+   { REG_OFON, 0x51 },
+   { REG_NULL, 0 },
 };
 
-static const u8 ov965x_vga_regs[NUM_FMT_REGS] = {
-   0x40, 0x04, 0x80, 0x26, 0xc6, 0xed, 0x01, 0x3d, 0x00,
-   0x10, 0x40, 0x91, 0x12, 0x43,
+static const struct i2c_rv ov965x_vga_regs[] = {
+   { REG_COM7, 0x40 },
+   { REG_COM3, 0x04 },
+   { REG_COM4, 0x80 },
+   { REG_HSTART, 0x26 },
+   { REG_HSTOP, 0xc6 },
+   { 0x32, 0xed },
+   { REG_VSTART, 0x01 },
+   { REG_VSTOP, 0x3d },
+   { REG_VREF, 0x00 },
+   { REG_EXHCH, 0x10 },
+   { REG_EXHCL, 0x40 },
+   { REG_ADC, 0x91 },
+   { REG_ACOM, 0x12 },
+   { REG_OFON, 0x43 },
+   { REG_NULL, 0 },
 };
 
 /* Determined empirically. */
-static const u8 ov965x_qvga_regs[NUM_FMT_REGS] = {
-   0x10, 0x04, 0x80, 0x25, 0xc5, 0xbf, 0x00, 0x80, 0x12,
-   0x10, 0x40, 0x91, 0x12, 0x43,
+static const struct i2c_rv ov965x_qvga_regs[] = {
+   { REG_COM7, 0x10 },
+   { REG_COM3, 0x04 },
+   { REG_COM4, 0x80 },
+   { REG_HSTART, 0x25 },
+   { REG_HSTOP, 0xc5 },
+   { 0x32, 0xbf },
+   { REG_VSTART, 0x00 },
+   { REG_VSTOP, 0x80 },
+   { REG_VREF, 0x12 },
+   { REG_EXHCH, 0x10 },
+   { REG_EXHCL, 0x40 },
+   { REG_ADC, 0x91 },
+   { REG_ACOM, 0x12 },
+   { REG_OFON, 0x43 },
+   { REG_NULL, 0 },
 };
 
 static const struct ov965x_framesize ov965x_framesizes[] = {
@@ -1266,11 +1295,12 @@ static int ov965x_set_fmt(struct v4l2_subdev *sd, 
struct v4l2_subdev_pad_config
 
 static int ov965x_set_frame_size(struct ov965x *ov965x)
 {
-   int i, ret = 0;
+   int ret = 0;
+
+   v4l2_dbg(1, debug, ov965x->client, "%s\n", __func__);
 
-   for (i = 0; ret == 0 && i < NUM_FMT_REGS; i++)
-   ret = ov965x_write(ov965x->client, frame_size_reg_addr[i],
-  ov965x->frame_size->regs[i]);
+   ret = ov965x_write_array(ov965x->client,
+ov965x->frame_size->regs);
return ret;
 }
 
-- 
1.9.1



Re: [PATCH v1 0/6] Add support of OV9655 camera

2017-07-03 Thread Hugues FRUCHET
Hi Nikolaus,

nothing really strange in trace, I wanted to check the latest S_FMT and 
it is well 1280x1024 YUV:
 >> [  425.579498] video2: VIDIOC_S_FMT: type=vid-cap, width=1280, 
height=1024, pixelformat=UYVY, field=none, bytesperline=2560, 
sizeimage=2621440, colorspace=0, flags=0x0, ycbcr_enc=0, quantization=0, 
xfer_func=0

You're right that it seems that the ISP is not seeing any data in input.
Have you double checked the polarities of sync signals ? I see 
differences in devicetree:
  960 ov9655: endpoint {
  961 remote-endpoint = <_ep>;
  962 #if 0   // not used by camera driver - define _ep for isp
  963 bus-width = <8>;
  964 data-shift = <2>;   /* Lines 
9:2 are used */
  965 hsync-active = <1>; /* Active 
high */
  966 vsync-active = <1>; /* Active 
high */
  967 data-active = <1>;  /* Active 
high */
  968 pclk-sample = <1>;  /* Rising */
  969 #endif

Which has been commented out in flavour of:

1011 /* parallel camera interface */
1012 _ep {
1013 remote-endpoint = <>;
1014 ti,isp-clock-divisor = <1>;
1015 ti,strobe-mode;
1016 bus-width = <8>;/* Used data lines */
1017 data-shift = <2>; /* Lines 9:2 are used */
1018 hsync-active = <0>; /* Active low */
1019 vsync-active = <1>; /* Active high */
1020 data-active = <1>;/* Active high */
1021 pclk-sample = <1>;/* Rising */
1022 };

there is a difference regarding active level of hsync.

Nevertheless seems OK if I check OMAP3 ISP register:
CCDC SYN_MODE=0x00071704
#define ISPCCDC_SYN_MODE_VDPOL  (1 << 2)
#define ISPCCDC_SYN_MODE_HDPOL  (1 << 3)

seems well that vertical is 1 and horizontal is 0.


BR,
Hugues.

On 07/03/2017 11:14 AM, H. Nikolaus Schaller wrote:
> Hi Hugues,
> 
>> Am 03.07.2017 um 10:16 schrieb Hugues FRUCHET <hugues.fruc...@st.com>:
>>
>> Hi Nikolaus,
>> Could you enable V4L2 UAPI traces ? Something like:
>> echo 0xFF >  /sys/devices/platform/soc/.> name>/video4linux/video2/dev_debug
>>
>> you will see then in kernel dmesg the V4L2 calls and their
>> parameters/return values.
> 
> Nice.
> 
>> root@letux:~# echo 255 
>> >/sys/devices/platform/6800.ocp/480bc000.isp/video4linux/video2/dev_debug
>> root@letux:~# ./camera-demo sxga
>> Camera: /dev/v4l-subdev8
>> Setting mode sxga
>> media-ctl -r
>> media-ctl -l '"ov965x":0 -> "OMAP3 ISP CCDC":0[1]'
>> media-ctl -l '"OMAP3 ISP CCDC":1 -> "OMAP3 ISP CCDC output":0[1]'
>> media-ctl -V '"ov965x":0 [UYVY2X8 1280x1024]'
>> media-ctl -V '"OMAP3 ISP CCDC":0 [UYVY2X8 1280x1024]'
>> media-ctl -V '"OMAP3 ISP CCDC":1 [UYVY 1280x1024]'
>> ### starting mplayer in sxga mode ###
>> mplayer tv:// -vf rotate=2 -tv 
>> driver=v4l2:device=/dev/video2:outfmt=uyvy:width=1280:height=1024:fps=15 -vo 
>> x11
>> MPlayer2 2.0-728-g2c378c7-4+b1 (C) 2000-2012 MPlayer Team
>>
>> Playing tv://.
>> Detected file format: TV
>> Selected driver: v4l2
>>   name: Video 4 Linux 2 input
>>   author: Martin Olschewski <olschew...@zpr.uni-koeln.de>
>>   comment: first try, more to come ;-)
>> [  425.216094] video2: open (0)
>> [  425.219329] video2: VIDIOC_QUERYCAP: driver=ispvideo, card=OMAP3 ISP CCDC 
>> output, bus=media, version=0x00040c00, capabilities=0x8423, 
>> device_caps=0x0421
>> [  425.236389] video2: VIDIOC_G_FMT: type=vid-cap, width=0, height=0, 
>> pixelformat=, field=any, bytesperline=0, sizeimage=0, colorspace=0, 
>> flags=0x0, ycbcr_enc=0, quantization=0, xfer_func=0
>> [  425.254699] video2: VIDIOC_G_STD: error -25: std=0x
>> [  425.260620] video2: VIDIOC_G_PARM: error -22: type=vid-cap, 
>> capability=0x0, capturemode=0x0, timeperframe=0/0, extendedmode=0, 
>> readbuffers=0
>> v4l2: ioctl get standard failed: Invalid argumen[  425.275573] video2: 
>> VIDIOC_ENUMSTD: error -25: index=0, id=0x0, name=, fps=0/0, framelines=0
>> t
>> Selected device: OMAP3 ISP CCDC output
>>   Capa[  425.289398] video2: VIDIOC_ENUMINPUT: index=0, name=camera, type=2, 
>> audioset=0x0, tuner=0, std=0x, status=0x0, capabilities=0x0
>> bilities:  video capture  video output  streamin[  425.306396] video2: 
>> VIDIOC_ENUMINPUT: error -22: index=1, name=, type=0, audioset=0x0, tuner=0, 
>> std=0x, stat

Re: [PATCH v2 0/7] [PATCH v2 0/7] Add support of OV9655 camera

2017-07-06 Thread Hugues FRUCHET
Hi Sylwester,

Do you have the possibility to check for non-regression of this patchset 
on 9650/52 camera ?

Best regards,
Hugues.

On 07/03/2017 11:16 AM, Hugues Fruchet wrote:
> This patchset enables OV9655 camera support.
> 
> OV9655 support has been tested using STM32F4DIS-CAM extension board
> plugged on connector P1 of STM32F746G-DISCO board.
> Due to lack of OV9650/52 hardware support, the modified related code
> could not have been checked for non-regression.
> 
> First patches upgrade current support of OV9650/52 to prepare then
> introduction of OV9655 variant patch.
> Because of OV9655 register set slightly different from OV9650/9652,
> not all of the driver features are supported (controls). Supported
> resolutions are limited to VGA, QVGA, QQVGA.
> Supported format is limited to RGB565.
> Controls are limited to color bar test pattern for test purpose.
> 
> OV9655 initial support is based on a driver written by H. Nikolaus Schaller 
> [1].
> OV9655 registers sequences come from STM32CubeF7 embedded software [2].
> 
> [1] 
> http://git.goldelico.com/?p=gta04-kernel.git;a=shortlog;h=refs/heads/work/hns/video/ov9655
> [2] 
> https://developer.mbed.org/teams/ST/code/BSP_DISCO_F746NG/file/e1d9da7fe856/Drivers/BSP/Components/ov9655/ov9655.c
> 
> ===
> = history =
> ===
> version 2:
>- Remove some unneeded semicolons (kbuild test robot):
>http://www.mail-archive.com/linux-media@vger.kernel.org/msg114616.html
>- Remove patch [media] ov9650: select the nearest higher resolution:
>  it is up to the application to find the best matching resolution
>  using ENUM_FRAMESIZES/S_FMT/S_SELECTION (S_CROP), see
>http://www.mail-archive.com/linux-media@vger.kernel.org/msg114667.html
>- dt-bindings: Fix remarks from Rob Herring about polarity:
>http://www.mail-archive.com/linux-media@vger.kernel.org/msg114705.html
>- dt-bindings: Add optional regulators avdd, dvdd, dovdd:
>http://www.mail-archive.com/linux-media@vger.kernel.org/msg114785.html
>- fix missing semicolons in if condition:
>http://www.mail-archive.com/linux-media@vger.kernel.org/msg114611.html
>- move ov965x_pixfmt relocation in right patch:
>http://www.mail-archive.com/linux-media@vger.kernel.org/msg114849.html
>- revisit OV965x renaming to ov965x for device id names and DT compatible 
> strings,
>  drop of_device_id .data device identification
>http://www.mail-archive.com/linux-media@vger.kernel.org/msg114635.html
>http://www.mail-archive.com/linux-media@vger.kernel.org/msg114738.html
>- Add analog power supply and clock gating, needed for GTA04 platform:
>http://www.mail-archive.com/linux-media@vger.kernel.org/msg114519.html
> 
> version 1:
>- Initial submission.
> 
> H. Nikolaus Schaller (1):
>DT bindings: add bindings for ov965x camera module
> 
> Hugues Fruchet (6):
>[media] ov9650: switch i2c device id to lower case
>[media] ov9650: add device tree support
>[media] ov9650: use write_array() for resolution sequences
>[media] ov9650: add multiple variant support
>[media] ov9650: add support of OV9655 variant
>[media] ov9650: add analog power supply and clock gating
> 
>   .../devicetree/bindings/media/i2c/ov965x.txt   |  45 ++
>   drivers/media/i2c/Kconfig  |   6 +-
>   drivers/media/i2c/ov9650.c | 816 
> +
>   3 files changed, 736 insertions(+), 131 deletions(-)
>   create mode 100644 Documentation/devicetree/bindings/media/i2c/ov965x.txt
> 

Re: [PATCH v1 1/6] DT bindings: add bindings for ov965x camera module

2017-06-28 Thread Hugues FRUCHET


On 06/28/2017 01:24 PM, H. Nikolaus Schaller wrote:
> 
>> Am 28.06.2017 um 12:50 schrieb Sylwester Nawrocki <s.nawro...@samsung.com>:
>>
>> On 06/28/2017 11:12 AM, H. Nikolaus Schaller wrote:
>>>> Am 28.06.2017 um 00:57 schrieb Sylwester Nawrocki <snawro...@kernel.org>:
>>>> On 06/27/2017 07:48 AM, H. Nikolaus Schaller wrote:
>>>>>> Am 26.06.2017 um 22:04 schrieb Sylwester Nawrocki <snawro...@kernel.org>:
>>>>>> On 06/26/2017 12:35 PM, Hugues FRUCHET wrote:
>>>>>>>> What I am missing to support the GTA04 camera is the control of the 
>>>>>>>> optional "vana-supply".
>>>>>>>> So the driver does not power up the camera module when needed and 
>>>>>>>> therefore probing fails.
>>>>>>>>
>>>>>>>> - vana-supply: a regulator to power up the camera module.
>>>>>>>>
>>>>>>>> Driver code is not complex to add:
>>>>>>
>>>>>>> Yes, I saw it in your code, but as I don't have any programmable power
>>>>>>> supply on my setup, I have not pushed this commit.
>>>>>>
>>>>>> Since you are about to add voltage supplies to the DT binding I'd suggest
>>>>>> to include all three voltage supplies of the sensor chip. Looking at the 
>>>>>> OV9650
>>>>>> and the OV9655 datasheet there are following names used for the voltage 
>>>>>> supply
>>>>>> pins:
>>>>>>
>>>>>> AVDD - Analog power supply,
>>>>>> DVDD - Power supply for digital core logic,
>>>>>> DOVDD - Digital power supply for I/O.
>>>>>
>>>>> The latter two are usually not independently switchable from the SoC power
>>>>> the module is connected to.
>>>>>
>>>>> And sometimes DVDD and DOVDD are connected together.
>>>>>
>>>>> So the driver can't make much use of knowing or requesting them because 
>>>>> the
>>>>> 1.8V supply is always active, even during suspend.
>>>>>
>>>>>>
>>>>>> I doubt the sensor can work without any of these voltage supplies, thus
>>>>>> regulator_get_optional() should not be used. I would just use the 
>>>>>> regulator
>>>>>> bulk API to handle all three power supplies.
>>>>>
>>>>> The digital part works with AVDD turned off. So the LDO supplying AVDD 
>>>>> should
>>>>> be switchable to save power ( on the GTA04 device).>
>>>>> But not all designs can switch it off. Hence the idea to define it as an
>>>>> /optional/ regulator. If it is not defined by DT, the driver simply 
>>>>> assumes
>>>>> it is always powered on.
>>>>
>>>> I didn't say we can't define regulator supply properties as optional in 
>>>> the DT
>>>> binding.  If we define them as such and any of these *-supply properties is
>>>> missing in DT with regulator_get() the regulator core will use dummy 
>>>> regulator
>>>> for that particular voltage supply.  While with regulator_get_optional()
>>>> -ENODEV is returned when the regulator cannot be found.
>>>
>>> Ah, ok. I see.
>>>
>>> I had thought that it is the right thing to do like 
>>> devm_gpiod_get_optional().
>>>
>>> That one it is described as:
>>>
>>> "* This is equivalent to gpiod_get(), except that when no GPIO was assigned 
>>> to
>>>   * the requested function it will return NULL. This is convenient for 
>>> drivers
>>>   * that need to handle optional GPIOs."
>>>
>>> Seems to be inconsistent definition of what "optional" means.
>>
>> Indeed, this commit explains it further:
>>
>> commit de1dd9fd2156874b45803299b3b27e65d5defdd9
>> regulator: core: Provide hints to the core about optional supplies
>>
>>> So we indeed should use devm_regulator_get() in this case. Thanks for > 
>>> pointing out!
>>
>>>>> So in summary we only need AVDD switched for the GTA04 - but it does not
>>>>> matter if the others are optional properties. We would not use them.
>>>>>
>>>>> It does matter if they are mandatory because it adds DT complexity (size
>>>>> and processing) without added function.
>>>>
>>>> We should not be defining DT binding only with selected use cases/board
>>>> designs in mind.  IMO all three voltage supplies should be listed in the
>>>> binding, presumably all can be made optional, with an assumption that when
>>>> the property is missing selected pin is hooked up to a fixed regulator.
>>>
>>> Ok, then it should just be defined in the bindings but not used by
>>> the driver?
>>
>> Yes, I think so. So we have a possibly complete binding right from the
>> beginning. I someone needs handling other supplies than AVDD they could
>> update the driver in future.
> 
> Fine! I have sent some patches to Hughues so that he can integrate it in
> his next version of the patch series.
> 
> BR and thanks,
> Nikolaus
> 

OK got it, I'll push in v2.

Re: [PATCH v1 4/6] [media] ov9650: use write_array() for resolution sequences

2017-06-29 Thread Hugues FRUCHET


On 06/26/2017 06:33 PM, Sakari Ailus wrote:
> Hi Hugues,
> 
> On Thu, Jun 22, 2017 at 05:05:40PM +0200, Hugues Fruchet wrote:
>> Align resolution sequences on initialization sequence using
>> i2c_rv structure NULL terminated .This add flexibility
>> on resolution sequence size.
>> Document resolution related registers by using corresponding
>> define instead of hexa address/value.
>>
>> Signed-off-by: Hugues Fruchet <hugues.fruc...@st.com>
>> ---
>>   drivers/media/i2c/ov9650.c | 98 
>> ++
>>   1 file changed, 64 insertions(+), 34 deletions(-)
>>
>> diff --git a/drivers/media/i2c/ov9650.c b/drivers/media/i2c/ov9650.c
>> index 4311da6..8b283c9 100644
>> --- a/drivers/media/i2c/ov9650.c
>> +++ b/drivers/media/i2c/ov9650.c
>> @@ -227,11 +227,16 @@ struct ov965x_ctrls {
>>  u8 update;
>>   };
>>   
>> +struct i2c_rv {
>> +u8 addr;
>> +u8 value;
>> +};
>> +
>>   struct ov965x_framesize {
>>  u16 width;
>>  u16 height;
>>  u16 max_exp_lines;
>> -const u8 *regs;
>> +const struct i2c_rv *regs;
>>   };
>>   
>>   struct ov965x_interval {
>> @@ -280,9 +285,11 @@ struct ov965x {
>>  u8 apply_frame_fmt;
>>   };
>>   
>> -struct i2c_rv {
>> -u8 addr;
>> -u8 value;
>> +struct ov965x_pixfmt {
>> +u32 code;
>> +u32 colorspace;
>> +/* REG_TSLB value, only bits [3:2] may be set. */
>> +u8 tslb_reg;
>>   };
>>   
>>   static const struct i2c_rv ov965x_init_regs[] = {
>> @@ -342,30 +349,59 @@ struct i2c_rv {
>>  { REG_NULL, 0 }
>>   };
>>   
>> -#define NUM_FMT_REGS 14
>> -/*
>> - * COM7,  COM3,  COM4, HSTART, HSTOP, HREF, VSTART, VSTOP, VREF,
>> - * EXHCH, EXHCL, ADC,  OCOM,   OFON
>> - */
>> -static const u8 frame_size_reg_addr[NUM_FMT_REGS] = {
>> -0x12, 0x0c, 0x0d, 0x17, 0x18, 0x32, 0x19, 0x1a, 0x03,
>> -0x2a, 0x2b, 0x37, 0x38, 0x39,
>> -};
>> -
>> -static const u8 ov965x_sxga_regs[NUM_FMT_REGS] = {
>> -0x00, 0x00, 0x00, 0x1e, 0xbe, 0xbf, 0x01, 0x81, 0x12,
>> -0x10, 0x34, 0x81, 0x93, 0x51,
>> +static const struct i2c_rv ov965x_sxga_regs[] = {
>> +{ REG_COM7, 0x00 },
>> +{ REG_COM3, 0x00 },
>> +{ REG_COM4, 0x00 },
>> +{ REG_HSTART, 0x1e },
>> +{ REG_HSTOP, 0xbe },
>> +{ 0x32, 0xbf },
>> +{ REG_VSTART, 0x01 },
>> +{ REG_VSTOP, 0x81 },
>> +{ REG_VREF, 0x12 },
>> +{ REG_EXHCH, 0x10 },
>> +{ REG_EXHCL, 0x34 },
>> +{ REG_ADC, 0x81 },
>> +{ REG_ACOM, 0x93 },
>> +{ REG_OFON, 0x51 },
>> +{ REG_NULL, 0 },
>>   };
>>   
>> -static const u8 ov965x_vga_regs[NUM_FMT_REGS] = {
>> -0x40, 0x04, 0x80, 0x26, 0xc6, 0xed, 0x01, 0x3d, 0x00,
>> -0x10, 0x40, 0x91, 0x12, 0x43,
>> +static const struct i2c_rv ov965x_vga_regs[] = {
>> +{ REG_COM7, 0x40 },
>> +{ REG_COM3, 0x04 },
>> +{ REG_COM4, 0x80 },
>> +{ REG_HSTART, 0x26 },
>> +{ REG_HSTOP, 0xc6 },
>> +{ 0x32, 0xed },
>> +{ REG_VSTART, 0x01 },
>> +{ REG_VSTOP, 0x3d },
>> +{ REG_VREF, 0x00 },
>> +{ REG_EXHCH, 0x10 },
>> +{ REG_EXHCL, 0x40 },
>> +{ REG_ADC, 0x91 },
>> +{ REG_ACOM, 0x12 },
>> +{ REG_OFON, 0x43 },
>> +{ REG_NULL, 0 },
>>   };
>>   
>>   /* Determined empirically. */
>> -static const u8 ov965x_qvga_regs[NUM_FMT_REGS] = {
>> -0x10, 0x04, 0x80, 0x25, 0xc5, 0xbf, 0x00, 0x80, 0x12,
>> -0x10, 0x40, 0x91, 0x12, 0x43,
>> +static const struct i2c_rv ov965x_qvga_regs[] = {
>> +{ REG_COM7, 0x10 },
>> +{ REG_COM3, 0x04 },
>> +{ REG_COM4, 0x80 },
>> +{ REG_HSTART, 0x25 },
>> +{ REG_HSTOP, 0xc5 },
>> +{ 0x32, 0xbf },
>> +{ REG_VSTART, 0x00 },
>> +{ REG_VSTOP, 0x80 },
>> +{ REG_VREF, 0x12 },
>> +{ REG_EXHCH, 0x10 },
>> +{ REG_EXHCL, 0x40 },
>> +{ REG_ADC, 0x91 },
>> +{ REG_ACOM, 0x12 },
>> +{ REG_OFON, 0x43 },
>> +{ REG_NULL, 0 },
>>   };
>>   
>>   static const struct ov965x_framesize ov965x_framesizes[] = {
>> @@ -387,13 +423,6 @@ struct i2c_rv {
>>  },
>>   };
>>   
>> -struct ov965x_pixfmt {
>> -u32 code;
>> -u32 colorspace;
>> -/* REG_TSLB value, only bits [3:2] may be set. */
>> -u8 tslb_reg;
>> -};
> 
> Any particu

Re: [PATCH v2 1/7] DT bindings: add bindings for ov965x camera module

2017-07-05 Thread Hugues FRUCHET

On 07/05/2017 04:03 PM, Rob Herring wrote:
> On Mon, Jul 03, 2017 at 11:16:02AM +0200, Hugues Fruchet wrote:
>> From: "H. Nikolaus Schaller" <h...@goldelico.com>
>>
>> This adds documentation of device tree bindings
>> for the OV965X family camera sensor module.
>>
>> Signed-off-by: H. Nikolaus Schaller <h...@goldelico.com>
>> Signed-off-by: Hugues Fruchet <hugues.fruc...@st.com>
>> ---
>>   .../devicetree/bindings/media/i2c/ov965x.txt   | 45 
>> ++
>>   1 file changed, 45 insertions(+)
>>   create mode 100644 Documentation/devicetree/bindings/media/i2c/ov965x.txt
>>
>> diff --git a/Documentation/devicetree/bindings/media/i2c/ov965x.txt 
>> b/Documentation/devicetree/bindings/media/i2c/ov965x.txt
>> new file mode 100644
>> index 000..4ceb727
>> --- /dev/null
>> +++ b/Documentation/devicetree/bindings/media/i2c/ov965x.txt
>> @@ -0,0 +1,45 @@
>> +* Omnivision OV9650/9652/9655 CMOS sensor
>> +
>> +The Omnivision OV965x sensor support multiple resolutions output, such as
>> +CIF, SVGA, UXGA. It also can support YUV422/420, RGB565/555 or raw RGB
>> +output format.
>> +
>> +Required Properties:
>> +- compatible: should be one of
>> +"ovti,ov9650"
>> +"ovti,ov9652"
>> +"ovti,ov9655"
>> +- clocks: reference to the mclk input clock.
>> +
>> +Optional Properties:
>> +- resetb-gpios: reference to the GPIO connected to the RESETB pin, if any,
>> +polarity is active low.
> 
> reset-gpios
> 
>> +- pwdn-gpios: reference to the GPIO connected to the PWDN pin, if any,
>> +polarity is active high.
> 
> powerdown-gpios
> 
> Both are standardish names for such signals.
> 
> Rob

Thanks Rob, I will fix,
Hugues.

> 

Re: [PATCH v5 2/8] [media] stm32-dcmi: STM32 DCMI camera interface driver

2017-05-09 Thread Hugues FRUCHET
Hi Hans,
It's OK, feel free to change.
BR
Hugues.


On 05/06/2017 10:54 AM, Hans Verkuil wrote:
> Hi Hugues,
>
> On 05/05/2017 05:31 PM, Hugues Fruchet wrote:
>> This V4L2 subdev driver enables Digital Camera Memory Interface (DCMI)
>> of STMicroelectronics STM32 SoC series.
>>
>> Reviewed-by: Hans Verkuil <hans.verk...@cisco.com>
>> Signed-off-by: Yannick Fertre <yannick.fer...@st.com>
>> Signed-off-by: Hugues Fruchet <hugues.fruc...@st.com>
>> ---
>>  drivers/media/platform/Kconfig|   12 +
>>  drivers/media/platform/Makefile   |2 +
>>  drivers/media/platform/stm32/Makefile |1 +
>>  drivers/media/platform/stm32/stm32-dcmi.c | 1403 
>> +
>>  4 files changed, 1418 insertions(+)
>>  create mode 100644 drivers/media/platform/stm32/Makefile
>>  create mode 100644 drivers/media/platform/stm32/stm32-dcmi.c
>>
>> diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig
>> index ac026ee..de6e18b 100644
>> --- a/drivers/media/platform/Kconfig
>> +++ b/drivers/media/platform/Kconfig
>> @@ -114,6 +114,18 @@ config VIDEO_S3C_CAMIF
>>To compile this driver as a module, choose M here: the module
>>will be called s3c-camif.
>>
>> +config VIDEO_STM32_DCMI
>> +tristate "Digital Camera Memory Interface (DCMI) support"
>
> Is it OK with you if I change this to:
>
>   tristate "STM32 Digital Camera Memory Interface (DCMI) support"
>
> Right now the text gives no indication that this driver is for an STM32 
> platform.
>
> No need to spin a new patch, just let me know you're OK with it and I'll make
> the change.
>
> Regards,
>
>   Hans
>
>> +depends on VIDEO_V4L2 && OF && HAS_DMA
>> +depends on ARCH_STM32 || COMPILE_TEST
>> +select VIDEOBUF2_DMA_CONTIG
>> +---help---
>> +  This module makes the STM32 Digital Camera Memory Interface (DCMI)
>> +  available as a v4l2 device.
>> +
>> +  To compile this driver as a module, choose M here: the module
>> +  will be called stm32-dcmi.
>> +
>>  source "drivers/media/platform/soc_camera/Kconfig"
>>  source "drivers/media/platform/exynos4-is/Kconfig"
>>  source "drivers/media/platform/am437x/Kconfig"

[PATCH v1 4/6] [media] ov9650: use write_array() for resolution sequences

2017-06-22 Thread Hugues Fruchet
Align resolution sequences on initialization sequence using
i2c_rv structure NULL terminated .This add flexibility
on resolution sequence size.
Document resolution related registers by using corresponding
define instead of hexa address/value.

Signed-off-by: Hugues Fruchet <hugues.fruc...@st.com>
---
 drivers/media/i2c/ov9650.c | 98 ++
 1 file changed, 64 insertions(+), 34 deletions(-)

diff --git a/drivers/media/i2c/ov9650.c b/drivers/media/i2c/ov9650.c
index 4311da6..8b283c9 100644
--- a/drivers/media/i2c/ov9650.c
+++ b/drivers/media/i2c/ov9650.c
@@ -227,11 +227,16 @@ struct ov965x_ctrls {
u8 update;
 };
 
+struct i2c_rv {
+   u8 addr;
+   u8 value;
+};
+
 struct ov965x_framesize {
u16 width;
u16 height;
u16 max_exp_lines;
-   const u8 *regs;
+   const struct i2c_rv *regs;
 };
 
 struct ov965x_interval {
@@ -280,9 +285,11 @@ struct ov965x {
u8 apply_frame_fmt;
 };
 
-struct i2c_rv {
-   u8 addr;
-   u8 value;
+struct ov965x_pixfmt {
+   u32 code;
+   u32 colorspace;
+   /* REG_TSLB value, only bits [3:2] may be set. */
+   u8 tslb_reg;
 };
 
 static const struct i2c_rv ov965x_init_regs[] = {
@@ -342,30 +349,59 @@ struct i2c_rv {
{ REG_NULL, 0 }
 };
 
-#define NUM_FMT_REGS 14
-/*
- * COM7,  COM3,  COM4, HSTART, HSTOP, HREF, VSTART, VSTOP, VREF,
- * EXHCH, EXHCL, ADC,  OCOM,   OFON
- */
-static const u8 frame_size_reg_addr[NUM_FMT_REGS] = {
-   0x12, 0x0c, 0x0d, 0x17, 0x18, 0x32, 0x19, 0x1a, 0x03,
-   0x2a, 0x2b, 0x37, 0x38, 0x39,
-};
-
-static const u8 ov965x_sxga_regs[NUM_FMT_REGS] = {
-   0x00, 0x00, 0x00, 0x1e, 0xbe, 0xbf, 0x01, 0x81, 0x12,
-   0x10, 0x34, 0x81, 0x93, 0x51,
+static const struct i2c_rv ov965x_sxga_regs[] = {
+   { REG_COM7, 0x00 },
+   { REG_COM3, 0x00 },
+   { REG_COM4, 0x00 },
+   { REG_HSTART, 0x1e },
+   { REG_HSTOP, 0xbe },
+   { 0x32, 0xbf },
+   { REG_VSTART, 0x01 },
+   { REG_VSTOP, 0x81 },
+   { REG_VREF, 0x12 },
+   { REG_EXHCH, 0x10 },
+   { REG_EXHCL, 0x34 },
+   { REG_ADC, 0x81 },
+   { REG_ACOM, 0x93 },
+   { REG_OFON, 0x51 },
+   { REG_NULL, 0 },
 };
 
-static const u8 ov965x_vga_regs[NUM_FMT_REGS] = {
-   0x40, 0x04, 0x80, 0x26, 0xc6, 0xed, 0x01, 0x3d, 0x00,
-   0x10, 0x40, 0x91, 0x12, 0x43,
+static const struct i2c_rv ov965x_vga_regs[] = {
+   { REG_COM7, 0x40 },
+   { REG_COM3, 0x04 },
+   { REG_COM4, 0x80 },
+   { REG_HSTART, 0x26 },
+   { REG_HSTOP, 0xc6 },
+   { 0x32, 0xed },
+   { REG_VSTART, 0x01 },
+   { REG_VSTOP, 0x3d },
+   { REG_VREF, 0x00 },
+   { REG_EXHCH, 0x10 },
+   { REG_EXHCL, 0x40 },
+   { REG_ADC, 0x91 },
+   { REG_ACOM, 0x12 },
+   { REG_OFON, 0x43 },
+   { REG_NULL, 0 },
 };
 
 /* Determined empirically. */
-static const u8 ov965x_qvga_regs[NUM_FMT_REGS] = {
-   0x10, 0x04, 0x80, 0x25, 0xc5, 0xbf, 0x00, 0x80, 0x12,
-   0x10, 0x40, 0x91, 0x12, 0x43,
+static const struct i2c_rv ov965x_qvga_regs[] = {
+   { REG_COM7, 0x10 },
+   { REG_COM3, 0x04 },
+   { REG_COM4, 0x80 },
+   { REG_HSTART, 0x25 },
+   { REG_HSTOP, 0xc5 },
+   { 0x32, 0xbf },
+   { REG_VSTART, 0x00 },
+   { REG_VSTOP, 0x80 },
+   { REG_VREF, 0x12 },
+   { REG_EXHCH, 0x10 },
+   { REG_EXHCL, 0x40 },
+   { REG_ADC, 0x91 },
+   { REG_ACOM, 0x12 },
+   { REG_OFON, 0x43 },
+   { REG_NULL, 0 },
 };
 
 static const struct ov965x_framesize ov965x_framesizes[] = {
@@ -387,13 +423,6 @@ struct i2c_rv {
},
 };
 
-struct ov965x_pixfmt {
-   u32 code;
-   u32 colorspace;
-   /* REG_TSLB value, only bits [3:2] may be set. */
-   u8 tslb_reg;
-};
-
 static const struct ov965x_pixfmt ov965x_formats[] = {
{ MEDIA_BUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_JPEG, 0x00},
{ MEDIA_BUS_FMT_YVYU8_2X8, V4L2_COLORSPACE_JPEG, 0x04},
@@ -1268,11 +1297,12 @@ static int ov965x_set_fmt(struct v4l2_subdev *sd, 
struct v4l2_subdev_pad_config
 
 static int ov965x_set_frame_size(struct ov965x *ov965x)
 {
-   int i, ret = 0;
+   int ret = 0;
+
+   v4l2_dbg(1, debug, ov965x->client, "%s\n", __func__);
 
-   for (i = 0; ret == 0 && i < NUM_FMT_REGS; i++)
-   ret = ov965x_write(ov965x->client, frame_size_reg_addr[i],
-  ov965x->frame_size->regs[i]);
+   ret = ov965x_write_array(ov965x->client,
+ov965x->frame_size->regs);
return ret;
 }
 
-- 
1.9.1



[PATCH v1 0/6] Add support of OV9655 camera

2017-06-22 Thread Hugues Fruchet
This patchset enables OV9655 camera support.

OV9655 support has been tested using STM32F4DIS-CAM extension board
plugged on connector P1 of STM32F746G-DISCO board.
Due to lack of OV9650/52 hardware support, the modified related code
could not have been checked for non-regression.

First patches upgrade current support of OV9650/52 to prepare then
introduction of OV9655 variant patch.
Because of OV9655 register set slightly different from OV9650/9652,
not all of the driver features are supported (controls). Supported
resolutions are limited to VGA, QVGA, QQVGA.
Supported format is limited to RGB565.
Controls are limited to color bar test pattern for test purpose.

OV9655 initial support is based on a driver written by H. Nikolaus Schaller [1].
OV9655 registers sequences come from STM32CubeF7 embedded software [2].

[1] 
http://git.goldelico.com/?p=gta04-kernel.git;a=shortlog;h=refs/heads/work/hns/video/ov9655
[2] 
https://developer.mbed.org/teams/ST/code/BSP_DISCO_F746NG/file/e1d9da7fe856/Drivers/BSP/Components/ov9655/ov9655.c

===
= history =
===
version 1:
  - Initial submission.

H. Nikolaus Schaller (1):
  DT bindings: add bindings for ov965x camera module

Hugues Fruchet (5):
  [media] ov9650: add device tree support
  [media] ov9650: select the nearest higher resolution
  [media] ov9650: use write_array() for resolution sequences
  [media] ov9650: add multiple variant support
  [media] ov9650: add support of OV9655 variant

 .../devicetree/bindings/media/i2c/ov965x.txt   |  37 +
 drivers/media/i2c/Kconfig  |   6 +-
 drivers/media/i2c/ov9650.c | 792 +
 3 files changed, 704 insertions(+), 131 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/media/i2c/ov965x.txt

-- 
1.9.1



[PATCH v1 1/6] DT bindings: add bindings for ov965x camera module

2017-06-22 Thread Hugues Fruchet
From: "H. Nikolaus Schaller" <h...@goldelico.com>

This adds documentation of device tree bindings
for the OV965X family camera sensor module.

Signed-off-by: H. Nikolaus Schaller <h...@goldelico.com>
Signed-off-by: Hugues Fruchet <hugues.fruc...@st.com>
---
 .../devicetree/bindings/media/i2c/ov965x.txt   | 37 ++
 1 file changed, 37 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/i2c/ov965x.txt

diff --git a/Documentation/devicetree/bindings/media/i2c/ov965x.txt 
b/Documentation/devicetree/bindings/media/i2c/ov965x.txt
new file mode 100644
index 000..0e0de1f
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/i2c/ov965x.txt
@@ -0,0 +1,37 @@
+* Omnivision OV9650/9652/9655 CMOS sensor
+
+The Omnivision OV965x sensor support multiple resolutions output, such as
+CIF, SVGA, UXGA. It also can support YUV422/420, RGB565/555 or raw RGB
+output format.
+
+Required Properties:
+- compatible: should be one of
+   "ovti,ov9650"
+   "ovti,ov9652"
+   "ovti,ov9655"
+- clocks: reference to the mclk input clock.
+
+Optional Properties:
+- resetb-gpios: reference to the GPIO connected to the resetb pin, if any.
+- pwdn-gpios: reference to the GPIO connected to the pwdn pin, if any.
+
+The device node must contain one 'port' child node for its digital output
+video port, in accordance with the video interface bindings defined in
+Documentation/devicetree/bindings/media/video-interfaces.txt.
+
+Example:
+
+ {
+   ov9655: camera@30 {
+   compatible = "ovti,ov9655";
+   reg = <0x30>;
+   pwdn-gpios = < 13 GPIO_ACTIVE_HIGH>;
+   clocks = <_ext_camera>;
+
+   port {
+   ov9655: endpoint {
+   remote-endpoint = <_0>;
+   };
+   };
+   };
+};
-- 
1.9.1



[PATCH v1 5/6] [media] ov9650: add multiple variant support

2017-06-22 Thread Hugues Fruchet
Ops support and registers set can now be different
from a variant to another.

Signed-off-by: Hugues Fruchet <hugues.fruc...@st.com>
---
 drivers/media/i2c/ov9650.c | 141 +
 1 file changed, 91 insertions(+), 50 deletions(-)

diff --git a/drivers/media/i2c/ov9650.c b/drivers/media/i2c/ov9650.c
index 8b283c9..a9d268d 100644
--- a/drivers/media/i2c/ov9650.c
+++ b/drivers/media/i2c/ov9650.c
@@ -38,7 +38,7 @@
 module_param(debug, int, 0644);
 MODULE_PARM_DESC(debug, "Debug level (0-2)");
 
-#define DRIVER_NAME "OV9650"
+#define DRIVER_NAME "ov965x"
 
 /*
  * OV9650/OV9652 register definitions
@@ -257,6 +257,21 @@ struct ov965x {
struct media_pad pad;
enum v4l2_mbus_type bus_type;
struct gpio_desc *gpios[NUM_GPIOS];
+
+   /* Variant specific regs and ops */
+   const struct i2c_rv *init_regs;
+   const struct ov965x_framesize *framesizes;
+   unsigned int nb_of_framesizes;
+   const struct ov965x_pixfmt *formats;
+   unsigned int nb_of_formats;
+   const struct ov965x_interval *intervals;
+   unsigned int nb_of_intervals;
+   int (*initialize_controls)(struct ov965x *ov965x);
+   int (*set_frame_interval)(struct ov965x *ov965x,
+ struct v4l2_subdev_frame_interval *fi);
+   void (*update_exposure_ctrl)(struct ov965x *ov965x);
+   int (*set_params)(struct ov965x *ov965x);
+
/* External master clock frequency */
unsigned long mclk_frequency;
struct clk *clk;
@@ -576,7 +591,7 @@ static int ov965x_s_power(struct v4l2_subdev *sd, int on)
__ov965x_set_power(ov965x, on);
if (on) {
ret = ov965x_write_array(client,
-ov965x_init_regs);
+ov965x->init_regs);
ov965x->apply_frame_fmt = 1;
ov965x->ctrls.update = 1;
}
@@ -1090,12 +1105,13 @@ static int ov965x_initialize_controls(struct ov965x 
*ov965x)
 /*
  * V4L2 subdev video and pad level operations
  */
-static void ov965x_get_default_format(struct v4l2_mbus_framefmt *mf)
+static void ov965x_get_default_format(struct ov965x *ov965x,
+ struct v4l2_mbus_framefmt *mf)
 {
-   mf->width = ov965x_framesizes[0].width;
-   mf->height = ov965x_framesizes[0].height;
-   mf->colorspace = ov965x_formats[0].colorspace;
-   mf->code = ov965x_formats[0].code;
+   mf->width = ov965x->framesizes[0].width;
+   mf->height = ov965x->framesizes[0].height;
+   mf->colorspace = ov965x->formats[0].colorspace;
+   mf->code = ov965x->formats[0].code;
mf->field = V4L2_FIELD_NONE;
 }
 
@@ -1103,10 +1119,12 @@ static int ov965x_enum_mbus_code(struct v4l2_subdev *sd,
 struct v4l2_subdev_pad_config *cfg,
 struct v4l2_subdev_mbus_code_enum *code)
 {
-   if (code->index >= ARRAY_SIZE(ov965x_formats))
+   struct ov965x *ov965x = to_ov965x(sd);
+
+   if (code->index >= ov965x->nb_of_formats)
return -EINVAL;
 
-   code->code = ov965x_formats[code->index].code;
+   code->code = ov965x->formats[code->index].code;
return 0;
 }
 
@@ -1114,22 +1132,22 @@ static int ov965x_enum_frame_sizes(struct v4l2_subdev 
*sd,
   struct v4l2_subdev_pad_config *cfg,
   struct v4l2_subdev_frame_size_enum *fse)
 {
-   int i = ARRAY_SIZE(ov965x_formats);
+   struct ov965x *ov965x = to_ov965x(sd);
+   int i = ov965x->nb_of_formats;
 
-   if (fse->index >= ARRAY_SIZE(ov965x_framesizes))
+   if (fse->index >= ov965x->nb_of_framesizes)
return -EINVAL;
 
while (--i)
-   if (fse->code == ov965x_formats[i].code)
+   if (fse->code == ov965x->formats[i].code)
break;
 
-   fse->code = ov965x_formats[i].code;
+   fse->code = ov965x->formats[i].code;
 
-   fse->min_width  = ov965x_framesizes[fse->index].width;
+   fse->min_width  = ov965x->framesizes[fse->index].width;
fse->max_width  = fse->min_width;
-   fse->max_height = ov965x_framesizes[fse->index].height;
+   fse->max_height = ov965x->framesizes[fse->index].height;
fse->min_height = fse->max_height;
-
return 0;
 }
 
@@ -1138,6 +1156,9 @@ static int ov965x_g_frame_interval(struct v4l2_subdev *sd,
 {
struct ov965x *ov965x = to_ov965x(sd);
 
+   if (!ov965x->fiv)
+   return 0;
+
mutex_lock(>lock);
fi->interval = ov965x->fiv->interval;
mutex_unlock(>lock);
@@ -1146,13 +1167,

[PATCH v1 6/6] [media] ov9650: add support of OV9655 variant

2017-06-22 Thread Hugues Fruchet
Add a first support of OV9655 variant.
Because of register set slightly different from OV9650/9652,
not all of the driver features are supported (controls).
Supported resolutions are limited to VGA, QVGA, QQVGA.
Supported format is limited to RGB565.
Controls are limited to color bar test pattern for test purpose.

Signed-off-by: H. Nikolaus Schaller <h...@goldelico.com>
Signed-off-by: Hugues Fruchet <hugues.fruc...@st.com>
---
 drivers/media/i2c/Kconfig  |   4 +-
 drivers/media/i2c/ov9650.c | 486 ++---
 2 files changed, 457 insertions(+), 33 deletions(-)

diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index efea14d..a8f638c 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -594,11 +594,11 @@ config VIDEO_OV7670
  controller.
 
 config VIDEO_OV9650
-   tristate "OmniVision OV9650/OV9652 sensor support"
+   tristate "OmniVision OV9650/OV9652/OV9655 sensor support"
depends on GPIOLIB && I2C && VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API
---help---
  This is a V4L2 sensor-level driver for the Omnivision
- OV9650 and OV9652 camera sensors.
+ OV9650 and OV9652 and OV9655 camera sensors.
 
 config VIDEO_VS6624
tristate "ST VS6624 sensor support"
diff --git a/drivers/media/i2c/ov9650.c b/drivers/media/i2c/ov9650.c
index a9d268d..c0819af 100644
--- a/drivers/media/i2c/ov9650.c
+++ b/drivers/media/i2c/ov9650.c
@@ -1,5 +1,5 @@
 /*
- * Omnivision OV9650/OV9652 CMOS Image Sensor driver
+ * Omnivision OV9650/OV9652/OV9655 CMOS Image Sensor driver
  *
  * Copyright (C) 2013, Sylwester Nawrocki <sylvester.nawro...@gmail.com>
  *
@@ -7,6 +7,15 @@
  * by Vladimir Fonov.
  * Copyright (c) 2010, Vladimir Fonov
  *
+ *
+ * Copyright (C) STMicroelectronics SA 2017
+ * Author: Hugues Fruchet <hugues.fruc...@st.com> for STMicroelectronics.
+ *
+ * OV9655 initial support based on a driver written by H. Nikolaus Schaller:
+ *   
http://git.goldelico.com/?p=gta04-kernel.git;a=shortlog;h=refs/heads/work/hns/video/ov9655
+ * OV9655 registers sequence from STM32CubeF7 embedded software, see:
+ *   
https://developer.mbed.org/teams/ST/code/BSP_DISCO_F746NG/file/e1d9da7fe856/Drivers/BSP/Components/ov9655/ov9655.c
+ *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 as
  * published by the Free Software Foundation.
@@ -58,14 +67,21 @@
 #define REG_PID0x0a/* Product ID MSB */
 #define REG_VER0x0b/* Product ID LSB */
 #define REG_COM3   0x0c
-#define  COM3_SWAP 0x40
+#define  COM3_COLORBAR 0x80
+#define  COM3_RGB565   0x00
+#define  COM3_SWAP 0x40/* Doesn't work in RGB */
+#define  COM3_RESETB   0x08
 #define  COM3_VARIOPIXEL1  0x04
+#define  OV9655_SINGLEFRAME0x01
 #define REG_COM4   0x0d/* Vario Pixels  */
 #define  COM4_VARIOPIXEL2  0x80
+#define  OV9655_TRISTATE   /* seems to have a different function */
 #define REG_COM5   0x0e/* System clock options */
 #define  COM5_SLAVE_MODE   0x10
-#define  COM5_SYSTEMCLOCK48MHZ 0x80
+#define  COM5_SYSTEMCLOCK48MHZ 0x80/* not on OV9655 */
+#define  OV9655_EXPOSURESTEP   0x01
 #define REG_COM6   0x0f/* HREF & ADBLC options */
+#define  COM6_BLC_OPTICAL  0x40/* Optical black */
 #define REG_AECH   0x10/* Exposure value, AEC[9:2] */
 #define REG_CLKRC  0x11/* Clock control */
 #define  CLK_EXT   0x40/* Use external clock directly */
@@ -74,13 +90,18 @@
 #define  COM7_RESET0x80
 #define  COM7_FMT_MASK 0x38
 #define  COM7_FMT_VGA  0x40
-#define COM7_FMT_CIF   0x20
+#define  COM7_FMT_CIF  0x20
 #define  COM7_FMT_QVGA 0x10
 #define  COM7_FMT_QCIF 0x08
-#define COM7_RGB   0x04
-#define COM7_YUV   0x00
-#define COM7_BAYER 0x01
-#define COM7_PBAYER0x05
+#define  COM7_RGB  0x04
+#define  COM7_YUV  0x00
+#define  COM7_BAYER0x01
+#define  COM7_PBAYER   0x05
+#define  OV9655_COM7_VGA   0x60
+#define  OV9655_COM7_RAWRGB0x00/* different format encoding */
+#define  OV9655_COM7_RAWRGBINT 0x01
+#define  OV9655_COM7_YUV   0x02
+#define  OV9655_COM7_RGB   0x03
 #define REG_COM8   0x13/* AGC/AEC options */
 #define  COM8_FASTAEC  0x80/* Enable fast AGC/AEC */
 #define  COM8_AECSTEP  0x40/* Unlimited AEC step size */
@@ -89,14 +110,23 @@
 #define  COM8_AWB  0x02/* White balance enable */
 #define  COM8_AEC  0x01/* Auto exposure enable */
 #define REG_COM9  

[PATCH v1 3/6] [media] ov9650: select the nearest higher resolution

2017-06-22 Thread Hugues Fruchet
Refine the resolution selection algorithm by selecting
only the nearest higher resolution (instead of lower and higher).

Signed-off-by: Hugues Fruchet <hugues.fruc...@st.com>
---
 drivers/media/i2c/ov9650.c | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/media/i2c/ov9650.c b/drivers/media/i2c/ov9650.c
index 8340a45..4311da6 100644
--- a/drivers/media/i2c/ov9650.c
+++ b/drivers/media/i2c/ov9650.c
@@ -1196,9 +1196,11 @@ static void __ov965x_try_frame_size(struct 
v4l2_mbus_framefmt *mf,
unsigned int min_err = UINT_MAX;
 
while (i--) {
-   int err = abs(fsize->width - mf->width)
-   + abs(fsize->height - mf->height);
-   if (err < min_err) {
+   int w_err = (fsize->width - mf->width);
+   int h_err = (fsize->height - mf->height);
+   int err = w_err + h_err;
+
+   if ((w_err >= 0) && (h_err >= 0) && (err < min_err)) {
min_err = err;
match = fsize;
}
-- 
1.9.1



[PATCH v1 2/6] [media] ov9650: add device tree support

2017-06-22 Thread Hugues Fruchet
Allows use of device tree configuration data.
If no device tree data is there, configuration is taken from platform data.
In order to keep GPIOs configuration compatible between both way of doing,
GPIOs are switched to descriptor-based interface.

Signed-off-by: H. Nikolaus Schaller <h...@goldelico.com>
Signed-off-by: Hugues Fruchet <hugues.fruc...@st.com>
---
 drivers/media/i2c/Kconfig  |  2 +-
 drivers/media/i2c/ov9650.c | 81 ++
 2 files changed, 61 insertions(+), 22 deletions(-)

diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index c380e24..efea14d 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -595,7 +595,7 @@ config VIDEO_OV7670
 
 config VIDEO_OV9650
tristate "OmniVision OV9650/OV9652 sensor support"
-   depends on I2C && VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API
+   depends on GPIOLIB && I2C && VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API
---help---
  This is a V4L2 sensor-level driver for the Omnivision
  OV9650 and OV9652 camera sensors.
diff --git a/drivers/media/i2c/ov9650.c b/drivers/media/i2c/ov9650.c
index 2de2fbb..8340a45 100644
--- a/drivers/media/i2c/ov9650.c
+++ b/drivers/media/i2c/ov9650.c
@@ -11,12 +11,14 @@
  * 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 
@@ -249,9 +251,10 @@ struct ov965x {
struct v4l2_subdev sd;
struct media_pad pad;
enum v4l2_mbus_type bus_type;
-   int gpios[NUM_GPIOS];
+   struct gpio_desc *gpios[NUM_GPIOS];
/* External master clock frequency */
unsigned long mclk_frequency;
+   struct clk *clk;
 
/* Protects the struct fields below */
struct mutex lock;
@@ -511,10 +514,10 @@ static int ov965x_set_color_matrix(struct ov965x *ov965x)
return 0;
 }
 
-static void ov965x_gpio_set(int gpio, int val)
+static void ov965x_gpio_set(struct gpio_desc *gpio, int val)
 {
-   if (gpio_is_valid(gpio))
-   gpio_set_value(gpio, val);
+   if (gpio)
+   gpiod_set_value_cansleep(gpio, val);
 }
 
 static void __ov965x_set_power(struct ov965x *ov965x, int on)
@@ -1406,24 +1409,28 @@ static int ov965x_configure_gpios(struct ov965x *ov965x,
  const struct ov9650_platform_data *pdata)
 {
int ret, i;
+   int gpios[NUM_GPIOS];
 
-   ov965x->gpios[GPIO_PWDN] = pdata->gpio_pwdn;
-   ov965x->gpios[GPIO_RST]  = pdata->gpio_reset;
+   gpios[GPIO_PWDN] = pdata->gpio_pwdn;
+   gpios[GPIO_RST]  = pdata->gpio_reset;
 
-   for (i = 0; i < ARRAY_SIZE(ov965x->gpios); i++) {
-   int gpio = ov965x->gpios[i];
+   for (i = 0; i < ARRAY_SIZE(gpios); i++) {
+   int gpio = gpios[i];
 
if (!gpio_is_valid(gpio))
continue;
ret = devm_gpio_request_one(>client->dev, gpio,
-   GPIOF_OUT_INIT_HIGH, "OV965X");
-   if (ret < 0)
+   GPIOF_OUT_INIT_HIGH, DRIVER_NAME);
+   if (ret < 0) {
+   dev_err(>client->dev,
+   "Failed to request gpio%d (%d)\n", gpio, ret);
return ret;
+   }
v4l2_dbg(1, debug, >sd, "set gpio %d to 1\n", gpio);
 
gpio_set_value(gpio, 1);
gpio_export(gpio, 0);
-   ov965x->gpios[i] = gpio;
+   ov965x->gpios[i] = gpio_to_desc(gpio);
}
 
return 0;
@@ -1469,14 +1476,10 @@ static int ov965x_probe(struct i2c_client *client,
struct v4l2_subdev *sd;
struct ov965x *ov965x;
int ret;
+   struct device_node *np = client->dev.of_node;
 
-   if (pdata == NULL) {
-   dev_err(>dev, "platform data not specified\n");
-   return -EINVAL;
-   }
-
-   if (pdata->mclk_frequency == 0) {
-   dev_err(>dev, "MCLK frequency not specified\n");
+   if (!pdata && !np) {
+   dev_err(>dev, "Platform data or device tree data must 
be provided\n");
return -EINVAL;
}
 
@@ -1486,7 +1489,36 @@ static int ov965x_probe(struct i2c_client *client,
 
mutex_init(>lock);
ov965x->client = client;
-   ov965x->mclk_frequency = pdata->mclk_frequency;
+   mutex_init(>lock);
+
+   if (np) {
+   /* Device tree */
+   ov965x->gpios[GPIO_RST] =
+   devm_gpiod_get_optional(>dev, "resetb",
+

[PATCH v1 3/5] [media] stm32-dcmi: crop sensor image to match user resolution

2017-06-22 Thread Hugues Fruchet
Add flexibility on supported resolutions by cropping sensor
image to fit user resolution format request.

Signed-off-by: Hugues Fruchet <hugues.fruc...@st.com>
---
 drivers/media/platform/stm32/stm32-dcmi.c | 54 ++-
 1 file changed, 53 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/stm32/stm32-dcmi.c 
b/drivers/media/platform/stm32/stm32-dcmi.c
index 75d53aa..bc5e052 100644
--- a/drivers/media/platform/stm32/stm32-dcmi.c
+++ b/drivers/media/platform/stm32/stm32-dcmi.c
@@ -131,6 +131,8 @@ struct stm32_dcmi {
struct v4l2_async_notifier  notifier;
struct dcmi_graph_entityentity;
struct v4l2_format  fmt;
+   struct v4l2_rectcrop;
+   booldo_crop;
 
const struct dcmi_format**user_formats;
unsigned intnum_user_formats;
@@ -538,6 +540,27 @@ static int dcmi_start_streaming(struct vb2_queue *vq, 
unsigned int count)
if (dcmi->bus.flags & V4L2_MBUS_PCLK_SAMPLE_RISING)
val |= CR_PCKPOL;
 
+   if (dcmi->do_crop) {
+   u32 size, start;
+
+   /* Crop resolution */
+   size = ((dcmi->crop.height - 1) << 16) |
+   ((dcmi->crop.width << 1) - 1);
+   reg_write(dcmi->regs, DCMI_CWSIZE, size);
+
+   /* Crop start point */
+   start = ((dcmi->crop.top) << 16) |
+((dcmi->crop.left << 1));
+   reg_write(dcmi->regs, DCMI_CWSTRT, start);
+
+   dev_dbg(dcmi->dev, "Cropping to %ux%u@%u:%u\n",
+   dcmi->crop.width, dcmi->crop.height,
+   dcmi->crop.left, dcmi->crop.top);
+
+   /* Enable crop */
+   val |= CR_CROP;
+   };
+
reg_write(dcmi->regs, DCMI_CR, val);
 
/* Enable dcmi */
@@ -707,6 +730,8 @@ static int dcmi_try_fmt(struct stm32_dcmi *dcmi, struct 
v4l2_format *f,
.which = V4L2_SUBDEV_FORMAT_TRY,
};
int ret;
+   __u32 width, height;
+   struct v4l2_mbus_framefmt *mf = 
 
dcmi_fmt = find_format_by_fourcc(dcmi, pixfmt->pixelformat);
if (!dcmi_fmt) {
@@ -724,8 +749,18 @@ static int dcmi_try_fmt(struct stm32_dcmi *dcmi, struct 
v4l2_format *f,
if (ret < 0)
return ret;
 
+   /* Align format on what sensor can do */
+   width = pixfmt->width;
+   height = pixfmt->height;
v4l2_fill_pix_format(pixfmt, );
 
+   /* We can do any resolution thanks to crop */
+   if ((mf->width > width) || (mf->height > height)) {
+   /* Restore width/height */
+   pixfmt->width = width;
+   pixfmt->height = height;
+   };
+
pixfmt->field = V4L2_FIELD_NONE;
pixfmt->bytesperline = pixfmt->width * dcmi_fmt->bpp;
pixfmt->sizeimage = pixfmt->bytesperline * pixfmt->height;
@@ -741,6 +776,8 @@ static int dcmi_set_fmt(struct stm32_dcmi *dcmi, struct 
v4l2_format *f)
struct v4l2_subdev_format format = {
.which = V4L2_SUBDEV_FORMAT_ACTIVE,
};
+   struct v4l2_mbus_framefmt *mf = 
+   struct v4l2_pix_format *pixfmt = >fmt.pix;
const struct dcmi_format *current_fmt;
int ret;
 
@@ -748,13 +785,28 @@ static int dcmi_set_fmt(struct stm32_dcmi *dcmi, struct 
v4l2_format *f)
if (ret)
return ret;
 
-   v4l2_fill_mbus_format(, >fmt.pix,
+   v4l2_fill_mbus_format(, pixfmt,
  current_fmt->mbus_code);
ret = v4l2_subdev_call(dcmi->entity.subdev, pad,
   set_fmt, NULL, );
if (ret < 0)
return ret;
 
+   /* Enable crop if sensor resolution is larger than request */
+   dcmi->do_crop = false;
+   if ((mf->width > pixfmt->width) || (mf->height > pixfmt->height)) {
+   dcmi->crop.width = pixfmt->width;
+   dcmi->crop.height = pixfmt->height;
+   dcmi->crop.left = (mf->width - pixfmt->width) / 2;
+   dcmi->crop.top = (mf->height - pixfmt->height) / 2;
+   dcmi->do_crop = true;
+
+   dev_dbg(dcmi->dev, "%ux%u cropped to %ux%u@(%u,%u)\n",
+   mf->width, mf->height,
+   dcmi->crop.width, dcmi->crop.height,
+   dcmi->crop.left, dcmi->crop.top);
+   };
+
dcmi->fmt = *f;
dcmi->current_fmt = current_fmt;
 
-- 
1.9.1



[PATCH v1 0/5] Camera support on STM32F746G-DISCO board

2017-06-22 Thread Hugues Fruchet
This patchset enables OV9655 camera support of STM32F4DIS-CAM extension
board plugged on connector P1 of STM32F746G-DISCO board.

Tested by doing a fullscreen preview with a modified version of yavta [1]
which redirects captured frames to framebuffer:
 yavta -s 480x272 -n 1 --capture=-1 /dev/video0 -D (note the unofficial
 "-D" option for "Display output")

First part of patches brings few fixes in DCMI driver and introduces
internal crop support in order to enable fullscreen preview (480x272)
by cropping VGA sensor output.

Second part relates to devicetree and configuration to enable DCMI on
STM32F746 MCU then enable DCMI and OV9655 support on STM32F746G-DISCO [2].

[1] http://git.ideasonboard.org/?p=yavta.git;a=summary
[2] due to STM32F746G-DISCO support not yet in media tree (4.13-rc1),
devicetree patches related to STM32F746G-DISCO are not yet provided.

===
= history =
===
version 1:
  - Initial submission for code review with restrictions [2].


Hugues Fruchet (5):
  [media] stm32-dcmi: catch dma submission error
  [media] stm32-dcmi: revisit control register handling
  [media] stm32-dcmi: crop sensor image to match user resolution
  ARM: dts: stm32: Enable DCMI support on STM32F746 MCU
  ARM: configs: stm32: DCMI + OV9655 camera support

 arch/arm/boot/dts/stm32f746.dtsi  | 31 +
 arch/arm/configs/stm32_defconfig  |  9 
 drivers/media/platform/stm32/stm32-dcmi.c | 72 ++-
 3 files changed, 101 insertions(+), 11 deletions(-)

-- 
1.9.1



[PATCH v1 2/5] [media] stm32-dcmi: revisit control register handling

2017-06-22 Thread Hugues Fruchet
Simplify bits handling of DCMI_CR register.

Signed-off-by: Hugues Fruchet <hugues.fruc...@st.com>
---
 drivers/media/platform/stm32/stm32-dcmi.c | 14 --
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/drivers/media/platform/stm32/stm32-dcmi.c 
b/drivers/media/platform/stm32/stm32-dcmi.c
index 0dd5d1c..75d53aa 100644
--- a/drivers/media/platform/stm32/stm32-dcmi.c
+++ b/drivers/media/platform/stm32/stm32-dcmi.c
@@ -490,7 +490,7 @@ static int dcmi_start_streaming(struct vb2_queue *vq, 
unsigned int count)
 {
struct stm32_dcmi *dcmi = vb2_get_drv_priv(vq);
struct dcmi_buf *buf, *node;
-   u32 val;
+   u32 val = 0;
int ret;
 
ret = clk_enable(dcmi->mclk);
@@ -510,22 +510,16 @@ static int dcmi_start_streaming(struct vb2_queue *vq, 
unsigned int count)
 
spin_lock_irq(>irqlock);
 
-   val = reg_read(dcmi->regs, DCMI_CR);
-
-   val &= ~(CR_PCKPOL | CR_HSPOL | CR_VSPOL |
-CR_EDM_0 | CR_EDM_1 | CR_FCRC_0 |
-CR_FCRC_1 | CR_JPEG | CR_ESS);
-
/* Set bus width */
switch (dcmi->bus.bus_width) {
case 14:
-   val &= CR_EDM_0 + CR_EDM_1;
+   val |= CR_EDM_0 | CR_EDM_1;
break;
case 12:
-   val &= CR_EDM_1;
+   val |= CR_EDM_1;
break;
case 10:
-   val &= CR_EDM_0;
+   val |= CR_EDM_0;
break;
default:
/* Set bus width to 8 bits by default */
-- 
1.9.1



[PATCH v1 1/5] [media] stm32-dcmi: catch dma submission error

2017-06-22 Thread Hugues Fruchet
Test cookie return by dmaengine_submit() and return error if any.

Signed-off-by: Hugues Fruchet <hugues.fruc...@st.com>
---
 drivers/media/platform/stm32/stm32-dcmi.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/media/platform/stm32/stm32-dcmi.c 
b/drivers/media/platform/stm32/stm32-dcmi.c
index 83d32a5..0dd5d1c 100644
--- a/drivers/media/platform/stm32/stm32-dcmi.c
+++ b/drivers/media/platform/stm32/stm32-dcmi.c
@@ -295,6 +295,10 @@ static int dcmi_start_dma(struct stm32_dcmi *dcmi,
 
/* Push current DMA transaction in the pending queue */
dcmi->dma_cookie = dmaengine_submit(desc);
+   if (dma_submit_error(dcmi->dma_cookie)) {
+   dev_err(dcmi->dev, "%s: DMA submission failed\n", __func__);
+   return -ENXIO;
+   }
 
dma_async_issue_pending(dcmi->dma_chan);
 
-- 
1.9.1



[PATCH v1 4/5] ARM: dts: stm32: Enable DCMI support on STM32F746 MCU

2017-06-22 Thread Hugues Fruchet
Enable DCMI camera interface on STM32F746 MCU.

Signed-off-by: Hugues Fruchet <hugues.fruc...@st.com>
---
 arch/arm/boot/dts/stm32f746.dtsi | 31 +++
 1 file changed, 31 insertions(+)

diff --git a/arch/arm/boot/dts/stm32f746.dtsi b/arch/arm/boot/dts/stm32f746.dtsi
index c2765ce..4bdf37c 100644
--- a/arch/arm/boot/dts/stm32f746.dtsi
+++ b/arch/arm/boot/dts/stm32f746.dtsi
@@ -326,6 +326,23 @@
bias-disable;
};
};
+
+   dcmi_pins: dcmi_pins@0 {
+   pins {
+   pinmux = 
,
+
,
+
,
+,
+,
+,
+,
+,
+,
+,
+;
+   slew-rate = <3>;
+   };
+   };
};
 
crc: crc@40023000 {
@@ -344,6 +361,20 @@
assigned-clocks = < 1 CLK_HSE_RTC>;
assigned-clock-rates = <100>;
};
+
+   dcmi: dcmi@5005 {
+   compatible = "st,stm32-dcmi";
+   reg = <0x5005 0x400>;
+   interrupts = <78>;
+   resets = < STM32F7_AHB2_RESET(DCMI)>;
+   clocks = < 0 STM32F7_AHB2_CLOCK(DCMI)>;
+   clock-names = "mclk";
+   pinctrl-names = "default";
+   pinctrl-0 = <_pins>;
+   dmas = < 1 1 0x414 0x3>;
+   dma-names = "tx";
+   status = "disabled";
+   };
};
 };
 
-- 
1.9.1



[PATCH v1 5/5] ARM: configs: stm32: DCMI + OV9655 camera support

2017-06-22 Thread Hugues Fruchet
Enable DCMI camera interface and OV9655 camera sensor drivers.

Signed-off-by: Hugues Fruchet <hugues.fruc...@st.com>
---
 arch/arm/configs/stm32_defconfig | 9 +
 1 file changed, 9 insertions(+)

diff --git a/arch/arm/configs/stm32_defconfig b/arch/arm/configs/stm32_defconfig
index a097538..0c3cd01 100644
--- a/arch/arm/configs/stm32_defconfig
+++ b/arch/arm/configs/stm32_defconfig
@@ -55,6 +55,15 @@ CONFIG_I2C_STM32F4=y
 CONFIG_REGULATOR=y
 CONFIG_REGULATOR_FIXED_VOLTAGE=y
 # CONFIG_USB_SUPPORT is not set
+CONFIG_VIDEO_V4L2=y
+CONFIG_MEDIA_CONTROLLER=y
+CONFIG_VIDEO_V4L2_SUBDEV_API=y
+CONFIG_MEDIA_SUBDRV_AUTOSELECT=n
+CONFIG_V4L_PLATFORM_DRIVERS=y
+CONFIG_MEDIA_SUPPORT=y
+CONFIG_MEDIA_CAMERA_SUPPORT=y
+CONFIG_VIDEO_STM32_DCMI=y
+CONFIG_VIDEO_OV9650=y
 CONFIG_NEW_LEDS=y
 CONFIG_LEDS_CLASS=y
 CONFIG_LEDS_GPIO=y
-- 
1.9.1



Re: [PATCH v1 6/6] [media] ov9650: add support of OV9655 variant

2017-06-26 Thread Hugues FRUCHET


On 06/26/2017 08:03 AM, H. Nikolaus Schaller wrote:
> 
>> Am 22.06.2017 um 17:05 schrieb Hugues Fruchet <hugues.fruc...@st.com>:
>>
>> Add a first support of OV9655 variant.
>> Because of register set slightly different from OV9650/9652,
>> not all of the driver features are supported (controls).
>> Supported resolutions are limited to VGA, QVGA, QQVGA.
>> Supported format is limited to RGB565.
>> Controls are limited to color bar test pattern for test purpose.
>>
>> Signed-off-by: H. Nikolaus Schaller <h...@goldelico.com>
>> Signed-off-by: Hugues Fruchet <hugues.fruc...@st.com>
>> ---
>> drivers/media/i2c/Kconfig  |   4 +-
>> drivers/media/i2c/ov9650.c | 486 
>> ++---
>> 2 files changed, 457 insertions(+), 33 deletions(-)
>>
>> diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
>> index efea14d..a8f638c 100644
>> --- a/drivers/media/i2c/Kconfig
>> +++ b/drivers/media/i2c/Kconfig
>> @@ -594,11 +594,11 @@ config VIDEO_OV7670
>>controller.
>>
>> config VIDEO_OV9650
>> -tristate "OmniVision OV9650/OV9652 sensor support"
>> +tristate "OmniVision OV9650/OV9652/OV9655 sensor support"
>>  depends on GPIOLIB && I2C && VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API
>>  ---help---
>>This is a V4L2 sensor-level driver for the Omnivision
>> -  OV9650 and OV9652 camera sensors.
>> +  OV9650 and OV9652 and OV9655 camera sensors.
>>
>> config VIDEO_VS6624
>>  tristate "ST VS6624 sensor support"
>> diff --git a/drivers/media/i2c/ov9650.c b/drivers/media/i2c/ov9650.c
>> index a9d268d..c0819af 100644
>> --- a/drivers/media/i2c/ov9650.c
>> +++ b/drivers/media/i2c/ov9650.c
>> @@ -1,5 +1,5 @@
>> /*
>> - * Omnivision OV9650/OV9652 CMOS Image Sensor driver
>> + * Omnivision OV9650/OV9652/OV9655 CMOS Image Sensor driver
>>   *
>>   * Copyright (C) 2013, Sylwester Nawrocki <sylvester.nawro...@gmail.com>
>>   *
>> @@ -7,6 +7,15 @@
>>   * by Vladimir Fonov.
>>   * Copyright (c) 2010, Vladimir Fonov
>>   *
>> + *
>> + * Copyright (C) STMicroelectronics SA 2017
>> + * Author: Hugues Fruchet <hugues.fruc...@st.com> for STMicroelectronics.
>> + *
>> + * OV9655 initial support based on a driver written by H. Nikolaus Schaller:
>> + *   
>> http://git.goldelico.com/?p=gta04-kernel.git;a=shortlog;h=refs/heads/work/hns/video/ov9655
>> + * OV9655 registers sequence from STM32CubeF7 embedded software, see:
>> + *   
>> https://developer.mbed.org/teams/ST/code/BSP_DISCO_F746NG/file/e1d9da7fe856/Drivers/BSP/Components/ov9655/ov9655.c
>> + *
>>   * This program is free software; you can redistribute it and/or modify
>>   * it under the terms of the GNU General Public License version 2 as
>>   * published by the Free Software Foundation.
>> @@ -58,14 +67,21 @@
>> #define REG_PID  0x0a/* Product ID MSB */
>> #define REG_VER  0x0b/* Product ID LSB */
>> #define REG_COM3 0x0c
>> -#define  COM3_SWAP  0x40
>> +#define  COM3_COLORBAR  0x80
>> +#define  COM3_RGB5650x00
>> +#define  COM3_SWAP  0x40/* Doesn't work in RGB */
>> +#define  COM3_RESETB0x08
>> #define  COM3_VARIOPIXEL10x04
>> +#define  OV9655_SINGLEFRAME 0x01
>> #define REG_COM4 0x0d/* Vario Pixels  */
>> #define  COM4_VARIOPIXEL20x80
>> +#define  OV9655_TRISTATE/* seems to have a different function */
>> #define REG_COM5 0x0e/* System clock options */
>> #define  COM5_SLAVE_MODE 0x10
>> -#define  COM5_SYSTEMCLOCK48MHZ  0x80
>> +#define  COM5_SYSTEMCLOCK48MHZ  0x80/* not on OV9655 */
>> +#define  OV9655_EXPOSURESTEP0x01
>> #define REG_COM6 0x0f/* HREF & ADBLC options */
>> +#define  COM6_BLC_OPTICAL   0x40/* Optical black */
>> #define REG_AECH 0x10/* Exposure value, AEC[9:2] */
>> #define REG_CLKRC0x11/* Clock control */
>> #define  CLK_EXT 0x40/* Use external clock directly */
>> @@ -74,13 +90,18 @@
>> #define  COM7_RESET  0x80
>> #define  COM7_FMT_MASK   0x38
>> #define  COM7_FMT_VGA0x40
>> -#define  COM7_FMT_CIF   0x20
>> +#define  COM7_FMT_CIF   0x20
>> #define  COM7_FMT_QVGA   0x10
>> #define  COM7_FMT_QCIF   

Re: [PATCH v1 3/5] [media] stm32-dcmi: crop sensor image to match user resolution

2017-06-26 Thread Hugues FRUCHET


On 06/26/2017 12:07 PM, Hans Verkuil wrote:
> On 26/06/17 11:53, Hugues FRUCHET wrote:
>> Hi Hans, thanks for review.
>>
>> Reply below.
>>
>> BR
>> Hugues.
>>
>> On 06/22/2017 05:19 PM, Hans Verkuil wrote:
>>> On 06/22/2017 05:12 PM, Hugues Fruchet wrote:
>>>> Add flexibility on supported resolutions by cropping sensor
>>>> image to fit user resolution format request.
>>>>
>>>> Signed-off-by: Hugues Fruchet <hugues.fruc...@st.com>
>>>> ---
>>>> drivers/media/platform/stm32/stm32-dcmi.c | 54 
>>>> ++-
>>>> 1 file changed, 53 insertions(+), 1 deletion(-)
>>>>
>>>> diff --git a/drivers/media/platform/stm32/stm32-dcmi.c 
>>>> b/drivers/media/platform/stm32/stm32-dcmi.c
>>>> index 75d53aa..bc5e052 100644
>>>> --- a/drivers/media/platform/stm32/stm32-dcmi.c
>>>> +++ b/drivers/media/platform/stm32/stm32-dcmi.c
>>>> @@ -131,6 +131,8 @@ struct stm32_dcmi {
>>>>struct v4l2_async_notifier  notifier;
>>>>struct dcmi_graph_entityentity;
>>>>struct v4l2_format  fmt;
>>>> +  struct v4l2_rectcrop;
>>>> +  booldo_crop;
>>>> 
>>>>const struct dcmi_format**user_formats;
>>>>unsigned intnum_user_formats;
>>>> @@ -538,6 +540,27 @@ static int dcmi_start_streaming(struct vb2_queue *vq, 
>>>> unsigned int count)
>>>>if (dcmi->bus.flags & V4L2_MBUS_PCLK_SAMPLE_RISING)
>>>>val |= CR_PCKPOL;
>>>> 
>>>> +  if (dcmi->do_crop) {
>>>> +  u32 size, start;
>>>> +
>>>> +  /* Crop resolution */
>>>> +  size = ((dcmi->crop.height - 1) << 16) |
>>>> +  ((dcmi->crop.width << 1) - 1);
>>>> +  reg_write(dcmi->regs, DCMI_CWSIZE, size);
>>>> +
>>>> +  /* Crop start point */
>>>> +  start = ((dcmi->crop.top) << 16) |
>>>> +   ((dcmi->crop.left << 1));
>>>> +  reg_write(dcmi->regs, DCMI_CWSTRT, start);
>>>> +
>>>> +  dev_dbg(dcmi->dev, "Cropping to %ux%u@%u:%u\n",
>>>> +  dcmi->crop.width, dcmi->crop.height,
>>>> +  dcmi->crop.left, dcmi->crop.top);
>>>> +
>>>> +  /* Enable crop */
>>>> +  val |= CR_CROP;
>>>> +  };
>>>> +
>>>>reg_write(dcmi->regs, DCMI_CR, val);
>>>> 
>>>>/* Enable dcmi */
>>>> @@ -707,6 +730,8 @@ static int dcmi_try_fmt(struct stm32_dcmi *dcmi, 
>>>> struct v4l2_format *f,
>>>>.which = V4L2_SUBDEV_FORMAT_TRY,
>>>>};
>>>>int ret;
>>>> +  __u32 width, height;
>>>> +  struct v4l2_mbus_framefmt *mf = 
>>>> 
>>>>dcmi_fmt = find_format_by_fourcc(dcmi, pixfmt->pixelformat);
>>>>if (!dcmi_fmt) {
>>>> @@ -724,8 +749,18 @@ static int dcmi_try_fmt(struct stm32_dcmi *dcmi, 
>>>> struct v4l2_format *f,
>>>>if (ret < 0)
>>>>return ret;
>>>> 
>>>> +  /* Align format on what sensor can do */
>>>> +  width = pixfmt->width;
>>>> +  height = pixfmt->height;
>>>>v4l2_fill_pix_format(pixfmt, );
>>>> 
>>>> +  /* We can do any resolution thanks to crop */
>>>> +  if ((mf->width > width) || (mf->height > height)) {
>>>> +  /* Restore width/height */
>>>> +  pixfmt->width = width;
>>>> +  pixfmt->height = height;
>>>> +  };
>>>> +
>>>>pixfmt->field = V4L2_FIELD_NONE;
>>>>pixfmt->bytesperline = pixfmt->width * dcmi_fmt->bpp;
>>>>pixfmt->sizeimage = pixfmt->bytesperline * pixfmt->height;
>>>> @@ -741,6 +776,8 @@ static int dcmi_set_fmt(struct stm32_dcmi *dcmi, 
>>>> struct v4l2_format *f)
>>>>struct v4l2_subdev_format format = {
>>>>.wh

Re: omap3isp camera was Re: [PATCH v1 0/6] Add support of OV9655 camera

2017-06-26 Thread Hugues FRUCHET
Nikolaus,
some comments about pixel format/resolution below:

On 06/26/2017 10:39 AM, Pavel Machek wrote:
> On Mon 2017-06-26 08:05:04, H. Nikolaus Schaller wrote:
>> Hi Pavel,
>>
>>> Am 25.06.2017 um 11:18 schrieb Pavel Machek :
>>>
>>> Hi!
>>>
 * unfortunately we still get no image :(

 The latter is likely a setup issue of our camera interface (OMAP3 ISP = 
 Image Signal Processor) which
 we were not yet able to solve. Oscilloscoping signals on the interface 
 indicated that signals and
 sync are correct. But we do not know since mplayer only shows a green 
 screen.
>>>
>>> What mplayer command line do you use? How did you set up the pipeline
>>> with media-ctl?
>>>
>>> On kernel.org, I have tree called camera-fw5-6 , where camera works
>>> for me on n900. On gitlab, there's modifed fcam-dev, which can be used
>>> for testing.
>>
>> We did have yet another (non-DT) camera driver and media-ctl working in with 
>> 3.12.37,
>> but had no success yet to update it to work with modern kernels or drivers. 
>> It
>> is either that the (newer) drivers missing something or the media-ctl has 
>> changed.
>>
>> Here is the log of our scripts with Hugues' driver and our latest setup:
>>
>> root@letux:~# ./camera-demo sxga
>> DISPLAY=:0
>> XAUTHORITY=tcp
>> Camera: /dev/v4l-subdev8
>> Setting mode sxga
>> media-ctl -r
>> media-ctl -l '"ov965x":0 -> "OMAP3 ISP CCDC":0[1]'
>> media-ctl -l '"OMAP3 ISP CCDC":1 -> "OMAP3 ISP CCDC output":0[1]'
>> media-ctl -V '"ov965x":0 [UYVY2X8 1280x1024]'
>> media-ctl -V '"OMAP3 ISP CCDC":0 [UYVY2X8 1280x1024]'
>> media-ctl -V '"OMAP3 ISP CCDC":1 [UYVY 1280x1024]'
> 
> Ok, so you are using capture, not preview.
> 
> You may want to try this one:
> 
> commit 0eae9d2a8f096f703cbc8f9a0ab155cd3cc14cef
> Author: Pavel 
> Date:   Mon Feb 13 21:26:51 2017 +0100
> 
>  omap3isp: fix VP2SDR bit so capture (not preview) works
> 
>  This is neccessary for capture (not preview) to work properly on
>  N900. Why is unknown.
>   
>   Pavel
> 
>> ### starting mplayer in sxga mode ###
>> mplayer tv:// -vf rotate=2 -tv 
>> driver=v4l2:device=/dev/video2:outfmt=uyvy:width=1280:height=1024:fps=15 -vo 
>> x11

=> "outfmt=uyvy:width=1280:height=1024"

Nikolaus,
Be careful that only VGA/RGB565 is coded in this basic version of OV9655,
perhaps this explain partly your troubles ?

>> MPlayer2 2.0-728-g2c378c7-4+b1 (C) 2000-2012 MPlayer Team
>>
>> Playing tv://.
>> Detected file format: TV
>> Selected driver: v4l2
>>   name: Video 4 Linux 2 input
>>   author: Martin Olschewski 
>>   comment: first try, more to come ;-)
>> v4l2: ioctl get standard failed: Invalid argument
>> Selected device: OMAP3 ISP CCDC output
>>   Capabilities:  video capture  video output  streaming
>>   supported norms:
>>   inputs: 0 = camera;
>>   Current input: 0
>>   Current format: unknown (0x0)
>> tv.c: norm_from_string(pal): Bogus norm parameter, setting default.
>> v4l2: ioctl enum norm failed: Inappropriate ioctl for device
>> Error: Cannot set norm!
>> Selected input hasn't got a tuner!
>> v4l2: ioctl set mute failed: Inappropriate ioctl for device
>> v4l2: ioctl query control failed: Inappropriate ioctl for device
>> v4l2: ioctl query control failed: Inappropriate ioctl for device
>> v4l2: ioctl query control failed: Inappropriate ioctl for device
>> v4l2: ioctl query control failed: Inappropriate ioctl for device
>> v4l2: ioctl streamon failed: Broken pipe
>> [ass] auto-open
>> Opening video filter: [rotate=2]
>> VIDEO:  1280x1024  15.000 fps0.0 kbps ( 0.0 kB/s)
>> Could not find matching colorspace - retrying with -vf scale...
>> Opening video filter: [scale]
>> [swscaler @ 0xb5ca9980]using unscaled uyvy422 -> yuv420p special converter
>> VO: [x11] 1024x1280 => 1024x1280 Planar YV12
>> [swscaler @ 0xb5ca9980]No accelerated colorspace conversion found from 
>> yuv420p to bgra.
>> Colorspace details not fully supported by selected vo.
>> Selected video codec: RAW UYVY [raw]
>> Audio: no sound
>> Starting playback...
>> V:   0.0  10/ 10 ??% ??% ??,?% 0 0 $<3>
>>
>>
>> MPlayer interrupted by signal 2 in module: filter_video
>> V:   0.0  11/ 11 ??% ??% ??,?% 0 0 $<3>
>> v4l2: ioctl set mute failed: Inappropriate ioctl for device
>> v4l2: 0 frames successfully processed, 0 frames dropped.
>>
>> Exiting... (Quit)
>> root@letux:~#
>>
>> BR and thanks,
>> Nikolaus
>>
> 
> 
> 


Re: [PATCH v1 3/5] [media] stm32-dcmi: crop sensor image to match user resolution

2017-06-26 Thread Hugues FRUCHET
Hi Hans, thanks for review.

Reply below.

BR
Hugues.

On 06/22/2017 05:19 PM, Hans Verkuil wrote:
> On 06/22/2017 05:12 PM, Hugues Fruchet wrote:
>> Add flexibility on supported resolutions by cropping sensor
>> image to fit user resolution format request.
>>
>> Signed-off-by: Hugues Fruchet <hugues.fruc...@st.com>
>> ---
>>drivers/media/platform/stm32/stm32-dcmi.c | 54 
>> ++-
>>1 file changed, 53 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/media/platform/stm32/stm32-dcmi.c 
>> b/drivers/media/platform/stm32/stm32-dcmi.c
>> index 75d53aa..bc5e052 100644
>> --- a/drivers/media/platform/stm32/stm32-dcmi.c
>> +++ b/drivers/media/platform/stm32/stm32-dcmi.c
>> @@ -131,6 +131,8 @@ struct stm32_dcmi {
>>  struct v4l2_async_notifier  notifier;
>>  struct dcmi_graph_entityentity;
>>  struct v4l2_format  fmt;
>> +struct v4l2_rectcrop;
>> +booldo_crop;
>>
>>  const struct dcmi_format**user_formats;
>>  unsigned intnum_user_formats;
>> @@ -538,6 +540,27 @@ static int dcmi_start_streaming(struct vb2_queue *vq, 
>> unsigned int count)
>>  if (dcmi->bus.flags & V4L2_MBUS_PCLK_SAMPLE_RISING)
>>  val |= CR_PCKPOL;
>>
>> +if (dcmi->do_crop) {
>> +u32 size, start;
>> +
>> +/* Crop resolution */
>> +size = ((dcmi->crop.height - 1) << 16) |
>> +((dcmi->crop.width << 1) - 1);
>> +reg_write(dcmi->regs, DCMI_CWSIZE, size);
>> +
>> +/* Crop start point */
>> +start = ((dcmi->crop.top) << 16) |
>> + ((dcmi->crop.left << 1));
>> +reg_write(dcmi->regs, DCMI_CWSTRT, start);
>> +
>> +dev_dbg(dcmi->dev, "Cropping to %ux%u@%u:%u\n",
>> +dcmi->crop.width, dcmi->crop.height,
>> +dcmi->crop.left, dcmi->crop.top);
>> +
>> +/* Enable crop */
>> +val |= CR_CROP;
>> +};
>> +
>>  reg_write(dcmi->regs, DCMI_CR, val);
>>
>>  /* Enable dcmi */
>> @@ -707,6 +730,8 @@ static int dcmi_try_fmt(struct stm32_dcmi *dcmi, struct 
>> v4l2_format *f,
>>  .which = V4L2_SUBDEV_FORMAT_TRY,
>>  };
>>  int ret;
>> +__u32 width, height;
>> +struct v4l2_mbus_framefmt *mf = 
>>
>>  dcmi_fmt = find_format_by_fourcc(dcmi, pixfmt->pixelformat);
>>  if (!dcmi_fmt) {
>> @@ -724,8 +749,18 @@ static int dcmi_try_fmt(struct stm32_dcmi *dcmi, struct 
>> v4l2_format *f,
>>  if (ret < 0)
>>  return ret;
>>
>> +/* Align format on what sensor can do */
>> +width = pixfmt->width;
>> +height = pixfmt->height;
>>  v4l2_fill_pix_format(pixfmt, );
>>
>> +/* We can do any resolution thanks to crop */
>> +if ((mf->width > width) || (mf->height > height)) {
>> +/* Restore width/height */
>> +pixfmt->width = width;
>> +pixfmt->height = height;
>> +};
>> +
>>  pixfmt->field = V4L2_FIELD_NONE;
>>  pixfmt->bytesperline = pixfmt->width * dcmi_fmt->bpp;
>>  pixfmt->sizeimage = pixfmt->bytesperline * pixfmt->height;
>> @@ -741,6 +776,8 @@ static int dcmi_set_fmt(struct stm32_dcmi *dcmi, struct 
>> v4l2_format *f)
>>  struct v4l2_subdev_format format = {
>>  .which = V4L2_SUBDEV_FORMAT_ACTIVE,
>>  };
>> +struct v4l2_mbus_framefmt *mf = 
>> +struct v4l2_pix_format *pixfmt = >fmt.pix;
>>  const struct dcmi_format *current_fmt;
>>  int ret;
>>
>> @@ -748,13 +785,28 @@ static int dcmi_set_fmt(struct stm32_dcmi *dcmi, 
>> struct v4l2_format *f)
>>  if (ret)
>>  return ret;
>>
>> -v4l2_fill_mbus_format(, >fmt.pix,
>> +v4l2_fill_mbus_format(, pixfmt,
>>current_fmt->mbus_code);
>>  ret = v4l2_subdev_call(dcmi->entity.subdev, pad,
>> set_fmt, NULL, );
>>  if (ret < 0)
>>  return ret;
>>
>> +/* Enable crop if sensor resolution is larger than request */
>> +dcmi->do_crop = false;
>> +if ((mf->width >

Re: [PATCH v1 5/6] [media] ov9650: add multiple variant support (fwd)

2017-06-26 Thread Hugues FRUCHET
Ok course, thanks Julia.

On 06/25/2017 10:00 PM, Julia Lawall wrote:
> Braces are probably missing aroud lines 1618-1620.
> 
> julia
> 
> -- Forwarded message --
> Date: Sun, 25 Jun 2017 23:06:03 +0800
> From: kbuild test robot <fengguang...@intel.com>
> To: kbu...@01.org
> Cc: Julia Lawall <julia.law...@lip6.fr>
> Subject: Re: [PATCH v1 5/6] [media] ov9650: add multiple variant support
> 
> Hi Hugues,
> 
> [auto build test WARNING on linuxtv-media/master]
> [also build test WARNING on v4.12-rc6 next-20170623]
> [if your patch is applied to the wrong git tree, please drop us a note to 
> help improve the system]
> 
> url:
> https://github.com/0day-ci/linux/commits/Hugues-Fruchet/Add-support-of-OV9655-camera/20170625-201153
> base:   git://linuxtv.org/media_tree.git master
> :: branch date: 3 hours ago
> :: commit date: 3 hours ago
> 
>>> drivers/media/i2c/ov9650.c:1618:2-44: code aligned with following code on 
>>> line 1619
> 
> git remote add linux-review https://github.com/0day-ci/linux
> git remote update linux-review
> git checkout a9fe8c23240a7f8df39c6238d98e41f41fedb641
> vim +1618 drivers/media/i2c/ov9650.c
> 
> a9fe8c23 Hugues Fruchet 2017-06-22  1612  ov965x->set_params = 
> __ov965x_set_params;
> 84a15ded Sylwester Nawrocki 2012-12-26  1613
> a9fe8c23 Hugues Fruchet 2017-06-22  1614  ov965x->frame_size = 
> >framesizes[0];
> a9fe8c23 Hugues Fruchet     2017-06-22  1615  
> ov965x_get_default_format(ov965x, >format);
> a9fe8c23 Hugues Fruchet 2017-06-22  1616
> a9fe8c23 Hugues Fruchet 2017-06-22  1617  if 
> (ov965x->initialize_controls)
> a9fe8c23 Hugues Fruchet 2017-06-22 @1618  ret = 
> ov965x->initialize_controls(ov965x);
> 84a15ded Sylwester Nawrocki 2012-12-26 @1619  if (ret < 0)
> 84a15ded Sylwester Nawrocki 2012-12-26  1620  goto 
> err_ctrls;
> 84a15ded Sylwester Nawrocki 2012-12-26  1621
> 84a15ded Sylwester Nawrocki 2012-12-26  1622  /* Update exposure time 
> min/max to match frame format */
> 
> ---
> 0-DAY kernel test infrastructureOpen Source Technology Center
> https://lists.01.org/pipermail/kbuild-all   Intel Corporation
> 

Re: [PATCH v1 0/6] Add support of OV9655 camera

2017-06-26 Thread Hugues FRUCHET
Hi Nikolaus,

On 06/22/2017 05:41 PM, H. Nikolaus Schaller wrote:
> 
>> Am 22.06.2017 um 17:05 schrieb Hugues Fruchet <hugues.fruc...@st.com>:
>>
>> This patchset enables OV9655 camera support.
>>
>> OV9655 support has been tested using STM32F4DIS-CAM extension board
>> plugged on connector P1 of STM32F746G-DISCO board.
>> Due to lack of OV9650/52 hardware support, the modified related code
>> could not have been checked for non-regression.
>>
>> First patches upgrade current support of OV9650/52 to prepare then
>> introduction of OV9655 variant patch.
>> Because of OV9655 register set slightly different from OV9650/9652,
>> not all of the driver features are supported (controls). Supported
>> resolutions are limited to VGA, QVGA, QQVGA.
>> Supported format is limited to RGB565.
>> Controls are limited to color bar test pattern for test purpose.
>>
>> OV9655 initial support is based on a driver written by H. Nikolaus Schaller 
>> [1].
> 
> Great!
> 
> I will test as soon as possible.
> 

Many thanks for your active review and testing Nikolaus !

>> OV9655 registers sequences come from STM32CubeF7 embedded software [2].
> 
> There is also a preliminary data sheet, e.g. here:
> 
> http://electricstuff.co.uk/OV9655-datasheet-annotated.pdf

This is the datasheet I've used for registers naming and signification.

BR,
Hugues.
> 
>>
>> [1] 
>> http://git.goldelico.com/?p=gta04-kernel.git;a=shortlog;h=refs/heads/work/hns/video/ov9655
>> [2] 
>> https://developer.mbed.org/teams/ST/code/BSP_DISCO_F746NG/file/e1d9da7fe856/Drivers/BSP/Components/ov9655/ov9655.c
>>
>> ===
>> = history =
>> ===
>> version 1:
>>   - Initial submission.
>>
>> H. Nikolaus Schaller (1):
>>   DT bindings: add bindings for ov965x camera module
>>
>> Hugues Fruchet (5):
>>   [media] ov9650: add device tree support
>>   [media] ov9650: select the nearest higher resolution
>>   [media] ov9650: use write_array() for resolution sequences
>>   [media] ov9650: add multiple variant support
>>   [media] ov9650: add support of OV9655 variant
>>
>> .../devicetree/bindings/media/i2c/ov965x.txt   |  37 +
>> drivers/media/i2c/Kconfig  |   6 +-
>> drivers/media/i2c/ov9650.c | 792 
>> +
>> 3 files changed, 704 insertions(+), 131 deletions(-)
>> create mode 100644 Documentation/devicetree/bindings/media/i2c/ov965x.txt
>>
>> -- 
>> 1.9.1
>>
> 
> BR and thanks,
> Nikolaus Schaller
> 

Re: [PATCH v1 1/6] DT bindings: add bindings for ov965x camera module

2017-06-26 Thread Hugues FRUCHET


On 06/23/2017 12:25 PM, H. Nikolaus Schaller wrote:
> Hi Hugues,
> 
>> Am 22.06.2017 um 17:05 schrieb Hugues Fruchet <hugues.fruc...@st.com>:
>>
>> From: "H. Nikolaus Schaller" <h...@goldelico.com>
>>
>> This adds documentation of device tree bindings
>> for the OV965X family camera sensor module.
>>
>> Signed-off-by: H. Nikolaus Schaller <h...@goldelico.com>
>> Signed-off-by: Hugues Fruchet <hugues.fruc...@st.com>
>> ---
>> .../devicetree/bindings/media/i2c/ov965x.txt   | 37 
>> ++
>> 1 file changed, 37 insertions(+)
>> create mode 100644 Documentation/devicetree/bindings/media/i2c/ov965x.txt
>>
>> diff --git a/Documentation/devicetree/bindings/media/i2c/ov965x.txt 
>> b/Documentation/devicetree/bindings/media/i2c/ov965x.txt
>> new file mode 100644
>> index 000..0e0de1f
>> --- /dev/null
>> +++ b/Documentation/devicetree/bindings/media/i2c/ov965x.txt
>> @@ -0,0 +1,37 @@
>> +* Omnivision OV9650/9652/9655 CMOS sensor
>> +
>> +The Omnivision OV965x sensor support multiple resolutions output, such as
>> +CIF, SVGA, UXGA. It also can support YUV422/420, RGB565/555 or raw RGB
>> +output format.
>> +
>> +Required Properties:
>> +- compatible: should be one of
>> +"ovti,ov9650"
>> +"ovti,ov9652"
>> +"ovti,ov9655"
>> +- clocks: reference to the mclk input clock.
> 
> I wonder why you have removed the clock-frequency property?
> 
> In some situations the camera driver must be able to tell the clock source
> which frequency it wants to see.
> 
> For example we connect the camera to an OMAP3-ISP (image signal processor) and
> there it is assumed that camera modules know the frequency and set the clock, 
> e.g.:
> 
> http://elixir.free-electrons.com/linux/v4.4/source/Documentation/devicetree/bindings/media/i2c/nokia,smia.txt#L52
> http://elixir.free-electrons.com/linux/v3.14/source/Documentation/devicetree/bindings/media/i2c/mt9p031.txt
> 
> If your clock is constant and defined elsewhere we should make this
> property optional instead of required. But it should not be missing.
> 
> Here is a hack to get it into your code:
> 
> http://git.goldelico.com/?p=gta04-kernel.git;a=blobdiff;f=drivers/media/i2c/ov9650.c;h=b7ab46c775b9e40087e427ae0777e9f7c283694a;hp=1846bcbb19ae71ce686dade320aa06ce2e429ca4;hb=ca85196f6fd9a77e5a0f796aeaf7aa2cde60ce91;hpb=8a71f21b75543a6d99102be1ae4677b28c478ac9
> 

Here is how it is used on my DT, the camera clock is a fixed crystal 24M 
clock:

+   clocks {
+   clk_ext_camera: clk-ext-camera {
+   #clock-cells = <0>;
+   compatible = "fixed-clock";
+   clock-frequency = <2400>;
+   };
+   };
[...]
+   ov9655: camera@30 {
+   compatible = "ovti,ov9655";
+   reg = <0x30>;
+   pwdn-gpios = < 13 GPIO_ACTIVE_HIGH>;
+   clocks = <_ext_camera>;
+   status = "okay";
+
+   port {
+   ov9655_0: endpoint {
+   remote-endpoint = <_0>;
+   };
+   };
+   };


>> +
>> +Optional Properties:
>> +- resetb-gpios: reference to the GPIO connected to the resetb pin, if any.
>> +- pwdn-gpios: reference to the GPIO connected to the pwdn pin, if any.
> 
> Here I wonder why you did split that up into two gpios. Each "*-gpios" can 
> have
> multiple entries and if one is not used, a 0 can be specified to make it 
> being ignored.
> 
> But it is up to DT maintainers what they prefer: separate single gpios or a 
> single gpio array.

I have followed the ov2640 binding, which have the same pins naming 
(resetb/pwdn).
As far as I see, separate single gpios are commonly used in
Documentation/devicetree/bindings/media/i2c/

> 
> 
> What I am missing to support the GTA04 camera is the control of the optional 
> "vana-supply".
> So the driver does not power up the camera module when needed and therefore 
> probing fails.
> 
>- vana-supply: a regulator to power up the camera module.
> 
> Driver code is not complex to add:
> 
> http://git.goldelico.com/?p=gta04-kernel.git;a=blobdiff;f=drivers/media/i2c/ov9650.c;h=1846bcbb19ae71ce686dade320aa06ce2e429ca4;hp=c0819afdcefcb19da351741d51dad00aaf909254;hb=8a71f21b75543a6d99102be1ae4677b28c478ac9;hpb=6db55fc472eea2ec6db03833df027aecf6649f88

Yes, I saw it in your code, but as I don't have any programmable power 
supply on my setup, I have not pushed this commit.
And I also don't have a clock to

Re: omap3isp camera was Re: [PATCH v1 0/6] Add support of OV9655 camera

2017-06-27 Thread Hugues FRUCHET
Hi Nikolaus,

I would propose to work first on YUV support, so you can test a YUV VGA 
grabbing using your OMPA3 setup, I will add this support then in patch 
serie.

For the co-work, let's continue on IRC (irc.freenode.net), chat #v4l, my 
pseudo is "hfr".

BR,
Hugues.

On 06/26/2017 06:28 PM, H. Nikolaus Schaller wrote:
> Hi Hugues,
> 
>> Am 26.06.2017 um 15:19 schrieb Hugues FRUCHET <hugues.fruc...@st.com>:
>>
>> Nikolaus,
>> some comments about pixel format/resolution below:
>>
>> On 06/26/2017 10:39 AM, Pavel Machek wrote:
>>> On Mon 2017-06-26 08:05:04, H. Nikolaus Schaller wrote:
>>>> Hi Pavel,
>>>>
>>>>> Am 25.06.2017 um 11:18 schrieb Pavel Machek <pa...@ucw.cz>:
>>>>>
>>>>> Hi!
>>>>>
>>>>>> * unfortunately we still get no image :(
>>>>>>
>>>>>> The latter is likely a setup issue of our camera interface (OMAP3 ISP = 
>>>>>> Image Signal Processor) which
>>>>>> we were not yet able to solve. Oscilloscoping signals on the interface 
>>>>>> indicated that signals and
>>>>>> sync are correct. But we do not know since mplayer only shows a green 
>>>>>> screen.
>>>>>
>>>>> What mplayer command line do you use? How did you set up the pipeline
>>>>> with media-ctl?
>>>>>
>>>>> On kernel.org, I have tree called camera-fw5-6 , where camera works
>>>>> for me on n900. On gitlab, there's modifed fcam-dev, which can be used
>>>>> for testing.
>>>>
>>>> We did have yet another (non-DT) camera driver and media-ctl working in 
>>>> with 3.12.37,
>>>> but had no success yet to update it to work with modern kernels or 
>>>> drivers. It
>>>> is either that the (newer) drivers missing something or the media-ctl has 
>>>> changed.
>>>>
>>>> Here is the log of our scripts with Hugues' driver and our latest setup:
>>>>
>>>> root@letux:~# ./camera-demo sxga
>>>> DISPLAY=:0
>>>> XAUTHORITY=tcp
>>>> Camera: /dev/v4l-subdev8
>>>> Setting mode sxga
>>>> media-ctl -r
>>>> media-ctl -l '"ov965x":0 -> "OMAP3 ISP CCDC":0[1]'
>>>> media-ctl -l '"OMAP3 ISP CCDC":1 -> "OMAP3 ISP CCDC output":0[1]'
>>>> media-ctl -V '"ov965x":0 [UYVY2X8 1280x1024]'
>>>> media-ctl -V '"OMAP3 ISP CCDC":0 [UYVY2X8 1280x1024]'
>>>> media-ctl -V '"OMAP3 ISP CCDC":1 [UYVY 1280x1024]'
>>>
>>> Ok, so you are using capture, not preview.
>>>
>>> You may want to try this one:
>>>
>>> commit 0eae9d2a8f096f703cbc8f9a0ab155cd3cc14cef
>>> Author: Pavel <pa...@ucw.cz>
>>> Date:   Mon Feb 13 21:26:51 2017 +0100
>>>
>>>  omap3isp: fix VP2SDR bit so capture (not preview) works
>>>
>>>  This is neccessary for capture (not preview) to work properly on
>>>  N900. Why is unknown.
>>> 
>>> Pavel
>>>
>>>> ### starting mplayer in sxga mode ###
>>>> mplayer tv:// -vf rotate=2 -tv 
>>>> driver=v4l2:device=/dev/video2:outfmt=uyvy:width=1280:height=1024:fps=15 
>>>> -vo x11
>>
>> => "outfmt=uyvy:width=1280:height=1024"
>>
>> Nikolaus,
>> Be careful that only VGA/RGB565 is coded in this basic version of OV9655,
>> perhaps this explain partly your troubles ?
> 
> Ah, I see. The driver should support SXGA and UYVY2X8 (because our 3.12 
> compatible driver did).
> 
> This very old (but working) non-DT driver for 3.12 kernels
> was not based on the ov9650.c code but mt9p031.c:
> 
>   
> http://git.goldelico.com/?p=gta04-kernel.git;a=blob;f=drivers/media/i2c/ov9655.c;hb=refs/heads/3.12.37
> 
> We abandoned this independent driver because we felt (like you) that 
> extending the existing
> ov9650 driver is a better solution for mainline.
> 
> 
> At least in theory. Therefore I assumed your submission supports SXGA and 
> UYVY as well,
> since your work is based on ours.
> 
> Nevertheless, VGA resolution doesn't work either.
> 
> root@letux:~# ./camera-demo vga
> DISPLAY=:0
> XAUTHORITY=tcp
> Camera: /dev/v4l-subdev8
> Setting mode vga
> media-ctl -r
> media-ctl -l '"ov965x":0 -> "OMAP3 ISP CCDC":0[1]'
> media-ctl -l '&

[PATCH v5 4/8] ARM: dts: stm32: Enable DCMI camera interface on STM32F429-EVAL board

2017-05-05 Thread Hugues Fruchet
Enable DCMI camera interface on STM32F429-EVAL board.

Signed-off-by: Hugues Fruchet <hugues.fruc...@st.com>
---
 arch/arm/boot/dts/stm32429i-eval.dts | 9 +
 1 file changed, 9 insertions(+)

diff --git a/arch/arm/boot/dts/stm32429i-eval.dts 
b/arch/arm/boot/dts/stm32429i-eval.dts
index 3c99466..617f2f7 100644
--- a/arch/arm/boot/dts/stm32429i-eval.dts
+++ b/arch/arm/boot/dts/stm32429i-eval.dts
@@ -141,6 +141,15 @@
clock-frequency = <2500>;
 };
 
+ {
+   status = "okay";
+
+   port {
+   dcmi_0: endpoint {
+   };
+   };
+};
+
  {
pinctrl-0 = <_pins>;
pinctrl-names = "default";
-- 
1.9.1



[PATCH v5 7/8] ARM: configs: stm32: STMPE1600 GPIO expander

2017-05-05 Thread Hugues Fruchet
Enable STMPE1600 GPIO expander.

Signed-off-by: Hugues Fruchet <hugues.fruc...@st.com>
---
 arch/arm/configs/stm32_defconfig | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/arm/configs/stm32_defconfig b/arch/arm/configs/stm32_defconfig
index a9d8e3c..84adc88 100644
--- a/arch/arm/configs/stm32_defconfig
+++ b/arch/arm/configs/stm32_defconfig
@@ -49,6 +49,8 @@ CONFIG_SERIAL_STM32_CONSOLE=y
 # CONFIG_HW_RANDOM is not set
 # CONFIG_HWMON is not set
 CONFIG_REGULATOR=y
+CONFIG_GPIO_STMPE=y
+CONFIG_MFD_STMPE=y
 CONFIG_REGULATOR_FIXED_VOLTAGE=y
 # CONFIG_USB_SUPPORT is not set
 CONFIG_NEW_LEDS=y
-- 
1.9.1



  1   2   3   4   >