This is an automated email from the ASF dual-hosted git repository.

GUIDINGLI pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 4cfd1121e9aa11bbeabba0f2540912984cbb1223
Author: raiden00pl <[email protected]>
AuthorDate: Wed Nov 25 09:17:12 2026 +0100

    arch/arm/stm32n6: Add DCMIPP and CSI-2 camera support.
    
    Add an imgdata driver for the DCMIPP pipe1 fed by the CSI-2 host.  It
    converts raw Bayer frames to RGB565 (black level, white balance,
    demosaicing, colour matrix, gamma) and scales them.  The DCMIPP
    registers an image sensor in front of the raw sensor that reports the
    RGB565 output and forwards the controls.  Optional automatic exposure
    and white balance run from the pipe1 statistics.
    
    Assisted-by: Claude:claude-opus-5-5
    Signed-off-by: raiden00pl <[email protected]>
---
 Documentation/guides/chip-specific/stm32_ports.rst |    2 +
 Documentation/platforms/arm/stm32n6/index.rst      |    4 +-
 arch/arm/src/common/stm32/Kconfig.have             |    3 +
 arch/arm/src/common/stm32/Kconfig.periph           |    9 +
 arch/arm/src/stm32n6/CMakeLists.txt                |    4 +
 arch/arm/src/stm32n6/Kconfig                       |   40 +
 arch/arm/src/stm32n6/Make.defs                     |    4 +
 arch/arm/src/stm32n6/hardware/stm32n6xxx_csi.h     |  174 +++
 arch/arm/src/stm32n6/hardware/stm32n6xxx_dcmipp.h  |  329 ++++
 .../src/stm32n6/hardware/stm32n6xxx_memorymap.h    |    2 +
 arch/arm/src/stm32n6/hardware/stm32n6xxx_rifsc.h   |    2 +
 arch/arm/src/stm32n6/stm32_csi.c                   |  334 +++++
 arch/arm/src/stm32n6/stm32_csi.h                   |   82 +
 arch/arm/src/stm32n6/stm32_dcmipp.c                | 1574 ++++++++++++++++++++
 arch/arm/src/stm32n6/stm32_dcmipp.h                |  101 ++
 arch/arm/src/stm32n6/stm32_rif.c                   |    8 +
 arch/arm/src/stm32n6/stm32n6xx_rcc.c               |    4 +
 17 files changed, 2675 insertions(+), 1 deletion(-)

diff --git a/Documentation/guides/chip-specific/stm32_ports.rst 
b/Documentation/guides/chip-specific/stm32_ports.rst
index 86b0040f097..601779dec5b 100644
--- a/Documentation/guides/chip-specific/stm32_ports.rst
+++ b/Documentation/guides/chip-specific/stm32_ports.rst
@@ -772,7 +772,9 @@ Peripheral    Core version  Driver
 ============  ============  ==================================================
 ADC           to be done    not supported
 CAN/FDCAN     to be done    not supported
+CSI           n6            arch/arm/src/stm32n6/stm32_csi.c
 DAC           to be done    not supported
+DCMIPP        n6            arch/arm/src/stm32n6/stm32_dcmipp.c
 DMA2D         v1            arch/arm/src/common/stm32/stm32_dma2d_v1.c
 ETH           v2            arch/arm/src/common/stm32/stm32_eth_v2.c
 EXTI          M33M55 v1     
arch/arm/src/common/stm32/stm32_exti_gpio_m33m55_v1.c
diff --git a/Documentation/platforms/arm/stm32n6/index.rst 
b/Documentation/platforms/arm/stm32n6/index.rst
index 9e6554f61ed..b23bddce5f7 100644
--- a/Documentation/platforms/arm/stm32n6/index.rst
+++ b/Documentation/platforms/arm/stm32n6/index.rst
@@ -26,6 +26,9 @@ The following list indicates peripherals supported in NuttX:
 Peripheral  Support  Notes
 ==========  =======  ===============================================
 Cache       Yes      L1 I- and D-cache.
+DCMIPP      Yes      Pipe1 with the CSI-2 host as a V4L2 capture
+                     interface: raw Bayer to RGB565 with scaling,
+                     automatic exposure and white balance.
 GPIO        Yes
 I2C         Yes      I2C1-4 through the common I2C v2 driver.
 LTDC        Yes      Common LTDC driver (v2 register layout), RGB565,
@@ -52,7 +55,6 @@ USB         Yes      USB1 or USB2 OTG HS host through the 
common OTG v2
                      driver, full and low speed on the embedded HS PHY.
 
 ADC         No
-DCMIPP      No
 IWDG        No
 LPTIM       No
 MPU         No
diff --git a/arch/arm/src/common/stm32/Kconfig.have 
b/arch/arm/src/common/stm32/Kconfig.have
index c2d2e3502b1..69890a31a15 100644
--- a/arch/arm/src/common/stm32/Kconfig.have
+++ b/arch/arm/src/common/stm32/Kconfig.have
@@ -287,6 +287,9 @@ config STM32_HAVE_DCMI
 config STM32_HAVE_IP_DCMI_V1
        bool
 
+config STM32_HAVE_DCMIPP
+       bool
+
 # DFSDM capabilities
 
 config STM32_HAVE_MDF1
diff --git a/arch/arm/src/common/stm32/Kconfig.periph 
b/arch/arm/src/common/stm32/Kconfig.periph
index fe35ed93cbe..1fa9720ee29 100644
--- a/arch/arm/src/common/stm32/Kconfig.periph
+++ b/arch/arm/src/common/stm32/Kconfig.periph
@@ -1154,6 +1154,15 @@ config STM32_DCMI
                modules and CMOS sensors through an 8-bit to 14-bit parallel 
interface,
                to receive video data.
 
+config STM32_DCMIPP
+       bool "DCMIPP"
+       depends on STM32_HAVE_DCMIPP && VIDEO_STREAM
+       ---help---
+               Digital camera interface pixel pipeline with the MIPI CSI-2
+               host.  Captures raw Bayer frames from a CSI-2 image sensor and
+               converts them to RGB565 in the main pipe ISP for the V4L2
+               capture driver.
+
 config STM32_SYSCFG_IOCOMPENSATION
        bool "SYSCFG I/O Compensation"
        depends on STM32_HAVE_IOCOMPENSATION
diff --git a/arch/arm/src/stm32n6/CMakeLists.txt 
b/arch/arm/src/stm32n6/CMakeLists.txt
index c7aa8b96868..9408d1cbbfd 100644
--- a/arch/arm/src/stm32n6/CMakeLists.txt
+++ b/arch/arm/src/stm32n6/CMakeLists.txt
@@ -43,6 +43,10 @@ if(CONFIG_STM32_OTGHS)
   list(APPEND SRCS stm32_otg_phyif.c)
 endif()
 
+if(CONFIG_STM32_DCMIPP)
+  list(APPEND SRCS stm32_csi.c stm32_dcmipp.c)
+endif()
+
 # Chip-specific RCC
 
 if(CONFIG_STM32_STM32N6XXXX)
diff --git a/arch/arm/src/stm32n6/Kconfig b/arch/arm/src/stm32n6/Kconfig
index 37075474177..6e66bbbdddd 100644
--- a/arch/arm/src/stm32n6/Kconfig
+++ b/arch/arm/src/stm32n6/Kconfig
@@ -48,6 +48,7 @@ config STM32_N6_PERIPHERALS
        select STM32_HAVE_IP_SDMMC_V2
        select STM32_HAVE_IP_SPI_V5
        select STM32_HAVE_IP_WDG_V3
+       select STM32_HAVE_DCMIPP
        select STM32_HAVE_DMA1
        select STM32_HAVE_DMA2
        select STM32_HAVE_DMA2D
@@ -163,4 +164,43 @@ config STM32N6_DEBUG
                to attach without switching to DEV boot mode.  This changes 
runtime
                BSEC registers only, not OTP fuses.
 
+menu "DCMIPP Configuration"
+       depends on STM32_DCMIPP
+
+config STM32_DCMIPP_AE
+       bool "Automatic exposure"
+       default y
+       select SCHED_LPWORK
+       ---help---
+               Adjust the sensor exposure time, then the gain, from the pipe1
+               statistics towards a target mean luminance.
+
+config STM32_DCMIPP_AE_TARGET
+       int "Target mean luminance"
+       default 46
+       range 16 224
+       depends on STM32_DCMIPP_AE
+       ---help---
+               Mean luminance (8-bit, linear, before gamma) of the frame.  46 
is
+               18 % of full scale, the reflectance of a middle grey.
+
+config STM32_DCMIPP_AWB
+       bool "Automatic white balance"
+       default y
+       select SCHED_LPWORK
+       ---help---
+               Grey world white balance: adjust the red and blue gains of the
+               pipe1 exposure block until the R, G and B means are equal.
+
+config STM32_DCMIPP_ISP_INTERVAL
+       int "Frames skipped after an update"
+       default 4
+       range 1 60
+       depends on STM32_DCMIPP_AE || STM32_DCMIPP_AWB
+       ---help---
+               Frames ignored after each exposure or white balance update; it
+               must cover the sensor latency.
+
+endmenu # DCMIPP Configuration
+
 endif # ARCH_CHIP_STM32N6
diff --git a/arch/arm/src/stm32n6/Make.defs b/arch/arm/src/stm32n6/Make.defs
index d4338e1a13f..10411627117 100644
--- a/arch/arm/src/stm32n6/Make.defs
+++ b/arch/arm/src/stm32n6/Make.defs
@@ -43,6 +43,10 @@ ifeq ($(CONFIG_STM32_OTGHS),y)
 CHIP_CSRCS += stm32_otg_phyif.c
 endif
 
+ifeq ($(CONFIG_STM32_DCMIPP),y)
+CHIP_CSRCS += stm32_csi.c stm32_dcmipp.c
+endif
+
 # Chip-specific RCC
 
 CHIP_CSRCS += stm32n6xx_rcc.c
diff --git a/arch/arm/src/stm32n6/hardware/stm32n6xxx_csi.h 
b/arch/arm/src/stm32n6/hardware/stm32n6xxx_csi.h
new file mode 100644
index 00000000000..8de30f5d612
--- /dev/null
+++ b/arch/arm/src/stm32n6/hardware/stm32n6xxx_csi.h
@@ -0,0 +1,174 @@
+/****************************************************************************
+ * arch/arm/src/stm32n6/hardware/stm32n6xxx_csi.h
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __ARCH_ARM_SRC_STM32N6_HARDWARE_STM32N6XXX_CSI_H
+#define __ARCH_ARM_SRC_STM32N6_HARDWARE_STM32N6XXX_CSI_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include "hardware/stm32_memorymap.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Register Offsets *********************************************************/
+
+#define STM32_CSI_CR_OFFSET        0x0000  /* Control register */
+#define STM32_CSI_PCR_OFFSET       0x0004  /* D-PHY RX control register */
+#define STM32_CSI_VC0CFGR1_OFFSET  0x0010  /* Virtual channel 0 config 1 */
+#define STM32_CSI_LMCFGR_OFFSET    0x0070  /* Lane merger configuration */
+#define STM32_CSI_IER0_OFFSET      0x0080  /* Interrupt enable register 0 */
+#define STM32_CSI_IER1_OFFSET      0x0084  /* Interrupt enable register 1 */
+#define STM32_CSI_SR0_OFFSET       0x0090  /* Status register 0 */
+#define STM32_CSI_SR1_OFFSET       0x0094  /* Status register 1 */
+#define STM32_CSI_FCR0_OFFSET      0x0100  /* Flag clear register 0 */
+#define STM32_CSI_FCR1_OFFSET      0x0104  /* Flag clear register 1 */
+#define STM32_CSI_PRCR_OFFSET      0x1000  /* PHY reset control register */
+#define STM32_CSI_PMCR_OFFSET      0x1004  /* PHY mode control register */
+#define STM32_CSI_PFCR_OFFSET      0x1008  /* PHY frequency control */
+#define STM32_CSI_PTCR0_OFFSET     0x1010  /* PHY test control register 0 */
+#define STM32_CSI_PTCR1_OFFSET     0x1014  /* PHY test control register 1 */
+
+/* Register Addresses *******************************************************/
+
+#define STM32_CSI_CR               (STM32_CSI_BASE + STM32_CSI_CR_OFFSET)
+#define STM32_CSI_PCR              (STM32_CSI_BASE + STM32_CSI_PCR_OFFSET)
+#define STM32_CSI_VC0CFGR1         (STM32_CSI_BASE + \
+                                    STM32_CSI_VC0CFGR1_OFFSET)
+#define STM32_CSI_LMCFGR           (STM32_CSI_BASE + STM32_CSI_LMCFGR_OFFSET)
+#define STM32_CSI_IER0             (STM32_CSI_BASE + STM32_CSI_IER0_OFFSET)
+#define STM32_CSI_IER1             (STM32_CSI_BASE + STM32_CSI_IER1_OFFSET)
+#define STM32_CSI_SR0              (STM32_CSI_BASE + STM32_CSI_SR0_OFFSET)
+#define STM32_CSI_SR1              (STM32_CSI_BASE + STM32_CSI_SR1_OFFSET)
+#define STM32_CSI_FCR0             (STM32_CSI_BASE + STM32_CSI_FCR0_OFFSET)
+#define STM32_CSI_FCR1             (STM32_CSI_BASE + STM32_CSI_FCR1_OFFSET)
+#define STM32_CSI_PRCR             (STM32_CSI_BASE + STM32_CSI_PRCR_OFFSET)
+#define STM32_CSI_PMCR             (STM32_CSI_BASE + STM32_CSI_PMCR_OFFSET)
+#define STM32_CSI_PFCR             (STM32_CSI_BASE + STM32_CSI_PFCR_OFFSET)
+#define STM32_CSI_PTCR0            (STM32_CSI_BASE + STM32_CSI_PTCR0_OFFSET)
+#define STM32_CSI_PTCR1            (STM32_CSI_BASE + STM32_CSI_PTCR1_OFFSET)
+
+/* Register Bitfield Definitions ********************************************/
+
+/* Control register */
+
+#define CSI_CR_CSIEN               (1 << 0)  /* Bit 0: CSI-2 host enable */
+#define CSI_CR_VC0START            (1 << 2)  /* Bit 2: Start virtual channel 0 
*/
+#define CSI_CR_VC0STOP             (1 << 3)  /* Bit 3: Stop virtual channel 0 
*/
+
+/* D-PHY RX control register */
+
+#define CSI_PCR_NPWRDOWN           (1 << 0)  /* Bit 0: Not in power down */
+#define CSI_PCR_CLEN               (1 << 1)  /* Bit 1: Clock lane enable */
+#define CSI_PCR_DL0EN              (1 << 2)  /* Bit 2: Data lane 0 enable */
+#define CSI_PCR_DL1EN              (1 << 3)  /* Bit 3: Data lane 1 enable */
+
+/* Virtual channel 0 configuration register 1 */
+
+#define CSI_VC0CFGR1_ALLDT         (1 << 0)  /* Bit 0: Accept all data types */
+#define CSI_VC0CFGR1_CDTFT_SHIFT   (8)       /* Bits 8-12: Common data type
+                                              * format */
+#define CSI_VC0CFGR1_CDTFT_MASK    (0x1f << CSI_VC0CFGR1_CDTFT_SHIFT)
+#  define CSI_VC0CFGR1_CDTFT(n)    ((uint32_t)(n) << CSI_VC0CFGR1_CDTFT_SHIFT)
+
+/* Data type formats (bits per pixel) for CDTFT */
+
+#define CSI_DTFT_BPP8              2         /* 8 bits per pixel */
+#define CSI_DTFT_BPP10             3         /* 10 bits per pixel */
+#define CSI_DTFT_BPP12             4         /* 12 bits per pixel */
+#define CSI_DTFT_BPP14             5         /* 14 bits per pixel */
+
+/* Lane merger configuration register */
+
+#define CSI_LMCFGR_LANENB_SHIFT    (8)       /* Bits 8-10: Number of data
+                                              * lanes */
+#define CSI_LMCFGR_LANENB_MASK     (0x7 << CSI_LMCFGR_LANENB_SHIFT)
+#  define CSI_LMCFGR_LANENB(n)     ((uint32_t)(n) << CSI_LMCFGR_LANENB_SHIFT)
+#define CSI_LMCFGR_DL0MAP_SHIFT    (16)      /* Bits 16-18: Physical lane of
+                                              * logical lane 0 */
+#define CSI_LMCFGR_DL0MAP_MASK     (0x7 << CSI_LMCFGR_DL0MAP_SHIFT)
+#  define CSI_LMCFGR_DL0MAP(n)     ((uint32_t)(n) << CSI_LMCFGR_DL0MAP_SHIFT)
+#define CSI_LMCFGR_DL1MAP_SHIFT    (20)      /* Bits 20-22: Physical lane of
+                                              * logical lane 1 */
+#define CSI_LMCFGR_DL1MAP_MASK     (0x7 << CSI_LMCFGR_DL1MAP_SHIFT)
+#  define CSI_LMCFGR_DL1MAP(n)     ((uint32_t)(n) << CSI_LMCFGR_DL1MAP_SHIFT)
+
+/* Interrupt enable register 0, status register 0 and flag clear register 0
+ * (same bit positions)
+ */
+
+#define CSI_INT0_SOF0              (1 << 8)  /* Bit 8: Start of frame on VC0 */
+#define CSI_INT0_EOF0              (1 << 12) /* Bit 12: End of frame on VC0 */
+#define CSI_INT0_SPKT              (1 << 16) /* Bit 16: Short packet */
+#define CSI_SR0_VC0STATEF          (1 << 17) /* Bit 17: VC0 running (SR0) */
+#define CSI_INT0_CCFIFOF           (1 << 21) /* Bit 21: Clock changer FIFO
+                                              * full */
+#define CSI_INT0_CRCERR            (1 << 24) /* Bit 24: CRC error */
+#define CSI_INT0_ECCERR            (1 << 25) /* Bit 25: ECC error */
+#define CSI_INT0_CECCERR           (1 << 26) /* Bit 26: Corrected ECC error */
+#define CSI_INT0_IDERR             (1 << 27) /* Bit 27: Data ID error */
+#define CSI_INT0_SPKTERR           (1 << 28) /* Bit 28: Short packet error */
+#define CSI_INT0_WDERR             (1 << 29) /* Bit 29: Watchdog error */
+#define CSI_INT0_SYNCERR           (1 << 30) /* Bit 30: Synchronization
+                                              * error */
+
+/* Interrupt enable register 1, status register 1 and flag clear register 1:
+ * D-PHY data lane n errors (n = 0 or 1)
+ */
+
+#define CSI_INT1_ESOTDL(n)         (1 << (0 + 8 * (n))) /* SOT error */
+#define CSI_INT1_ESOTSYNCDL(n)     (1 << (1 + 8 * (n))) /* SOT sync error */
+#define CSI_INT1_EESCDL(n)         (1 << (2 + 8 * (n))) /* Escape entry
+                                                         * error */
+#define CSI_INT1_ESYNCESCDL(n)     (1 << (3 + 8 * (n))) /* LP sync error */
+#define CSI_INT1_ECTRLDL(n)        (1 << (4 + 8 * (n))) /* Control error */
+
+/* PHY reset control register */
+
+#define CSI_PRCR_PEN               (1 << 1)  /* Bit 1: D-PHY out of reset */
+
+/* PHY frequency control register */
+
+#define CSI_PFCR_CCFR_SHIFT        (0)       /* Bits 0-5: Configuration clock
+                                              * frequency range */
+#define CSI_PFCR_CCFR_MASK         (0x3f << CSI_PFCR_CCFR_SHIFT)
+#  define CSI_PFCR_CCFR(n)         ((uint32_t)(n) << CSI_PFCR_CCFR_SHIFT)
+#define CSI_PFCR_HSFR_SHIFT        (8)       /* Bits 8-14: High-speed
+                                              * frequency range */
+#define CSI_PFCR_HSFR_MASK         (0x7f << CSI_PFCR_HSFR_SHIFT)
+#  define CSI_PFCR_HSFR(n)         ((uint32_t)(n) << CSI_PFCR_HSFR_SHIFT)
+#define CSI_PFCR_DLD               (1 << 16) /* Bit 16: Data lane direction */
+
+/* PHY test control registers */
+
+#define CSI_PTCR0_TCKEN            (1 << 0)  /* Bit 0: Test clock enable */
+#define CSI_PTCR0_TRSEN            (1 << 1)  /* Bit 1: Test interface reset */
+#define CSI_PTCR1_TDI_SHIFT        (0)       /* Bits 0-7: Test data input */
+#define CSI_PTCR1_TDI_MASK         (0xff << CSI_PTCR1_TDI_SHIFT)
+#  define CSI_PTCR1_TDI(n)         ((uint32_t)(n) << CSI_PTCR1_TDI_SHIFT)
+#define CSI_PTCR1_TWM              (1 << 16) /* Bit 16: Test write mode */
+
+#endif /* __ARCH_ARM_SRC_STM32N6_HARDWARE_STM32N6XXX_CSI_H */
diff --git a/arch/arm/src/stm32n6/hardware/stm32n6xxx_dcmipp.h 
b/arch/arm/src/stm32n6/hardware/stm32n6xxx_dcmipp.h
new file mode 100644
index 00000000000..9bc8e10b690
--- /dev/null
+++ b/arch/arm/src/stm32n6/hardware/stm32n6xxx_dcmipp.h
@@ -0,0 +1,329 @@
+/****************************************************************************
+ * arch/arm/src/stm32n6/hardware/stm32n6xxx_dcmipp.h
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __ARCH_ARM_SRC_STM32N6_HARDWARE_STM32N6XXX_DCMIPP_H
+#define __ARCH_ARM_SRC_STM32N6_HARDWARE_STM32N6XXX_DCMIPP_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include "hardware/stm32_memorymap.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Register Offsets *********************************************************/
+
+/* Common registers */
+
+#define STM32_DCMIPP_PRCR_OFFSET       0x0104  /* Parallel interface control */
+#define STM32_DCMIPP_CMCR_OFFSET       0x0204  /* Common configuration */
+#define STM32_DCMIPP_CMIER_OFFSET      0x03f0  /* Common interrupt enable */
+#define STM32_DCMIPP_CMSR1_OFFSET      0x03f4  /* Common status register 1 */
+#define STM32_DCMIPP_CMSR2_OFFSET      0x03f8  /* Common status register 2 */
+#define STM32_DCMIPP_CMFCR_OFFSET      0x03fc  /* Common interrupt clear */
+
+/* Pipe1 (main pipe with ISP) registers */
+
+#define STM32_DCMIPP_P1FSCR_OFFSET     0x0804  /* Flow selection config */
+#define STM32_DCMIPP_P1BLCCR_OFFSET    0x0840  /* Black level calibration */
+#define STM32_DCMIPP_P1EXCR1_OFFSET    0x0844  /* Exposure control 1 */
+#define STM32_DCMIPP_P1EXCR2_OFFSET    0x0848  /* Exposure control 2 */
+#define STM32_DCMIPP_P1ST1CR_OFFSET    0x0850  /* Statistics 1 control */
+#define STM32_DCMIPP_P1ST2CR_OFFSET    0x0854  /* Statistics 2 control */
+#define STM32_DCMIPP_P1ST3CR_OFFSET    0x0858  /* Statistics 3 control */
+#define STM32_DCMIPP_P1STSTR_OFFSET    0x085c  /* Statistics window start */
+#define STM32_DCMIPP_P1STSZR_OFFSET    0x0860  /* Statistics window size */
+#define STM32_DCMIPP_P1ST1SR_OFFSET    0x0864  /* Statistics 1 status */
+#define STM32_DCMIPP_P1ST2SR_OFFSET    0x0868  /* Statistics 2 status */
+#define STM32_DCMIPP_P1ST3SR_OFFSET    0x086c  /* Statistics 3 status */
+#define STM32_DCMIPP_P1DMCR_OFFSET     0x0870  /* Demosaicing configuration */
+#define STM32_DCMIPP_P1CCCR_OFFSET     0x0880  /* ColorConv configuration */
+#define STM32_DCMIPP_P1CCRR1_OFFSET    0x0884  /* ColorConv red coeff 1 */
+#define STM32_DCMIPP_P1CCRR2_OFFSET    0x0888  /* ColorConv red coeff 2 */
+#define STM32_DCMIPP_P1CCGR1_OFFSET    0x088c  /* ColorConv green coeff 1 */
+#define STM32_DCMIPP_P1CCGR2_OFFSET    0x0890  /* ColorConv green coeff 2 */
+#define STM32_DCMIPP_P1CCBR1_OFFSET    0x0894  /* ColorConv blue coeff 1 */
+#define STM32_DCMIPP_P1CCBR2_OFFSET    0x0898  /* ColorConv blue coeff 2 */
+#define STM32_DCMIPP_P1FCTCR_OFFSET    0x0900  /* Flow control config */
+#define STM32_DCMIPP_P1CRSTR_OFFSET    0x0904  /* Crop window start */
+#define STM32_DCMIPP_P1CRSZR_OFFSET    0x0908  /* Crop window size */
+#define STM32_DCMIPP_P1DCCR_OFFSET     0x090c  /* Decimation */
+#define STM32_DCMIPP_P1DSCR_OFFSET     0x0910  /* Downsize configuration */
+#define STM32_DCMIPP_P1DSRTIOR_OFFSET  0x0914  /* Downsize ratio */
+#define STM32_DCMIPP_P1DSSZR_OFFSET    0x0918  /* Downsize destination size */
+#define STM32_DCMIPP_P1GMCR_OFFSET     0x0970  /* Gamma configuration */
+#define STM32_DCMIPP_P1PPCR_OFFSET     0x09c0  /* Pixel packer config */
+#define STM32_DCMIPP_P1PPM0AR1_OFFSET  0x09c4  /* Memory0 address 1 */
+#define STM32_DCMIPP_P1PPM0PR_OFFSET   0x09cc  /* Memory0 pitch */
+
+/* Register Addresses *******************************************************/
+
+#define STM32_DCMIPP_PRCR       (STM32_DCMIPP_BASE + STM32_DCMIPP_PRCR_OFFSET)
+#define STM32_DCMIPP_CMCR       (STM32_DCMIPP_BASE + STM32_DCMIPP_CMCR_OFFSET)
+#define STM32_DCMIPP_CMIER      (STM32_DCMIPP_BASE + STM32_DCMIPP_CMIER_OFFSET)
+#define STM32_DCMIPP_CMSR1      (STM32_DCMIPP_BASE + STM32_DCMIPP_CMSR1_OFFSET)
+#define STM32_DCMIPP_CMSR2      (STM32_DCMIPP_BASE + STM32_DCMIPP_CMSR2_OFFSET)
+#define STM32_DCMIPP_CMFCR      (STM32_DCMIPP_BASE + STM32_DCMIPP_CMFCR_OFFSET)
+
+#define STM32_DCMIPP_P1FSCR     (STM32_DCMIPP_BASE + \
+                                 STM32_DCMIPP_P1FSCR_OFFSET)
+#define STM32_DCMIPP_P1BLCCR    (STM32_DCMIPP_BASE + \
+                                 STM32_DCMIPP_P1BLCCR_OFFSET)
+#define STM32_DCMIPP_P1EXCR1    (STM32_DCMIPP_BASE + \
+                                 STM32_DCMIPP_P1EXCR1_OFFSET)
+#define STM32_DCMIPP_P1EXCR2    (STM32_DCMIPP_BASE + \
+                                 STM32_DCMIPP_P1EXCR2_OFFSET)
+#define STM32_DCMIPP_P1ST1CR    (STM32_DCMIPP_BASE + \
+                                 STM32_DCMIPP_P1ST1CR_OFFSET)
+#define STM32_DCMIPP_P1ST2CR    (STM32_DCMIPP_BASE + \
+                                 STM32_DCMIPP_P1ST2CR_OFFSET)
+#define STM32_DCMIPP_P1ST3CR    (STM32_DCMIPP_BASE + \
+                                 STM32_DCMIPP_P1ST3CR_OFFSET)
+#define STM32_DCMIPP_P1STSTR    (STM32_DCMIPP_BASE + \
+                                 STM32_DCMIPP_P1STSTR_OFFSET)
+#define STM32_DCMIPP_P1STSZR    (STM32_DCMIPP_BASE + \
+                                 STM32_DCMIPP_P1STSZR_OFFSET)
+#define STM32_DCMIPP_P1ST1SR    (STM32_DCMIPP_BASE + \
+                                 STM32_DCMIPP_P1ST1SR_OFFSET)
+#define STM32_DCMIPP_P1ST2SR    (STM32_DCMIPP_BASE + \
+                                 STM32_DCMIPP_P1ST2SR_OFFSET)
+#define STM32_DCMIPP_P1ST3SR    (STM32_DCMIPP_BASE + \
+                                 STM32_DCMIPP_P1ST3SR_OFFSET)
+#define STM32_DCMIPP_P1DMCR     (STM32_DCMIPP_BASE + \
+                                 STM32_DCMIPP_P1DMCR_OFFSET)
+#define STM32_DCMIPP_P1CCCR     (STM32_DCMIPP_BASE + \
+                                 STM32_DCMIPP_P1CCCR_OFFSET)
+#define STM32_DCMIPP_P1CCRR1    (STM32_DCMIPP_BASE + \
+                                 STM32_DCMIPP_P1CCRR1_OFFSET)
+#define STM32_DCMIPP_P1CCRR2    (STM32_DCMIPP_BASE + \
+                                 STM32_DCMIPP_P1CCRR2_OFFSET)
+#define STM32_DCMIPP_P1CCGR1    (STM32_DCMIPP_BASE + \
+                                 STM32_DCMIPP_P1CCGR1_OFFSET)
+#define STM32_DCMIPP_P1CCGR2    (STM32_DCMIPP_BASE + \
+                                 STM32_DCMIPP_P1CCGR2_OFFSET)
+#define STM32_DCMIPP_P1CCBR1    (STM32_DCMIPP_BASE + \
+                                 STM32_DCMIPP_P1CCBR1_OFFSET)
+#define STM32_DCMIPP_P1CCBR2    (STM32_DCMIPP_BASE + \
+                                 STM32_DCMIPP_P1CCBR2_OFFSET)
+#define STM32_DCMIPP_P1FCTCR    (STM32_DCMIPP_BASE + \
+                                 STM32_DCMIPP_P1FCTCR_OFFSET)
+#define STM32_DCMIPP_P1CRSTR    (STM32_DCMIPP_BASE + \
+                                 STM32_DCMIPP_P1CRSTR_OFFSET)
+#define STM32_DCMIPP_P1CRSZR    (STM32_DCMIPP_BASE + \
+                                 STM32_DCMIPP_P1CRSZR_OFFSET)
+#define STM32_DCMIPP_P1DCCR     (STM32_DCMIPP_BASE + \
+                                 STM32_DCMIPP_P1DCCR_OFFSET)
+#define STM32_DCMIPP_P1DSCR     (STM32_DCMIPP_BASE + \
+                                 STM32_DCMIPP_P1DSCR_OFFSET)
+#define STM32_DCMIPP_P1DSRTIOR  (STM32_DCMIPP_BASE + \
+                                 STM32_DCMIPP_P1DSRTIOR_OFFSET)
+#define STM32_DCMIPP_P1DSSZR    (STM32_DCMIPP_BASE + \
+                                 STM32_DCMIPP_P1DSSZR_OFFSET)
+#define STM32_DCMIPP_P1GMCR     (STM32_DCMIPP_BASE + \
+                                 STM32_DCMIPP_P1GMCR_OFFSET)
+#define STM32_DCMIPP_P1PPCR     (STM32_DCMIPP_BASE + \
+                                 STM32_DCMIPP_P1PPCR_OFFSET)
+#define STM32_DCMIPP_P1PPM0AR1  (STM32_DCMIPP_BASE + \
+                                 STM32_DCMIPP_P1PPM0AR1_OFFSET)
+#define STM32_DCMIPP_P1PPM0PR   (STM32_DCMIPP_BASE + \
+                                 STM32_DCMIPP_P1PPM0PR_OFFSET)
+
+/* Register Bitfield Definitions ********************************************/
+
+/* Parallel interface control register */
+
+#define DCMIPP_PRCR_ENABLE         (1 << 14) /* Bit 14: Parallel interface
+                                              * enable */
+
+/* Common configuration register */
+
+#define DCMIPP_CMCR_INSEL          (1 << 0)  /* Bit 0: Input from CSI-2 host */
+
+/* Common interrupt enable, status 2 and clear registers (pipe1 and AXI) */
+
+#define DCMIPP_CMINT_ATXERR        (1 << 5)  /* Bit 5: AXI transfer error */
+#define DCMIPP_CMINT_P1LINE        (1 << 16) /* Bit 16: Pipe1 multi-line */
+#define DCMIPP_CMINT_P1FRAME       (1 << 17) /* Bit 17: Pipe1 frame done */
+#define DCMIPP_CMINT_P1VSYNC       (1 << 18) /* Bit 18: Pipe1 vertical sync */
+#define DCMIPP_CMINT_P1OVR         (1 << 23) /* Bit 23: Pipe1 overrun */
+
+/* Common status register 1 */
+
+#define DCMIPP_CMSR1_P1CPTACT      (1 << 23) /* Bit 23: Pipe1 capture active */
+
+/* Pipe1 flow selection configuration register */
+
+#define DCMIPP_P1FSCR_DTIDA_SHIFT  (0)       /* Bits 0-5: Data type ID A */
+#define DCMIPP_P1FSCR_DTIDA_MASK   (0x3f << DCMIPP_P1FSCR_DTIDA_SHIFT)
+#  define DCMIPP_P1FSCR_DTIDA(n)   ((uint32_t)(n) << DCMIPP_P1FSCR_DTIDA_SHIFT)
+#define DCMIPP_P1FSCR_DTIDB_SHIFT  (8)       /* Bits 8-13: Data type ID B */
+#define DCMIPP_P1FSCR_DTIDB_MASK   (0x3f << DCMIPP_P1FSCR_DTIDB_SHIFT)
+#define DCMIPP_P1FSCR_DTMODE_SHIFT (16)      /* Bits 16-17: Data type mode */
+#define DCMIPP_P1FSCR_DTMODE_MASK  (0x3 << DCMIPP_P1FSCR_DTMODE_SHIFT)
+#  define DCMIPP_P1FSCR_DTMODE_DTIDA (0 << DCMIPP_P1FSCR_DTMODE_SHIFT)
+#define DCMIPP_P1FSCR_PIPEDIFF     (1 << 18) /* Bit 18: Separate pipe2 flow */
+#define DCMIPP_P1FSCR_VC_SHIFT     (19)      /* Bits 19-20: Virtual channel */
+#define DCMIPP_P1FSCR_VC_MASK      (0x3 << DCMIPP_P1FSCR_VC_SHIFT)
+#  define DCMIPP_P1FSCR_VC(n)      ((uint32_t)(n) << DCMIPP_P1FSCR_VC_SHIFT)
+#define DCMIPP_P1FSCR_PIPEN        (1 << 31) /* Bit 31: Pipe enable */
+
+/* CSI-2 data types */
+
+#define DCMIPP_DT_RAW8             0x2a      /* RAW8 Bayer */
+#define DCMIPP_DT_RAW10            0x2b      /* RAW10 Bayer */
+#define DCMIPP_DT_RAW12            0x2c      /* RAW12 Bayer */
+
+/* Pipe1 black level calibration control register */
+
+#define DCMIPP_P1BLCCR_ENABLE      (1 << 0)  /* Bit 0: Enable */
+#define DCMIPP_P1BLCCR_BLCB_SHIFT  (8)       /* Bits 8-15: Blue black level */
+#define DCMIPP_P1BLCCR_BLCG_SHIFT  (16)      /* Bits 16-23: Green black level 
*/
+#define DCMIPP_P1BLCCR_BLCR_SHIFT  (24)      /* Bits 24-31: Red black level */
+
+/* Pipe1 exposure control registers (gain = MULT * 2^SHF / 128) */
+
+#define DCMIPP_P1EXCR1_ENABLE      (1 << 0)  /* Bit 0: Enable */
+#define DCMIPP_P1EXCR1_MULTR_SHIFT (20)      /* Bits 20-27: Red multiplier */
+#define DCMIPP_P1EXCR1_SHFR_SHIFT  (28)      /* Bits 28-30: Red shift */
+#define DCMIPP_P1EXCR2_MULTB_SHIFT (4)       /* Bits 4-11: Blue multiplier */
+#define DCMIPP_P1EXCR2_SHFB_SHIFT  (12)      /* Bits 12-14: Blue shift */
+#define DCMIPP_P1EXCR2_MULTG_SHIFT (20)      /* Bits 20-27: Green multiplier */
+#define DCMIPP_P1EXCR2_SHFG_SHIFT  (28)      /* Bits 28-30: Green shift */
+
+/* Pipe1 statistics 1-3 control registers */
+
+#define DCMIPP_P1STCR_ENABLE       (1 << 0)  /* Bit 0: Enable */
+#define DCMIPP_P1STCR_BINS_SHIFT   (2)       /* Bits 2-3: Bins or average
+                                              * range */
+#define DCMIPP_P1STCR_BINS_MASK    (0x3 << DCMIPP_P1STCR_BINS_SHIFT)
+#  define DCMIPP_P1STCR_AVER_ALL   (0 << DCMIPP_P1STCR_BINS_SHIFT)
+#define DCMIPP_P1STCR_SRC_SHIFT    (4)       /* Bits 4-6: Source */
+#define DCMIPP_P1STCR_SRC_MASK     (0x7 << DCMIPP_P1STCR_SRC_SHIFT)
+#  define DCMIPP_P1STCR_SRC_PRER   (0 << DCMIPP_P1STCR_SRC_SHIFT)
+#  define DCMIPP_P1STCR_SRC_PREG   (1 << DCMIPP_P1STCR_SRC_SHIFT)
+#  define DCMIPP_P1STCR_SRC_PREB   (2 << DCMIPP_P1STCR_SRC_SHIFT)
+#  define DCMIPP_P1STCR_SRC_PREL   (3 << DCMIPP_P1STCR_SRC_SHIFT)
+#  define DCMIPP_P1STCR_SRC_POSTR  (4 << DCMIPP_P1STCR_SRC_SHIFT)
+#  define DCMIPP_P1STCR_SRC_POSTG  (5 << DCMIPP_P1STCR_SRC_SHIFT)
+#  define DCMIPP_P1STCR_SRC_POSTB  (6 << DCMIPP_P1STCR_SRC_SHIFT)
+#  define DCMIPP_P1STCR_SRC_POSTL  (7 << DCMIPP_P1STCR_SRC_SHIFT)
+#define DCMIPP_P1STCR_MODE_BINS    (1 << 7)  /* Bit 7: Bins, not average */
+
+/* Pipe1 statistics window start and size registers */
+
+#define DCMIPP_P1STSTR_HSTART_SHIFT (0)      /* Bits 0-11: Horizontal start */
+#define DCMIPP_P1STSTR_VSTART_SHIFT (16)     /* Bits 16-27: Vertical start */
+#define DCMIPP_P1STSZR_HSIZE_SHIFT (0)       /* Bits 0-11: Horizontal size */
+#define DCMIPP_P1STSZR_VSIZE_SHIFT (16)      /* Bits 16-27: Vertical size */
+#define DCMIPP_P1STSZR_CROPEN      (1 << 31) /* Bit 31: Window enable */
+
+/* Pipe1 statistics 1-3 status registers (accumulation divided by 256) */
+
+#define DCMIPP_P1STSR_ACCU_MASK    (0xffffff) /* Bits 0-23: Accumulation */
+
+/* Pipe1 demosaicing configuration register */
+
+#define DCMIPP_P1DMCR_ENABLE       (1 << 0)  /* Bit 0: Enable */
+#define DCMIPP_P1DMCR_TYPE_SHIFT   (1)       /* Bits 1-2: Raw Bayer type */
+#define DCMIPP_P1DMCR_TYPE_MASK    (0x3 << DCMIPP_P1DMCR_TYPE_SHIFT)
+#  define DCMIPP_P1DMCR_TYPE_RGGB  (0 << DCMIPP_P1DMCR_TYPE_SHIFT)
+#  define DCMIPP_P1DMCR_TYPE_GRBG  (1 << DCMIPP_P1DMCR_TYPE_SHIFT)
+#  define DCMIPP_P1DMCR_TYPE_GBRG  (2 << DCMIPP_P1DMCR_TYPE_SHIFT)
+#  define DCMIPP_P1DMCR_TYPE_BGGR  (3 << DCMIPP_P1DMCR_TYPE_SHIFT)
+#define DCMIPP_P1DMCR_PEAK_SHIFT   (16)      /* Bits 16-18: Peak strength */
+#define DCMIPP_P1DMCR_LINEV_SHIFT  (20)      /* Bits 20-22: Vertical line
+                                              * strength */
+#define DCMIPP_P1DMCR_LINEH_SHIFT  (24)      /* Bits 24-26: Horizontal line
+                                              * strength */
+#define DCMIPP_P1DMCR_EDGE_SHIFT   (28)      /* Bits 28-30: Edge strength */
+
+/* Pipe1 ColorConv configuration register */
+
+#define DCMIPP_P1CCCR_ENABLE       (1 << 0)  /* Bit 0: Enable */
+
+/* Pipe1 ColorConv coefficient registers: two 11-bit signed coefficients
+ * (8 fractional bits) per register, or one coefficient and a 10-bit
+ * offset in the second register of each row.
+ */
+
+#define DCMIPP_P1CC_LOW_SHIFT      (0)       /* Bits 0-10: First coefficient */
+#define DCMIPP_P1CC_HIGH_SHIFT     (16)      /* Bits 16-26: Second
+                                              * coefficient (RG, GG, BG) */
+#define DCMIPP_P1CC_COEF_MASK      (0x7ff)
+
+/* Pipe1 flow control configuration register */
+
+#define DCMIPP_P1FCTCR_FRATE_SHIFT (0)       /* Bits 0-1: Frame capture rate */
+#define DCMIPP_P1FCTCR_FRATE_MASK  (0x3 << DCMIPP_P1FCTCR_FRATE_SHIFT)
+#define DCMIPP_P1FCTCR_CPTMODE     (1 << 2)  /* Bit 2: Snapshot mode */
+#define DCMIPP_P1FCTCR_CPTREQ      (1 << 3)  /* Bit 3: Capture requested */
+
+/* Pipe1 crop window start and size registers */
+
+#define DCMIPP_P1CRSTR_HSTART_SHIFT (0)      /* Bits 0-11: Horizontal start */
+#define DCMIPP_P1CRSTR_VSTART_SHIFT (16)     /* Bits 16-27: Vertical start */
+#define DCMIPP_P1CRSZR_HSIZE_SHIFT (0)       /* Bits 0-11: Horizontal size */
+#define DCMIPP_P1CRSZR_VSIZE_SHIFT (16)      /* Bits 16-27: Vertical size */
+#define DCMIPP_P1CRSZR_ENABLE      (1 << 31) /* Bit 31: Crop enable */
+
+/* Pipe1 decimation register (1, 1/2, 1/4 or 1/8) */
+
+#define DCMIPP_P1DCCR_ENABLE       (1 << 0)  /* Bit 0: Enable */
+#define DCMIPP_P1DCCR_HDEC_SHIFT   (1)       /* Bits 1-2: Horizontal
+                                              * decimation */
+#define DCMIPP_P1DCCR_HDEC_MASK    (0x3 << DCMIPP_P1DCCR_HDEC_SHIFT)
+#  define DCMIPP_P1DCCR_HDEC(n)    ((uint32_t)(n) << DCMIPP_P1DCCR_HDEC_SHIFT)
+#define DCMIPP_P1DCCR_VDEC_SHIFT   (3)       /* Bits 3-4: Vertical decimation 
*/
+#define DCMIPP_P1DCCR_VDEC_MASK    (0x3 << DCMIPP_P1DCCR_VDEC_SHIFT)
+#  define DCMIPP_P1DCCR_VDEC(n)    ((uint32_t)(n) << DCMIPP_P1DCCR_VDEC_SHIFT)
+
+/* Pipe1 downsize configuration, ratio and destination size registers */
+
+#define DCMIPP_P1DSCR_HDIV_SHIFT   (0)       /* Bits 0-9: Horizontal division
+                                              * factor (1024 * dst / src) */
+#define DCMIPP_P1DSCR_VDIV_SHIFT   (16)      /* Bits 16-25: Vertical division
+                                              * factor */
+#define DCMIPP_P1DSCR_ENABLE       (1 << 31) /* Bit 31: Downsize enable */
+#define DCMIPP_P1DSRTIOR_HRATIO_SHIFT (0)    /* Bits 0-15: Horizontal ratio
+                                              * (8192 * src / dst) */
+#define DCMIPP_P1DSRTIOR_VRATIO_SHIFT (16)   /* Bits 16-31: Vertical ratio */
+#define DCMIPP_P1DSSZR_HSIZE_SHIFT (0)       /* Bits 0-11: Output width */
+#define DCMIPP_P1DSSZR_VSIZE_SHIFT (16)      /* Bits 16-27: Output height */
+
+/* Pipe1 gamma configuration register */
+
+#define DCMIPP_P1GMCR_ENABLE       (1 << 0)  /* Bit 0: Gamma enable */
+
+/* Pipe1 pixel packer configuration register */
+
+#define DCMIPP_P1PPCR_FORMAT_SHIFT (0)       /* Bits 0-3: Output format */
+#define DCMIPP_P1PPCR_FORMAT_MASK  (0xf << DCMIPP_P1PPCR_FORMAT_SHIFT)
+#  define DCMIPP_P1PPCR_FORMAT_RGB888 (0 << DCMIPP_P1PPCR_FORMAT_SHIFT)
+#  define DCMIPP_P1PPCR_FORMAT_RGB565 (1 << DCMIPP_P1PPCR_FORMAT_SHIFT)
+#define DCMIPP_P1PPCR_SWAPRB       (1 << 4)  /* Bit 4: Swap red and blue */
+#define DCMIPP_P1PPCR_DBM          (1 << 16) /* Bit 16: Double buffer mode */
+
+#endif /* __ARCH_ARM_SRC_STM32N6_HARDWARE_STM32N6XXX_DCMIPP_H */
diff --git a/arch/arm/src/stm32n6/hardware/stm32n6xxx_memorymap.h 
b/arch/arm/src/stm32n6/hardware/stm32n6xxx_memorymap.h
index f12fed7231d..b6b969806e6 100644
--- a/arch/arm/src/stm32n6/hardware/stm32n6xxx_memorymap.h
+++ b/arch/arm/src/stm32n6/hardware/stm32n6xxx_memorymap.h
@@ -125,6 +125,8 @@
 /* APB5 peripherals *********************************************************/
 
 #define STM32_LTDC_BASE       0x58001000
+#define STM32_DCMIPP_BASE     0x58002000    /* DCMIPP pixel pipelines */
+#define STM32_CSI_BASE        0x58006000    /* CSI-2 host and D-PHY */
 
 /* Debug ********************************************************************/
 
diff --git a/arch/arm/src/stm32n6/hardware/stm32n6xxx_rifsc.h 
b/arch/arm/src/stm32n6/hardware/stm32n6xxx_rifsc.h
index ea461e0198e..b79eae15978 100644
--- a/arch/arm/src/stm32n6/hardware/stm32n6xxx_rifsc.h
+++ b/arch/arm/src/stm32n6/hardware/stm32n6xxx_rifsc.h
@@ -93,6 +93,8 @@
 #define RIFSC_PERIPH_OTG1HS         (1 * 32 + 24)
 #define RIFSC_PERIPH_OTG2HS         (1 * 32 + 25)
 #define RIFSC_PERIPH_ETH1           (1 * 32 + 28)
+#define RIFSC_PERIPH_CSI            (2 * 32 + 28)
+#define RIFSC_PERIPH_DCMIPP         (2 * 32 + 29)
 #define RIFSC_PERIPH_DMA2D          (3 * 32 + 5)
 #define RIFSC_PERIPH_LTDC           (3 * 32 + 6)
 #define RIFSC_PERIPH_LTDCL1         (3 * 32 + 7)
diff --git a/arch/arm/src/stm32n6/stm32_csi.c b/arch/arm/src/stm32n6/stm32_csi.c
new file mode 100644
index 00000000000..325eec98164
--- /dev/null
+++ b/arch/arm/src/stm32n6/stm32_csi.c
@@ -0,0 +1,334 @@
+/****************************************************************************
+ * arch/arm/src/stm32n6/stm32_csi.c
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/* MIPI CSI-2 host and D-PHY receiver of the STM32N6.  The D-PHY set-up
+ * (frequency ranges and test interface writes) follows the sequence of
+ * the ST HAL DCMIPP driver.
+ */
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/param.h>
+#include <stdint.h>
+#include <errno.h>
+#include <debug.h>
+
+#include <nuttx/arch.h>
+#include <nuttx/signal.h>
+
+#include "arm_internal.h"
+#include "hardware/stm32n6xxx_csi.h"
+#include "stm32_csi.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* D-PHY configuration clock frequency range for the 20 MHz IC18 clock,
+ * as programmed by the ST HAL.
+ */
+
+#define CSI_PHY_CCFR             0x28
+
+/* Physical data lanes of logical lanes 0 and 1 (no swap) */
+
+#define CSI_LANE0                1
+#define CSI_LANE1                2
+
+/* Receive errors corrupting a frame (a corrected ECC error does not) */
+
+#define CSI_ERR0                 (CSI_INT0_CRCERR | CSI_INT0_ECCERR | \
+                                  CSI_INT0_IDERR | CSI_INT0_SPKTERR | \
+                                  CSI_INT0_WDERR | CSI_INT0_SYNCERR)
+#define CSI_ERR1                 (CSI_INT1_ESOTDL(0) | \
+                                  CSI_INT1_ESOTSYNCDL(0) | \
+                                  CSI_INT1_ECTRLDL(0) | \
+                                  CSI_INT1_ESOTDL(1) | \
+                                  CSI_INT1_ESOTSYNCDL(1) | \
+                                  CSI_INT1_ECTRLDL(1))
+
+/* Timeout waiting for the virtual channel state, in milliseconds */
+
+#define CSI_VC_TIMEOUT           100
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct csi_phyfreq_s
+{
+  uint16_t rate;                 /* Upper bit rate of the range (Mbit/s) */
+  uint8_t  hsfreqrange;          /* D-PHY hsfreqrange */
+  uint16_t osc;                  /* DLL target oscillation frequency */
+};
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct csi_phyfreq_s g_csi_phyfreq[] =
+{
+  {   80, 0x00, 460 },
+  {   90, 0x10, 460 },
+  {  100, 0x20, 460 },
+  {  110, 0x30, 460 },
+  {  120, 0x01, 460 },
+  {  130, 0x11, 460 },
+  {  140, 0x21, 460 },
+  {  150, 0x31, 460 },
+  {  160, 0x02, 460 },
+  {  170, 0x12, 460 },
+  {  180, 0x22, 460 },
+  {  190, 0x32, 460 },
+  {  205, 0x03, 460 },
+  {  220, 0x13, 460 },
+  {  235, 0x23, 460 },
+  {  250, 0x33, 460 },
+  {  275, 0x04, 460 },
+  {  300, 0x14, 460 },
+  {  325, 0x25, 460 },
+  {  350, 0x35, 460 },
+  {  400, 0x05, 460 },
+  {  450, 0x16, 460 },
+  {  500, 0x26, 460 },
+  {  550, 0x37, 460 },
+  {  600, 0x07, 460 },
+  {  650, 0x18, 460 },
+  {  700, 0x28, 460 },
+  {  750, 0x39, 460 },
+  {  800, 0x09, 460 },
+  {  850, 0x19, 460 },
+  {  900, 0x29, 460 },
+  {  950, 0x3a, 460 },
+  { 1000, 0x0a, 460 },
+  { 1050, 0x1a, 460 },
+  { 1100, 0x2a, 460 },
+  { 1150, 0x3b, 460 },
+  { 1200, 0x0b, 460 },
+  { 1250, 0x1b, 460 },
+  { 1300, 0x2b, 460 },
+  { 1350, 0x3c, 460 },
+  { 1400, 0x0c, 460 },
+  { 1450, 0x1c, 460 },
+  { 1500, 0x2c, 460 },
+  { 1550, 0x3d, 285 },
+  { 1600, 0x0d, 295 },
+  { 1650, 0x1d, 304 },
+  { 1700, 0x2e, 313 },
+  { 1750, 0x3e, 322 },
+  { 1800, 0x0e, 331 },
+  { 1850, 0x1e, 341 },
+  { 1900, 0x2f, 350 },
+  { 1950, 0x3f, 359 },
+  { 2000, 0x0f, 368 },
+  { 2050, 0x40, 377 },
+  { 2100, 0x41, 387 },
+  { 2150, 0x42, 396 },
+  { 2200, 0x43, 405 },
+  { 2250, 0x44, 414 },
+  { 2300, 0x45, 423 },
+  { 2350, 0x46, 432 },
+  { 2400, 0x47, 442 },
+  { 2450, 0x48, 451 },
+  { 2500, 0x49, 460 },
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: csi_phywrite
+ *
+ * Description:
+ *   Write an 8-bit D-PHY register through the test interface: clock in the
+ *   address (MSB then LSB with TWM set) and then the data.
+ *
+ ****************************************************************************/
+
+static void csi_phywrite(uint8_t msb, uint8_t lsb, uint8_t val)
+{
+  modifyreg32(STM32_CSI_PTCR1, 0, CSI_PTCR1_TWM);
+  modifyreg32(STM32_CSI_PTCR0, 0, CSI_PTCR0_TCKEN);
+  modifyreg32(STM32_CSI_PTCR1, 0, CSI_PTCR1_TWM);
+  putreg32(0, STM32_CSI_PTCR0);
+  putreg32(0, STM32_CSI_PTCR1);
+  putreg32(CSI_PTCR1_TDI(msb), STM32_CSI_PTCR1);
+  putreg32(CSI_PTCR0_TCKEN, STM32_CSI_PTCR0);
+  putreg32(0, STM32_CSI_PTCR0);
+  modifyreg32(STM32_CSI_PTCR1, 0, CSI_PTCR1_TWM);
+  putreg32(CSI_PTCR0_TCKEN, STM32_CSI_PTCR0);
+  modifyreg32(STM32_CSI_PTCR1, 0, CSI_PTCR1_TWM | CSI_PTCR1_TDI(lsb));
+  putreg32(0, STM32_CSI_PTCR0);
+  putreg32(0, STM32_CSI_PTCR1);
+  putreg32(CSI_PTCR1_TDI(val), STM32_CSI_PTCR1);
+  putreg32(CSI_PTCR0_TCKEN, STM32_CSI_PTCR0);
+  putreg32(0, STM32_CSI_PTCR0);
+}
+
+/****************************************************************************
+ * Name: csi_waitvc
+ ****************************************************************************/
+
+static int csi_waitvc(bool running)
+{
+  int i;
+
+  for (i = 0; i <= CSI_VC_TIMEOUT; i++)
+    {
+      if (((getreg32(STM32_CSI_SR0) & CSI_SR0_VC0STATEF) != 0) == running)
+        {
+          return OK;
+        }
+
+      nxsig_usleep(1000);
+    }
+
+  return -ETIMEDOUT;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: stm32_csi_start
+ ****************************************************************************/
+
+int stm32_csi_start(unsigned int lanes, unsigned int bitrate,
+                    unsigned int bpp)
+{
+  FAR const struct csi_phyfreq_s *freq = NULL;
+  uint32_t regval;
+  int ret;
+  int i;
+
+  if (lanes < 1 || lanes > 2 || bpp < 8 || bpp > 14 || (bpp & 1) != 0)
+    {
+      return -EINVAL;
+    }
+
+  for (i = 0; i < nitems(g_csi_phyfreq); i++)
+    {
+      if (g_csi_phyfreq[i].rate >= bitrate)
+        {
+          freq = &g_csi_phyfreq[i];
+          break;
+        }
+    }
+
+  if (freq == NULL)
+    {
+      return -EINVAL;
+    }
+
+  /* Lane merger: logical lanes map to the physical lanes in order */
+
+  putreg32(0, STM32_CSI_CR);
+  putreg32(CSI_LMCFGR_LANENB(lanes) | CSI_LMCFGR_DL0MAP(CSI_LANE0) |
+           CSI_LMCFGR_DL1MAP(CSI_LANE1), STM32_CSI_LMCFGR);
+  putreg32(CSI_CR_CSIEN, STM32_CSI_CR);
+
+  /* Stop the D-PHY with all lanes disabled and pulse its test clock */
+
+  putreg32(0, STM32_CSI_PRCR);
+  putreg32(0, STM32_CSI_PCR);
+  putreg32(CSI_PTCR0_TCKEN, STM32_CSI_PTCR0);
+  nxsig_usleep(1000);
+  putreg32(0, STM32_CSI_PTCR0);
+
+  /* Frequency ranges, deskew polarity and the DLL oscillation target */
+
+  regval = CSI_PFCR_CCFR(CSI_PHY_CCFR) | CSI_PFCR_HSFR(freq->hsfreqrange);
+  putreg32(regval, STM32_CSI_PFCR);
+
+  csi_phywrite(0x00, 0x08, 0x38);
+  csi_phywrite(0x00, 0xe4, 0x11);
+  csi_phywrite(0x00, 0xe3, freq->osc >> 8);
+  csi_phywrite(0x00, 0xe2, freq->osc & 0xff);
+
+  putreg32(regval | CSI_PFCR_DLD, STM32_CSI_PFCR);
+
+  /* Enable the clock lane and the data lanes, then the D-PHY */
+
+  regval = CSI_PCR_NPWRDOWN | CSI_PCR_CLEN | CSI_PCR_DL0EN;
+  if (lanes == 2)
+    {
+      regval |= CSI_PCR_DL1EN;
+    }
+
+  putreg32(regval, STM32_CSI_PCR);
+  putreg32(CSI_PRCR_PEN, STM32_CSI_PRCR);
+  putreg32(0, STM32_CSI_PMCR);
+
+  /* Forward every data type of virtual channel 0, all with the same
+   * pixel size (CDTFT: 8 bpp = 2, 10 bpp = 3, ...).
+   */
+
+  putreg32(CSI_VC0CFGR1_CDTFT(bpp / 2 - 2) | CSI_VC0CFGR1_ALLDT,
+           STM32_CSI_VC0CFGR1);
+  modifyreg32(STM32_CSI_CR, 0, CSI_CR_VC0START);
+
+  ret = csi_waitvc(true);
+  if (ret < 0)
+    {
+      verr("ERROR: CSI virtual channel 0 did not start\n");
+      stm32_csi_stop();
+    }
+
+  return ret;
+}
+
+/****************************************************************************
+ * Name: stm32_csi_errors
+ ****************************************************************************/
+
+bool stm32_csi_errors(void)
+{
+  uint32_t err0 = getreg32(STM32_CSI_SR0) & CSI_ERR0;
+  uint32_t err1 = getreg32(STM32_CSI_SR1) & CSI_ERR1;
+
+  putreg32(err0, STM32_CSI_FCR0);
+  putreg32(err1, STM32_CSI_FCR1);
+  return err0 != 0 || err1 != 0;
+}
+
+/****************************************************************************
+ * Name: stm32_csi_stop
+ ****************************************************************************/
+
+void stm32_csi_stop(void)
+{
+  if ((getreg32(STM32_CSI_SR0) & CSI_SR0_VC0STATEF) != 0)
+    {
+      modifyreg32(STM32_CSI_CR, 0, CSI_CR_VC0STOP);
+      csi_waitvc(false);
+    }
+
+  putreg32(0, STM32_CSI_PCR);
+  putreg32(0, STM32_CSI_PRCR);
+  putreg32(0, STM32_CSI_CR);
+}
diff --git a/arch/arm/src/stm32n6/stm32_csi.h b/arch/arm/src/stm32n6/stm32_csi.h
new file mode 100644
index 00000000000..9eb9c190258
--- /dev/null
+++ b/arch/arm/src/stm32n6/stm32_csi.h
@@ -0,0 +1,82 @@
+/****************************************************************************
+ * arch/arm/src/stm32n6/stm32_csi.h
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __ARCH_ARM_SRC_STM32N6_STM32_CSI_H
+#define __ARCH_ARM_SRC_STM32N6_STM32_CSI_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <stdbool.h>
+#include <stdint.h>
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: stm32_csi_start
+ *
+ * Description:
+ *   Configure the CSI-2 host and its D-PHY and start virtual channel 0.
+ *   Every data type on virtual channel 0 is forwarded to the DCMIPP.  It
+ *   sleeps and must be called from a task.
+ *
+ * Input Parameters:
+ *   lanes   - Number of data lanes (1 or 2)
+ *   bitrate - Bit rate per lane in Mbit/s (80 to 2500)
+ *   bpp     - Bits per pixel of the stream (8, 10, 12 or 14)
+ *
+ * Returned Value:
+ *   Zero on success; a negated errno value on failure.
+ *
+ ****************************************************************************/
+
+int stm32_csi_start(unsigned int lanes, unsigned int bitrate,
+                    unsigned int bpp);
+
+/****************************************************************************
+ * Name: stm32_csi_errors
+ *
+ * Description:
+ *   Return and clear the receive errors (packet and D-PHY lane errors)
+ *   seen since the last call.
+ *
+ ****************************************************************************/
+
+bool stm32_csi_errors(void);
+
+/****************************************************************************
+ * Name: stm32_csi_stop
+ *
+ * Description:
+ *   Stop virtual channel 0, power down the D-PHY and disable the CSI-2
+ *   host.  It sleeps and must be called from a task.
+ *
+ ****************************************************************************/
+
+void stm32_csi_stop(void);
+
+#endif /* __ARCH_ARM_SRC_STM32N6_STM32_CSI_H */
diff --git a/arch/arm/src/stm32n6/stm32_dcmipp.c 
b/arch/arm/src/stm32n6/stm32_dcmipp.c
new file mode 100644
index 00000000000..42629f568d7
--- /dev/null
+++ b/arch/arm/src/stm32n6/stm32_dcmipp.c
@@ -0,0 +1,1574 @@
+/****************************************************************************
+ * arch/arm/src/stm32n6/stm32_dcmipp.c
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/* DCMIPP capture interface for raw Bayer MIPI CSI-2 sensors.
+ *
+ * Only pipe1 (the main pipe) is used:
+ *
+ *   CSI-2 VC0 -> black level -> exposure (white balance gains) ->
+ *   demosaicing -> colour correction -> decimation -> downsize ->
+ *   gamma -> RGB565 pixel packer -> memory
+ *
+ * The raw sensor is not registered with V4L2 directly: the DCMIPP
+ * registers an image sensor of its own that reports the RGB565 output
+ * formats and sizes, forwards the other controls to the raw sensor and
+ * implements V4L2_CID_EXPOSURE_AUTO and V4L2_CID_AUTO_WHITE_BALANCE.
+ *
+ * The black level, colour matrix and initial white balance gains come
+ * from the board.  The statistics unit averages R, G and B after the
+ * demosaicing over the whole frame.  From these means a
+ * worker adjusts the sensor exposure time and gain towards a target
+ * luminance (CONFIG_STM32_DCMIPP_AE) and the red and blue gains for a grey
+ * world (CONFIG_STM32_DCMIPP_AWB).
+ */
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/param.h>
+#include <sys/video_controls.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <debug.h>
+
+#include <nuttx/arch.h>
+#include <nuttx/cache.h>
+#include <nuttx/clock.h>
+#include <nuttx/irq.h>
+#include <nuttx/mutex.h>
+#include <nuttx/signal.h>
+#include <nuttx/video/video.h>
+#include <nuttx/wqueue.h>
+#include <nuttx/video/imgdata.h>
+#include <nuttx/video/imgsensor.h>
+
+#include "arm_internal.h"
+#include "chip.h"
+#include "hardware/stm32n6xxx_dcmipp.h"
+#include "hardware/stm32n6xxx_rcc.h"
+#include "stm32_csi.h"
+#include "stm32_dcmipp.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Maximum downsize factor; larger reductions use the decimation first */
+
+#define DCMIPP_DSIZE_MAX         8
+
+/* Demosaicing filter strengths: 0, no sensor specific tuning */
+
+#define DCMIPP_DM_PEAK           0
+#define DCMIPP_DM_LINEV          0
+#define DCMIPP_DM_LINEH          0
+#define DCMIPP_DM_EDGE           0
+
+#if defined(CONFIG_STM32_DCMIPP_AE) || defined(CONFIG_STM32_DCMIPP_AWB)
+#  define HAVE_DCMIPP_AUTO
+#endif
+
+/* Pipe1 interrupts: the frame start (vertical sync), the frame end and
+ * the errors.
+ */
+
+#define DCMIPP_P1_ERRS           (DCMIPP_CMINT_ATXERR | DCMIPP_CMINT_P1OVR)
+#define DCMIPP_P1_INTS           (DCMIPP_P1_ERRS | DCMIPP_CMINT_P1FRAME | \
+                                  DCMIPP_CMINT_P1VSYNC)
+
+/* Automatic exposure: dead band around the target (8-bit luminance) and
+ * limits of the exposure change in one step (Q8).  The gain table holds
+ * 2^(n / 20) in Q8.
+ */
+
+#define DCMIPP_AE_TOLERANCE      4
+#define DCMIPP_AE_RATIO_MIN      64
+#define DCMIPP_AE_RATIO_MAX      1024
+#define DCMIPP_AE_POW2_STEPS     20
+
+/* Automatic white balance: gain limits (128 = 1.0), usable green mean
+ * (8-bit) and dead band (1/32 of the gain).
+ */
+
+#define DCMIPP_AWB_GAIN_MIN      64
+#define DCMIPP_AWB_GAIN_MAX      512
+#define DCMIPP_AWB_GREEN_MIN     8
+#define DCMIPP_AWB_GREEN_MAX     224
+#define DCMIPP_AWB_DEADBAND      32
+
+/* Timeout waiting for the end of a capture, in milliseconds */
+
+#define DCMIPP_STOP_TIMEOUT      100
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct stm32_dcmipp_s
+{
+  struct imgdata_s data;              /* Must be first */
+  struct imgsensor_s isp;             /* Sensor seen by V4L2 */
+  struct v4l2_frmsizeenum frmsizes[3];
+  FAR struct imgsensor_s *sensor;     /* Raw sensor */
+  FAR const struct stm32_dcmipp_config_s *config;
+  imgdata_capture_t callback;         /* Frame completion callback */
+  FAR void *arg;                      /* Callback argument */
+  uintptr_t buf;                      /* Buffer for the next frame or 0 */
+  uint32_t framesize;                 /* Bytes in one output frame */
+  bool capturing;
+  bool armed;                         /* Capture requested into buf */
+  bool active;                        /* Frame being written into buf */
+  bool frameerr;                      /* Error during the active frame */
+#ifdef HAVE_DCMIPP_AUTO
+  struct work_s work;                 /* Statistics processing */
+  uint32_t stat[3];                   /* R, G, B sums / 256 */
+  uint32_t statpixels;                /* Pixels in the statistics window */
+  uint16_t gain[3];                   /* White balance gains, 128 = 1.0 */
+  volatile uint8_t skip;              /* Frames before the next statistics */
+  volatile bool busy;                 /* Statistics being processed */
+#endif
+#ifdef CONFIG_STM32_DCMIPP_AWB
+  volatile bool awbauto;              /* V4L2_CID_AUTO_WHITE_BALANCE */
+#endif
+#ifdef CONFIG_STM32_DCMIPP_AE
+  mutex_t aelock;                     /* AE against manual settings */
+  volatile bool aeauto;               /* V4L2_CID_EXPOSURE_AUTO is auto */
+  bool ae;                            /* Exposure time control available */
+  bool aegain;                        /* Gain control available */
+  int32_t expmin;                     /* Exposure time range */
+  int32_t expmax;
+  int32_t gainmin;                    /* Gain range */
+  int32_t gainmax;
+#endif
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int dcmipp_init(FAR struct imgdata_s *data);
+static int dcmipp_uninit(FAR struct imgdata_s *data);
+static int dcmipp_set_buf(FAR struct imgdata_s *data,
+                          uint8_t nr_datafmts,
+                          FAR imgdata_format_t *datafmts,
+                          FAR uint8_t *addr, uint32_t size);
+static int dcmipp_validate_frame_setting(FAR struct imgdata_s *data,
+                                         uint8_t nr_datafmts,
+                                         FAR imgdata_format_t *datafmts,
+                                         FAR imgdata_interval_t *interval);
+static int dcmipp_start_capture(FAR struct imgdata_s *data,
+                                uint8_t nr_datafmts,
+                                FAR imgdata_format_t *datafmts,
+                                FAR imgdata_interval_t *interval,
+                                FAR imgdata_capture_t callback,
+                                FAR void *arg);
+static int dcmipp_stop_capture(FAR struct imgdata_s *data);
+
+static bool dcmipp_isp_is_available(FAR struct imgsensor_s *sensor);
+static int dcmipp_isp_init(FAR struct imgsensor_s *sensor);
+static int dcmipp_isp_uninit(FAR struct imgsensor_s *sensor);
+static FAR const char *
+dcmipp_isp_get_driver_name(FAR struct imgsensor_s *sensor);
+static int dcmipp_isp_validate_frame_setting(FAR struct imgsensor_s *sensor,
+                                             imgsensor_stream_type_t type,
+                                             uint8_t nr_datafmts,
+                                             FAR imgsensor_format_t *fmts,
+                                             FAR imgsensor_interval_t *ival);
+static int dcmipp_isp_start_capture(FAR struct imgsensor_s *sensor,
+                                    imgsensor_stream_type_t type,
+                                    uint8_t nr_datafmts,
+                                    FAR imgsensor_format_t *fmts,
+                                    FAR imgsensor_interval_t *ival);
+static int dcmipp_isp_stop_capture(FAR struct imgsensor_s *sensor,
+                                   imgsensor_stream_type_t type);
+static int dcmipp_isp_get_frame_interval(FAR struct imgsensor_s *sensor,
+                                         imgsensor_stream_type_t type,
+                                         FAR imgsensor_interval_t *ival);
+static int
+dcmipp_isp_get_supported_value(FAR struct imgsensor_s *sensor, uint32_t id,
+                               FAR imgsensor_supported_value_t *val);
+static int dcmipp_isp_get_value(FAR struct imgsensor_s *sensor,
+                                uint32_t id, uint32_t size,
+                                FAR imgsensor_value_t *value);
+static int dcmipp_isp_set_value(FAR struct imgsensor_s *sensor,
+                                uint32_t id, uint32_t size,
+                                imgsensor_value_t value);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct imgdata_ops_s g_dcmipp_ops =
+{
+  .init                   = dcmipp_init,
+  .uninit                 = dcmipp_uninit,
+  .set_buf                = dcmipp_set_buf,
+  .validate_frame_setting = dcmipp_validate_frame_setting,
+  .start_capture          = dcmipp_start_capture,
+  .stop_capture           = dcmipp_stop_capture,
+};
+
+static const struct imgsensor_ops_s g_dcmipp_isp_ops =
+{
+  .is_available           = dcmipp_isp_is_available,
+  .init                   = dcmipp_isp_init,
+  .uninit                 = dcmipp_isp_uninit,
+  .get_driver_name        = dcmipp_isp_get_driver_name,
+  .validate_frame_setting = dcmipp_isp_validate_frame_setting,
+  .start_capture          = dcmipp_isp_start_capture,
+  .stop_capture           = dcmipp_isp_stop_capture,
+  .get_frame_interval     = dcmipp_isp_get_frame_interval,
+  .get_supported_value    = dcmipp_isp_get_supported_value,
+  .get_value              = dcmipp_isp_get_value,
+  .set_value              = dcmipp_isp_set_value,
+};
+
+/* Pipe1 output format */
+
+static const struct v4l2_fmtdesc g_dcmipp_fmtdescs[] =
+{
+  {
+    .pixelformat = V4L2_PIX_FMT_RGB565,
+    .description = "RGB565",
+  },
+};
+
+static struct stm32_dcmipp_s g_dcmipp =
+{
+  .data =
+    {
+      .ops = &g_dcmipp_ops,
+    },
+  .isp =
+    {
+      .ops = &g_dcmipp_isp_ops,
+    },
+};
+
+#ifdef CONFIG_STM32_DCMIPP_AE
+static const uint16_t g_dcmipp_pow2[DCMIPP_AE_POW2_STEPS] =
+{
+  256, 265, 274, 284, 294, 304, 315, 326, 338, 350,
+  362, 375, 388, 402, 416, 431, 446, 461, 478, 495
+};
+#endif
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: dcmipp_gain
+ *
+ * Description:
+ *   Convert a gain (128 = 1.0) to the exposure block shift and multiplier
+ *   fields: gain = MULT * 2^SHF / 128 with MULT < 256.
+ *
+ ****************************************************************************/
+
+static uint32_t dcmipp_gain(uint32_t gain, unsigned int multshift,
+                            unsigned int shfshift)
+{
+  uint32_t shift = 0;
+
+  while (gain >= 256 && shift < 7)
+    {
+      gain >>= 1;
+      shift++;
+    }
+
+  return ((gain & 0xff) << multshift) | (shift << shfshift);
+}
+
+/****************************************************************************
+ * Name: dcmipp_coef
+ *
+ * Description:
+ *   Pack two signed colour conversion coefficients (256 = 1.0).
+ *
+ ****************************************************************************/
+
+static uint32_t dcmipp_coef(int16_t low, int16_t high)
+{
+  uint32_t regval;
+
+  regval  = ((uint32_t)low & DCMIPP_P1CC_COEF_MASK) << DCMIPP_P1CC_LOW_SHIFT;
+  regval |= ((uint32_t)high & DCMIPP_P1CC_COEF_MASK) <<
+            DCMIPP_P1CC_HIGH_SHIFT;
+  return regval;
+}
+
+/****************************************************************************
+ * Name: dcmipp_setwb
+ *
+ * Description:
+ *   Program the white balance gains (128 = 1.0) of the exposure block.
+ *
+ ****************************************************************************/
+
+static void dcmipp_setwb(FAR const uint16_t *gain)
+{
+  putreg32(dcmipp_gain(gain[1], DCMIPP_P1EXCR2_MULTG_SHIFT,
+                       DCMIPP_P1EXCR2_SHFG_SHIFT) |
+           dcmipp_gain(gain[2], DCMIPP_P1EXCR2_MULTB_SHIFT,
+                       DCMIPP_P1EXCR2_SHFB_SHIFT),
+           STM32_DCMIPP_P1EXCR2);
+  putreg32(dcmipp_gain(gain[0], DCMIPP_P1EXCR1_MULTR_SHIFT,
+                       DCMIPP_P1EXCR1_SHFR_SHIFT) | DCMIPP_P1EXCR1_ENABLE,
+           STM32_DCMIPP_P1EXCR1);
+}
+
+/****************************************************************************
+ * Name: dcmipp_configisp
+ *
+ * Description:
+ *   Program the static pipe1 image processing.
+ *
+ ****************************************************************************/
+
+static void dcmipp_configisp(FAR const struct stm32_dcmipp_config_s *cfg)
+{
+  uint32_t regval;
+
+  /* Black level */
+
+  if (cfg->blacklevel != 0)
+    {
+      regval = DCMIPP_P1BLCCR_ENABLE |
+               ((uint32_t)cfg->blacklevel << DCMIPP_P1BLCCR_BLCR_SHIFT) |
+               ((uint32_t)cfg->blacklevel << DCMIPP_P1BLCCR_BLCG_SHIFT) |
+               ((uint32_t)cfg->blacklevel << DCMIPP_P1BLCCR_BLCB_SHIFT);
+    }
+  else
+    {
+      regval = 0;
+    }
+
+  putreg32(regval, STM32_DCMIPP_P1BLCCR);
+
+  /* White balance gains in the exposure block */
+
+  dcmipp_setwb(cfg->gain);
+
+  /* Demosaicing */
+
+  putreg32(DCMIPP_P1DMCR_ENABLE |
+           ((uint32_t)cfg->bayer << DCMIPP_P1DMCR_TYPE_SHIFT) |
+           (DCMIPP_DM_PEAK << DCMIPP_P1DMCR_PEAK_SHIFT) |
+           (DCMIPP_DM_LINEV << DCMIPP_P1DMCR_LINEV_SHIFT) |
+           (DCMIPP_DM_LINEH << DCMIPP_P1DMCR_LINEH_SHIFT) |
+           ((uint32_t)DCMIPP_DM_EDGE << DCMIPP_P1DMCR_EDGE_SHIFT),
+           STM32_DCMIPP_P1DMCR);
+
+  /* Colour correction matrix, no offsets and no clamping */
+
+  putreg32(dcmipp_coef(cfg->ccm[0][0], cfg->ccm[0][1]),
+           STM32_DCMIPP_P1CCRR1);
+  putreg32(dcmipp_coef(cfg->ccm[0][2], 0), STM32_DCMIPP_P1CCRR2);
+  putreg32(dcmipp_coef(cfg->ccm[1][0], cfg->ccm[1][1]),
+           STM32_DCMIPP_P1CCGR1);
+  putreg32(dcmipp_coef(cfg->ccm[1][2], 0), STM32_DCMIPP_P1CCGR2);
+  putreg32(dcmipp_coef(cfg->ccm[2][0], cfg->ccm[2][1]),
+           STM32_DCMIPP_P1CCBR1);
+  putreg32(dcmipp_coef(cfg->ccm[2][2], 0), STM32_DCMIPP_P1CCBR2);
+  putreg32(DCMIPP_P1CCCR_ENABLE, STM32_DCMIPP_P1CCCR);
+
+  /* Gamma */
+
+  putreg32(cfg->gamma ? DCMIPP_P1GMCR_ENABLE : 0, STM32_DCMIPP_P1GMCR);
+}
+
+#ifdef HAVE_DCMIPP_AUTO
+/****************************************************************************
+ * Name: dcmipp_configstats
+ *
+ * Description:
+ *   Average R, G and B after the demosaicing over the whole sensor frame
+ *   (average metering).  The 24-bit sums / 256 hold a full 5 MP frame.
+ *
+ ****************************************************************************/
+
+static void dcmipp_configstats(FAR struct stm32_dcmipp_s *priv)
+{
+  FAR const struct stm32_dcmipp_config_s *cfg = priv->config;
+  uint32_t width  = cfg->width & ~1;
+  uint32_t height = cfg->height & ~1;
+
+  putreg32(0, STM32_DCMIPP_P1STSTR);
+  putreg32((width << DCMIPP_P1STSZR_HSIZE_SHIFT) |
+           (height << DCMIPP_P1STSZR_VSIZE_SHIFT) | DCMIPP_P1STSZR_CROPEN,
+           STM32_DCMIPP_P1STSZR);
+
+  putreg32(DCMIPP_P1STCR_ENABLE | DCMIPP_P1STCR_SRC_POSTR |
+           DCMIPP_P1STCR_AVER_ALL, STM32_DCMIPP_P1ST1CR);
+  putreg32(DCMIPP_P1STCR_ENABLE | DCMIPP_P1STCR_SRC_POSTG |
+           DCMIPP_P1STCR_AVER_ALL, STM32_DCMIPP_P1ST2CR);
+  putreg32(DCMIPP_P1STCR_ENABLE | DCMIPP_P1STCR_SRC_POSTB |
+           DCMIPP_P1STCR_AVER_ALL, STM32_DCMIPP_P1ST3CR);
+
+  priv->statpixels = width * height;
+}
+#endif
+
+#ifdef CONFIG_STM32_DCMIPP_AE
+/****************************************************************************
+ * Name: dcmipp_aetotal
+ *
+ * Description:
+ *   Exposure time times the linear sensor gain, Q8.
+ *
+ ****************************************************************************/
+
+static uint64_t dcmipp_aetotal(FAR struct stm32_dcmipp_s *priv,
+                               int32_t exposure, int32_t gain)
+{
+  uint32_t steps = priv->config->gainsteps;
+  uint32_t shift;
+  uint32_t g;
+
+  exposure = MIN(MAX(exposure, priv->expmin), priv->expmax);
+  if (!priv->aegain)
+    {
+      return (uint64_t)exposure << 8;
+    }
+
+  g     = MIN(MAX(gain, priv->gainmin), priv->gainmax) - priv->gainmin;
+  shift = MIN(g / steps, 31);
+
+  return ((uint64_t)exposure *
+          g_dcmipp_pow2[(g % steps) * DCMIPP_AE_POW2_STEPS / steps]) <<
+         shift;
+}
+
+/****************************************************************************
+ * Name: dcmipp_aesplit
+ *
+ * Description:
+ *   Split an exposure time times gain product (Q8) into the sensor
+ *   settings.  The exposure time is used first, the gain only adds noise.
+ *
+ ****************************************************************************/
+
+static void dcmipp_aesplit(FAR struct stm32_dcmipp_s *priv, uint64_t total,
+                           FAR int32_t *exposure, FAR int32_t *gain)
+{
+  uint32_t steps = priv->config->gainsteps;
+  uint64_t lin;
+  int32_t g = 0;
+  int i;
+
+  if (!priv->aegain || total <= ((uint64_t)priv->expmax << 8))
+    {
+      *exposure = MIN(MAX((int32_t)((total + 128) >> 8), priv->expmin),
+                      priv->expmax);
+      *gain     = priv->aegain ? priv->gainmin : 0;
+      return;
+    }
+
+  /* Linear gain (Q8) at the longest exposure time, then in sensor steps */
+
+  *exposure = priv->expmax;
+  lin       = total / priv->expmax;
+
+  while (lin >= 512 && g < priv->gainmax - priv->gainmin)
+    {
+      lin >>= 1;
+      g    += steps;
+    }
+
+  for (i = DCMIPP_AE_POW2_STEPS - 1; i > 0 && g_dcmipp_pow2[i] > lin; i--)
+    {
+    }
+
+  g    += i * steps / DCMIPP_AE_POW2_STEPS;
+  *gain = MIN(priv->gainmin + g, priv->gainmax);
+}
+
+/****************************************************************************
+ * Name: dcmipp_ae
+ *
+ * Description:
+ *   Move the sensor exposure half way to the one giving the target mean
+ *   luminance.  Nothing changes inside the dead band.
+ *
+ ****************************************************************************/
+
+static void dcmipp_ae(FAR struct stm32_dcmipp_s *priv,
+                      FAR const uint32_t *avg)
+{
+  imgsensor_value_t exposure;
+  imgsensor_value_t gain;
+  uint32_t target = CONFIG_STM32_DCMIPP_AE_TARGET << 8;
+  uint64_t total;
+  uint32_t ratio;
+  uint32_t lum;
+  int32_t newexp;
+  int32_t newgain;
+
+  if (!priv->ae)
+    {
+      return;
+    }
+
+  /* BT.601 luminance of the means, 1/256 units */
+
+  lum = (77 * avg[0] + 150 * avg[1] + 29 * avg[2]) >> 8;
+  if (abs((int32_t)lum - (int32_t)target) <= (DCMIPP_AE_TOLERANCE << 8))
+    {
+      return;
+    }
+
+  gain.value32 = 0;
+  if (IMGSENSOR_GET_VALUE(priv->sensor, IMGSENSOR_ID_EXPOSURE_ABSOLUTE,
+                          sizeof(int32_t), &exposure) < 0 ||
+      (priv->aegain &&
+       IMGSENSOR_GET_VALUE(priv->sensor, IMGSENSOR_ID_GAIN,
+                           sizeof(int32_t), &gain) < 0))
+    {
+      return;
+    }
+
+  /* Exposure ratio towards the target (Q8), limited.  Take half of it, or
+   * all of it when half does not change the coarse sensor settings.
+   */
+
+  ratio = lum > 0 ? (target << 8) / lum : DCMIPP_AE_RATIO_MAX;
+  ratio = MIN(MAX(ratio, DCMIPP_AE_RATIO_MIN), DCMIPP_AE_RATIO_MAX);
+  total = dcmipp_aetotal(priv, exposure.value32, gain.value32);
+
+  dcmipp_aesplit(priv, (total * ((ratio + 256) / 2)) >> 8,
+                 &newexp, &newgain);
+  if (newexp == exposure.value32 && newgain == gain.value32)
+    {
+      dcmipp_aesplit(priv, (total * ratio) >> 8, &newexp, &newgain);
+    }
+
+  if (newexp != exposure.value32)
+    {
+      exposure.value32 = newexp;
+      IMGSENSOR_SET_VALUE(priv->sensor, IMGSENSOR_ID_EXPOSURE_ABSOLUTE,
+                          sizeof(int32_t), exposure);
+    }
+
+  if (priv->aegain && newgain != gain.value32)
+    {
+      gain.value32 = newgain;
+      IMGSENSOR_SET_VALUE(priv->sensor, IMGSENSOR_ID_GAIN,
+                          sizeof(int32_t), gain);
+    }
+}
+#endif
+
+#ifdef CONFIG_STM32_DCMIPP_AWB
+/****************************************************************************
+ * Name: dcmipp_awb
+ *
+ * Description:
+ *   Grey world white balance: move the red and blue gains half way to the
+ *   ones matching the red and blue means to the green one.  Dark and
+ *   saturated frames are skipped.
+ *
+ ****************************************************************************/
+
+static void dcmipp_awb(FAR struct stm32_dcmipp_s *priv,
+                       FAR const uint32_t *avg)
+{
+  bool update = false;
+  uint32_t target;
+  uint32_t gain;
+  int i;
+
+  if (avg[1] < (DCMIPP_AWB_GREEN_MIN << 8) ||
+      avg[1] > (DCMIPP_AWB_GREEN_MAX << 8))
+    {
+      return;
+    }
+
+  for (i = 0; i < 3; i += 2)
+    {
+      gain   = priv->gain[i];
+      target = avg[i] > 0 ? gain * avg[1] / avg[i] : DCMIPP_AWB_GAIN_MAX;
+
+      if (abs((int32_t)target - (int32_t)gain) * DCMIPP_AWB_DEADBAND <=
+          gain)
+        {
+          continue;
+        }
+
+      gain = MIN(MAX((gain + target) / 2, DCMIPP_AWB_GAIN_MIN),
+                 DCMIPP_AWB_GAIN_MAX);
+      if (gain != priv->gain[i])
+        {
+          priv->gain[i] = gain;
+          update        = true;
+        }
+    }
+
+  if (update)
+    {
+      dcmipp_setwb(priv->gain);
+    }
+}
+#endif
+
+#ifdef HAVE_DCMIPP_AUTO
+/****************************************************************************
+ * Name: dcmipp_worker
+ *
+ * Description:
+ *   Run the automatic exposure and white balance on the latest statistics.
+ *
+ ****************************************************************************/
+
+static void dcmipp_worker(FAR void *arg)
+{
+  FAR struct stm32_dcmipp_s *priv = arg;
+  uint32_t avg[3];
+  int i;
+
+  if (priv->capturing && priv->statpixels > 0)
+    {
+      /* Means of the 8-bit components, 1/256 units */
+
+      for (i = 0; i < 3; i++)
+        {
+          avg[i] = ((uint64_t)priv->stat[i] << 16) / priv->statpixels;
+        }
+
+#ifdef CONFIG_STM32_DCMIPP_AE
+      nxmutex_lock(&priv->aelock);
+      if (priv->aeauto)
+        {
+          dcmipp_ae(priv, avg);
+        }
+
+      nxmutex_unlock(&priv->aelock);
+#endif
+#ifdef CONFIG_STM32_DCMIPP_AWB
+      if (priv->awbauto)
+        {
+          dcmipp_awb(priv, avg);
+        }
+#endif
+    }
+
+  /* Wait for frames with the new settings */
+
+  priv->skip = CONFIG_STM32_DCMIPP_ISP_INTERVAL;
+  priv->busy = false;
+}
+
+/****************************************************************************
+ * Name: dcmipp_stats
+ *
+ * Description:
+ *   Latch the statistics of the previous frame at the vertical sync and
+ *   defer their processing to the worker.
+ *
+ ****************************************************************************/
+
+static void dcmipp_stats(FAR struct stm32_dcmipp_s *priv)
+{
+  if (priv->skip > 0)
+    {
+      priv->skip--;
+      return;
+    }
+
+  if (priv->busy)
+    {
+      return;
+    }
+
+  priv->stat[0] = getreg32(STM32_DCMIPP_P1ST1SR) & DCMIPP_P1STSR_ACCU_MASK;
+  priv->stat[1] = getreg32(STM32_DCMIPP_P1ST2SR) & DCMIPP_P1STSR_ACCU_MASK;
+  priv->stat[2] = getreg32(STM32_DCMIPP_P1ST3SR) & DCMIPP_P1STSR_ACCU_MASK;
+  priv->busy    = true;
+
+  work_queue(LPWORK, &priv->work, dcmipp_worker, priv, 0);
+}
+
+/****************************************************************************
+ * Name: dcmipp_autostart
+ *
+ * Description:
+ *   Prepare the automatic exposure and white balance for a new capture.
+ *
+ ****************************************************************************/
+
+static void dcmipp_autostart(FAR struct stm32_dcmipp_s *priv)
+{
+#ifdef CONFIG_STM32_DCMIPP_AE
+  imgsensor_supported_value_t val;
+
+  /* Take the exposure time and gain ranges from the sensor */
+
+  priv->ae     = false;
+  priv->aegain = false;
+
+  if (priv->sensor != NULL &&
+      IMGSENSOR_GET_SUPPORTED_VALUE(priv->sensor,
+                                    IMGSENSOR_ID_EXPOSURE_ABSOLUTE,
+                                    &val) >= 0)
+    {
+      priv->expmin = MAX(val.u.range.minimum, 1);
+      priv->expmax = val.u.range.maximum;
+      priv->ae     = priv->expmax > priv->expmin;
+    }
+
+  if (priv->ae && priv->config->gainsteps > 0 &&
+      IMGSENSOR_GET_SUPPORTED_VALUE(priv->sensor, IMGSENSOR_ID_GAIN,
+                                    &val) >= 0)
+    {
+      priv->gainmin = val.u.range.minimum;
+      priv->gainmax = val.u.range.maximum;
+      priv->aegain  = priv->gainmax > priv->gainmin;
+    }
+#endif
+
+  /* The first frames come from the pipe start */
+
+  priv->skip = CONFIG_STM32_DCMIPP_ISP_INTERVAL;
+}
+#endif
+
+/****************************************************************************
+ * Name: dcmipp_configscaler
+ *
+ * Description:
+ *   Scale the sensor frame to the output size: decimate by powers of two
+ *   until the remaining ratio fits the downsizer.
+ *
+ ****************************************************************************/
+
+static void dcmipp_configscaler(FAR const struct stm32_dcmipp_config_s *cfg,
+                                uint32_t width, uint32_t height)
+{
+  uint32_t srcw = cfg->width;
+  uint32_t srch = cfg->height;
+  uint32_t hdec = 0;
+  uint32_t vdec = 0;
+  uint32_t hratio;
+  uint32_t vratio;
+  uint32_t hdiv;
+  uint32_t vdiv;
+
+  /* Crop to the sensor frame, so that extra lines or columns sent by the
+   * sensor never reach the memory.
+   */
+
+  putreg32(0, STM32_DCMIPP_P1CRSTR);
+  putreg32((srcw << DCMIPP_P1CRSZR_HSIZE_SHIFT) |
+           (srch << DCMIPP_P1CRSZR_VSIZE_SHIFT) | DCMIPP_P1CRSZR_ENABLE,
+           STM32_DCMIPP_P1CRSZR);
+
+  while (width * DCMIPP_DSIZE_MAX < srcw && hdec < 3)
+    {
+      hdec++;
+      srcw /= 2;
+    }
+
+  while (height * DCMIPP_DSIZE_MAX < srch && vdec < 3)
+    {
+      vdec++;
+      srch /= 2;
+    }
+
+  if (hdec != 0 || vdec != 0)
+    {
+      putreg32(DCMIPP_P1DCCR_ENABLE | DCMIPP_P1DCCR_HDEC(hdec) |
+               DCMIPP_P1DCCR_VDEC(vdec), STM32_DCMIPP_P1DCCR);
+    }
+  else
+    {
+      putreg32(0, STM32_DCMIPP_P1DCCR);
+    }
+
+  if (srcw == width && srch == height)
+    {
+      putreg32(0, STM32_DCMIPP_P1DSCR);
+      return;
+    }
+
+  /* Ratio: 8192 * src / dst; division factor: 1024 * dst / src */
+
+  hratio = MIN(srcw * 8192 / width, 65535);
+  vratio = MIN(srch * 8192 / height, 65535);
+  hdiv   = MIN(width * 1024 / srcw, 1023);
+  vdiv   = MIN(height * 1024 / srch, 1023);
+
+  putreg32((hratio << DCMIPP_P1DSRTIOR_HRATIO_SHIFT) |
+           (vratio << DCMIPP_P1DSRTIOR_VRATIO_SHIFT),
+           STM32_DCMIPP_P1DSRTIOR);
+  putreg32((width << DCMIPP_P1DSSZR_HSIZE_SHIFT) |
+           (height << DCMIPP_P1DSSZR_VSIZE_SHIFT), STM32_DCMIPP_P1DSSZR);
+  putreg32(DCMIPP_P1DSCR_ENABLE | (hdiv << DCMIPP_P1DSCR_HDIV_SHIFT) |
+           (vdiv << DCMIPP_P1DSCR_VDIV_SHIFT), STM32_DCMIPP_P1DSCR);
+}
+
+/****************************************************************************
+ * Name: dcmipp_disablepipe
+ *
+ * Description:
+ *   Let the frame being captured end, then disable pipe1.
+ *
+ ****************************************************************************/
+
+static void dcmipp_disablepipe(void)
+{
+  int i;
+
+  for (i = 0; i < DCMIPP_STOP_TIMEOUT; i++)
+    {
+      if ((getreg32(STM32_DCMIPP_CMSR1) & DCMIPP_CMSR1_P1CPTACT) == 0)
+        {
+          break;
+        }
+
+      nxsig_usleep(1000);
+    }
+
+  modifyreg32(STM32_DCMIPP_P1FSCR, DCMIPP_P1FSCR_PIPEN, 0);
+}
+
+/****************************************************************************
+ * Name: dcmipp_arm
+ *
+ * Description:
+ *   Request the capture of the next frame into priv->buf.  The pipe takes
+ *   the address and the request at the frame start.
+ *
+ ****************************************************************************/
+
+static void dcmipp_arm(FAR struct stm32_dcmipp_s *priv)
+{
+  putreg32(priv->buf, STM32_DCMIPP_P1PPM0AR1);
+  modifyreg32(STM32_DCMIPP_P1FCTCR, 0, DCMIPP_P1FCTCR_CPTREQ);
+  priv->armed = true;
+}
+
+/****************************************************************************
+ * Name: dcmipp_done
+ *
+ * Description:
+ *   Hand the frame in priv->buf to the capture framework.  Its callback
+ *   gives the next buffer with set_buf() or stops the capture.
+ *
+ ****************************************************************************/
+
+static void dcmipp_done(FAR struct stm32_dcmipp_s *priv, bool err)
+{
+  struct timespec ts;
+  struct timeval tv;
+
+  priv->buf = 0;
+  if (!priv->capturing || priv->callback == NULL)
+    {
+      return;
+    }
+
+  /* One clean and invalidate of the whole data cache drops the lines the
+   * CPU may have fetched from this buffer during the transfer and writes
+   * back any dirty line of the next one before the DCMIPP writes it.  Its
+   * cost is bounded by the cache size, not by the frame size.
+   */
+
+  up_flush_dcache_all();
+
+  clock_systime_timespec(&ts);
+  tv.tv_sec  = ts.tv_sec;
+  tv.tv_usec = ts.tv_nsec / 1000;
+
+  priv->callback(err ? EIO : 0, err ? 0 : priv->framesize, &tv, priv->arg);
+}
+
+/****************************************************************************
+ * Name: dcmipp_interrupt
+ *
+ * Description:
+ *   Each buffer gets one frame: the capture request is withdrawn at the
+ *   frame start (vertical sync), where the pipe takes it with the address,
+ *   and is renewed by set_buf() with the next buffer.  A frame starting
+ *   before that is not captured, so the DCMIPP never writes a buffer
+ *   handed back to the application.
+ *
+ ****************************************************************************/
+
+static int dcmipp_interrupt(int irq, FAR void *context, FAR void *arg)
+{
+  FAR struct stm32_dcmipp_s *priv = arg;
+  bool armed = priv->armed;
+  uint32_t status;
+
+  /* A frame start in this status precedes a request made while handling
+   * it, so only a request made before counts (armed).
+   */
+
+  status = getreg32(STM32_DCMIPP_CMSR2) & getreg32(STM32_DCMIPP_CMIER);
+  putreg32(status, STM32_DCMIPP_CMFCR);
+
+  if ((status & DCMIPP_P1_ERRS) != 0)
+    {
+      priv->frameerr = true;
+      verr("ERROR: DCMIPP %s\n", (status & DCMIPP_CMINT_ATXERR) != 0 ?
+           "AXI transfer error" : "pipe1 overrun");
+    }
+
+  if ((status & DCMIPP_CMINT_P1FRAME) != 0)
+    {
+      if (priv->active)
+        {
+          if (stm32_csi_errors())
+            {
+              priv->frameerr = true;
+            }
+
+          priv->active = false;
+          dcmipp_done(priv, priv->frameerr);
+        }
+      else if (priv->armed)
+        {
+          /* The frame start was missed: the pipe may already write the
+           * next frame into the same buffer.
+           */
+
+          modifyreg32(STM32_DCMIPP_P1FCTCR, DCMIPP_P1FCTCR_CPTREQ, 0);
+          priv->armed = false;
+          dcmipp_done(priv, true);
+        }
+    }
+
+  if ((status & DCMIPP_CMINT_P1VSYNC) != 0 && priv->capturing)
+    {
+#ifdef HAVE_DCMIPP_AUTO
+      dcmipp_stats(priv);
+#endif
+
+      /* A frame without frame end until the next start is lost */
+
+      if (priv->active)
+        {
+          priv->active = false;
+          dcmipp_done(priv, true);
+        }
+      else if (armed && priv->armed)
+        {
+          modifyreg32(STM32_DCMIPP_P1FCTCR, DCMIPP_P1FCTCR_CPTREQ, 0);
+          priv->armed    = false;
+          priv->active   = true;
+          priv->frameerr = false;
+
+          /* Drop the CSI-2 errors seen before this frame */
+
+          stm32_csi_errors();
+        }
+    }
+
+  return OK;
+}
+
+/****************************************************************************
+ * Name: dcmipp_init
+ ****************************************************************************/
+
+static int dcmipp_init(FAR struct imgdata_s *data)
+{
+  FAR struct stm32_dcmipp_s *priv = (FAR struct stm32_dcmipp_s *)data;
+  FAR const struct stm32_dcmipp_config_s *cfg = priv->config;
+  int ret;
+
+  /* Reset the DCMIPP and the CSI-2 host */
+
+  putreg32(RCC_APB5RSTR_DCMIPPRST | RCC_APB5RSTR_CSIRST,
+           STM32_RCC_APB5RSTSR);
+  putreg32(RCC_APB5RSTR_DCMIPPRST | RCC_APB5RSTR_CSIRST,
+           STM32_RCC_APB5RSTCR);
+
+  /* Serial input, pipe1 takes the raw data type of virtual channel 0 */
+
+  putreg32(0, STM32_DCMIPP_PRCR);
+  putreg32(DCMIPP_CMCR_INSEL, STM32_DCMIPP_CMCR);
+  putreg32(DCMIPP_P1FSCR_DTIDA(DCMIPP_DT_RAW8 + (cfg->bpp - 8) / 2) |
+           DCMIPP_P1FSCR_DTMODE_DTIDA | DCMIPP_P1FSCR_VC(0),
+           STM32_DCMIPP_P1FSCR);
+
+  dcmipp_configisp(cfg);
+
+#ifdef HAVE_DCMIPP_AUTO
+  dcmipp_configstats(priv);
+  priv->gain[0] = cfg->gain[0];
+  priv->gain[1] = cfg->gain[1];
+  priv->gain[2] = cfg->gain[2];
+  priv->busy    = false;
+#endif
+
+  /* Start the D-PHY and virtual channel 0 of the CSI-2 host */
+
+  ret = stm32_csi_start(cfg->lanes, cfg->bitrate, cfg->bpp);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  priv->capturing = false;
+  priv->armed     = false;
+  priv->active    = false;
+  priv->buf       = 0;
+  priv->callback  = NULL;
+  up_enable_irq(STM32_IRQ_DCMIPP);
+  return OK;
+}
+
+/****************************************************************************
+ * Name: dcmipp_uninit
+ ****************************************************************************/
+
+static int dcmipp_uninit(FAR struct imgdata_s *data)
+{
+  dcmipp_stop_capture(data);
+  up_disable_irq(STM32_IRQ_DCMIPP);
+  stm32_csi_stop();
+  return OK;
+}
+
+/****************************************************************************
+ * Name: dcmipp_set_buf
+ ****************************************************************************/
+
+static int dcmipp_set_buf(FAR struct imgdata_s *data,
+                          uint8_t nr_datafmts,
+                          FAR imgdata_format_t *datafmts,
+                          FAR uint8_t *addr, uint32_t size)
+{
+  FAR struct stm32_dcmipp_s *priv = (FAR struct stm32_dcmipp_s *)data;
+  uint32_t framesize;
+  irqstate_t flags;
+
+  framesize = datafmts[IMGDATA_FMT_MAIN].width *
+              datafmts[IMGDATA_FMT_MAIN].height * 2;
+
+  /* The buffer must be cache-line aligned so that the cache maintenance
+   * cannot touch unrelated data.
+   */
+
+  if (addr == NULL ||
+      ((uintptr_t)addr & (ARMV8M_DCACHE_LINESIZE - 1)) != 0 ||
+      size < framesize)
+    {
+      return -EINVAL;
+    }
+
+  /* No dirty line may be evicted over the frame.  From the frame interrupt
+   * dcmipp_done() has already cleaned the whole cache.
+   */
+
+  if (!up_interrupt_context())
+    {
+      up_flush_dcache((uintptr_t)addr, (uintptr_t)addr + framesize);
+    }
+
+  flags = enter_critical_section();
+
+  priv->buf       = (uintptr_t)addr;
+  priv->framesize = framesize;
+  if (priv->capturing)
+    {
+      dcmipp_arm(priv);
+    }
+
+  leave_critical_section(flags);
+  return OK;
+}
+
+/****************************************************************************
+ * Name: dcmipp_validate_frame_setting
+ ****************************************************************************/
+
+static int dcmipp_validate_frame_setting(FAR struct imgdata_s *data,
+                                         uint8_t nr_datafmts,
+                                         FAR imgdata_format_t *datafmts,
+                                         FAR imgdata_interval_t *interval)
+{
+  FAR struct stm32_dcmipp_s *priv = (FAR struct stm32_dcmipp_s *)data;
+  FAR const struct stm32_dcmipp_config_s *cfg = priv->config;
+  FAR imgdata_format_t *fmt;
+
+  if (nr_datafmts != 1 || datafmts == NULL)
+    {
+      return -EINVAL;
+    }
+
+  fmt = &datafmts[IMGDATA_FMT_MAIN];
+  if (fmt->pixelformat != IMGDATA_PIX_FMT_RGB565)
+    {
+      return -EINVAL;
+    }
+
+  /* The line pitch must be a multiple of 16 bytes; at most 1/64 of the
+   * sensor size (1/8 decimation and 1/8 downsize).
+   */
+
+  if ((fmt->width & 7) != 0 || fmt->width > cfg->width ||
+      fmt->height > cfg->height ||
+      fmt->width * 64 < cfg->width || fmt->height * 64 < cfg->height)
+    {
+      return -EINVAL;
+    }
+
+  /* Frames are whole cache lines, so that consecutive buffers never share
+   * one.
+   */
+
+  if ((fmt->width * fmt->height * 2) % ARMV8M_DCACHE_LINESIZE != 0)
+    {
+      return -EINVAL;
+    }
+
+  return OK;
+}
+
+/****************************************************************************
+ * Name: dcmipp_start_capture
+ ****************************************************************************/
+
+static int dcmipp_start_capture(FAR struct imgdata_s *data,
+                                uint8_t nr_datafmts,
+                                FAR imgdata_format_t *datafmts,
+                                FAR imgdata_interval_t *interval,
+                                FAR imgdata_capture_t callback,
+                                FAR void *arg)
+{
+  FAR struct stm32_dcmipp_s *priv = (FAR struct stm32_dcmipp_s *)data;
+  FAR imgdata_format_t *fmt = &datafmts[IMGDATA_FMT_MAIN];
+  irqstate_t flags;
+  int ret;
+
+  ret = dcmipp_validate_frame_setting(data, nr_datafmts, datafmts,
+                                      interval);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  if (priv->buf == 0 || priv->framesize != fmt->width * fmt->height * 2)
+    {
+      return -EINVAL;
+    }
+
+  /* A stop from the frame interrupt leaves the pipe enabled */
+
+  if ((getreg32(STM32_DCMIPP_P1FSCR) & DCMIPP_P1FSCR_PIPEN) != 0)
+    {
+      dcmipp_disablepipe();
+    }
+
+  dcmipp_configscaler(priv->config, fmt->width, fmt->height);
+
+  putreg32(DCMIPP_P1PPCR_FORMAT_RGB565, STM32_DCMIPP_P1PPCR);
+  putreg32(fmt->width * 2, STM32_DCMIPP_P1PPM0PR);
+
+#ifdef HAVE_DCMIPP_AUTO
+  dcmipp_autostart(priv);
+#endif
+
+  flags = enter_critical_section();
+
+  priv->callback  = callback;
+  priv->arg       = arg;
+  priv->capturing = true;
+  priv->active    = false;
+
+  /* Continuous mode, one frame per buffer (see dcmipp_interrupt()) */
+
+  putreg32(0, STM32_DCMIPP_P1FCTCR);
+  putreg32(DCMIPP_P1_INTS, STM32_DCMIPP_CMFCR);
+  modifyreg32(STM32_DCMIPP_CMIER, 0, DCMIPP_P1_INTS);
+  modifyreg32(STM32_DCMIPP_P1FSCR, 0, DCMIPP_P1FSCR_PIPEN);
+  dcmipp_arm(priv);
+
+  leave_critical_section(flags);
+  return OK;
+}
+
+/****************************************************************************
+ * Name: dcmipp_stop_capture
+ ****************************************************************************/
+
+static int dcmipp_stop_capture(FAR struct imgdata_s *data)
+{
+  FAR struct stm32_dcmipp_s *priv = (FAR struct stm32_dcmipp_s *)data;
+  irqstate_t flags;
+
+  flags = enter_critical_section();
+
+  priv->capturing = false;
+  priv->armed     = false;
+  priv->active    = false;
+  priv->buf       = 0;
+  modifyreg32(STM32_DCMIPP_P1FCTCR, DCMIPP_P1FCTCR_CPTREQ, 0);
+  modifyreg32(STM32_DCMIPP_CMIER, DCMIPP_P1_INTS, 0);
+  putreg32(DCMIPP_P1_INTS, STM32_DCMIPP_CMFCR);
+
+  leave_critical_section(flags);
+
+  /* The capture ends with the current frame.  The capture framework may
+   * stop from the frame interrupt; dcmipp_start_capture() then disables
+   * the pipe.
+   */
+
+  if (up_interrupt_context())
+    {
+#ifdef HAVE_DCMIPP_AUTO
+      work_cancel(LPWORK, &priv->work);
+      priv->busy = false;
+#endif
+    }
+  else
+    {
+#ifdef HAVE_DCMIPP_AUTO
+      work_cancel_sync(LPWORK, &priv->work);
+      priv->busy = false;
+#endif
+      dcmipp_disablepipe();
+    }
+
+  return OK;
+}
+
+/****************************************************************************
+ * Name: dcmipp_isp_sensorfmt
+ *
+ * Description:
+ *   Replace the pipe1 output format by the raw sensor frame.
+ *
+ ****************************************************************************/
+
+static int dcmipp_isp_sensorfmt(FAR struct stm32_dcmipp_s *priv,
+                                uint8_t nr_datafmts,
+                                FAR const imgsensor_format_t *fmts,
+                                FAR imgsensor_format_t *raw)
+{
+  FAR const struct stm32_dcmipp_config_s *cfg = priv->config;
+
+  if (nr_datafmts != 1 || fmts == NULL ||
+      fmts[IMGSENSOR_FMT_MAIN].pixelformat != IMGSENSOR_PIX_FMT_RGB565 ||
+      fmts[IMGSENSOR_FMT_MAIN].width > cfg->width ||
+      fmts[IMGSENSOR_FMT_MAIN].height > cfg->height)
+    {
+      return -EINVAL;
+    }
+
+  raw->width       = cfg->width;
+  raw->height      = cfg->height;
+  raw->pixelformat = cfg->pixelformat;
+  return OK;
+}
+
+/****************************************************************************
+ * Name: dcmipp_isp_is_available
+ ****************************************************************************/
+
+static bool dcmipp_isp_is_available(FAR struct imgsensor_s *sensor)
+{
+  return IMGSENSOR_IS_AVAILABLE(g_dcmipp.sensor);
+}
+
+/****************************************************************************
+ * Name: dcmipp_isp_init
+ ****************************************************************************/
+
+static int dcmipp_isp_init(FAR struct imgsensor_s *sensor)
+{
+  return IMGSENSOR_INIT(g_dcmipp.sensor);
+}
+
+/****************************************************************************
+ * Name: dcmipp_isp_uninit
+ ****************************************************************************/
+
+static int dcmipp_isp_uninit(FAR struct imgsensor_s *sensor)
+{
+  return IMGSENSOR_UNINIT(g_dcmipp.sensor);
+}
+
+/****************************************************************************
+ * Name: dcmipp_isp_get_driver_name
+ ****************************************************************************/
+
+static FAR const char *
+dcmipp_isp_get_driver_name(FAR struct imgsensor_s *sensor)
+{
+  return IMGSENSOR_GET_DRIVER_NAME(g_dcmipp.sensor);
+}
+
+/****************************************************************************
+ * Name: dcmipp_isp_validate_frame_setting
+ ****************************************************************************/
+
+static int dcmipp_isp_validate_frame_setting(FAR struct imgsensor_s *sensor,
+                                             imgsensor_stream_type_t type,
+                                             uint8_t nr_datafmts,
+                                             FAR imgsensor_format_t *fmts,
+                                             FAR imgsensor_interval_t *ival)
+{
+  imgsensor_format_t raw;
+  int ret;
+
+  ret = dcmipp_isp_sensorfmt(&g_dcmipp, nr_datafmts, fmts, &raw);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  return IMGSENSOR_VALIDATE_FRAME_SETTING(g_dcmipp.sensor, type, 1, &raw,
+                                          ival);
+}
+
+/****************************************************************************
+ * Name: dcmipp_isp_start_capture
+ ****************************************************************************/
+
+static int dcmipp_isp_start_capture(FAR struct imgsensor_s *sensor,
+                                    imgsensor_stream_type_t type,
+                                    uint8_t nr_datafmts,
+                                    FAR imgsensor_format_t *fmts,
+                                    FAR imgsensor_interval_t *ival)
+{
+  imgsensor_format_t raw;
+  int ret;
+
+  ret = dcmipp_isp_sensorfmt(&g_dcmipp, nr_datafmts, fmts, &raw);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  return IMGSENSOR_START_CAPTURE(g_dcmipp.sensor, type, 1, &raw, ival);
+}
+
+/****************************************************************************
+ * Name: dcmipp_isp_stop_capture
+ ****************************************************************************/
+
+static int dcmipp_isp_stop_capture(FAR struct imgsensor_s *sensor,
+                                   imgsensor_stream_type_t type)
+{
+  return IMGSENSOR_STOP_CAPTURE(g_dcmipp.sensor, type);
+}
+
+/****************************************************************************
+ * Name: dcmipp_isp_get_frame_interval
+ ****************************************************************************/
+
+static int dcmipp_isp_get_frame_interval(FAR struct imgsensor_s *sensor,
+                                         imgsensor_stream_type_t type,
+                                         FAR imgsensor_interval_t *ival)
+{
+  return IMGSENSOR_GET_FRAME_INTERVAL(g_dcmipp.sensor, type, ival);
+}
+
+/****************************************************************************
+ * Name: dcmipp_isp_get_supported_value
+ ****************************************************************************/
+
+static int
+dcmipp_isp_get_supported_value(FAR struct imgsensor_s *sensor, uint32_t id,
+                               FAR imgsensor_supported_value_t *val)
+{
+  switch (id)
+    {
+#ifdef CONFIG_STM32_DCMIPP_AE
+      case IMGSENSOR_ID_EXPOSURE_AUTO:
+        val->type                  = IMGSENSOR_CTRL_TYPE_INTEGER;
+        val->u.range.minimum       = IMGSENSOR_EXPOSURE_AUTO;
+        val->u.range.maximum       = IMGSENSOR_EXPOSURE_MANUAL;
+        val->u.range.step          = 1;
+        val->u.range.default_value = IMGSENSOR_EXPOSURE_AUTO;
+        return OK;
+#endif
+
+#ifdef CONFIG_STM32_DCMIPP_AWB
+      case IMGSENSOR_ID_AUTO_WHITE_BALANCE:
+        val->type                  = IMGSENSOR_CTRL_TYPE_BOOLEAN;
+        val->u.range.minimum       = 0;
+        val->u.range.maximum       = 1;
+        val->u.range.step          = 1;
+        val->u.range.default_value = 1;
+        return OK;
+#endif
+
+      default:
+        return IMGSENSOR_GET_SUPPORTED_VALUE(g_dcmipp.sensor, id, val);
+    }
+}
+
+/****************************************************************************
+ * Name: dcmipp_isp_get_value
+ ****************************************************************************/
+
+static int dcmipp_isp_get_value(FAR struct imgsensor_s *sensor,
+                                uint32_t id, uint32_t size,
+                                FAR imgsensor_value_t *value)
+{
+  switch (id)
+    {
+#ifdef CONFIG_STM32_DCMIPP_AE
+      case IMGSENSOR_ID_EXPOSURE_AUTO:
+        value->value32 = g_dcmipp.aeauto ? IMGSENSOR_EXPOSURE_AUTO :
+                                           IMGSENSOR_EXPOSURE_MANUAL;
+        return OK;
+#endif
+
+#ifdef CONFIG_STM32_DCMIPP_AWB
+      case IMGSENSOR_ID_AUTO_WHITE_BALANCE:
+        value->value32 = g_dcmipp.awbauto;
+        return OK;
+#endif
+
+      default:
+        return IMGSENSOR_GET_VALUE(g_dcmipp.sensor, id, size, value);
+    }
+}
+
+/****************************************************************************
+ * Name: dcmipp_isp_set_value
+ *
+ * Description:
+ *   With the automatic exposure on, the exposure time and the gain belong
+ *   to it; with it off, the values set by the application are kept.
+ *
+ ****************************************************************************/
+
+static int dcmipp_isp_set_value(FAR struct imgsensor_s *sensor,
+                                uint32_t id, uint32_t size,
+                                imgsensor_value_t value)
+{
+#ifdef CONFIG_STM32_DCMIPP_AE
+  int ret;
+#endif
+
+  switch (id)
+    {
+#ifdef CONFIG_STM32_DCMIPP_AE
+      case IMGSENSOR_ID_EXPOSURE_AUTO:
+        if (value.value32 != IMGSENSOR_EXPOSURE_AUTO &&
+            value.value32 != IMGSENSOR_EXPOSURE_MANUAL)
+          {
+            return -EINVAL;
+          }
+
+        nxmutex_lock(&g_dcmipp.aelock);
+        g_dcmipp.aeauto = value.value32 == IMGSENSOR_EXPOSURE_AUTO;
+        nxmutex_unlock(&g_dcmipp.aelock);
+        return OK;
+
+      case IMGSENSOR_ID_EXPOSURE_ABSOLUTE:
+      case IMGSENSOR_ID_GAIN:
+        nxmutex_lock(&g_dcmipp.aelock);
+        ret = g_dcmipp.aeauto ? -EBUSY :
+              IMGSENSOR_SET_VALUE(g_dcmipp.sensor, id, size, value);
+        nxmutex_unlock(&g_dcmipp.aelock);
+        return ret;
+#endif
+
+#ifdef CONFIG_STM32_DCMIPP_AWB
+      case IMGSENSOR_ID_AUTO_WHITE_BALANCE:
+        g_dcmipp.awbauto = value.value32 != 0;
+        return OK;
+#endif
+
+      default:
+        break;
+    }
+
+  return IMGSENSOR_SET_VALUE(g_dcmipp.sensor, id, size, value);
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: stm32_dcmipp_initialize
+ ****************************************************************************/
+
+int stm32_dcmipp_initialize(FAR const struct stm32_dcmipp_config_s *config,
+                            FAR struct imgsensor_s *sensor)
+{
+  FAR struct stm32_dcmipp_s *priv = &g_dcmipp;
+  int ret;
+  int i;
+
+  if (config == NULL || sensor == NULL || config->bpp < 8 ||
+      config->bpp > 14 || (config->bpp & 1) != 0 ||
+      config->bayer > STM32_DCMIPP_BAYER_BGGR)
+    {
+      return -EINVAL;
+    }
+
+  priv->config = config;
+  priv->sensor = sensor;
+#ifdef CONFIG_STM32_DCMIPP_AE
+  nxmutex_init(&priv->aelock);
+  priv->aeauto = true;
+#endif
+#ifdef CONFIG_STM32_DCMIPP_AWB
+  priv->awbauto = true;
+#endif
+
+  /* QVGA, VGA and the sensor size; any size accepted by
+   * dcmipp_validate_frame_setting() can be set.
+   */
+
+  for (i = 0; i < nitems(priv->frmsizes); i++)
+    {
+      priv->frmsizes[i].type = V4L2_FRMSIZE_TYPE_DISCRETE;
+    }
+
+  priv->frmsizes[0].discrete.width  = VIDEO_HSIZE_QVGA;
+  priv->frmsizes[0].discrete.height = VIDEO_VSIZE_QVGA;
+  priv->frmsizes[1].discrete.width  = VIDEO_HSIZE_VGA;
+  priv->frmsizes[1].discrete.height = VIDEO_VSIZE_VGA;
+  priv->frmsizes[2].discrete.width  = config->width;
+  priv->frmsizes[2].discrete.height = config->height;
+
+  priv->isp.fmtdescs         = g_dcmipp_fmtdescs;
+  priv->isp.fmtdescs_num     = nitems(g_dcmipp_fmtdescs);
+  priv->isp.frmsizes         = priv->frmsizes;
+  priv->isp.frmsizes_num     = nitems(priv->frmsizes);
+  priv->isp.frmintervals     = sensor->frmintervals;
+  priv->isp.frmintervals_num = sensor->frmintervals_num;
+
+  ret = irq_attach(STM32_IRQ_DCMIPP, dcmipp_interrupt, priv);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  imgdata_register(&priv->data);
+  return imgsensor_register(&priv->isp);
+}
diff --git a/arch/arm/src/stm32n6/stm32_dcmipp.h 
b/arch/arm/src/stm32n6/stm32_dcmipp.h
new file mode 100644
index 00000000000..46e6ef65224
--- /dev/null
+++ b/arch/arm/src/stm32n6/stm32_dcmipp.h
@@ -0,0 +1,101 @@
+/****************************************************************************
+ * arch/arm/src/stm32n6/stm32_dcmipp.h
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __ARCH_ARM_SRC_STM32N6_STM32_DCMIPP_H
+#define __ARCH_ARM_SRC_STM32N6_STM32_DCMIPP_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <stdbool.h>
+#include <stdint.h>
+
+#include <nuttx/video/imgdata.h>
+#include <nuttx/video/imgsensor.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Bayer patterns of the raw sensor data */
+
+#define STM32_DCMIPP_BAYER_RGGB  0
+#define STM32_DCMIPP_BAYER_GRBG  1
+#define STM32_DCMIPP_BAYER_GBRG  2
+#define STM32_DCMIPP_BAYER_BGGR  3
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* Description of the raw Bayer CSI-2 sensor attached to the DCMIPP and the
+ * image signal processing applied in pipe1.  The white balance gains are
+ * the initial ones with CONFIG_STM32_DCMIPP_AWB.
+ */
+
+struct stm32_dcmipp_config_s
+{
+  uint16_t width;          /* Sensor frame width in pixels */
+  uint16_t height;         /* Sensor frame height in lines */
+  uint32_t pixelformat;    /* Sensor format, IMGSENSOR_PIX_FMT_xxx */
+  uint8_t  lanes;          /* CSI-2 data lanes (1 or 2) */
+  uint16_t bitrate;        /* CSI-2 bit rate per lane in Mbit/s */
+  uint8_t  bpp;            /* Raw bits per pixel (8, 10, 12 or 14) */
+  uint8_t  bayer;          /* STM32_DCMIPP_BAYER_xxx */
+  uint8_t  blacklevel;     /* Black level subtracted (8-bit scale) */
+  uint16_t gain[3];        /* R, G, B white balance gains, 128 = 1.0 */
+  int16_t  ccm[3][3];      /* Colour correction matrix, 256 = 1.0 */
+  bool     gamma;          /* Enable the gamma correction */
+  uint8_t  gainsteps;      /* Sensor gain steps doubling the gain (AE),
+                            * 0: exposure time only */
+};
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: stm32_dcmipp_initialize
+ *
+ * Description:
+ *   Initialize the DCMIPP and CSI-2 host capture interface.  Pipe1
+ *   demosaics the raw stream and outputs RGB565 frames scaled to the
+ *   requested size.  The DCMIPP registers itself as the image data and,
+ *   in front of the raw sensor, as the image sensor of the capture
+ *   framework; do not register the raw sensor.
+ *
+ * Input Parameters:
+ *   config - Sensor and image processing description; must stay valid
+ *   sensor - Raw sensor
+ *
+ * Returned Value:
+ *   Zero on success; a negated errno value on failure.
+ *
+ ****************************************************************************/
+
+int stm32_dcmipp_initialize(FAR const struct stm32_dcmipp_config_s *config,
+                            FAR struct imgsensor_s *sensor);
+
+#endif /* __ARCH_ARM_SRC_STM32N6_STM32_DCMIPP_H */
diff --git a/arch/arm/src/stm32n6/stm32_rif.c b/arch/arm/src/stm32n6/stm32_rif.c
index 4c4297bc113..a658ccc89b6 100644
--- a/arch/arm/src/stm32n6/stm32_rif.c
+++ b/arch/arm/src/stm32n6/stm32_rif.c
@@ -107,6 +107,14 @@ void stm32_rifconfig(void)
   rif_setslave_secpriv(RIFSC_PERIPH_DMA2D);
 #endif
 
+#ifdef CONFIG_STM32_DCMIPP
+  /* The DCMIPP writes the camera frames to Secure AXISRAM */
+
+  rif_setmaster(RIFSC_MASTER_DCMIPP, RIF_MASTER_CID1_SEC_PRIV);
+  rif_setslave_secpriv(RIFSC_PERIPH_DCMIPP);
+  rif_setslave_secpriv(RIFSC_PERIPH_CSI);
+#endif
+
 #ifdef CONFIG_STM32_SDMMC1
   /* The SDMMC IDMA reads and writes buffers in Secure AXISRAM */
 
diff --git a/arch/arm/src/stm32n6/stm32n6xx_rcc.c 
b/arch/arm/src/stm32n6/stm32n6xx_rcc.c
index ee3df3d3347..826792fbdf4 100644
--- a/arch/arm/src/stm32n6/stm32n6xx_rcc.c
+++ b/arch/arm/src/stm32n6/stm32n6xx_rcc.c
@@ -527,6 +527,10 @@ static inline void rcc_enableapb5(void)
   regval |= RCC_APB5ENR_LTDCEN;
 #endif
 
+#ifdef CONFIG_STM32_DCMIPP
+  regval |= RCC_APB5ENR_DCMIPPEN | RCC_APB5ENR_CSIEN;
+#endif
+
   if (regval != 0)
     {
       putreg32(regval, STM32_RCC_APB5ENSR);

Reply via email to