linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 00/15] Intel IPU6 and IPU6 input system drivers
@ 2023-10-24 11:29 bingbu.cao
  2023-10-24 11:29 ` [PATCH v2 01/15] media: intel/ipu6: add Intel IPU6 PCI device driver bingbu.cao
                   ` (16 more replies)
  0 siblings, 17 replies; 86+ messages in thread
From: bingbu.cao @ 2023-10-24 11:29 UTC (permalink / raw)
  To: linux-media, sakari.ailus, laurent.pinchart
  Cc: andriy.shevchenko, hdegoede, ilpo.jarvinen, andreaskleist,
	claus.stovgaard, tfiga, senozhatsky, tomi.valkeinen, bingbu.cao,
	bingbu.cao, tian.shu.qiu, hongju.wang

From: Bingbu Cao <bingbu.cao@intel.com>

This patch series adds a driver for Intel IPU6 input system.
IPU6 is the sixth generation of Imaging Processing Unit, it is a PCI
device which can be found in some Intel Client Platforms. User can use
IPU6 to capture images from MIPI camera sensors.

IPU6 has its own firmware which exposes ABIs to driver, and communicates
with CSE to do firmware authentication. IPU6 has its MMU hardware, so
the driver sets up a page table to allow IPU6 DMA to access the system
memory.

IPU6 input system driver uses MC and V4L2 sub-device APIs besides V4L2.
---

v1 -> v2:
  - Add support with latest v4l2 async API
  - Add support for latest bridge and Intel ivsc driver
  - Fix lots of coding style issues not covered by checkpatch.pl
  - Fix several bugs
  - Fix several code issues found by Sparse and cppcheck

RFC -> v1:
  - Add multiplexed streams support
  - Use auxiliary bus to register IPU6 devices
  - Add IPU6 hardware and driver overview documentation
  - Updata IPU6 admin-guide documentation
  - Update number of source pads and video nodes to support
    multiplexed streams

Bingbu Cao (15):
  media: intel/ipu6: add Intel IPU6 PCI device driver
  media: intel/ipu6: add IPU auxiliary devices
  media: intel/ipu6: add IPU6 buttress interface driver
  media: intel/ipu6: CPD parsing for get firmware components
  media: intel/ipu6: add IPU6 DMA mapping API and MMU table
  media: intel/ipu6: add syscom interfaces between firmware and driver
  media: intel/ipu6: input system ABI between firmware and driver
  media: intel/ipu6: add IPU6 CSI2 receiver v4l2 sub-device
  media: intel/ipu6: add the CSI2 DPHY implementation
  media: intel/ipu6: add input system driver
  media: intel/ipu6: input system video capture nodes
  media: add Kconfig and Makefile for IPU6
  MAINTAINERS: add maintainers for Intel IPU6 input system driver
  Documentation: add Intel IPU6 ISYS driver admin-guide doc
  Documentation: add documentation of Intel IPU6 driver and hardware
    overview

 Documentation/admin-guide/media/ipu6-isys.rst |  159 ++
 .../admin-guide/media/ipu6_isys_graph.svg     |  338 +++++
 .../admin-guide/media/ipu6_isys_multi.svg     | 1124 ++++++++++++++
 .../admin-guide/media/v4l-drivers.rst         |    1 +
 .../driver-api/media/drivers/index.rst        |    1 +
 .../driver-api/media/drivers/ipu6.rst         |  205 +++
 MAINTAINERS                                   |   10 +
 drivers/media/pci/intel/Kconfig               |    1 +
 drivers/media/pci/intel/Makefile              |    1 +
 drivers/media/pci/intel/ipu6/Kconfig          |   17 +
 drivers/media/pci/intel/ipu6/Makefile         |   23 +
 drivers/media/pci/intel/ipu6/ipu6-bus.c       |  157 ++
 drivers/media/pci/intel/ipu6/ipu6-bus.h       |   50 +
 drivers/media/pci/intel/ipu6/ipu6-buttress.c  |  900 +++++++++++
 drivers/media/pci/intel/ipu6/ipu6-buttress.h  |  107 ++
 drivers/media/pci/intel/ipu6/ipu6-cpd.c       |  355 +++++
 drivers/media/pci/intel/ipu6/ipu6-cpd.h       |  104 ++
 drivers/media/pci/intel/ipu6/ipu6-dma.c       |  491 ++++++
 drivers/media/pci/intel/ipu6/ipu6-dma.h       |   20 +
 drivers/media/pci/intel/ipu6/ipu6-fw-com.c    |  411 +++++
 drivers/media/pci/intel/ipu6/ipu6-fw-com.h    |   47 +
 drivers/media/pci/intel/ipu6/ipu6-fw-isys.c   |  484 ++++++
 drivers/media/pci/intel/ipu6/ipu6-fw-isys.h   |  570 +++++++
 drivers/media/pci/intel/ipu6/ipu6-isys-csi2.c |  654 ++++++++
 drivers/media/pci/intel/ipu6/ipu6-isys-csi2.h |   81 +
 .../media/pci/intel/ipu6/ipu6-isys-dwc-phy.c  |  533 +++++++
 .../media/pci/intel/ipu6/ipu6-isys-jsl-phy.c  |  237 +++
 .../media/pci/intel/ipu6/ipu6-isys-mcd-phy.c  |  712 +++++++++
 .../media/pci/intel/ipu6/ipu6-isys-queue.c    |  846 +++++++++++
 .../media/pci/intel/ipu6/ipu6-isys-queue.h    |   94 ++
 .../media/pci/intel/ipu6/ipu6-isys-subdev.c   |  379 +++++
 .../media/pci/intel/ipu6/ipu6-isys-subdev.h   |   58 +
 .../media/pci/intel/ipu6/ipu6-isys-video.c    | 1239 +++++++++++++++
 .../media/pci/intel/ipu6/ipu6-isys-video.h    |  129 ++
 drivers/media/pci/intel/ipu6/ipu6-isys.c      | 1345 +++++++++++++++++
 drivers/media/pci/intel/ipu6/ipu6-isys.h      |  201 +++
 drivers/media/pci/intel/ipu6/ipu6-mmu.c       |  828 ++++++++++
 drivers/media/pci/intel/ipu6/ipu6-mmu.h       |   67 +
 .../intel/ipu6/ipu6-platform-buttress-regs.h  |  230 +++
 .../intel/ipu6/ipu6-platform-isys-csi2-reg.h  |  187 +++
 .../media/pci/intel/ipu6/ipu6-platform-regs.h |  179 +++
 drivers/media/pci/intel/ipu6/ipu6.c           |  955 ++++++++++++
 drivers/media/pci/intel/ipu6/ipu6.h           |  352 +++++
 43 files changed, 14882 insertions(+)
 create mode 100644 Documentation/admin-guide/media/ipu6-isys.rst
 create mode 100644 Documentation/admin-guide/media/ipu6_isys_graph.svg
 create mode 100644 Documentation/admin-guide/media/ipu6_isys_multi.svg
 create mode 100644 Documentation/driver-api/media/drivers/ipu6.rst
 create mode 100644 drivers/media/pci/intel/ipu6/Kconfig
 create mode 100644 drivers/media/pci/intel/ipu6/Makefile
 create mode 100644 drivers/media/pci/intel/ipu6/ipu6-bus.c
 create mode 100644 drivers/media/pci/intel/ipu6/ipu6-bus.h
 create mode 100644 drivers/media/pci/intel/ipu6/ipu6-buttress.c
 create mode 100644 drivers/media/pci/intel/ipu6/ipu6-buttress.h
 create mode 100644 drivers/media/pci/intel/ipu6/ipu6-cpd.c
 create mode 100644 drivers/media/pci/intel/ipu6/ipu6-cpd.h
 create mode 100644 drivers/media/pci/intel/ipu6/ipu6-dma.c
 create mode 100644 drivers/media/pci/intel/ipu6/ipu6-dma.h
 create mode 100644 drivers/media/pci/intel/ipu6/ipu6-fw-com.c
 create mode 100644 drivers/media/pci/intel/ipu6/ipu6-fw-com.h
 create mode 100644 drivers/media/pci/intel/ipu6/ipu6-fw-isys.c
 create mode 100644 drivers/media/pci/intel/ipu6/ipu6-fw-isys.h
 create mode 100644 drivers/media/pci/intel/ipu6/ipu6-isys-csi2.c
 create mode 100644 drivers/media/pci/intel/ipu6/ipu6-isys-csi2.h
 create mode 100644 drivers/media/pci/intel/ipu6/ipu6-isys-dwc-phy.c
 create mode 100644 drivers/media/pci/intel/ipu6/ipu6-isys-jsl-phy.c
 create mode 100644 drivers/media/pci/intel/ipu6/ipu6-isys-mcd-phy.c
 create mode 100644 drivers/media/pci/intel/ipu6/ipu6-isys-queue.c
 create mode 100644 drivers/media/pci/intel/ipu6/ipu6-isys-queue.h
 create mode 100644 drivers/media/pci/intel/ipu6/ipu6-isys-subdev.c
 create mode 100644 drivers/media/pci/intel/ipu6/ipu6-isys-subdev.h
 create mode 100644 drivers/media/pci/intel/ipu6/ipu6-isys-video.c
 create mode 100644 drivers/media/pci/intel/ipu6/ipu6-isys-video.h
 create mode 100644 drivers/media/pci/intel/ipu6/ipu6-isys.c
 create mode 100644 drivers/media/pci/intel/ipu6/ipu6-isys.h
 create mode 100644 drivers/media/pci/intel/ipu6/ipu6-mmu.c
 create mode 100644 drivers/media/pci/intel/ipu6/ipu6-mmu.h
 create mode 100644 drivers/media/pci/intel/ipu6/ipu6-platform-buttress-regs.h
 create mode 100644 drivers/media/pci/intel/ipu6/ipu6-platform-isys-csi2-reg.h
 create mode 100644 drivers/media/pci/intel/ipu6/ipu6-platform-regs.h
 create mode 100644 drivers/media/pci/intel/ipu6/ipu6.c
 create mode 100644 drivers/media/pci/intel/ipu6/ipu6.h

-- 
2.42.0


^ permalink raw reply	[flat|nested] 86+ messages in thread

* [PATCH v2 01/15] media: intel/ipu6: add Intel IPU6 PCI device driver
  2023-10-24 11:29 [PATCH v2 00/15] Intel IPU6 and IPU6 input system drivers bingbu.cao
@ 2023-10-24 11:29 ` bingbu.cao
  2023-10-25 12:39   ` Andreas Helbech Kleist
                     ` (3 more replies)
  2023-10-24 11:29 ` [PATCH v2 02/15] media: intel/ipu6: add IPU auxiliary devices bingbu.cao
                   ` (15 subsequent siblings)
  16 siblings, 4 replies; 86+ messages in thread
From: bingbu.cao @ 2023-10-24 11:29 UTC (permalink / raw)
  To: linux-media, sakari.ailus, laurent.pinchart
  Cc: andriy.shevchenko, hdegoede, ilpo.jarvinen, andreaskleist,
	claus.stovgaard, tfiga, senozhatsky, tomi.valkeinen, bingbu.cao,
	bingbu.cao, tian.shu.qiu, hongju.wang

From: Bingbu Cao <bingbu.cao@intel.com>

Intel Image Processing Unit 6th Gen includes input and processing systems
but the hardware presents itself as a single PCI device in system.

IPU6 PCI device driver basically does PCI configurations and load
the firmware binary, initialises IPU virtual bus, and sets up platform
specific variants to support multiple IPU6 devices in single device
driver.

Signed-off-by: Bingbu Cao <bingbu.cao@intel.com>
Reported-by: Hans de Goede <hdegoede@redhat.com>
Suggested-by: Andreas Helbech Kleist <andreaskleist@gmail.com>
---
 .../media/pci/intel/ipu6/ipu6-platform-regs.h | 179 ++++
 drivers/media/pci/intel/ipu6/ipu6.c           | 952 ++++++++++++++++++
 drivers/media/pci/intel/ipu6/ipu6.h           | 352 +++++++
 3 files changed, 1483 insertions(+)
 create mode 100644 drivers/media/pci/intel/ipu6/ipu6-platform-regs.h
 create mode 100644 drivers/media/pci/intel/ipu6/ipu6.c
 create mode 100644 drivers/media/pci/intel/ipu6/ipu6.h

diff --git a/drivers/media/pci/intel/ipu6/ipu6-platform-regs.h b/drivers/media/pci/intel/ipu6/ipu6-platform-regs.h
new file mode 100644
index 000000000000..cae26009c9fc
--- /dev/null
+++ b/drivers/media/pci/intel/ipu6/ipu6-platform-regs.h
@@ -0,0 +1,179 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/* Copyright (C) 2018 - 2023 Intel Corporation */
+
+#ifndef IPU6_PLATFORM_REGS_H
+#define IPU6_PLATFORM_REGS_H
+
+#include <linux/bits.h>
+
+/*
+ * IPU6 uses uniform address within IPU6, therefore all subsystem registers
+ * locates in one single space starts from 0 but in different sctions with
+ * different addresses, the subsystem offsets are defined to 0 as the
+ * register definition will have the address offset to 0.
+ */
+#define IPU6_UNIFIED_OFFSET			0
+
+#define IPU6_ISYS_IOMMU0_OFFSET		0x2e0000
+#define IPU6_ISYS_IOMMU1_OFFSET		0x2e0500
+#define IPU6_ISYS_IOMMUI_OFFSET		0x2e0a00
+
+#define IPU6_PSYS_IOMMU0_OFFSET		0x1b0000
+#define IPU6_PSYS_IOMMU1_OFFSET		0x1b0700
+#define IPU6_PSYS_IOMMU1R_OFFSET	0x1b0e00
+#define IPU6_PSYS_IOMMUI_OFFSET		0x1b1500
+
+/* the offset from IOMMU base register */
+#define IPU6_MMU_L1_STREAM_ID_REG_OFFSET	0x0c
+#define IPU6_MMU_L2_STREAM_ID_REG_OFFSET	0x4c
+#define IPU6_PSYS_MMU1W_L2_STREAM_ID_REG_OFFSET	0x8c
+
+#define IPU6_MMU_INFO_OFFSET		0x8
+
+#define IPU6_ISYS_SPC_OFFSET		0x210000
+
+#define IPU6SE_PSYS_SPC_OFFSET		0x110000
+#define IPU6_PSYS_SPC_OFFSET		0x118000
+
+#define IPU6_ISYS_DMEM_OFFSET		0x200000
+#define IPU6_PSYS_DMEM_OFFSET		0x100000
+
+#define IPU6_REG_ISYS_UNISPART_IRQ_EDGE			0x27c000
+#define IPU6_REG_ISYS_UNISPART_IRQ_MASK			0x27c004
+#define IPU6_REG_ISYS_UNISPART_IRQ_STATUS		0x27c008
+#define IPU6_REG_ISYS_UNISPART_IRQ_CLEAR		0x27c00c
+#define IPU6_REG_ISYS_UNISPART_IRQ_ENABLE		0x27c010
+#define IPU6_REG_ISYS_UNISPART_IRQ_LEVEL_NOT_PULSE	0x27c014
+#define IPU6_REG_ISYS_UNISPART_SW_IRQ_REG		0x27c414
+#define IPU6_REG_ISYS_UNISPART_SW_IRQ_MUX_REG		0x27c418
+#define IPU6_ISYS_UNISPART_IRQ_CSI0			BIT(2)
+#define IPU6_ISYS_UNISPART_IRQ_CSI1			BIT(3)
+#define IPU6_ISYS_UNISPART_IRQ_SW			BIT(22)
+
+#define IPU6_REG_ISYS_ISL_TOP_IRQ_EDGE			0x2b0200
+#define IPU6_REG_ISYS_ISL_TOP_IRQ_MASK			0x2b0204
+#define IPU6_REG_ISYS_ISL_TOP_IRQ_STATUS		0x2b0208
+#define IPU6_REG_ISYS_ISL_TOP_IRQ_CLEAR			0x2b020c
+#define IPU6_REG_ISYS_ISL_TOP_IRQ_ENABLE		0x2b0210
+#define IPU6_REG_ISYS_ISL_TOP_IRQ_LEVEL_NOT_PULSE	0x2b0214
+
+#define IPU6_REG_ISYS_CMPR_TOP_IRQ_EDGE			0x2d2100
+#define IPU6_REG_ISYS_CMPR_TOP_IRQ_MASK			0x2d2104
+#define IPU6_REG_ISYS_CMPR_TOP_IRQ_STATUS		0x2d2108
+#define IPU6_REG_ISYS_CMPR_TOP_IRQ_CLEAR		0x2d210c
+#define IPU6_REG_ISYS_CMPR_TOP_IRQ_ENABLE		0x2d2110
+#define IPU6_REG_ISYS_CMPR_TOP_IRQ_LEVEL_NOT_PULSE	0x2d2114
+
+/* CDC Burst collector thresholds for isys - 3 FIFOs i = 0..2 */
+#define IPU6_REG_ISYS_CDC_THRESHOLD(i)		(0x27c400 + ((i) * 4))
+
+#define IPU6_CSI_IRQ_NUM_PER_PIPE			4
+#define IPU6SE_ISYS_CSI_PORT_NUM			4
+#define IPU6_ISYS_CSI_PORT_NUM				8
+
+#define IPU6_ISYS_CSI_PORT_IRQ(irq_num)		BIT(irq_num)
+
+/* PKG DIR OFFSET in IMR in secure mode */
+#define IPU6_PKG_DIR_IMR_OFFSET			0x40
+
+#define IPU6_ISYS_REG_SPC_STATUS_CTRL		0x0
+
+#define IPU6_ISYS_SPC_STATUS_START			BIT(1)
+#define IPU6_ISYS_SPC_STATUS_RUN			BIT(3)
+#define IPU6_ISYS_SPC_STATUS_READY			BIT(5)
+#define IPU6_ISYS_SPC_STATUS_CTRL_ICACHE_INVALIDATE	BIT(12)
+#define IPU6_ISYS_SPC_STATUS_ICACHE_PREFETCH		BIT(13)
+
+#define IPU6_PSYS_REG_SPC_STATUS_CTRL			0x0
+#define IPU6_PSYS_REG_SPC_START_PC			0x4
+#define IPU6_PSYS_REG_SPC_ICACHE_BASE			0x10
+#define IPU6_REG_PSYS_INFO_SEG_0_CONFIG_ICACHE_MASTER	0x14
+
+#define IPU6_PSYS_SPC_STATUS_START			BIT(1)
+#define IPU6_PSYS_SPC_STATUS_RUN			BIT(3)
+#define IPU6_PSYS_SPC_STATUS_READY			BIT(5)
+#define IPU6_PSYS_SPC_STATUS_CTRL_ICACHE_INVALIDATE	BIT(12)
+#define IPU6_PSYS_SPC_STATUS_ICACHE_PREFETCH		BIT(13)
+
+#define IPU6_PSYS_REG_SPP0_STATUS_CTRL			0x20000
+
+#define IPU6_INFO_ENABLE_SNOOP			BIT(0)
+#define IPU6_INFO_DEC_FORCE_FLUSH		BIT(1)
+#define IPU6_INFO_DEC_PASS_THROUGH		BIT(2)
+#define IPU6_INFO_ZLW				BIT(3)
+#define IPU6_INFO_REQUEST_DESTINATION_IOSF	BIT(9)
+#define IPU6_INFO_IMR_BASE			BIT(10)
+#define IPU6_INFO_IMR_DESTINED			BIT(11)
+
+#define IPU6_INFO_REQUEST_DESTINATION_PRIMARY IPU6_INFO_REQUEST_DESTINATION_IOSF
+
+/*
+ * s2m_pixel_soc_pixel_remapping is dedicated for the enabling of the
+ * pixel s2m remp ability.Remap here  means that s2m rearange the order
+ * of the pixels in each 4 pixels group.
+ * For examle, mirroring remping means that if input's 4 first pixels
+ * are 1 2 3 4 then in output we should see 4 3 2 1 in this 4 first pixels.
+ * 0xE4 is from s2m MAS document. It means no remapping.
+ */
+#define S2M_PIXEL_SOC_PIXEL_REMAPPING_FLAG_NO_REMAPPING 0xe4
+/*
+ * csi_be_soc_pixel_remapping is for the enabling of the pixel remapping.
+ * This remapping is exactly like the stream2mmio remapping.
+ */
+#define CSI_BE_SOC_PIXEL_REMAPPING_FLAG_NO_REMAPPING    0xe4
+
+#define IPU6_REG_DMA_TOP_AB_GROUP1_BASE_ADDR		0x1ae000
+#define IPU6_REG_DMA_TOP_AB_GROUP2_BASE_ADDR		0x1af000
+#define IPU6_REG_DMA_TOP_AB_RING_MIN_OFFSET(n)		(0x4 + (n) * 0xc)
+#define IPU6_REG_DMA_TOP_AB_RING_MAX_OFFSET(n)		(0x8 + (n) * 0xc)
+#define IPU6_REG_DMA_TOP_AB_RING_ACCESS_OFFSET(n)	(0xc + (n) * 0xc)
+
+enum ipu6_device_ab_group1_target_id {
+	IPU6_DEVICE_AB_GROUP1_TARGET_ID_R0_SPC_DMEM,
+	IPU6_DEVICE_AB_GROUP1_TARGET_ID_R1_SPC_DMEM,
+	IPU6_DEVICE_AB_GROUP1_TARGET_ID_R2_SPC_DMEM,
+	IPU6_DEVICE_AB_GROUP1_TARGET_ID_R3_SPC_STATUS_REG,
+	IPU6_DEVICE_AB_GROUP1_TARGET_ID_R4_SPC_MASTER_BASE_ADDR,
+	IPU6_DEVICE_AB_GROUP1_TARGET_ID_R5_SPC_PC_STALL,
+	IPU6_DEVICE_AB_GROUP1_TARGET_ID_R6_SPC_EQ,
+	IPU6_DEVICE_AB_GROUP1_TARGET_ID_R7_SPC_RESERVED,
+	IPU6_DEVICE_AB_GROUP1_TARGET_ID_R8_SPC_RESERVED,
+	IPU6_DEVICE_AB_GROUP1_TARGET_ID_R9_SPP0,
+	IPU6_DEVICE_AB_GROUP1_TARGET_ID_R10_SPP1,
+	IPU6_DEVICE_AB_GROUP1_TARGET_ID_R11_CENTRAL_R1,
+	IPU6_DEVICE_AB_GROUP1_TARGET_ID_R12_IRQ,
+	IPU6_DEVICE_AB_GROUP1_TARGET_ID_R13_CENTRAL_R2,
+	IPU6_DEVICE_AB_GROUP1_TARGET_ID_R14_DMA,
+	IPU6_DEVICE_AB_GROUP1_TARGET_ID_R15_DMA,
+	IPU6_DEVICE_AB_GROUP1_TARGET_ID_R16_GP,
+	IPU6_DEVICE_AB_GROUP1_TARGET_ID_R17_ZLW_INSERTER,
+	IPU6_DEVICE_AB_GROUP1_TARGET_ID_R18_AB,
+};
+
+enum nci_ab_access_mode {
+	NCI_AB_ACCESS_MODE_RW,	/* read & write */
+	NCI_AB_ACCESS_MODE_RO,	/* read only */
+	NCI_AB_ACCESS_MODE_WO,	/* write only */
+	NCI_AB_ACCESS_MODE_NA,	/* No access at all */
+};
+
+/* IRQ-related registers in PSYS */
+#define IPU6_REG_PSYS_GPDEV_IRQ_EDGE		0x1aa200
+#define IPU6_REG_PSYS_GPDEV_IRQ_MASK		0x1aa204
+#define IPU6_REG_PSYS_GPDEV_IRQ_STATUS		0x1aa208
+#define IPU6_REG_PSYS_GPDEV_IRQ_CLEAR		0x1aa20c
+#define IPU6_REG_PSYS_GPDEV_IRQ_ENABLE		0x1aa210
+#define IPU6_REG_PSYS_GPDEV_IRQ_LEVEL_NOT_PULSE	0x1aa214
+/* There are 8 FW interrupts, n = 0..7 */
+#define IPU6_PSYS_GPDEV_FWIRQ0			5
+#define IPU6_PSYS_GPDEV_FWIRQ1			6
+#define IPU6_PSYS_GPDEV_FWIRQ2			7
+#define IPU6_PSYS_GPDEV_FWIRQ3			8
+#define IPU6_PSYS_GPDEV_FWIRQ4			9
+#define IPU6_PSYS_GPDEV_FWIRQ5			10
+#define IPU6_PSYS_GPDEV_FWIRQ6			11
+#define IPU6_PSYS_GPDEV_FWIRQ7			12
+#define IPU6_PSYS_GPDEV_IRQ_FWIRQ(n)		BIT(n)
+#define IPU6_REG_PSYS_GPDEV_FWIRQ(n)		(4 * (n) + 0x1aa100)
+
+#endif /* IPU6_PLATFORM_REGS_H */
diff --git a/drivers/media/pci/intel/ipu6/ipu6.c b/drivers/media/pci/intel/ipu6/ipu6.c
new file mode 100644
index 000000000000..84960a283daf
--- /dev/null
+++ b/drivers/media/pci/intel/ipu6/ipu6.c
@@ -0,0 +1,952 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2013 - 2023 Intel Corporation
+ */
+
+#include <linux/bitfield.h>
+#include <linux/module.h>
+#include <linux/pci-ats.h>
+#include <linux/pm_runtime.h>
+
+#include <media/ipu-bridge.h>
+
+#include "ipu6.h"
+#include "ipu6-cpd.h"
+#include "ipu6-isys.h"
+#include "ipu6-mmu.h"
+#include "ipu6-platform-buttress-regs.h"
+#include "ipu6-platform-isys-csi2-reg.h"
+#include "ipu6-platform-regs.h"
+
+#define IPU6_PCI_BAR		0
+
+struct ipu6_cell_program {
+	u32 magic_number;
+
+	u32 blob_offset;
+	u32 blob_size;
+
+	u32 start[3];
+
+	u32 icache_source;
+	u32 icache_target;
+	u32 icache_size;
+
+	u32 pmem_source;
+	u32 pmem_target;
+	u32 pmem_size;
+
+	u32 data_source;
+	u32 data_target;
+	u32 data_size;
+
+	u32 bss_target;
+	u32 bss_size;
+
+	u32 cell_id;
+	u32 regs_addr;
+
+	u32 cell_pmem_data_bus_address;
+	u32 cell_dmem_data_bus_address;
+	u32 cell_pmem_control_bus_address;
+	u32 cell_dmem_control_bus_address;
+
+	u32 next;
+	u32 dummy[2];
+};
+
+static u32 ipu6se_csi_offsets[] = {
+	IPU6_CSI_PORT_A_ADDR_OFFSET,
+	IPU6_CSI_PORT_B_ADDR_OFFSET,
+	IPU6_CSI_PORT_C_ADDR_OFFSET,
+	IPU6_CSI_PORT_D_ADDR_OFFSET
+};
+
+/*
+ * IPU6 on TGL support maximum 8 csi2 ports
+ * IPU6SE on JSL and IPU6EP on ADL support maximum 4 csi2 ports
+ * IPU6EP on MTL support maximum 6 csi2 ports
+ */
+static u32 ipu6_tgl_csi_offsets[] = {
+	IPU6_CSI_PORT_A_ADDR_OFFSET,
+	IPU6_CSI_PORT_B_ADDR_OFFSET,
+	IPU6_CSI_PORT_C_ADDR_OFFSET,
+	IPU6_CSI_PORT_D_ADDR_OFFSET,
+	IPU6_CSI_PORT_E_ADDR_OFFSET,
+	IPU6_CSI_PORT_F_ADDR_OFFSET,
+	IPU6_CSI_PORT_G_ADDR_OFFSET,
+	IPU6_CSI_PORT_H_ADDR_OFFSET
+};
+
+static u32 ipu6ep_mtl_csi_offsets[] = {
+	IPU6_CSI_PORT_A_ADDR_OFFSET,
+	IPU6_CSI_PORT_B_ADDR_OFFSET,
+	IPU6_CSI_PORT_C_ADDR_OFFSET,
+	IPU6_CSI_PORT_D_ADDR_OFFSET,
+	IPU6_CSI_PORT_E_ADDR_OFFSET,
+	IPU6_CSI_PORT_F_ADDR_OFFSET
+};
+
+static u32 ipu6_csi_offsets[] = {
+	IPU6_CSI_PORT_A_ADDR_OFFSET,
+	IPU6_CSI_PORT_B_ADDR_OFFSET,
+	IPU6_CSI_PORT_C_ADDR_OFFSET,
+	IPU6_CSI_PORT_D_ADDR_OFFSET
+};
+
+static struct ipu6_isys_internal_pdata isys_ipdata = {
+	.hw_variant = {
+		.offset = IPU6_UNIFIED_OFFSET,
+		.nr_mmus = 3,
+		.mmu_hw = {
+			{
+				.offset = IPU6_ISYS_IOMMU0_OFFSET,
+				.info_bits = IPU6_INFO_REQUEST_DESTINATION_IOSF,
+				.nr_l1streams = 16,
+				.l1_block_sz = {
+					3, 8, 2, 2, 2, 2, 2, 2, 1, 1,
+					1, 1, 1, 1, 1, 1
+				},
+				.nr_l2streams = 16,
+				.l2_block_sz = {
+					2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+					2, 2, 2, 2, 2, 2
+				},
+				.insert_read_before_invalidate = false,
+				.l1_stream_id_reg_offset =
+				IPU6_MMU_L1_STREAM_ID_REG_OFFSET,
+				.l2_stream_id_reg_offset =
+				IPU6_MMU_L2_STREAM_ID_REG_OFFSET,
+			},
+			{
+				.offset = IPU6_ISYS_IOMMU1_OFFSET,
+				.info_bits = 0,
+				.nr_l1streams = 16,
+				.l1_block_sz = {
+					2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+					2, 2, 2, 1, 1, 4
+				},
+				.nr_l2streams = 16,
+				.l2_block_sz = {
+					2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+					2, 2, 2, 2, 2, 2
+				},
+				.insert_read_before_invalidate = false,
+				.l1_stream_id_reg_offset =
+				IPU6_MMU_L1_STREAM_ID_REG_OFFSET,
+				.l2_stream_id_reg_offset =
+				IPU6_MMU_L2_STREAM_ID_REG_OFFSET,
+			},
+			{
+				.offset = IPU6_ISYS_IOMMUI_OFFSET,
+				.info_bits = 0,
+				.nr_l1streams = 0,
+				.nr_l2streams = 0,
+				.insert_read_before_invalidate = false,
+			},
+		},
+		.cdc_fifos = 3,
+		.cdc_fifo_threshold = {6, 8, 2},
+		.dmem_offset = IPU6_ISYS_DMEM_OFFSET,
+		.spc_offset = IPU6_ISYS_SPC_OFFSET,
+	},
+	.isys_dma_overshoot = IPU6_ISYS_OVERALLOC_MIN,
+};
+
+static struct ipu6_psys_internal_pdata psys_ipdata = {
+	.hw_variant = {
+		.offset = IPU6_UNIFIED_OFFSET,
+		.nr_mmus = 4,
+		.mmu_hw = {
+			{
+				.offset = IPU6_PSYS_IOMMU0_OFFSET,
+				.info_bits =
+				IPU6_INFO_REQUEST_DESTINATION_IOSF,
+				.nr_l1streams = 16,
+				.l1_block_sz = {
+					2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+					2, 2, 2, 2, 2, 2
+				},
+				.nr_l2streams = 16,
+				.l2_block_sz = {
+					2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+					2, 2, 2, 2, 2, 2
+				},
+				.insert_read_before_invalidate = false,
+				.l1_stream_id_reg_offset =
+				IPU6_MMU_L1_STREAM_ID_REG_OFFSET,
+				.l2_stream_id_reg_offset =
+				IPU6_MMU_L2_STREAM_ID_REG_OFFSET,
+			},
+			{
+				.offset = IPU6_PSYS_IOMMU1_OFFSET,
+				.info_bits = 0,
+				.nr_l1streams = 32,
+				.l1_block_sz = {
+					1, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+					2, 2, 2, 2, 2, 10,
+					5, 4, 14, 6, 4, 14, 6, 4, 8,
+					4, 2, 1, 1, 1, 1, 14
+				},
+				.nr_l2streams = 32,
+				.l2_block_sz = {
+					2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+					2, 2, 2, 2, 2, 2,
+					2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+					2, 2, 2, 2, 2, 2
+				},
+				.insert_read_before_invalidate = false,
+				.l1_stream_id_reg_offset =
+				IPU6_MMU_L1_STREAM_ID_REG_OFFSET,
+				.l2_stream_id_reg_offset =
+				IPU6_PSYS_MMU1W_L2_STREAM_ID_REG_OFFSET,
+			},
+			{
+				.offset = IPU6_PSYS_IOMMU1R_OFFSET,
+				.info_bits = 0,
+				.nr_l1streams = 16,
+				.l1_block_sz = {
+					1, 4, 4, 4, 4, 16, 8, 4, 32,
+					16, 16, 2, 2, 2, 1, 12
+				},
+				.nr_l2streams = 16,
+				.l2_block_sz = {
+					2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+					2, 2, 2, 2, 2, 2
+				},
+				.insert_read_before_invalidate = false,
+				.l1_stream_id_reg_offset =
+				IPU6_MMU_L1_STREAM_ID_REG_OFFSET,
+				.l2_stream_id_reg_offset =
+				IPU6_MMU_L2_STREAM_ID_REG_OFFSET,
+			},
+			{
+				.offset = IPU6_PSYS_IOMMUI_OFFSET,
+				.info_bits = 0,
+				.nr_l1streams = 0,
+				.nr_l2streams = 0,
+				.insert_read_before_invalidate = false,
+			},
+		},
+		.dmem_offset = IPU6_PSYS_DMEM_OFFSET,
+	},
+};
+
+static const struct ipu6_buttress_ctrl isys_buttress_ctrl = {
+	.ratio = IPU6_IS_FREQ_CTL_DEFAULT_RATIO,
+	.qos_floor = IPU6_IS_FREQ_CTL_DEFAULT_QOS_FLOOR_RATIO,
+	.freq_ctl = IPU6_BUTTRESS_REG_IS_FREQ_CTL,
+	.pwr_sts_shift = IPU6_BUTTRESS_PWR_STATE_IS_PWR_SHIFT,
+	.pwr_sts_mask = IPU6_BUTTRESS_PWR_STATE_IS_PWR_MASK,
+	.pwr_sts_on = IPU6_BUTTRESS_PWR_STATE_UP_DONE,
+	.pwr_sts_off = IPU6_BUTTRESS_PWR_STATE_DN_DONE,
+};
+
+static const struct ipu6_buttress_ctrl psys_buttress_ctrl = {
+	.ratio = IPU6_PS_FREQ_CTL_DEFAULT_RATIO,
+	.qos_floor = IPU6_PS_FREQ_CTL_DEFAULT_QOS_FLOOR_RATIO,
+	.freq_ctl = IPU6_BUTTRESS_REG_PS_FREQ_CTL,
+	.pwr_sts_shift = IPU6_BUTTRESS_PWR_STATE_PS_PWR_SHIFT,
+	.pwr_sts_mask = IPU6_BUTTRESS_PWR_STATE_PS_PWR_MASK,
+	.pwr_sts_on = IPU6_BUTTRESS_PWR_STATE_UP_DONE,
+	.pwr_sts_off = IPU6_BUTTRESS_PWR_STATE_DN_DONE,
+};
+
+static void
+ipu6_pkg_dir_configure_spc(struct ipu6_device *isp,
+			   const struct ipu6_hw_variants *hw_variant,
+			   int pkg_dir_idx, void __iomem *base,
+			   u64 *pkg_dir, dma_addr_t pkg_dir_vied_address)
+{
+	struct ipu6_cell_program *prog;
+	void __iomem *spc_base;
+	u32 server_fw_addr;
+	dma_addr_t dma_addr;
+	u32 pg_offset;
+
+	server_fw_addr = lower_32_bits(*(pkg_dir + (pkg_dir_idx + 1) * 2));
+	if (pkg_dir_idx == IPU6_CPD_PKG_DIR_ISYS_SERVER_IDX)
+		dma_addr = sg_dma_address(isp->isys->fw_sgt.sgl);
+	else
+		dma_addr = sg_dma_address(isp->psys->fw_sgt.sgl);
+
+	pg_offset = server_fw_addr - dma_addr;
+	prog = (struct ipu6_cell_program *)((u64)isp->cpd_fw->data + pg_offset);
+	spc_base = base + prog->regs_addr;
+	if (spc_base != (base + hw_variant->spc_offset))
+		dev_warn(&isp->pdev->dev,
+			 "SPC reg addr %p not matching value from CPD %p\n",
+			 base + hw_variant->spc_offset, spc_base);
+	writel(server_fw_addr + prog->blob_offset +
+	       prog->icache_source, spc_base + IPU6_PSYS_REG_SPC_ICACHE_BASE);
+	writel(IPU6_INFO_REQUEST_DESTINATION_IOSF,
+	       spc_base + IPU6_REG_PSYS_INFO_SEG_0_CONFIG_ICACHE_MASTER);
+	writel(prog->start[1], spc_base + IPU6_PSYS_REG_SPC_START_PC);
+	writel(pkg_dir_vied_address, base + hw_variant->dmem_offset);
+}
+
+void ipu6_configure_spc(struct ipu6_device *isp,
+			const struct ipu6_hw_variants *hw_variant,
+			int pkg_dir_idx, void __iomem *base, u64 *pkg_dir,
+			dma_addr_t pkg_dir_dma_addr)
+{
+	void __iomem *dmem_base = base + hw_variant->dmem_offset;
+	void __iomem *spc_regs_base = base + hw_variant->spc_offset;
+	u32 val;
+
+	val = readl(spc_regs_base + IPU6_PSYS_REG_SPC_STATUS_CTRL);
+	val |= IPU6_PSYS_SPC_STATUS_CTRL_ICACHE_INVALIDATE;
+	writel(val, spc_regs_base + IPU6_PSYS_REG_SPC_STATUS_CTRL);
+
+	if (isp->secure_mode)
+		writel(IPU6_PKG_DIR_IMR_OFFSET, dmem_base);
+	else
+		ipu6_pkg_dir_configure_spc(isp, hw_variant, pkg_dir_idx, base,
+					   pkg_dir, pkg_dir_dma_addr);
+}
+EXPORT_SYMBOL_NS_GPL(ipu6_configure_spc, INTEL_IPU6);
+
+static void ipu6_internal_pdata_init(struct ipu6_device *isp)
+{
+	u8 hw_ver = isp->hw_ver;
+
+	isys_ipdata.num_parallel_streams = IPU6_ISYS_NUM_STREAMS;
+	isys_ipdata.sram_gran_shift = IPU6_SRAM_GRANULARITY_SHIFT;
+	isys_ipdata.sram_gran_size = IPU6_SRAM_GRANULARITY_SIZE;
+	isys_ipdata.max_sram_size = IPU6_MAX_SRAM_SIZE;
+	isys_ipdata.sensor_type_start = IPU6_FW_ISYS_SENSOR_TYPE_START;
+	isys_ipdata.sensor_type_end = IPU6_FW_ISYS_SENSOR_TYPE_END;
+	isys_ipdata.max_streams = IPU6_ISYS_NUM_STREAMS;
+	isys_ipdata.max_send_queues = IPU6_N_MAX_SEND_QUEUES;
+	isys_ipdata.max_sram_blocks = IPU6_NOF_SRAM_BLOCKS_MAX;
+	isys_ipdata.max_devq_size = IPU6_DEV_SEND_QUEUE_SIZE;
+	isys_ipdata.csi2.nports = ARRAY_SIZE(ipu6_csi_offsets);
+	isys_ipdata.csi2.offsets = ipu6_csi_offsets;
+	isys_ipdata.csi2.irq_mask = IPU6_CSI_RX_ERROR_IRQ_MASK;
+	isys_ipdata.csi2.ctrl0_irq_edge = IPU6_REG_ISYS_CSI_TOP_CTRL0_IRQ_EDGE;
+	isys_ipdata.csi2.ctrl0_irq_clear =
+		IPU6_REG_ISYS_CSI_TOP_CTRL0_IRQ_CLEAR;
+	isys_ipdata.csi2.ctrl0_irq_mask = IPU6_REG_ISYS_CSI_TOP_CTRL0_IRQ_MASK;
+	isys_ipdata.csi2.ctrl0_irq_enable =
+		IPU6_REG_ISYS_CSI_TOP_CTRL0_IRQ_ENABLE;
+	isys_ipdata.csi2.ctrl0_irq_status =
+		IPU6_REG_ISYS_CSI_TOP_CTRL0_IRQ_STATUS;
+	isys_ipdata.csi2.ctrl0_irq_lnp =
+		IPU6_REG_ISYS_CSI_TOP_CTRL0_IRQ_LEVEL_NOT_PULSE;
+	isys_ipdata.enhanced_iwake = is_ipu6ep_mtl(hw_ver) || is_ipu6ep(hw_ver);
+	psys_ipdata.hw_variant.spc_offset = IPU6_PSYS_SPC_OFFSET;
+	isys_ipdata.csi2.fw_access_port_ofs = CSI_REG_HUB_FW_ACCESS_PORT_OFS;
+
+	if (is_ipu6ep(hw_ver)) {
+		isys_ipdata.ltr = IPU6EP_LTR_VALUE;
+		isys_ipdata.memopen_threshold = IPU6EP_MIN_MEMOPEN_TH;
+	}
+
+	if (is_ipu6_tgl(hw_ver)) {
+		isys_ipdata.csi2.nports = ARRAY_SIZE(ipu6_tgl_csi_offsets);
+		isys_ipdata.csi2.offsets = ipu6_tgl_csi_offsets;
+	}
+
+	if (is_ipu6ep_mtl(hw_ver)) {
+		isys_ipdata.csi2.nports = ARRAY_SIZE(ipu6ep_mtl_csi_offsets);
+		isys_ipdata.csi2.offsets = ipu6ep_mtl_csi_offsets;
+
+		isys_ipdata.csi2.ctrl0_irq_edge =
+			IPU6V6_REG_ISYS_CSI_TOP_CTRL0_IRQ_EDGE;
+		isys_ipdata.csi2.ctrl0_irq_clear =
+			IPU6V6_REG_ISYS_CSI_TOP_CTRL0_IRQ_CLEAR;
+		isys_ipdata.csi2.ctrl0_irq_mask =
+			IPU6V6_REG_ISYS_CSI_TOP_CTRL0_IRQ_MASK;
+		isys_ipdata.csi2.ctrl0_irq_enable =
+			IPU6V6_REG_ISYS_CSI_TOP_CTRL0_IRQ_ENABLE;
+		isys_ipdata.csi2.ctrl0_irq_lnp =
+			IPU6V6_REG_ISYS_CSI_TOP_CTRL0_IRQ_LEVEL_NOT_PULSE;
+		isys_ipdata.csi2.ctrl0_irq_status =
+			IPU6V6_REG_ISYS_CSI_TOP_CTRL0_IRQ_STATUS;
+		isys_ipdata.csi2.fw_access_port_ofs =
+			CSI_REG_HUB_FW_ACCESS_PORT_V6OFS;
+		isys_ipdata.ltr = IPU6EP_MTL_LTR_VALUE;
+		isys_ipdata.memopen_threshold = IPU6EP_MTL_MIN_MEMOPEN_TH;
+	}
+
+	if (is_ipu6se(hw_ver)) {
+		isys_ipdata.csi2.nports = ARRAY_SIZE(ipu6se_csi_offsets);
+		isys_ipdata.csi2.irq_mask = IPU6SE_CSI_RX_ERROR_IRQ_MASK;
+		isys_ipdata.csi2.offsets = ipu6se_csi_offsets;
+		isys_ipdata.num_parallel_streams = IPU6SE_ISYS_NUM_STREAMS;
+		isys_ipdata.sram_gran_shift = IPU6SE_SRAM_GRANULARITY_SHIFT;
+		isys_ipdata.sram_gran_size = IPU6SE_SRAM_GRANULARITY_SIZE;
+		isys_ipdata.max_sram_size = IPU6SE_MAX_SRAM_SIZE;
+		isys_ipdata.sensor_type_start =
+			IPU6SE_FW_ISYS_SENSOR_TYPE_START;
+		isys_ipdata.sensor_type_end = IPU6SE_FW_ISYS_SENSOR_TYPE_END;
+		isys_ipdata.max_streams = IPU6SE_ISYS_NUM_STREAMS;
+		isys_ipdata.max_send_queues = IPU6SE_N_MAX_SEND_QUEUES;
+		isys_ipdata.max_sram_blocks = IPU6SE_NOF_SRAM_BLOCKS_MAX;
+		isys_ipdata.max_devq_size = IPU6SE_DEV_SEND_QUEUE_SIZE;
+		psys_ipdata.hw_variant.spc_offset = IPU6SE_PSYS_SPC_OFFSET;
+	}
+}
+
+static int ipu6_isys_check_fwnode_graph(struct fwnode_handle *fwnode)
+{
+	struct fwnode_handle *endpoint;
+
+	if (IS_ERR_OR_NULL(fwnode))
+		return -EINVAL;
+
+	endpoint = fwnode_graph_get_next_endpoint(fwnode, NULL);
+	if (endpoint) {
+		fwnode_handle_put(endpoint);
+		return 0;
+	}
+
+	return ipu6_isys_check_fwnode_graph(fwnode->secondary);
+}
+
+static struct ipu6_bus_device *
+ipu6_isys_init(struct pci_dev *pdev, struct device *parent,
+	       struct ipu6_buttress_ctrl *ctrl, void __iomem *base,
+	       const struct ipu6_isys_internal_pdata *ipdata)
+{
+	struct fwnode_handle *fwnode = dev_fwnode(&pdev->dev);
+	struct ipu6_bus_device *isys_adev;
+	struct ipu6_isys_pdata *pdata;
+	int ret;
+
+	/* check fwnode at first, fallback into bridge if no fwnode graph */
+	ret = ipu6_isys_check_fwnode_graph(fwnode);
+	if (ret) {
+		if (fwnode && !IS_ERR_OR_NULL(fwnode->secondary)) {
+			dev_err(&pdev->dev,
+				"fwnode graph has no endpoints connection\n");
+			return ERR_PTR(-EINVAL);
+		}
+
+		ret = ipu_bridge_init(&pdev->dev, ipu_bridge_parse_ssdb);
+		if (ret) {
+			if (ret != -EPROBE_DEFER)
+				dev_err_probe(&pdev->dev, ret,
+					      "IPU6 bridge init failed\n");
+			return ERR_PTR(ret);
+		}
+	}
+
+	pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
+	if (!pdata)
+		return ERR_PTR(-ENOMEM);
+
+	pdata->base = base;
+	pdata->ipdata = ipdata;
+
+	isys_adev = ipu6_bus_initialize_device(pdev, parent, pdata, ctrl,
+					       IPU6_ISYS_NAME);
+	if (IS_ERR(isys_adev)) {
+		dev_err_probe(&pdev->dev, PTR_ERR(isys_adev),
+			      "ipu6_bus_initialize_device isys failed\n");
+		kfree(pdata);
+		return ERR_CAST(isys_adev);
+	}
+
+	isys_adev->mmu = ipu6_mmu_init(&pdev->dev, base, ISYS_MMID,
+				       &ipdata->hw_variant);
+	if (IS_ERR(isys_adev->mmu)) {
+		dev_err_probe(&pdev->dev, PTR_ERR(isys_adev),
+			      "ipu6_mmu_init(isys_adev->mmu) failed\n");
+		put_device(&isys_adev->auxdev.dev);
+		kfree(pdata);
+		return ERR_CAST(isys_adev->mmu);
+	}
+
+	isys_adev->mmu->dev = &isys_adev->auxdev.dev;
+
+	ret = ipu6_bus_add_device(isys_adev);
+	if (ret) {
+		kfree(pdata);
+		return ERR_PTR(ret);
+	}
+
+	return isys_adev;
+}
+
+static struct ipu6_bus_device *
+ipu6_psys_init(struct pci_dev *pdev, struct device *parent,
+	       struct ipu6_buttress_ctrl *ctrl, void __iomem *base,
+	       const struct ipu6_psys_internal_pdata *ipdata)
+{
+	struct ipu6_bus_device *psys_adev;
+	struct ipu6_psys_pdata *pdata;
+	int ret;
+
+	pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
+	if (!pdata)
+		return ERR_PTR(-ENOMEM);
+
+	pdata->base = base;
+	pdata->ipdata = ipdata;
+
+	psys_adev = ipu6_bus_initialize_device(pdev, parent, pdata, ctrl,
+					       IPU6_PSYS_NAME);
+	if (IS_ERR(psys_adev)) {
+		dev_err_probe(&pdev->dev, PTR_ERR(psys_adev),
+			      "ipu6_bus_initialize_device psys failed\n");
+		kfree(pdata);
+		return ERR_CAST(psys_adev);
+	}
+
+	psys_adev->mmu = ipu6_mmu_init(&pdev->dev, base, PSYS_MMID,
+				       &ipdata->hw_variant);
+	if (IS_ERR(psys_adev->mmu)) {
+		dev_err_probe(&pdev->dev, PTR_ERR(psys_adev),
+			      "ipu6_mmu_init(psys_adev->mmu) failed\n");
+		put_device(&psys_adev->auxdev.dev);
+		kfree(pdata);
+		return ERR_CAST(psys_adev->mmu);
+	}
+
+	psys_adev->mmu->dev = &psys_adev->auxdev.dev;
+
+	ret = ipu6_bus_add_device(psys_adev);
+	if (ret) {
+		kfree(pdata);
+		return ERR_PTR(ret);
+	}
+
+	return psys_adev;
+}
+
+static int ipu6_pci_config_setup(struct pci_dev *dev, u8 hw_ver)
+{
+	int ret;
+
+	/* disable IPU6 PCI ATS on mtl ES2 */
+	if (is_ipu6ep_mtl(hw_ver) && boot_cpu_data.x86_stepping == 0x2 &&
+	    pci_ats_supported(dev))
+		pci_disable_ats(dev);
+
+	/* No PCI msi capability for IPU6EP */
+	if (is_ipu6ep(hw_ver) || is_ipu6ep_mtl(hw_ver)) {
+		/* likely do nothing as msi not enabled by default */
+		pci_disable_msi(dev);
+		return 0;
+	}
+
+	ret = pci_alloc_irq_vectors(dev, 1, 1, PCI_IRQ_MSI);
+	if (ret)
+		dev_err_probe(&dev->dev, ret, "Request msi failed");
+
+	return ret;
+}
+
+static void ipu6_configure_vc_mechanism(struct ipu6_device *isp)
+{
+	u32 val = readl(isp->base + BUTTRESS_REG_BTRS_CTRL);
+
+	if (IPU6_BTRS_ARB_STALL_MODE_VC0 == IPU6_BTRS_ARB_MODE_TYPE_STALL)
+		val |= BUTTRESS_REG_BTRS_CTRL_STALL_MODE_VC0;
+	else
+		val &= ~BUTTRESS_REG_BTRS_CTRL_STALL_MODE_VC0;
+
+	if (IPU6_BTRS_ARB_STALL_MODE_VC1 == IPU6_BTRS_ARB_MODE_TYPE_STALL)
+		val |= BUTTRESS_REG_BTRS_CTRL_STALL_MODE_VC1;
+	else
+		val &= ~BUTTRESS_REG_BTRS_CTRL_STALL_MODE_VC1;
+
+	writel(val, isp->base + BUTTRESS_REG_BTRS_CTRL);
+}
+
+static int request_cpd_fw(const struct firmware **firmware_p, const char *name,
+			  struct device *device)
+{
+	const struct firmware *fw;
+	struct firmware *dst;
+	int ret = 0;
+
+	ret = request_firmware(&fw, name, device);
+	if (ret)
+		return ret;
+
+	if (is_vmalloc_addr(fw->data)) {
+		*firmware_p = fw;
+		return 0;
+	}
+
+	dst = kzalloc(sizeof(*dst), GFP_KERNEL);
+	if (!dst) {
+		ret = -ENOMEM;
+		goto release_firmware;
+	}
+
+	dst->size = fw->size;
+	dst->data = vmalloc(fw->size);
+	if (!dst->data) {
+		kfree(dst);
+		ret = -ENOMEM;
+		goto release_firmware;
+	}
+
+	memcpy((void *)dst->data, fw->data, fw->size);
+	*firmware_p = dst;
+
+release_firmware:
+	release_firmware(fw);
+
+	return ret;
+}
+
+static int ipu6_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
+{
+	struct ipu6_buttress_ctrl *isys_ctrl = NULL, *psys_ctrl = NULL;
+	void __iomem *isys_base = NULL;
+	void __iomem *psys_base = NULL;
+	struct ipu6_device *isp;
+	phys_addr_t phys;
+	u32 val, version, sku_id;
+	int ret;
+
+	isp = devm_kzalloc(&pdev->dev, sizeof(*isp), GFP_KERNEL);
+	if (!isp)
+		return -ENOMEM;
+
+	isp->pdev = pdev;
+	INIT_LIST_HEAD(&isp->devices);
+
+	ret = pcim_enable_device(pdev);
+	if (ret)
+		return dev_err_probe(&pdev->dev, ret,
+				     "Enable PCI device failed\n");
+
+	phys = pci_resource_start(pdev, IPU6_PCI_BAR);
+	dev_dbg(&pdev->dev, "IPU6 PCI bar[%u] = %pa\n", IPU6_PCI_BAR, &phys);
+
+	ret = pcim_iomap_regions(pdev, 1 << IPU6_PCI_BAR, pci_name(pdev));
+	if (ret)
+		return dev_err_probe(&pdev->dev, ret,
+				     "Failed to I/O mem remappinp\n");
+
+	isp->base = pcim_iomap_table(pdev)[IPU6_PCI_BAR];
+	pci_set_drvdata(pdev, isp);
+	pci_set_master(pdev);
+
+	isp->cpd_metadata_cmpnt_size = sizeof(struct ipu6_cpd_metadata_cmpnt);
+	switch (id->device) {
+	case PCI_DEVICE_ID_INTEL_IPU6:
+		isp->hw_ver = IPU6_VER_6;
+		isp->cpd_fw_name = IPU6_FIRMWARE_NAME;
+		break;
+	case PCI_DEVICE_ID_INTEL_IPU6SE:
+		isp->hw_ver = IPU6_VER_6SE;
+		isp->cpd_fw_name = IPU6SE_FIRMWARE_NAME;
+		isp->cpd_metadata_cmpnt_size =
+			sizeof(struct ipu6se_cpd_metadata_cmpnt);
+		break;
+	case PCI_DEVICE_ID_INTEL_IPU6EP_ADLP:
+	case PCI_DEVICE_ID_INTEL_IPU6EP_ADLN:
+	case PCI_DEVICE_ID_INTEL_IPU6EP_RPLP:
+		isp->hw_ver = IPU6_VER_6EP;
+		isp->cpd_fw_name = IPU6EP_FIRMWARE_NAME;
+		break;
+	case PCI_DEVICE_ID_INTEL_IPU6EP_MTL:
+		isp->hw_ver = IPU6_VER_6EP_MTL;
+		isp->cpd_fw_name = IPU6EPMTL_FIRMWARE_NAME;
+		break;
+	default:
+		return dev_err_probe(&pdev->dev, -ENODEV,
+				     "Unsupported IPU6 device %x\n",
+				     id->device);
+	}
+
+	ipu6_internal_pdata_init(isp);
+
+	isys_base = isp->base + isys_ipdata.hw_variant.offset;
+	psys_base = isp->base + psys_ipdata.hw_variant.offset;
+
+	ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(39));
+	if (ret)
+		return dev_err_probe(&pdev->dev, ret,
+				     "Failed to set DMA mask\n");
+
+	dma_set_max_seg_size(&pdev->dev, UINT_MAX);
+
+	ret = ipu6_pci_config_setup(pdev, isp->hw_ver);
+	if (ret)
+		return ret;
+
+	ret = ipu6_buttress_init(isp);
+	if (ret)
+		return ret;
+
+	ret = request_cpd_fw(&isp->cpd_fw, isp->cpd_fw_name, &pdev->dev);
+	if (ret) {
+		dev_err_probe(&isp->pdev->dev, ret,
+			      "Requesting signed firmware %s failed\n",
+			      isp->cpd_fw_name);
+		goto buttress_exit;
+	}
+
+	ret = ipu6_cpd_validate_cpd_file(isp, isp->cpd_fw->data,
+					 isp->cpd_fw->size);
+	if (ret) {
+		dev_err_probe(&isp->pdev->dev, ret,
+			      "Failed to validate cpd\n");
+		goto out_ipu6_bus_del_devices;
+	}
+
+	isys_ctrl = devm_kmemdup(&pdev->dev, &isys_buttress_ctrl,
+				 sizeof(isys_buttress_ctrl), GFP_KERNEL);
+	if (!isys_ctrl) {
+		ret = -ENOMEM;
+		goto out_ipu6_bus_del_devices;
+	}
+
+	isp->isys = ipu6_isys_init(pdev, &pdev->dev, isys_ctrl, isys_base,
+				   &isys_ipdata);
+	if (IS_ERR(isp->isys)) {
+		ret = PTR_ERR(isp->isys);
+		goto out_ipu6_bus_del_devices;
+	}
+
+	psys_ctrl = devm_kmemdup(&pdev->dev, &psys_buttress_ctrl,
+				 sizeof(psys_buttress_ctrl), GFP_KERNEL);
+	if (!psys_ctrl) {
+		ret = -ENOMEM;
+		goto out_ipu6_bus_del_devices;
+	}
+
+	isp->psys = ipu6_psys_init(pdev, &isp->isys->auxdev.dev, psys_ctrl,
+				   psys_base, &psys_ipdata);
+	if (IS_ERR(isp->psys)) {
+		ret = PTR_ERR(isp->psys);
+		goto out_ipu6_bus_del_devices;
+	}
+
+	ret = pm_runtime_resume_and_get(&isp->psys->auxdev.dev);
+	if (ret < 0)
+		goto out_ipu6_bus_del_devices;
+
+	ret = ipu6_mmu_hw_init(isp->psys->mmu);
+	if (ret) {
+		dev_err_probe(&isp->pdev->dev, ret,
+			      "Failed to set MMU hardware\n");
+		goto out_ipu6_bus_del_devices;
+	}
+
+	ret = ipu6_buttress_map_fw_image(isp->psys, isp->cpd_fw,
+					 &isp->psys->fw_sgt);
+	if (ret) {
+		dev_err_probe(&isp->pdev->dev, ret, "failed to map fw image\n");
+		goto out_ipu6_bus_del_devices;
+	}
+
+	ret = ipu6_cpd_create_pkg_dir(isp->psys, isp->cpd_fw->data);
+	if (ret) {
+		dev_err_probe(&isp->pdev->dev, ret,
+			      "failed to create pkg dir\n");
+		goto out_ipu6_bus_del_devices;
+	}
+
+	ret = devm_request_threaded_irq(&pdev->dev, pdev->irq,
+					ipu6_buttress_isr,
+					ipu6_buttress_isr_threaded,
+					IRQF_SHARED, IPU6_NAME, isp);
+	if (ret) {
+		dev_err_probe(&pdev->dev, ret, "Requesting irq failed\n");
+		goto out_ipu6_bus_del_devices;
+	}
+
+	ret = ipu6_buttress_authenticate(isp);
+	if (ret) {
+		dev_err_probe(&isp->pdev->dev, ret,
+			      "FW authentication failed\n");
+		goto out_ipu6_bus_del_devices;
+	}
+
+	ipu6_mmu_hw_cleanup(isp->psys->mmu);
+	pm_runtime_put(&isp->psys->auxdev.dev);
+
+	/* Configure the arbitration mechanisms for VC requests */
+	ipu6_configure_vc_mechanism(isp);
+
+	val = readl(isp->base + BUTTRESS_REG_SKU);
+	sku_id = FIELD_GET(GENMASK(6, 4), val);
+	version = FIELD_GET(GENMASK(3, 0), val);
+	dev_info(&pdev->dev, "IPU%u-v%u[%x] hardware version %d\n",
+		 version, sku_id, pdev->device, isp->hw_ver);
+
+	pm_runtime_put_noidle(&pdev->dev);
+	pm_runtime_allow(&pdev->dev);
+
+	isp->bus_ready_to_probe = true;
+
+	return 0;
+
+out_ipu6_bus_del_devices:
+	if (isp->psys) {
+		ipu6_cpd_free_pkg_dir(isp->psys);
+		ipu6_buttress_unmap_fw_image(isp->psys, &isp->psys->fw_sgt);
+	}
+	if (!IS_ERR_OR_NULL(isp->psys) && !IS_ERR_OR_NULL(isp->psys->mmu))
+		ipu6_mmu_cleanup(isp->psys->mmu);
+	if (!IS_ERR_OR_NULL(isp->isys) && !IS_ERR_OR_NULL(isp->isys->mmu))
+		ipu6_mmu_cleanup(isp->isys->mmu);
+	ipu6_bus_del_devices(pdev);
+	release_firmware(isp->cpd_fw);
+buttress_exit:
+	ipu6_buttress_exit(isp);
+
+	return ret;
+}
+
+static void ipu6_pci_remove(struct pci_dev *pdev)
+{
+	struct ipu6_device *isp = pci_get_drvdata(pdev);
+	struct ipu6_mmu *isys_mmu = isp->isys->mmu;
+	struct ipu6_mmu *psys_mmu = isp->psys->mmu;
+
+	ipu6_cpd_free_pkg_dir(isp->psys);
+
+	ipu6_buttress_unmap_fw_image(isp->psys, &isp->psys->fw_sgt);
+
+	ipu6_bus_del_devices(pdev);
+
+	pm_runtime_forbid(&pdev->dev);
+	pm_runtime_get_noresume(&pdev->dev);
+
+	pci_release_regions(pdev);
+	pci_disable_device(pdev);
+
+	ipu6_buttress_exit(isp);
+
+	release_firmware(isp->cpd_fw);
+
+	ipu6_mmu_cleanup(psys_mmu);
+	ipu6_mmu_cleanup(isys_mmu);
+}
+
+static void ipu6_pci_reset_prepare(struct pci_dev *pdev)
+{
+	struct ipu6_device *isp = pci_get_drvdata(pdev);
+
+	pm_runtime_forbid(&isp->pdev->dev);
+}
+
+static void ipu6_pci_reset_done(struct pci_dev *pdev)
+{
+	struct ipu6_device *isp = pci_get_drvdata(pdev);
+
+	ipu6_buttress_restore(isp);
+	if (isp->secure_mode)
+		ipu6_buttress_reset_authentication(isp);
+
+	isp->need_ipc_reset = true;
+	pm_runtime_allow(&isp->pdev->dev);
+}
+
+/*
+ * PCI base driver code requires driver to provide these to enable
+ * PCI device level PM state transitions (D0<->D3)
+ */
+static int ipu6_suspend(struct device *dev)
+{
+	return 0;
+}
+
+static int ipu6_resume(struct device *dev)
+{
+	struct pci_dev *pdev = to_pci_dev(dev);
+	struct ipu6_device *isp = pci_get_drvdata(pdev);
+	struct ipu6_buttress *b = &isp->buttress;
+	int ret;
+
+	/* Configure the arbitration mechanisms for VC requests */
+	ipu6_configure_vc_mechanism(isp);
+
+	isp->secure_mode = ipu6_buttress_get_secure_mode(isp);
+	dev_info(dev, "IPU6 in %s mode\n",
+		 isp->secure_mode ? "secure" : "non-secure");
+
+	ipu6_buttress_restore(isp);
+
+	ret = ipu6_buttress_ipc_reset(isp, &b->cse);
+	if (ret)
+		dev_err(&isp->pdev->dev, "IPC reset protocol failed!\n");
+
+	ret = pm_runtime_resume_and_get(&isp->psys->auxdev.dev);
+	if (ret < 0) {
+		dev_err(&isp->psys->auxdev.dev, "Failed to get runtime PM\n");
+		return 0;
+	}
+
+	ret = ipu6_buttress_authenticate(isp);
+	if (ret)
+		dev_err(&isp->pdev->dev, "FW authentication failed(%d)\n", ret);
+
+	pm_runtime_put(&isp->psys->auxdev.dev);
+
+	return 0;
+}
+
+static int ipu6_runtime_resume(struct device *dev)
+{
+	struct pci_dev *pdev = to_pci_dev(dev);
+	struct ipu6_device *isp = pci_get_drvdata(pdev);
+	int ret;
+
+	ipu6_configure_vc_mechanism(isp);
+	ipu6_buttress_restore(isp);
+
+	if (isp->need_ipc_reset) {
+		struct ipu6_buttress *b = &isp->buttress;
+
+		isp->need_ipc_reset = false;
+		ret = ipu6_buttress_ipc_reset(isp, &b->cse);
+		if (ret)
+			dev_err(&isp->pdev->dev, "IPC reset protocol failed\n");
+	}
+
+	return 0;
+}
+
+static const struct dev_pm_ops ipu6_pm_ops = {
+	SET_SYSTEM_SLEEP_PM_OPS(&ipu6_suspend, &ipu6_resume)
+	SET_RUNTIME_PM_OPS(&ipu6_suspend, &ipu6_runtime_resume, NULL)
+};
+
+static const struct pci_device_id ipu6_pci_tbl[] = {
+	{ PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_IPU6) },
+	{ PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_IPU6SE) },
+	{ PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_IPU6EP_ADLP) },
+	{ PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_IPU6EP_ADLN) },
+	{ PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_IPU6EP_RPLP) },
+	{ PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_IPU6EP_MTL) },
+	{ }
+};
+MODULE_DEVICE_TABLE(pci, ipu6_pci_tbl);
+
+static const struct pci_error_handlers pci_err_handlers = {
+	.reset_prepare = ipu6_pci_reset_prepare,
+	.reset_done = ipu6_pci_reset_done,
+};
+
+static struct pci_driver ipu6_pci_driver = {
+	.name = IPU6_NAME,
+	.id_table = ipu6_pci_tbl,
+	.probe = ipu6_pci_probe,
+	.remove = ipu6_pci_remove,
+	.driver = {
+		.pm = pm_ptr(&ipu6_pm_ops),
+	},
+	.err_handler = &pci_err_handlers,
+};
+
+module_pci_driver(ipu6_pci_driver);
+
+MODULE_IMPORT_NS(INTEL_IPU_BRIDGE);
+MODULE_AUTHOR("Sakari Ailus <sakari.ailus@linux.intel.com>");
+MODULE_AUTHOR("Tianshu Qiu <tian.shu.qiu@intel.com>");
+MODULE_AUTHOR("Bingbu Cao <bingbu.cao@intel.com>");
+MODULE_AUTHOR("Qingwu Zhang <qingwu.zhang@intel.com>");
+MODULE_AUTHOR("Yunliang Ding <yunliang.ding@intel.com>");
+MODULE_AUTHOR("Hongju Wang <hongju.wang@intel.com>");
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("Intel IPU6 PCI driver");
diff --git a/drivers/media/pci/intel/ipu6/ipu6.h b/drivers/media/pci/intel/ipu6/ipu6.h
new file mode 100644
index 000000000000..d27ca2df4a2e
--- /dev/null
+++ b/drivers/media/pci/intel/ipu6/ipu6.h
@@ -0,0 +1,352 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/* Copyright (C) 2013 - 2023 Intel Corporation */
+
+#ifndef IPU6_H
+#define IPU6_H
+
+#include <linux/firmware.h>
+#include <linux/pci.h>
+
+#include "ipu6-buttress.h"
+
+#define PCI_DEVICE_ID_INTEL_IPU6		0x9a19
+#define PCI_DEVICE_ID_INTEL_IPU6SE		0x4e19
+#define PCI_DEVICE_ID_INTEL_IPU6EP_ADLP		0x465d
+#define PCI_DEVICE_ID_INTEL_IPU6EP_ADLN		0x462e
+#define PCI_DEVICE_ID_INTEL_IPU6EP_RPLP		0xa75d
+#define PCI_DEVICE_ID_INTEL_IPU6EP_MTL		0x7d19
+
+#define IPU6_NAME			"intel-ipu6"
+#define IPU6_MEDIA_DEV_MODEL_NAME	"ipu6"
+
+#define IPU6SE_FIRMWARE_NAME		"intel/ipu6se_fw.bin"
+#define IPU6EP_FIRMWARE_NAME		"intel/ipu6ep_fw.bin"
+#define IPU6_FIRMWARE_NAME		"intel/ipu6_fw.bin"
+#define IPU6EPMTL_FIRMWARE_NAME		"intel/ipu6epmtl_fw.bin"
+
+enum ipu6_version {
+	IPU6_VER_INVALID = 0,
+	IPU6_VER_6 = 1,
+	IPU6_VER_6SE = 3,
+	IPU6_VER_6EP = 5,
+	IPU6_VER_6EP_MTL = 6,
+};
+
+/*
+ * IPU6 - TGL
+ * IPU6SE - JSL
+ * IPU6EP - ADL/RPL
+ * IPU6EP_MTL - MTL
+ */
+static inline bool is_ipu6se(u8 hw_ver)
+{
+	return hw_ver == IPU6_VER_6SE;
+}
+
+static inline bool is_ipu6ep(u8 hw_ver)
+{
+	return hw_ver == IPU6_VER_6EP;
+}
+
+static inline bool is_ipu6ep_mtl(u8 hw_ver)
+{
+	return hw_ver == IPU6_VER_6EP_MTL;
+}
+
+static inline bool is_ipu6_tgl(u8 hw_ver)
+{
+	return hw_ver == IPU6_VER_6;
+}
+
+/*
+ * ISYS DMA can overshoot. For higher resolutions over allocation is one line
+ * but it must be at minimum 1024 bytes. Value could be different in
+ * different versions / generations thus provide it via platform data.
+ */
+#define IPU6_ISYS_OVERALLOC_MIN		1024
+
+/* Physical pages in GDA is 128, page size is 2K for IPU6, 1K for others */
+#define IPU6_DEVICE_GDA_NR_PAGES		128
+
+/* Virtualization factor to calculate the available virtual pages */
+#define IPU6_DEVICE_GDA_VIRT_FACTOR	32
+
+#define NR_OF_MMU_RESOURCES			2
+
+struct ipu6_device {
+	struct pci_dev *pdev;
+	struct list_head devices;
+	struct ipu6_bus_device *isys;
+	struct ipu6_bus_device *psys;
+	struct ipu6_buttress buttress;
+
+	const struct firmware *cpd_fw;
+	const char *cpd_fw_name;
+	u32 cpd_metadata_cmpnt_size;
+
+	void __iomem *base;
+	struct ipu6_trace *trace;
+	bool need_ipc_reset;
+	bool secure_mode;
+	u8 hw_ver;
+	bool bus_ready_to_probe;
+};
+
+#define IPU6_ISYS_NAME "isys"
+#define IPU6_PSYS_NAME "psys"
+
+#define IPU6_MMU_MAX_DEVICES		4
+#define IPU6_MMU_ADDR_BITS		32
+/* The firmware is accessible within the first 2 GiB only in non-secure mode. */
+#define IPU6_MMU_ADDR_BITS_NON_SECURE	31
+
+#define IPU6_MMU_MAX_TLB_L1_STREAMS	32
+#define IPU6_MMU_MAX_TLB_L2_STREAMS	32
+#define IPU6_MAX_LI_BLOCK_ADDR		128
+#define IPU6_MAX_L2_BLOCK_ADDR		64
+
+#define IPU6_ISYS_MAX_CSI2_LEGACY_PORTS	4
+#define IPU6_ISYS_MAX_CSI2_COMBO_PORTS	2
+
+#define IPU6_MAX_FRAME_COUNTER	0xff
+
+#define IPU6SE_ISYS_NUM_STREAMS          IPU6SE_NONSECURE_STREAM_ID_MAX
+#define IPU6_ISYS_NUM_STREAMS            IPU6_NONSECURE_STREAM_ID_MAX
+
+/*
+ * To maximize the IOSF utlization, IPU6 need to send requests in bursts.
+ * At the DMA interface with the buttress, there are CDC FIFOs with burst
+ * collection capability. CDC FIFO burst collectors have a configurable
+ * threshold and is configured based on the outcome of performance measurements.
+ *
+ * isys has 3 ports with IOSF interface for VC0, VC1 and VC2
+ * psys has 4 ports with IOSF interface for VC0, VC1w, VC1r and VC2
+ *
+ * Threshold values are pre-defined and are arrived at after performance
+ * evaluations on a type of IPU6
+ */
+#define IPU6_MAX_VC_IOSF_PORTS		4
+
+/*
+ * IPU6 must configure correct arbitration mechanism related to the IOSF VC
+ * requests. There are two options per VC0 and VC1 - > 0 means rearbitrate on
+ * stall and 1 means stall until the request is completed.
+ */
+#define IPU6_BTRS_ARB_MODE_TYPE_REARB	0
+#define IPU6_BTRS_ARB_MODE_TYPE_STALL	1
+
+/* Currently chosen arbitration mechanism for VC0 */
+#define IPU6_BTRS_ARB_STALL_MODE_VC0	\
+			IPU6_BTRS_ARB_MODE_TYPE_REARB
+
+/* Currently chosen arbitration mechanism for VC1 */
+#define IPU6_BTRS_ARB_STALL_MODE_VC1	\
+			IPU6_BTRS_ARB_MODE_TYPE_REARB
+
+/*
+ * MMU Invalidation HW bug workaround by ZLW mechanism
+ *
+ * Old IPU6 MMUV2 has a bug in the invalidation mechanism which might result in
+ * wrong translation or replication of the translation. This will cause data
+ * corruption. So we cannot directly use the MMU V2 invalidation registers
+ * to invalidate the MMU. Instead, whenever an invalidate is called, we need to
+ * clear the TLB by evicting all the valid translations by filling it with trash
+ * buffer (which is guaranteed not to be used by any other processes). ZLW is
+ * used to fill the L1 and L2 caches with the trash buffer translations. ZLW
+ * or Zero length write, is pre-fetch mechanism to pre-fetch the pages in
+ * advance to the L1 and L2 caches without triggering any memory operations.
+ *
+ * In MMU V2, L1 -> 16 streams and 64 blocks, maximum 16 blocks per stream
+ * One L1 block has 16 entries, hence points to 16 * 4K pages
+ * L2 -> 16 streams and 32 blocks. 2 blocks per streams
+ * One L2 block maps to 1024 L1 entries, hence points to 4MB address range
+ * 2 blocks per L2 stream means, 1 stream points to 8MB range
+ *
+ * As we need to clear the caches and 8MB being the biggest cache size, we need
+ * to have trash buffer which points to 8MB address range. As these trash
+ * buffers are not used for any memory transactions, we need only the least
+ * amount of physical memory. So we reserve 8MB IOVA address range but only
+ * one page is reserved from physical memory. Each of this 8MB IOVA address
+ * range is then mapped to the same physical memory page.
+ */
+/* One L2 entry maps 1024 L1 entries and one L1 entry per page */
+#define IPU6_MMUV2_L2_RANGE		(1024 * PAGE_SIZE)
+/* Max L2 blocks per stream */
+#define IPU6_MMUV2_MAX_L2_BLOCKS	2
+/* Max L1 blocks per stream */
+#define IPU6_MMUV2_MAX_L1_BLOCKS	16
+#define IPU6_MMUV2_TRASH_RANGE	(IPU6_MMUV2_L2_RANGE * IPU6_MMUV2_MAX_L2_BLOCKS)
+/* Entries per L1 block */
+#define MMUV2_ENTRIES_PER_L1_BLOCK	16
+#define MMUV2_TRASH_L1_BLOCK_OFFSET	(MMUV2_ENTRIES_PER_L1_BLOCK * PAGE_SIZE)
+#define MMUV2_TRASH_L2_BLOCK_OFFSET	IPU6_MMUV2_L2_RANGE
+
+/*
+ * In some of the IPU6 MMUs, there is provision to configure L1 and L2 page
+ * table caches. Both these L1 and L2 caches are divided into multiple sections
+ * called streams. There is maximum 16 streams for both caches. Each of these
+ * sections are subdivided into multiple blocks. When nr_l1streams = 0 and
+ * nr_l2streams = 0, means the MMU is of type MMU_V1 and do not support
+ * L1/L2 page table caches.
+ *
+ * L1 stream per block sizes are configurable and varies per usecase.
+ * L2 has constant block sizes - 2 blocks per stream.
+ *
+ * MMU1 support pre-fetching of the pages to have less cache lookup misses. To
+ * enable the pre-fetching, MMU1 AT (Address Translator) device registers
+ * need to be configured.
+ *
+ * There are four types of memory accesses which requires ZLW configuration.
+ * ZLW(Zero Length Write) is a mechanism to enable VT-d pre-fetching on IOMMU.
+ *
+ * 1. Sequential Access or 1D mode
+ *	Set ZLW_EN -> 1
+ *	set ZLW_PAGE_CROSS_1D -> 1
+ *	Set ZLW_N to "N" pages so that ZLW will be inserte N pages ahead where
+ *		  N is pre-defined and hardcoded in the platform data
+ *	Set ZLW_2D -> 0
+ *
+ * 2. ZLW 2D mode
+ *	Set ZLW_EN -> 1
+ *	set ZLW_PAGE_CROSS_1D -> 1,
+ *	Set ZLW_N -> 0
+ *	Set ZLW_2D -> 1
+ *
+ * 3. ZLW Enable (no 1D or 2D mode)
+ *	Set ZLW_EN -> 1
+ *	set ZLW_PAGE_CROSS_1D -> 0,
+ *	Set ZLW_N -> 0
+ *	Set ZLW_2D -> 0
+ *
+ * 4. ZLW disable
+ *	Set ZLW_EN -> 0
+ *	set ZLW_PAGE_CROSS_1D -> 0,
+ *	Set ZLW_N -> 0
+ *	Set ZLW_2D -> 0
+ *
+ * To configure the ZLW for the above memory access, four registers are
+ * available. Hence to track these four settings, we have the following entries
+ * in the struct ipu6_mmu_hw. Each of these entries are per stream and
+ * available only for the L1 streams.
+ *
+ * a. l1_zlw_en -> To track zlw enabled per stream (ZLW_EN)
+ * b. l1_zlw_1d_mode -> Track 1D mode per stream. ZLW inserted at page boundary
+ * c. l1_ins_zlw_ahead_pages -> to track how advance the ZLW need to be inserted
+ *			Insert ZLW request N pages ahead address.
+ * d. l1_zlw_2d_mode -> To track 2D mode per stream (ZLW_2D)
+ *
+ *
+ * Currently L1/L2 streams, blocks, AT ZLW configurations etc. are pre-defined
+ * as per the usecase specific calculations. Any change to this pre-defined
+ * table has to happen in sync with IPU6 FW.
+ */
+struct ipu6_mmu_hw {
+	union {
+		unsigned long offset;
+		void __iomem *base;
+	};
+	u32 info_bits;
+	u8 nr_l1streams;
+	/*
+	 * L1 has variable blocks per stream - total of 64 blocks and maximum of
+	 * 16 blocks per stream. Configurable by using the block start address
+	 * per stream. Block start address is calculated from the block size
+	 */
+	u8 l1_block_sz[IPU6_MMU_MAX_TLB_L1_STREAMS];
+	/* Is ZLW is enabled in each stream */
+	bool l1_zlw_en[IPU6_MMU_MAX_TLB_L1_STREAMS];
+	bool l1_zlw_1d_mode[IPU6_MMU_MAX_TLB_L1_STREAMS];
+	u8 l1_ins_zlw_ahead_pages[IPU6_MMU_MAX_TLB_L1_STREAMS];
+	bool l1_zlw_2d_mode[IPU6_MMU_MAX_TLB_L1_STREAMS];
+
+	u32 l1_stream_id_reg_offset;
+	u32 l2_stream_id_reg_offset;
+
+	u8 nr_l2streams;
+	/*
+	 * L2 has fixed 2 blocks per stream. Block address is calculated
+	 * from the block size
+	 */
+	u8 l2_block_sz[IPU6_MMU_MAX_TLB_L2_STREAMS];
+	/* flag to track if WA is needed for successive invalidate HW bug */
+	bool insert_read_before_invalidate;
+};
+
+struct ipu6_mmu_pdata {
+	u32 nr_mmus;
+	struct ipu6_mmu_hw mmu_hw[IPU6_MMU_MAX_DEVICES];
+	int mmid;
+};
+
+struct ipu6_isys_csi2_pdata {
+	void __iomem *base;
+};
+
+struct ipu6_isys_internal_csi2_pdata {
+	u32 nports;
+	u32 irq_mask;
+	u32 *offsets;
+	u32 ctrl0_irq_edge;
+	u32 ctrl0_irq_clear;
+	u32 ctrl0_irq_mask;
+	u32 ctrl0_irq_enable;
+	u32 ctrl0_irq_lnp;
+	u32 ctrl0_irq_status;
+	u32 fw_access_port_ofs;
+};
+
+struct ipu6_isys_internal_tpg_pdata {
+	u32 ntpgs;
+	u32 *offsets;
+	u32 *sels;
+};
+
+struct ipu6_hw_variants {
+	unsigned long offset;
+	u32 nr_mmus;
+	struct ipu6_mmu_hw mmu_hw[IPU6_MMU_MAX_DEVICES];
+	u8 cdc_fifos;
+	u8 cdc_fifo_threshold[IPU6_MAX_VC_IOSF_PORTS];
+	u32 dmem_offset;
+	u32 spc_offset;
+};
+
+struct ipu6_isys_internal_pdata {
+	struct ipu6_isys_internal_csi2_pdata csi2;
+	struct ipu6_hw_variants hw_variant;
+	u32 num_parallel_streams;
+	u32 isys_dma_overshoot;
+	u32 sram_gran_shift;
+	u32 sram_gran_size;
+	u32 max_sram_size;
+	u32 max_streams;
+	u32 max_send_queues;
+	u32 max_sram_blocks;
+	u32 max_devq_size;
+	u32 sensor_type_start;
+	u32 sensor_type_end;
+	u32 ltr;
+	u32 memopen_threshold;
+	bool enhanced_iwake;
+};
+
+struct ipu6_isys_pdata {
+	void __iomem *base;
+	const struct ipu6_isys_internal_pdata *ipdata;
+};
+
+struct ipu6_psys_internal_pdata {
+	struct ipu6_hw_variants hw_variant;
+};
+
+struct ipu6_psys_pdata {
+	void __iomem *base;
+	const struct ipu6_psys_internal_pdata *ipdata;
+};
+
+int ipu6_fw_authenticate(void *data, u64 val);
+void ipu6_configure_spc(struct ipu6_device *isp,
+			const struct ipu6_hw_variants *hw_variant,
+			int pkg_dir_idx, void __iomem *base, u64 *pkg_dir,
+			dma_addr_t pkg_dir_dma_addr);
+#endif /* IPU6_H */
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 86+ messages in thread

* [PATCH v2 02/15] media: intel/ipu6: add IPU auxiliary devices
  2023-10-24 11:29 [PATCH v2 00/15] Intel IPU6 and IPU6 input system drivers bingbu.cao
  2023-10-24 11:29 ` [PATCH v2 01/15] media: intel/ipu6: add Intel IPU6 PCI device driver bingbu.cao
@ 2023-10-24 11:29 ` bingbu.cao
  2023-10-24 12:58   ` Andy Shevchenko
  2023-10-24 11:29 ` [PATCH v2 03/15] media: intel/ipu6: add IPU6 buttress interface driver bingbu.cao
                   ` (14 subsequent siblings)
  16 siblings, 1 reply; 86+ messages in thread
From: bingbu.cao @ 2023-10-24 11:29 UTC (permalink / raw)
  To: linux-media, sakari.ailus, laurent.pinchart
  Cc: andriy.shevchenko, hdegoede, ilpo.jarvinen, andreaskleist,
	claus.stovgaard, tfiga, senozhatsky, tomi.valkeinen, bingbu.cao,
	bingbu.cao, tian.shu.qiu, hongju.wang

From: Bingbu Cao <bingbu.cao@intel.com>

Even the IPU input system and processing system are in a single PCI
device, each system has its own power sequence, the processing system
power up depends on the input system power up.

Besides, input system and processing system have their own MMU
hardware for IPU DMA address mapping.

Register the IS/PS devices on auxiliary bus and attach power domain
to implement the power sequence dependency.

Signed-off-by: Bingbu Cao <bingbu.cao@intel.com>
---
 drivers/media/pci/intel/ipu6/ipu6-bus.c | 157 ++++++++++++++++++++++++
 drivers/media/pci/intel/ipu6/ipu6-bus.h |  50 ++++++++
 drivers/media/pci/intel/ipu6/ipu6.c     |   5 +-
 3 files changed, 211 insertions(+), 1 deletion(-)
 create mode 100644 drivers/media/pci/intel/ipu6/ipu6-bus.c
 create mode 100644 drivers/media/pci/intel/ipu6/ipu6-bus.h

diff --git a/drivers/media/pci/intel/ipu6/ipu6-bus.c b/drivers/media/pci/intel/ipu6/ipu6-bus.c
new file mode 100644
index 000000000000..eabeda5ee4c9
--- /dev/null
+++ b/drivers/media/pci/intel/ipu6/ipu6-bus.c
@@ -0,0 +1,157 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2013 - 2023 Intel Corporation
+ */
+
+#include <linux/pci.h>
+#include <linux/pm_domain.h>
+#include <linux/pm_runtime.h>
+
+#include "ipu6.h"
+#include "ipu6-bus.h"
+#include "ipu6-dma.h"
+
+static int bus_pm_runtime_suspend(struct device *dev)
+{
+	struct ipu6_bus_device *adev = to_ipu6_bus_device(dev);
+	int ret;
+
+	ret = pm_generic_runtime_suspend(dev);
+	if (ret)
+		return ret;
+
+	ret = ipu6_buttress_power(dev, adev->ctrl, false);
+	if (!ret)
+		return 0;
+
+	dev_err(dev, "power down failed!\n");
+
+	/* Powering down failed, attempt to resume device now */
+	ret = pm_generic_runtime_resume(dev);
+	if (!ret)
+		return -EBUSY;
+
+	return -EIO;
+}
+
+static int bus_pm_runtime_resume(struct device *dev)
+{
+	struct ipu6_bus_device *adev = to_ipu6_bus_device(dev);
+	int ret;
+
+	ret = ipu6_buttress_power(dev, adev->ctrl, true);
+	if (ret)
+		return ret;
+
+	ret = pm_generic_runtime_resume(dev);
+	if (ret)
+		goto out_err;
+
+	return 0;
+
+out_err:
+	ipu6_buttress_power(dev, adev->ctrl, false);
+
+	return -EBUSY;
+}
+
+static struct dev_pm_domain ipu6_bus_pm_domain = {
+	.ops = {
+		.runtime_suspend = bus_pm_runtime_suspend,
+		.runtime_resume = bus_pm_runtime_resume,
+	},
+};
+
+static DEFINE_MUTEX(ipu6_bus_mutex);
+
+static void ipu6_bus_release(struct device *dev)
+{
+	struct ipu6_bus_device *adev = to_ipu6_bus_device(dev);
+
+	kfree(adev->pdata);
+	kfree(adev);
+}
+
+struct ipu6_bus_device *
+ipu6_bus_initialize_device(struct pci_dev *pdev, struct device *parent,
+			   void *pdata, struct ipu6_buttress_ctrl *ctrl,
+			   char *name)
+{
+	struct auxiliary_device *auxdev;
+	struct ipu6_bus_device *adev;
+	struct ipu6_device *isp = pci_get_drvdata(pdev);
+	int ret;
+
+	adev = kzalloc(sizeof(*adev), GFP_KERNEL);
+	if (!adev)
+		return ERR_PTR(-ENOMEM);
+
+	adev->dma_mask = DMA_BIT_MASK(isp->secure_mode ? IPU6_MMU_ADDR_BITS :
+				      IPU6_MMU_ADDR_BITS_NON_SECURE);
+	adev->isp = isp;
+	adev->ctrl = ctrl;
+	adev->pdata = pdata;
+	auxdev = &adev->auxdev;
+	auxdev->name = name;
+	auxdev->id = (pci_domain_nr(pdev->bus) << 16) |
+		      PCI_DEVID(pdev->bus->number, pdev->devfn);
+
+	auxdev->dev.parent = parent;
+	auxdev->dev.release = ipu6_bus_release;
+	auxdev->dev.dma_ops = &ipu6_dma_ops;
+	auxdev->dev.dma_mask = &adev->dma_mask;
+	auxdev->dev.dma_parms = pdev->dev.dma_parms;
+	auxdev->dev.coherent_dma_mask = adev->dma_mask;
+
+	ret = auxiliary_device_init(auxdev);
+	if (ret < 0) {
+		dev_err(&isp->pdev->dev, "auxiliary device init failed (%d)\n",
+			ret);
+		kfree(adev);
+		return ERR_PTR(ret);
+	}
+
+	dev_pm_domain_set(&auxdev->dev, &ipu6_bus_pm_domain);
+
+	pm_runtime_forbid(&adev->auxdev.dev);
+	pm_runtime_enable(&adev->auxdev.dev);
+
+	return adev;
+}
+
+int ipu6_bus_add_device(struct ipu6_bus_device *adev)
+{
+	struct auxiliary_device *auxdev = &adev->auxdev;
+	int ret;
+
+	ret = auxiliary_device_add(auxdev);
+	if (ret) {
+		auxiliary_device_uninit(auxdev);
+		return ret;
+	}
+
+	mutex_lock(&ipu6_bus_mutex);
+	list_add(&adev->list, &adev->isp->devices);
+	mutex_unlock(&ipu6_bus_mutex);
+
+	pm_runtime_allow(&auxdev->dev);
+
+	return 0;
+}
+
+void ipu6_bus_del_devices(struct pci_dev *pdev)
+{
+	struct ipu6_device *isp = pci_get_drvdata(pdev);
+	struct ipu6_bus_device *adev, *save;
+
+	mutex_lock(&ipu6_bus_mutex);
+
+	list_for_each_entry_safe(adev, save, &isp->devices, list) {
+		pm_runtime_disable(&adev->auxdev.dev);
+		list_del(&adev->list);
+		auxiliary_device_delete(&adev->auxdev);
+		auxiliary_device_uninit(&adev->auxdev);
+	}
+
+	mutex_unlock(&ipu6_bus_mutex);
+}
diff --git a/drivers/media/pci/intel/ipu6/ipu6-bus.h b/drivers/media/pci/intel/ipu6/ipu6-bus.h
new file mode 100644
index 000000000000..fa8bd73c3976
--- /dev/null
+++ b/drivers/media/pci/intel/ipu6/ipu6-bus.h
@@ -0,0 +1,50 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/* Copyright (C) 2013 - 2023 Intel Corporation */
+
+#ifndef IPU6_BUS_H
+#define IPU6_BUS_H
+
+#include <linux/auxiliary_bus.h>
+#include <linux/pci.h>
+
+#define IPU6_BUS_NAME	IPU6_NAME "-bus"
+
+struct ipu6_buttress_ctrl;
+
+struct ipu6_bus_device {
+	struct auxiliary_device auxdev;
+	struct auxiliary_driver *auxdrv;
+	const struct ipu6_auxdrv_data *auxdrv_data;
+	struct list_head list;
+	void *pdata;
+	struct ipu6_mmu *mmu;
+	struct ipu6_device *isp;
+	struct ipu6_buttress_ctrl *ctrl;
+	u64 dma_mask;
+	const struct firmware *fw;
+	struct sg_table fw_sgt;
+	u64 *pkg_dir;
+	dma_addr_t pkg_dir_dma_addr;
+	unsigned int pkg_dir_size;
+};
+
+struct ipu6_auxdrv_data {
+	irqreturn_t (*isr)(struct ipu6_bus_device *adev);
+	irqreturn_t (*isr_threaded)(struct ipu6_bus_device *adev);
+	bool wake_isr_thread;
+};
+
+#define to_ipu6_bus_device(_dev) container_of(to_auxiliary_dev(_dev), \
+					      struct ipu6_bus_device, auxdev)
+#define auxdev_to_adev(_auxdev) container_of(_auxdev, \
+					     struct ipu6_bus_device, auxdev)
+#define ipu6_bus_get_drvdata(adev) dev_get_drvdata(&(adev)->auxdev.dev)
+
+struct ipu6_bus_device *
+ipu6_bus_initialize_device(struct pci_dev *pdev, struct device *parent,
+			   void *pdata, struct ipu6_buttress_ctrl *ctrl,
+			   char *name);
+int ipu6_bus_add_device(struct ipu6_bus_device *adev);
+void ipu6_bus_del_devices(struct pci_dev *pdev);
+
+#endif
diff --git a/drivers/media/pci/intel/ipu6/ipu6.c b/drivers/media/pci/intel/ipu6/ipu6.c
index 84960a283daf..b652662fa72e 100644
--- a/drivers/media/pci/intel/ipu6/ipu6.c
+++ b/drivers/media/pci/intel/ipu6/ipu6.c
@@ -666,7 +666,10 @@ static int ipu6_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 		return dev_err_probe(&pdev->dev, ret,
 				     "Failed to set DMA mask\n");
 
-	dma_set_max_seg_size(&pdev->dev, UINT_MAX);
+	ret = dma_set_max_seg_size(&pdev->dev, UINT_MAX);
+	if (ret)
+		return dev_err_probe(&pdev->dev, ret,
+				     "Failed to set max_seg_size\n");
 
 	ret = ipu6_pci_config_setup(pdev, isp->hw_ver);
 	if (ret)
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 86+ messages in thread

* [PATCH v2 03/15] media: intel/ipu6: add IPU6 buttress interface driver
  2023-10-24 11:29 [PATCH v2 00/15] Intel IPU6 and IPU6 input system drivers bingbu.cao
  2023-10-24 11:29 ` [PATCH v2 01/15] media: intel/ipu6: add Intel IPU6 PCI device driver bingbu.cao
  2023-10-24 11:29 ` [PATCH v2 02/15] media: intel/ipu6: add IPU auxiliary devices bingbu.cao
@ 2023-10-24 11:29 ` bingbu.cao
  2024-01-03  9:22   ` Andreas Helbech Kleist
  2023-10-24 11:29 ` [PATCH v2 04/15] media: intel/ipu6: CPD parsing for get firmware components bingbu.cao
                   ` (13 subsequent siblings)
  16 siblings, 1 reply; 86+ messages in thread
From: bingbu.cao @ 2023-10-24 11:29 UTC (permalink / raw)
  To: linux-media, sakari.ailus, laurent.pinchart
  Cc: andriy.shevchenko, hdegoede, ilpo.jarvinen, andreaskleist,
	claus.stovgaard, tfiga, senozhatsky, tomi.valkeinen, bingbu.cao,
	bingbu.cao, tian.shu.qiu, hongju.wang

From: Bingbu Cao <bingbu.cao@intel.com>

The IPU6 buttress is the interface between IPU device (input system
and processing system) with rest of the SoC. It contains overall IPU
hardware control registers, these control registers are used as the
interfaces with the Intel Converged Security Engine and Punit to do
firmware authentication and power management.

Signed-off-by: Bingbu Cao <bingbu.cao@intel.com>
---
 drivers/media/pci/intel/ipu6/ipu6-buttress.c  | 900 ++++++++++++++++++
 drivers/media/pci/intel/ipu6/ipu6-buttress.h  | 107 +++
 .../intel/ipu6/ipu6-platform-buttress-regs.h  | 230 +++++
 3 files changed, 1237 insertions(+)
 create mode 100644 drivers/media/pci/intel/ipu6/ipu6-buttress.c
 create mode 100644 drivers/media/pci/intel/ipu6/ipu6-buttress.h
 create mode 100644 drivers/media/pci/intel/ipu6/ipu6-platform-buttress-regs.h

diff --git a/drivers/media/pci/intel/ipu6/ipu6-buttress.c b/drivers/media/pci/intel/ipu6/ipu6-buttress.c
new file mode 100644
index 000000000000..4a2db598b2b9
--- /dev/null
+++ b/drivers/media/pci/intel/ipu6/ipu6-buttress.c
@@ -0,0 +1,900 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2013 - 2023 Intel Corporation
+ */
+
+#include <linux/bitfield.h>
+#include <linux/completion.h>
+#include <linux/firmware.h>
+#include <linux/iopoll.h>
+#include <linux/pci.h>
+#include <linux/pm_runtime.h>
+
+#include "ipu6.h"
+#include "ipu6-bus.h"
+#include "ipu6-buttress.h"
+#include "ipu6-platform-buttress-regs.h"
+
+#define BOOTLOADER_STATUS_OFFSET       0x15c
+
+#define BOOTLOADER_MAGIC_KEY		0xb00710ad
+
+#define ENTRY	BUTTRESS_IU2CSECSR_IPC_PEER_COMP_ACTIONS_RST_PHASE1
+#define EXIT	BUTTRESS_IU2CSECSR_IPC_PEER_COMP_ACTIONS_RST_PHASE2
+#define QUERY	BUTTRESS_IU2CSECSR_IPC_PEER_QUERIED_IP_COMP_ACTIONS_RST_PHASE
+
+#define BUTTRESS_TSC_SYNC_RESET_TRIAL_MAX	10
+
+#define BUTTRESS_POWER_TIMEOUT_US		(200 * USEC_PER_MSEC)
+
+#define BUTTRESS_CSE_BOOTLOAD_TIMEOUT_US	(5 * USEC_PER_SEC)
+#define BUTTRESS_CSE_AUTHENTICATE_TIMEOUT_US	(10 * USEC_PER_SEC)
+#define BUTTRESS_CSE_FWRESET_TIMEOUT_US		(100 * USEC_PER_MSEC)
+
+#define BUTTRESS_IPC_TX_TIMEOUT_MS		MSEC_PER_SEC
+#define BUTTRESS_IPC_RX_TIMEOUT_MS		MSEC_PER_SEC
+#define BUTTRESS_IPC_VALIDITY_TIMEOUT_US	(1 * USEC_PER_SEC)
+#define BUTTRESS_TSC_SYNC_TIMEOUT_US		(5 * USEC_PER_MSEC)
+
+#define BUTTRESS_IPC_RESET_RETRY		2000
+#define BUTTRESS_CSE_IPC_RESET_RETRY	4
+#define BUTTRESS_IPC_CMD_SEND_RETRY	1
+
+#define BUTTRESS_MAX_CONSECUTIVE_IRQS	100
+
+static const u32 ipu6_adev_irq_mask[2] = {
+	BUTTRESS_ISR_IS_IRQ,
+	BUTTRESS_ISR_PS_IRQ
+};
+
+int ipu6_buttress_ipc_reset(struct ipu6_device *isp,
+			    struct ipu6_buttress_ipc *ipc)
+{
+	unsigned int retries = BUTTRESS_IPC_RESET_RETRY;
+	struct ipu6_buttress *b = &isp->buttress;
+	u32 val = 0, csr_in_clr;
+
+	if (!isp->secure_mode) {
+		dev_dbg(&isp->pdev->dev, "Skip IPC reset for non-secure mode");
+		return 0;
+	}
+
+	mutex_lock(&b->ipc_mutex);
+
+	/* Clear-by-1 CSR (all bits), corresponding internal states. */
+	val = readl(isp->base + ipc->csr_in);
+	writel(val, isp->base + ipc->csr_in);
+
+	/* Set peer CSR bit IPC_PEER_COMP_ACTIONS_RST_PHASE1 */
+	writel(ENTRY, isp->base + ipc->csr_out);
+	/*
+	 * Clear-by-1 all CSR bits EXCEPT following
+	 * bits:
+	 * A. IPC_PEER_COMP_ACTIONS_RST_PHASE1.
+	 * B. IPC_PEER_COMP_ACTIONS_RST_PHASE2.
+	 * C. Possibly custom bits, depending on
+	 * their role.
+	 */
+	csr_in_clr = BUTTRESS_IU2CSECSR_IPC_PEER_DEASSERTED_REG_VALID_REQ |
+		BUTTRESS_IU2CSECSR_IPC_PEER_ACKED_REG_VALID |
+		BUTTRESS_IU2CSECSR_IPC_PEER_ASSERTED_REG_VALID_REQ | QUERY;
+
+	do {
+		usleep_range(400, 500);
+		val = readl(isp->base + ipc->csr_in);
+		switch (val) {
+		case ENTRY | EXIT:
+		case ENTRY | EXIT | QUERY:
+			/*
+			 * 1) Clear-by-1 CSR bits
+			 * (IPC_PEER_COMP_ACTIONS_RST_PHASE1,
+			 * IPC_PEER_COMP_ACTIONS_RST_PHASE2).
+			 * 2) Set peer CSR bit
+			 * IPC_PEER_QUERIED_IP_COMP_ACTIONS_RST_PHASE.
+			 */
+			writel(ENTRY | EXIT, isp->base + ipc->csr_in);
+			writel(QUERY, isp->base + ipc->csr_out);
+			break;
+		case ENTRY:
+		case ENTRY | QUERY:
+			/*
+			 * 1) Clear-by-1 CSR bits
+			 * (IPC_PEER_COMP_ACTIONS_RST_PHASE1,
+			 * IPC_PEER_QUERIED_IP_COMP_ACTIONS_RST_PHASE).
+			 * 2) Set peer CSR bit
+			 * IPC_PEER_COMP_ACTIONS_RST_PHASE1.
+			 */
+			writel(ENTRY | QUERY, isp->base + ipc->csr_in);
+			writel(ENTRY, isp->base + ipc->csr_out);
+			break;
+		case EXIT:
+		case EXIT | QUERY:
+			/*
+			 * Clear-by-1 CSR bit
+			 * IPC_PEER_COMP_ACTIONS_RST_PHASE2.
+			 * 1) Clear incoming doorbell.
+			 * 2) Clear-by-1 all CSR bits EXCEPT following
+			 * bits:
+			 * A. IPC_PEER_COMP_ACTIONS_RST_PHASE1.
+			 * B. IPC_PEER_COMP_ACTIONS_RST_PHASE2.
+			 * C. Possibly custom bits, depending on
+			 * their role.
+			 * 3) Set peer CSR bit
+			 * IPC_PEER_COMP_ACTIONS_RST_PHASE2.
+			 */
+			writel(EXIT, isp->base + ipc->csr_in);
+			writel(0, isp->base + ipc->db0_in);
+			writel(csr_in_clr, isp->base + ipc->csr_in);
+			writel(EXIT, isp->base + ipc->csr_out);
+
+			/*
+			 * Read csr_in again to make sure if RST_PHASE2 is done.
+			 * If csr_in is QUERY, it should be handled again.
+			 */
+			usleep_range(200, 300);
+			val = readl(isp->base + ipc->csr_in);
+			if (val & QUERY) {
+				dev_dbg(&isp->pdev->dev,
+					"RST_PHASE2 retry csr_in = %x\n", val);
+				break;
+			}
+			mutex_unlock(&b->ipc_mutex);
+			return 0;
+		case QUERY:
+			/*
+			 * 1) Clear-by-1 CSR bit
+			 * IPC_PEER_QUERIED_IP_COMP_ACTIONS_RST_PHASE.
+			 * 2) Set peer CSR bit
+			 * IPC_PEER_COMP_ACTIONS_RST_PHASE1
+			 */
+			writel(QUERY, isp->base + ipc->csr_in);
+			writel(ENTRY, isp->base + ipc->csr_out);
+			break;
+		default:
+			dev_warn_ratelimited(&isp->pdev->dev,
+					     "Unexpected CSR 0x%x\n", val);
+			break;
+		}
+	} while (retries--);
+
+	mutex_unlock(&b->ipc_mutex);
+	dev_err(&isp->pdev->dev, "Timed out while waiting for CSE\n");
+
+	return -ETIMEDOUT;
+}
+
+static void ipu6_buttress_ipc_validity_close(struct ipu6_device *isp,
+					     struct ipu6_buttress_ipc *ipc)
+{
+	writel(BUTTRESS_IU2CSECSR_IPC_PEER_DEASSERTED_REG_VALID_REQ,
+	       isp->base + ipc->csr_out);
+}
+
+static int
+ipu6_buttress_ipc_validity_open(struct ipu6_device *isp,
+				struct ipu6_buttress_ipc *ipc)
+{
+	unsigned int mask = BUTTRESS_IU2CSECSR_IPC_PEER_ACKED_REG_VALID;
+	void __iomem *addr;
+	int ret;
+	u32 val;
+
+	writel(BUTTRESS_IU2CSECSR_IPC_PEER_ASSERTED_REG_VALID_REQ,
+	       isp->base + ipc->csr_out);
+
+	addr = isp->base + ipc->csr_in;
+	ret = readl_poll_timeout(addr, val, val & mask, 200,
+				 BUTTRESS_IPC_VALIDITY_TIMEOUT_US);
+	if (ret) {
+		dev_err(&isp->pdev->dev, "CSE validity timeout 0x%x\n", val);
+		ipu6_buttress_ipc_validity_close(isp, ipc);
+	}
+
+	return ret;
+}
+
+static void ipu6_buttress_ipc_recv(struct ipu6_device *isp,
+				   struct ipu6_buttress_ipc *ipc, u32 *ipc_msg)
+{
+	if (ipc_msg)
+		*ipc_msg = readl(isp->base + ipc->data0_in);
+	writel(0, isp->base + ipc->db0_in);
+}
+
+static int ipu6_buttress_ipc_send_bulk(struct ipu6_device *isp,
+				       enum ipu6_buttress_ipc_domain ipc_domain,
+				       struct ipu6_ipc_buttress_bulk_msg *msgs,
+				       u32 size)
+{
+	unsigned long tx_timeout_jiffies, rx_timeout_jiffies;
+	unsigned int i, retry = BUTTRESS_IPC_CMD_SEND_RETRY;
+	struct ipu6_buttress *b = &isp->buttress;
+	struct ipu6_buttress_ipc *ipc;
+	u32 val;
+	int ret;
+	int tout;
+
+	ipc = ipc_domain == IPU6_BUTTRESS_IPC_CSE ? &b->cse : &b->ish;
+
+	mutex_lock(&b->ipc_mutex);
+
+	ret = ipu6_buttress_ipc_validity_open(isp, ipc);
+	if (ret) {
+		dev_err(&isp->pdev->dev, "IPC validity open failed\n");
+		goto out;
+	}
+
+	tx_timeout_jiffies = msecs_to_jiffies(BUTTRESS_IPC_TX_TIMEOUT_MS);
+	rx_timeout_jiffies = msecs_to_jiffies(BUTTRESS_IPC_RX_TIMEOUT_MS);
+
+	for (i = 0; i < size; i++) {
+		reinit_completion(&ipc->send_complete);
+		if (msgs[i].require_resp)
+			reinit_completion(&ipc->recv_complete);
+
+		dev_dbg(&isp->pdev->dev, "bulk IPC command: 0x%x\n",
+			msgs[i].cmd);
+		writel(msgs[i].cmd, isp->base + ipc->data0_out);
+		val = BUTTRESS_IU2CSEDB0_BUSY | msgs[i].cmd_size;
+		writel(val, isp->base + ipc->db0_out);
+
+		tout = wait_for_completion_timeout(&ipc->send_complete,
+						   tx_timeout_jiffies);
+		if (!tout) {
+			dev_err(&isp->pdev->dev, "send IPC response timeout\n");
+			if (!retry--) {
+				ret = -ETIMEDOUT;
+				goto out;
+			}
+
+			/* Try again if CSE is not responding on first try */
+			writel(0, isp->base + ipc->db0_out);
+			i--;
+			continue;
+		}
+
+		retry = BUTTRESS_IPC_CMD_SEND_RETRY;
+
+		if (!msgs[i].require_resp)
+			continue;
+
+		tout = wait_for_completion_timeout(&ipc->recv_complete,
+						   rx_timeout_jiffies);
+		if (!tout) {
+			dev_err(&isp->pdev->dev, "recv IPC response timeout\n");
+			ret = -ETIMEDOUT;
+			goto out;
+		}
+
+		if (ipc->nack_mask &&
+		    (ipc->recv_data & ipc->nack_mask) == ipc->nack) {
+			dev_err(&isp->pdev->dev,
+				"IPC NACK for cmd 0x%x\n", msgs[i].cmd);
+			ret = -EIO;
+			goto out;
+		}
+
+		if (ipc->recv_data != msgs[i].expected_resp) {
+			dev_err(&isp->pdev->dev,
+				"expected resp: 0x%x, IPC response: 0x%x ",
+				msgs[i].expected_resp, ipc->recv_data);
+			ret = -EIO;
+			goto out;
+		}
+	}
+
+	dev_dbg(&isp->pdev->dev, "bulk IPC commands done\n");
+
+out:
+	ipu6_buttress_ipc_validity_close(isp, ipc);
+	mutex_unlock(&b->ipc_mutex);
+	return ret;
+}
+
+static int
+ipu6_buttress_ipc_send(struct ipu6_device *isp,
+		       enum ipu6_buttress_ipc_domain ipc_domain,
+		       u32 ipc_msg, u32 size, bool require_resp,
+		       u32 expected_resp)
+{
+	struct ipu6_ipc_buttress_bulk_msg msg = {
+		.cmd = ipc_msg,
+		.cmd_size = size,
+		.require_resp = require_resp,
+		.expected_resp = expected_resp,
+	};
+
+	return ipu6_buttress_ipc_send_bulk(isp, ipc_domain, &msg, 1);
+}
+
+static irqreturn_t ipu6_buttress_call_isr(struct ipu6_bus_device *adev)
+{
+	irqreturn_t ret = IRQ_WAKE_THREAD;
+
+	if (!adev || !adev->auxdrv || !adev->auxdrv_data)
+		return IRQ_NONE;
+
+	if (adev->auxdrv_data->isr)
+		ret = adev->auxdrv_data->isr(adev);
+
+	if (ret == IRQ_WAKE_THREAD && !adev->auxdrv_data->isr_threaded)
+		ret = IRQ_NONE;
+
+	return ret;
+}
+
+irqreturn_t ipu6_buttress_isr(int irq, void *isp_ptr)
+{
+	struct ipu6_device *isp = isp_ptr;
+	struct ipu6_bus_device *adev[] = { isp->isys, isp->psys };
+	struct ipu6_buttress *b = &isp->buttress;
+	u32 reg_irq_sts = BUTTRESS_REG_ISR_STATUS;
+	irqreturn_t ret = IRQ_NONE;
+	u32 disable_irqs = 0;
+	u32 irq_status;
+	u32 i, count = 0;
+
+	pm_runtime_get_noresume(&isp->pdev->dev);
+
+	irq_status = readl(isp->base + reg_irq_sts);
+	if (!irq_status) {
+		pm_runtime_put_noidle(&isp->pdev->dev);
+		return IRQ_NONE;
+	}
+
+	do {
+		writel(irq_status, isp->base + BUTTRESS_REG_ISR_CLEAR);
+
+		for (i = 0; i < ARRAY_SIZE(ipu6_adev_irq_mask); i++) {
+			irqreturn_t r = ipu6_buttress_call_isr(adev[i]);
+
+			if (!(irq_status & ipu6_adev_irq_mask[i]))
+				continue;
+
+			if (r == IRQ_WAKE_THREAD) {
+				ret = IRQ_WAKE_THREAD;
+				disable_irqs |= ipu6_adev_irq_mask[i];
+			} else if (ret == IRQ_NONE && r == IRQ_HANDLED) {
+				ret = IRQ_HANDLED;
+			}
+		}
+
+		if ((irq_status & BUTTRESS_EVENT) && ret == IRQ_NONE)
+			ret = IRQ_HANDLED;
+
+		if (irq_status & BUTTRESS_ISR_IPC_FROM_CSE_IS_WAITING) {
+			dev_dbg(&isp->pdev->dev,
+				"BUTTRESS_ISR_IPC_FROM_CSE_IS_WAITING\n");
+			ipu6_buttress_ipc_recv(isp, &b->cse, &b->cse.recv_data);
+			complete(&b->cse.recv_complete);
+		}
+
+		if (irq_status & BUTTRESS_ISR_IPC_FROM_ISH_IS_WAITING) {
+			dev_dbg(&isp->pdev->dev,
+				"BUTTRESS_ISR_IPC_FROM_ISH_IS_WAITING\n");
+			ipu6_buttress_ipc_recv(isp, &b->ish, &b->ish.recv_data);
+			complete(&b->ish.recv_complete);
+		}
+
+		if (irq_status & BUTTRESS_ISR_IPC_EXEC_DONE_BY_CSE) {
+			dev_dbg(&isp->pdev->dev,
+				"BUTTRESS_ISR_IPC_EXEC_DONE_BY_CSE\n");
+			complete(&b->cse.send_complete);
+		}
+
+		if (irq_status & BUTTRESS_ISR_IPC_EXEC_DONE_BY_ISH) {
+			dev_dbg(&isp->pdev->dev,
+				"BUTTRESS_ISR_IPC_EXEC_DONE_BY_CSE\n");
+			complete(&b->ish.send_complete);
+		}
+
+		if (irq_status & BUTTRESS_ISR_SAI_VIOLATION &&
+		    ipu6_buttress_get_secure_mode(isp))
+			dev_err(&isp->pdev->dev,
+				"BUTTRESS_ISR_SAI_VIOLATION\n");
+
+		if (irq_status & (BUTTRESS_ISR_IS_FATAL_MEM_ERR |
+				  BUTTRESS_ISR_PS_FATAL_MEM_ERR))
+			dev_err(&isp->pdev->dev,
+				"BUTTRESS_ISR_FATAL_MEM_ERR\n");
+
+		if (irq_status & BUTTRESS_ISR_UFI_ERROR)
+			dev_err(&isp->pdev->dev, "BUTTRESS_ISR_UFI_ERROR\n");
+
+		if (++count == BUTTRESS_MAX_CONSECUTIVE_IRQS) {
+			dev_err(&isp->pdev->dev, "too many consecutive IRQs\n");
+			ret = IRQ_NONE;
+			break;
+		}
+
+		irq_status = readl(isp->base + reg_irq_sts);
+	} while (irq_status);
+
+	if (disable_irqs)
+		writel(BUTTRESS_IRQS & ~disable_irqs,
+		       isp->base + BUTTRESS_REG_ISR_ENABLE);
+
+	pm_runtime_put(&isp->pdev->dev);
+
+	return ret;
+}
+
+irqreturn_t ipu6_buttress_isr_threaded(int irq, void *isp_ptr)
+{
+	struct ipu6_device *isp = isp_ptr;
+	struct ipu6_bus_device *adev[] = { isp->isys, isp->psys };
+	const struct ipu6_auxdrv_data *drv_data = NULL;
+	irqreturn_t ret = IRQ_NONE;
+	unsigned int i;
+
+	for (i = 0; i < ARRAY_SIZE(ipu6_adev_irq_mask) && adev[i]; i++) {
+		drv_data = adev[i]->auxdrv_data;
+		if (!drv_data)
+			continue;
+
+		if (drv_data->wake_isr_thread &&
+		    drv_data->isr_threaded(adev[i]) == IRQ_HANDLED)
+			ret = IRQ_HANDLED;
+	}
+
+	writel(BUTTRESS_IRQS, isp->base + BUTTRESS_REG_ISR_ENABLE);
+
+	return ret;
+}
+
+int ipu6_buttress_power(struct device *dev, struct ipu6_buttress_ctrl *ctrl,
+			bool on)
+{
+	struct ipu6_device *isp = to_ipu6_bus_device(dev)->isp;
+	u32 pwr_sts, val;
+	int ret;
+
+	if (!ctrl)
+		return 0;
+
+	mutex_lock(&isp->buttress.power_mutex);
+
+	if (!on) {
+		val = 0;
+		pwr_sts = ctrl->pwr_sts_off << ctrl->pwr_sts_shift;
+	} else {
+		val = BUTTRESS_FREQ_CTL_START |
+			FIELD_PREP(BUTTRESS_FREQ_CTL_RATIO_MASK,
+				   ctrl->ratio) |
+			FIELD_PREP(BUTTRESS_FREQ_CTL_QOS_FLOOR_MASK,
+				   ctrl->qos_floor) |
+			BUTTRESS_FREQ_CTL_ICCMAX_LEVEL;
+
+		pwr_sts = ctrl->pwr_sts_on << ctrl->pwr_sts_shift;
+	}
+
+	writel(val, isp->base + ctrl->freq_ctl);
+
+	ret = readl_poll_timeout(isp->base + BUTTRESS_REG_PWR_STATE,
+				 val, (val & ctrl->pwr_sts_mask) == pwr_sts,
+				 100, BUTTRESS_POWER_TIMEOUT_US);
+	if (ret)
+		dev_err(&isp->pdev->dev,
+			"Change power status timeout with 0x%x\n", val);
+
+	ctrl->started = !ret && on;
+
+	mutex_unlock(&isp->buttress.power_mutex);
+
+	return ret;
+}
+
+bool ipu6_buttress_get_secure_mode(struct ipu6_device *isp)
+{
+	u32 val;
+
+	val = readl(isp->base + BUTTRESS_REG_SECURITY_CTL);
+
+	return val & BUTTRESS_SECURITY_CTL_FW_SECURE_MODE;
+}
+
+bool ipu6_buttress_auth_done(struct ipu6_device *isp)
+{
+	u32 val;
+
+	if (!isp->secure_mode)
+		return true;
+
+	val = readl(isp->base + BUTTRESS_REG_SECURITY_CTL);
+	val = FIELD_GET(BUTTRESS_SECURITY_CTL_FW_SETUP_MASK, val);
+
+	return val == BUTTRESS_SECURITY_CTL_AUTH_DONE;
+}
+EXPORT_SYMBOL_NS_GPL(ipu6_buttress_auth_done, INTEL_IPU6);
+
+int ipu6_buttress_reset_authentication(struct ipu6_device *isp)
+{
+	int ret;
+	u32 val;
+
+	if (!isp->secure_mode) {
+		dev_dbg(&isp->pdev->dev, "Skip auth for non-secure mode\n");
+		return 0;
+	}
+
+	writel(BUTTRESS_FW_RESET_CTL_START, isp->base +
+	       BUTTRESS_REG_FW_RESET_CTL);
+
+	ret = readl_poll_timeout(isp->base + BUTTRESS_REG_FW_RESET_CTL, val,
+				 val & BUTTRESS_FW_RESET_CTL_DONE, 500,
+				 BUTTRESS_CSE_FWRESET_TIMEOUT_US);
+	if (ret) {
+		dev_err(&isp->pdev->dev,
+			"Time out while resetting authentication state\n");
+		return ret;
+	}
+
+	dev_dbg(&isp->pdev->dev, "FW reset for authentication done\n");
+	writel(0, isp->base + BUTTRESS_REG_FW_RESET_CTL);
+	/* leave some time for HW restore */
+	usleep_range(800, 1000);
+
+	return 0;
+}
+
+int ipu6_buttress_map_fw_image(struct ipu6_bus_device *sys,
+			       const struct firmware *fw, struct sg_table *sgt)
+{
+	struct page **pages;
+	const void *addr;
+	unsigned long n_pages;
+	unsigned int i;
+	int ret;
+
+	n_pages = PHYS_PFN(PAGE_ALIGN(fw->size));
+
+	pages = kmalloc_array(n_pages, sizeof(*pages), GFP_KERNEL);
+	if (!pages)
+		return -ENOMEM;
+
+	addr = fw->data;
+	for (i = 0; i < n_pages; i++) {
+		struct page *p = vmalloc_to_page(addr);
+
+		if (!p) {
+			ret = -ENOMEM;
+			goto out;
+		}
+		pages[i] = p;
+		addr += PAGE_SIZE;
+	}
+
+	ret = sg_alloc_table_from_pages(sgt, pages, n_pages, 0, fw->size,
+					GFP_KERNEL);
+	if (ret) {
+		ret = -ENOMEM;
+		goto out;
+	}
+
+	ret = dma_map_sgtable(&sys->auxdev.dev, sgt, DMA_TO_DEVICE, 0);
+	if (ret < 0) {
+		ret = -ENOMEM;
+		sg_free_table(sgt);
+		goto out;
+	}
+
+	dma_sync_sgtable_for_device(&sys->auxdev.dev, sgt, DMA_TO_DEVICE);
+
+out:
+	kfree(pages);
+
+	return ret;
+}
+EXPORT_SYMBOL_NS_GPL(ipu6_buttress_map_fw_image, INTEL_IPU6);
+
+void ipu6_buttress_unmap_fw_image(struct ipu6_bus_device *sys,
+				  struct sg_table *sgt)
+{
+	dma_unmap_sgtable(&sys->auxdev.dev, sgt, DMA_TO_DEVICE, 0);
+	sg_free_table(sgt);
+}
+EXPORT_SYMBOL_NS_GPL(ipu6_buttress_unmap_fw_image, INTEL_IPU6);
+
+int ipu6_buttress_authenticate(struct ipu6_device *isp)
+{
+	struct ipu6_buttress *b = &isp->buttress;
+	struct ipu6_psys_pdata *psys_pdata;
+	u32 data, mask, done, fail;
+	int ret;
+
+	if (!isp->secure_mode) {
+		dev_dbg(&isp->pdev->dev, "Skip auth for non-secure mode\n");
+		return 0;
+	}
+
+	psys_pdata = isp->psys->pdata;
+
+	mutex_lock(&b->auth_mutex);
+
+	if (ipu6_buttress_auth_done(isp)) {
+		ret = 0;
+		goto out_unlock;
+	}
+
+	/*
+	 * Write address of FIT table to FW_SOURCE register
+	 * Let's use fw address. I.e. not using FIT table yet
+	 */
+	data = lower_32_bits(isp->psys->pkg_dir_dma_addr);
+	writel(data, isp->base + BUTTRESS_REG_FW_SOURCE_BASE_LO);
+
+	data = upper_32_bits(isp->psys->pkg_dir_dma_addr);
+	writel(data, isp->base + BUTTRESS_REG_FW_SOURCE_BASE_HI);
+
+	/*
+	 * Write boot_load into IU2CSEDATA0
+	 * Write sizeof(boot_load) | 0x2 << CLIENT_ID to
+	 * IU2CSEDB.IU2CSECMD and set IU2CSEDB.IU2CSEBUSY as
+	 */
+	dev_info(&isp->pdev->dev, "Sending BOOT_LOAD to CSE\n");
+
+	ret = ipu6_buttress_ipc_send(isp, IPU6_BUTTRESS_IPC_CSE,
+				     BUTTRESS_IU2CSEDATA0_IPC_BOOT_LOAD,
+				     1, true,
+				     BUTTRESS_CSE2IUDATA0_IPC_BOOT_LOAD_DONE);
+	if (ret) {
+		dev_err(&isp->pdev->dev, "CSE boot_load failed\n");
+		goto out_unlock;
+	}
+
+	mask = BUTTRESS_SECURITY_CTL_FW_SETUP_MASK;
+	done = BUTTRESS_SECURITY_CTL_FW_SETUP_DONE;
+	fail = BUTTRESS_SECURITY_CTL_AUTH_FAILED;
+	ret = readl_poll_timeout(isp->base + BUTTRESS_REG_SECURITY_CTL, data,
+				 ((data & mask) == done ||
+				  (data & mask) == fail), 500,
+				 BUTTRESS_CSE_BOOTLOAD_TIMEOUT_US);
+	if (ret) {
+		dev_err(&isp->pdev->dev, "CSE boot_load timeout\n");
+		goto out_unlock;
+	}
+
+	if ((data & mask) == fail) {
+		dev_err(&isp->pdev->dev, "CSE auth failed\n");
+		ret = -EINVAL;
+		goto out_unlock;
+	}
+
+	ret = readl_poll_timeout(psys_pdata->base + BOOTLOADER_STATUS_OFFSET,
+				 data, data == BOOTLOADER_MAGIC_KEY, 500,
+				 BUTTRESS_CSE_BOOTLOAD_TIMEOUT_US);
+	if (ret) {
+		dev_err(&isp->pdev->dev, "Unexpected magic number 0x%x\n",
+			data);
+		goto out_unlock;
+	}
+
+	/*
+	 * Write authenticate_run into IU2CSEDATA0
+	 * Write sizeof(boot_load) | 0x2 << CLIENT_ID to
+	 * IU2CSEDB.IU2CSECMD and set IU2CSEDB.IU2CSEBUSY as
+	 */
+	dev_info(&isp->pdev->dev, "Sending AUTHENTICATE_RUN to CSE\n");
+	ret = ipu6_buttress_ipc_send(isp, IPU6_BUTTRESS_IPC_CSE,
+				     BUTTRESS_IU2CSEDATA0_IPC_AUTH_RUN,
+				     1, true,
+				     BUTTRESS_CSE2IUDATA0_IPC_AUTH_RUN_DONE);
+	if (ret) {
+		dev_err(&isp->pdev->dev, "CSE authenticate_run failed\n");
+		goto out_unlock;
+	}
+
+	done = BUTTRESS_SECURITY_CTL_AUTH_DONE;
+	ret = readl_poll_timeout(isp->base + BUTTRESS_REG_SECURITY_CTL, data,
+				 ((data & mask) == done ||
+				  (data & mask) == fail), 500,
+				 BUTTRESS_CSE_AUTHENTICATE_TIMEOUT_US);
+	if (ret) {
+		dev_err(&isp->pdev->dev, "CSE authenticate timeout\n");
+		goto out_unlock;
+	}
+
+	if ((data & mask) == fail) {
+		dev_err(&isp->pdev->dev, "CSE boot_load failed\n");
+		ret = -EINVAL;
+		goto out_unlock;
+	}
+
+	dev_info(&isp->pdev->dev, "CSE authenticate_run done\n");
+
+out_unlock:
+	mutex_unlock(&b->auth_mutex);
+
+	return ret;
+}
+
+static int ipu6_buttress_send_tsc_request(struct ipu6_device *isp)
+{
+	u32 val, mask, done;
+	int ret;
+
+	mask = BUTTRESS_PWR_STATE_HH_STATUS_MASK;
+
+	writel(BUTTRESS_FABRIC_CMD_START_TSC_SYNC,
+	       isp->base + BUTTRESS_REG_FABRIC_CMD);
+
+	val = readl(isp->base + BUTTRESS_REG_PWR_STATE);
+	val = FIELD_GET(mask, val);
+	if (val == BUTTRESS_PWR_STATE_HH_STATE_ERR) {
+		dev_err(&isp->pdev->dev, "Start tsc sync failed\n");
+		return -EINVAL;
+	}
+
+	done = BUTTRESS_PWR_STATE_HH_STATE_DONE;
+	ret = readl_poll_timeout(isp->base + BUTTRESS_REG_PWR_STATE, val,
+				 FIELD_GET(mask, val) == done, 500,
+				 BUTTRESS_TSC_SYNC_TIMEOUT_US);
+	if (ret)
+		dev_err(&isp->pdev->dev, "Start tsc sync timeout\n");
+
+	return ret;
+}
+
+int ipu6_buttress_start_tsc_sync(struct ipu6_device *isp)
+{
+	unsigned int i;
+
+	for (i = 0; i < BUTTRESS_TSC_SYNC_RESET_TRIAL_MAX; i++) {
+		u32 val;
+		int ret;
+
+		ret = ipu6_buttress_send_tsc_request(isp);
+		if (ret != -ETIMEDOUT)
+			return ret;
+
+		val = readl(isp->base + BUTTRESS_REG_TSW_CTL);
+		val = val | BUTTRESS_TSW_CTL_SOFT_RESET;
+		writel(val, isp->base + BUTTRESS_REG_TSW_CTL);
+		val = val & ~BUTTRESS_TSW_CTL_SOFT_RESET;
+		writel(val, isp->base + BUTTRESS_REG_TSW_CTL);
+	}
+
+	dev_err(&isp->pdev->dev, "TSC sync failed (timeout)\n");
+
+	return -ETIMEDOUT;
+}
+EXPORT_SYMBOL_NS_GPL(ipu6_buttress_start_tsc_sync, INTEL_IPU6);
+
+void ipu6_buttress_tsc_read(struct ipu6_device *isp, u64 *val)
+{
+	u32 tsc_hi_1, tsc_hi_2, tsc_lo;
+	unsigned long flags;
+
+	local_irq_save(flags);
+	tsc_hi_1 = readl(isp->base + BUTTRESS_REG_TSC_HI);
+	tsc_lo = readl(isp->base + BUTTRESS_REG_TSC_LO);
+	tsc_hi_2 = readl(isp->base + BUTTRESS_REG_TSC_HI);
+	if (tsc_hi_1 == tsc_hi_2) {
+		*val = (u64)tsc_hi_1 << 32 | tsc_lo;
+	} else {
+		/* Check if TSC has rolled over */
+		if (tsc_lo & BIT(31))
+			*val = (u64)tsc_hi_1 << 32 | tsc_lo;
+		else
+			*val = (u64)tsc_hi_2 << 32 | tsc_lo;
+	}
+	local_irq_restore(flags);
+}
+EXPORT_SYMBOL_NS_GPL(ipu6_buttress_tsc_read, INTEL_IPU6);
+
+u64 ipu6_buttress_tsc_ticks_to_ns(u64 ticks, const struct ipu6_device *isp)
+{
+	u64 ns = ticks * 10000;
+
+	/*
+	 * converting TSC tick count to ns is calculated by:
+	 * Example (TSC clock frequency is 19.2MHz):
+	 * ns = ticks * 1000 000 000 / 19.2Mhz
+	 *    = ticks * 1000 000 000 / 19200000Hz
+	 *    = ticks * 10000 / 192 ns
+	 */
+	return div_u64(ns, isp->buttress.ref_clk);
+}
+EXPORT_SYMBOL_NS_GPL(ipu6_buttress_tsc_ticks_to_ns, INTEL_IPU6);
+
+void ipu6_buttress_restore(struct ipu6_device *isp)
+{
+	struct ipu6_buttress *b = &isp->buttress;
+
+	writel(BUTTRESS_IRQS, isp->base + BUTTRESS_REG_ISR_CLEAR);
+	writel(BUTTRESS_IRQS, isp->base + BUTTRESS_REG_ISR_ENABLE);
+	writel(b->wdt_cached_value, isp->base + BUTTRESS_REG_WDT);
+}
+
+int ipu6_buttress_init(struct ipu6_device *isp)
+{
+	int ret, ipc_reset_retry = BUTTRESS_CSE_IPC_RESET_RETRY;
+	struct ipu6_buttress *b = &isp->buttress;
+	u32 val;
+
+	mutex_init(&b->power_mutex);
+	mutex_init(&b->auth_mutex);
+	mutex_init(&b->cons_mutex);
+	mutex_init(&b->ipc_mutex);
+	init_completion(&b->ish.send_complete);
+	init_completion(&b->cse.send_complete);
+	init_completion(&b->ish.recv_complete);
+	init_completion(&b->cse.recv_complete);
+
+	b->cse.nack = BUTTRESS_CSE2IUDATA0_IPC_NACK;
+	b->cse.nack_mask = BUTTRESS_CSE2IUDATA0_IPC_NACK_MASK;
+	b->cse.csr_in = BUTTRESS_REG_CSE2IUCSR;
+	b->cse.csr_out = BUTTRESS_REG_IU2CSECSR;
+	b->cse.db0_in = BUTTRESS_REG_CSE2IUDB0;
+	b->cse.db0_out = BUTTRESS_REG_IU2CSEDB0;
+	b->cse.data0_in = BUTTRESS_REG_CSE2IUDATA0;
+	b->cse.data0_out = BUTTRESS_REG_IU2CSEDATA0;
+
+	/* no ISH on IPU6 */
+	memset(&b->ish, 0, sizeof(b->ish));
+	INIT_LIST_HEAD(&b->constraints);
+
+	isp->secure_mode = ipu6_buttress_get_secure_mode(isp);
+	dev_info(&isp->pdev->dev, "IPU6 in %s mode touch 0x%x mask 0x%x\n",
+		 isp->secure_mode ? "secure" : "non-secure",
+		 readl(isp->base + BUTTRESS_REG_SECURITY_TOUCH),
+		 readl(isp->base + BUTTRESS_REG_CAMERA_MASK));
+
+	b->wdt_cached_value = readl(isp->base + BUTTRESS_REG_WDT);
+	writel(BUTTRESS_IRQS, isp->base + BUTTRESS_REG_ISR_CLEAR);
+	writel(BUTTRESS_IRQS, isp->base + BUTTRESS_REG_ISR_ENABLE);
+
+	/* get ref_clk frequency by reading the indication in btrs control */
+	val = readl(isp->base + BUTTRESS_REG_BTRS_CTRL);
+	val = FIELD_GET(BUTTRESS_REG_BTRS_CTRL_REF_CLK_IND, val);
+
+	switch (val) {
+	case 0x0:
+		b->ref_clk = 240;
+		break;
+	case 0x1:
+		b->ref_clk = 192;
+		break;
+	case 0x2:
+		b->ref_clk = 384;
+		break;
+	default:
+		dev_warn(&isp->pdev->dev,
+			 "Unsupported ref clock, use 19.2Mhz by default.\n");
+		b->ref_clk = 192;
+		break;
+	}
+
+	/* Retry couple of times in case of CSE initialization is delayed */
+	do {
+		ret = ipu6_buttress_ipc_reset(isp, &b->cse);
+		if (ret) {
+			dev_warn(&isp->pdev->dev,
+				 "IPC reset protocol failed, retrying\n");
+		} else {
+			dev_dbg(&isp->pdev->dev, "IPC reset done\n");
+			return 0;
+		}
+	} while (ipc_reset_retry--);
+
+	dev_err(&isp->pdev->dev, "IPC reset protocol failed\n");
+
+	mutex_destroy(&b->power_mutex);
+	mutex_destroy(&b->auth_mutex);
+	mutex_destroy(&b->cons_mutex);
+	mutex_destroy(&b->ipc_mutex);
+
+	return ret;
+}
+
+void ipu6_buttress_exit(struct ipu6_device *isp)
+{
+	struct ipu6_buttress *b = &isp->buttress;
+
+	writel(0, isp->base + BUTTRESS_REG_ISR_ENABLE);
+
+	mutex_destroy(&b->power_mutex);
+	mutex_destroy(&b->auth_mutex);
+	mutex_destroy(&b->cons_mutex);
+	mutex_destroy(&b->ipc_mutex);
+}
diff --git a/drivers/media/pci/intel/ipu6/ipu6-buttress.h b/drivers/media/pci/intel/ipu6/ipu6-buttress.h
new file mode 100644
index 000000000000..8a62a2e0d661
--- /dev/null
+++ b/drivers/media/pci/intel/ipu6/ipu6-buttress.h
@@ -0,0 +1,107 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/* Copyright (C) 2013 - 2023 Intel Corporation */
+
+#ifndef IPU6_BUTTRESS_H
+#define IPU6_BUTTRESS_H
+
+#include <linux/device.h>
+
+struct firmware;
+struct ipu6_device;
+struct ipu6_bus_device;
+
+#define IPU6_BUTTRESS_NUM_OF_SENS_CKS	3
+#define IPU6_BUTTRESS_NUM_OF_PLL_CKS	3
+
+#define BUTTRESS_PS_FREQ_STEP		25U
+#define BUTTRESS_MIN_FORCE_PS_FREQ	(BUTTRESS_PS_FREQ_STEP * 8)
+#define BUTTRESS_MAX_FORCE_PS_FREQ	(BUTTRESS_PS_FREQ_STEP * 32)
+
+#define BUTTRESS_IS_FREQ_STEP		25U
+#define BUTTRESS_MIN_FORCE_IS_FREQ	(BUTTRESS_IS_FREQ_STEP * 8)
+#define BUTTRESS_MAX_FORCE_IS_FREQ	(BUTTRESS_IS_FREQ_STEP * 16)
+
+struct ipu6_buttress_ctrl {
+	u32 freq_ctl, pwr_sts_shift, pwr_sts_mask, pwr_sts_on, pwr_sts_off;
+	unsigned int ratio;
+	unsigned int qos_floor;
+	bool started;
+};
+
+struct ipu6_buttress_fused_freqs {
+	unsigned int min_freq;
+	unsigned int max_freq;
+	unsigned int efficient_freq;
+};
+
+struct ipu6_buttress_ipc {
+	struct completion send_complete;
+	struct completion recv_complete;
+	u32 nack;
+	u32 nack_mask;
+	u32 recv_data;
+	u32 csr_out;
+	u32 csr_in;
+	u32 db0_in;
+	u32 db0_out;
+	u32 data0_out;
+	u32 data0_in;
+};
+
+struct ipu6_buttress {
+	struct mutex power_mutex, auth_mutex, cons_mutex, ipc_mutex;
+	struct ipu6_buttress_ipc cse;
+	struct ipu6_buttress_ipc ish;
+	struct list_head constraints;
+	u32 wdt_cached_value;
+	bool force_suspend;
+	u32 ref_clk;
+};
+
+struct ipu6_buttress_sensor_clk_freq {
+	unsigned int rate;
+	unsigned int val;
+};
+
+enum ipu6_buttress_ipc_domain {
+	IPU6_BUTTRESS_IPC_CSE,
+	IPU6_BUTTRESS_IPC_ISH,
+};
+
+struct ipu6_buttress_constraint {
+	struct list_head list;
+	unsigned int min_freq;
+};
+
+struct ipu6_ipc_buttress_bulk_msg {
+	u32 cmd;
+	u32 expected_resp;
+	bool require_resp;
+	u8 cmd_size;
+};
+
+int ipu6_buttress_ipc_reset(struct ipu6_device *isp,
+			    struct ipu6_buttress_ipc *ipc);
+int ipu6_buttress_map_fw_image(struct ipu6_bus_device *sys,
+			       const struct firmware *fw,
+			       struct sg_table *sgt);
+void ipu6_buttress_unmap_fw_image(struct ipu6_bus_device *sys,
+				  struct sg_table *sgt);
+int ipu6_buttress_power(struct device *dev, struct ipu6_buttress_ctrl *ctrl,
+			bool on);
+bool ipu6_buttress_get_secure_mode(struct ipu6_device *isp);
+int ipu6_buttress_authenticate(struct ipu6_device *isp);
+int ipu6_buttress_reset_authentication(struct ipu6_device *isp);
+bool ipu6_buttress_auth_done(struct ipu6_device *isp);
+int ipu6_buttress_start_tsc_sync(struct ipu6_device *isp);
+void ipu6_buttress_tsc_read(struct ipu6_device *isp, u64 *val);
+u64 ipu6_buttress_tsc_ticks_to_ns(u64 ticks, const struct ipu6_device *isp);
+
+irqreturn_t ipu6_buttress_isr(int irq, void *isp_ptr);
+irqreturn_t ipu6_buttress_isr_threaded(int irq, void *isp_ptr);
+int ipu6_buttress_init(struct ipu6_device *isp);
+void ipu6_buttress_exit(struct ipu6_device *isp);
+void ipu6_buttress_csi_port_config(struct ipu6_device *isp,
+				   u32 legacy, u32 combo);
+void ipu6_buttress_restore(struct ipu6_device *isp);
+#endif /* IPU6_BUTTRESS_H */
diff --git a/drivers/media/pci/intel/ipu6/ipu6-platform-buttress-regs.h b/drivers/media/pci/intel/ipu6/ipu6-platform-buttress-regs.h
new file mode 100644
index 000000000000..5d31951b7253
--- /dev/null
+++ b/drivers/media/pci/intel/ipu6/ipu6-platform-buttress-regs.h
@@ -0,0 +1,230 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/* Copyright (C) 2023 Intel Corporation */
+
+#ifndef IPU6_PLATFORM_BUTTRESS_REGS_H
+#define IPU6_PLATFORM_BUTTRESS_REGS_H
+
+/* IS_WORKPOINT_REQ */
+#define IPU6_BUTTRESS_REG_IS_FREQ_CTL		0x34
+/* PS_WORKPOINT_REQ */
+#define IPU6_BUTTRESS_REG_PS_FREQ_CTL		0x38
+
+#define IPU6_IS_FREQ_MAX		533
+#define IPU6_IS_FREQ_MIN		200
+#define IPU6_PS_FREQ_MAX		450
+#define IPU6_IS_FREQ_RATIO_BASE		25
+#define IPU6_PS_FREQ_RATIO_BASE		25
+
+/* should be tuned for real silicon */
+#define IPU6_IS_FREQ_CTL_DEFAULT_RATIO		0x08
+#define IPU6SE_IS_FREQ_CTL_DEFAULT_RATIO	0x0a
+#define IPU6_PS_FREQ_CTL_DEFAULT_RATIO		0x0d
+
+#define IPU6_IS_FREQ_CTL_DEFAULT_QOS_FLOOR_RATIO	0x10
+#define IPU6_PS_FREQ_CTL_DEFAULT_QOS_FLOOR_RATIO	0x0708
+
+#define IPU6_BUTTRESS_PWR_STATE_IS_PWR_SHIFT	3
+#define IPU6_BUTTRESS_PWR_STATE_IS_PWR_MASK	GENMASK(4, 3)
+
+#define IPU6_BUTTRESS_PWR_STATE_PS_PWR_SHIFT	6
+#define IPU6_BUTTRESS_PWR_STATE_PS_PWR_MASK	GENMASK(7, 6)
+
+#define IPU6_BUTTRESS_PWR_STATE_DN_DONE		0x0
+#define IPU6_BUTTRESS_PWR_STATE_UP_PROCESS	0x1
+#define IPU6_BUTTRESS_PWR_STATE_DN_PROCESS	0x2
+#define IPU6_BUTTRESS_PWR_STATE_UP_DONE		0x3
+
+#define IPU6_BUTTRESS_REG_FPGA_SUPPORT_0	0x270
+#define IPU6_BUTTRESS_REG_FPGA_SUPPORT_1	0x274
+#define IPU6_BUTTRESS_REG_FPGA_SUPPORT_2	0x278
+#define IPU6_BUTTRESS_REG_FPGA_SUPPORT_3	0x27c
+#define IPU6_BUTTRESS_REG_FPGA_SUPPORT_4	0x280
+#define IPU6_BUTTRESS_REG_FPGA_SUPPORT_5	0x284
+#define IPU6_BUTTRESS_REG_FPGA_SUPPORT_6	0x288
+#define IPU6_BUTTRESS_REG_FPGA_SUPPORT_7	0x28c
+
+#define BUTTRESS_REG_WDT			0x8
+#define BUTTRESS_REG_BTRS_CTRL			0xc
+#define BUTTRESS_REG_BTRS_CTRL_STALL_MODE_VC0	BIT(0)
+#define BUTTRESS_REG_BTRS_CTRL_STALL_MODE_VC1	BIT(1)
+#define BUTTRESS_REG_BTRS_CTRL_REF_CLK_IND	GENMASK(9, 8)
+
+#define BUTTRESS_REG_FW_RESET_CTL	0x30
+#define BUTTRESS_FW_RESET_CTL_START	BIT(0)
+#define BUTTRESS_FW_RESET_CTL_DONE	BIT(1)
+
+#define BUTTRESS_REG_IS_FREQ_CTL	0x34
+#define BUTTRESS_REG_PS_FREQ_CTL	0x38
+
+#define BUTTRESS_FREQ_CTL_START		BIT(31)
+#define BUTTRESS_FREQ_CTL_ICCMAX_LEVEL		GENMASK(19, 16)
+#define BUTTRESS_FREQ_CTL_QOS_FLOOR_MASK	GENMASK(15, 8)
+#define BUTTRESS_FREQ_CTL_RATIO_MASK	GENMASK(7, 0)
+
+#define BUTTRESS_REG_PWR_STATE	0x5c
+
+#define BUTTRESS_PWR_STATE_RESET		0x0
+#define BUTTRESS_PWR_STATE_PWR_ON_DONE		0x1
+#define BUTTRESS_PWR_STATE_PWR_RDY		0x3
+#define BUTTRESS_PWR_STATE_PWR_IDLE		0x4
+
+#define BUTTRESS_PWR_STATE_HH_STATUS_MASK	GENMASK(12, 11)
+
+enum {
+	BUTTRESS_PWR_STATE_HH_STATE_IDLE,
+	BUTTRESS_PWR_STATE_HH_STATE_IN_PRGS,
+	BUTTRESS_PWR_STATE_HH_STATE_DONE,
+	BUTTRESS_PWR_STATE_HH_STATE_ERR,
+};
+
+#define BUTTRESS_PWR_STATE_IS_PWR_FSM_MASK	GENMASK(23, 19)
+
+#define BUTTRESS_PWR_STATE_IS_PWR_FSM_IDLE			0x0
+#define BUTTRESS_PWR_STATE_IS_PWR_FSM_WAIT_4_PLL_CMP		0x1
+#define BUTTRESS_PWR_STATE_IS_PWR_FSM_WAIT_4_CLKACK		0x2
+#define BUTTRESS_PWR_STATE_IS_PWR_FSM_WAIT_4_PG_ACK		0x3
+#define BUTTRESS_PWR_STATE_IS_PWR_FSM_RST_ASSRT_CYCLES		0x4
+#define BUTTRESS_PWR_STATE_IS_PWR_FSM_STOP_CLK_CYCLES1		0x5
+#define BUTTRESS_PWR_STATE_IS_PWR_FSM_STOP_CLK_CYCLES2		0x6
+#define BUTTRESS_PWR_STATE_IS_PWR_FSM_RST_DEASSRT_CYCLES	0x7
+#define BUTTRESS_PWR_STATE_IS_PWR_FSM_WAIT_4_FUSE_WR_CMP	0x8
+#define BUTTRESS_PWR_STATE_IS_PWR_FSM_BRK_POINT			0x9
+#define BUTTRESS_PWR_STATE_IS_PWR_FSM_IS_RDY			0xa
+#define BUTTRESS_PWR_STATE_IS_PWR_FSM_HALT_HALTED		0xb
+#define BUTTRESS_PWR_STATE_IS_PWR_FSM_RST_DURATION_CNT3		0xc
+#define BUTTRESS_PWR_STATE_IS_PWR_FSM_WAIT_4_CLKACK_PD		0xd
+#define BUTTRESS_PWR_STATE_IS_PWR_FSM_PD_BRK_POINT		0xe
+#define BUTTRESS_PWR_STATE_IS_PWR_FSM_WAIT_4_PD_PG_ACK0		0xf
+
+#define BUTTRESS_PWR_STATE_PS_PWR_FSM_MASK	GENMASK(28, 24)
+
+#define BUTTRESS_PWR_STATE_PS_PWR_FSM_IDLE			0x0
+#define BUTTRESS_PWR_STATE_PS_PWR_FSM_WAIT_PU_PLL_IP_RDY	0x1
+#define BUTTRESS_PWR_STATE_PS_PWR_FSM_WAIT_RO_PRE_CNT_EXH	0x2
+#define BUTTRESS_PWR_STATE_PS_PWR_FSM_WAIT_PU_VGI_PWRGOOD	0x3
+#define BUTTRESS_PWR_STATE_PS_PWR_FSM_WAIT_RO_POST_CNT_EXH	0x4
+#define BUTTRESS_PWR_STATE_PS_PWR_FSM_WR_PLL_RATIO		0x5
+#define BUTTRESS_PWR_STATE_PS_PWR_FSM_WAIT_PU_PLL_CMP		0x6
+#define BUTTRESS_PWR_STATE_PS_PWR_FSM_WAIT_PU_CLKACK		0x7
+#define BUTTRESS_PWR_STATE_PS_PWR_FSM_RST_ASSRT_CYCLES		0x8
+#define BUTTRESS_PWR_STATE_PS_PWR_FSM_STOP_CLK_CYCLES1		0x9
+#define BUTTRESS_PWR_STATE_PS_PWR_FSM_STOP_CLK_CYCLES2		0xa
+#define BUTTRESS_PWR_STATE_PS_PWR_FSM_RST_DEASSRT_CYCLES	0xb
+#define BUTTRESS_PWR_STATE_PS_PWR_FSM_PU_BRK_PNT		0xc
+#define BUTTRESS_PWR_STATE_PS_PWR_FSM_WAIT_FUSE_ACCPT		0xd
+#define BUTTRESS_PWR_STATE_PS_PWR_FSM_PS_PWR_UP			0xf
+#define BUTTRESS_PWR_STATE_PS_PWR_FSM_WAIT_4_HALTED		0x10
+#define BUTTRESS_PWR_STATE_PS_PWR_FSM_RESET_CNT3		0x11
+#define BUTTRESS_PWR_STATE_PS_PWR_FSM_WAIT_PD_CLKACK		0x12
+#define BUTTRESS_PWR_STATE_PS_PWR_FSM_WAIT_PD_OFF_IND		0x13
+#define BUTTRESS_PWR_STATE_PS_PWR_FSM_WAIT_DVFS_PH4		0x14
+#define BUTTRESS_PWR_STATE_PS_PWR_FSM_WAIT_DVFS_PLL_CMP		0x15
+#define BUTTRESS_PWR_STATE_PS_PWR_FSM_WAIT_DVFS_CLKACK		0x16
+
+#define BUTTRESS_REG_SECURITY_CTL	0x300
+#define BUTTRESS_REG_SKU		0x314
+#define BUTTRESS_REG_SECURITY_TOUCH	0x318
+#define BUTTRESS_REG_CAMERA_MASK	0x84
+
+#define BUTTRESS_SECURITY_CTL_FW_SECURE_MODE	BIT(16)
+#define BUTTRESS_SECURITY_CTL_FW_SETUP_MASK	GENMASK(4, 0)
+
+#define BUTTRESS_SECURITY_CTL_FW_SETUP_DONE		BIT(0)
+#define BUTTRESS_SECURITY_CTL_AUTH_DONE			BIT(1)
+#define BUTTRESS_SECURITY_CTL_AUTH_FAILED		BIT(3)
+
+#define BUTTRESS_REG_FW_SOURCE_BASE_LO	0x78
+#define BUTTRESS_REG_FW_SOURCE_BASE_HI	0x7C
+#define BUTTRESS_REG_FW_SOURCE_SIZE	0x80
+
+#define BUTTRESS_REG_ISR_STATUS		0x90
+#define BUTTRESS_REG_ISR_ENABLED_STATUS	0x94
+#define BUTTRESS_REG_ISR_ENABLE		0x98
+#define BUTTRESS_REG_ISR_CLEAR		0x9C
+
+#define BUTTRESS_ISR_IS_IRQ			BIT(0)
+#define BUTTRESS_ISR_PS_IRQ			BIT(1)
+#define BUTTRESS_ISR_IPC_EXEC_DONE_BY_CSE	BIT(2)
+#define BUTTRESS_ISR_IPC_EXEC_DONE_BY_ISH	BIT(3)
+#define BUTTRESS_ISR_IPC_FROM_CSE_IS_WAITING	BIT(4)
+#define BUTTRESS_ISR_IPC_FROM_ISH_IS_WAITING	BIT(5)
+#define BUTTRESS_ISR_CSE_CSR_SET		BIT(6)
+#define BUTTRESS_ISR_ISH_CSR_SET		BIT(7)
+#define BUTTRESS_ISR_SPURIOUS_CMP		BIT(8)
+#define BUTTRESS_ISR_WATCHDOG_EXPIRED		BIT(9)
+#define BUTTRESS_ISR_PUNIT_2_IUNIT_IRQ		BIT(10)
+#define BUTTRESS_ISR_SAI_VIOLATION		BIT(11)
+#define BUTTRESS_ISR_HW_ASSERTION		BIT(12)
+#define BUTTRESS_ISR_IS_CORRECTABLE_MEM_ERR	BIT(13)
+#define BUTTRESS_ISR_IS_FATAL_MEM_ERR		BIT(14)
+#define BUTTRESS_ISR_IS_NON_FATAL_MEM_ERR	BIT(15)
+#define BUTTRESS_ISR_PS_CORRECTABLE_MEM_ERR	BIT(16)
+#define BUTTRESS_ISR_PS_FATAL_MEM_ERR		BIT(17)
+#define BUTTRESS_ISR_PS_NON_FATAL_MEM_ERR	BIT(18)
+#define BUTTRESS_ISR_PS_FAST_THROTTLE		BIT(19)
+#define BUTTRESS_ISR_UFI_ERROR			BIT(20)
+
+#define BUTTRESS_REG_IU2CSEDB0	0x100
+
+#define BUTTRESS_IU2CSEDB0_BUSY		BIT(31)
+#define BUTTRESS_IU2CSEDB0_IPC_CLIENT_ID_VAL	2
+
+#define BUTTRESS_REG_IU2CSEDATA0	0x104
+
+#define BUTTRESS_IU2CSEDATA0_IPC_BOOT_LOAD		1
+#define BUTTRESS_IU2CSEDATA0_IPC_AUTH_RUN		2
+#define BUTTRESS_IU2CSEDATA0_IPC_AUTH_REPLACE		3
+#define BUTTRESS_IU2CSEDATA0_IPC_UPDATE_SECURE_TOUCH	16
+
+#define BUTTRESS_CSE2IUDATA0_IPC_BOOT_LOAD_DONE			BIT(0)
+#define BUTTRESS_CSE2IUDATA0_IPC_AUTH_RUN_DONE			BIT(1)
+#define BUTTRESS_CSE2IUDATA0_IPC_AUTH_REPLACE_DONE		BIT(2)
+#define BUTTRESS_CSE2IUDATA0_IPC_UPDATE_SECURE_TOUCH_DONE	BIT(4)
+
+#define BUTTRESS_REG_IU2CSECSR		0x108
+
+#define BUTTRESS_IU2CSECSR_IPC_PEER_COMP_ACTIONS_RST_PHASE1		BIT(0)
+#define BUTTRESS_IU2CSECSR_IPC_PEER_COMP_ACTIONS_RST_PHASE2		BIT(1)
+#define BUTTRESS_IU2CSECSR_IPC_PEER_QUERIED_IP_COMP_ACTIONS_RST_PHASE	BIT(2)
+#define BUTTRESS_IU2CSECSR_IPC_PEER_ASSERTED_REG_VALID_REQ		BIT(3)
+#define BUTTRESS_IU2CSECSR_IPC_PEER_ACKED_REG_VALID			BIT(4)
+#define BUTTRESS_IU2CSECSR_IPC_PEER_DEASSERTED_REG_VALID_REQ		BIT(5)
+
+#define BUTTRESS_REG_CSE2IUDB0		0x304
+#define BUTTRESS_REG_CSE2IUCSR		0x30C
+#define BUTTRESS_REG_CSE2IUDATA0	0x308
+
+/* 0x20 == NACK, 0xf == unknown command */
+#define BUTTRESS_CSE2IUDATA0_IPC_NACK      0xf20
+#define BUTTRESS_CSE2IUDATA0_IPC_NACK_MASK GENMASK(15, 0)
+
+#define BUTTRESS_REG_ISH2IUCSR		0x50
+#define BUTTRESS_REG_ISH2IUDB0		0x54
+#define BUTTRESS_REG_ISH2IUDATA0	0x58
+
+#define BUTTRESS_REG_IU2ISHDB0		0x10C
+#define BUTTRESS_REG_IU2ISHDATA0	0x110
+#define BUTTRESS_REG_IU2ISHDATA1	0x114
+#define BUTTRESS_REG_IU2ISHCSR		0x118
+
+#define BUTTRESS_REG_FABRIC_CMD		0x88
+
+#define BUTTRESS_FABRIC_CMD_START_TSC_SYNC	BIT(0)
+#define BUTTRESS_FABRIC_CMD_IS_DRAIN		BIT(4)
+
+#define BUTTRESS_REG_TSW_CTL		0x120
+#define BUTTRESS_TSW_CTL_SOFT_RESET	BIT(8)
+
+#define BUTTRESS_REG_TSC_LO	0x164
+#define BUTTRESS_REG_TSC_HI	0x168
+
+#define BUTTRESS_IRQS		(BUTTRESS_ISR_IPC_FROM_CSE_IS_WAITING | \
+				 BUTTRESS_ISR_IPC_EXEC_DONE_BY_CSE |    \
+				 BUTTRESS_ISR_IS_IRQ | BUTTRESS_ISR_PS_IRQ)
+
+#define BUTTRESS_EVENT		 (BUTTRESS_ISR_IPC_FROM_CSE_IS_WAITING | \
+				  BUTTRESS_ISR_IPC_FROM_ISH_IS_WAITING | \
+				  BUTTRESS_ISR_IPC_EXEC_DONE_BY_CSE |    \
+				  BUTTRESS_ISR_IPC_EXEC_DONE_BY_ISH |    \
+				  BUTTRESS_ISR_SAI_VIOLATION)
+#endif /* IPU6_PLATFORM_BUTTRESS_REGS_H */
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 86+ messages in thread

* [PATCH v2 04/15] media: intel/ipu6: CPD parsing for get firmware components
  2023-10-24 11:29 [PATCH v2 00/15] Intel IPU6 and IPU6 input system drivers bingbu.cao
                   ` (2 preceding siblings ...)
  2023-10-24 11:29 ` [PATCH v2 03/15] media: intel/ipu6: add IPU6 buttress interface driver bingbu.cao
@ 2023-10-24 11:29 ` bingbu.cao
  2023-10-24 11:29 ` [PATCH v2 05/15] media: intel/ipu6: add IPU6 DMA mapping API and MMU table bingbu.cao
                   ` (12 subsequent siblings)
  16 siblings, 0 replies; 86+ messages in thread
From: bingbu.cao @ 2023-10-24 11:29 UTC (permalink / raw)
  To: linux-media, sakari.ailus, laurent.pinchart
  Cc: andriy.shevchenko, hdegoede, ilpo.jarvinen, andreaskleist,
	claus.stovgaard, tfiga, senozhatsky, tomi.valkeinen, bingbu.cao,
	bingbu.cao, tian.shu.qiu, hongju.wang

From: Bingbu Cao <bingbu.cao@intel.com>

For IPU6, firmware is generated and released as signed
Code Partition Directory (CPD) format file, which is aligned with
the SPI flash code partition definition. CPD format include CPD
header, manifest, metadata and module data. Driver can parse them
according to the CPD layout to acquire each component.

Signed-off-by: Bingbu Cao <bingbu.cao@intel.com>
---
 drivers/media/pci/intel/ipu6/ipu6-cpd.c | 355 ++++++++++++++++++++++++
 drivers/media/pci/intel/ipu6/ipu6-cpd.h | 104 +++++++
 2 files changed, 459 insertions(+)
 create mode 100644 drivers/media/pci/intel/ipu6/ipu6-cpd.c
 create mode 100644 drivers/media/pci/intel/ipu6/ipu6-cpd.h

diff --git a/drivers/media/pci/intel/ipu6/ipu6-cpd.c b/drivers/media/pci/intel/ipu6/ipu6-cpd.c
new file mode 100644
index 000000000000..7dc78a624095
--- /dev/null
+++ b/drivers/media/pci/intel/ipu6/ipu6-cpd.c
@@ -0,0 +1,355 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2013 - 2023 Intel Corporation
+ */
+
+#include <linux/bitfield.h>
+
+#include "ipu6.h"
+#include "ipu6-bus.h"
+#include "ipu6-cpd.h"
+
+/* 15 entries + header*/
+#define MAX_PKG_DIR_ENT_CNT		16
+/* 2 qword per entry/header */
+#define PKG_DIR_ENT_LEN			2
+/* PKG_DIR size in bytes */
+#define PKG_DIR_SIZE			((MAX_PKG_DIR_ENT_CNT) *	\
+					 (PKG_DIR_ENT_LEN) * sizeof(u64))
+/* _IUPKDR_ */
+#define PKG_DIR_HDR_MARK		0x5f4955504b44525fULL
+
+/* $CPD */
+#define CPD_HDR_MARK			0x44504324
+
+#define MAX_MANIFEST_SIZE		(SZ_2K * sizeof(u32))
+#define MAX_METADATA_SIZE		SZ_64K
+
+#define MAX_COMPONENT_ID		127
+#define MAX_COMPONENT_VERSION		0xffff
+
+#define MANIFEST_IDX	0
+#define METADATA_IDX	1
+#define MODULEDATA_IDX	2
+/*
+ * PKG_DIR Entry (type == id)
+ * 63:56        55      54:48   47:32   31:24   23:0
+ * Rsvd         Rsvd    Type    Version Rsvd    Size
+ */
+#define PKG_DIR_SIZE_MASK	GENMASK(23, 0)
+#define PKG_DIR_VERSION_MASK	GENMASK(47, 32)
+#define PKG_DIR_TYPE_MASK	GENMASK(54, 48)
+
+static inline const struct ipu6_cpd_ent *ipu6_cpd_get_entry(const void *cpd,
+							    u8 idx)
+{
+	const struct ipu6_cpd_hdr *cpd_hdr = cpd;
+	const struct ipu6_cpd_ent *ent;
+
+	ent = (const struct ipu6_cpd_ent *)((const u8 *)cpd + cpd_hdr->hdr_len);
+	return ent + idx;
+}
+
+#define ipu6_cpd_get_manifest(cpd) ipu6_cpd_get_entry(cpd, MANIFEST_IDX)
+#define ipu6_cpd_get_metadata(cpd) ipu6_cpd_get_entry(cpd, METADATA_IDX)
+#define ipu6_cpd_get_moduledata(cpd) ipu6_cpd_get_entry(cpd, MODULEDATA_IDX)
+
+static const struct ipu6_cpd_metadata_cmpnt_hdr *
+ipu6_cpd_metadata_get_cmpnt(struct ipu6_device *isp, const void *metadata,
+			    unsigned int metadata_size, u8 idx)
+{
+	size_t extn_size = sizeof(struct ipu6_cpd_metadata_extn);
+	size_t cmpnt_count = metadata_size - extn_size;
+
+	cmpnt_count = div_u64(cmpnt_count, isp->cpd_metadata_cmpnt_size);
+
+	if (idx > MAX_COMPONENT_ID || idx >= cmpnt_count) {
+		dev_err(&isp->pdev->dev, "Component index out of range (%d)\n",
+			idx);
+		return ERR_PTR(-EINVAL);
+	}
+
+	return metadata + extn_size + idx * isp->cpd_metadata_cmpnt_size;
+}
+
+static u32 ipu6_cpd_metadata_cmpnt_version(struct ipu6_device *isp,
+					   const void *metadata,
+					   unsigned int metadata_size, u8 idx)
+{
+	const struct ipu6_cpd_metadata_cmpnt_hdr *cmpnt;
+
+	cmpnt = ipu6_cpd_metadata_get_cmpnt(isp, metadata, metadata_size, idx);
+	if (IS_ERR(cmpnt))
+		return PTR_ERR(cmpnt);
+
+	return cmpnt->ver;
+}
+
+static int ipu6_cpd_metadata_get_cmpnt_id(struct ipu6_device *isp,
+					  const void *metadata,
+					  unsigned int metadata_size, u8 idx)
+{
+	const struct ipu6_cpd_metadata_cmpnt_hdr *cmpnt;
+
+	cmpnt = ipu6_cpd_metadata_get_cmpnt(isp, metadata, metadata_size, idx);
+	if (IS_ERR(cmpnt))
+		return PTR_ERR(cmpnt);
+
+	return cmpnt->id;
+}
+
+static int ipu6_cpd_parse_module_data(struct ipu6_device *isp,
+				      const void *module_data,
+				      unsigned int module_data_size,
+				      dma_addr_t dma_addr_module_data,
+				      u64 *pkg_dir, const void *metadata,
+				      unsigned int metadata_size)
+{
+	const struct ipu6_cpd_module_data_hdr *module_data_hdr;
+	const struct ipu6_cpd_hdr *dir_hdr;
+	const struct ipu6_cpd_ent *dir_ent;
+	unsigned int i;
+	u8 len;
+
+	if (!module_data)
+		return -EINVAL;
+
+	module_data_hdr = module_data;
+	dir_hdr = module_data + module_data_hdr->hdr_len;
+	len = dir_hdr->hdr_len;
+	dir_ent = (const struct ipu6_cpd_ent *)(((u8 *)dir_hdr) + len);
+
+	pkg_dir[0] = PKG_DIR_HDR_MARK;
+	/* pkg_dir entry count = component count + pkg_dir header */
+	pkg_dir[1] = dir_hdr->ent_cnt + 1;
+
+	for (i = 0; i < dir_hdr->ent_cnt; i++, dir_ent++) {
+		u64 *p = &pkg_dir[PKG_DIR_ENT_LEN *  (1 + i)];
+		int ver, id;
+
+		*p++ = dma_addr_module_data + dir_ent->offset;
+		id = ipu6_cpd_metadata_get_cmpnt_id(isp, metadata,
+						    metadata_size, i);
+		if (id < 0 || id > MAX_COMPONENT_ID) {
+			dev_err(&isp->pdev->dev, "Invalid CPD component id\n");
+			return -EINVAL;
+		}
+
+		ver = ipu6_cpd_metadata_cmpnt_version(isp, metadata,
+						      metadata_size, i);
+		if (ver < 0 || ver > MAX_COMPONENT_VERSION) {
+			dev_err(&isp->pdev->dev,
+				"Invalid CPD component version\n");
+			return -EINVAL;
+		}
+
+		*p = FIELD_PREP(PKG_DIR_SIZE_MASK, dir_ent->len) |
+			FIELD_PREP(PKG_DIR_TYPE_MASK, id) |
+			FIELD_PREP(PKG_DIR_VERSION_MASK, ver);
+	}
+
+	return 0;
+}
+
+int ipu6_cpd_create_pkg_dir(struct ipu6_bus_device *adev, const void *src)
+{
+	dma_addr_t dma_addr_src = sg_dma_address(adev->fw_sgt.sgl);
+	const struct ipu6_cpd_ent *ent, *man_ent, *met_ent;
+	struct device *dev = &adev->auxdev.dev;
+	struct ipu6_device *isp = adev->isp;
+	unsigned int man_sz, met_sz;
+	void *pkg_dir_pos;
+	int ret;
+
+	man_ent = ipu6_cpd_get_manifest(src);
+	man_sz = man_ent->len;
+
+	met_ent = ipu6_cpd_get_metadata(src);
+	met_sz = met_ent->len;
+
+	adev->pkg_dir_size = PKG_DIR_SIZE + man_sz + met_sz;
+	adev->pkg_dir = dma_alloc_attrs(dev, adev->pkg_dir_size,
+					&adev->pkg_dir_dma_addr, GFP_KERNEL, 0);
+	if (!adev->pkg_dir)
+		return -ENOMEM;
+
+	/*
+	 * pkg_dir entry/header:
+	 * qword | 63:56 | 55   | 54:48 | 47:32 | 31:24 | 23:0
+	 * N         Address/Offset/"_IUPKDR_"
+	 * N + 1 | rsvd  | rsvd | type  | ver   | rsvd  | size
+	 *
+	 * We can ignore other fields that size in N + 1 qword as they
+	 * are 0 anyway. Just setting size for now.
+	 */
+
+	ent = ipu6_cpd_get_moduledata(src);
+
+	ret = ipu6_cpd_parse_module_data(isp, src + ent->offset,
+					 ent->len, dma_addr_src + ent->offset,
+					 adev->pkg_dir, src + met_ent->offset,
+					 met_ent->len);
+	if (ret) {
+		dev_err(&isp->pdev->dev, "Failed to parse module data\n");
+		dma_free_attrs(dev, adev->pkg_dir_size,
+			       adev->pkg_dir, adev->pkg_dir_dma_addr, 0);
+		return ret;
+	}
+
+	/* Copy manifest after pkg_dir */
+	pkg_dir_pos = adev->pkg_dir + PKG_DIR_ENT_LEN * MAX_PKG_DIR_ENT_CNT;
+	memcpy(pkg_dir_pos, src + man_ent->offset, man_sz);
+
+	/* Copy metadata after manifest */
+	pkg_dir_pos += man_sz;
+	memcpy(pkg_dir_pos, src + met_ent->offset, met_sz);
+
+	dma_sync_single_range_for_device(dev, adev->pkg_dir_dma_addr,
+					 0, adev->pkg_dir_size, DMA_TO_DEVICE);
+
+	return 0;
+}
+EXPORT_SYMBOL_NS_GPL(ipu6_cpd_create_pkg_dir, INTEL_IPU6);
+
+void ipu6_cpd_free_pkg_dir(struct ipu6_bus_device *adev)
+{
+	dma_free_attrs(&adev->auxdev.dev, adev->pkg_dir_size, adev->pkg_dir,
+		       adev->pkg_dir_dma_addr, 0);
+}
+EXPORT_SYMBOL_NS_GPL(ipu6_cpd_free_pkg_dir, INTEL_IPU6);
+
+static int ipu6_cpd_validate_cpd(struct ipu6_device *isp, const void *cpd,
+				 unsigned long cpd_size,
+				 unsigned long data_size)
+{
+	const struct ipu6_cpd_hdr *cpd_hdr = cpd;
+	const struct ipu6_cpd_ent *ent;
+	unsigned int i;
+	u8 len;
+
+	len = cpd_hdr->hdr_len;
+
+	/* Ensure cpd hdr is within moduledata */
+	if (cpd_size < len) {
+		dev_err(&isp->pdev->dev, "Invalid CPD moduledata size\n");
+		return -EINVAL;
+	}
+
+	/* Sanity check for CPD header */
+	if ((cpd_size - len) / sizeof(*ent) < cpd_hdr->ent_cnt) {
+		dev_err(&isp->pdev->dev, "Invalid CPD header\n");
+		return -EINVAL;
+	}
+
+	/* Ensure that all entries are within moduledata */
+	ent = (const struct ipu6_cpd_ent *)(((const u8 *)cpd_hdr) + len);
+	for (i = 0; i < cpd_hdr->ent_cnt; i++, ent++) {
+		if (data_size < ent->offset ||
+		    data_size - ent->offset < ent->len) {
+			dev_err(&isp->pdev->dev, "Invalid CPD entry (%d)\n", i);
+			return -EINVAL;
+		}
+	}
+
+	return 0;
+}
+
+static int ipu6_cpd_validate_moduledata(struct ipu6_device *isp,
+					const void *moduledata,
+					u32 moduledata_size)
+{
+	const struct ipu6_cpd_module_data_hdr *mod_hdr = moduledata;
+	int ret;
+
+	/* Ensure moduledata hdr is within moduledata */
+	if (moduledata_size < sizeof(*mod_hdr) ||
+	    moduledata_size < mod_hdr->hdr_len) {
+		dev_err(&isp->pdev->dev, "Invalid CPD moduledata size\n");
+		return -EINVAL;
+	}
+
+	dev_info(&isp->pdev->dev, "FW version: %x\n", mod_hdr->fw_pkg_date);
+	ret = ipu6_cpd_validate_cpd(isp, moduledata + mod_hdr->hdr_len,
+				    moduledata_size - mod_hdr->hdr_len,
+				    moduledata_size);
+	if (ret) {
+		dev_err(&isp->pdev->dev, "Invalid CPD in moduledata\n");
+		return ret;
+	}
+
+	return 0;
+}
+
+static int ipu6_cpd_validate_metadata(struct ipu6_device *isp,
+				      const void *metadata, u32 meta_size)
+{
+	const struct ipu6_cpd_metadata_extn *extn = metadata;
+
+	/* Sanity check for metadata size */
+	if (meta_size < sizeof(*extn) || meta_size > MAX_METADATA_SIZE) {
+		dev_err(&isp->pdev->dev, "Invalid CPD metadata\n");
+		return -EINVAL;
+	}
+
+	/* Validate extension and image types */
+	if (extn->extn_type != IPU6_CPD_METADATA_EXTN_TYPE_IUNIT ||
+	    extn->img_type != IPU6_CPD_METADATA_IMAGE_TYPE_MAIN_FIRMWARE) {
+		dev_err(&isp->pdev->dev,
+			"Invalid CPD metadata descriptor img_type (%d)\n",
+			extn->img_type);
+		return -EINVAL;
+	}
+
+	/* Validate metadata size multiple of metadata components */
+	if ((meta_size - sizeof(*extn)) % isp->cpd_metadata_cmpnt_size) {
+		dev_err(&isp->pdev->dev, "Invalid CPD metadata size\n");
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+int ipu6_cpd_validate_cpd_file(struct ipu6_device *isp, const void *cpd_file,
+			       unsigned long cpd_file_size)
+{
+	const struct ipu6_cpd_hdr *hdr = cpd_file;
+	const struct ipu6_cpd_ent *ent;
+	int ret;
+
+	ret = ipu6_cpd_validate_cpd(isp, cpd_file, cpd_file_size,
+				    cpd_file_size);
+	if (ret) {
+		dev_err(&isp->pdev->dev, "Invalid CPD in file\n");
+		return ret;
+	}
+
+	/* Check for CPD file marker */
+	if (hdr->hdr_mark != CPD_HDR_MARK) {
+		dev_err(&isp->pdev->dev, "Invalid CPD header\n");
+		return -EINVAL;
+	}
+
+	/* Sanity check for manifest size */
+	ent = ipu6_cpd_get_manifest(cpd_file);
+	if (ent->len > MAX_MANIFEST_SIZE) {
+		dev_err(&isp->pdev->dev, "Invalid CPD manifest size\n");
+		return -EINVAL;
+	}
+
+	/* Validate metadata */
+	ent = ipu6_cpd_get_metadata(cpd_file);
+	ret = ipu6_cpd_validate_metadata(isp, cpd_file + ent->offset, ent->len);
+	if (ret) {
+		dev_err(&isp->pdev->dev, "Invalid CPD metadata\n");
+		return ret;
+	}
+
+	/* Validate moduledata */
+	ent = ipu6_cpd_get_moduledata(cpd_file);
+	ret = ipu6_cpd_validate_moduledata(isp, cpd_file + ent->offset,
+					   ent->len);
+	if (ret)
+		dev_err(&isp->pdev->dev, "Invalid CPD moduledata\n");
+
+	return ret;
+}
diff --git a/drivers/media/pci/intel/ipu6/ipu6-cpd.h b/drivers/media/pci/intel/ipu6/ipu6-cpd.h
new file mode 100644
index 000000000000..0b606b5b3336
--- /dev/null
+++ b/drivers/media/pci/intel/ipu6/ipu6-cpd.h
@@ -0,0 +1,104 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/* Copyright (C) 2015 - 2023 Intel Corporation */
+
+#ifndef IPU6_CPD_H
+#define IPU6_CPD_H
+
+#include "ipu6-bus.h"
+
+#define IPU6_CPD_SIZE_OF_FW_ARCH_VERSION	7
+#define IPU6_CPD_SIZE_OF_SYSTEM_VERSION		11
+#define IPU6_CPD_SIZE_OF_COMPONENT_NAME		12
+
+#define IPU6_CPD_METADATA_EXTN_TYPE_IUNIT	0x10
+
+#define IPU6_CPD_METADATA_IMAGE_TYPE_RESERVED		0
+#define IPU6_CPD_METADATA_IMAGE_TYPE_BOOTLOADER		1
+#define IPU6_CPD_METADATA_IMAGE_TYPE_MAIN_FIRMWARE	2
+
+#define IPU6_CPD_PKG_DIR_PSYS_SERVER_IDX	0
+#define IPU6_CPD_PKG_DIR_ISYS_SERVER_IDX	1
+
+#define IPU6_CPD_PKG_DIR_CLIENT_PG_TYPE		3
+
+#define IPU6_CPD_METADATA_HASH_KEY_SIZE		48
+#define IPU6SE_CPD_METADATA_HASH_KEY_SIZE	32
+
+struct ipu6_cpd_module_data_hdr {
+	u32 hdr_len;
+	u32 endian;
+	u32 fw_pkg_date;
+	u32 hive_sdk_date;
+	u32 compiler_date;
+	u32 target_platform_type;
+	u8 sys_ver[IPU6_CPD_SIZE_OF_SYSTEM_VERSION];
+	u8 fw_arch_ver[IPU6_CPD_SIZE_OF_FW_ARCH_VERSION];
+	u8 rsvd[2];
+} __packed;
+
+/*
+ * ipu6_cpd_hdr structure updated as the chksum and
+ * sub_partition_name is unused on host side
+ * CSE layout version 1.6 for IPU6SE (hdr_len = 0x10)
+ * CSE layout version 1.7 for IPU6 (hdr_len = 0x14)
+ */
+struct ipu6_cpd_hdr {
+	u32 hdr_mark;
+	u32 ent_cnt;
+	u8 hdr_ver;
+	u8 ent_ver;
+	u8 hdr_len;
+} __packed;
+
+struct ipu6_cpd_ent {
+	u8 name[IPU6_CPD_SIZE_OF_COMPONENT_NAME];
+	u32 offset;
+	u32 len;
+	u8 rsvd[4];
+} __packed;
+
+struct ipu6_cpd_metadata_cmpnt_hdr {
+	u32 id;
+	u32 size;
+	u32 ver;
+} __packed;
+
+struct ipu6_cpd_metadata_cmpnt {
+	struct ipu6_cpd_metadata_cmpnt_hdr hdr;
+	u8 sha2_hash[IPU6_CPD_METADATA_HASH_KEY_SIZE];
+	u32 entry_point;
+	u32 icache_base_offs;
+	u8 attrs[16];
+} __packed;
+
+struct ipu6se_cpd_metadata_cmpnt {
+	struct ipu6_cpd_metadata_cmpnt_hdr hdr;
+	u8 sha2_hash[IPU6SE_CPD_METADATA_HASH_KEY_SIZE];
+	u32 entry_point;
+	u32 icache_base_offs;
+	u8 attrs[16];
+} __packed;
+
+struct ipu6_cpd_metadata_extn {
+	u32 extn_type;
+	u32 len;
+	u32 img_type;
+	u8 rsvd[16];
+} __packed;
+
+struct ipu6_cpd_client_pkg_hdr {
+	u32 prog_list_offs;
+	u32 prog_list_size;
+	u32 prog_desc_offs;
+	u32 prog_desc_size;
+	u32 pg_manifest_offs;
+	u32 pg_manifest_size;
+	u32 prog_bin_offs;
+	u32 prog_bin_size;
+} __packed;
+
+int ipu6_cpd_create_pkg_dir(struct ipu6_bus_device *adev, const void *src);
+void ipu6_cpd_free_pkg_dir(struct ipu6_bus_device *adev);
+int ipu6_cpd_validate_cpd_file(struct ipu6_device *isp, const void *cpd_file,
+			       unsigned long cpd_file_size);
+#endif /* IPU6_CPD_H */
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 86+ messages in thread

* [PATCH v2 05/15] media: intel/ipu6: add IPU6 DMA mapping API and MMU table
  2023-10-24 11:29 [PATCH v2 00/15] Intel IPU6 and IPU6 input system drivers bingbu.cao
                   ` (3 preceding siblings ...)
  2023-10-24 11:29 ` [PATCH v2 04/15] media: intel/ipu6: CPD parsing for get firmware components bingbu.cao
@ 2023-10-24 11:29 ` bingbu.cao
  2023-12-06 14:53   ` Andreas Helbech Kleist
  2023-10-24 11:29 ` [PATCH v2 06/15] media: intel/ipu6: add syscom interfaces between firmware and driver bingbu.cao
                   ` (11 subsequent siblings)
  16 siblings, 1 reply; 86+ messages in thread
From: bingbu.cao @ 2023-10-24 11:29 UTC (permalink / raw)
  To: linux-media, sakari.ailus, laurent.pinchart
  Cc: andriy.shevchenko, hdegoede, ilpo.jarvinen, andreaskleist,
	claus.stovgaard, tfiga, senozhatsky, tomi.valkeinen, bingbu.cao,
	bingbu.cao, tian.shu.qiu, hongju.wang

From: Bingbu Cao <bingbu.cao@intel.com>

he Intel IPU6 has an internal microcontroller (scalar processor, SP) which
is used to execute the firmware. The SP can access IPU internal memory and
map system DRAM to its an internal 32-bit virtual address space.

This patch adds a driver for the IPU MMU and a DMA mapping implementation
using the internal MMU. The system IOMMU may be used besides the IPU MMU.

Signed-off-by: Bingbu Cao <bingbu.cao@intel.com>
---
 drivers/media/pci/intel/ipu6/ipu6-dma.c | 491 ++++++++++++++
 drivers/media/pci/intel/ipu6/ipu6-dma.h |  20 +
 drivers/media/pci/intel/ipu6/ipu6-mmu.c | 828 ++++++++++++++++++++++++
 drivers/media/pci/intel/ipu6/ipu6-mmu.h |  67 ++
 4 files changed, 1406 insertions(+)
 create mode 100644 drivers/media/pci/intel/ipu6/ipu6-dma.c
 create mode 100644 drivers/media/pci/intel/ipu6/ipu6-dma.h
 create mode 100644 drivers/media/pci/intel/ipu6/ipu6-mmu.c
 create mode 100644 drivers/media/pci/intel/ipu6/ipu6-mmu.h

diff --git a/drivers/media/pci/intel/ipu6/ipu6-dma.c b/drivers/media/pci/intel/ipu6/ipu6-dma.c
new file mode 100644
index 000000000000..7dcf961a9f7d
--- /dev/null
+++ b/drivers/media/pci/intel/ipu6/ipu6-dma.c
@@ -0,0 +1,491 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2013 - 2023 Intel Corporation
+ */
+
+#include <linux/cacheflush.h>
+#include <linux/vmalloc.h>
+
+#include "ipu6.h"
+#include "ipu6-bus.h"
+#include "ipu6-dma.h"
+#include "ipu6-mmu.h"
+
+struct vm_info {
+	struct list_head list;
+	struct page **pages;
+	dma_addr_t ipu6_iova;
+	void *vaddr;
+	unsigned long size;
+};
+
+static struct vm_info *get_vm_info(struct ipu6_mmu *mmu, dma_addr_t iova)
+{
+	struct vm_info *info, *save;
+
+	list_for_each_entry_safe(info, save, &mmu->vma_list, list) {
+		if (iova >= info->ipu6_iova &&
+		    iova < (info->ipu6_iova + info->size))
+			return info;
+	}
+
+	return NULL;
+}
+
+static void __dma_clear_buffer(struct page *page, size_t size,
+			       unsigned long attrs)
+{
+	void *ptr;
+
+	if (!page)
+		return;
+	/*
+	 * Ensure that the allocated pages are zeroed, and that any data
+	 * lurking in the kernel direct-mapped region is invalidated.
+	 */
+	ptr = page_address(page);
+	memset(ptr, 0, size);
+	if ((attrs & DMA_ATTR_SKIP_CPU_SYNC) == 0)
+		clflush_cache_range(ptr, size);
+}
+
+static struct page **__dma_alloc_buffer(struct device *dev, size_t size,
+					gfp_t gfp, unsigned long attrs)
+{
+	int count = PHYS_PFN(size);
+	int array_size = count * sizeof(struct page *);
+	struct page **pages;
+	int i = 0;
+
+	pages = kvzalloc(array_size, GFP_KERNEL);
+	if (!pages)
+		return NULL;
+
+	gfp |= __GFP_NOWARN;
+
+	while (count) {
+		int j, order = __fls(count);
+
+		pages[i] = alloc_pages(gfp, order);
+		while (!pages[i] && order)
+			pages[i] = alloc_pages(gfp, --order);
+		if (!pages[i])
+			goto error;
+
+		if (order) {
+			split_page(pages[i], order);
+			j = 1 << order;
+			while (j--)
+				pages[i + j] = pages[i] + j;
+		}
+
+		__dma_clear_buffer(pages[i], PAGE_SIZE << order, attrs);
+		i += 1 << order;
+		count -= 1 << order;
+	}
+
+	return pages;
+error:
+	while (i--)
+		if (pages[i])
+			__free_pages(pages[i], 0);
+	kvfree(pages);
+	return NULL;
+}
+
+static void __dma_free_buffer(struct device *dev, struct page **pages,
+			      size_t size, unsigned long attrs)
+{
+	int count = PHYS_PFN(size);
+	unsigned int i;
+
+	for (i = 0; i < count && pages[i]; i++) {
+		__dma_clear_buffer(pages[i], PAGE_SIZE, attrs);
+		__free_pages(pages[i], 0);
+	}
+
+	kvfree(pages);
+}
+
+static void ipu6_dma_sync_single_for_cpu(struct device *dev,
+					 dma_addr_t dma_handle,
+					 size_t size,
+					 enum dma_data_direction dir)
+{
+	void *vaddr;
+	u32 offset;
+	struct vm_info *info;
+	struct ipu6_mmu *mmu = to_ipu6_bus_device(dev)->mmu;
+
+	info = get_vm_info(mmu, dma_handle);
+	if (WARN_ON(!info))
+		return;
+
+	offset = dma_handle - info->ipu6_iova;
+	if (WARN_ON(size > (info->size - offset)))
+		return;
+
+	vaddr = info->vaddr + offset;
+	clflush_cache_range(vaddr, size);
+}
+
+static void ipu6_dma_sync_sg_for_cpu(struct device *dev,
+				     struct scatterlist *sglist,
+				     int nents, enum dma_data_direction dir)
+{
+	struct scatterlist *sg;
+	int i;
+
+	for_each_sg(sglist, sg, nents, i)
+		clflush_cache_range(page_to_virt(sg_page(sg)), sg->length);
+}
+
+static void *ipu6_dma_alloc(struct device *dev, size_t size,
+			    dma_addr_t *dma_handle, gfp_t gfp,
+			    unsigned long attrs)
+{
+	struct ipu6_mmu *mmu = to_ipu6_bus_device(dev)->mmu;
+	struct pci_dev *pdev = to_ipu6_bus_device(dev)->isp->pdev;
+	dma_addr_t pci_dma_addr, ipu6_iova;
+	struct vm_info *info;
+	unsigned long count;
+	struct page **pages;
+	struct iova *iova;
+	unsigned int i;
+	int ret;
+
+	info = kzalloc(sizeof(*info), GFP_KERNEL);
+	if (!info)
+		return NULL;
+
+	size = PAGE_ALIGN(size);
+	count = PHYS_PFN(size);
+
+	iova = alloc_iova(&mmu->dmap->iovad, count,
+			  PHYS_PFN(dma_get_mask(dev)), 0);
+	if (!iova)
+		goto out_kfree;
+
+	pages = __dma_alloc_buffer(dev, size, gfp, attrs);
+	if (!pages)
+		goto out_free_iova;
+
+	dev_dbg(dev, "dma_alloc: size %zu iova low pfn %lu, high pfn %lu\n",
+		size, iova->pfn_lo, iova->pfn_hi);
+	for (i = 0; iova->pfn_lo + i <= iova->pfn_hi; i++) {
+		pci_dma_addr = dma_map_page_attrs(&pdev->dev, pages[i], 0,
+						  PAGE_SIZE, DMA_BIDIRECTIONAL,
+						  attrs);
+		dev_dbg(dev, "dma_alloc: mapped pci_dma_addr %pad\n",
+			&pci_dma_addr);
+		if (dma_mapping_error(&pdev->dev, pci_dma_addr)) {
+			dev_err(dev, "pci_dma_mapping for page[%d] failed", i);
+			goto out_unmap;
+		}
+
+		ret = ipu6_mmu_map(mmu->dmap->mmu_info,
+				   PFN_PHYS(iova->pfn_lo + i), pci_dma_addr,
+				   PAGE_SIZE);
+		if (ret) {
+			dev_err(dev, "ipu6_mmu_map for pci_dma[%d] %pad failed",
+				i, &pci_dma_addr);
+			dma_unmap_page_attrs(&pdev->dev, pci_dma_addr,
+					     PAGE_SIZE, DMA_BIDIRECTIONAL,
+					     attrs);
+			goto out_unmap;
+		}
+	}
+
+	info->vaddr = vmap(pages, count, VM_USERMAP, PAGE_KERNEL);
+	if (!info->vaddr)
+		goto out_unmap;
+
+	*dma_handle = PFN_PHYS(iova->pfn_lo);
+
+	info->pages = pages;
+	info->ipu6_iova = *dma_handle;
+	info->size = size;
+	list_add(&info->list, &mmu->vma_list);
+
+	return info->vaddr;
+
+out_unmap:
+	while (i--) {
+		ipu6_iova = PFN_PHYS(iova->pfn_lo + i);
+		pci_dma_addr = ipu6_mmu_iova_to_phys(mmu->dmap->mmu_info,
+						     ipu6_iova);
+		dma_unmap_page_attrs(&pdev->dev, pci_dma_addr, PAGE_SIZE,
+				     DMA_BIDIRECTIONAL, attrs);
+
+		ipu6_mmu_unmap(mmu->dmap->mmu_info, ipu6_iova, PAGE_SIZE);
+	}
+
+	__dma_free_buffer(dev, pages, size, attrs);
+
+out_free_iova:
+	__free_iova(&mmu->dmap->iovad, iova);
+out_kfree:
+	kfree(info);
+
+	return NULL;
+}
+
+static void ipu6_dma_free(struct device *dev, size_t size, void *vaddr,
+			  dma_addr_t dma_handle,
+			  unsigned long attrs)
+{
+	struct ipu6_mmu *mmu = to_ipu6_bus_device(dev)->mmu;
+	struct pci_dev *pdev = to_ipu6_bus_device(dev)->isp->pdev;
+	struct iova *iova = find_iova(&mmu->dmap->iovad, PHYS_PFN(dma_handle));
+	dma_addr_t pci_dma_addr, ipu6_iova;
+	struct vm_info *info;
+	struct page **pages;
+	unsigned int i;
+
+	if (WARN_ON(!iova))
+		return;
+
+	info = get_vm_info(mmu, dma_handle);
+	if (WARN_ON(!info))
+		return;
+
+	if (WARN_ON(!info->vaddr))
+		return;
+
+	if (WARN_ON(!info->pages))
+		return;
+
+	list_del(&info->list);
+
+	size = PAGE_ALIGN(size);
+
+	pages = info->pages;
+
+	vunmap(vaddr);
+
+	for (i = 0; i < PHYS_PFN(size); i++) {
+		ipu6_iova = PFN_PHYS(iova->pfn_lo + i);
+		pci_dma_addr = ipu6_mmu_iova_to_phys(mmu->dmap->mmu_info,
+						     ipu6_iova);
+		dma_unmap_page_attrs(&pdev->dev, pci_dma_addr, PAGE_SIZE,
+				     DMA_BIDIRECTIONAL, attrs);
+	}
+
+	ipu6_mmu_unmap(mmu->dmap->mmu_info, PFN_PHYS(iova->pfn_lo),
+		       PFN_PHYS(iova_size(iova)));
+
+	__dma_free_buffer(dev, pages, size, attrs);
+
+	mmu->tlb_invalidate(mmu);
+
+	__free_iova(&mmu->dmap->iovad, iova);
+
+	kfree(info);
+}
+
+static int ipu6_dma_mmap(struct device *dev, struct vm_area_struct *vma,
+			 void *addr, dma_addr_t iova, size_t size,
+			 unsigned long attrs)
+{
+	struct ipu6_mmu *mmu = to_ipu6_bus_device(dev)->mmu;
+	size_t count = PHYS_PFN(PAGE_ALIGN(size));
+	struct vm_info *info;
+	size_t i;
+
+	info = get_vm_info(mmu, iova);
+	if (!info)
+		return -EFAULT;
+
+	if (!info->vaddr)
+		return -EFAULT;
+
+	if (vma->vm_start & ~PAGE_MASK)
+		return -EINVAL;
+
+	if (size > info->size)
+		return -EFAULT;
+
+	for (i = 0; i < count; i++)
+		vm_insert_page(vma, vma->vm_start + PFN_PHYS(i),
+			       info->pages[i]);
+
+	return 0;
+}
+
+static void ipu6_dma_unmap_sg(struct device *dev,
+			      struct scatterlist *sglist,
+			      int nents, enum dma_data_direction dir,
+			      unsigned long attrs)
+{
+	struct pci_dev *pdev = to_ipu6_bus_device(dev)->isp->pdev;
+	struct ipu6_mmu *mmu = to_ipu6_bus_device(dev)->mmu;
+	struct iova *iova = find_iova(&mmu->dmap->iovad,
+				      PHYS_PFN(sg_dma_address(sglist)));
+	int i, npages, count;
+	struct scatterlist *sg;
+	dma_addr_t pci_dma_addr;
+
+	if (!nents)
+		return;
+
+	if (WARN_ON(!iova))
+		return;
+
+	if ((attrs & DMA_ATTR_SKIP_CPU_SYNC) == 0)
+		ipu6_dma_sync_sg_for_cpu(dev, sglist, nents, DMA_BIDIRECTIONAL);
+
+	/* get the nents as orig_nents given by caller */
+	count = 0;
+	npages = iova_size(iova);
+	for_each_sg(sglist, sg, nents, i) {
+		if (sg_dma_len(sg) == 0 ||
+		    sg_dma_address(sg) == DMA_MAPPING_ERROR)
+			break;
+
+		npages -= PHYS_PFN(PAGE_ALIGN(sg_dma_len(sg)));
+		count++;
+		if (npages <= 0)
+			break;
+	}
+
+	/*
+	 * Before IPU6 mmu unmap, return the pci dma address back to sg
+	 * assume the nents is less than orig_nents as the least granule
+	 * is 1 SZ_4K page
+	 */
+	dev_dbg(dev, "trying to unmap concatenated %u ents\n", count);
+	for_each_sg(sglist, sg, count, i) {
+		dev_dbg(dev, "ipu unmap sg[%d] %pad\n", i, &sg_dma_address(sg));
+		pci_dma_addr = ipu6_mmu_iova_to_phys(mmu->dmap->mmu_info,
+						     sg_dma_address(sg));
+		dev_dbg(dev, "return pci_dma_addr %pad back to sg[%d]\n",
+			&pci_dma_addr, i);
+		sg_dma_address(sg) = pci_dma_addr;
+	}
+
+	dev_dbg(dev, "ipu6_mmu_unmap low pfn %lu high pfn %lu\n",
+		iova->pfn_lo, iova->pfn_hi);
+	ipu6_mmu_unmap(mmu->dmap->mmu_info, PFN_PHYS(iova->pfn_lo),
+		       PFN_PHYS(iova_size(iova)));
+
+	mmu->tlb_invalidate(mmu);
+
+	dma_unmap_sg_attrs(&pdev->dev, sglist, nents, dir, attrs);
+
+	__free_iova(&mmu->dmap->iovad, iova);
+}
+
+static int ipu6_dma_map_sg(struct device *dev, struct scatterlist *sglist,
+			   int nents, enum dma_data_direction dir,
+			   unsigned long attrs)
+{
+	struct ipu6_mmu *mmu = to_ipu6_bus_device(dev)->mmu;
+	struct pci_dev *pdev = to_ipu6_bus_device(dev)->isp->pdev;
+	struct scatterlist *sg;
+	struct iova *iova;
+	size_t npages = 0;
+	unsigned long iova_addr;
+	int i, count;
+
+	for_each_sg(sglist, sg, nents, i) {
+		if (sg->offset) {
+			dev_err(dev, "Unsupported non-zero sg[%d].offset %x\n",
+				i, sg->offset);
+			return -EFAULT;
+		}
+	}
+
+	dev_dbg(dev, "pci_dma_map_sg trying to map %d ents\n", nents);
+	count  = dma_map_sg_attrs(&pdev->dev, sglist, nents, dir, attrs);
+	if (count <= 0) {
+		dev_err(dev, "pci_dma_map_sg %d ents failed\n", nents);
+		return 0;
+	}
+
+	dev_dbg(dev, "pci_dma_map_sg %d ents mapped\n", count);
+
+	for_each_sg(sglist, sg, count, i)
+		npages += PHYS_PFN(PAGE_ALIGN(sg_dma_len(sg)));
+
+	iova = alloc_iova(&mmu->dmap->iovad, npages,
+			  PHYS_PFN(dma_get_mask(dev)), 0);
+	if (!iova)
+		return 0;
+
+	dev_dbg(dev, "dmamap: iova low pfn %lu, high pfn %lu\n", iova->pfn_lo,
+		iova->pfn_hi);
+
+	iova_addr = iova->pfn_lo;
+	for_each_sg(sglist, sg, count, i) {
+		int ret;
+
+		dev_dbg(dev, "mapping entry %d: iova 0x%llx phy %pad size %d\n",
+			i, PFN_PHYS(iova_addr), &sg_dma_address(sg),
+			sg_dma_len(sg));
+
+		ret = ipu6_mmu_map(mmu->dmap->mmu_info, PFN_PHYS(iova_addr),
+				   sg_dma_address(sg),
+				   PAGE_ALIGN(sg_dma_len(sg)));
+		if (ret)
+			goto out_fail;
+
+		sg_dma_address(sg) = PFN_PHYS(iova_addr);
+
+		iova_addr += PHYS_PFN(PAGE_ALIGN(sg_dma_len(sg)));
+	}
+
+	if ((attrs & DMA_ATTR_SKIP_CPU_SYNC) == 0)
+		ipu6_dma_sync_sg_for_cpu(dev, sglist, nents, DMA_BIDIRECTIONAL);
+
+	return count;
+
+out_fail:
+	ipu6_dma_unmap_sg(dev, sglist, i, dir, attrs);
+
+	return 0;
+}
+
+/*
+ * Create scatter-list for the already allocated DMA buffer
+ */
+static int ipu6_dma_get_sgtable(struct device *dev, struct sg_table *sgt,
+				void *cpu_addr, dma_addr_t handle, size_t size,
+				unsigned long attrs)
+{
+	struct ipu6_mmu *mmu = to_ipu6_bus_device(dev)->mmu;
+	struct vm_info *info;
+	int n_pages;
+	int ret = 0;
+
+	info = get_vm_info(mmu, handle);
+	if (!info)
+		return -EFAULT;
+
+	if (!info->vaddr)
+		return -EFAULT;
+
+	if (WARN_ON(!info->pages))
+		return -ENOMEM;
+
+	n_pages = PHYS_PFN(PAGE_ALIGN(size));
+
+	ret = sg_alloc_table_from_pages(sgt, info->pages, n_pages, 0, size,
+					GFP_KERNEL);
+	if (ret)
+		dev_warn(dev, "IPU6 get sgt table failed\n");
+
+	return ret;
+}
+
+const struct dma_map_ops ipu6_dma_ops = {
+	.alloc = ipu6_dma_alloc,
+	.free = ipu6_dma_free,
+	.mmap = ipu6_dma_mmap,
+	.map_sg = ipu6_dma_map_sg,
+	.unmap_sg = ipu6_dma_unmap_sg,
+	.sync_single_for_cpu = ipu6_dma_sync_single_for_cpu,
+	.sync_single_for_device = ipu6_dma_sync_single_for_cpu,
+	.sync_sg_for_cpu = ipu6_dma_sync_sg_for_cpu,
+	.sync_sg_for_device = ipu6_dma_sync_sg_for_cpu,
+	.get_sgtable = ipu6_dma_get_sgtable,
+};
diff --git a/drivers/media/pci/intel/ipu6/ipu6-dma.h b/drivers/media/pci/intel/ipu6/ipu6-dma.h
new file mode 100644
index 000000000000..0c8d4348c999
--- /dev/null
+++ b/drivers/media/pci/intel/ipu6/ipu6-dma.h
@@ -0,0 +1,20 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/* Copyright (C) 2013 - 2023 Intel Corporation */
+
+#ifndef IPU6_DMA_H
+#define IPU6_DMA_H
+
+#include <linux/dma-map-ops.h>
+#include <linux/iova.h>
+
+struct ipu6_mmu_info;
+
+struct ipu6_dma_mapping {
+	struct ipu6_mmu_info *mmu_info;
+	struct iova_domain iovad;
+	struct kref ref;
+};
+
+extern const struct dma_map_ops ipu6_dma_ops;
+
+#endif /* IPU6_DMA_H */
diff --git a/drivers/media/pci/intel/ipu6/ipu6-mmu.c b/drivers/media/pci/intel/ipu6/ipu6-mmu.c
new file mode 100644
index 000000000000..6e5c7cb27f89
--- /dev/null
+++ b/drivers/media/pci/intel/ipu6/ipu6-mmu.c
@@ -0,0 +1,828 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2013 - 2023 Intel Corporation
+ */
+
+#include <linux/cacheflush.h>
+#include <linux/iova.h>
+
+#include "ipu6.h"
+#include "ipu6-dma.h"
+#include "ipu6-mmu.h"
+#include "ipu6-platform-regs.h"
+
+#define ISP_PAGE_SHIFT		12
+#define ISP_PAGE_SIZE		BIT(ISP_PAGE_SHIFT)
+#define ISP_PAGE_MASK		(~(ISP_PAGE_SIZE - 1))
+
+#define ISP_L1PT_SHIFT		22
+#define ISP_L1PT_MASK		(~((1U << ISP_L1PT_SHIFT) - 1))
+
+#define ISP_L2PT_SHIFT		12
+#define ISP_L2PT_MASK		(~(ISP_L1PT_MASK | (~(ISP_PAGE_MASK))))
+
+#define ISP_L1PT_PTES           1024
+#define ISP_L2PT_PTES           1024
+
+#define ISP_PADDR_SHIFT		12
+
+#define REG_TLB_INVALIDATE	0x0000
+
+#define REG_L1_PHYS		0x0004	/* 27-bit pfn */
+#define REG_INFO		0x0008
+
+#define TBL_PHYS_ADDR(a)	((phys_addr_t)(a) << ISP_PADDR_SHIFT)
+
+static void tlb_invalidate(struct ipu6_mmu *mmu)
+{
+	unsigned long flags;
+	unsigned int i;
+
+	spin_lock_irqsave(&mmu->ready_lock, flags);
+	if (!mmu->ready) {
+		spin_unlock_irqrestore(&mmu->ready_lock, flags);
+		return;
+	}
+
+	for (i = 0; i < mmu->nr_mmus; i++) {
+		/*
+		 * To avoid the HW bug induced dead lock in some of the IPU6
+		 * MMUs on successive invalidate calls, we need to first do a
+		 * read to the page table base before writing the invalidate
+		 * register. MMUs which need to implement this WA, will have
+		 * the insert_read_before_invalidate flags set as true.
+		 * Disregard the return value of the read.
+		 */
+		if (mmu->mmu_hw[i].insert_read_before_invalidate)
+			readl(mmu->mmu_hw[i].base + REG_L1_PHYS);
+
+		writel(0xffffffff, mmu->mmu_hw[i].base +
+		       REG_TLB_INVALIDATE);
+		/*
+		 * The TLB invalidation is a "single cycle" (IOMMU clock cycles)
+		 * When the actual MMIO write reaches the IPU6 TLB Invalidate
+		 * register, wmb() will force the TLB invalidate out if the CPU
+		 * attempts to update the IOMMU page table (or sooner).
+		 */
+		wmb();
+	}
+	spin_unlock_irqrestore(&mmu->ready_lock, flags);
+}
+
+#ifdef DEBUG
+static void page_table_dump(struct ipu6_mmu_info *mmu_info)
+{
+	u32 l1_idx;
+
+	dev_dbg(mmu_info->dev, "begin IOMMU page table dump\n");
+
+	for (l1_idx = 0; l1_idx < ISP_L1PT_PTES; l1_idx++) {
+		u32 l2_idx;
+		u32 iova = (phys_addr_t)l1_idx << ISP_L1PT_SHIFT;
+
+		if (mmu_info->l1_pt[l1_idx] == mmu_info->dummy_l2_pteval)
+			continue;
+		dev_dbg(mmu_info->dev,
+			"l1 entry %u; iovas 0x%8.8x-0x%8.8x, at %pa\n",
+			l1_idx, iova, iova + ISP_PAGE_SIZE,
+			TBL_PHYS_ADDR(mmu_info->l1_pt[l1_idx]));
+
+		for (l2_idx = 0; l2_idx < ISP_L2PT_PTES; l2_idx++) {
+			u32 *l2_pt = mmu_info->l2_pts[l1_idx];
+			u32 iova2 = iova + (l2_idx << ISP_L2PT_SHIFT);
+
+			if (l2_pt[l2_idx] == mmu_info->dummy_page_pteval)
+				continue;
+
+			dev_dbg(mmu_info->dev,
+				"\tl2 entry %u; iova 0x%8.8x, phys %pa\n",
+				l2_idx, iova2,
+				TBL_PHYS_ADDR(l2_pt[l2_idx]));
+		}
+	}
+
+	dev_dbg(mmu_info->dev, "end IOMMU page table dump\n");
+}
+#endif /* DEBUG */
+
+static dma_addr_t map_single(struct ipu6_mmu_info *mmu_info, void *ptr)
+{
+	dma_addr_t dma;
+
+	dma = dma_map_single(mmu_info->dev, ptr, PAGE_SIZE, DMA_BIDIRECTIONAL);
+	if (dma_mapping_error(mmu_info->dev, dma))
+		return 0;
+
+	return dma;
+}
+
+static int get_dummy_page(struct ipu6_mmu_info *mmu_info)
+{
+	void *pt = (void *)get_zeroed_page(GFP_ATOMIC | GFP_DMA32);
+	dma_addr_t dma;
+
+	if (!pt)
+		return -ENOMEM;
+
+	dev_dbg(mmu_info->dev, "dummy_page: get_zeroed_page() == %p\n", pt);
+
+	dma = map_single(mmu_info, pt);
+	if (!dma) {
+		dev_err(mmu_info->dev, "Failed to map dummy page\n");
+		goto err_free_page;
+	}
+
+	mmu_info->dummy_page = pt;
+	mmu_info->dummy_page_pteval = dma >> ISP_PAGE_SHIFT;
+
+	return 0;
+
+err_free_page:
+	free_page((unsigned long)pt);
+	return -ENOMEM;
+}
+
+static void free_dummy_page(struct ipu6_mmu_info *mmu_info)
+{
+	dma_unmap_single(mmu_info->dev,
+			 TBL_PHYS_ADDR(mmu_info->dummy_page_pteval),
+			 PAGE_SIZE, DMA_BIDIRECTIONAL);
+	free_page((unsigned long)mmu_info->dummy_page);
+}
+
+static int alloc_dummy_l2_pt(struct ipu6_mmu_info *mmu_info)
+{
+	u32 *pt = (u32 *)get_zeroed_page(GFP_ATOMIC | GFP_DMA32);
+	dma_addr_t dma;
+	unsigned int i;
+
+	if (!pt)
+		return -ENOMEM;
+
+	dev_dbg(mmu_info->dev, "dummy_l2: get_zeroed_page() = %p\n", pt);
+
+	dma = map_single(mmu_info, pt);
+	if (!dma) {
+		dev_err(mmu_info->dev, "Failed to map l2pt page\n");
+		goto err_free_page;
+	}
+
+	for (i = 0; i < ISP_L2PT_PTES; i++)
+		pt[i] = mmu_info->dummy_page_pteval;
+
+	mmu_info->dummy_l2_pt = pt;
+	mmu_info->dummy_l2_pteval = dma >> ISP_PAGE_SHIFT;
+
+	return 0;
+
+err_free_page:
+	free_page((unsigned long)pt);
+	return -ENOMEM;
+}
+
+static void free_dummy_l2_pt(struct ipu6_mmu_info *mmu_info)
+{
+	dma_unmap_single(mmu_info->dev,
+			 TBL_PHYS_ADDR(mmu_info->dummy_l2_pteval),
+			 PAGE_SIZE, DMA_BIDIRECTIONAL);
+	free_page((unsigned long)mmu_info->dummy_l2_pt);
+}
+
+static u32 *alloc_l1_pt(struct ipu6_mmu_info *mmu_info)
+{
+	u32 *pt = (u32 *)get_zeroed_page(GFP_ATOMIC | GFP_DMA32);
+	dma_addr_t dma;
+	unsigned int i;
+
+	if (!pt)
+		return NULL;
+
+	dev_dbg(mmu_info->dev, "alloc_l1: get_zeroed_page() = %p\n", pt);
+
+	for (i = 0; i < ISP_L1PT_PTES; i++)
+		pt[i] = mmu_info->dummy_l2_pteval;
+
+	dma = map_single(mmu_info, pt);
+	if (!dma) {
+		dev_err(mmu_info->dev, "Failed to map l1pt page\n");
+		goto err_free_page;
+	}
+
+	mmu_info->l1_pt_dma = dma >> ISP_PADDR_SHIFT;
+	dev_dbg(mmu_info->dev, "l1 pt %p mapped at %llx\n", pt, dma);
+
+	return pt;
+
+err_free_page:
+	free_page((unsigned long)pt);
+	return NULL;
+}
+
+static u32 *alloc_l2_pt(struct ipu6_mmu_info *mmu_info)
+{
+	u32 *pt = (u32 *)get_zeroed_page(GFP_ATOMIC | GFP_DMA32);
+	unsigned int i;
+
+	if (!pt)
+		return NULL;
+
+	dev_dbg(mmu_info->dev, "alloc_l2: get_zeroed_page() = %p\n", pt);
+
+	for (i = 0; i < ISP_L1PT_PTES; i++)
+		pt[i] = mmu_info->dummy_page_pteval;
+
+	return pt;
+}
+
+static int l2_map(struct ipu6_mmu_info *mmu_info, unsigned long iova,
+		  phys_addr_t paddr, size_t size)
+{
+	u32 l1_idx = iova >> ISP_L1PT_SHIFT;
+	u32 iova_start = iova;
+	u32 *l2_pt, *l2_virt;
+	unsigned int l2_idx;
+	unsigned long flags;
+	dma_addr_t dma;
+	u32 l1_entry;
+
+	dev_dbg(mmu_info->dev,
+		"mapping l2 page table for l1 index %u (iova %8.8x)\n",
+		l1_idx, (u32)iova);
+
+	spin_lock_irqsave(&mmu_info->lock, flags);
+	l1_entry = mmu_info->l1_pt[l1_idx];
+	if (l1_entry == mmu_info->dummy_l2_pteval) {
+		l2_virt = mmu_info->l2_pts[l1_idx];
+		if (likely(!l2_virt)) {
+			l2_virt = alloc_l2_pt(mmu_info);
+			if (!l2_virt) {
+				spin_unlock_irqrestore(&mmu_info->lock, flags);
+				return -ENOMEM;
+			}
+		}
+
+		dma = map_single(mmu_info, l2_virt);
+		if (!dma) {
+			dev_err(mmu_info->dev, "Failed to map l2pt page\n");
+			free_page((unsigned long)l2_virt);
+			spin_unlock_irqrestore(&mmu_info->lock, flags);
+			return -EINVAL;
+		}
+
+		l1_entry = dma >> ISP_PADDR_SHIFT;
+
+		dev_dbg(mmu_info->dev, "page for l1_idx %u %p allocated\n",
+			l1_idx, l2_virt);
+		mmu_info->l1_pt[l1_idx] = l1_entry;
+		mmu_info->l2_pts[l1_idx] = l2_virt;
+		clflush_cache_range((void *)&mmu_info->l1_pt[l1_idx],
+				    sizeof(mmu_info->l1_pt[l1_idx]));
+	}
+
+	l2_pt = mmu_info->l2_pts[l1_idx];
+
+	dev_dbg(mmu_info->dev, "l2_pt at %p with dma 0x%x\n", l2_pt, l1_entry);
+
+	paddr = ALIGN(paddr, ISP_PAGE_SIZE);
+
+	l2_idx = (iova_start & ISP_L2PT_MASK) >> ISP_L2PT_SHIFT;
+
+	dev_dbg(mmu_info->dev, "l2_idx %u, phys 0x%8.8x\n", l2_idx,
+		l2_pt[l2_idx]);
+	if (l2_pt[l2_idx] != mmu_info->dummy_page_pteval) {
+		spin_unlock_irqrestore(&mmu_info->lock, flags);
+		return -EINVAL;
+	}
+
+	l2_pt[l2_idx] = paddr >> ISP_PADDR_SHIFT;
+
+	clflush_cache_range((void *)&l2_pt[l2_idx], sizeof(l2_pt[l2_idx]));
+	spin_unlock_irqrestore(&mmu_info->lock, flags);
+
+	dev_dbg(mmu_info->dev, "l2 index %u mapped as 0x%8.8x\n", l2_idx,
+		l2_pt[l2_idx]);
+
+	return 0;
+}
+
+static int __ipu6_mmu_map(struct ipu6_mmu_info *mmu_info, unsigned long iova,
+			  phys_addr_t paddr, size_t size)
+{
+	u32 iova_start = round_down(iova, ISP_PAGE_SIZE);
+	u32 iova_end = ALIGN(iova + size, ISP_PAGE_SIZE);
+
+	dev_dbg(mmu_info->dev,
+		"mapping iova 0x%8.8x--0x%8.8x, size %zu at paddr 0x%10.10llx\n",
+		iova_start, iova_end, size, paddr);
+
+	return l2_map(mmu_info, iova_start, paddr, size);
+}
+
+static size_t l2_unmap(struct ipu6_mmu_info *mmu_info, unsigned long iova,
+		       phys_addr_t dummy, size_t size)
+{
+	u32 l1_idx = iova >> ISP_L1PT_SHIFT;
+	u32 iova_start = iova;
+	unsigned int l2_idx;
+	size_t unmapped = 0;
+	unsigned long flags;
+	u32 *l2_pt;
+
+	dev_dbg(mmu_info->dev, "unmapping l2 page table for l1 index %u (iova 0x%8.8lx)\n",
+		l1_idx, iova);
+
+	spin_lock_irqsave(&mmu_info->lock, flags);
+	if (mmu_info->l1_pt[l1_idx] == mmu_info->dummy_l2_pteval) {
+		spin_unlock_irqrestore(&mmu_info->lock, flags);
+		dev_err(mmu_info->dev,
+			"unmap iova 0x%8.8lx l1 idx %u which was not mapped\n",
+			iova, l1_idx);
+		return 0;
+	}
+
+	for (l2_idx = (iova_start & ISP_L2PT_MASK) >> ISP_L2PT_SHIFT;
+	     (iova_start & ISP_L1PT_MASK) + (l2_idx << ISP_PAGE_SHIFT)
+		     < iova_start + size && l2_idx < ISP_L2PT_PTES; l2_idx++) {
+		l2_pt = mmu_info->l2_pts[l1_idx];
+		dev_dbg(mmu_info->dev,
+			"unmap l2 index %u with pteval 0x%10.10llx\n",
+			l2_idx, TBL_PHYS_ADDR(l2_pt[l2_idx]));
+		l2_pt[l2_idx] = mmu_info->dummy_page_pteval;
+
+		clflush_cache_range((void *)&l2_pt[l2_idx],
+				    sizeof(l2_pt[l2_idx]));
+		unmapped++;
+	}
+	spin_unlock_irqrestore(&mmu_info->lock, flags);
+
+	return unmapped << ISP_PAGE_SHIFT;
+}
+
+static size_t __ipu6_mmu_unmap(struct ipu6_mmu_info *mmu_info,
+			       unsigned long iova, size_t size)
+{
+	return l2_unmap(mmu_info, iova, 0, size);
+}
+
+static int allocate_trash_buffer(struct ipu6_mmu *mmu)
+{
+	unsigned int n_pages = PHYS_PFN(PAGE_ALIGN(IPU6_MMUV2_TRASH_RANGE));
+	struct iova *iova;
+	unsigned int i;
+	dma_addr_t dma;
+	unsigned long iova_addr;
+	int ret;
+
+	/* Allocate 8MB in iova range */
+	iova = alloc_iova(&mmu->dmap->iovad, n_pages,
+			  PHYS_PFN(mmu->dmap->mmu_info->aperture_end), 0);
+	if (!iova) {
+		dev_err(mmu->dev, "cannot allocate iova range for trash\n");
+		return -ENOMEM;
+	}
+
+	dma = dma_map_page(mmu->dmap->mmu_info->dev, mmu->trash_page, 0,
+			   PAGE_SIZE, DMA_BIDIRECTIONAL);
+	if (dma_mapping_error(mmu->dmap->mmu_info->dev, dma)) {
+		dev_err(mmu->dmap->mmu_info->dev, "Failed to map trash page\n");
+		ret = -ENOMEM;
+		goto out_free_iova;
+	}
+
+	mmu->pci_trash_page = dma;
+
+	/*
+	 * Map the 8MB iova address range to the same physical trash page
+	 * mmu->trash_page which is already reserved at the probe
+	 */
+	iova_addr = iova->pfn_lo;
+	for (i = 0; i < n_pages; i++) {
+		ret = ipu6_mmu_map(mmu->dmap->mmu_info, PFN_PHYS(iova_addr),
+				   mmu->pci_trash_page, PAGE_SIZE);
+		if (ret) {
+			dev_err(mmu->dev,
+				"mapping trash buffer range failed\n");
+			goto out_unmap;
+		}
+
+		iova_addr++;
+	}
+
+	mmu->iova_trash_page = PFN_PHYS(iova->pfn_lo);
+	dev_dbg(mmu->dev, "iova trash buffer for MMUID: %d is %u\n",
+		mmu->mmid, (unsigned int)mmu->iova_trash_page);
+	return 0;
+
+out_unmap:
+	ipu6_mmu_unmap(mmu->dmap->mmu_info, PFN_PHYS(iova->pfn_lo),
+		       PFN_PHYS(iova_size(iova)));
+	dma_unmap_page(mmu->dmap->mmu_info->dev, mmu->pci_trash_page,
+		       PAGE_SIZE, DMA_BIDIRECTIONAL);
+out_free_iova:
+	__free_iova(&mmu->dmap->iovad, iova);
+	return ret;
+}
+
+int ipu6_mmu_hw_init(struct ipu6_mmu *mmu)
+{
+	struct ipu6_mmu_info *mmu_info;
+	unsigned long flags;
+	unsigned int i;
+
+	mmu_info = mmu->dmap->mmu_info;
+
+	/* Initialise the each MMU HW block */
+	for (i = 0; i < mmu->nr_mmus; i++) {
+		struct ipu6_mmu_hw *mmu_hw = &mmu->mmu_hw[i];
+		unsigned int j;
+		u16 block_addr;
+
+		/* Write page table address per MMU */
+		writel((phys_addr_t)mmu_info->l1_pt_dma,
+		       mmu->mmu_hw[i].base + REG_L1_PHYS);
+
+		/* Set info bits per MMU */
+		writel(mmu->mmu_hw[i].info_bits,
+		       mmu->mmu_hw[i].base + REG_INFO);
+
+		/* Configure MMU TLB stream configuration for L1 */
+		for (j = 0, block_addr = 0; j < mmu_hw->nr_l1streams;
+		     block_addr += mmu->mmu_hw[i].l1_block_sz[j], j++) {
+			if (block_addr > IPU6_MAX_LI_BLOCK_ADDR) {
+				dev_err(mmu->dev, "invalid L1 configuration\n");
+				return -EINVAL;
+			}
+
+			/* Write block start address for each streams */
+			writel(block_addr, mmu_hw->base +
+			       mmu_hw->l1_stream_id_reg_offset + 4 * j);
+		}
+
+		/* Configure MMU TLB stream configuration for L2 */
+		for (j = 0, block_addr = 0; j < mmu_hw->nr_l2streams;
+		     block_addr += mmu->mmu_hw[i].l2_block_sz[j], j++) {
+			if (block_addr > IPU6_MAX_L2_BLOCK_ADDR) {
+				dev_err(mmu->dev, "invalid L2 configuration\n");
+				return -EINVAL;
+			}
+
+			writel(block_addr, mmu_hw->base +
+			       mmu_hw->l2_stream_id_reg_offset + 4 * j);
+		}
+	}
+
+	if (!mmu->trash_page) {
+		int ret;
+
+		mmu->trash_page = alloc_page(GFP_KERNEL);
+		if (!mmu->trash_page) {
+			dev_err(mmu->dev, "insufficient memory for trash buffer\n");
+			return -ENOMEM;
+		}
+
+		ret = allocate_trash_buffer(mmu);
+		if (ret) {
+			__free_page(mmu->trash_page);
+			mmu->trash_page = NULL;
+			dev_err(mmu->dev, "trash buffer allocation failed\n");
+			return ret;
+		}
+	}
+
+	spin_lock_irqsave(&mmu->ready_lock, flags);
+	mmu->ready = true;
+	spin_unlock_irqrestore(&mmu->ready_lock, flags);
+
+	return 0;
+}
+EXPORT_SYMBOL_NS_GPL(ipu6_mmu_hw_init, INTEL_IPU6);
+
+static struct ipu6_mmu_info *ipu6_mmu_alloc(struct ipu6_device *isp)
+{
+	struct ipu6_mmu_info *mmu_info;
+	int ret;
+
+	mmu_info = kzalloc(sizeof(*mmu_info), GFP_KERNEL);
+	if (!mmu_info)
+		return NULL;
+
+	mmu_info->aperture_start = 0;
+	mmu_info->aperture_end = DMA_BIT_MASK(isp->secure_mode ?
+					      IPU6_MMU_ADDR_BITS :
+					      IPU6_MMU_ADDR_BITS_NON_SECURE);
+	mmu_info->pgsize_bitmap = SZ_4K;
+	mmu_info->dev = &isp->pdev->dev;
+
+	ret = get_dummy_page(mmu_info);
+	if (ret)
+		goto err_free_info;
+
+	ret = alloc_dummy_l2_pt(mmu_info);
+	if (ret)
+		goto err_free_dummy_page;
+
+	mmu_info->l2_pts = vzalloc(ISP_L2PT_PTES * sizeof(*mmu_info->l2_pts));
+	if (!mmu_info->l2_pts)
+		goto err_free_dummy_l2_pt;
+
+	/*
+	 * We always map the L1 page table (a single page as well as
+	 * the L2 page tables).
+	 */
+	mmu_info->l1_pt = alloc_l1_pt(mmu_info);
+	if (!mmu_info->l1_pt)
+		goto err_free_l2_pts;
+
+	spin_lock_init(&mmu_info->lock);
+
+	dev_dbg(mmu_info->dev, "domain initialised\n");
+
+	return mmu_info;
+
+err_free_l2_pts:
+	vfree(mmu_info->l2_pts);
+err_free_dummy_l2_pt:
+	free_dummy_l2_pt(mmu_info);
+err_free_dummy_page:
+	free_dummy_page(mmu_info);
+err_free_info:
+	kfree(mmu_info);
+
+	return NULL;
+}
+
+void ipu6_mmu_hw_cleanup(struct ipu6_mmu *mmu)
+{
+	unsigned long flags;
+
+	spin_lock_irqsave(&mmu->ready_lock, flags);
+	mmu->ready = false;
+	spin_unlock_irqrestore(&mmu->ready_lock, flags);
+}
+EXPORT_SYMBOL_NS_GPL(ipu6_mmu_hw_cleanup, INTEL_IPU6);
+
+static struct ipu6_dma_mapping *alloc_dma_mapping(struct ipu6_device *isp)
+{
+	struct ipu6_dma_mapping *dmap;
+
+	dmap = kzalloc(sizeof(*dmap), GFP_KERNEL);
+	if (!dmap)
+		return NULL;
+
+	dmap->mmu_info = ipu6_mmu_alloc(isp);
+	if (!dmap->mmu_info) {
+		kfree(dmap);
+		return NULL;
+	}
+	init_iova_domain(&dmap->iovad, SZ_4K, 1);
+	dmap->mmu_info->dmap = dmap;
+
+	kref_init(&dmap->ref);
+
+	dev_dbg(&isp->pdev->dev, "alloc mapping\n");
+
+	iova_cache_get();
+
+	return dmap;
+}
+
+phys_addr_t ipu6_mmu_iova_to_phys(struct ipu6_mmu_info *mmu_info,
+				  dma_addr_t iova)
+{
+	phys_addr_t phy_addr;
+	unsigned long flags;
+	u32 *l2_pt;
+
+	spin_lock_irqsave(&mmu_info->lock, flags);
+	l2_pt = mmu_info->l2_pts[iova >> ISP_L1PT_SHIFT];
+	phy_addr = (phys_addr_t)l2_pt[(iova & ISP_L2PT_MASK) >> ISP_L2PT_SHIFT];
+	phy_addr <<= ISP_PAGE_SHIFT;
+	spin_unlock_irqrestore(&mmu_info->lock, flags);
+
+	return phy_addr;
+}
+
+static size_t ipu6_mmu_pgsize(unsigned long pgsize_bitmap,
+			      unsigned long addr_merge, size_t size)
+{
+	unsigned int pgsize_idx;
+	size_t pgsize;
+
+	/* Max page size that still fits into 'size' */
+	pgsize_idx = __fls(size);
+
+	if (likely(addr_merge)) {
+		/* Max page size allowed by address */
+		unsigned int align_pgsize_idx = __ffs(addr_merge);
+
+		pgsize_idx = min(pgsize_idx, align_pgsize_idx);
+	}
+
+	pgsize = (1UL << (pgsize_idx + 1)) - 1;
+	pgsize &= pgsize_bitmap;
+
+	WARN_ON(!pgsize);
+
+	/* pick the biggest page */
+	pgsize_idx = __fls(pgsize);
+	pgsize = 1UL << pgsize_idx;
+
+	return pgsize;
+}
+
+size_t ipu6_mmu_unmap(struct ipu6_mmu_info *mmu_info, unsigned long iova,
+		      size_t size)
+{
+	size_t unmapped_page, unmapped = 0;
+	unsigned int min_pagesz;
+
+	/* find out the minimum page size supported */
+	min_pagesz = 1 << __ffs(mmu_info->pgsize_bitmap);
+
+	/*
+	 * The virtual address and the size of the mapping must be
+	 * aligned (at least) to the size of the smallest page supported
+	 * by the hardware
+	 */
+	if (!IS_ALIGNED(iova | size, min_pagesz)) {
+		dev_err(NULL, "unaligned: iova 0x%lx size 0x%zx min_pagesz 0x%x\n",
+			iova, size, min_pagesz);
+		return -EINVAL;
+	}
+
+	/*
+	 * Keep iterating until we either unmap 'size' bytes (or more)
+	 * or we hit an area that isn't mapped.
+	 */
+	while (unmapped < size) {
+		size_t pgsize = ipu6_mmu_pgsize(mmu_info->pgsize_bitmap,
+						iova, size - unmapped);
+
+		unmapped_page = __ipu6_mmu_unmap(mmu_info, iova, pgsize);
+		if (!unmapped_page)
+			break;
+
+		dev_dbg(mmu_info->dev, "unmapped: iova 0x%lx size 0x%zx\n",
+			iova, unmapped_page);
+
+		iova += unmapped_page;
+		unmapped += unmapped_page;
+	}
+
+	return unmapped;
+}
+
+int ipu6_mmu_map(struct ipu6_mmu_info *mmu_info, unsigned long iova,
+		 phys_addr_t paddr, size_t size)
+{
+	unsigned long orig_iova = iova;
+	unsigned int min_pagesz;
+	size_t orig_size = size;
+	int ret = 0;
+
+	if (mmu_info->pgsize_bitmap == 0UL)
+		return -ENODEV;
+
+	/* find out the minimum page size supported */
+	min_pagesz = 1 << __ffs(mmu_info->pgsize_bitmap);
+
+	/*
+	 * both the virtual address and the physical one, as well as
+	 * the size of the mapping, must be aligned (at least) to the
+	 * size of the smallest page supported by the hardware
+	 */
+	if (!IS_ALIGNED(iova | paddr | size, min_pagesz)) {
+		dev_err(mmu_info->dev,
+			"unaligned: iova %lx pa %pa size %zx min_pagesz %x\n",
+			iova, &paddr, size, min_pagesz);
+		return -EINVAL;
+	}
+
+	dev_dbg(mmu_info->dev, "map: iova 0x%lx pa %pa size 0x%zx\n",
+		iova, &paddr, size);
+
+	while (size) {
+		size_t pgsize = ipu6_mmu_pgsize(mmu_info->pgsize_bitmap,
+						iova | paddr, size);
+
+		dev_dbg(mmu_info->dev,
+			"mapping: iova 0x%lx pa %pa pgsize 0x%zx\n",
+			iova, &paddr, pgsize);
+
+		ret = __ipu6_mmu_map(mmu_info, iova, paddr, pgsize);
+		if (ret)
+			break;
+
+		iova += pgsize;
+		paddr += pgsize;
+		size -= pgsize;
+	}
+
+	/* unroll mapping in case something went wrong */
+	if (ret)
+		ipu6_mmu_unmap(mmu_info, orig_iova, orig_size - size);
+
+	return ret;
+}
+
+static void ipu6_mmu_destroy(struct ipu6_mmu *mmu)
+{
+	struct ipu6_dma_mapping *dmap = mmu->dmap;
+	struct ipu6_mmu_info *mmu_info = dmap->mmu_info;
+	struct iova *iova;
+	u32 l1_idx;
+
+	if (mmu->iova_trash_page) {
+		iova = find_iova(&dmap->iovad, PHYS_PFN(mmu->iova_trash_page));
+		if (iova) {
+			/* unmap and free the trash buffer iova */
+			ipu6_mmu_unmap(mmu_info, PFN_PHYS(iova->pfn_lo),
+				       PFN_PHYS(iova_size(iova)));
+			__free_iova(&dmap->iovad, iova);
+		} else {
+			dev_err(mmu->dev, "trash buffer iova not found.\n");
+		}
+
+		mmu->iova_trash_page = 0;
+		dma_unmap_page(mmu_info->dev, mmu->pci_trash_page,
+			       PAGE_SIZE, DMA_BIDIRECTIONAL);
+		mmu->pci_trash_page = 0;
+		__free_page(mmu->trash_page);
+	}
+
+	for (l1_idx = 0; l1_idx < ISP_L1PT_PTES; l1_idx++) {
+		if (mmu_info->l1_pt[l1_idx] != mmu_info->dummy_l2_pteval) {
+			dma_unmap_single(mmu_info->dev,
+					 TBL_PHYS_ADDR(mmu_info->l1_pt[l1_idx]),
+					 PAGE_SIZE, DMA_BIDIRECTIONAL);
+			free_page((unsigned long)mmu_info->l2_pts[l1_idx]);
+		}
+	}
+
+	free_dummy_page(mmu_info);
+	dma_unmap_single(mmu_info->dev, TBL_PHYS_ADDR(mmu_info->l1_pt_dma),
+			 PAGE_SIZE, DMA_BIDIRECTIONAL);
+	free_page((unsigned long)mmu_info->dummy_l2_pt);
+	free_page((unsigned long)mmu_info->l1_pt);
+	kfree(mmu_info);
+}
+
+struct ipu6_mmu *ipu6_mmu_init(struct device *dev,
+			       void __iomem *base, int mmid,
+			       const struct ipu6_hw_variants *hw)
+{
+	struct ipu6_device *isp = pci_get_drvdata(to_pci_dev(dev));
+	struct ipu6_mmu_pdata *pdata;
+	struct ipu6_mmu *mmu;
+	unsigned int i;
+
+	if (hw->nr_mmus > IPU6_MMU_MAX_DEVICES)
+		return ERR_PTR(-EINVAL);
+
+	pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
+	if (!pdata)
+		return ERR_PTR(-ENOMEM);
+
+	for (i = 0; i < hw->nr_mmus; i++) {
+		struct ipu6_mmu_hw *pdata_mmu = &pdata->mmu_hw[i];
+		const struct ipu6_mmu_hw *src_mmu = &hw->mmu_hw[i];
+
+		if (src_mmu->nr_l1streams > IPU6_MMU_MAX_TLB_L1_STREAMS ||
+		    src_mmu->nr_l2streams > IPU6_MMU_MAX_TLB_L2_STREAMS)
+			return ERR_PTR(-EINVAL);
+
+		*pdata_mmu = *src_mmu;
+		pdata_mmu->base = base + src_mmu->offset;
+	}
+
+	mmu = devm_kzalloc(dev, sizeof(*mmu), GFP_KERNEL);
+	if (!mmu)
+		return ERR_PTR(-ENOMEM);
+
+	mmu->mmid = mmid;
+	mmu->mmu_hw = pdata->mmu_hw;
+	mmu->nr_mmus = hw->nr_mmus;
+	mmu->tlb_invalidate = tlb_invalidate;
+	mmu->ready = false;
+	INIT_LIST_HEAD(&mmu->vma_list);
+	spin_lock_init(&mmu->ready_lock);
+
+	mmu->dmap = alloc_dma_mapping(isp);
+	if (!mmu->dmap) {
+		dev_err(dev, "can't alloc dma mapping\n");
+		return ERR_PTR(-ENOMEM);
+	}
+
+	return mmu;
+}
+
+void ipu6_mmu_cleanup(struct ipu6_mmu *mmu)
+{
+	struct ipu6_dma_mapping *dmap = mmu->dmap;
+
+	ipu6_mmu_destroy(mmu);
+	mmu->dmap = NULL;
+	iova_cache_put();
+	put_iova_domain(&dmap->iovad);
+	kfree(dmap);
+}
diff --git a/drivers/media/pci/intel/ipu6/ipu6-mmu.h b/drivers/media/pci/intel/ipu6/ipu6-mmu.h
new file mode 100644
index 000000000000..305fd03bc8ea
--- /dev/null
+++ b/drivers/media/pci/intel/ipu6/ipu6-mmu.h
@@ -0,0 +1,67 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/* Copyright (C) 2013 - 2023 Intel Corporation */
+
+#ifndef IPU6_MMU_H
+#define IPU6_MMU_H
+
+#define ISYS_MMID 1
+#define PSYS_MMID 0
+
+#include <linux/device.h>
+
+struct ipu6_mmu_info {
+	struct device *dev;
+
+	u32 *l1_pt;
+	u32 l1_pt_dma;
+	u32 **l2_pts;
+
+	u32 *dummy_l2_pt;
+	u32 dummy_l2_pteval;
+	void *dummy_page;
+	u32 dummy_page_pteval;
+
+	dma_addr_t aperture_start;
+	dma_addr_t aperture_end;
+	unsigned long pgsize_bitmap;
+
+	spinlock_t lock;	/* Serialize access to users */
+	struct ipu6_dma_mapping *dmap;
+};
+
+struct ipu6_mmu {
+	struct list_head node;
+
+	struct ipu6_mmu_hw *mmu_hw;
+	unsigned int nr_mmus;
+	unsigned int mmid;
+
+	phys_addr_t pgtbl;
+	struct device *dev;
+
+	struct ipu6_dma_mapping *dmap;
+	struct list_head vma_list;
+
+	struct page *trash_page;
+	dma_addr_t pci_trash_page; /* IOVA from PCI DMA services (parent) */
+	dma_addr_t iova_trash_page; /* IOVA for IPU6 child nodes to use */
+
+	bool ready;
+	spinlock_t ready_lock;	/* Serialize access to bool ready */
+
+	void (*tlb_invalidate)(struct ipu6_mmu *mmu);
+};
+
+struct ipu6_mmu *ipu6_mmu_init(struct device *dev,
+			       void __iomem *base, int mmid,
+			       const struct ipu6_hw_variants *hw);
+void ipu6_mmu_cleanup(struct ipu6_mmu *mmu);
+int ipu6_mmu_hw_init(struct ipu6_mmu *mmu);
+void ipu6_mmu_hw_cleanup(struct ipu6_mmu *mmu);
+int ipu6_mmu_map(struct ipu6_mmu_info *mmu_info, unsigned long iova,
+		 phys_addr_t paddr, size_t size);
+size_t ipu6_mmu_unmap(struct ipu6_mmu_info *mmu_info, unsigned long iova,
+		      size_t size);
+phys_addr_t ipu6_mmu_iova_to_phys(struct ipu6_mmu_info *mmu_info,
+				  dma_addr_t iova);
+#endif
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 86+ messages in thread

* [PATCH v2 06/15] media: intel/ipu6: add syscom interfaces between firmware and driver
  2023-10-24 11:29 [PATCH v2 00/15] Intel IPU6 and IPU6 input system drivers bingbu.cao
                   ` (4 preceding siblings ...)
  2023-10-24 11:29 ` [PATCH v2 05/15] media: intel/ipu6: add IPU6 DMA mapping API and MMU table bingbu.cao
@ 2023-10-24 11:29 ` bingbu.cao
  2023-11-23  9:33   ` Andreas Helbech Kleist
  2023-10-24 11:29 ` [PATCH v2 07/15] media: intel/ipu6: input system ABI " bingbu.cao
                   ` (10 subsequent siblings)
  16 siblings, 1 reply; 86+ messages in thread
From: bingbu.cao @ 2023-10-24 11:29 UTC (permalink / raw)
  To: linux-media, sakari.ailus, laurent.pinchart
  Cc: andriy.shevchenko, hdegoede, ilpo.jarvinen, andreaskleist,
	claus.stovgaard, tfiga, senozhatsky, tomi.valkeinen, bingbu.cao,
	bingbu.cao, tian.shu.qiu, hongju.wang

From: Bingbu Cao <bingbu.cao@intel.com>

Syscom is an inter-process(or) communication mechanism between an IPU
and host. Syscom uses message queues for message exchange between IPU
and host. Each message queue has its consumer and producer, host queue
messages to firmware as the producer and then firmware to dequeue the
messages as consumer and vice versa. IPU and host use shared registers
or memory to reside the read and write indices which are updated by
consumer and producer.

Signed-off-by: Bingbu Cao <bingbu.cao@intel.com>
---
 drivers/media/pci/intel/ipu6/ipu6-fw-com.c | 411 +++++++++++++++++++++
 drivers/media/pci/intel/ipu6/ipu6-fw-com.h |  47 +++
 2 files changed, 458 insertions(+)
 create mode 100644 drivers/media/pci/intel/ipu6/ipu6-fw-com.c
 create mode 100644 drivers/media/pci/intel/ipu6/ipu6-fw-com.h

diff --git a/drivers/media/pci/intel/ipu6/ipu6-fw-com.c b/drivers/media/pci/intel/ipu6/ipu6-fw-com.c
new file mode 100644
index 000000000000..a162cc657234
--- /dev/null
+++ b/drivers/media/pci/intel/ipu6/ipu6-fw-com.c
@@ -0,0 +1,411 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2013 - 2023 Intel Corporation
+ */
+
+#include "ipu6.h"
+#include "ipu6-bus.h"
+#include "ipu6-fw-com.h"
+
+/*
+ * FWCOM layer is a shared resource between FW and driver. It consist
+ * of token queues to both send and receive directions. Queue is simply
+ * an array of structures with read and write indexes to the queue.
+ * There are 1...n queues to both directions. Queues locates in
+ * system RAM and are mapped to ISP MMU so that both CPU and ISP can
+ * see the same buffer. Indexes are located in ISP DMEM so that FW code
+ * can poll those with very low latency and cost. CPU access to indexes is
+ * more costly but that happens only at message sending time and
+ * interrupt triggered message handling. CPU doesn't need to poll indexes.
+ * wr_reg / rd_reg are offsets to those dmem location. They are not
+ * the indexes itself.
+ */
+
+/* Shared structure between driver and FW - do not modify */
+struct ipu6_fw_sys_queue {
+	u64 host_address;
+	u32 vied_address;
+	u32 size;
+	u32 token_size;
+	u32 wr_reg;	/* reg number in subsystem's regmem */
+	u32 rd_reg;
+	u32 _align;
+} __packed;
+
+struct ipu6_fw_sys_queue_res {
+	u64 host_address;
+	u32 vied_address;
+	u32 reg;
+} __packed;
+
+enum syscom_state {
+	/* Program load or explicit host setting should init to this */
+	SYSCOM_STATE_UNINIT = 0x57A7E000,
+	/* SP Syscom sets this when it is ready for use */
+	SYSCOM_STATE_READY = 0x57A7E001,
+	/* SP Syscom sets this when no more syscom accesses will happen */
+	SYSCOM_STATE_INACTIVE = 0x57A7E002
+};
+
+enum syscom_cmd {
+	/* Program load or explicit host setting should init to this */
+	SYSCOM_COMMAND_UNINIT = 0x57A7F000,
+	/* Host Syscom requests syscom to become inactive */
+	SYSCOM_COMMAND_INACTIVE = 0x57A7F001
+};
+
+/* firmware config: data that sent from the host to SP via DDR */
+/* Cell copies data into a context */
+
+struct ipu6_fw_syscom_config {
+	u32 firmware_address;
+
+	u32 num_input_queues;
+	u32 num_output_queues;
+
+	/* ISP pointers to an array of ipu6_fw_sys_queue structures */
+	u32 input_queue;
+	u32 output_queue;
+
+	/* ISYS / PSYS private data */
+	u32 specific_addr;
+	u32 specific_size;
+};
+
+struct ipu6_fw_com_context {
+	struct ipu6_bus_device *adev;
+	void __iomem *dmem_addr;
+	int (*cell_ready)(struct ipu6_bus_device *adev);
+	void (*cell_start)(struct ipu6_bus_device *adev);
+
+	void *dma_buffer;
+	dma_addr_t dma_addr;
+	unsigned int dma_size;
+	unsigned long attrs;
+
+	struct ipu6_fw_sys_queue *input_queue;	/* array of host to SP queues */
+	struct ipu6_fw_sys_queue *output_queue;	/* array of SP to host */
+
+	u32 config_vied_addr;
+
+	unsigned int buttress_boot_offset;
+	void __iomem *base_addr;
+};
+
+#define FW_COM_WR_REG 0
+#define FW_COM_RD_REG 4
+
+#define REGMEM_OFFSET 0
+#define TUNIT_MAGIC_PATTERN 0x5a5a5a5a
+
+enum regmem_id {
+	/* pass pkg_dir address to SPC in non-secure mode */
+	PKG_DIR_ADDR_REG = 0,
+	/* Tunit CFG blob for secure - provided by host.*/
+	TUNIT_CFG_DWR_REG = 1,
+	/* syscom commands - modified by the host */
+	SYSCOM_COMMAND_REG = 2,
+	/* Store interrupt status - updated by SP */
+	SYSCOM_IRQ_REG = 3,
+	/* first syscom queue pointer register */
+	SYSCOM_QPR_BASE_REG = 4
+};
+
+enum message_direction {
+	DIR_RECV = 0,
+	DIR_SEND
+};
+
+#define BUTTRESS_FW_BOOT_PARAMS_0 0x4000
+#define BUTTRESS_FW_BOOT_PARAM_REG(base, offset, id)			\
+	((base) + BUTTRESS_FW_BOOT_PARAMS_0 + ((offset) + (id)) * 4)
+
+enum buttress_syscom_id {
+	/* pass syscom configuration to SPC */
+	SYSCOM_CONFIG_ID		= 0,
+	/* syscom state - modified by SP */
+	SYSCOM_STATE_ID			= 1,
+	/* syscom vtl0 addr mask */
+	SYSCOM_VTL0_ADDR_MASK_ID	= 2,
+	SYSCOM_ID_MAX
+};
+
+static void ipu6_sys_queue_init(struct ipu6_fw_sys_queue *q, unsigned int size,
+				unsigned int token_size,
+				struct ipu6_fw_sys_queue_res *res)
+{
+	unsigned int buf_size = (size + 1) * token_size;
+
+	q->size = size + 1;
+	q->token_size = token_size;
+
+	/* acquire the shared buffer space */
+	q->host_address = res->host_address;
+	res->host_address += buf_size;
+	q->vied_address = res->vied_address;
+	res->vied_address += buf_size;
+
+	/* acquire the shared read and writer pointers */
+	q->wr_reg = res->reg;
+	res->reg++;
+	q->rd_reg = res->reg;
+	res->reg++;
+}
+
+void *ipu6_fw_com_prepare(struct ipu6_fw_com_cfg *cfg,
+			  struct ipu6_bus_device *adev, void __iomem *base)
+{
+	size_t conf_size, inq_size, outq_size, specific_size;
+	struct ipu6_fw_syscom_config *config_host_addr;
+	unsigned int sizeinput = 0, sizeoutput = 0;
+	struct ipu6_fw_sys_queue_res res;
+	struct ipu6_fw_com_context *ctx;
+	struct device *dev = &adev->auxdev.dev;
+	size_t sizeall, offset;
+	unsigned long attrs = 0;
+	void *specific_host_addr;
+	unsigned int i;
+
+	if (!cfg || !cfg->cell_start || !cfg->cell_ready)
+		return NULL;
+
+	ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
+	if (!ctx)
+		return NULL;
+	ctx->dmem_addr = base + cfg->dmem_addr + REGMEM_OFFSET;
+	ctx->adev = adev;
+	ctx->cell_start = cfg->cell_start;
+	ctx->cell_ready = cfg->cell_ready;
+	ctx->buttress_boot_offset = cfg->buttress_boot_offset;
+	ctx->base_addr  = base;
+
+	/*
+	 * Allocate DMA mapped memory. Allocate one big chunk.
+	 */
+	/* Base cfg for FW */
+	conf_size = roundup(sizeof(struct ipu6_fw_syscom_config), 8);
+	/* Descriptions of the queues */
+	inq_size = size_mul(cfg->num_input_queues,
+			    sizeof(struct ipu6_fw_sys_queue));
+	outq_size = size_mul(cfg->num_output_queues,
+			     sizeof(struct ipu6_fw_sys_queue));
+	/* FW specific information structure */
+	specific_size = roundup(cfg->specific_size, 8);
+
+	sizeall = conf_size + inq_size + outq_size + specific_size;
+
+	for (i = 0; i < cfg->num_input_queues; i++)
+		sizeinput += size_mul(cfg->input[i].queue_size + 1,
+				      cfg->input[i].token_size);
+
+	for (i = 0; i < cfg->num_output_queues; i++)
+		sizeoutput += size_mul(cfg->output[i].queue_size + 1,
+				       cfg->output[i].token_size);
+
+	sizeall += sizeinput + sizeoutput;
+
+	ctx->dma_buffer = dma_alloc_attrs(dev, sizeall, &ctx->dma_addr,
+					  GFP_KERNEL, attrs);
+	ctx->attrs = attrs;
+	if (!ctx->dma_buffer) {
+		dev_err(dev, "failed to allocate dma memory\n");
+		kfree(ctx);
+		return NULL;
+	}
+
+	ctx->dma_size = sizeall;
+
+	config_host_addr = ctx->dma_buffer;
+	ctx->config_vied_addr = ctx->dma_addr;
+
+	offset = conf_size;
+	ctx->input_queue = ctx->dma_buffer + offset;
+	config_host_addr->input_queue = ctx->dma_addr + offset;
+	config_host_addr->num_input_queues = cfg->num_input_queues;
+
+	offset += inq_size;
+	ctx->output_queue = ctx->dma_buffer + offset;
+	config_host_addr->output_queue = ctx->dma_addr + offset;
+	config_host_addr->num_output_queues = cfg->num_output_queues;
+
+	/* copy firmware specific data */
+	offset += outq_size;
+	specific_host_addr = ctx->dma_buffer + offset;
+	config_host_addr->specific_addr = ctx->dma_addr + offset;
+	config_host_addr->specific_size = cfg->specific_size;
+	if (cfg->specific_addr && cfg->specific_size)
+		memcpy(specific_host_addr, cfg->specific_addr,
+		       cfg->specific_size);
+
+	/* initialize input queues */
+	offset += specific_size;
+	res.reg = SYSCOM_QPR_BASE_REG;
+	res.host_address = (u64)(ctx->dma_buffer + offset);
+	res.vied_address = ctx->dma_addr + offset;
+	for (i = 0; i < cfg->num_input_queues; i++)
+		ipu6_sys_queue_init(ctx->input_queue + i,
+				    cfg->input[i].queue_size,
+				    cfg->input[i].token_size, &res);
+
+	/* initialize output queues */
+	offset += sizeinput;
+	res.host_address = (u64)(ctx->dma_buffer + offset);
+	res.vied_address = ctx->dma_addr + offset;
+	for (i = 0; i < cfg->num_output_queues; i++) {
+		ipu6_sys_queue_init(ctx->output_queue + i,
+				    cfg->output[i].queue_size,
+				    cfg->output[i].token_size, &res);
+	}
+
+	return ctx;
+}
+EXPORT_SYMBOL_NS_GPL(ipu6_fw_com_prepare, INTEL_IPU6);
+
+int ipu6_fw_com_open(struct ipu6_fw_com_context *ctx)
+{
+	/* write magic pattern to disable the tunit trace */
+	writel(TUNIT_MAGIC_PATTERN, ctx->dmem_addr + TUNIT_CFG_DWR_REG * 4);
+	/* Check if SP is in valid state */
+	if (!ctx->cell_ready(ctx->adev))
+		return -EIO;
+
+	/* store syscom uninitialized command */
+	writel(SYSCOM_COMMAND_UNINIT, ctx->dmem_addr + SYSCOM_COMMAND_REG * 4);
+
+	/* store syscom uninitialized state */
+	writel(SYSCOM_STATE_UNINIT,
+	       BUTTRESS_FW_BOOT_PARAM_REG(ctx->base_addr,
+					  ctx->buttress_boot_offset,
+					  SYSCOM_STATE_ID));
+
+	/* store firmware configuration address */
+	writel(ctx->config_vied_addr,
+	       BUTTRESS_FW_BOOT_PARAM_REG(ctx->base_addr,
+					  ctx->buttress_boot_offset,
+					  SYSCOM_CONFIG_ID));
+	ctx->cell_start(ctx->adev);
+
+	return 0;
+}
+EXPORT_SYMBOL_NS_GPL(ipu6_fw_com_open, INTEL_IPU6);
+
+int ipu6_fw_com_close(struct ipu6_fw_com_context *ctx)
+{
+	int state;
+
+	state = readl(BUTTRESS_FW_BOOT_PARAM_REG(ctx->base_addr,
+						 ctx->buttress_boot_offset,
+						 SYSCOM_STATE_ID));
+	if (state != SYSCOM_STATE_READY)
+		return -EBUSY;
+
+	/* set close request flag */
+	writel(SYSCOM_COMMAND_INACTIVE, ctx->dmem_addr +
+	       SYSCOM_COMMAND_REG * 4);
+
+	return 0;
+}
+EXPORT_SYMBOL_NS_GPL(ipu6_fw_com_close, INTEL_IPU6);
+
+int ipu6_fw_com_release(struct ipu6_fw_com_context *ctx, unsigned int force)
+{
+	/* check if release is forced, an verify cell state if it is not */
+	if (!force && !ctx->cell_ready(ctx->adev))
+		return -EBUSY;
+
+	dma_free_attrs(&ctx->adev->auxdev.dev, ctx->dma_size,
+		       ctx->dma_buffer, ctx->dma_addr, ctx->attrs);
+	kfree(ctx);
+	return 0;
+}
+EXPORT_SYMBOL_NS_GPL(ipu6_fw_com_release, INTEL_IPU6);
+
+bool ipu6_fw_com_ready(struct ipu6_fw_com_context *ctx)
+{
+	int state;
+
+	state = readl(BUTTRESS_FW_BOOT_PARAM_REG(ctx->base_addr,
+						 ctx->buttress_boot_offset,
+						 SYSCOM_STATE_ID));
+
+	return state == SYSCOM_STATE_READY;
+}
+EXPORT_SYMBOL_NS_GPL(ipu6_fw_com_ready, INTEL_IPU6);
+
+void *ipu6_send_get_token(struct ipu6_fw_com_context *ctx, int q_nbr)
+{
+	struct ipu6_fw_sys_queue *q = &ctx->input_queue[q_nbr];
+	void __iomem *q_dmem = ctx->dmem_addr + q->wr_reg * 4;
+	unsigned int wr, rd;
+	unsigned int packets;
+	unsigned int index;
+
+	wr = readl(q_dmem + FW_COM_WR_REG);
+	rd = readl(q_dmem + FW_COM_RD_REG);
+
+	if (WARN_ON_ONCE(wr >= q->size || rd >= q->size))
+		return NULL;
+
+	if (wr < rd)
+		packets = rd - wr - 1;
+	else
+		packets = q->size - (wr - rd + 1);
+
+	if (!packets)
+		return NULL;
+
+	index = readl(q_dmem + FW_COM_WR_REG);
+
+	return (void *)(q->host_address + index * q->token_size);
+}
+EXPORT_SYMBOL_NS_GPL(ipu6_send_get_token, INTEL_IPU6);
+
+void ipu6_send_put_token(struct ipu6_fw_com_context *ctx, int q_nbr)
+{
+	struct ipu6_fw_sys_queue *q = &ctx->input_queue[q_nbr];
+	void __iomem *q_dmem = ctx->dmem_addr + q->wr_reg * 4;
+	unsigned int wr = readl(q_dmem + FW_COM_WR_REG) + 1;
+
+	if (wr >= q->size)
+		wr = 0;
+
+	writel(wr, q_dmem + FW_COM_WR_REG);
+}
+EXPORT_SYMBOL_NS_GPL(ipu6_send_put_token, INTEL_IPU6);
+
+void *ipu6_recv_get_token(struct ipu6_fw_com_context *ctx, int q_nbr)
+{
+	struct ipu6_fw_sys_queue *q = &ctx->output_queue[q_nbr];
+	void __iomem *q_dmem = ctx->dmem_addr + q->wr_reg * 4;
+	unsigned int wr, rd;
+	unsigned int packets;
+
+	wr = readl(q_dmem + FW_COM_WR_REG);
+	rd = readl(q_dmem + FW_COM_RD_REG);
+
+	if (WARN_ON_ONCE(wr >= q->size || rd >= q->size))
+		return NULL;
+
+	if (wr < rd)
+		wr += q->size;
+
+	packets = wr - rd;
+	if (!packets)
+		return NULL;
+
+	return (void *)(q->host_address + rd * q->token_size);
+}
+EXPORT_SYMBOL_NS_GPL(ipu6_recv_get_token, INTEL_IPU6);
+
+void ipu6_recv_put_token(struct ipu6_fw_com_context *ctx, int q_nbr)
+{
+	struct ipu6_fw_sys_queue *q = &ctx->output_queue[q_nbr];
+	void __iomem *q_dmem = ctx->dmem_addr + q->wr_reg * 4;
+	unsigned int rd = readl(q_dmem + FW_COM_RD_REG) + 1;
+
+	if (rd >= q->size)
+		rd = 0;
+
+	writel(rd, q_dmem + FW_COM_RD_REG);
+}
+EXPORT_SYMBOL_NS_GPL(ipu6_recv_put_token, INTEL_IPU6);
diff --git a/drivers/media/pci/intel/ipu6/ipu6-fw-com.h b/drivers/media/pci/intel/ipu6/ipu6-fw-com.h
new file mode 100644
index 000000000000..660c406b3ac9
--- /dev/null
+++ b/drivers/media/pci/intel/ipu6/ipu6-fw-com.h
@@ -0,0 +1,47 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/* Copyright (C) 2013 - 2023 Intel Corporation */
+
+#ifndef IPU6_FW_COM_H
+#define IPU6_FW_COM_H
+
+struct ipu6_fw_com_context;
+struct ipu6_bus_device;
+
+struct ipu6_fw_syscom_queue_config {
+	unsigned int queue_size;	/* tokens per queue */
+	unsigned int token_size;	/* bytes per token */
+};
+
+#define SYSCOM_BUTTRESS_FW_PARAMS_ISYS_OFFSET	0
+
+struct ipu6_fw_com_cfg {
+	unsigned int num_input_queues;
+	unsigned int num_output_queues;
+	struct ipu6_fw_syscom_queue_config *input;
+	struct ipu6_fw_syscom_queue_config *output;
+
+	unsigned int dmem_addr;
+
+	/* firmware-specific configuration data */
+	void *specific_addr;
+	unsigned int specific_size;
+	int (*cell_ready)(struct ipu6_bus_device *adev);
+	void (*cell_start)(struct ipu6_bus_device *adev);
+
+	unsigned int buttress_boot_offset;
+};
+
+void *ipu6_fw_com_prepare(struct ipu6_fw_com_cfg *cfg,
+			  struct ipu6_bus_device *adev, void __iomem *base);
+
+int ipu6_fw_com_open(struct ipu6_fw_com_context *ctx);
+bool ipu6_fw_com_ready(struct ipu6_fw_com_context *ctx);
+int ipu6_fw_com_close(struct ipu6_fw_com_context *ctx);
+int ipu6_fw_com_release(struct ipu6_fw_com_context *ctx, unsigned int force);
+
+void *ipu6_recv_get_token(struct ipu6_fw_com_context *ctx, int q_nbr);
+void ipu6_recv_put_token(struct ipu6_fw_com_context *ctx, int q_nbr);
+void *ipu6_send_get_token(struct ipu6_fw_com_context *ctx, int q_nbr);
+void ipu6_send_put_token(struct ipu6_fw_com_context *ctx, int q_nbr);
+
+#endif
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 86+ messages in thread

* [PATCH v2 07/15] media: intel/ipu6: input system ABI between firmware and driver
  2023-10-24 11:29 [PATCH v2 00/15] Intel IPU6 and IPU6 input system drivers bingbu.cao
                   ` (5 preceding siblings ...)
  2023-10-24 11:29 ` [PATCH v2 06/15] media: intel/ipu6: add syscom interfaces between firmware and driver bingbu.cao
@ 2023-10-24 11:29 ` bingbu.cao
  2023-10-24 11:29 ` [PATCH v2 08/15] media: intel/ipu6: add IPU6 CSI2 receiver v4l2 sub-device bingbu.cao
                   ` (9 subsequent siblings)
  16 siblings, 0 replies; 86+ messages in thread
From: bingbu.cao @ 2023-10-24 11:29 UTC (permalink / raw)
  To: linux-media, sakari.ailus, laurent.pinchart
  Cc: andriy.shevchenko, hdegoede, ilpo.jarvinen, andreaskleist,
	claus.stovgaard, tfiga, senozhatsky, tomi.valkeinen, bingbu.cao,
	bingbu.cao, tian.shu.qiu, hongju.wang

From: Bingbu Cao <bingbu.cao@intel.com>

Implement the input system firmware ABIs between the firmware and
driver - include stream configuration, control command, capture
request and response, etc.

Signed-off-by: Bingbu Cao <bingbu.cao@intel.com>
---
 drivers/media/pci/intel/ipu6/ipu6-fw-isys.c | 484 +++++++++++++++++
 drivers/media/pci/intel/ipu6/ipu6-fw-isys.h | 570 ++++++++++++++++++++
 2 files changed, 1054 insertions(+)
 create mode 100644 drivers/media/pci/intel/ipu6/ipu6-fw-isys.c
 create mode 100644 drivers/media/pci/intel/ipu6/ipu6-fw-isys.h

diff --git a/drivers/media/pci/intel/ipu6/ipu6-fw-isys.c b/drivers/media/pci/intel/ipu6/ipu6-fw-isys.c
new file mode 100644
index 000000000000..28353cb53607
--- /dev/null
+++ b/drivers/media/pci/intel/ipu6/ipu6-fw-isys.c
@@ -0,0 +1,484 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2013 - 2023 Intel Corporation
+ */
+
+#include <linux/cacheflush.h>
+#include <linux/delay.h>
+
+#include <media/mipi-csi2.h>
+
+#include "ipu6-fw-com.h"
+#include "ipu6-isys.h"
+#include "ipu6-platform-isys-csi2-reg.h"
+#include "ipu6-platform-regs.h"
+
+static const char send_msg_types[N_IPU6_FW_ISYS_SEND_TYPE][32] = {
+	"STREAM_OPEN",
+	"STREAM_START",
+	"STREAM_START_AND_CAPTURE",
+	"STREAM_CAPTURE",
+	"STREAM_STOP",
+	"STREAM_FLUSH",
+	"STREAM_CLOSE"
+};
+
+static int handle_proxy_response(struct ipu6_isys *isys, unsigned int req_id)
+{
+	struct device *dev = &isys->adev->auxdev.dev;
+	struct ipu6_fw_isys_proxy_resp_info_abi *resp;
+	int ret;
+
+	resp = ipu6_recv_get_token(isys->fwcom, IPU6_BASE_PROXY_RECV_QUEUES);
+	if (!resp)
+		return 1;
+
+	dev_dbg(dev, "Proxy response: id %u, error %u, details %u\n",
+		resp->request_id, resp->error_info.error,
+		resp->error_info.error_details);
+
+	ret = req_id == resp->request_id ? 0 : -EIO;
+
+	ipu6_recv_put_token(isys->fwcom, IPU6_BASE_PROXY_RECV_QUEUES);
+
+	return ret;
+}
+
+int ipu6_fw_isys_send_proxy_token(struct ipu6_isys *isys,
+				  unsigned int req_id,
+				  unsigned int index,
+				  unsigned int offset, u32 value)
+{
+	struct ipu6_fw_com_context *ctx = isys->fwcom;
+	struct device *dev = &isys->adev->auxdev.dev;
+	struct ipu6_fw_proxy_send_queue_token *token;
+	unsigned int timeout = 1000;
+	int ret;
+
+	dev_dbg(dev,
+		"proxy send: req_id 0x%x, index %d, offset 0x%x, value 0x%x\n",
+		req_id, index, offset, value);
+
+	token = ipu6_send_get_token(ctx, IPU6_BASE_PROXY_SEND_QUEUES);
+	if (!token)
+		return -EBUSY;
+
+	token->request_id = req_id;
+	token->region_index = index;
+	token->offset = offset;
+	token->value = value;
+	ipu6_send_put_token(ctx, IPU6_BASE_PROXY_SEND_QUEUES);
+
+	do {
+		usleep_range(100, 110);
+		ret = handle_proxy_response(isys, req_id);
+		if (!ret)
+			break;
+		if (ret == -EIO) {
+			dev_err(dev, "Proxy respond with unexpected id\n");
+			break;
+		}
+		timeout--;
+	} while (ret && timeout);
+
+	if (!timeout)
+		dev_err(dev, "Proxy response timed out\n");
+
+	return ret;
+}
+
+int ipu6_fw_isys_complex_cmd(struct ipu6_isys *isys,
+			     const unsigned int stream_handle,
+			     void *cpu_mapped_buf,
+			     dma_addr_t dma_mapped_buf,
+			     size_t size, u16 send_type)
+{
+	struct ipu6_fw_com_context *ctx = isys->fwcom;
+	struct device *dev = &isys->adev->auxdev.dev;
+	struct ipu6_fw_send_queue_token *token;
+
+	if (send_type >= N_IPU6_FW_ISYS_SEND_TYPE)
+		return -EINVAL;
+
+	dev_dbg(dev, "send_token: %s\n", send_msg_types[send_type]);
+
+	/*
+	 * Time to flush cache in case we have some payload. Not all messages
+	 * have that
+	 */
+	if (cpu_mapped_buf)
+		clflush_cache_range(cpu_mapped_buf, size);
+
+	token = ipu6_send_get_token(ctx,
+				    stream_handle + IPU6_BASE_MSG_SEND_QUEUES);
+	if (!token)
+		return -EBUSY;
+
+	token->payload = dma_mapped_buf;
+	token->buf_handle = (unsigned long)cpu_mapped_buf;
+	token->send_type = send_type;
+
+	ipu6_send_put_token(ctx, stream_handle + IPU6_BASE_MSG_SEND_QUEUES);
+
+	return 0;
+}
+
+int ipu6_fw_isys_simple_cmd(struct ipu6_isys *isys,
+			    const unsigned int stream_handle, u16 send_type)
+{
+	return ipu6_fw_isys_complex_cmd(isys, stream_handle, NULL, 0, 0,
+					send_type);
+}
+
+int ipu6_fw_isys_close(struct ipu6_isys *isys)
+{
+	struct device *dev = &isys->adev->auxdev.dev;
+	int retry = IPU6_ISYS_CLOSE_RETRY;
+	unsigned long flags;
+	void *fwcom;
+	int ret;
+
+	/*
+	 * Stop the isys fw. Actual close takes
+	 * some time as the FW must stop its actions including code fetch
+	 * to SP icache.
+	 * spinlock to wait the interrupt handler to be finished
+	 */
+	spin_lock_irqsave(&isys->power_lock, flags);
+	ret = ipu6_fw_com_close(isys->fwcom);
+	fwcom = isys->fwcom;
+	isys->fwcom = NULL;
+	spin_unlock_irqrestore(&isys->power_lock, flags);
+	if (ret)
+		dev_err(dev, "Device close failure: %d\n", ret);
+
+	/* release probably fails if the close failed. Let's try still */
+	do {
+		usleep_range(400, 500);
+		ret = ipu6_fw_com_release(fwcom, 0);
+		retry--;
+	} while (ret && retry);
+
+	if (ret) {
+		dev_err(dev, "Device release time out %d\n", ret);
+		spin_lock_irqsave(&isys->power_lock, flags);
+		isys->fwcom = fwcom;
+		spin_unlock_irqrestore(&isys->power_lock, flags);
+	}
+
+	return ret;
+}
+
+void ipu6_fw_isys_cleanup(struct ipu6_isys *isys)
+{
+	int ret;
+
+	ret = ipu6_fw_com_release(isys->fwcom, 1);
+	if (ret < 0)
+		dev_warn(&isys->adev->auxdev.dev,
+			 "Device busy, fw_com release failed.");
+	isys->fwcom = NULL;
+}
+
+static void start_sp(struct ipu6_bus_device *adev)
+{
+	struct ipu6_isys *isys = ipu6_bus_get_drvdata(adev);
+	void __iomem *spc_regs_base = isys->pdata->base +
+		isys->pdata->ipdata->hw_variant.spc_offset;
+	u32 val = IPU6_ISYS_SPC_STATUS_START |
+		IPU6_ISYS_SPC_STATUS_RUN |
+		IPU6_ISYS_SPC_STATUS_CTRL_ICACHE_INVALIDATE;
+
+	val |= isys->icache_prefetch ? IPU6_ISYS_SPC_STATUS_ICACHE_PREFETCH : 0;
+
+	writel(val, spc_regs_base + IPU6_ISYS_REG_SPC_STATUS_CTRL);
+}
+
+static int query_sp(struct ipu6_bus_device *adev)
+{
+	struct ipu6_isys *isys = ipu6_bus_get_drvdata(adev);
+	void __iomem *spc_regs_base = isys->pdata->base +
+		isys->pdata->ipdata->hw_variant.spc_offset;
+	u32 val;
+
+	val = readl(spc_regs_base + IPU6_ISYS_REG_SPC_STATUS_CTRL);
+	/* return true when READY == 1, START == 0 */
+	val &= IPU6_ISYS_SPC_STATUS_READY | IPU6_ISYS_SPC_STATUS_START;
+
+	return val == IPU6_ISYS_SPC_STATUS_READY;
+}
+
+static int ipu6_isys_fwcom_cfg_init(struct ipu6_isys *isys,
+				    struct ipu6_fw_com_cfg *fwcom,
+				    unsigned int num_streams)
+{
+	unsigned int max_send_queues, max_sram_blocks, max_devq_size;
+	struct ipu6_fw_syscom_queue_config *input_queue_cfg;
+	struct ipu6_fw_syscom_queue_config *output_queue_cfg;
+	struct device *dev = &isys->adev->auxdev.dev;
+	int type_proxy = IPU6_FW_ISYS_QUEUE_TYPE_PROXY;
+	int type_dev = IPU6_FW_ISYS_QUEUE_TYPE_DEV;
+	int type_msg = IPU6_FW_ISYS_QUEUE_TYPE_MSG;
+	int base_dev_send = IPU6_BASE_DEV_SEND_QUEUES;
+	int base_msg_send = IPU6_BASE_MSG_SEND_QUEUES;
+	int base_msg_recv = IPU6_BASE_MSG_RECV_QUEUES;
+	struct ipu6_fw_isys_fw_config *isys_fw_cfg;
+	u32 num_in_message_queues;
+	unsigned int max_streams;
+	unsigned int size;
+	unsigned int i;
+
+	max_streams = isys->pdata->ipdata->max_streams;
+	max_send_queues = isys->pdata->ipdata->max_send_queues;
+	max_sram_blocks = isys->pdata->ipdata->max_sram_blocks;
+	max_devq_size = isys->pdata->ipdata->max_devq_size;
+	num_in_message_queues = clamp(num_streams, 1U, max_streams);
+	isys_fw_cfg = devm_kzalloc(dev, sizeof(*isys_fw_cfg), GFP_KERNEL);
+	if (!isys_fw_cfg)
+		return -ENOMEM;
+
+	isys_fw_cfg->num_send_queues[type_proxy] = IPU6_N_MAX_PROXY_SEND_QUEUES;
+	isys_fw_cfg->num_send_queues[type_dev] = IPU6_N_MAX_DEV_SEND_QUEUES;
+	isys_fw_cfg->num_send_queues[type_msg] = num_in_message_queues;
+	isys_fw_cfg->num_recv_queues[type_proxy] = IPU6_N_MAX_PROXY_RECV_QUEUES;
+	/* Common msg/dev return queue */
+	isys_fw_cfg->num_recv_queues[type_dev] = 0;
+	isys_fw_cfg->num_recv_queues[type_msg] = 1;
+
+	size = sizeof(*input_queue_cfg) * max_send_queues;
+	input_queue_cfg = devm_kzalloc(dev, size, GFP_KERNEL);
+	if (!input_queue_cfg)
+		return -ENOMEM;
+
+	size = sizeof(*output_queue_cfg) * IPU6_N_MAX_RECV_QUEUES;
+	output_queue_cfg = devm_kzalloc(dev, size, GFP_KERNEL);
+	if (!output_queue_cfg)
+		return -ENOMEM;
+
+	fwcom->input = input_queue_cfg;
+	fwcom->output = output_queue_cfg;
+
+	fwcom->num_input_queues = isys_fw_cfg->num_send_queues[type_proxy] +
+		isys_fw_cfg->num_send_queues[type_dev] +
+		isys_fw_cfg->num_send_queues[type_msg];
+
+	fwcom->num_output_queues = isys_fw_cfg->num_recv_queues[type_proxy] +
+		isys_fw_cfg->num_recv_queues[type_dev] +
+		isys_fw_cfg->num_recv_queues[type_msg];
+
+	/* SRAM partitioning. Equal partitioning is set. */
+	for (i = 0; i < max_sram_blocks; i++) {
+		if (i < num_in_message_queues)
+			isys_fw_cfg->buffer_partition.num_gda_pages[i] =
+				(IPU6_DEVICE_GDA_NR_PAGES *
+				 IPU6_DEVICE_GDA_VIRT_FACTOR) /
+				num_in_message_queues;
+		else
+			isys_fw_cfg->buffer_partition.num_gda_pages[i] = 0;
+	}
+
+	/* FW assumes proxy interface at fwcom queue 0 */
+	for (i = 0; i < isys_fw_cfg->num_send_queues[type_proxy]; i++) {
+		input_queue_cfg[i].token_size =
+			sizeof(struct ipu6_fw_proxy_send_queue_token);
+		input_queue_cfg[i].queue_size = IPU6_ISYS_SIZE_PROXY_SEND_QUEUE;
+	}
+
+	for (i = 0; i < isys_fw_cfg->num_send_queues[type_dev]; i++) {
+		input_queue_cfg[base_dev_send + i].token_size =
+			sizeof(struct ipu6_fw_send_queue_token);
+		input_queue_cfg[base_dev_send + i].queue_size = max_devq_size;
+	}
+
+	for (i = 0; i < isys_fw_cfg->num_send_queues[type_msg]; i++) {
+		input_queue_cfg[base_msg_send + i].token_size =
+			sizeof(struct ipu6_fw_send_queue_token);
+		input_queue_cfg[base_msg_send + i].queue_size =
+			IPU6_ISYS_SIZE_SEND_QUEUE;
+	}
+
+	for (i = 0; i < isys_fw_cfg->num_recv_queues[type_proxy]; i++) {
+		output_queue_cfg[i].token_size =
+			sizeof(struct ipu6_fw_proxy_resp_queue_token);
+		output_queue_cfg[i].queue_size =
+			IPU6_ISYS_SIZE_PROXY_RECV_QUEUE;
+	}
+	/* There is no recv DEV queue */
+	for (i = 0; i < isys_fw_cfg->num_recv_queues[type_msg]; i++) {
+		output_queue_cfg[base_msg_recv + i].token_size =
+			sizeof(struct ipu6_fw_resp_queue_token);
+		output_queue_cfg[base_msg_recv + i].queue_size =
+			IPU6_ISYS_SIZE_RECV_QUEUE;
+	}
+
+	fwcom->dmem_addr = isys->pdata->ipdata->hw_variant.dmem_offset;
+	fwcom->specific_addr = isys_fw_cfg;
+	fwcom->specific_size = sizeof(*isys_fw_cfg);
+
+	return 0;
+}
+
+int ipu6_fw_isys_init(struct ipu6_isys *isys, unsigned int num_streams)
+{
+	struct device *dev = &isys->adev->auxdev.dev;
+	int retry = IPU6_ISYS_OPEN_RETRY;
+	struct ipu6_fw_com_cfg fwcom = {
+		.cell_start = start_sp,
+		.cell_ready = query_sp,
+		.buttress_boot_offset = SYSCOM_BUTTRESS_FW_PARAMS_ISYS_OFFSET,
+	};
+	int ret;
+
+	ipu6_isys_fwcom_cfg_init(isys, &fwcom, num_streams);
+
+	isys->fwcom = ipu6_fw_com_prepare(&fwcom, isys->adev,
+					  isys->pdata->base);
+	if (!isys->fwcom) {
+		dev_err(dev, "isys fw com prepare failed\n");
+		return -EIO;
+	}
+
+	ret = ipu6_fw_com_open(isys->fwcom);
+	if (ret) {
+		dev_err(dev, "isys fw com open failed %d\n", ret);
+		return ret;
+	}
+
+	do {
+		usleep_range(400, 500);
+		if (ipu6_fw_com_ready(isys->fwcom))
+			break;
+		retry--;
+	} while (retry > 0);
+
+	if (!retry) {
+		dev_err(dev, "isys port open ready failed %d\n", ret);
+		ipu6_fw_isys_close(isys);
+		ret = -EIO;
+	}
+
+	return ret;
+}
+
+struct ipu6_fw_isys_resp_info_abi *
+ipu6_fw_isys_get_resp(void *context, unsigned int queue)
+{
+	return ipu6_recv_get_token(context, queue);
+}
+
+void ipu6_fw_isys_put_resp(void *context, unsigned int queue)
+{
+	ipu6_recv_put_token(context, queue);
+}
+
+void ipu6_fw_isys_dump_stream_cfg(struct device *dev,
+				  struct ipu6_fw_isys_stream_cfg_data_abi *cfg)
+{
+	unsigned int i;
+
+	dev_dbg(dev, "-----------------------------------------------------\n");
+	dev_dbg(dev, "IPU6_FW_ISYS_STREAM_CFG_DATA\n");
+
+	dev_dbg(dev, "compfmt = %d\n", cfg->vc);
+	dev_dbg(dev, "src = %d\n", cfg->src);
+	dev_dbg(dev, "vc = %d\n", cfg->vc);
+	dev_dbg(dev, "isl_use = %d\n", cfg->isl_use);
+	dev_dbg(dev, "sensor_type = %d\n", cfg->sensor_type);
+
+	dev_dbg(dev, "send_irq_sof_discarded = %d\n",
+		cfg->send_irq_sof_discarded);
+	dev_dbg(dev, "send_irq_eof_discarded = %d\n",
+		cfg->send_irq_eof_discarded);
+	dev_dbg(dev, "send_resp_sof_discarded = %d\n",
+		cfg->send_resp_sof_discarded);
+	dev_dbg(dev, "send_resp_eof_discarded = %d\n",
+		cfg->send_resp_eof_discarded);
+
+	dev_dbg(dev, "crop:\n");
+	dev_dbg(dev, "\t.left_top = [%d, %d]\n", cfg->crop.left_offset,
+		cfg->crop.top_offset);
+	dev_dbg(dev, "\t.right_bottom = [%d, %d]\n", cfg->crop.right_offset,
+		cfg->crop.bottom_offset);
+
+	dev_dbg(dev, "nof_input_pins = %d\n", cfg->nof_input_pins);
+	for (i = 0; i < cfg->nof_input_pins; i++) {
+		dev_dbg(dev, "input pin[%d]:\n", i);
+		dev_dbg(dev, "\t.dt = 0x%0x\n", cfg->input_pins[i].dt);
+		dev_dbg(dev, "\t.mipi_store_mode = %d\n",
+			cfg->input_pins[i].mipi_store_mode);
+		dev_dbg(dev, "\t.bits_per_pix = %d\n",
+			cfg->input_pins[i].bits_per_pix);
+		dev_dbg(dev, "\t.mapped_dt = 0x%0x\n",
+			cfg->input_pins[i].mapped_dt);
+		dev_dbg(dev, "\t.input_res = %dx%d\n",
+			cfg->input_pins[i].input_res.width,
+			cfg->input_pins[i].input_res.height);
+		dev_dbg(dev, "\t.mipi_decompression = %d\n",
+			cfg->input_pins[i].mipi_decompression);
+		dev_dbg(dev, "\t.capture_mode = %d\n",
+			cfg->input_pins[i].capture_mode);
+	}
+
+	dev_dbg(dev, "nof_output_pins = %d\n", cfg->nof_output_pins);
+	for (i = 0; i < cfg->nof_output_pins; i++) {
+		dev_dbg(dev, "output_pin[%d]:\n", i);
+		dev_dbg(dev, "\t.input_pin_id = %d\n",
+			cfg->output_pins[i].input_pin_id);
+		dev_dbg(dev, "\t.output_res = %dx%d\n",
+			cfg->output_pins[i].output_res.width,
+			cfg->output_pins[i].output_res.height);
+		dev_dbg(dev, "\t.stride = %d\n", cfg->output_pins[i].stride);
+		dev_dbg(dev, "\t.pt = %d\n", cfg->output_pins[i].pt);
+		dev_dbg(dev, "\t.payload_buf_size = %d\n",
+			cfg->output_pins[i].payload_buf_size);
+		dev_dbg(dev, "\t.ft = %d\n", cfg->output_pins[i].ft);
+		dev_dbg(dev, "\t.watermark_in_lines = %d\n",
+			cfg->output_pins[i].watermark_in_lines);
+		dev_dbg(dev, "\t.send_irq = %d\n",
+			cfg->output_pins[i].send_irq);
+		dev_dbg(dev, "\t.reserve_compression = %d\n",
+			cfg->output_pins[i].reserve_compression);
+		dev_dbg(dev, "\t.snoopable = %d\n",
+			cfg->output_pins[i].snoopable);
+		dev_dbg(dev, "\t.error_handling_enable = %d\n",
+			cfg->output_pins[i].error_handling_enable);
+		dev_dbg(dev, "\t.sensor_type = %d\n",
+			cfg->output_pins[i].sensor_type);
+	}
+	dev_dbg(dev, "-----------------------------------------------------\n");
+}
+
+void
+ipu6_fw_isys_dump_frame_buff_set(struct device *dev,
+				 struct ipu6_fw_isys_frame_buff_set_abi *buf,
+				 unsigned int outputs)
+{
+	unsigned int i;
+
+	dev_dbg(dev, "-----------------------------------------------------\n");
+	dev_dbg(dev, "IPU6_FW_ISYS_FRAME_BUFF_SET\n");
+
+	for (i = 0; i < outputs; i++) {
+		dev_dbg(dev, "output_pin[%d]:\n", i);
+		dev_dbg(dev, "\t.out_buf_id = %llu\n",
+			buf->output_pins[i].out_buf_id);
+		dev_dbg(dev, "\t.addr = 0x%x\n", buf->output_pins[i].addr);
+		dev_dbg(dev, "\t.compress = %d\n",
+			buf->output_pins[i].compress);
+	}
+
+	dev_dbg(dev, "send_irq_sof = 0x%x\n", buf->send_irq_sof);
+	dev_dbg(dev, "send_irq_eof = 0x%x\n", buf->send_irq_eof);
+	dev_dbg(dev, "send_resp_sof = 0x%x\n", buf->send_resp_sof);
+	dev_dbg(dev, "send_resp_eof = 0x%x\n", buf->send_resp_eof);
+	dev_dbg(dev, "send_irq_capture_ack = 0x%x\n",
+		buf->send_irq_capture_ack);
+	dev_dbg(dev, "send_irq_capture_done = 0x%x\n",
+		buf->send_irq_capture_done);
+	dev_dbg(dev, "send_resp_capture_ack = 0x%x\n",
+		buf->send_resp_capture_ack);
+	dev_dbg(dev, "send_resp_capture_done = 0x%x\n",
+		buf->send_resp_capture_done);
+
+	dev_dbg(dev, "-----------------------------------------------------\n");
+}
diff --git a/drivers/media/pci/intel/ipu6/ipu6-fw-isys.h b/drivers/media/pci/intel/ipu6/ipu6-fw-isys.h
new file mode 100644
index 000000000000..772d779332ba
--- /dev/null
+++ b/drivers/media/pci/intel/ipu6/ipu6-fw-isys.h
@@ -0,0 +1,570 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/* Copyright (C) 2013 - 2023 Intel Corporation */
+
+#ifndef IPU6_FW_ISYS_H
+#define IPU6_FW_ISYS_H
+
+struct ipu6_isys;
+
+/* Max number of Input/Output Pins */
+#define IPU6_MAX_IPINS 4
+
+#define IPU6_MAX_OPINS ((IPU6_MAX_IPINS) + 1)
+
+#define IPU6_STREAM_ID_MAX 16
+#define IPU6_NONSECURE_STREAM_ID_MAX 12
+#define IPU6_DEV_SEND_QUEUE_SIZE (IPU6_STREAM_ID_MAX)
+#define IPU6_NOF_SRAM_BLOCKS_MAX (IPU6_STREAM_ID_MAX)
+#define IPU6_N_MAX_MSG_SEND_QUEUES (IPU6_STREAM_ID_MAX)
+#define IPU6SE_STREAM_ID_MAX 8
+#define IPU6SE_NONSECURE_STREAM_ID_MAX 4
+#define IPU6SE_DEV_SEND_QUEUE_SIZE (IPU6SE_STREAM_ID_MAX)
+#define IPU6SE_NOF_SRAM_BLOCKS_MAX (IPU6SE_STREAM_ID_MAX)
+#define IPU6SE_N_MAX_MSG_SEND_QUEUES (IPU6SE_STREAM_ID_MAX)
+
+/* Single return queue for all streams/commands type */
+#define IPU6_N_MAX_MSG_RECV_QUEUES 1
+/* Single device queue for high priority commands (bypass in-order queue) */
+#define IPU6_N_MAX_DEV_SEND_QUEUES 1
+/* Single dedicated send queue for proxy interface */
+#define IPU6_N_MAX_PROXY_SEND_QUEUES 1
+/* Single dedicated recv queue for proxy interface */
+#define IPU6_N_MAX_PROXY_RECV_QUEUES 1
+/* Send queues layout */
+#define IPU6_BASE_PROXY_SEND_QUEUES 0
+#define IPU6_BASE_DEV_SEND_QUEUES \
+	(IPU6_BASE_PROXY_SEND_QUEUES + IPU6_N_MAX_PROXY_SEND_QUEUES)
+#define IPU6_BASE_MSG_SEND_QUEUES \
+	(IPU6_BASE_DEV_SEND_QUEUES + IPU6_N_MAX_DEV_SEND_QUEUES)
+/* Recv queues layout */
+#define IPU6_BASE_PROXY_RECV_QUEUES 0
+#define IPU6_BASE_MSG_RECV_QUEUES \
+	(IPU6_BASE_PROXY_RECV_QUEUES + IPU6_N_MAX_PROXY_RECV_QUEUES)
+#define IPU6_N_MAX_RECV_QUEUES \
+	(IPU6_BASE_MSG_RECV_QUEUES + IPU6_N_MAX_MSG_RECV_QUEUES)
+
+#define IPU6_N_MAX_SEND_QUEUES \
+	(IPU6_BASE_MSG_SEND_QUEUES + IPU6_N_MAX_MSG_SEND_QUEUES)
+#define IPU6SE_N_MAX_SEND_QUEUES \
+	(IPU6_BASE_MSG_SEND_QUEUES + IPU6SE_N_MAX_MSG_SEND_QUEUES)
+
+/* Max number of supported input pins routed in ISL */
+#define IPU6_MAX_IPINS_IN_ISL 2
+
+/* Max number of planes for frame formats supported by the FW */
+#define IPU6_PIN_PLANES_MAX 4
+
+#define IPU6_FW_ISYS_SENSOR_TYPE_START 14
+#define IPU6_FW_ISYS_SENSOR_TYPE_END 19
+#define IPU6SE_FW_ISYS_SENSOR_TYPE_START 6
+#define IPU6SE_FW_ISYS_SENSOR_TYPE_END 11
+/*
+ * Device close takes some time from last ack message to actual stopping
+ * of the SP processor. As long as the SP processor runs we can't proceed with
+ * clean up of resources.
+ */
+#define IPU6_ISYS_OPEN_RETRY			2000
+#define IPU6_ISYS_CLOSE_RETRY			2000
+#define IPU6_FW_CALL_TIMEOUT_JIFFIES		msecs_to_jiffies(2000)
+
+enum ipu6_fw_isys_resp_type {
+	IPU6_FW_ISYS_RESP_TYPE_STREAM_OPEN_DONE = 0,
+	IPU6_FW_ISYS_RESP_TYPE_STREAM_START_ACK,
+	IPU6_FW_ISYS_RESP_TYPE_STREAM_START_AND_CAPTURE_ACK,
+	IPU6_FW_ISYS_RESP_TYPE_STREAM_CAPTURE_ACK,
+	IPU6_FW_ISYS_RESP_TYPE_STREAM_STOP_ACK,
+	IPU6_FW_ISYS_RESP_TYPE_STREAM_FLUSH_ACK,
+	IPU6_FW_ISYS_RESP_TYPE_STREAM_CLOSE_ACK,
+	IPU6_FW_ISYS_RESP_TYPE_PIN_DATA_READY,
+	IPU6_FW_ISYS_RESP_TYPE_PIN_DATA_WATERMARK,
+	IPU6_FW_ISYS_RESP_TYPE_FRAME_SOF,
+	IPU6_FW_ISYS_RESP_TYPE_FRAME_EOF,
+	IPU6_FW_ISYS_RESP_TYPE_STREAM_START_AND_CAPTURE_DONE,
+	IPU6_FW_ISYS_RESP_TYPE_STREAM_CAPTURE_DONE,
+	IPU6_FW_ISYS_RESP_TYPE_PIN_DATA_SKIPPED,
+	IPU6_FW_ISYS_RESP_TYPE_STREAM_CAPTURE_SKIPPED,
+	IPU6_FW_ISYS_RESP_TYPE_FRAME_SOF_DISCARDED,
+	IPU6_FW_ISYS_RESP_TYPE_FRAME_EOF_DISCARDED,
+	IPU6_FW_ISYS_RESP_TYPE_STATS_DATA_READY,
+	N_IPU6_FW_ISYS_RESP_TYPE
+};
+
+enum ipu6_fw_isys_send_type {
+	IPU6_FW_ISYS_SEND_TYPE_STREAM_OPEN = 0,
+	IPU6_FW_ISYS_SEND_TYPE_STREAM_START,
+	IPU6_FW_ISYS_SEND_TYPE_STREAM_START_AND_CAPTURE,
+	IPU6_FW_ISYS_SEND_TYPE_STREAM_CAPTURE,
+	IPU6_FW_ISYS_SEND_TYPE_STREAM_STOP,
+	IPU6_FW_ISYS_SEND_TYPE_STREAM_FLUSH,
+	IPU6_FW_ISYS_SEND_TYPE_STREAM_CLOSE,
+	N_IPU6_FW_ISYS_SEND_TYPE
+};
+
+enum ipu6_fw_isys_queue_type {
+	IPU6_FW_ISYS_QUEUE_TYPE_PROXY = 0,
+	IPU6_FW_ISYS_QUEUE_TYPE_DEV,
+	IPU6_FW_ISYS_QUEUE_TYPE_MSG,
+	N_IPU6_FW_ISYS_QUEUE_TYPE
+};
+
+enum ipu6_fw_isys_stream_source {
+	IPU6_FW_ISYS_STREAM_SRC_PORT_0 = 0,
+	IPU6_FW_ISYS_STREAM_SRC_PORT_1,
+	IPU6_FW_ISYS_STREAM_SRC_PORT_2,
+	IPU6_FW_ISYS_STREAM_SRC_PORT_3,
+	IPU6_FW_ISYS_STREAM_SRC_PORT_4,
+	IPU6_FW_ISYS_STREAM_SRC_PORT_5,
+	IPU6_FW_ISYS_STREAM_SRC_PORT_6,
+	IPU6_FW_ISYS_STREAM_SRC_PORT_7,
+	IPU6_FW_ISYS_STREAM_SRC_PORT_8,
+	IPU6_FW_ISYS_STREAM_SRC_PORT_9,
+	IPU6_FW_ISYS_STREAM_SRC_PORT_10,
+	IPU6_FW_ISYS_STREAM_SRC_PORT_11,
+	IPU6_FW_ISYS_STREAM_SRC_PORT_12,
+	IPU6_FW_ISYS_STREAM_SRC_PORT_13,
+	IPU6_FW_ISYS_STREAM_SRC_PORT_14,
+	IPU6_FW_ISYS_STREAM_SRC_PORT_15,
+	IPU6_FW_ISYS_STREAM_SRC_MIPIGEN_0,
+	IPU6_FW_ISYS_STREAM_SRC_MIPIGEN_1,
+	IPU6_FW_ISYS_STREAM_SRC_MIPIGEN_2,
+	IPU6_FW_ISYS_STREAM_SRC_MIPIGEN_3,
+	IPU6_FW_ISYS_STREAM_SRC_MIPIGEN_4,
+	IPU6_FW_ISYS_STREAM_SRC_MIPIGEN_5,
+	IPU6_FW_ISYS_STREAM_SRC_MIPIGEN_6,
+	IPU6_FW_ISYS_STREAM_SRC_MIPIGEN_7,
+	IPU6_FW_ISYS_STREAM_SRC_MIPIGEN_8,
+	IPU6_FW_ISYS_STREAM_SRC_MIPIGEN_9,
+	N_IPU6_FW_ISYS_STREAM_SRC
+};
+
+#define IPU6_FW_ISYS_STREAM_SRC_CSI2_PORT0 IPU6_FW_ISYS_STREAM_SRC_PORT_0
+#define IPU6_FW_ISYS_STREAM_SRC_CSI2_PORT1 IPU6_FW_ISYS_STREAM_SRC_PORT_1
+#define IPU6_FW_ISYS_STREAM_SRC_CSI2_PORT2 IPU6_FW_ISYS_STREAM_SRC_PORT_2
+#define IPU6_FW_ISYS_STREAM_SRC_CSI2_PORT3 IPU6_FW_ISYS_STREAM_SRC_PORT_3
+
+#define IPU6_FW_ISYS_STREAM_SRC_CSI2_3PH_PORTA IPU6_FW_ISYS_STREAM_SRC_PORT_4
+#define IPU6_FW_ISYS_STREAM_SRC_CSI2_3PH_PORTB IPU6_FW_ISYS_STREAM_SRC_PORT_5
+#define IPU6_FW_ISYS_STREAM_SRC_CSI2_3PH_CPHY_PORT0 \
+	IPU6_FW_ISYS_STREAM_SRC_PORT_6
+#define IPU6_FW_ISYS_STREAM_SRC_CSI2_3PH_CPHY_PORT1 \
+	IPU6_FW_ISYS_STREAM_SRC_PORT_7
+#define IPU6_FW_ISYS_STREAM_SRC_CSI2_3PH_CPHY_PORT2 \
+	IPU6_FW_ISYS_STREAM_SRC_PORT_8
+#define IPU6_FW_ISYS_STREAM_SRC_CSI2_3PH_CPHY_PORT3 \
+	IPU6_FW_ISYS_STREAM_SRC_PORT_9
+
+#define IPU6_FW_ISYS_STREAM_SRC_MIPIGEN_PORT0 IPU6_FW_ISYS_STREAM_SRC_MIPIGEN_0
+#define IPU6_FW_ISYS_STREAM_SRC_MIPIGEN_PORT1 IPU6_FW_ISYS_STREAM_SRC_MIPIGEN_1
+
+/**
+ * enum ipu6_fw_isys_mipi_vc: MIPI csi2 spec
+ * supports up to 4 virtual per physical channel
+ */
+enum ipu6_fw_isys_mipi_vc {
+	IPU6_FW_ISYS_MIPI_VC_0 = 0,
+	IPU6_FW_ISYS_MIPI_VC_1,
+	IPU6_FW_ISYS_MIPI_VC_2,
+	IPU6_FW_ISYS_MIPI_VC_3,
+	N_IPU6_FW_ISYS_MIPI_VC
+};
+
+enum ipu6_fw_isys_frame_format_type {
+	IPU6_FW_ISYS_FRAME_FORMAT_NV11 = 0, /* 12 bit YUV 411, Y, UV plane */
+	IPU6_FW_ISYS_FRAME_FORMAT_NV12,	/* 12 bit YUV 420, Y, UV plane */
+	IPU6_FW_ISYS_FRAME_FORMAT_NV12_16, /* 16 bit YUV 420, Y, UV plane */
+	/* 12 bit YUV 420, Intel proprietary tiled format */
+	IPU6_FW_ISYS_FRAME_FORMAT_NV12_TILEY,
+
+	IPU6_FW_ISYS_FRAME_FORMAT_NV16,	/* 16 bit YUV 422, Y, UV plane */
+	IPU6_FW_ISYS_FRAME_FORMAT_NV21,	/* 12 bit YUV 420, Y, VU plane */
+	IPU6_FW_ISYS_FRAME_FORMAT_NV61,	/* 16 bit YUV 422, Y, VU plane */
+	IPU6_FW_ISYS_FRAME_FORMAT_YV12,	/* 12 bit YUV 420, Y, V, U plane */
+	IPU6_FW_ISYS_FRAME_FORMAT_YV16,	/* 16 bit YUV 422, Y, V, U plane */
+	IPU6_FW_ISYS_FRAME_FORMAT_YUV420, /* 12 bit YUV 420, Y, U, V plane */
+	IPU6_FW_ISYS_FRAME_FORMAT_YUV420_10, /* yuv420, 10 bits per subpixel */
+	IPU6_FW_ISYS_FRAME_FORMAT_YUV420_12, /* yuv420, 12 bits per subpixel */
+	IPU6_FW_ISYS_FRAME_FORMAT_YUV420_14, /* yuv420, 14 bits per subpixel */
+	IPU6_FW_ISYS_FRAME_FORMAT_YUV420_16, /* yuv420, 16 bits per subpixel */
+	IPU6_FW_ISYS_FRAME_FORMAT_YUV422, /* 16 bit YUV 422, Y, U, V plane */
+	IPU6_FW_ISYS_FRAME_FORMAT_YUV422_16, /* yuv422, 16 bits per subpixel */
+	IPU6_FW_ISYS_FRAME_FORMAT_UYVY,	/* 16 bit YUV 422, UYVY interleaved */
+	IPU6_FW_ISYS_FRAME_FORMAT_YUYV,	/* 16 bit YUV 422, YUYV interleaved */
+	IPU6_FW_ISYS_FRAME_FORMAT_YUV444, /* 24 bit YUV 444, Y, U, V plane */
+	/* Internal format, 2 y lines followed by a uvinterleaved line */
+	IPU6_FW_ISYS_FRAME_FORMAT_YUV_LINE,
+	IPU6_FW_ISYS_FRAME_FORMAT_RAW8,	/* RAW8, 1 plane */
+	IPU6_FW_ISYS_FRAME_FORMAT_RAW10, /* RAW10, 1 plane */
+	IPU6_FW_ISYS_FRAME_FORMAT_RAW12, /* RAW12, 1 plane */
+	IPU6_FW_ISYS_FRAME_FORMAT_RAW14, /* RAW14, 1 plane */
+	IPU6_FW_ISYS_FRAME_FORMAT_RAW16, /* RAW16, 1 plane */
+	/**
+	 * 16 bit RGB, 1 plane. Each 3 sub pixels are packed into one 16 bit
+	 * value, 5 bits for R, 6 bits for G and 5 bits for B.
+	 */
+	IPU6_FW_ISYS_FRAME_FORMAT_RGB565,
+	IPU6_FW_ISYS_FRAME_FORMAT_PLANAR_RGB888, /* 24 bit RGB, 3 planes */
+	IPU6_FW_ISYS_FRAME_FORMAT_RGBA888, /* 32 bit RGBA, 1 plane, A=Alpha */
+	IPU6_FW_ISYS_FRAME_FORMAT_QPLANE6, /* Internal, for advanced ISP */
+	IPU6_FW_ISYS_FRAME_FORMAT_BINARY_8, /* byte stream, used for jpeg. */
+	N_IPU6_FW_ISYS_FRAME_FORMAT
+};
+
+#define IPU6_FW_ISYS_FRAME_FORMAT_RAW	(IPU6_FW_ISYS_FRAME_FORMAT_RAW16)
+
+enum ipu6_fw_isys_pin_type {
+	/* captured as MIPI packets */
+	IPU6_FW_ISYS_PIN_TYPE_MIPI = 0,
+	/* captured through the SoC path */
+	IPU6_FW_ISYS_PIN_TYPE_RAW_SOC = 3,
+};
+
+/**
+ * enum ipu6_fw_isys_mipi_store_mode. Describes if long MIPI packets reach
+ * MIPI SRAM with the long packet header or
+ * if not, then only option is to capture it with pin type MIPI.
+ */
+enum ipu6_fw_isys_mipi_store_mode {
+	IPU6_FW_ISYS_MIPI_STORE_MODE_NORMAL = 0,
+	IPU6_FW_ISYS_MIPI_STORE_MODE_DISCARD_LONG_HEADER,
+	N_IPU6_FW_ISYS_MIPI_STORE_MODE
+};
+
+enum ipu6_fw_isys_capture_mode {
+	IPU6_FW_ISYS_CAPTURE_MODE_REGULAR = 0,
+	IPU6_FW_ISYS_CAPTURE_MODE_BURST,
+	N_IPU6_FW_ISYS_CAPTURE_MODE,
+};
+
+enum ipu6_fw_isys_sensor_mode {
+	IPU6_FW_ISYS_SENSOR_MODE_NORMAL = 0,
+	IPU6_FW_ISYS_SENSOR_MODE_TOBII,
+	N_IPU6_FW_ISYS_SENSOR_MODE,
+};
+
+enum ipu6_fw_isys_error {
+	IPU6_FW_ISYS_ERROR_NONE = 0,
+	IPU6_FW_ISYS_ERROR_FW_INTERNAL_CONSISTENCY,
+	IPU6_FW_ISYS_ERROR_HW_CONSISTENCY,
+	IPU6_FW_ISYS_ERROR_DRIVER_INVALID_COMMAND_SEQUENCE,
+	IPU6_FW_ISYS_ERROR_DRIVER_INVALID_DEVICE_CONFIGURATION,
+	IPU6_FW_ISYS_ERROR_DRIVER_INVALID_STREAM_CONFIGURATION,
+	IPU6_FW_ISYS_ERROR_DRIVER_INVALID_FRAME_CONFIGURATION,
+	IPU6_FW_ISYS_ERROR_INSUFFICIENT_RESOURCES,
+	IPU6_FW_ISYS_ERROR_HW_REPORTED_STR2MMIO,
+	IPU6_FW_ISYS_ERROR_HW_REPORTED_SIG2CIO,
+	IPU6_FW_ISYS_ERROR_SENSOR_FW_SYNC,
+	IPU6_FW_ISYS_ERROR_STREAM_IN_SUSPENSION,
+	IPU6_FW_ISYS_ERROR_RESPONSE_QUEUE_FULL,
+	N_IPU6_FW_ISYS_ERROR
+};
+
+enum ipu6_fw_proxy_error {
+	IPU6_FW_PROXY_ERROR_NONE = 0,
+	IPU6_FW_PROXY_ERROR_INVALID_WRITE_REGION,
+	IPU6_FW_PROXY_ERROR_INVALID_WRITE_OFFSET,
+	N_IPU6_FW_PROXY_ERROR
+};
+
+/* firmware ABI structure below are aligned in firmware, no need pack */
+struct ipu6_fw_isys_buffer_partition_abi {
+	u32 num_gda_pages[IPU6_STREAM_ID_MAX];
+};
+
+struct ipu6_fw_isys_fw_config {
+	struct ipu6_fw_isys_buffer_partition_abi buffer_partition;
+	u32 num_send_queues[N_IPU6_FW_ISYS_QUEUE_TYPE];
+	u32 num_recv_queues[N_IPU6_FW_ISYS_QUEUE_TYPE];
+};
+
+/**
+ * struct ipu6_fw_isys_resolution_abi: Generic resolution structure.
+ */
+struct ipu6_fw_isys_resolution_abi {
+	u32 width;
+	u32 height;
+};
+
+/**
+ * struct ipu6_fw_isys_output_pin_payload_abi
+ * @out_buf_id: Points to output pin buffer - buffer identifier
+ * @addr: Points to output pin buffer - CSS Virtual Address
+ * @compress: Request frame compression (1), or  not (0)
+ */
+struct ipu6_fw_isys_output_pin_payload_abi {
+	u64 out_buf_id;
+	u32 addr;
+	u32 compress;
+};
+
+/**
+ * struct ipu6_fw_isys_output_pin_info_abi
+ * @output_res: output pin resolution
+ * @stride: output stride in Bytes (not valid for statistics)
+ * @watermark_in_lines: pin watermark level in lines
+ * @payload_buf_size: minimum size in Bytes of all buffers that will be
+ *			supplied for capture on this pin
+ * @send_irq: assert if pin event should trigger irq
+ * @pt: pin type -real format "enum ipu6_fw_isys_pin_type"
+ * @ft: frame format type -real format "enum ipu6_fw_isys_frame_format_type"
+ * @input_pin_id: related input pin id
+ * @reserve_compression: reserve compression resources for pin
+ */
+struct ipu6_fw_isys_output_pin_info_abi {
+	struct ipu6_fw_isys_resolution_abi output_res;
+	u32 stride;
+	u32 watermark_in_lines;
+	u32 payload_buf_size;
+	u32 ts_offsets[IPU6_PIN_PLANES_MAX];
+	u32 s2m_pixel_soc_pixel_remapping;
+	u32 csi_be_soc_pixel_remapping;
+	u8 send_irq;
+	u8 input_pin_id;
+	u8 pt;
+	u8 ft;
+	u8 reserved;
+	u8 reserve_compression;
+	u8 snoopable;
+	u8 error_handling_enable;
+	u32 sensor_type;
+};
+
+/**
+ * struct ipu6_fw_isys_input_pin_info_abi
+ * @input_res: input resolution
+ * @dt: mipi data type ((enum ipu6_fw_isys_mipi_data_type)
+ * @mipi_store_mode: defines if legacy long packet header will be stored or
+ *		     discarded if discarded, output pin type for this
+ *		     input pin can only be MIPI
+ *		     (enum ipu6_fw_isys_mipi_store_mode)
+ * @bits_per_pix: native bits per pixel
+ * @mapped_dt: actual data type from sensor
+ * @mipi_decompression: defines which compression will be in mipi backend
+ * @crop_first_and_last_lines    Control whether to crop the
+ *                              first and last line of the
+ *                              input image. Crop done by HW
+ *                              device.
+ * @capture_mode: mode of capture, regular or burst, default value is regular
+ */
+struct ipu6_fw_isys_input_pin_info_abi {
+	struct ipu6_fw_isys_resolution_abi input_res;
+	u8 dt;
+	u8 mipi_store_mode;
+	u8 bits_per_pix;
+	u8 mapped_dt;
+	u8 mipi_decompression;
+	u8 crop_first_and_last_lines;
+	u8 capture_mode;
+	u8 reserved;
+};
+
+/**
+ * struct ipu6_fw_isys_cropping_abi - cropping coordinates
+ */
+struct ipu6_fw_isys_cropping_abi {
+	s32 top_offset;
+	s32 left_offset;
+	s32 bottom_offset;
+	s32 right_offset;
+};
+
+/**
+ * struct ipu6_fw_isys_stream_cfg_data_abi
+ * ISYS stream configuration data structure
+ * @crop: for extended use and is not used in FW currently
+ * @input_pins: input pin descriptors
+ * @output_pins: output pin descriptors
+ * @compfmt: de-compression setting for User Defined Data
+ * @nof_input_pins: number of input pins
+ * @nof_output_pins: number of output pins
+ * @send_irq_sof_discarded: send irq on discarded frame sof response
+ *		- if '1' it will override the send_resp_sof_discarded
+ *		  and send the response
+ *		- if '0' the send_resp_sof_discarded will determine
+ *		  whether to send the response
+ * @send_irq_eof_discarded: send irq on discarded frame eof response
+ *		- if '1' it will override the send_resp_eof_discarded
+ *		  and send the response
+ *		- if '0' the send_resp_eof_discarded will determine
+ *		  whether to send the response
+ * @send_resp_sof_discarded: send response for discarded frame sof detected,
+ *			     used only when send_irq_sof_discarded is '0'
+ * @send_resp_eof_discarded: send response for discarded frame eof detected,
+ *			     used only when send_irq_eof_discarded is '0'
+ * @src: Stream source index e.g. MIPI_generator_0, CSI2-rx_1
+ * @vc: MIPI Virtual Channel (up to 4 virtual per physical channel)
+ * @isl_use: indicates whether stream requires ISL and how
+ * @sensor_type: type of connected sensor, tobii or others, default is 0
+ */
+struct ipu6_fw_isys_stream_cfg_data_abi {
+	struct ipu6_fw_isys_cropping_abi crop;
+	struct ipu6_fw_isys_input_pin_info_abi input_pins[IPU6_MAX_IPINS];
+	struct ipu6_fw_isys_output_pin_info_abi output_pins[IPU6_MAX_OPINS];
+	u32 compfmt;
+	u8 nof_input_pins;
+	u8 nof_output_pins;
+	u8 send_irq_sof_discarded;
+	u8 send_irq_eof_discarded;
+	u8 send_resp_sof_discarded;
+	u8 send_resp_eof_discarded;
+	u8 src;
+	u8 vc;
+	u8 isl_use;
+	u8 sensor_type;
+	u8 reserved;
+	u8 reserved2;
+};
+
+/**
+ * struct ipu6_fw_isys_frame_buff_set - frame buffer set
+ * @output_pins: output pin addresses
+ * @send_irq_sof: send irq on frame sof response
+ *		- if '1' it will override the send_resp_sof and
+ *		  send the response
+ *		- if '0' the send_resp_sof will determine whether to
+ *		  send the response
+ * @send_irq_eof: send irq on frame eof response
+ *		- if '1' it will override the send_resp_eof and
+ *		  send the response
+ *		- if '0' the send_resp_eof will determine whether to
+ *		  send the response
+ * @send_resp_sof: send response for frame sof detected,
+ *		   used only when send_irq_sof is '0'
+ * @send_resp_eof: send response for frame eof detected,
+ *		   used only when send_irq_eof is '0'
+ * @send_resp_capture_ack: send response for capture ack event
+ * @send_resp_capture_done: send response for capture done event
+ */
+struct ipu6_fw_isys_frame_buff_set_abi {
+	struct ipu6_fw_isys_output_pin_payload_abi output_pins[IPU6_MAX_OPINS];
+	u8 send_irq_sof;
+	u8 send_irq_eof;
+	u8 send_irq_capture_ack;
+	u8 send_irq_capture_done;
+	u8 send_resp_sof;
+	u8 send_resp_eof;
+	u8 send_resp_capture_ack;
+	u8 send_resp_capture_done;
+	u8 reserved[8];
+};
+
+/**
+ * struct ipu6_fw_isys_error_info_abi
+ * @error: error code if something went wrong
+ * @error_details: depending on error code, it may contain additional error info
+ */
+struct ipu6_fw_isys_error_info_abi {
+	u32 error;
+	u32 error_details;
+};
+
+/**
+ * struct ipu6_fw_isys_resp_info_comm
+ * @pin: this var is only valid for pin event related responses,
+ *     contains pin addresses
+ * @error_info: error information from the FW
+ * @timestamp: Time information for event if available
+ * @stream_handle: stream id the response corresponds to
+ * @type: response type (enum ipu6_fw_isys_resp_type)
+ * @pin_id: pin id that the pin payload corresponds to
+ */
+struct ipu6_fw_isys_resp_info_abi {
+	u64 buf_id;
+	struct ipu6_fw_isys_output_pin_payload_abi pin;
+	struct ipu6_fw_isys_error_info_abi error_info;
+	u32 timestamp[2];
+	u8 stream_handle;
+	u8 type;
+	u8 pin_id;
+	u8 reserved;
+	u32 reserved2;
+};
+
+/**
+ * struct ipu6_fw_isys_proxy_error_info_comm
+ * @proxy_error: error code if something went wrong
+ * @proxy_error_details: depending on error code, it may contain additional
+ *			error info
+ */
+struct ipu6_fw_isys_proxy_error_info_abi {
+	u32 error;
+	u32 error_details;
+};
+
+struct ipu6_fw_isys_proxy_resp_info_abi {
+	u32 request_id;
+	struct ipu6_fw_isys_proxy_error_info_abi error_info;
+};
+
+/**
+ * struct ipu6_fw_proxy_write_queue_token
+ * @request_id: update id for the specific proxy write request
+ * @region_index: Region id for the proxy write request
+ * @offset: Offset of the write request according to the base address
+ *	    of the region
+ * @value: Value that is requested to be written with the proxy write request
+ */
+struct ipu6_fw_proxy_write_queue_token {
+	u32 request_id;
+	u32 region_index;
+	u32 offset;
+	u32 value;
+};
+
+/**
+ * struct ipu6_fw_resp_queue_token
+ */
+struct ipu6_fw_resp_queue_token {
+	struct ipu6_fw_isys_resp_info_abi resp_info;
+};
+
+/**
+ * struct ipu6_fw_send_queue_token
+ */
+struct ipu6_fw_send_queue_token {
+	u64 buf_handle;
+	u32 payload;
+	u16 send_type;
+	u16 stream_id;
+};
+
+/**
+ * struct ipu6_fw_proxy_resp_queue_token
+ */
+struct ipu6_fw_proxy_resp_queue_token {
+	struct ipu6_fw_isys_proxy_resp_info_abi proxy_resp_info;
+};
+
+/**
+ * struct ipu6_fw_proxy_send_queue_token
+ */
+struct ipu6_fw_proxy_send_queue_token {
+	u32 request_id;
+	u32 region_index;
+	u32 offset;
+	u32 value;
+};
+
+void ipu6_fw_isys_dump_stream_cfg(struct device *dev,
+				  struct ipu6_fw_isys_stream_cfg_data_abi
+				  *stream_cfg);
+void
+ipu6_fw_isys_dump_frame_buff_set(struct device *dev,
+				 struct ipu6_fw_isys_frame_buff_set_abi *buf,
+				 unsigned int outputs);
+int ipu6_fw_isys_init(struct ipu6_isys *isys, unsigned int num_streams);
+int ipu6_fw_isys_close(struct ipu6_isys *isys);
+int ipu6_fw_isys_simple_cmd(struct ipu6_isys *isys,
+			    const unsigned int stream_handle, u16 send_type);
+int ipu6_fw_isys_complex_cmd(struct ipu6_isys *isys,
+			     const unsigned int stream_handle,
+			     void *cpu_mapped_buf, dma_addr_t dma_mapped_buf,
+			     size_t size, u16 send_type);
+int ipu6_fw_isys_send_proxy_token(struct ipu6_isys *isys,
+				  unsigned int req_id,
+				  unsigned int index,
+				  unsigned int offset, u32 value);
+void ipu6_fw_isys_cleanup(struct ipu6_isys *isys);
+struct ipu6_fw_isys_resp_info_abi *
+ipu6_fw_isys_get_resp(void *context, unsigned int queue);
+void ipu6_fw_isys_put_resp(void *context, unsigned int queue);
+#endif
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 86+ messages in thread

* [PATCH v2 08/15] media: intel/ipu6: add IPU6 CSI2 receiver v4l2 sub-device
  2023-10-24 11:29 [PATCH v2 00/15] Intel IPU6 and IPU6 input system drivers bingbu.cao
                   ` (6 preceding siblings ...)
  2023-10-24 11:29 ` [PATCH v2 07/15] media: intel/ipu6: input system ABI " bingbu.cao
@ 2023-10-24 11:29 ` bingbu.cao
  2023-11-08 11:25   ` Andreas Helbech Kleist
  2023-10-24 11:29 ` [PATCH v2 09/15] media: intel/ipu6: add the CSI2 DPHY implementation bingbu.cao
                   ` (8 subsequent siblings)
  16 siblings, 1 reply; 86+ messages in thread
From: bingbu.cao @ 2023-10-24 11:29 UTC (permalink / raw)
  To: linux-media, sakari.ailus, laurent.pinchart
  Cc: andriy.shevchenko, hdegoede, ilpo.jarvinen, andreaskleist,
	claus.stovgaard, tfiga, senozhatsky, tomi.valkeinen, bingbu.cao,
	bingbu.cao, tian.shu.qiu, hongju.wang

From: Bingbu Cao <bingbu.cao@intel.com>

Input system CSI2 receiver is exposed as a v4l2 sub-device.
Each CSI2 sub-device represent one single CSI2 hardware port
which be linked with external sub-device such camera sensor
by linked with ISYS CSI2's sink pad. CSI2 source pad is linked
to the sink pad of video capture device.

Signed-off-by: Bingbu Cao <bingbu.cao@intel.com>
---
 drivers/media/pci/intel/ipu6/ipu6-isys-csi2.c | 654 ++++++++++++++++++
 drivers/media/pci/intel/ipu6/ipu6-isys-csi2.h |  81 +++
 .../media/pci/intel/ipu6/ipu6-isys-subdev.c   | 379 ++++++++++
 .../media/pci/intel/ipu6/ipu6-isys-subdev.h   |  58 ++
 .../intel/ipu6/ipu6-platform-isys-csi2-reg.h  | 187 +++++
 5 files changed, 1359 insertions(+)
 create mode 100644 drivers/media/pci/intel/ipu6/ipu6-isys-csi2.c
 create mode 100644 drivers/media/pci/intel/ipu6/ipu6-isys-csi2.h
 create mode 100644 drivers/media/pci/intel/ipu6/ipu6-isys-subdev.c
 create mode 100644 drivers/media/pci/intel/ipu6/ipu6-isys-subdev.h
 create mode 100644 drivers/media/pci/intel/ipu6/ipu6-platform-isys-csi2-reg.h

diff --git a/drivers/media/pci/intel/ipu6/ipu6-isys-csi2.c b/drivers/media/pci/intel/ipu6/ipu6-isys-csi2.c
new file mode 100644
index 000000000000..0dedf3f51850
--- /dev/null
+++ b/drivers/media/pci/intel/ipu6/ipu6-isys-csi2.c
@@ -0,0 +1,654 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2013 - 2023 Intel Corporation
+ */
+
+#include <linux/bitfield.h>
+#include <linux/delay.h>
+
+#include <media/media-entity.h>
+#include <media/v4l2-device.h>
+#include <media/v4l2-event.h>
+
+#include "ipu6-isys.h"
+#include "ipu6-isys-subdev.h"
+#include "ipu6-platform-buttress-regs.h"
+#include "ipu6-platform-isys-csi2-reg.h"
+#include "ipu6-platform-regs.h"
+
+static const u32 csi2_supported_codes[] = {
+	MEDIA_BUS_FMT_RGB565_1X16,
+	MEDIA_BUS_FMT_RGB888_1X24,
+	MEDIA_BUS_FMT_UYVY8_1X16,
+	MEDIA_BUS_FMT_YUYV8_1X16,
+	MEDIA_BUS_FMT_SBGGR10_1X10,
+	MEDIA_BUS_FMT_SGBRG10_1X10,
+	MEDIA_BUS_FMT_SGRBG10_1X10,
+	MEDIA_BUS_FMT_SRGGB10_1X10,
+	MEDIA_BUS_FMT_SBGGR12_1X12,
+	MEDIA_BUS_FMT_SGBRG12_1X12,
+	MEDIA_BUS_FMT_SGRBG12_1X12,
+	MEDIA_BUS_FMT_SRGGB12_1X12,
+	MEDIA_BUS_FMT_SBGGR8_1X8,
+	MEDIA_BUS_FMT_SGBRG8_1X8,
+	MEDIA_BUS_FMT_SGRBG8_1X8,
+	MEDIA_BUS_FMT_SRGGB8_1X8,
+	0
+};
+
+/*
+ * Strings corresponding to CSI-2 receiver errors are here.
+ * Corresponding macros are defined in the header file.
+ */
+static const struct ipu6_csi2_error dphy_rx_errors[] = {
+	{ "Single packet header error corrected", true },
+	{ "Multiple packet header errors detected", true },
+	{ "Payload checksum (CRC) error", true },
+	{ "Transfer FIFO overflow", false },
+	{ "Reserved short packet data type detected", true },
+	{ "Reserved long packet data type detected", true },
+	{ "Incomplete long packet detected", false },
+	{ "Frame sync error", false },
+	{ "Line sync error", false },
+	{ "DPHY recoverable synchronization error", true },
+	{ "DPHY fatal error", false },
+	{ "DPHY elastic FIFO overflow", false },
+	{ "Inter-frame short packet discarded", true },
+	{ "Inter-frame long packet discarded", true },
+	{ "MIPI pktgen overflow", false },
+	{ "MIPI pktgen data loss", false },
+	{ "FIFO overflow", false },
+	{ "Lane deskew", false },
+	{ "SOT sync error", false },
+	{ "HSIDLE detected", false }
+};
+
+s64 ipu6_isys_csi2_get_link_freq(struct ipu6_isys_csi2 *csi2)
+{
+	struct media_pad *src_pad;
+	struct v4l2_subdev *ext_sd;
+	struct device *dev;
+
+	if (!csi2)
+		return -EINVAL;
+
+	dev = &csi2->isys->adev->auxdev.dev;
+	src_pad = media_entity_remote_source_pad_unique(&csi2->asd.sd.entity);
+	if (IS_ERR_OR_NULL(src_pad)) {
+		dev_err(dev, "can't get source pad of %s\n", csi2->asd.sd.name);
+		return -ENOLINK;
+	}
+
+	ext_sd = media_entity_to_v4l2_subdev(src_pad->entity);
+	if (WARN(!ext_sd, "Failed to get subdev for %s\n", csi2->asd.sd.name))
+		return -ENODEV;
+
+	return v4l2_get_link_freq(ext_sd->ctrl_handler, 0, 0);
+}
+
+static int csi2_subscribe_event(struct v4l2_subdev *sd, struct v4l2_fh *fh,
+				struct v4l2_event_subscription *sub)
+{
+	struct ipu6_isys_csi2 *csi2 = to_ipu6_isys_csi2(sd);
+	struct device *dev = &csi2->isys->adev->auxdev.dev;
+
+	dev_dbg(dev, "csi2 subscribe event(type %u id %u)\n",
+		sub->type, sub->id);
+
+	switch (sub->type) {
+	case V4L2_EVENT_FRAME_SYNC:
+		return v4l2_event_subscribe(fh, sub, 10, NULL);
+	case V4L2_EVENT_CTRL:
+		return v4l2_ctrl_subscribe_event(fh, sub);
+	default:
+		return -EINVAL;
+	}
+}
+
+static const struct v4l2_subdev_core_ops csi2_sd_core_ops = {
+	.subscribe_event = csi2_subscribe_event,
+	.unsubscribe_event = v4l2_event_subdev_unsubscribe,
+};
+
+/*
+ * The input system CSI2+ receiver has several
+ * parameters affecting the receiver timings. These depend
+ * on the MIPI bus frequency F in Hz (sensor transmitter rate)
+ * as follows:
+ *	register value = (A/1e9 + B * UI) / COUNT_ACC
+ * where
+ *	UI = 1 / (2 * F) in seconds
+ *	COUNT_ACC = counter accuracy in seconds
+ *	COUNT_ACC = 0.125 ns = 1 / 8 ns, ACCINV = 8.
+ *
+ * A and B are coefficients from the table below,
+ * depending whether the register minimum or maximum value is
+ * calculated.
+ *				       Minimum     Maximum
+ * Clock lane			       A     B     A     B
+ * reg_rx_csi_dly_cnt_termen_clane     0     0    38     0
+ * reg_rx_csi_dly_cnt_settle_clane    95    -8   300   -16
+ * Data lanes
+ * reg_rx_csi_dly_cnt_termen_dlane0    0     0    35     4
+ * reg_rx_csi_dly_cnt_settle_dlane0   85    -2   145    -6
+ * reg_rx_csi_dly_cnt_termen_dlane1    0     0    35     4
+ * reg_rx_csi_dly_cnt_settle_dlane1   85    -2   145    -6
+ * reg_rx_csi_dly_cnt_termen_dlane2    0     0    35     4
+ * reg_rx_csi_dly_cnt_settle_dlane2   85    -2   145    -6
+ * reg_rx_csi_dly_cnt_termen_dlane3    0     0    35     4
+ * reg_rx_csi_dly_cnt_settle_dlane3   85    -2   145    -6
+ *
+ * We use the minimum values of both A and B.
+ */
+
+#define DIV_SHIFT	8
+#define CSI2_ACCINV	8
+
+static u32 calc_timing(s32 a, s32 b, s64 link_freq, u32 accinv)
+{
+	return accinv * a + (accinv * b * (500000000 >> DIV_SHIFT)
+			     / (int32_t)(link_freq >> DIV_SHIFT));
+}
+
+static int
+ipu6_isys_csi2_calc_timing(struct ipu6_isys_csi2 *csi2,
+			   struct ipu6_isys_csi2_timing *timing, u32 accinv)
+{
+	struct device *dev = &csi2->isys->adev->auxdev.dev;
+	s64 link_freq;
+
+	link_freq = ipu6_isys_csi2_get_link_freq(csi2);
+	if (link_freq < 0)
+		return link_freq;
+
+	timing->ctermen = calc_timing(CSI2_CSI_RX_DLY_CNT_TERMEN_CLANE_A,
+				      CSI2_CSI_RX_DLY_CNT_TERMEN_CLANE_B,
+				      link_freq, accinv);
+	timing->csettle = calc_timing(CSI2_CSI_RX_DLY_CNT_SETTLE_CLANE_A,
+				      CSI2_CSI_RX_DLY_CNT_SETTLE_CLANE_B,
+				      link_freq, accinv);
+	timing->dtermen = calc_timing(CSI2_CSI_RX_DLY_CNT_TERMEN_DLANE_A,
+				      CSI2_CSI_RX_DLY_CNT_TERMEN_DLANE_B,
+				      link_freq, accinv);
+	timing->dsettle = calc_timing(CSI2_CSI_RX_DLY_CNT_SETTLE_DLANE_A,
+				      CSI2_CSI_RX_DLY_CNT_SETTLE_DLANE_B,
+				      link_freq, accinv);
+
+	dev_dbg(dev, "ctermen %u csettle %u dtermen %u dsettle %u\n",
+		timing->ctermen, timing->csettle,
+		timing->dtermen, timing->dsettle);
+
+	return 0;
+}
+
+void ipu6_isys_register_errors(struct ipu6_isys_csi2 *csi2)
+{
+	u32 irq = readl(csi2->base + CSI_PORT_REG_BASE_IRQ_CSI +
+			CSI_PORT_REG_BASE_IRQ_STATUS_OFFSET);
+	struct ipu6_isys *isys = csi2->isys;
+	u32 mask;
+
+	mask = isys->pdata->ipdata->csi2.irq_mask;
+	writel(irq & mask, csi2->base + CSI_PORT_REG_BASE_IRQ_CSI +
+	       CSI_PORT_REG_BASE_IRQ_CLEAR_OFFSET);
+	csi2->receiver_errors |= irq & mask;
+}
+
+void ipu6_isys_csi2_error(struct ipu6_isys_csi2 *csi2)
+{
+	struct device *dev = &csi2->isys->adev->auxdev.dev;
+	const struct ipu6_csi2_error *errors;
+	u32 status;
+	u32 i;
+
+	/* register errors once more in case of interrupts are disabled */
+	ipu6_isys_register_errors(csi2);
+	status = csi2->receiver_errors;
+	csi2->receiver_errors = 0;
+	errors = dphy_rx_errors;
+
+	for (i = 0; i < CSI_RX_NUM_ERRORS_IN_IRQ; i++) {
+		if (status & BIT(i))
+			dev_err_ratelimited(dev, "csi2-%i error: %s\n",
+					    csi2->port, errors[i].error_string);
+	}
+}
+
+static int ipu6_isys_csi2_set_stream(struct v4l2_subdev *sd,
+				     const struct ipu6_isys_csi2_timing *timing,
+				     unsigned int nlanes, int enable)
+{
+	struct ipu6_isys_csi2 *csi2 = to_ipu6_isys_csi2(sd);
+	struct ipu6_isys *isys = csi2->isys;
+	struct device *dev = &isys->adev->auxdev.dev;
+	struct ipu6_isys_csi2_config cfg;
+	unsigned int nports;
+	int ret = 0;
+	u32 mask = 0;
+	u32 i;
+
+	dev_dbg(dev, "stream %s CSI2-%u with %u lanes\n", enable ? "on" : "off",
+		csi2->port, nlanes);
+
+	cfg.port = csi2->port;
+	cfg.nlanes = nlanes;
+
+	mask = isys->pdata->ipdata->csi2.irq_mask;
+	nports = isys->pdata->ipdata->csi2.nports;
+
+	if (!enable) {
+		writel(0, csi2->base + CSI_REG_CSI_FE_ENABLE);
+		writel(0, csi2->base + CSI_REG_PPI2CSI_ENABLE);
+
+		writel(0,
+		       csi2->base + CSI_PORT_REG_BASE_IRQ_CSI +
+		       CSI_PORT_REG_BASE_IRQ_ENABLE_OFFSET);
+		writel(mask,
+		       csi2->base + CSI_PORT_REG_BASE_IRQ_CSI +
+		       CSI_PORT_REG_BASE_IRQ_CLEAR_OFFSET);
+		writel(0,
+		       csi2->base + CSI_PORT_REG_BASE_IRQ_CSI_SYNC +
+		       CSI_PORT_REG_BASE_IRQ_ENABLE_OFFSET);
+		writel(0xffffffff,
+		       csi2->base + CSI_PORT_REG_BASE_IRQ_CSI_SYNC +
+		       CSI_PORT_REG_BASE_IRQ_CLEAR_OFFSET);
+
+		isys->phy_set_power(isys, &cfg, timing, false);
+
+		writel(0, isys->pdata->base + CSI_REG_HUB_FW_ACCESS_PORT
+		       (isys->pdata->ipdata->csi2.fw_access_port_ofs,
+			csi2->port));
+		writel(0, isys->pdata->base +
+		       CSI_REG_HUB_DRV_ACCESS_PORT(csi2->port));
+
+		return ret;
+	}
+
+	/* reset port reset */
+	writel(0x1, csi2->base + CSI_REG_PORT_GPREG_SRST);
+	usleep_range(100, 200);
+	writel(0x0, csi2->base + CSI_REG_PORT_GPREG_SRST);
+
+	/* enable port clock */
+	for (i = 0; i < nports; i++) {
+		writel(1, isys->pdata->base + CSI_REG_HUB_DRV_ACCESS_PORT(i));
+		writel(1, isys->pdata->base + CSI_REG_HUB_FW_ACCESS_PORT
+		       (isys->pdata->ipdata->csi2.fw_access_port_ofs, i));
+	}
+
+	/* enable all error related irq */
+	writel(mask,
+	       csi2->base + CSI_PORT_REG_BASE_IRQ_CSI +
+	       CSI_PORT_REG_BASE_IRQ_STATUS_OFFSET);
+	writel(mask,
+	       csi2->base + CSI_PORT_REG_BASE_IRQ_CSI +
+	       CSI_PORT_REG_BASE_IRQ_MASK_OFFSET);
+	writel(mask,
+	       csi2->base + CSI_PORT_REG_BASE_IRQ_CSI +
+	       CSI_PORT_REG_BASE_IRQ_CLEAR_OFFSET);
+	writel(mask,
+	       csi2->base + CSI_PORT_REG_BASE_IRQ_CSI +
+	       CSI_PORT_REG_BASE_IRQ_LEVEL_NOT_PULSE_OFFSET);
+	writel(mask,
+	       csi2->base + CSI_PORT_REG_BASE_IRQ_CSI +
+	       CSI_PORT_REG_BASE_IRQ_ENABLE_OFFSET);
+
+	/*
+	 * Using event from firmware instead of irq to handle CSI2 sync event
+	 * which can reduce system wakeups. If CSI2 sync irq enabled, we need
+	 * disable the firmware CSI2 sync event to avoid duplicate handling.
+	 */
+	writel(0xffffffff, csi2->base + CSI_PORT_REG_BASE_IRQ_CSI_SYNC +
+	       CSI_PORT_REG_BASE_IRQ_STATUS_OFFSET);
+	writel(0, csi2->base + CSI_PORT_REG_BASE_IRQ_CSI_SYNC +
+	       CSI_PORT_REG_BASE_IRQ_MASK_OFFSET);
+	writel(0xffffffff, csi2->base + CSI_PORT_REG_BASE_IRQ_CSI_SYNC +
+	       CSI_PORT_REG_BASE_IRQ_CLEAR_OFFSET);
+	writel(0, csi2->base + CSI_PORT_REG_BASE_IRQ_CSI_SYNC +
+	       CSI_PORT_REG_BASE_IRQ_LEVEL_NOT_PULSE_OFFSET);
+	writel(0xffffffff, csi2->base + CSI_PORT_REG_BASE_IRQ_CSI_SYNC +
+	       CSI_PORT_REG_BASE_IRQ_ENABLE_OFFSET);
+
+	/* configure to enable FE and PPI2CSI */
+	writel(0, csi2->base + CSI_REG_CSI_FE_MODE);
+	writel(CSI_SENSOR_INPUT, csi2->base + CSI_REG_CSI_FE_MUX_CTRL);
+	writel(CSI_CNTR_SENSOR_LINE_ID | CSI_CNTR_SENSOR_FRAME_ID,
+	       csi2->base + CSI_REG_CSI_FE_SYNC_CNTR_SEL);
+	writel(FIELD_PREP(PPI_INTF_CONFIG_NOF_ENABLED_DLANES_MASK, nlanes - 1),
+	       csi2->base + CSI_REG_PPI2CSI_CONFIG_PPI_INTF);
+
+	writel(1, csi2->base + CSI_REG_PPI2CSI_ENABLE);
+	writel(1, csi2->base + CSI_REG_CSI_FE_ENABLE);
+
+	ret = isys->phy_set_power(isys, &cfg, timing, true);
+	if (ret)
+		dev_err(dev, "csi-%d phy power up failed %d\n", csi2->port,
+			ret);
+
+	return ret;
+}
+
+static int set_stream(struct v4l2_subdev *sd, int enable)
+{
+	struct ipu6_isys_csi2 *csi2 = to_ipu6_isys_csi2(sd);
+	struct device *dev = &csi2->isys->adev->auxdev.dev;
+	struct ipu6_isys_csi2_timing timing = { };
+	unsigned int nlanes;
+	int ret;
+
+	dev_dbg(dev, "csi2 stream %s callback\n", enable ? "on" : "off");
+
+	if (!enable) {
+		csi2->stream_count--;
+		if (csi2->stream_count)
+			return 0;
+
+		ipu6_isys_csi2_set_stream(sd, &timing, 0, enable);
+		return 0;
+	}
+
+	if (csi2->stream_count) {
+		csi2->stream_count++;
+		return 0;
+	}
+
+	nlanes = csi2->nlanes;
+
+	ret = ipu6_isys_csi2_calc_timing(csi2, &timing, CSI2_ACCINV);
+	if (ret)
+		return ret;
+
+	ret = ipu6_isys_csi2_set_stream(sd, &timing, nlanes, enable);
+	if (ret)
+		return ret;
+
+	csi2->stream_count++;
+
+	return 0;
+}
+
+static int ipu6_isys_csi2_set_sel(struct v4l2_subdev *sd,
+				  struct v4l2_subdev_state *state,
+				  struct v4l2_subdev_selection *sel)
+{
+	struct ipu6_isys_subdev *asd = to_ipu6_isys_subdev(sd);
+	struct device *dev = &asd->isys->adev->auxdev.dev;
+	struct v4l2_mbus_framefmt *sink_ffmt;
+	struct v4l2_mbus_framefmt *src_ffmt;
+	struct v4l2_rect *crop;
+
+	if (sel->pad == CSI2_PAD_SINK || sel->target != V4L2_SEL_TGT_CROP)
+		return -EINVAL;
+
+	sink_ffmt = v4l2_subdev_state_get_opposite_stream_format(state,
+								 sel->pad,
+								 sel->stream);
+	if (!sink_ffmt)
+		return -EINVAL;
+
+	src_ffmt = v4l2_subdev_state_get_stream_format(state, sel->pad,
+						       sel->stream);
+	if (!src_ffmt)
+		return -EINVAL;
+
+	crop = v4l2_subdev_state_get_stream_crop(state, sel->pad, sel->stream);
+	if (!crop)
+		return -EINVAL;
+
+	/* Only vertical cropping is supported */
+	sel->r.left = 0;
+	sel->r.width = sink_ffmt->width;
+	/* Non-bayer formats can't be single line cropped */
+	if (!ipu6_isys_is_bayer_format(sink_ffmt->code))
+		sel->r.top &= ~1;
+	sel->r.height = clamp(sel->r.height & ~1, IPU6_ISYS_MIN_HEIGHT,
+			      sink_ffmt->height - sel->r.top);
+	*crop = sel->r;
+
+	/* update source pad format */
+	src_ffmt->width = sel->r.width;
+	src_ffmt->height = sel->r.height;
+	if (ipu6_isys_is_bayer_format(sink_ffmt->code))
+		src_ffmt->code = ipu6_isys_convert_bayer_order(sink_ffmt->code,
+							       sel->r.left,
+							       sel->r.top);
+	dev_dbg(dev, "set crop for %s sel: %d,%d,%d,%d code: 0x%x\n",
+		sd->name, sel->r.left, sel->r.top, sel->r.width, sel->r.height,
+		src_ffmt->code);
+
+	return 0;
+}
+
+static int ipu6_isys_csi2_get_sel(struct v4l2_subdev *sd,
+				  struct v4l2_subdev_state *state,
+				  struct v4l2_subdev_selection *sel)
+{
+	struct v4l2_mbus_framefmt *sink_ffmt;
+	struct v4l2_rect *crop;
+	int ret = 0;
+
+	if (sd->entity.pads[sel->pad].flags & MEDIA_PAD_FL_SINK)
+		return -EINVAL;
+
+	sink_ffmt = v4l2_subdev_state_get_opposite_stream_format(state,
+								 sel->pad,
+								 sel->stream);
+	if (!sink_ffmt)
+		return -EINVAL;
+
+	crop = v4l2_subdev_state_get_stream_crop(state, sel->pad, sel->stream);
+	if (!crop)
+		return -EINVAL;
+
+	switch (sel->target) {
+	case V4L2_SEL_TGT_CROP_DEFAULT:
+	case V4L2_SEL_TGT_CROP_BOUNDS:
+		sel->r.left = 0;
+		sel->r.top = 0;
+		sel->r.width = sink_ffmt->width;
+		sel->r.height = sink_ffmt->height;
+		break;
+	case V4L2_SEL_TGT_CROP:
+		sel->r = *crop;
+		break;
+	default:
+		ret = -EINVAL;
+	}
+
+	return ret;
+}
+
+static const struct v4l2_subdev_video_ops csi2_sd_video_ops = {
+	.s_stream = set_stream,
+};
+
+static const struct v4l2_subdev_pad_ops csi2_sd_pad_ops = {
+	.init_cfg = ipu6_isys_subdev_init_cfg,
+	.get_fmt = v4l2_subdev_get_fmt,
+	.set_fmt = ipu6_isys_subdev_set_fmt,
+	.get_selection = ipu6_isys_csi2_get_sel,
+	.set_selection = ipu6_isys_csi2_set_sel,
+	.enum_mbus_code = ipu6_isys_subdev_enum_mbus_code,
+	.set_routing = ipu6_isys_subdev_set_routing,
+};
+
+static const struct v4l2_subdev_ops csi2_sd_ops = {
+	.core = &csi2_sd_core_ops,
+	.video = &csi2_sd_video_ops,
+	.pad = &csi2_sd_pad_ops,
+};
+
+static const struct media_entity_operations csi2_entity_ops = {
+	.link_validate = v4l2_subdev_link_validate,
+	.has_pad_interdep = v4l2_subdev_has_pad_interdep,
+};
+
+void ipu6_isys_csi2_cleanup(struct ipu6_isys_csi2 *csi2)
+{
+	if (!csi2->isys)
+		return;
+
+	v4l2_device_unregister_subdev(&csi2->asd.sd);
+	v4l2_subdev_cleanup(&csi2->asd.sd);
+	ipu6_isys_subdev_cleanup(&csi2->asd);
+	csi2->isys = NULL;
+}
+
+int ipu6_isys_csi2_init(struct ipu6_isys_csi2 *csi2,
+			struct ipu6_isys *isys,
+			void __iomem *base, unsigned int index)
+{
+	struct device *dev = &isys->adev->auxdev.dev;
+	int ret;
+
+	csi2->isys = isys;
+	csi2->base = base;
+	csi2->port = index;
+
+	csi2->asd.sd.entity.ops = &csi2_entity_ops;
+	csi2->asd.isys = isys;
+	ret = ipu6_isys_subdev_init(&csi2->asd, &csi2_sd_ops, 0,
+				    NR_OF_CSI2_SINK_PADS, NR_OF_CSI2_SRC_PADS);
+	if (ret)
+		goto fail;
+
+	csi2->asd.source = IPU6_FW_ISYS_STREAM_SRC_CSI2_PORT0 + index;
+	csi2->asd.supported_codes = csi2_supported_codes;
+	snprintf(csi2->asd.sd.name, sizeof(csi2->asd.sd.name),
+		 IPU6_ISYS_ENTITY_PREFIX " CSI2 %u", index);
+	v4l2_set_subdevdata(&csi2->asd.sd, &csi2->asd);
+	ret = v4l2_subdev_init_finalize(&csi2->asd.sd);
+	if (ret) {
+		dev_err(dev, "failed to init v4l2 subdev\n");
+		goto fail;
+	}
+
+	ret = v4l2_device_register_subdev(&isys->v4l2_dev, &csi2->asd.sd);
+	if (ret) {
+		dev_err(dev, "failed to register v4l2 subdev\n");
+		goto fail;
+	}
+
+	return 0;
+
+fail:
+	ipu6_isys_csi2_cleanup(csi2);
+
+	return ret;
+}
+
+void ipu6_isys_csi2_sof_event_by_stream(struct ipu6_isys_stream *stream)
+{
+	struct video_device *vdev = stream->asd->sd.devnode;
+	struct device *dev = &stream->isys->adev->auxdev.dev;
+	struct ipu6_isys_csi2 *csi2 = ipu6_isys_subdev_to_csi2(stream->asd);
+	struct v4l2_event ev = {
+		.type = V4L2_EVENT_FRAME_SYNC,
+	};
+
+	ev.u.frame_sync.frame_sequence = atomic_inc_return(&stream->sequence);
+	v4l2_event_queue(vdev, &ev);
+
+	dev_dbg(dev, "sof_event::csi2-%i sequence: %i, vc: %d\n",
+		csi2->port, ev.u.frame_sync.frame_sequence, stream->vc);
+}
+
+void ipu6_isys_csi2_eof_event_by_stream(struct ipu6_isys_stream *stream)
+{
+	struct device *dev = &stream->isys->adev->auxdev.dev;
+	struct ipu6_isys_csi2 *csi2 = ipu6_isys_subdev_to_csi2(stream->asd);
+	u32 frame_sequence = atomic_read(&stream->sequence);
+
+	dev_dbg(dev, "eof_event::csi2-%i sequence: %i\n",
+		csi2->port, frame_sequence);
+}
+
+int ipu6_isys_csi2_get_remote_desc(u32 source_stream,
+				   struct ipu6_isys_csi2 *csi2,
+				   struct media_entity *source_entity,
+				   struct v4l2_mbus_frame_desc_entry *entry,
+				   int *nr_queues)
+{
+	struct v4l2_mbus_frame_desc_entry *desc_entry = NULL;
+	struct device *dev = &csi2->isys->adev->auxdev.dev;
+	struct v4l2_mbus_frame_desc desc;
+	struct v4l2_subdev *source;
+	struct media_pad *pad;
+	unsigned int i;
+	int count = 0;
+	int ret;
+
+	source = media_entity_to_v4l2_subdev(source_entity);
+	if (!source)
+		return -EPIPE;
+
+	pad = media_pad_remote_pad_first(&csi2->asd.pad[CSI2_PAD_SINK]);
+	if (!pad)
+		return -EPIPE;
+
+	ret = v4l2_subdev_call(source, pad, get_frame_desc, pad->index, &desc);
+	if (ret)
+		return ret;
+
+	if (desc.type != V4L2_MBUS_FRAME_DESC_TYPE_CSI2) {
+		dev_err(dev, "Unsupported frame descriptor type\n");
+		return -EINVAL;
+	}
+
+	for (i = 0; i < desc.num_entries; i++) {
+		if (source_stream == desc.entry[i].stream) {
+			desc_entry = &desc.entry[i];
+			break;
+		}
+	}
+
+	if (!desc_entry) {
+		dev_err(dev, "Failed to find stream %u from remote subdev\n",
+			source_stream);
+		return -EINVAL;
+	}
+
+	if (desc_entry->bus.csi2.vc >= NR_OF_CSI2_VC) {
+		dev_err(dev, "invalid vc %d\n", desc_entry->bus.csi2.vc);
+		return -EINVAL;
+	}
+
+	*entry = *desc_entry;
+	for (i = 0; i < desc.num_entries; i++) {
+		if (entry->bus.csi2.vc == desc.entry[i].bus.csi2.vc)
+			count++;
+	}
+
+	*nr_queues = count;
+	return 0;
+}
+
+void ipu6_isys_set_csi2_streams_status(struct ipu6_isys_video *av, bool status)
+{
+	struct ipu6_isys_stream *stream = av->stream;
+	struct v4l2_subdev *sd = &stream->asd->sd;
+	struct v4l2_subdev_state *state;
+	struct media_pad *r_pad;
+	unsigned int i;
+	u32 r_stream;
+
+	r_pad = media_pad_remote_pad_first(&av->pad);
+	r_stream = ipu6_isys_get_src_stream_by_src_pad(sd, r_pad->index);
+
+	state = v4l2_subdev_lock_and_get_active_state(sd);
+
+	for (i = 0; i < state->stream_configs.num_configs; i++) {
+		struct v4l2_subdev_stream_config *cfg =
+			&state->stream_configs.configs[i];
+
+		if (cfg->pad == r_pad->index && r_stream == cfg->stream) {
+			dev_dbg(&av->isys->adev->auxdev.dev,
+				"%s: pad:%u, stream:%u, status:%u\n",
+				sd->entity.name, r_pad->index, r_stream,
+				status);
+			cfg->enabled = status;
+		}
+	}
+
+	v4l2_subdev_unlock_state(state);
+}
diff --git a/drivers/media/pci/intel/ipu6/ipu6-isys-csi2.h b/drivers/media/pci/intel/ipu6/ipu6-isys-csi2.h
new file mode 100644
index 000000000000..93d8e6a4a6d8
--- /dev/null
+++ b/drivers/media/pci/intel/ipu6/ipu6-isys-csi2.h
@@ -0,0 +1,81 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/* Copyright (C) 2013 - 2023 Intel Corporation */
+
+#ifndef IPU6_ISYS_CSI2_H
+#define IPU6_ISYS_CSI2_H
+
+#include <media/media-entity.h>
+#include <media/v4l2-device.h>
+
+#include "ipu6-isys-subdev.h"
+#include "ipu6-isys-video.h"
+
+struct ipu6_isys;
+struct ipu6_isys_csi2_pdata;
+struct ipu6_isys_csi2_timing;
+struct ipu6_isys_stream;
+
+#define NR_OF_CSI2_VC			16
+#define INVALID_VC_ID			-1
+#define NR_OF_CSI2_SINK_PADS		1
+#define CSI2_PAD_SINK			0
+#define NR_OF_CSI2_SRC_PADS		8
+#define CSI2_PAD_SRC			1
+#define NR_OF_CSI2_PADS	(NR_OF_CSI2_SINK_PADS + NR_OF_CSI2_SRC_PADS)
+
+#define CSI2_CSI_RX_DLY_CNT_TERMEN_CLANE_A		0
+#define CSI2_CSI_RX_DLY_CNT_TERMEN_CLANE_B		0
+#define CSI2_CSI_RX_DLY_CNT_SETTLE_CLANE_A		95
+#define CSI2_CSI_RX_DLY_CNT_SETTLE_CLANE_B		-8
+
+#define CSI2_CSI_RX_DLY_CNT_TERMEN_DLANE_A		0
+#define CSI2_CSI_RX_DLY_CNT_TERMEN_DLANE_B		0
+#define CSI2_CSI_RX_DLY_CNT_SETTLE_DLANE_A		85
+#define CSI2_CSI_RX_DLY_CNT_SETTLE_DLANE_B		-2
+
+struct ipu6_isys_csi2 {
+	struct ipu6_isys_subdev asd;
+	struct ipu6_isys_csi2_pdata *pdata;
+	struct ipu6_isys *isys;
+
+	void __iomem *base;
+	u32 receiver_errors;
+	unsigned int nlanes;
+	unsigned int port;
+	unsigned int stream_count;
+};
+
+struct ipu6_isys_csi2_timing {
+	u32 ctermen;
+	u32 csettle;
+	u32 dtermen;
+	u32 dsettle;
+};
+
+struct ipu6_csi2_error {
+	const char *error_string;
+	bool is_info_only;
+};
+
+#define ipu6_isys_subdev_to_csi2(__sd) \
+	container_of(__sd, struct ipu6_isys_csi2, asd)
+
+#define to_ipu6_isys_csi2(sd) container_of(to_ipu6_isys_subdev(sd), \
+					   struct ipu6_isys_csi2, asd)
+
+s64 ipu6_isys_csi2_get_link_freq(struct ipu6_isys_csi2 *csi2);
+int ipu6_isys_csi2_init(struct ipu6_isys_csi2 *csi2, struct ipu6_isys *isys,
+			void __iomem *base, unsigned int index);
+void ipu6_isys_csi2_cleanup(struct ipu6_isys_csi2 *csi2);
+void ipu6_isys_csi2_sof_event_by_stream(struct ipu6_isys_stream *stream);
+void ipu6_isys_csi2_eof_event_by_stream(struct ipu6_isys_stream *stream);
+void ipu6_isys_register_errors(struct ipu6_isys_csi2 *csi2);
+void ipu6_isys_csi2_error(struct ipu6_isys_csi2 *csi2);
+int ipu6_isys_csi2_get_remote_desc(u32 source_stream,
+				   struct ipu6_isys_csi2 *csi2,
+				   struct media_entity *source_entity,
+				   struct v4l2_mbus_frame_desc_entry *entry,
+				   int *nr_queues);
+void ipu6_isys_set_csi2_streams_status(struct ipu6_isys_video *av, bool status);
+
+#endif /* IPU6_ISYS_CSI2_H */
diff --git a/drivers/media/pci/intel/ipu6/ipu6-isys-subdev.c b/drivers/media/pci/intel/ipu6/ipu6-isys-subdev.c
new file mode 100644
index 000000000000..7f104205d153
--- /dev/null
+++ b/drivers/media/pci/intel/ipu6/ipu6-isys-subdev.c
@@ -0,0 +1,379 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2013 - 2023 Intel Corporation
+ */
+
+#include <media/mipi-csi2.h>
+
+#include "ipu6-isys.h"
+#include "ipu6-isys-subdev.h"
+
+unsigned int ipu6_isys_mbus_code_to_bpp(u32 code)
+{
+	switch (code) {
+	case MEDIA_BUS_FMT_RGB888_1X24:
+		return 24;
+	case MEDIA_BUS_FMT_RGB565_1X16:
+	case MEDIA_BUS_FMT_UYVY8_1X16:
+	case MEDIA_BUS_FMT_YUYV8_1X16:
+		return 16;
+	case MEDIA_BUS_FMT_SBGGR12_1X12:
+	case MEDIA_BUS_FMT_SGBRG12_1X12:
+	case MEDIA_BUS_FMT_SGRBG12_1X12:
+	case MEDIA_BUS_FMT_SRGGB12_1X12:
+		return 12;
+	case MEDIA_BUS_FMT_SBGGR10_1X10:
+	case MEDIA_BUS_FMT_SGBRG10_1X10:
+	case MEDIA_BUS_FMT_SGRBG10_1X10:
+	case MEDIA_BUS_FMT_SRGGB10_1X10:
+		return 10;
+	case MEDIA_BUS_FMT_SBGGR8_1X8:
+	case MEDIA_BUS_FMT_SGBRG8_1X8:
+	case MEDIA_BUS_FMT_SGRBG8_1X8:
+	case MEDIA_BUS_FMT_SRGGB8_1X8:
+		return 8;
+	default:
+		WARN_ON(1);
+		return 8;
+	}
+}
+
+unsigned int ipu6_isys_mbus_code_to_mipi(u32 code)
+{
+	switch (code) {
+	case MEDIA_BUS_FMT_RGB565_1X16:
+		return MIPI_CSI2_DT_RGB565;
+	case MEDIA_BUS_FMT_RGB888_1X24:
+		return MIPI_CSI2_DT_RGB888;
+	case MEDIA_BUS_FMT_UYVY8_1X16:
+	case MEDIA_BUS_FMT_YUYV8_1X16:
+		return MIPI_CSI2_DT_YUV422_8B;
+	case MEDIA_BUS_FMT_SBGGR12_1X12:
+	case MEDIA_BUS_FMT_SGBRG12_1X12:
+	case MEDIA_BUS_FMT_SGRBG12_1X12:
+	case MEDIA_BUS_FMT_SRGGB12_1X12:
+		return MIPI_CSI2_DT_RAW12;
+	case MEDIA_BUS_FMT_SBGGR10_1X10:
+	case MEDIA_BUS_FMT_SGBRG10_1X10:
+	case MEDIA_BUS_FMT_SGRBG10_1X10:
+	case MEDIA_BUS_FMT_SRGGB10_1X10:
+		return MIPI_CSI2_DT_RAW10;
+	case MEDIA_BUS_FMT_SBGGR8_1X8:
+	case MEDIA_BUS_FMT_SGBRG8_1X8:
+	case MEDIA_BUS_FMT_SGRBG8_1X8:
+	case MEDIA_BUS_FMT_SRGGB8_1X8:
+		return MIPI_CSI2_DT_RAW8;
+	default:
+		/* return unavailable MIPI data type - 0x3f */
+		WARN_ON(1);
+		return 0x3f;
+	}
+}
+
+bool ipu6_isys_is_bayer_format(u32 code)
+{
+	switch (ipu6_isys_mbus_code_to_mipi(code)) {
+	case MIPI_CSI2_DT_RAW8:
+	case MIPI_CSI2_DT_RAW10:
+	case MIPI_CSI2_DT_RAW12:
+		return true;
+	default:
+		return false;
+	}
+}
+
+u32 ipu6_isys_convert_bayer_order(u32 code, int x, int y)
+{
+	static const u32 code_map[] = {
+		MEDIA_BUS_FMT_SRGGB8_1X8,
+		MEDIA_BUS_FMT_SGRBG8_1X8,
+		MEDIA_BUS_FMT_SGBRG8_1X8,
+		MEDIA_BUS_FMT_SBGGR8_1X8,
+		MEDIA_BUS_FMT_SRGGB10_1X10,
+		MEDIA_BUS_FMT_SGRBG10_1X10,
+		MEDIA_BUS_FMT_SGBRG10_1X10,
+		MEDIA_BUS_FMT_SBGGR10_1X10,
+		MEDIA_BUS_FMT_SRGGB12_1X12,
+		MEDIA_BUS_FMT_SGRBG12_1X12,
+		MEDIA_BUS_FMT_SGBRG12_1X12,
+		MEDIA_BUS_FMT_SBGGR12_1X12
+	};
+	u32 i;
+
+	for (i = 0; i < ARRAY_SIZE(code_map); i++)
+		if (code_map[i] == code)
+			break;
+
+	if (WARN_ON(i == ARRAY_SIZE(code_map)))
+		return code;
+
+	return code_map[i ^ (((y & 1) << 1) | (x & 1))];
+}
+
+int ipu6_isys_subdev_set_fmt(struct v4l2_subdev *sd,
+			     struct v4l2_subdev_state *state,
+			     struct v4l2_subdev_format *format)
+{
+	struct ipu6_isys_subdev *asd = to_ipu6_isys_subdev(sd);
+	struct v4l2_mbus_framefmt *fmt;
+	struct v4l2_rect *crop;
+	u32 code = asd->supported_codes[0];
+	u32 other_pad, other_stream;
+	unsigned int i;
+	int ret;
+
+	/* No transcoding, source and sink formats must match. */
+	if ((sd->entity.pads[format->pad].flags & MEDIA_PAD_FL_SOURCE) &&
+	    sd->entity.num_pads > 1)
+		return v4l2_subdev_get_fmt(sd, state, format);
+
+	format->format.width = clamp(format->format.width, IPU6_ISYS_MIN_WIDTH,
+				     IPU6_ISYS_MAX_WIDTH);
+	format->format.height = clamp(format->format.height,
+				      IPU6_ISYS_MIN_HEIGHT,
+				      IPU6_ISYS_MAX_HEIGHT);
+
+	for (i = 0; asd->supported_codes[i]; i++) {
+		if (asd->supported_codes[i] == format->format.code) {
+			code = asd->supported_codes[i];
+			break;
+		}
+	}
+	format->format.code = code;
+	format->format.field = V4L2_FIELD_NONE;
+
+	/* Store the format and propagate it to the source pad. */
+	fmt = v4l2_subdev_state_get_stream_format(state, format->pad,
+						  format->stream);
+	if (!fmt)
+		return -EINVAL;
+
+	*fmt = format->format;
+
+	if (!(sd->entity.pads[format->pad].flags & MEDIA_PAD_FL_SINK))
+		return 0;
+
+	/* propagate format to following source pad */
+	fmt = v4l2_subdev_state_get_opposite_stream_format(state, format->pad,
+							   format->stream);
+	if (!fmt)
+		return -EINVAL;
+
+	*fmt = format->format;
+
+	ret = v4l2_subdev_routing_find_opposite_end(&state->routing,
+						    format->pad,
+						    format->stream,
+						    &other_pad,
+						    &other_stream);
+	if (ret)
+		return -EINVAL;
+
+	crop = v4l2_subdev_state_get_stream_crop(state, other_pad,
+						 other_stream);
+	/* reset crop */
+	crop->left = 0;
+	crop->top = 0;
+	crop->width = fmt->width;
+	crop->height = fmt->height;
+
+	return 0;
+}
+
+int ipu6_isys_subdev_enum_mbus_code(struct v4l2_subdev *sd,
+				    struct v4l2_subdev_state *state,
+				    struct v4l2_subdev_mbus_code_enum *code)
+{
+	struct ipu6_isys_subdev *asd = to_ipu6_isys_subdev(sd);
+	const u32 *supported_codes = asd->supported_codes;
+	u32 index;
+
+	for (index = 0; supported_codes[index]; index++) {
+		if (index == code->index) {
+			code->code = supported_codes[index];
+			return 0;
+		}
+	}
+
+	return -EINVAL;
+}
+
+static int subdev_set_routing(struct v4l2_subdev *sd,
+			      struct v4l2_subdev_state *state,
+			      struct v4l2_subdev_krouting *routing)
+{
+	static const struct v4l2_mbus_framefmt format = {
+		.width = 4096,
+		.height = 3072,
+		.code = MEDIA_BUS_FMT_SGRBG10_1X10,
+		.field = V4L2_FIELD_NONE,
+	};
+	int ret;
+
+	ret = v4l2_subdev_routing_validate(sd, routing,
+					   V4L2_SUBDEV_ROUTING_ONLY_1_TO_1);
+	if (ret)
+		return ret;
+
+	return v4l2_subdev_set_routing_with_fmt(sd, state, routing, &format);
+}
+
+int ipu6_isys_get_stream_pad_fmt(struct v4l2_subdev *sd, u32 pad, u32 stream,
+				 struct v4l2_mbus_framefmt *format)
+{
+	struct v4l2_mbus_framefmt *fmt;
+	struct v4l2_subdev_state *state;
+	int ret = -EINVAL;
+
+	if (!sd || !format)
+		return -EINVAL;
+
+	state = v4l2_subdev_lock_and_get_active_state(sd);
+	fmt = v4l2_subdev_state_get_stream_format(state, pad, stream);
+	if (fmt) {
+		*format = *fmt;
+		ret = 0;
+	}
+	v4l2_subdev_unlock_state(state);
+
+	return ret;
+}
+
+int ipu6_isys_get_stream_pad_crop(struct v4l2_subdev *sd, u32 pad, u32 stream,
+				  struct v4l2_rect *crop)
+{
+	struct v4l2_subdev_state *state;
+	struct v4l2_rect *rect;
+	int ret = -EINVAL;
+
+	if (!sd || !crop)
+		return -EINVAL;
+
+	state = v4l2_subdev_lock_and_get_active_state(sd);
+	rect = v4l2_subdev_state_get_stream_crop(state, pad, stream);
+	if (rect) {
+		*crop = *rect;
+		ret = 0;
+	}
+	v4l2_subdev_unlock_state(state);
+
+	return ret;
+}
+
+u32 ipu6_isys_get_src_stream_by_src_pad(struct v4l2_subdev *sd, u32 pad)
+{
+	struct v4l2_subdev_state *state;
+	struct v4l2_subdev_route *routes;
+	unsigned int i;
+	u32 source_stream = 0;
+
+	state = v4l2_subdev_lock_and_get_active_state(sd);
+	if (!state)
+		return 0;
+
+	routes = state->routing.routes;
+	for (i = 0; i < state->routing.num_routes; i++) {
+		if (routes[i].source_pad == pad) {
+			source_stream = routes[i].source_stream;
+			break;
+		}
+	}
+
+	v4l2_subdev_unlock_state(state);
+
+	return source_stream;
+}
+
+int ipu6_isys_subdev_init_cfg(struct v4l2_subdev *sd,
+			      struct v4l2_subdev_state *state)
+{
+	struct v4l2_subdev_route route = {
+		.sink_pad = 0,
+		.sink_stream = 0,
+		.source_pad = 1,
+		.source_stream = 0,
+		.flags = V4L2_SUBDEV_ROUTE_FL_ACTIVE,
+	};
+	struct v4l2_subdev_krouting routing = {
+		.num_routes = 1,
+		.routes = &route,
+	};
+
+	return subdev_set_routing(sd, state, &routing);
+}
+
+int ipu6_isys_subdev_set_routing(struct v4l2_subdev *sd,
+				 struct v4l2_subdev_state *state,
+				 enum v4l2_subdev_format_whence which,
+				 struct v4l2_subdev_krouting *routing)
+{
+	return subdev_set_routing(sd, state, routing);
+}
+
+int ipu6_isys_subdev_init(struct ipu6_isys_subdev *asd,
+			  const struct v4l2_subdev_ops *ops,
+			  unsigned int nr_ctrls,
+			  unsigned int num_sink_pads,
+			  unsigned int num_source_pads)
+{
+	unsigned int num_pads = num_sink_pads + num_source_pads;
+	unsigned int i;
+	int ret;
+
+	v4l2_subdev_init(&asd->sd, ops);
+
+	asd->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE |
+			 V4L2_SUBDEV_FL_HAS_EVENTS |
+			 V4L2_SUBDEV_FL_STREAMS;
+	asd->sd.owner = THIS_MODULE;
+	asd->sd.entity.function = MEDIA_ENT_F_VID_IF_BRIDGE;
+
+	asd->pad = devm_kcalloc(&asd->isys->adev->auxdev.dev, num_pads,
+				sizeof(*asd->pad), GFP_KERNEL);
+
+	if (!asd->pad)
+		return -ENOMEM;
+
+	for (i = 0; i < num_sink_pads; i++)
+		asd->pad[i].flags = MEDIA_PAD_FL_SINK |
+				    MEDIA_PAD_FL_MUST_CONNECT;
+
+	for (i = num_sink_pads; i < num_pads; i++)
+		asd->pad[i].flags = MEDIA_PAD_FL_SOURCE;
+
+	ret = media_entity_pads_init(&asd->sd.entity, num_pads, asd->pad);
+	if (ret)
+		return ret;
+
+	if (asd->ctrl_init) {
+		ret = v4l2_ctrl_handler_init(&asd->ctrl_handler, nr_ctrls);
+		if (ret)
+			goto out_media_entity_cleanup;
+
+		asd->ctrl_init(&asd->sd);
+		if (asd->ctrl_handler.error) {
+			ret = asd->ctrl_handler.error;
+			goto out_v4l2_ctrl_handler_free;
+		}
+
+		asd->sd.ctrl_handler = &asd->ctrl_handler;
+	}
+
+	asd->source = -1;
+
+	return 0;
+
+out_v4l2_ctrl_handler_free:
+	v4l2_ctrl_handler_free(&asd->ctrl_handler);
+
+out_media_entity_cleanup:
+	media_entity_cleanup(&asd->sd.entity);
+
+	return ret;
+}
+
+void ipu6_isys_subdev_cleanup(struct ipu6_isys_subdev *asd)
+{
+	media_entity_cleanup(&asd->sd.entity);
+	v4l2_ctrl_handler_free(&asd->ctrl_handler);
+}
diff --git a/drivers/media/pci/intel/ipu6/ipu6-isys-subdev.h b/drivers/media/pci/intel/ipu6/ipu6-isys-subdev.h
new file mode 100644
index 000000000000..13e2c57efaea
--- /dev/null
+++ b/drivers/media/pci/intel/ipu6/ipu6-isys-subdev.h
@@ -0,0 +1,58 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/* Copyright (C) 2013 - 2023 Intel Corporation */
+
+#ifndef IPU6_ISYS_SUBDEV_H
+#define IPU6_ISYS_SUBDEV_H
+
+#include <media/v4l2-ctrls.h>
+#include <media/v4l2-subdev.h>
+
+struct ipu6_isys;
+
+struct ipu6_isys_subdev {
+	struct v4l2_subdev sd;
+	struct ipu6_isys *isys;
+	u32 const *supported_codes;
+	struct media_pad *pad;
+	struct v4l2_ctrl_handler ctrl_handler;
+	void (*ctrl_init)(struct v4l2_subdev *sd);
+	int source;	/* SSI stream source; -1 if unset */
+};
+
+#define to_ipu6_isys_subdev(__sd) \
+	container_of(__sd, struct ipu6_isys_subdev, sd)
+
+unsigned int ipu6_isys_mbus_code_to_bpp(u32 code);
+unsigned int ipu6_isys_mbus_code_to_mipi(u32 code);
+bool ipu6_isys_is_bayer_format(u32 code);
+u32 ipu6_isys_convert_bayer_order(u32 code, int x, int y);
+
+int ipu6_isys_subdev_set_fmt(struct v4l2_subdev *sd,
+			     struct v4l2_subdev_state *state,
+			     struct v4l2_subdev_format *fmt);
+int ipu6_isys_subdev_enum_mbus_code(struct v4l2_subdev *sd,
+				    struct v4l2_subdev_state *state,
+				    struct v4l2_subdev_mbus_code_enum
+				    *code);
+int ipu6_isys_subdev_link_validate(struct v4l2_subdev *sd,
+				   struct media_link *link,
+				   struct v4l2_subdev_format *source_fmt,
+				   struct v4l2_subdev_format *sink_fmt);
+u32 ipu6_isys_get_src_stream_by_src_pad(struct v4l2_subdev *sd, u32 pad);
+int ipu6_isys_get_stream_pad_fmt(struct v4l2_subdev *sd, u32 pad, u32 stream,
+				 struct v4l2_mbus_framefmt *format);
+int ipu6_isys_get_stream_pad_crop(struct v4l2_subdev *sd, u32 pad, u32 stream,
+				  struct v4l2_rect *crop);
+int ipu6_isys_subdev_init_cfg(struct v4l2_subdev *sd,
+			      struct v4l2_subdev_state *state);
+int ipu6_isys_subdev_set_routing(struct v4l2_subdev *sd,
+				 struct v4l2_subdev_state *state,
+				 enum v4l2_subdev_format_whence which,
+				 struct v4l2_subdev_krouting *routing);
+int ipu6_isys_subdev_init(struct ipu6_isys_subdev *asd,
+			  const struct v4l2_subdev_ops *ops,
+			  unsigned int nr_ctrls,
+			  unsigned int num_sink_pads,
+			  unsigned int num_source_pads);
+void ipu6_isys_subdev_cleanup(struct ipu6_isys_subdev *asd);
+#endif /* IPU6_ISYS_SUBDEV_H */
diff --git a/drivers/media/pci/intel/ipu6/ipu6-platform-isys-csi2-reg.h b/drivers/media/pci/intel/ipu6/ipu6-platform-isys-csi2-reg.h
new file mode 100644
index 000000000000..09f3cee5665d
--- /dev/null
+++ b/drivers/media/pci/intel/ipu6/ipu6-platform-isys-csi2-reg.h
@@ -0,0 +1,187 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/* Copyright (C) 2023 Intel Corporation */
+
+#ifndef IPU6_PLATFORM_ISYS_CSI2_REG_H
+#define IPU6_PLATFORM_ISYS_CSI2_REG_H
+
+#define CSI_REG_BASE			0x220000
+#define CSI_REG_BASE_PORT(id)		((id) * 0x1000)
+
+#define IPU6_CSI_PORT_A_ADDR_OFFSET	\
+		(CSI_REG_BASE + CSI_REG_BASE_PORT(0))
+#define IPU6_CSI_PORT_B_ADDR_OFFSET	\
+		(CSI_REG_BASE + CSI_REG_BASE_PORT(1))
+#define IPU6_CSI_PORT_C_ADDR_OFFSET	\
+		(CSI_REG_BASE + CSI_REG_BASE_PORT(2))
+#define IPU6_CSI_PORT_D_ADDR_OFFSET	\
+		(CSI_REG_BASE + CSI_REG_BASE_PORT(3))
+#define IPU6_CSI_PORT_E_ADDR_OFFSET	\
+		(CSI_REG_BASE + CSI_REG_BASE_PORT(4))
+#define IPU6_CSI_PORT_F_ADDR_OFFSET	\
+		(CSI_REG_BASE + CSI_REG_BASE_PORT(5))
+#define IPU6_CSI_PORT_G_ADDR_OFFSET	\
+		(CSI_REG_BASE + CSI_REG_BASE_PORT(6))
+#define IPU6_CSI_PORT_H_ADDR_OFFSET	\
+		(CSI_REG_BASE + CSI_REG_BASE_PORT(7))
+
+/* CSI Port Genral Purpose Registers */
+#define CSI_REG_PORT_GPREG_SRST                 0x0
+#define CSI_REG_PORT_GPREG_CSI2_SLV_REG_SRST    0x4
+#define CSI_REG_PORT_GPREG_CSI2_PORT_CONTROL    0x8
+
+/*
+ * Port IRQs mapping events:
+ * IRQ0 - CSI_FE event
+ * IRQ1 - CSI_SYNC
+ * IRQ2 - S2M_SIDS0TO7
+ * IRQ3 - S2M_SIDS8TO15
+ */
+#define CSI_PORT_REG_BASE_IRQ_CSI               0x80
+#define CSI_PORT_REG_BASE_IRQ_CSI_SYNC          0xA0
+#define CSI_PORT_REG_BASE_IRQ_S2M_SIDS0TOS7     0xC0
+#define CSI_PORT_REG_BASE_IRQ_S2M_SIDS8TOS15    0xE0
+
+#define CSI_PORT_REG_BASE_IRQ_EDGE_OFFSET	0x0
+#define CSI_PORT_REG_BASE_IRQ_MASK_OFFSET	0x4
+#define CSI_PORT_REG_BASE_IRQ_STATUS_OFFSET	0x8
+#define CSI_PORT_REG_BASE_IRQ_CLEAR_OFFSET	0xc
+#define CSI_PORT_REG_BASE_IRQ_ENABLE_OFFSET	0x10
+#define CSI_PORT_REG_BASE_IRQ_LEVEL_NOT_PULSE_OFFSET	0x14
+
+#define IPU6SE_CSI_RX_ERROR_IRQ_MASK		GENMASK(18, 0)
+#define IPU6_CSI_RX_ERROR_IRQ_MASK		GENMASK(19, 0)
+
+#define CSI_RX_NUM_ERRORS_IN_IRQ		20
+#define CSI_RX_NUM_IRQ				32
+
+#define IPU_CSI_RX_IRQ_FS_VC(chn)	(1 << ((chn) * 2))
+#define IPU_CSI_RX_IRQ_FE_VC(chn)	(2 << ((chn) * 2))
+
+/* PPI2CSI */
+#define CSI_REG_PPI2CSI_ENABLE				0x200
+#define CSI_REG_PPI2CSI_CONFIG_PPI_INTF			0x204
+#define PPI_INTF_CONFIG_NOF_ENABLED_DLANES_MASK		GENMASK(4, 3)
+#define CSI_REG_PPI2CSI_CONFIG_CSI_FEATURE		0x208
+
+enum CSI_PPI2CSI_CTRL {
+	CSI_PPI2CSI_DISABLE = 0,
+	CSI_PPI2CSI_ENABLE = 1,
+};
+
+/* CSI_FE */
+#define CSI_REG_CSI_FE_ENABLE                   0x280
+#define CSI_REG_CSI_FE_MODE                     0x284
+#define CSI_REG_CSI_FE_MUX_CTRL                 0x288
+#define CSI_REG_CSI_FE_SYNC_CNTR_SEL            0x290
+
+enum CSI_FE_ENABLE_TYPE {
+	CSI_FE_DISABLE = 0,
+	CSI_FE_ENABLE = 1,
+};
+
+enum CSI_FE_MODE_TYPE {
+	CSI_FE_DPHY_MODE = 0,
+	CSI_FE_CPHY_MODE = 1,
+};
+
+enum CSI_FE_INPUT_SELECTOR {
+	CSI_SENSOR_INPUT = 0,
+	CSI_MIPIGEN_INPUT = 1,
+};
+
+enum CSI_FE_SYNC_CNTR_SEL_TYPE {
+	CSI_CNTR_SENSOR_LINE_ID = BIT(0),
+	CSI_CNTR_INT_LINE_PKT_ID = ~CSI_CNTR_SENSOR_LINE_ID,
+	CSI_CNTR_SENSOR_FRAME_ID = BIT(1),
+	CSI_CNTR_INT_FRAME_PKT_ID = ~CSI_CNTR_SENSOR_FRAME_ID,
+};
+
+/* CSI HUB General Purpose Registers */
+#define CSI_REG_HUB_GPREG_SRST			(CSI_REG_BASE + 0x18000)
+#define CSI_REG_HUB_GPREG_SLV_REG_SRST		(CSI_REG_BASE + 0x18004)
+
+#define CSI_REG_HUB_DRV_ACCESS_PORT(id)	(CSI_REG_BASE + 0x18018 + (id) * 4)
+#define CSI_REG_HUB_FW_ACCESS_PORT_OFS		0x17000
+#define CSI_REG_HUB_FW_ACCESS_PORT_V6OFS	0x16000
+#define CSI_REG_HUB_FW_ACCESS_PORT(ofs, id)	\
+					(CSI_REG_BASE + (ofs) + (id) * 4)
+
+enum CSI_PORT_CLK_GATING_SWITCH {
+	CSI_PORT_CLK_GATING_OFF = 0,
+	CSI_PORT_CLK_GATING_ON = 1,
+};
+
+#define CSI_REG_BASE_HUB_IRQ                        0x18200
+
+#define IPU6_REG_ISYS_CSI_TOP_CTRL0_IRQ_EDGE			0x238200
+#define IPU6_REG_ISYS_CSI_TOP_CTRL0_IRQ_MASK			0x238204
+#define IPU6_REG_ISYS_CSI_TOP_CTRL0_IRQ_STATUS			0x238208
+#define IPU6_REG_ISYS_CSI_TOP_CTRL0_IRQ_CLEAR			0x23820c
+#define IPU6_REG_ISYS_CSI_TOP_CTRL0_IRQ_ENABLE			0x238210
+#define IPU6_REG_ISYS_CSI_TOP_CTRL0_IRQ_LEVEL_NOT_PULSE		0x238214
+
+#define IPU6_REG_ISYS_CSI_TOP_CTRL1_IRQ_EDGE			0x238220
+#define IPU6_REG_ISYS_CSI_TOP_CTRL1_IRQ_MASK			0x238224
+#define IPU6_REG_ISYS_CSI_TOP_CTRL1_IRQ_STATUS			0x238228
+#define IPU6_REG_ISYS_CSI_TOP_CTRL1_IRQ_CLEAR			0x23822c
+#define IPU6_REG_ISYS_CSI_TOP_CTRL1_IRQ_ENABLE			0x238230
+#define IPU6_REG_ISYS_CSI_TOP_CTRL1_IRQ_LEVEL_NOT_PULSE		0x238234
+
+/* MTL IPU6V6 irq ctrl0 & ctrl1 */
+#define IPU6V6_REG_ISYS_CSI_TOP_CTRL0_IRQ_EDGE			0x238700
+#define IPU6V6_REG_ISYS_CSI_TOP_CTRL0_IRQ_MASK			0x238704
+#define IPU6V6_REG_ISYS_CSI_TOP_CTRL0_IRQ_STATUS		0x238708
+#define IPU6V6_REG_ISYS_CSI_TOP_CTRL0_IRQ_CLEAR			0x23870c
+#define IPU6V6_REG_ISYS_CSI_TOP_CTRL0_IRQ_ENABLE		0x238710
+#define IPU6V6_REG_ISYS_CSI_TOP_CTRL0_IRQ_LEVEL_NOT_PULSE	0x238714
+
+#define IPU6V6_REG_ISYS_CSI_TOP_CTRL1_IRQ_EDGE			0x238720
+#define IPU6V6_REG_ISYS_CSI_TOP_CTRL1_IRQ_MASK			0x238724
+#define IPU6V6_REG_ISYS_CSI_TOP_CTRL1_IRQ_STATUS		0x238728
+#define IPU6V6_REG_ISYS_CSI_TOP_CTRL1_IRQ_CLEAR			0x23872c
+#define IPU6V6_REG_ISYS_CSI_TOP_CTRL1_IRQ_ENABLE		0x238730
+#define IPU6V6_REG_ISYS_CSI_TOP_CTRL1_IRQ_LEVEL_NOT_PULSE	0x238734
+
+/*
+ * 3:0 CSI_PORT.irq_out[3:0] CSI_PORT_CTRL0 IRQ outputs (4bits)
+ * [0] CSI_PORT.IRQ_CTRL0_csi
+ * [1] CSI_PORT.IRQ_CTRL1_csi_sync
+ * [2] CSI_PORT.IRQ_CTRL2_s2m_sids0to7
+ * [3] CSI_PORT.IRQ_CTRL3_s2m_sids8to15
+ */
+#define IPU6_ISYS_UNISPART_IRQ_CSI2(port)		\
+				   (0x3 << ((port) * IPU6_CSI_IRQ_NUM_PER_PIPE))
+
+/*
+ * ipu6se support 2 front ends, 2 port per front end, 4 ports 0..3
+ * sip0 - 0, 1
+ * sip1 - 2, 3
+ * 0 and 2 support 4 data lanes, 1 and 3 support 2 data lanes
+ * all offset are base from isys base address
+ */
+
+#define CSI2_HUB_GPREG_SIP_SRST(sip)			(0x238038 + (sip) * 4)
+#define CSI2_HUB_GPREG_SIP_FB_PORT_CFG(sip)		(0x238050 + (sip) * 4)
+
+#define CSI2_HUB_GPREG_DPHY_TIMER_INCR			0x238040
+#define CSI2_HUB_GPREG_HPLL_FREQ			0x238044
+#define CSI2_HUB_GPREG_IS_CLK_RATIO			0x238048
+#define CSI2_HUB_GPREG_HPLL_FREQ_ISCLK_RATE_OVERRIDE	0x23804c
+#define CSI2_HUB_GPREG_PORT_CLKGATING_DISABLE		0x238058
+#define CSI2_HUB_GPREG_SIP0_CSI_RX_A_CONTROL		0x23805c
+#define CSI2_HUB_GPREG_SIP0_CSI_RX_B_CONTROL		0x238088
+#define CSI2_HUB_GPREG_SIP1_CSI_RX_A_CONTROL		0x2380a4
+#define CSI2_HUB_GPREG_SIP1_CSI_RX_B_CONTROL		0x2380d0
+
+#define CSI2_SIP_TOP_CSI_RX_BASE(sip)		(0x23805c + (sip) * 0x48)
+#define CSI2_SIP_TOP_CSI_RX_PORT_BASE_0(port)	(0x23805c + ((port) / 2) * 0x48)
+#define CSI2_SIP_TOP_CSI_RX_PORT_BASE_1(port)	(0x238088 + ((port) / 2) * 0x48)
+
+/* offset from port base */
+#define CSI2_SIP_TOP_CSI_RX_PORT_CONTROL		0x0
+#define CSI2_SIP_TOP_CSI_RX_DLY_CNT_TERMEN_CLANE	0x4
+#define CSI2_SIP_TOP_CSI_RX_DLY_CNT_SETTLE_CLANE	0x8
+#define CSI2_SIP_TOP_CSI_RX_DLY_CNT_TERMEN_DLANE(lane)	(0xc + (lane) * 8)
+#define CSI2_SIP_TOP_CSI_RX_DLY_CNT_SETTLE_DLANE(lane)	(0x10 + (lane) * 8)
+
+#endif /* IPU6_ISYS_CSI2_REG_H */
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 86+ messages in thread

* [PATCH v2 09/15] media: intel/ipu6: add the CSI2 DPHY implementation
  2023-10-24 11:29 [PATCH v2 00/15] Intel IPU6 and IPU6 input system drivers bingbu.cao
                   ` (7 preceding siblings ...)
  2023-10-24 11:29 ` [PATCH v2 08/15] media: intel/ipu6: add IPU6 CSI2 receiver v4l2 sub-device bingbu.cao
@ 2023-10-24 11:29 ` bingbu.cao
  2023-10-24 11:29 ` [PATCH v2 10/15] media: intel/ipu6: add input system driver bingbu.cao
                   ` (7 subsequent siblings)
  16 siblings, 0 replies; 86+ messages in thread
From: bingbu.cao @ 2023-10-24 11:29 UTC (permalink / raw)
  To: linux-media, sakari.ailus, laurent.pinchart
  Cc: andriy.shevchenko, hdegoede, ilpo.jarvinen, andreaskleist,
	claus.stovgaard, tfiga, senozhatsky, tomi.valkeinen, bingbu.cao,
	bingbu.cao, tian.shu.qiu, hongju.wang

From: Bingbu Cao <bingbu.cao@intel.com>

IPU6 CSI2 DPHY hardware varies on different platforms, current
IPU6 has three DPHY hardware instance which maybe used on tigerlake,
alderlake, metorlake and jasperlake. MCD DPHY is shipped on tigerlake
and alderlake, DWC DPHY is shipped on metorlake.

Each PHY has its own register space, input system driver call the
DPHY callback which was set at isys_probe().

Signed-off-by: Bingbu Cao <bingbu.cao@intel.com>
---
 .../media/pci/intel/ipu6/ipu6-isys-dwc-phy.c  | 533 +++++++++++++
 .../media/pci/intel/ipu6/ipu6-isys-jsl-phy.c  | 237 ++++++
 .../media/pci/intel/ipu6/ipu6-isys-mcd-phy.c  | 712 ++++++++++++++++++
 3 files changed, 1482 insertions(+)
 create mode 100644 drivers/media/pci/intel/ipu6/ipu6-isys-dwc-phy.c
 create mode 100644 drivers/media/pci/intel/ipu6/ipu6-isys-jsl-phy.c
 create mode 100644 drivers/media/pci/intel/ipu6/ipu6-isys-mcd-phy.c

diff --git a/drivers/media/pci/intel/ipu6/ipu6-isys-dwc-phy.c b/drivers/media/pci/intel/ipu6/ipu6-isys-dwc-phy.c
new file mode 100644
index 000000000000..58af982f43ee
--- /dev/null
+++ b/drivers/media/pci/intel/ipu6/ipu6-isys-dwc-phy.c
@@ -0,0 +1,533 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2013 - 2023 Intel Corporation
+ */
+
+#include <linux/bitfield.h>
+#include <linux/delay.h>
+#include <linux/iopoll.h>
+
+#include "ipu6-isys.h"
+#include "ipu6-platform-isys-csi2-reg.h"
+#include "ipu6-platform-regs.h"
+
+#define IPU6_DWC_DPHY_BASE(i)			(0x238038 + 0x34 * (i))
+#define IPU6_DWC_DPHY_RSTZ			0x00
+#define IPU6_DWC_DPHY_SHUTDOWNZ			0x04
+#define IPU6_DWC_DPHY_HSFREQRANGE		0x08
+#define IPU6_DWC_DPHY_CFGCLKFREQRANGE		0x0c
+#define IPU6_DWC_DPHY_TEST_IFC_ACCESS_MODE	0x10
+#define IPU6_DWC_DPHY_TEST_IFC_REQ		0x14
+#define IPU6_DWC_DPHY_TEST_IFC_REQ_COMPLETION	0x18
+#define IPU6_DWC_DPHY_DFT_CTRL0			0x28
+#define IPU6_DWC_DPHY_DFT_CTRL1			0x2c
+#define IPU6_DWC_DPHY_DFT_CTRL2			0x30
+
+/*
+ * test IFC request definition:
+ * - req: 0 for read, 1 for write
+ * - 12 bits address
+ * - 8bits data (will ignore for read)
+ * --24----16------4-----0
+ * --|-data-|-addr-|-req-|
+ */
+#define IFC_REQ(req, addr, data) (FIELD_PREP(GENMASK(23, 16), data) | \
+				  FIELD_PREP(GENMASK(15, 4), addr) | \
+				  FIELD_PREP(GENMASK(1, 0), req))
+
+#define TEST_IFC_REQ_READ	0
+#define TEST_IFC_REQ_WRITE	1
+#define TEST_IFC_REQ_RESET	2
+
+#define TEST_IFC_ACCESS_MODE_FSM	0
+#define TEST_IFC_ACCESS_MODE_IFC_CTL	1
+
+enum phy_fsm_state {
+	PHY_FSM_STATE_POWERON = 0,
+	PHY_FSM_STATE_BGPON = 1,
+	PHY_FSM_STATE_CAL_TYPE = 2,
+	PHY_FSM_STATE_BURNIN_CAL = 3,
+	PHY_FSM_STATE_TERMCAL = 4,
+	PHY_FSM_STATE_OFFSETCAL = 5,
+	PHY_FSM_STATE_OFFSET_LANE = 6,
+	PHY_FSM_STATE_IDLE = 7,
+	PHY_FSM_STATE_ULP = 8,
+	PHY_FSM_STATE_DDLTUNNING = 9,
+	PHY_FSM_STATE_SKEW_BACKWARD = 10,
+	PHY_FSM_STATE_INVALID,
+};
+
+static void dwc_dphy_write(struct ipu6_isys *isys, u32 phy_id, u32 addr,
+			   u32 data)
+{
+	struct device *dev = &isys->adev->auxdev.dev;
+	void __iomem *isys_base = isys->pdata->base;
+	void __iomem *base = isys_base + IPU6_DWC_DPHY_BASE(phy_id);
+
+	dev_dbg(dev, "write: reg 0x%lx = data 0x%x", base + addr - isys_base,
+		data);
+	writel(data, base + addr);
+}
+
+static u32 dwc_dphy_read(struct ipu6_isys *isys, u32 phy_id, u32 addr)
+{
+	struct device *dev = &isys->adev->auxdev.dev;
+	void __iomem *isys_base = isys->pdata->base;
+	void __iomem *base = isys_base + IPU6_DWC_DPHY_BASE(phy_id);
+	u32 data;
+
+	data = readl(base + addr);
+	dev_dbg(dev, "read: reg 0x%lx = data 0x%x", base + addr - isys_base,
+		data);
+
+	return data;
+}
+
+static void dwc_dphy_write_mask(struct ipu6_isys *isys, u32 phy_id, u32 addr,
+				u32 data, u8 shift, u8 width)
+{
+	u32 temp;
+	u32 mask;
+
+	mask = (1 << width) - 1;
+	temp = dwc_dphy_read(isys, phy_id, addr);
+	temp &= ~(mask << shift);
+	temp |= (data & mask) << shift;
+	dwc_dphy_write(isys, phy_id, addr, temp);
+}
+
+static u32 __maybe_unused dwc_dphy_read_mask(struct ipu6_isys *isys, u32 phy_id,
+					     u32 addr, u8 shift,  u8 width)
+{
+	u32 val;
+
+	val = dwc_dphy_read(isys, phy_id, addr) >> shift;
+	return val & ((1 << width) - 1);
+}
+
+#define DWC_DPHY_TIMEOUT (5 * USEC_PER_SEC)
+static int dwc_dphy_ifc_read(struct ipu6_isys *isys, u32 phy_id, u32 addr,
+			     u32 *val)
+{
+	struct device *dev = &isys->adev->auxdev.dev;
+	void __iomem *isys_base = isys->pdata->base;
+	void __iomem *base = isys_base + IPU6_DWC_DPHY_BASE(phy_id);
+	void __iomem *reg;
+	u32 completion;
+	int ret;
+
+	dwc_dphy_write(isys, phy_id, IPU6_DWC_DPHY_TEST_IFC_REQ,
+		       IFC_REQ(TEST_IFC_REQ_READ, addr, 0));
+	reg = base + IPU6_DWC_DPHY_TEST_IFC_REQ_COMPLETION;
+	ret = readl_poll_timeout(reg, completion, !(completion & BIT(0)),
+				 10, DWC_DPHY_TIMEOUT);
+	if (ret) {
+		dev_err(dev, "DWC ifc request read timeout\n");
+		return ret;
+	}
+
+	*val = completion >> 8 & 0xff;
+	*val = FIELD_GET(GENMASK(15, 8), completion);
+	dev_dbg(dev, "DWC ifc read 0x%x = 0x%x", addr, *val);
+
+	return 0;
+}
+
+static int dwc_dphy_ifc_write(struct ipu6_isys *isys, u32 phy_id, u32 addr,
+			      u32 data)
+{
+	struct device *dev = &isys->adev->auxdev.dev;
+	void __iomem *isys_base = isys->pdata->base;
+	void __iomem *base = isys_base + IPU6_DWC_DPHY_BASE(phy_id);
+	void __iomem *reg;
+	u32 completion;
+	int ret;
+
+	dwc_dphy_write(isys, phy_id, IPU6_DWC_DPHY_TEST_IFC_REQ,
+		       IFC_REQ(TEST_IFC_REQ_WRITE, addr, data));
+	completion = readl(base + IPU6_DWC_DPHY_TEST_IFC_REQ_COMPLETION);
+	reg = base + IPU6_DWC_DPHY_TEST_IFC_REQ_COMPLETION;
+	ret = readl_poll_timeout(reg, completion, !(completion & BIT(0)),
+				 10, DWC_DPHY_TIMEOUT);
+	if (ret)
+		dev_err(dev, "DWC ifc request write timeout\n");
+
+	return ret;
+}
+
+static void dwc_dphy_ifc_write_mask(struct ipu6_isys *isys, u32 phy_id,
+				    u32 addr, u32 data, u8 shift, u8 width)
+{
+	u32 temp, mask;
+	int ret;
+
+	ret = dwc_dphy_ifc_read(isys, phy_id, addr, &temp);
+	if (ret)
+		return;
+
+	mask = (1 << width) - 1;
+	temp &= ~(mask << shift);
+	temp |= (data & mask) << shift;
+	dwc_dphy_ifc_write(isys, phy_id, addr, temp);
+}
+
+static u32 dwc_dphy_ifc_read_mask(struct ipu6_isys *isys, u32 phy_id, u32 addr,
+				  u8 shift, u8 width)
+{
+	int ret;
+	u32 val;
+
+	ret = dwc_dphy_ifc_read(isys, phy_id, addr, &val);
+	if (ret)
+		return 0;
+
+	return ((val >> shift) & ((1 << width) - 1));
+}
+
+static int dwc_dphy_pwr_up(struct ipu6_isys *isys, u32 phy_id)
+{
+	struct device *dev = &isys->adev->auxdev.dev;
+	u32 fsm_state;
+	int ret;
+
+	dwc_dphy_write(isys, phy_id, IPU6_DWC_DPHY_RSTZ, 1);
+	usleep_range(10, 20);
+	dwc_dphy_write(isys, phy_id, IPU6_DWC_DPHY_SHUTDOWNZ, 1);
+
+	ret = read_poll_timeout(dwc_dphy_ifc_read_mask, fsm_state,
+				(fsm_state == PHY_FSM_STATE_IDLE ||
+				 fsm_state == PHY_FSM_STATE_ULP),
+				100, DWC_DPHY_TIMEOUT, false, isys,
+				phy_id, 0x1e, 0, 4);
+
+	if (ret)
+		dev_err(dev, "Dphy %d power up failed, state 0x%x", phy_id,
+			fsm_state);
+
+	return ret;
+}
+
+struct dwc_dphy_freq_range {
+	u8 hsfreq;
+	u16 min;
+	u16 max;
+	u16 default_mbps;
+	u16 osc_freq_target;
+};
+
+#define DPHY_FREQ_RANGE_NUM		(63)
+#define DPHY_FREQ_RANGE_INVALID_INDEX	(0xff)
+static const struct dwc_dphy_freq_range freqranges[DPHY_FREQ_RANGE_NUM] = {
+	{0x00,	80,	97,	80,	335},
+	{0x10,	80,	107,	90,	335},
+	{0x20,	84,	118,	100,	335},
+	{0x30,	93,	128,	110,	335},
+	{0x01,	103,	139,	120,	335},
+	{0x11,	112,	149,	130,	335},
+	{0x21,	122,	160,	140,	335},
+	{0x31,	131,	170,	150,	335},
+	{0x02,	141,	181,	160,	335},
+	{0x12,	150,	191,	170,	335},
+	{0x22,	160,	202,	180,	335},
+	{0x32,	169,	212,	190,	335},
+	{0x03,	183,	228,	205,	335},
+	{0x13,	198,	244,	220,	335},
+	{0x23,	212,	259,	235,	335},
+	{0x33,	226,	275,	250,	335},
+	{0x04,	250,	301,	275,	335},
+	{0x14,	274,	328,	300,	335},
+	{0x25,	297,	354,	325,	335},
+	{0x35,	321,	380,	350,	335},
+	{0x05,	369,	433,	400,	335},
+	{0x16,	416,	485,	450,	335},
+	{0x26,	464,	538,	500,	335},
+	{0x37,	511,	590,	550,	335},
+	{0x07,	559,	643,	600,	335},
+	{0x18,	606,	695,	650,	335},
+	{0x28,	654,	748,	700,	335},
+	{0x39,	701,	800,	750,	335},
+	{0x09,	749,	853,	800,	335},
+	{0x19,	796,	905,	850,	335},
+	{0x29,	844,	958,	900,	335},
+	{0x3a,	891,	1010,	950,	335},
+	{0x0a,	939,	1063,	1000,	335},
+	{0x1a,	986,	1115,	1050,	335},
+	{0x2a,	1034,	1168,	1100,	335},
+	{0x3b,	1081,	1220,	1150,	335},
+	{0x0b,	1129,	1273,	1200,	335},
+	{0x1b,	1176,	1325,	1250,	335},
+	{0x2b,	1224,	1378,	1300,	335},
+	{0x3c,	1271,	1430,	1350,	335},
+	{0x0c,	1319,	1483,	1400,	335},
+	{0x1c,	1366,	1535,	1450,	335},
+	{0x2c,	1414,	1588,	1500,	335},
+	{0x3d,	1461,	1640,	1550,	208},
+	{0x0d,	1509,	1693,	1600,	214},
+	{0x1d,	1556,	1745,	1650,	221},
+	{0x2e,	1604,	1798,	1700,	228},
+	{0x3e,	1651,	1850,	1750,	234},
+	{0x0e,	1699,	1903,	1800,	241},
+	{0x1e,	1746,	1955,	1850,	248},
+	{0x2f,	1794,	2008,	1900,	255},
+	{0x3f,	1841,	2060,	1950,	261},
+	{0x0f,	1889,	2113,	2000,	268},
+	{0x40,	1936,	2165,	2050,	275},
+	{0x41,	1984,	2218,	2100,	281},
+	{0x42,	2031,	2270,	2150,	288},
+	{0x43,	2079,	2323,	2200,	294},
+	{0x44,	2126,	2375,	2250,	302},
+	{0x45,	2174,	2428,	2300,	308},
+	{0x46,	2221,	2480,	2350,	315},
+	{0x47,	2269,	2500,	2400,	321},
+	{0x48,	2316,	2500,	2450,	328},
+	{0x49,	2364,	2500,	2500,	335}
+};
+
+static u16 get_hsfreq_by_mbps(u32 mbps)
+{
+	unsigned int i = DPHY_FREQ_RANGE_NUM;
+
+	while (i--) {
+		if (freqranges[i].default_mbps == mbps ||
+		    (mbps >= freqranges[i].min && mbps <= freqranges[i].max))
+			return i;
+	}
+
+	return DPHY_FREQ_RANGE_INVALID_INDEX;
+}
+
+static int ipu6_isys_dwc_phy_config(struct ipu6_isys *isys,
+				    u32 phy_id, u32 mbps)
+{
+	struct ipu6_bus_device *adev = isys->adev;
+	struct device *dev = &adev->auxdev.dev;
+	struct ipu6_device *isp = adev->isp;
+	u32 cfg_clk_freqrange;
+	u32 osc_freq_target;
+	u32 index;
+
+	dev_dbg(dev, "config Dphy %u with %u mbps", phy_id, mbps);
+
+	index = get_hsfreq_by_mbps(mbps);
+	if (index == DPHY_FREQ_RANGE_INVALID_INDEX) {
+		dev_err(dev, "link freq not found for mbps %u", mbps);
+		return -EINVAL;
+	}
+
+	dwc_dphy_write_mask(isys, phy_id, IPU6_DWC_DPHY_HSFREQRANGE,
+			    freqranges[index].hsfreq, 0, 7);
+
+	/* Force termination Calibration */
+	if (isys->phy_termcal_val) {
+		dwc_dphy_ifc_write_mask(isys, phy_id, 0x20a, 0x1, 0, 1);
+		dwc_dphy_ifc_write_mask(isys, phy_id, 0x209, 0x3, 0, 2);
+		dwc_dphy_ifc_write_mask(isys, phy_id, 0x209,
+					isys->phy_termcal_val, 4, 4);
+	}
+
+	/*
+	 * Enable override to configure the DDL target oscillation
+	 * frequency on bit 0 of register 0xe4
+	 */
+	dwc_dphy_ifc_write_mask(isys, phy_id, 0xe4, 0x1, 0, 1);
+	/*
+	 * configure registers 0xe2, 0xe3 with the
+	 * appropriate DDL target oscillation frequency
+	 * 0x1cc(460)
+	 */
+	osc_freq_target = freqranges[index].osc_freq_target;
+	dwc_dphy_ifc_write_mask(isys, phy_id, 0xe2,
+				osc_freq_target & 0xff, 0, 8);
+	dwc_dphy_ifc_write_mask(isys, phy_id, 0xe3,
+				(osc_freq_target >> 8) & 0xf, 0, 4);
+
+	if (mbps < 1500) {
+		/* deskew_polarity_rw, for < 1.5Gbps */
+		dwc_dphy_ifc_write_mask(isys, phy_id, 0x8, 0x1, 5, 1);
+	}
+
+	/*
+	 * Set cfgclkfreqrange[5:0] = round[(Fcfg_clk(MHz)-17)*4]
+	 * (38.4 - 17) * 4 = ~85 (0x55)
+	 */
+	cfg_clk_freqrange = (isp->buttress.ref_clk - 170) * 4 / 10;
+	dev_dbg(dev, "ref_clk = %u clk_freqrange = %u",
+		isp->buttress.ref_clk, cfg_clk_freqrange);
+	dwc_dphy_write_mask(isys, phy_id, IPU6_DWC_DPHY_CFGCLKFREQRANGE,
+			    cfg_clk_freqrange, 0, 8);
+
+	dwc_dphy_write_mask(isys, phy_id, IPU6_DWC_DPHY_DFT_CTRL2, 0x1, 4, 1);
+	dwc_dphy_write_mask(isys, phy_id, IPU6_DWC_DPHY_DFT_CTRL2, 0x1, 8, 1);
+
+	return 0;
+}
+
+static void ipu6_isys_dwc_phy_aggr_setup(struct ipu6_isys *isys, u32 master,
+					 u32 slave, u32 mbps)
+{
+	/* Config mastermacro */
+	dwc_dphy_ifc_write_mask(isys, master, 0x133, 0x1, 0, 1);
+	dwc_dphy_ifc_write_mask(isys, slave, 0x133, 0x0, 0, 1);
+
+	/* Config master PHY clk lane to drive long channel clk */
+	dwc_dphy_ifc_write_mask(isys, master, 0x307, 0x1, 2, 1);
+	dwc_dphy_ifc_write_mask(isys, slave, 0x307, 0x0, 2, 1);
+
+	/* Config both PHYs data lanes to get clk from long channel */
+	dwc_dphy_ifc_write_mask(isys, master, 0x508, 0x1, 5, 1);
+	dwc_dphy_ifc_write_mask(isys, slave, 0x508, 0x1, 5, 1);
+	dwc_dphy_ifc_write_mask(isys, master, 0x708, 0x1, 5, 1);
+	dwc_dphy_ifc_write_mask(isys, slave, 0x708, 0x1, 5, 1);
+
+	/* Config slave PHY clk lane to bypass long channel clk to DDR clk */
+	dwc_dphy_ifc_write_mask(isys, master, 0x308, 0x0, 3, 1);
+	dwc_dphy_ifc_write_mask(isys, slave, 0x308, 0x1, 3, 1);
+
+	/* Override slave PHY clk lane enable (DPHYRXCLK_CLL_demux module) */
+	dwc_dphy_ifc_write_mask(isys, slave, 0xe0, 0x3, 0, 2);
+
+	/* Override slave PHY DDR clk lane enable (DPHYHSRX_div124 module) */
+	dwc_dphy_ifc_write_mask(isys, slave, 0xe1, 0x1, 1, 1);
+	dwc_dphy_ifc_write_mask(isys, slave, 0x307, 0x1, 3, 1);
+
+	/* Turn off slave PHY LP-RX clk lane */
+	dwc_dphy_ifc_write_mask(isys, slave, 0x304, 0x1, 7, 1);
+	dwc_dphy_ifc_write_mask(isys, slave, 0x305, 0xa, 0, 5);
+}
+
+#define PHY_E	4
+static int ipu6_isys_dwc_phy_powerup_ack(struct ipu6_isys *isys, u32 phy_id)
+{
+	struct device *dev = &isys->adev->auxdev.dev;
+	u32 rescal_done;
+	int ret;
+
+	ret = dwc_dphy_pwr_up(isys, phy_id);
+	if (ret != 0) {
+		dev_err(dev, "Dphy %u power up failed(%d)", phy_id, ret);
+		return ret;
+	}
+
+	/* reset forcerxmode */
+	dwc_dphy_write_mask(isys, phy_id, IPU6_DWC_DPHY_DFT_CTRL2, 0, 4, 1);
+	dwc_dphy_write_mask(isys, phy_id, IPU6_DWC_DPHY_DFT_CTRL2, 0, 8, 1);
+
+	dev_dbg(dev, "Dphy %u is ready!", phy_id);
+
+	if (phy_id != PHY_E || isys->phy_termcal_val)
+		return 0;
+
+	usleep_range(100, 200);
+	rescal_done = dwc_dphy_ifc_read_mask(isys, phy_id, 0x221, 7, 1);
+	if (rescal_done) {
+		isys->phy_termcal_val = dwc_dphy_ifc_read_mask(isys, phy_id,
+							       0x220, 2, 4);
+		dev_dbg(dev, "termcal done with value = %u",
+			isys->phy_termcal_val);
+	}
+
+	return 0;
+}
+
+static void ipu6_isys_dwc_phy_reset(struct ipu6_isys *isys, u32 phy_id)
+{
+	dev_dbg(&isys->adev->auxdev.dev, "Reset phy %u", phy_id);
+
+	dwc_dphy_write(isys, phy_id, IPU6_DWC_DPHY_SHUTDOWNZ, 0);
+	dwc_dphy_write(isys, phy_id, IPU6_DWC_DPHY_RSTZ, 0);
+	dwc_dphy_write(isys, phy_id, IPU6_DWC_DPHY_TEST_IFC_ACCESS_MODE,
+		       TEST_IFC_ACCESS_MODE_FSM);
+	dwc_dphy_write(isys, phy_id, IPU6_DWC_DPHY_TEST_IFC_REQ,
+		       TEST_IFC_REQ_RESET);
+}
+
+int ipu6_isys_dwc_phy_set_power(struct ipu6_isys *isys,
+				struct ipu6_isys_csi2_config *cfg,
+				const struct ipu6_isys_csi2_timing *timing,
+				bool on)
+{
+	struct device *dev = &isys->adev->auxdev.dev;
+	void __iomem *isys_base = isys->pdata->base;
+	u32 phy_id, primary, secondary;
+	u32 nlanes, port, mbps;
+	s64 link_freq;
+	int ret;
+
+	port = cfg->port;
+
+	if (!isys_base || port >= isys->pdata->ipdata->csi2.nports) {
+		dev_warn(dev, "invalid port ID %d\n", port);
+		return -EINVAL;
+	}
+
+	nlanes = cfg->nlanes;
+	/* only port 0, 2 and 4 support 4 lanes */
+	if (nlanes == 4 && port % 2) {
+		dev_err(dev, "invalid csi-port %u with %u lanes\n", port,
+			nlanes);
+		return -EINVAL;
+	}
+
+	link_freq = ipu6_isys_csi2_get_link_freq(&isys->csi2[port]);
+	if (link_freq < 0) {
+		dev_err(dev, "get link freq failed(%lld).\n", link_freq);
+		return link_freq;
+	}
+
+	mbps = div_u64(link_freq, 500000);
+
+	phy_id = port;
+	primary = port & ~1;
+	secondary = primary + 1;
+	if (on) {
+		if (nlanes == 4) {
+			dev_dbg(dev, "config phy %u and %u in aggr mode\n",
+				primary, secondary);
+
+			ipu6_isys_dwc_phy_reset(isys, primary);
+			ipu6_isys_dwc_phy_reset(isys, secondary);
+			ipu6_isys_dwc_phy_aggr_setup(isys, primary,
+						     secondary, mbps);
+
+			ret = ipu6_isys_dwc_phy_config(isys, primary, mbps);
+			if (ret)
+				return ret;
+			ret = ipu6_isys_dwc_phy_config(isys, secondary, mbps);
+			if (ret)
+				return ret;
+
+			ret = ipu6_isys_dwc_phy_powerup_ack(isys, primary);
+			if (ret)
+				return ret;
+
+			ret = ipu6_isys_dwc_phy_powerup_ack(isys, secondary);
+			return ret;
+		}
+
+		dev_dbg(dev, "config phy %u with %u lanes in non-aggr mode\n",
+			phy_id, nlanes);
+
+		ipu6_isys_dwc_phy_reset(isys, phy_id);
+		ret = ipu6_isys_dwc_phy_config(isys, phy_id, mbps);
+		if (ret)
+			return ret;
+
+		ret = ipu6_isys_dwc_phy_powerup_ack(isys, phy_id);
+		return ret;
+	}
+
+	if (nlanes == 4) {
+		dev_dbg(dev, "Power down phy %u and phy %u for port %u\n",
+			primary, secondary, port);
+		ipu6_isys_dwc_phy_reset(isys, secondary);
+		ipu6_isys_dwc_phy_reset(isys, primary);
+
+		return 0;
+	}
+
+	dev_dbg(dev, "Powerdown phy %u with %u lanes\n", phy_id, nlanes);
+
+	ipu6_isys_dwc_phy_reset(isys, phy_id);
+
+	return 0;
+}
diff --git a/drivers/media/pci/intel/ipu6/ipu6-isys-jsl-phy.c b/drivers/media/pci/intel/ipu6/ipu6-isys-jsl-phy.c
new file mode 100644
index 000000000000..f9ee7496613e
--- /dev/null
+++ b/drivers/media/pci/intel/ipu6/ipu6-isys-jsl-phy.c
@@ -0,0 +1,237 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2013 - 2023 Intel Corporation
+ */
+#include <linux/bitfield.h>
+
+#include "ipu6-isys.h"
+#include "ipu6-platform-isys-csi2-reg.h"
+#include "ipu6-platform-regs.h"
+
+/* only use BB0, BB2, BB4, and BB6 on PHY0 */
+#define IPU6SE_ISYS_PHY_BB_NUM		4
+#define IPU6SE_ISYS_PHY_0_BASE		0x10000
+
+#define PHY_CPHY_DLL_OVRD(x)		(0x100 + 0x100 * (x))
+#define PHY_CPHY_RX_CONTROL1(x)		(0x110 + 0x100 * (x))
+#define PHY_DPHY_CFG(x)			(0x148 + 0x100 * (x))
+#define PHY_BB_AFE_CONFIG(x)		(0x174 + 0x100 * (x))
+
+/*
+ * use port_cfg to configure that which data lanes used
+ * +---------+     +------+ +-----+
+ * | port0 x4<-----|      | |     |
+ * |         |     | port | |     |
+ * | port1 x2<-----|      | |     |
+ * |         |     |      <-| PHY |
+ * | port2 x4<-----|      | |     |
+ * |         |     |config| |     |
+ * | port3 x2<-----|      | |     |
+ * +---------+     +------+ +-----+
+ */
+static const unsigned int csi2_port_cfg[][3] = {
+	{0, 0, 0x1f}, /* no link */
+	{4, 0, 0x10}, /* x4 + x4 config */
+	{2, 0, 0x12}, /* x2 + x2 config */
+	{1, 0, 0x13}, /* x1 + x1 config */
+	{2, 1, 0x15}, /* x2x1 + x2x1 config */
+	{1, 1, 0x16}, /* x1x1 + x1x1 config */
+	{2, 2, 0x18}, /* x2x2 + x2x2 config */
+	{1, 2, 0x19} /* x1x2 + x1x2 config */
+};
+
+/* port, nlanes, bbindex, portcfg */
+static const unsigned int phy_port_cfg[][4] = {
+	/* sip0 */
+	{0, 1, 0, 0x15},
+	{0, 2, 0, 0x15},
+	{0, 4, 0, 0x15},
+	{0, 4, 2, 0x22},
+	/* sip1 */
+	{2, 1, 4, 0x15},
+	{2, 2, 4, 0x15},
+	{2, 4, 4, 0x15},
+	{2, 4, 6, 0x22}
+};
+
+static void ipu6_isys_csi2_phy_config_by_port(struct ipu6_isys *isys,
+					      unsigned int port,
+					      unsigned int nlanes)
+{
+	struct device *dev = &isys->adev->auxdev.dev;
+	void __iomem *base = isys->adev->isp->base;
+	unsigned int bbnum;
+	u32 val, reg, i;
+
+	dev_dbg(dev, "port %u with %u lanes", port, nlanes);
+
+	/* only support <1.5Gbps */
+	for (i = 0; i < IPU6SE_ISYS_PHY_BB_NUM; i++) {
+		/* cphy_dll_ovrd.crcdc_fsm_dlane0 = 13 */
+		reg = IPU6SE_ISYS_PHY_0_BASE + PHY_CPHY_DLL_OVRD(i);
+		val = readl(base + reg);
+		val |= FIELD_PREP(GENMASK(6, 1), 13);
+		writel(val, base + reg);
+
+		/* cphy_rx_control1.en_crc1 = 1 */
+		reg = IPU6SE_ISYS_PHY_0_BASE + PHY_CPHY_RX_CONTROL1(i);
+		val = readl(base + reg);
+		val |= BIT(31);
+		writel(val, base + reg);
+
+		/* dphy_cfg.reserved = 1, .lden_from_dll_ovrd_0 = 1 */
+		reg = IPU6SE_ISYS_PHY_0_BASE + PHY_DPHY_CFG(i);
+		val = readl(base + reg);
+		val |= BIT(25) | BIT(26);
+		writel(val, base + reg);
+
+		/* cphy_dll_ovrd.lden_crcdc_fsm_dlane0 = 1 */
+		reg = IPU6SE_ISYS_PHY_0_BASE + PHY_CPHY_DLL_OVRD(i);
+		val = readl(base + reg);
+		val |= BIT(0);
+		writel(val, base + reg);
+	}
+
+	/* Front end config, use minimal channel loss */
+	for (i = 0; i < ARRAY_SIZE(phy_port_cfg); i++) {
+		if (phy_port_cfg[i][0] == port &&
+		    phy_port_cfg[i][1] == nlanes) {
+			bbnum = phy_port_cfg[i][2] / 2;
+			reg = IPU6SE_ISYS_PHY_0_BASE + PHY_BB_AFE_CONFIG(bbnum);
+			val = readl(base + reg);
+			val |= phy_port_cfg[i][3];
+			writel(val, base + reg);
+		}
+	}
+}
+
+static void ipu6_isys_csi2_rx_control(struct ipu6_isys *isys)
+{
+	void __iomem *base = isys->adev->isp->base;
+	u32 val, reg;
+
+	reg = CSI2_HUB_GPREG_SIP0_CSI_RX_A_CONTROL;
+	val = readl(base + reg);
+	val |= BIT(0);
+	writel(val, base + CSI2_HUB_GPREG_SIP0_CSI_RX_A_CONTROL);
+
+	reg = CSI2_HUB_GPREG_SIP0_CSI_RX_B_CONTROL;
+	val = readl(base + reg);
+	val |= BIT(0);
+	writel(val, base + CSI2_HUB_GPREG_SIP0_CSI_RX_B_CONTROL);
+
+	reg = CSI2_HUB_GPREG_SIP1_CSI_RX_A_CONTROL;
+	val = readl(base + reg);
+	val |= BIT(0);
+	writel(val, base + CSI2_HUB_GPREG_SIP1_CSI_RX_A_CONTROL);
+
+	reg = CSI2_HUB_GPREG_SIP1_CSI_RX_B_CONTROL;
+	val = readl(base + reg);
+	val |= BIT(0);
+	writel(val, base + CSI2_HUB_GPREG_SIP1_CSI_RX_B_CONTROL);
+}
+
+static int ipu6_isys_csi2_set_port_cfg(struct ipu6_isys *isys,
+				       unsigned int port, unsigned int nlanes)
+{
+	struct device *dev = &isys->adev->auxdev.dev;
+	unsigned int sip = port / 2;
+	unsigned int index;
+
+	switch (nlanes) {
+	case 1:
+		index = 5;
+		break;
+	case 2:
+		index = 6;
+		break;
+	case 4:
+		index = 1;
+		break;
+	default:
+		dev_err(dev, "lanes nr %u is unsupported\n", nlanes);
+		return -EINVAL;
+	}
+
+	dev_dbg(dev, "port config for port %u with %u lanes\n",	port, nlanes);
+
+	writel(csi2_port_cfg[index][2],
+	       isys->pdata->base + CSI2_HUB_GPREG_SIP_FB_PORT_CFG(sip));
+
+	return 0;
+}
+
+static void
+ipu6_isys_csi2_set_timing(struct ipu6_isys *isys,
+			  const struct ipu6_isys_csi2_timing *timing,
+			  unsigned int port, unsigned int nlanes)
+{
+	struct device *dev = &isys->adev->auxdev.dev;
+	void __iomem *reg;
+	u32 port_base;
+	u32 i;
+
+	port_base = (port % 2) ? CSI2_SIP_TOP_CSI_RX_PORT_BASE_1(port) :
+		CSI2_SIP_TOP_CSI_RX_PORT_BASE_0(port);
+
+	dev_dbg(dev, "set timing for port %u with %u lanes\n", port, nlanes);
+
+	reg = isys->pdata->base + port_base;
+	reg += CSI2_SIP_TOP_CSI_RX_DLY_CNT_TERMEN_CLANE;
+
+	writel(timing->ctermen, reg);
+
+	reg = isys->pdata->base + port_base;
+	reg += CSI2_SIP_TOP_CSI_RX_DLY_CNT_SETTLE_CLANE;
+	writel(timing->csettle, reg);
+
+	for (i = 0; i < nlanes; i++) {
+		reg = isys->pdata->base + port_base;
+		reg += CSI2_SIP_TOP_CSI_RX_DLY_CNT_TERMEN_DLANE(i);
+		writel(timing->dtermen, reg);
+
+		reg = isys->pdata->base + port_base;
+		reg += CSI2_SIP_TOP_CSI_RX_DLY_CNT_SETTLE_DLANE(i);
+		writel(timing->dsettle, reg);
+	}
+}
+
+#define DPHY_TIMER_INCR	0x28
+int ipu6_isys_jsl_phy_set_power(struct ipu6_isys *isys,
+				struct ipu6_isys_csi2_config *cfg,
+				const struct ipu6_isys_csi2_timing *timing,
+				bool on)
+{
+	struct device *dev = &isys->adev->auxdev.dev;
+	void __iomem *isys_base = isys->pdata->base;
+	int ret = 0;
+	u32 nlanes;
+	u32 port;
+
+	if (!on)
+		return 0;
+
+	port = cfg->port;
+	nlanes = cfg->nlanes;
+
+	if (!isys_base || port >= isys->pdata->ipdata->csi2.nports) {
+		dev_warn(dev, "invalid port ID %d\n", port);
+		return -EINVAL;
+	}
+
+	ipu6_isys_csi2_phy_config_by_port(isys, port, nlanes);
+
+	writel(DPHY_TIMER_INCR,
+	       isys->pdata->base + CSI2_HUB_GPREG_DPHY_TIMER_INCR);
+
+	/* set port cfg and rx timing */
+	ipu6_isys_csi2_set_timing(isys, timing, port, nlanes);
+
+	ret = ipu6_isys_csi2_set_port_cfg(isys, port, nlanes);
+	if (ret)
+		return ret;
+
+	ipu6_isys_csi2_rx_control(isys);
+
+	return 0;
+}
diff --git a/drivers/media/pci/intel/ipu6/ipu6-isys-mcd-phy.c b/drivers/media/pci/intel/ipu6/ipu6-isys-mcd-phy.c
new file mode 100644
index 000000000000..3482ce5b252e
--- /dev/null
+++ b/drivers/media/pci/intel/ipu6/ipu6-isys-mcd-phy.c
@@ -0,0 +1,712 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2013 - 2023 Intel Corporation
+ */
+#include <linux/delay.h>
+#include <linux/iopoll.h>
+
+#include <media/v4l2-async.h>
+
+#include "ipu6-isys.h"
+#include "ipu6-platform-isys-csi2-reg.h"
+#include "ipu6-platform-regs.h"
+
+#define CSI_REG_HUB_GPREG_PHY_CTL(id) (CSI_REG_BASE + 0x18008 + (id) * 0x8)
+#define CSI_REG_HUB_GPREG_PHY_CTL_RESET			BIT(4)
+#define CSI_REG_HUB_GPREG_PHY_CTL_PWR_EN		BIT(0)
+#define CSI_REG_HUB_GPREG_PHY_STATUS(id) (CSI_REG_BASE + 0x1800c + (id) * 0x8)
+#define CSI_REG_HUB_GPREG_PHY_POWER_ACK			BIT(0)
+#define CSI_REG_HUB_GPREG_PHY_READY			BIT(4)
+
+#define MCD_PHY_POWER_STATUS_TIMEOUT			(200 * USEC_PER_MSEC)
+
+/*
+ * bridge to phy in buttress reg map, each phy has 16 kbytes
+ * only 2 phys for TGL U and Y
+ */
+#define IPU6_ISYS_MCD_PHY_BASE(i)			(0x10000 + (i) * 0x4000)
+
+/*
+ *  There are 2 MCD DPHY instances on TGL and 1 MCD DPHY instance on ADL.
+ *  Each MCD PHY has 12-lanes which has 8 data lanes and 4 clock lanes.
+ *  CSI port 1, 3 (5, 7) can support max 2 data lanes.
+ *  CSI port 0, 2 (4, 6) can support max 4 data lanes.
+ *  PHY configurations are PPI based instead of port.
+ *  Left:
+ *  +---------+---------+---------+---------+--------+---------+----------+
+ *  |         |         |         |         |        |         |          |
+ *  | PPI     | PPI5    | PPI4    | PPI3    | PPI2   | PPI1    | PPI0     |
+ *  +---------+---------+---------+---------+--------+---------+----------+
+ *  |         |         |         |         |        |         |          |
+ *  | x4      | unused  | D3      | D2      | C0     | D0      | D1       |
+ *  |---------+---------+---------+---------+--------+---------+----------+
+ *  |         |         |         |         |        |         |          |
+ *  | x2x2    | C1      | D0      | D1      | C0     | D0      | D1       |
+ *  ----------+---------+---------+---------+--------+---------+----------+
+ *  |         |         |         |         |        |         |          |
+ *  | x2x1    | C1      | D0      | unused  | C0     | D0      | D1       |
+ *  +---------+---------+---------+---------+--------+---------+----------+
+ *  |         |         |         |         |        |         |          |
+ *  | x1x1    | C1      | D0      | unused  | C0     | D0      | unused   |
+ *  +---------+---------+---------+---------+--------+---------+----------+
+ *  |         |         |         |         |        |         |          |
+ *  | x1x2    | C1      | D0      | D1      | C0     | D0      | unused   |
+ *  +---------+---------+---------+---------+--------+---------+----------+
+ *
+ *  Right:
+ *  +---------+---------+---------+---------+--------+---------+----------+
+ *  |         |         |         |         |        |         |          |
+ *  | PPI     | PPI6    | PPI7    | PPI8    | PPI9   | PPI10   | PPI11    |
+ *  +---------+---------+---------+---------+--------+---------+----------+
+ *  |         |         |         |         |        |         |          |
+ *  | x4      | D1      | D0      | C2      | D2     | D3      | unused   |
+ *  |---------+---------+---------+---------+--------+---------+----------+
+ *  |         |         |         |         |        |         |          |
+ *  | x2x2    | D1      | D0      | C2      | D1     | D0      | C3       |
+ *  ----------+---------+---------+---------+--------+---------+----------+
+ *  |         |         |         |         |        |         |          |
+ *  | x2x1    | D1      | D0      | C2      | unused | D0      | C3       |
+ *  +---------+---------+---------+---------+--------+---------+----------+
+ *  |         |         |         |         |        |         |          |
+ *  | x1x1    | unused  | D0      | C2      | unused | D0      | C3       |
+ *  +---------+---------+---------+---------+--------+---------+----------+
+ *  |         |         |         |         |        |         |          |
+ *  | x1x2    | unused  | D0      | C2      | D1     | D0      | C3       |
+ *  +---------+---------+---------+---------+--------+---------+----------+
+ *
+ * ppi mapping per phy :
+ *
+ * x4 + x4:
+ * Left : port0 - PPI range {0, 1, 2, 3, 4}
+ * Right: port2 - PPI range {6, 7, 8, 9, 10}
+ *
+ * x4 + x2x2:
+ * Left: port0 - PPI range {0, 1, 2, 3, 4}
+ * Right: port2 - PPI range {6, 7, 8}, port3 - PPI range {9, 10, 11}
+ *
+ * x2x2 + x4:
+ * Left: port0 - PPI range {0, 1, 2}, port1 - PPI range {3, 4, 5}
+ * Right: port2 - PPI range {6, 7, 8, 9, 10}
+ *
+ * x2x2 + x2x2:
+ * Left : port0 - PPI range {0, 1, 2}, port1 - PPI range {3, 4, 5}
+ * Right: port2 - PPI range {6, 7, 8}, port3 - PPI range {9, 10, 11}
+ */
+
+struct phy_reg {
+	u32 reg;
+	u32 val;
+};
+
+static const struct phy_reg common_init_regs[] = {
+	/* for TGL-U, use 0x80000000 */
+	{0x00000040, 0x80000000},
+	{0x00000044, 0x00a80880},
+	{0x00000044, 0x00b80880},
+	{0x00000010, 0x0000078c},
+	{0x00000344, 0x2f4401e2},
+	{0x00000544, 0x924401e2},
+	{0x00000744, 0x594401e2},
+	{0x00000944, 0x624401e2},
+	{0x00000b44, 0xfc4401e2},
+	{0x00000d44, 0xc54401e2},
+	{0x00000f44, 0x034401e2},
+	{0x00001144, 0x8f4401e2},
+	{0x00001344, 0x754401e2},
+	{0x00001544, 0xe94401e2},
+	{0x00001744, 0xcb4401e2},
+	{0x00001944, 0xfa4401e2}
+};
+
+static const struct phy_reg x1_port0_config_regs[] = {
+	{0x00000694, 0xc80060fa},
+	{0x00000680, 0x3d4f78ea},
+	{0x00000690, 0x10a0140b},
+	{0x000006a8, 0xdf04010a},
+	{0x00000700, 0x57050060},
+	{0x00000710, 0x0030001c},
+	{0x00000738, 0x5f004444},
+	{0x0000073c, 0x78464204},
+	{0x00000748, 0x7821f940},
+	{0x0000074c, 0xb2000433},
+	{0x00000494, 0xfe6030fa},
+	{0x00000480, 0x29ef5ed0},
+	{0x00000490, 0x10a0540b},
+	{0x000004a8, 0x7a01010a},
+	{0x00000500, 0xef053460},
+	{0x00000510, 0xe030101c},
+	{0x00000538, 0xdf808444},
+	{0x0000053c, 0xc8422204},
+	{0x00000540, 0x0180088c},
+	{0x00000574, 0x00000000},
+	{0x00000000, 0x00000000}
+};
+
+static const struct phy_reg x1_port1_config_regs[] = {
+	{0x00000c94, 0xc80060fa},
+	{0x00000c80, 0xcf47abea},
+	{0x00000c90, 0x10a0840b},
+	{0x00000ca8, 0xdf04010a},
+	{0x00000d00, 0x57050060},
+	{0x00000d10, 0x0030001c},
+	{0x00000d38, 0x5f004444},
+	{0x00000d3c, 0x78464204},
+	{0x00000d48, 0x7821f940},
+	{0x00000d4c, 0xb2000433},
+	{0x00000a94, 0xc91030fa},
+	{0x00000a80, 0x5a166ed0},
+	{0x00000a90, 0x10a0540b},
+	{0x00000aa8, 0x5d060100},
+	{0x00000b00, 0xef053460},
+	{0x00000b10, 0xa030101c},
+	{0x00000b38, 0xdf808444},
+	{0x00000b3c, 0xc8422204},
+	{0x00000b40, 0x0180088c},
+	{0x00000b74, 0x00000000},
+	{0x00000000, 0x00000000}
+};
+
+static const struct phy_reg x1_port2_config_regs[] = {
+	{0x00001294, 0x28f000fa},
+	{0x00001280, 0x08130cea},
+	{0x00001290, 0x10a0140b},
+	{0x000012a8, 0xd704010a},
+	{0x00001300, 0x8d050060},
+	{0x00001310, 0x0030001c},
+	{0x00001338, 0xdf008444},
+	{0x0000133c, 0x78422204},
+	{0x00001348, 0x7821f940},
+	{0x0000134c, 0x5a000433},
+	{0x00001094, 0x2d20b0fa},
+	{0x00001080, 0xade75dd0},
+	{0x00001090, 0x10a0540b},
+	{0x000010a8, 0xb101010a},
+	{0x00001100, 0x33053460},
+	{0x00001110, 0x0030101c},
+	{0x00001138, 0xdf808444},
+	{0x0000113c, 0xc8422204},
+	{0x00001140, 0x8180088c},
+	{0x00001174, 0x00000000},
+	{0x00000000, 0x00000000}
+};
+
+static const struct phy_reg x1_port3_config_regs[] = {
+	{0x00001894, 0xc80060fa},
+	{0x00001880, 0x0f90fd6a},
+	{0x00001890, 0x10a0840b},
+	{0x000018a8, 0xdf04010a},
+	{0x00001900, 0x57050060},
+	{0x00001910, 0x0030001c},
+	{0x00001938, 0x5f004444},
+	{0x0000193c, 0x78464204},
+	{0x00001948, 0x7821f940},
+	{0x0000194c, 0xb2000433},
+	{0x00001694, 0x3050d0fa},
+	{0x00001680, 0x0ef6d050},
+	{0x00001690, 0x10a0540b},
+	{0x000016a8, 0xe301010a},
+	{0x00001700, 0x69053460},
+	{0x00001710, 0xa030101c},
+	{0x00001738, 0xdf808444},
+	{0x0000173c, 0xc8422204},
+	{0x00001740, 0x0180088c},
+	{0x00001774, 0x00000000},
+	{0x00000000, 0x00000000}
+};
+
+static const struct phy_reg x2_port0_config_regs[] = {
+	{0x00000694, 0xc80060fa},
+	{0x00000680, 0x3d4f78ea},
+	{0x00000690, 0x10a0140b},
+	{0x000006a8, 0xdf04010a},
+	{0x00000700, 0x57050060},
+	{0x00000710, 0x0030001c},
+	{0x00000738, 0x5f004444},
+	{0x0000073c, 0x78464204},
+	{0x00000748, 0x7821f940},
+	{0x0000074c, 0xb2000433},
+	{0x00000494, 0xc80060fa},
+	{0x00000480, 0x29ef5ed8},
+	{0x00000490, 0x10a0540b},
+	{0x000004a8, 0x7a01010a},
+	{0x00000500, 0xef053460},
+	{0x00000510, 0xe030101c},
+	{0x00000538, 0xdf808444},
+	{0x0000053c, 0xc8422204},
+	{0x00000540, 0x0180088c},
+	{0x00000574, 0x00000000},
+	{0x00000294, 0xc80060fa},
+	{0x00000280, 0xcb45b950},
+	{0x00000290, 0x10a0540b},
+	{0x000002a8, 0x8c01010a},
+	{0x00000300, 0xef053460},
+	{0x00000310, 0x8030101c},
+	{0x00000338, 0x41808444},
+	{0x0000033c, 0x32422204},
+	{0x00000340, 0x0180088c},
+	{0x00000374, 0x00000000},
+	{0x00000000, 0x00000000}
+};
+
+static const struct phy_reg x2_port1_config_regs[] = {
+	{0x00000c94, 0xc80060fa},
+	{0x00000c80, 0xcf47abea},
+	{0x00000c90, 0x10a0840b},
+	{0x00000ca8, 0xdf04010a},
+	{0x00000d00, 0x57050060},
+	{0x00000d10, 0x0030001c},
+	{0x00000d38, 0x5f004444},
+	{0x00000d3c, 0x78464204},
+	{0x00000d48, 0x7821f940},
+	{0x00000d4c, 0xb2000433},
+	{0x00000a94, 0xc80060fa},
+	{0x00000a80, 0x5a166ed8},
+	{0x00000a90, 0x10a0540b},
+	{0x00000aa8, 0x7a01010a},
+	{0x00000b00, 0xef053460},
+	{0x00000b10, 0xa030101c},
+	{0x00000b38, 0xdf808444},
+	{0x00000b3c, 0xc8422204},
+	{0x00000b40, 0x0180088c},
+	{0x00000b74, 0x00000000},
+	{0x00000894, 0xc80060fa},
+	{0x00000880, 0x4d4f21d0},
+	{0x00000890, 0x10a0540b},
+	{0x000008a8, 0x5601010a},
+	{0x00000900, 0xef053460},
+	{0x00000910, 0x8030101c},
+	{0x00000938, 0xdf808444},
+	{0x0000093c, 0xc8422204},
+	{0x00000940, 0x0180088c},
+	{0x00000974, 0x00000000},
+	{0x00000000, 0x00000000}
+};
+
+static const struct phy_reg x2_port2_config_regs[] = {
+	{0x00001294, 0xc80060fa},
+	{0x00001280, 0x08130cea},
+	{0x00001290, 0x10a0140b},
+	{0x000012a8, 0xd704010a},
+	{0x00001300, 0x8d050060},
+	{0x00001310, 0x0030001c},
+	{0x00001338, 0xdf008444},
+	{0x0000133c, 0x78422204},
+	{0x00001348, 0x7821f940},
+	{0x0000134c, 0x5a000433},
+	{0x00001094, 0xc80060fa},
+	{0x00001080, 0xade75dd8},
+	{0x00001090, 0x10a0540b},
+	{0x000010a8, 0xb101010a},
+	{0x00001100, 0x33053460},
+	{0x00001110, 0x0030101c},
+	{0x00001138, 0xdf808444},
+	{0x0000113c, 0xc8422204},
+	{0x00001140, 0x8180088c},
+	{0x00001174, 0x00000000},
+	{0x00000e94, 0xc80060fa},
+	{0x00000e80, 0x0fbf16d0},
+	{0x00000e90, 0x10a0540b},
+	{0x00000ea8, 0x7a01010a},
+	{0x00000f00, 0xf5053460},
+	{0x00000f10, 0xc030101c},
+	{0x00000f38, 0xdf808444},
+	{0x00000f3c, 0xc8422204},
+	{0x00000f40, 0x8180088c},
+	{0x00000000, 0x00000000}
+};
+
+static const struct phy_reg x2_port3_config_regs[] = {
+	{0x00001894, 0xc80060fa},
+	{0x00001880, 0x0f90fd6a},
+	{0x00001890, 0x10a0840b},
+	{0x000018a8, 0xdf04010a},
+	{0x00001900, 0x57050060},
+	{0x00001910, 0x0030001c},
+	{0x00001938, 0x5f004444},
+	{0x0000193c, 0x78464204},
+	{0x00001948, 0x7821f940},
+	{0x0000194c, 0xb2000433},
+	{0x00001694, 0xc80060fa},
+	{0x00001680, 0x0ef6d058},
+	{0x00001690, 0x10a0540b},
+	{0x000016a8, 0x7a01010a},
+	{0x00001700, 0x69053460},
+	{0x00001710, 0xa030101c},
+	{0x00001738, 0xdf808444},
+	{0x0000173c, 0xc8422204},
+	{0x00001740, 0x0180088c},
+	{0x00001774, 0x00000000},
+	{0x00001494, 0xc80060fa},
+	{0x00001480, 0xf9d34bd0},
+	{0x00001490, 0x10a0540b},
+	{0x000014a8, 0x7a01010a},
+	{0x00001500, 0x1b053460},
+	{0x00001510, 0x0030101c},
+	{0x00001538, 0xdf808444},
+	{0x0000153c, 0xc8422204},
+	{0x00001540, 0x8180088c},
+	{0x00001574, 0x00000000},
+	{0x00000000, 0x00000000}
+};
+
+static const struct phy_reg x4_port0_config_regs[] = {
+	{0x00000694, 0xc80060fa},
+	{0x00000680, 0x3d4f78fa},
+	{0x00000690, 0x10a0140b},
+	{0x000006a8, 0xdf04010a},
+	{0x00000700, 0x57050060},
+	{0x00000710, 0x0030001c},
+	{0x00000738, 0x5f004444},
+	{0x0000073c, 0x78464204},
+	{0x00000748, 0x7821f940},
+	{0x0000074c, 0xb2000433},
+	{0x00000494, 0xfe6030fa},
+	{0x00000480, 0x29ef5ed8},
+	{0x00000490, 0x10a0540b},
+	{0x000004a8, 0x7a01010a},
+	{0x00000500, 0xef053460},
+	{0x00000510, 0xe030101c},
+	{0x00000538, 0xdf808444},
+	{0x0000053c, 0xc8422204},
+	{0x00000540, 0x0180088c},
+	{0x00000574, 0x00000004},
+	{0x00000294, 0x23e030fa},
+	{0x00000280, 0xcb45b950},
+	{0x00000290, 0x10a0540b},
+	{0x000002a8, 0x8c01010a},
+	{0x00000300, 0xef053460},
+	{0x00000310, 0x8030101c},
+	{0x00000338, 0x41808444},
+	{0x0000033c, 0x32422204},
+	{0x00000340, 0x0180088c},
+	{0x00000374, 0x00000004},
+	{0x00000894, 0x5620b0fa},
+	{0x00000880, 0x4d4f21dc},
+	{0x00000890, 0x10a0540b},
+	{0x000008a8, 0x5601010a},
+	{0x00000900, 0xef053460},
+	{0x00000910, 0x8030101c},
+	{0x00000938, 0xdf808444},
+	{0x0000093c, 0xc8422204},
+	{0x00000940, 0x0180088c},
+	{0x00000974, 0x00000004},
+	{0x00000a94, 0xc91030fa},
+	{0x00000a80, 0x5a166ecc},
+	{0x00000a90, 0x10a0540b},
+	{0x00000aa8, 0x5d01010a},
+	{0x00000b00, 0xef053460},
+	{0x00000b10, 0xa030101c},
+	{0x00000b38, 0xdf808444},
+	{0x00000b3c, 0xc8422204},
+	{0x00000b40, 0x0180088c},
+	{0x00000b74, 0x00000004},
+	{0x00000000, 0x00000000}
+};
+
+static const struct phy_reg x4_port1_config_regs[] = {
+	{0x00000000, 0x00000000}
+};
+
+static const struct phy_reg x4_port2_config_regs[] = {
+	{0x00001294, 0x28f000fa},
+	{0x00001280, 0x08130cfa},
+	{0x00001290, 0x10c0140b},
+	{0x000012a8, 0xd704010a},
+	{0x00001300, 0x8d050060},
+	{0x00001310, 0x0030001c},
+	{0x00001338, 0xdf008444},
+	{0x0000133c, 0x78422204},
+	{0x00001348, 0x7821f940},
+	{0x0000134c, 0x5a000433},
+	{0x00001094, 0x2d20b0fa},
+	{0x00001080, 0xade75dd8},
+	{0x00001090, 0x10a0540b},
+	{0x000010a8, 0xb101010a},
+	{0x00001100, 0x33053460},
+	{0x00001110, 0x0030101c},
+	{0x00001138, 0xdf808444},
+	{0x0000113c, 0xc8422204},
+	{0x00001140, 0x8180088c},
+	{0x00001174, 0x00000004},
+	{0x00000e94, 0xd308d0fa},
+	{0x00000e80, 0x0fbf16d0},
+	{0x00000e90, 0x10a0540b},
+	{0x00000ea8, 0x2c01010a},
+	{0x00000f00, 0xf5053460},
+	{0x00000f10, 0xc030101c},
+	{0x00000f38, 0xdf808444},
+	{0x00000f3c, 0xc8422204},
+	{0x00000f40, 0x8180088c},
+	{0x00000f74, 0x00000004},
+	{0x00001494, 0x136850fa},
+	{0x00001480, 0xf9d34bdc},
+	{0x00001490, 0x10a0540b},
+	{0x000014a8, 0x5a01010a},
+	{0x00001500, 0x1b053460},
+	{0x00001510, 0x0030101c},
+	{0x00001538, 0xdf808444},
+	{0x0000153c, 0xc8422204},
+	{0x00001540, 0x8180088c},
+	{0x00001574, 0x00000004},
+	{0x00001694, 0x3050d0fa},
+	{0x00001680, 0x0ef6d04c},
+	{0x00001690, 0x10a0540b},
+	{0x000016a8, 0xe301010a},
+	{0x00001700, 0x69053460},
+	{0x00001710, 0xa030101c},
+	{0x00001738, 0xdf808444},
+	{0x0000173c, 0xc8422204},
+	{0x00001740, 0x0180088c},
+	{0x00001774, 0x00000004},
+	{0x00000000, 0x00000000}
+};
+
+static const struct phy_reg x4_port3_config_regs[] = {
+	{0x00000000, 0x00000000}
+};
+
+static const struct phy_reg *x1_config_regs[4] = {
+	x1_port0_config_regs,
+	x1_port1_config_regs,
+	x1_port2_config_regs,
+	x1_port3_config_regs
+};
+
+static const struct phy_reg *x2_config_regs[4] = {
+	x2_port0_config_regs,
+	x2_port1_config_regs,
+	x2_port2_config_regs,
+	x2_port3_config_regs
+};
+
+static const struct phy_reg *x4_config_regs[4] = {
+	x4_port0_config_regs,
+	x4_port1_config_regs,
+	x4_port2_config_regs,
+	x4_port3_config_regs
+};
+
+static const struct phy_reg **config_regs[3] = {
+	x1_config_regs,
+	x2_config_regs,
+	x4_config_regs
+};
+
+static int ipu6_isys_mcd_phy_powerup_ack(struct ipu6_isys *isys, u8 id)
+{
+	struct device *dev = &isys->adev->auxdev.dev;
+	void __iomem *isys_base = isys->pdata->base;
+	u32 val;
+	int ret;
+
+	val = readl(isys_base + CSI_REG_HUB_GPREG_PHY_CTL(id));
+	val |= CSI_REG_HUB_GPREG_PHY_CTL_PWR_EN;
+	writel(val, isys_base + CSI_REG_HUB_GPREG_PHY_CTL(id));
+
+	ret = readl_poll_timeout(isys_base + CSI_REG_HUB_GPREG_PHY_STATUS(id),
+				 val, val & CSI_REG_HUB_GPREG_PHY_POWER_ACK,
+				 200, MCD_PHY_POWER_STATUS_TIMEOUT);
+	if (ret)
+		dev_err(dev, "PHY%d powerup ack timeout", id);
+
+	return ret;
+}
+
+static int ipu6_isys_mcd_phy_powerdown_ack(struct ipu6_isys *isys, u8 id)
+{
+	struct device *dev = &isys->adev->auxdev.dev;
+	void __iomem *isys_base = isys->pdata->base;
+	u32 val;
+	int ret;
+
+	writel(0, isys_base + CSI_REG_HUB_GPREG_PHY_CTL(id));
+	ret = readl_poll_timeout(isys_base + CSI_REG_HUB_GPREG_PHY_STATUS(id),
+				 val, !(val & CSI_REG_HUB_GPREG_PHY_POWER_ACK),
+				 200, MCD_PHY_POWER_STATUS_TIMEOUT);
+	if (ret)
+		dev_err(dev, "PHY%d powerdown ack timeout", id);
+
+	return ret;
+}
+
+static void ipu6_isys_mcd_phy_reset(struct ipu6_isys *isys, u8 id, bool assert)
+{
+	void __iomem *isys_base = isys->pdata->base;
+	u32 val;
+
+	val = readl(isys_base + CSI_REG_HUB_GPREG_PHY_CTL(id));
+	if (assert)
+		val |= CSI_REG_HUB_GPREG_PHY_CTL_RESET;
+	else
+		val &= ~(CSI_REG_HUB_GPREG_PHY_CTL_RESET);
+
+	writel(val, isys_base + CSI_REG_HUB_GPREG_PHY_CTL(id));
+}
+
+static int ipu6_isys_mcd_phy_ready(struct ipu6_isys *isys, u8 id)
+{
+	struct device *dev = &isys->adev->auxdev.dev;
+	void __iomem *isys_base = isys->pdata->base;
+	u32 val;
+	int ret;
+
+	ret = readl_poll_timeout(isys_base + CSI_REG_HUB_GPREG_PHY_STATUS(id),
+				 val, val & CSI_REG_HUB_GPREG_PHY_READY,
+				 200, MCD_PHY_POWER_STATUS_TIMEOUT);
+	if (ret)
+		dev_err(dev, "PHY%d ready ack timeout", id);
+
+	return ret;
+}
+
+static void ipu6_isys_mcd_phy_common_init(struct ipu6_isys *isys)
+{
+	struct ipu6_bus_device *adev = isys->adev;
+	struct ipu6_device *isp = adev->isp;
+	void __iomem *isp_base = isp->base;
+	struct sensor_async_sd *s_asd;
+	struct v4l2_async_connection *asc;
+	void __iomem *phy_base;
+	unsigned int i;
+	u8 phy_id;
+
+	list_for_each_entry(asc, &isys->notifier.done_list, asc_entry) {
+		s_asd = container_of(asc, struct sensor_async_sd, asc);
+		phy_id = s_asd->csi2.port / 4;
+		phy_base = isp_base + IPU6_ISYS_MCD_PHY_BASE(phy_id);
+
+		for (i = 0; i < ARRAY_SIZE(common_init_regs); i++)
+			writel(common_init_regs[i].val,
+			       phy_base + common_init_regs[i].reg);
+	}
+}
+
+static int ipu6_isys_driver_port_to_phy_port(struct ipu6_isys_csi2_config *cfg)
+{
+	int phy_port;
+	int ret;
+
+	if (!(cfg->nlanes == 4 || cfg->nlanes == 2 || cfg->nlanes == 1))
+		return -EINVAL;
+
+	/* B,F -> C0 A,E -> C1 C,G -> C2 D,H -> C4 */
+	/* normalize driver port number */
+	phy_port = cfg->port % 4;
+
+	/* swap port number only for A and B */
+	if (phy_port == 0)
+		phy_port = 1;
+	else if (phy_port == 1)
+		phy_port = 0;
+
+	ret = phy_port;
+
+	/* check validity per lane configuration */
+	if (cfg->nlanes == 4 && !(phy_port == 0 || phy_port == 2))
+		ret = -EINVAL;
+	else if ((cfg->nlanes == 2 || cfg->nlanes == 1) &&
+		 !(phy_port >= 0 && phy_port <= 3))
+		ret = -EINVAL;
+
+	return ret;
+}
+
+static int ipu6_isys_mcd_phy_config(struct ipu6_isys *isys)
+{
+	struct device *dev = &isys->adev->auxdev.dev;
+	struct ipu6_bus_device *adev = isys->adev;
+	const struct phy_reg **phy_config_regs;
+	struct ipu6_device *isp = adev->isp;
+	void __iomem *isp_base = isp->base;
+	struct sensor_async_sd *s_asd;
+	struct ipu6_isys_csi2_config cfg;
+	struct v4l2_async_connection *asc;
+	u8 phy_port, phy_id;
+	unsigned int i;
+	void __iomem *phy_base;
+
+	list_for_each_entry(asc, &isys->notifier.done_list, asc_entry) {
+		s_asd = container_of(asc, struct sensor_async_sd, asc);
+		cfg.port = s_asd->csi2.port;
+		cfg.nlanes = s_asd->csi2.nlanes;
+		phy_port = ipu6_isys_driver_port_to_phy_port(&cfg);
+		if (phy_port < 0) {
+			dev_err(dev, "invalid port %d for lane %d", cfg.port,
+				cfg.nlanes);
+			return -ENXIO;
+		}
+
+		phy_id = cfg.port / 4;
+		phy_base = isp_base + IPU6_ISYS_MCD_PHY_BASE(phy_id);
+		dev_dbg(dev, "port%d PHY%u lanes %u\n", cfg.port, phy_id,
+			cfg.nlanes);
+
+		phy_config_regs = config_regs[cfg.nlanes / 2];
+		cfg.port = phy_port;
+		for (i = 0; phy_config_regs[cfg.port][i].reg; i++)
+			writel(phy_config_regs[cfg.port][i].val,
+			       phy_base + phy_config_regs[cfg.port][i].reg);
+	}
+
+	return 0;
+}
+
+#define CSI_MCD_PHY_NUM		2
+static refcount_t phy_power_ref_count[CSI_MCD_PHY_NUM];
+
+int ipu6_isys_mcd_phy_set_power(struct ipu6_isys *isys,
+				struct ipu6_isys_csi2_config *cfg,
+				const struct ipu6_isys_csi2_timing *timing,
+				bool on)
+{
+	struct device *dev = &isys->adev->auxdev.dev;
+	void __iomem *isys_base = isys->pdata->base;
+	u8 port, phy_id;
+	refcount_t *ref;
+	int ret;
+
+	port = cfg->port;
+	phy_id = port / 4;
+
+	ref = &phy_power_ref_count[phy_id];
+
+	dev_dbg(dev, "for phy %d port %d, lanes: %d\n", phy_id, port,
+		cfg->nlanes);
+
+	if (!isys_base || port >= isys->pdata->ipdata->csi2.nports) {
+		dev_warn(dev, "invalid port ID %d\n", port);
+		return -EINVAL;
+	}
+
+	if (on) {
+		if (refcount_read(ref)) {
+			dev_dbg(dev, "for phy %d is already UP", phy_id);
+			refcount_inc(ref);
+			return 0;
+		}
+
+		ret = ipu6_isys_mcd_phy_powerup_ack(isys, phy_id);
+		if (ret)
+			return ret;
+
+		ipu6_isys_mcd_phy_reset(isys, phy_id, 0);
+		ipu6_isys_mcd_phy_common_init(isys);
+
+		ret = ipu6_isys_mcd_phy_config(isys);
+		if (ret)
+			return ret;
+
+		ipu6_isys_mcd_phy_reset(isys, phy_id, 1);
+		ret = ipu6_isys_mcd_phy_ready(isys, phy_id);
+		if (ret)
+			return ret;
+
+		refcount_set(ref, 1);
+		return 0;
+	}
+
+	if (!refcount_dec_and_test(ref))
+		return 0;
+
+	return ipu6_isys_mcd_phy_powerdown_ack(isys, phy_id);
+}
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 86+ messages in thread

* [PATCH v2 10/15] media: intel/ipu6: add input system driver
  2023-10-24 11:29 [PATCH v2 00/15] Intel IPU6 and IPU6 input system drivers bingbu.cao
                   ` (8 preceding siblings ...)
  2023-10-24 11:29 ` [PATCH v2 09/15] media: intel/ipu6: add the CSI2 DPHY implementation bingbu.cao
@ 2023-10-24 11:29 ` bingbu.cao
  2023-11-23  9:37   ` Andreas Helbech Kleist
                     ` (2 more replies)
  2023-10-24 11:29 ` [PATCH v2 11/15] media: intel/ipu6: input system video capture nodes bingbu.cao
                   ` (6 subsequent siblings)
  16 siblings, 3 replies; 86+ messages in thread
From: bingbu.cao @ 2023-10-24 11:29 UTC (permalink / raw)
  To: linux-media, sakari.ailus, laurent.pinchart
  Cc: andriy.shevchenko, hdegoede, ilpo.jarvinen, andreaskleist,
	claus.stovgaard, tfiga, senozhatsky, tomi.valkeinen, bingbu.cao,
	bingbu.cao, tian.shu.qiu, hongju.wang

From: Bingbu Cao <bingbu.cao@intel.com>

Input system driver do basic isys hardware setup and irq handling
and work with fwnode and v4l2 to register the ISYS v4l2 devices.

Signed-off-by: Bingbu Cao <bingbu.cao@intel.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reported-by: Claus Stovgaard <claus.stovgaard@gmail.com>
---
 drivers/media/pci/intel/ipu6/ipu6-isys.c | 1345 ++++++++++++++++++++++
 drivers/media/pci/intel/ipu6/ipu6-isys.h |  201 ++++
 2 files changed, 1546 insertions(+)
 create mode 100644 drivers/media/pci/intel/ipu6/ipu6-isys.c
 create mode 100644 drivers/media/pci/intel/ipu6/ipu6-isys.h

diff --git a/drivers/media/pci/intel/ipu6/ipu6-isys.c b/drivers/media/pci/intel/ipu6/ipu6-isys.c
new file mode 100644
index 000000000000..2ea0c9ad6f16
--- /dev/null
+++ b/drivers/media/pci/intel/ipu6/ipu6-isys.c
@@ -0,0 +1,1345 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2013 - 2023 Intel Corporation
+ */
+
+#include <linux/bitfield.h>
+#include <linux/delay.h>
+#include <linux/dma-mapping.h>
+#include <linux/firmware.h>
+#include <linux/module.h>
+#include <linux/pci.h>
+#include <linux/pm_runtime.h>
+
+#include <media/v4l2-ctrls.h>
+#include <media/v4l2-device.h>
+#include <media/v4l2-event.h>
+#include <media/v4l2-fwnode.h>
+#include <media/v4l2-ioctl.h>
+
+#include "ipu6-cpd.h"
+#include "ipu6-dma.h"
+#include "ipu6-isys.h"
+#include "ipu6-mmu.h"
+#include "ipu6-platform-buttress-regs.h"
+#include "ipu6-platform-isys-csi2-reg.h"
+#include "ipu6-platform-regs.h"
+
+#define IPU6_BUTTRESS_FABIC_CONTROL		0x68
+#define GDA_ENABLE_IWAKE_INDEX			2
+#define GDA_IWAKE_THRESHOLD_INDEX		1
+#define GDA_IRQ_CRITICAL_THRESHOLD_INDEX	0
+#define GDA_MEMOPEN_THRESHOLD_INDEX		3
+#define DEFAULT_DID_RATIO			90
+#define DEFAULT_IWAKE_THRESHOLD			0x42
+#define DEFAULT_MEM_OPEN_TIME			10
+#define ONE_THOUSAND_MICROSECOND		1000
+/* One page is 2KB, 8 x 16 x 16 = 2048B = 2KB */
+#define ISF_DMA_TOP_GDA_PROFERTY_PAGE_SIZE	0x800
+
+/* LTR & DID value are 10 bit at most */
+#define LTR_DID_VAL_MAX		1023
+#define LTR_DEFAULT_VALUE	0x70503C19
+#define FILL_TIME_DEFAULT_VALUE 0xFFF0783C
+#define LTR_DID_PKGC_2R		20
+#define LTR_SCALE_DEFAULT	5
+#define LTR_SCALE_1024NS	2
+#define DID_SCALE_1US		2
+#define DID_SCALE_32US		3
+#define REG_PKGC_PMON_CFG	0xB00
+
+#define VAL_PKGC_PMON_CFG_RESET 0x38
+#define VAL_PKGC_PMON_CFG_START 0x7
+
+#define IS_PIXEL_BUFFER_PAGES		0x80
+/*
+ * when iwake mode is disabled, the critical threshold is statically set
+ * to 75% of the IS pixel buffer, criticalThreshold = (128 * 3) / 4
+ */
+#define CRITICAL_THRESHOLD_IWAKE_DISABLE	(IS_PIXEL_BUFFER_PAGES * 3 / 4)
+
+union fabric_ctrl {
+	struct {
+		u16 ltr_val   : 10;
+		u16 ltr_scale : 3;
+		u16 reserved  : 3;
+		u16 did_val   : 10;
+		u16 did_scale : 3;
+		u16 reserved2 : 1;
+		u16 keep_power_in_D0   : 1;
+		u16 keep_power_override : 1;
+	} bits;
+	u32 value;
+};
+
+enum ltr_did_type {
+	LTR_IWAKE_ON,
+	LTR_IWAKE_OFF,
+	LTR_ISYS_ON,
+	LTR_ISYS_OFF,
+	LTR_ENHANNCE_IWAKE,
+	LTR_TYPE_MAX
+};
+
+#define ISYS_PM_QOS_VALUE	300
+
+static int isys_isr_one(struct ipu6_bus_device *adev);
+
+static int
+isys_complete_ext_device_registration(struct ipu6_isys *isys,
+				      struct v4l2_subdev *sd,
+				      struct ipu6_isys_csi2_config *csi2)
+{
+	struct device *dev = &isys->adev->auxdev.dev;
+	unsigned int i;
+	int ret;
+
+	for (i = 0; i < sd->entity.num_pads; i++) {
+		if (sd->entity.pads[i].flags & MEDIA_PAD_FL_SOURCE)
+			break;
+	}
+
+	if (i == sd->entity.num_pads) {
+		dev_warn(dev, "no src pad in external entity\n");
+		ret = -ENOENT;
+		goto unregister_subdev;
+	}
+
+	ret = media_create_pad_link(&sd->entity, i,
+				    &isys->csi2[csi2->port].asd.sd.entity,
+				    0, 0);
+	if (ret) {
+		dev_warn(dev, "can't create link\n");
+		goto unregister_subdev;
+	}
+
+	isys->csi2[csi2->port].nlanes = csi2->nlanes;
+
+	return 0;
+
+unregister_subdev:
+	v4l2_device_unregister_subdev(sd);
+
+	return ret;
+}
+
+static void isys_stream_init(struct ipu6_isys *isys)
+{
+	u32 i;
+
+	for (i = 0; i < IPU6_ISYS_MAX_STREAMS; i++) {
+		mutex_init(&isys->streams[i].mutex);
+		init_completion(&isys->streams[i].stream_open_completion);
+		init_completion(&isys->streams[i].stream_close_completion);
+		init_completion(&isys->streams[i].stream_start_completion);
+		init_completion(&isys->streams[i].stream_stop_completion);
+		INIT_LIST_HEAD(&isys->streams[i].queues);
+		isys->streams[i].isys = isys;
+		isys->streams[i].stream_handle = i;
+		isys->streams[i].vc = INVALID_VC_ID;
+	}
+}
+
+static void isys_csi2_unregister_subdevices(struct ipu6_isys *isys)
+{
+	const struct ipu6_isys_internal_csi2_pdata *csi2 =
+		&isys->pdata->ipdata->csi2;
+	unsigned int i;
+
+	for (i = 0; i < csi2->nports; i++)
+		ipu6_isys_csi2_cleanup(&isys->csi2[i]);
+}
+
+static int isys_csi2_register_subdevices(struct ipu6_isys *isys)
+{
+	const struct ipu6_isys_internal_csi2_pdata *csi2_pdata =
+		&isys->pdata->ipdata->csi2;
+	struct device *dev = &isys->adev->auxdev.dev;
+	unsigned int i;
+	int ret;
+
+	isys->csi2 = devm_kcalloc(dev, csi2_pdata->nports,
+				  sizeof(*isys->csi2), GFP_KERNEL);
+	if (!isys->csi2)
+		return -ENOMEM;
+
+	for (i = 0; i < csi2_pdata->nports; i++) {
+		ret = ipu6_isys_csi2_init(&isys->csi2[i], isys,
+					  isys->pdata->base +
+					  csi2_pdata->offsets[i], i);
+		if (ret)
+			goto fail;
+
+		isys->isr_csi2_bits |= IPU6_ISYS_UNISPART_IRQ_CSI2(i);
+	}
+
+	return 0;
+
+fail:
+	while (i--)
+		ipu6_isys_csi2_cleanup(&isys->csi2[i]);
+
+	return ret;
+}
+
+static int isys_csi2_create_media_links(struct ipu6_isys *isys)
+{
+	const struct ipu6_isys_internal_csi2_pdata *csi2_pdata =
+		&isys->pdata->ipdata->csi2;
+	struct device *dev = &isys->adev->auxdev.dev;
+	unsigned int i, j, k;
+	int ret;
+
+	for (i = 0; i < csi2_pdata->nports; i++) {
+		struct media_entity *sd = &isys->csi2[i].asd.sd.entity;
+
+		for (j = 0; j < NR_OF_VIDEO_DEVICE; j++) {
+			struct media_entity *v = &isys->av[j].vdev.entity;
+			u32 flag = MEDIA_LNK_FL_DYNAMIC;
+
+			for (k = CSI2_PAD_SRC; k < NR_OF_CSI2_PADS; k++) {
+				ret = media_create_pad_link(sd, k, v, 0, flag);
+				if (ret) {
+					dev_err(dev, "CSI2 can't create link\n");
+					return ret;
+				}
+			}
+		}
+	}
+
+	return 0;
+}
+
+static void isys_unregister_video_devices(struct ipu6_isys *isys)
+{
+	unsigned int i;
+
+	for (i = 0; i < NR_OF_VIDEO_DEVICE; i++)
+		ipu6_isys_video_cleanup(&isys->av[i]);
+}
+
+static int isys_register_video_devices(struct ipu6_isys *isys)
+{
+	unsigned int i;
+	int ret;
+
+	for (i = 0; i < NR_OF_VIDEO_DEVICE; i++) {
+		snprintf(isys->av[i].vdev.name, sizeof(isys->av[i].vdev.name),
+			 IPU6_ISYS_ENTITY_PREFIX " ISYS Capture %u", i);
+		isys->av[i].isys = isys;
+		isys->av[i].aq.buf_prepare = ipu6_isys_buf_prepare;
+		isys->av[i].aq.fill_frame_buf_set =
+			ipu6_isys_buf_to_fw_frame_buf_pin;
+		isys->av[i].aq.link_fmt_validate = ipu6_isys_link_fmt_validate;
+		isys->av[i].aq.vbq.buf_struct_size =
+			sizeof(struct ipu6_isys_video_buffer);
+		isys->av[i].pfmt = &ipu6_isys_pfmts[0];
+
+		ret = ipu6_isys_video_init(&isys->av[i]);
+		if (ret)
+			goto fail;
+	}
+
+	return 0;
+
+fail:
+	while (i--)
+		ipu6_isys_video_cleanup(&isys->av[i]);
+
+	return ret;
+}
+
+void isys_setup_hw(struct ipu6_isys *isys)
+{
+	void __iomem *base = isys->pdata->base;
+	const u8 *thd = isys->pdata->ipdata->hw_variant.cdc_fifo_threshold;
+	u32 irqs = 0;
+	unsigned int i, nports;
+
+	nports = isys->pdata->ipdata->csi2.nports;
+
+	/* Enable irqs for all MIPI ports */
+	for (i = 0; i < nports; i++)
+		irqs |= IPU6_ISYS_UNISPART_IRQ_CSI2(i);
+
+	writel(irqs, base + isys->pdata->ipdata->csi2.ctrl0_irq_edge);
+	writel(irqs, base + isys->pdata->ipdata->csi2.ctrl0_irq_lnp);
+	writel(irqs, base + isys->pdata->ipdata->csi2.ctrl0_irq_mask);
+	writel(irqs, base + isys->pdata->ipdata->csi2.ctrl0_irq_enable);
+	writel(GENMASK(19, 0),
+	       base + isys->pdata->ipdata->csi2.ctrl0_irq_clear);
+
+	irqs = ISYS_UNISPART_IRQS;
+	writel(irqs, base + IPU6_REG_ISYS_UNISPART_IRQ_EDGE);
+	writel(irqs, base + IPU6_REG_ISYS_UNISPART_IRQ_LEVEL_NOT_PULSE);
+	writel(GENMASK(28, 0), base + IPU6_REG_ISYS_UNISPART_IRQ_CLEAR);
+	writel(irqs, base + IPU6_REG_ISYS_UNISPART_IRQ_MASK);
+	writel(irqs, base + IPU6_REG_ISYS_UNISPART_IRQ_ENABLE);
+
+	writel(0, base + IPU6_REG_ISYS_UNISPART_SW_IRQ_REG);
+	writel(0, base + IPU6_REG_ISYS_UNISPART_SW_IRQ_MUX_REG);
+
+	/* Write CDC FIFO threshold values for isys */
+	for (i = 0; i < isys->pdata->ipdata->hw_variant.cdc_fifos; i++)
+		writel(thd[i], base + IPU6_REG_ISYS_CDC_THRESHOLD(i));
+}
+
+static void ipu6_isys_csi2_isr(struct ipu6_isys_csi2 *csi2)
+{
+	struct ipu6_isys_stream *stream;
+	unsigned int i;
+	u32 status;
+	int source;
+
+	ipu6_isys_register_errors(csi2);
+
+	status = readl(csi2->base + CSI_PORT_REG_BASE_IRQ_CSI_SYNC +
+		       CSI_PORT_REG_BASE_IRQ_STATUS_OFFSET);
+
+	writel(status, csi2->base + CSI_PORT_REG_BASE_IRQ_CSI_SYNC +
+	       CSI_PORT_REG_BASE_IRQ_CLEAR_OFFSET);
+
+	source = csi2->asd.source;
+	for (i = 0; i < NR_OF_CSI2_VC; i++) {
+		if (status & IPU_CSI_RX_IRQ_FS_VC(i)) {
+			stream = ipu6_isys_query_stream_by_source(csi2->isys,
+								  source, i);
+			if (stream) {
+				ipu6_isys_csi2_sof_event_by_stream(stream);
+				ipu6_isys_put_stream(stream);
+			}
+		}
+
+		if (status & IPU_CSI_RX_IRQ_FE_VC(i)) {
+			stream = ipu6_isys_query_stream_by_source(csi2->isys,
+								  source, i);
+			if (stream) {
+				ipu6_isys_csi2_eof_event_by_stream(stream);
+				ipu6_isys_put_stream(stream);
+			}
+		}
+	}
+}
+
+irqreturn_t isys_isr(struct ipu6_bus_device *adev)
+{
+	struct ipu6_isys *isys = ipu6_bus_get_drvdata(adev);
+	void __iomem *base = isys->pdata->base;
+	u32 status_sw, status_csi;
+	u32 ctrl0_status, ctrl0_clear;
+
+	spin_lock(&isys->power_lock);
+	if (!isys->power) {
+		spin_unlock(&isys->power_lock);
+		return IRQ_NONE;
+	}
+
+	ctrl0_status = isys->pdata->ipdata->csi2.ctrl0_irq_status;
+	ctrl0_clear = isys->pdata->ipdata->csi2.ctrl0_irq_clear;
+
+	status_csi = readl(isys->pdata->base + ctrl0_status);
+	status_sw = readl(isys->pdata->base +
+			  IPU6_REG_ISYS_UNISPART_IRQ_STATUS);
+
+	writel(ISYS_UNISPART_IRQS & ~IPU6_ISYS_UNISPART_IRQ_SW,
+	       base + IPU6_REG_ISYS_UNISPART_IRQ_MASK);
+
+	do {
+		writel(status_csi, isys->pdata->base + ctrl0_clear);
+
+		writel(status_sw, isys->pdata->base +
+		       IPU6_REG_ISYS_UNISPART_IRQ_CLEAR);
+
+		if (isys->isr_csi2_bits & status_csi) {
+			unsigned int i;
+
+			for (i = 0; i < isys->pdata->ipdata->csi2.nports; i++) {
+				/* irq from not enabled port */
+				if (!isys->csi2[i].base)
+					continue;
+				if (status_csi & IPU6_ISYS_UNISPART_IRQ_CSI2(i))
+					ipu6_isys_csi2_isr(&isys->csi2[i]);
+			}
+		}
+
+		writel(0, base + IPU6_REG_ISYS_UNISPART_SW_IRQ_REG);
+
+		if (!isys_isr_one(adev))
+			status_sw = IPU6_ISYS_UNISPART_IRQ_SW;
+		else
+			status_sw = 0;
+
+		status_csi = readl(isys->pdata->base + ctrl0_status);
+		status_sw |= readl(isys->pdata->base +
+				   IPU6_REG_ISYS_UNISPART_IRQ_STATUS);
+	} while ((status_csi & isys->isr_csi2_bits) ||
+		 (status_sw & IPU6_ISYS_UNISPART_IRQ_SW));
+
+	writel(ISYS_UNISPART_IRQS, base + IPU6_REG_ISYS_UNISPART_IRQ_MASK);
+
+	spin_unlock(&isys->power_lock);
+
+	return IRQ_HANDLED;
+}
+
+static void get_lut_ltrdid(struct ipu6_isys *isys, struct ltr_did *pltr_did)
+{
+	struct isys_iwake_watermark *iwake_watermark = &isys->iwake_watermark;
+	struct ltr_did ltrdid_default;
+
+	ltrdid_default.lut_ltr.value = LTR_DEFAULT_VALUE;
+	ltrdid_default.lut_fill_time.value = FILL_TIME_DEFAULT_VALUE;
+
+	if (iwake_watermark->ltrdid.lut_ltr.value)
+		*pltr_did = iwake_watermark->ltrdid;
+	else
+		*pltr_did = ltrdid_default;
+}
+
+static int set_iwake_register(struct ipu6_isys *isys, u32 index, u32 value)
+{
+	struct device *dev = &isys->adev->auxdev.dev;
+	u32 req_id = index;
+	u32 offset = 0;
+	int ret;
+
+	ret = ipu6_fw_isys_send_proxy_token(isys, req_id, index, offset, value);
+	if (ret)
+		dev_err(dev, "write %d failed %d", index, ret);
+
+	return ret;
+}
+
+/*
+ * When input system is powered up and before enabling any new sensor capture,
+ * or after disabling any sensor capture the following values need to be set:
+ * LTR_value = LTR(usec) from calculation;
+ * LTR_scale = 2;
+ * DID_value = DID(usec) from calculation;
+ * DID_scale = 2;
+ *
+ * When input system is powered down, the LTR and DID values
+ * must be returned to the default values:
+ * LTR_value = 1023;
+ * LTR_scale = 5;
+ * DID_value = 1023;
+ * DID_scale = 2;
+ */
+static void set_iwake_ltrdid(struct ipu6_isys *isys, u16 ltr, u16 did,
+			     enum ltr_did_type use)
+{
+	struct device *dev = &isys->adev->auxdev.dev;
+	u16 ltr_val, ltr_scale = LTR_SCALE_1024NS;
+	u16 did_val, did_scale = DID_SCALE_1US;
+	struct ipu6_device *isp = isys->adev->isp;
+	union fabric_ctrl fc;
+
+	switch (use) {
+	case LTR_IWAKE_ON:
+		ltr_val = min_t(u16, ltr, (u16)LTR_DID_VAL_MAX);
+		did_val = min_t(u16, did, (u16)LTR_DID_VAL_MAX);
+		ltr_scale = (ltr == LTR_DID_VAL_MAX &&
+			     did == LTR_DID_VAL_MAX) ?
+			LTR_SCALE_DEFAULT : LTR_SCALE_1024NS;
+		break;
+	case LTR_ISYS_ON:
+	case LTR_IWAKE_OFF:
+		ltr_val = LTR_DID_PKGC_2R;
+		did_val = LTR_DID_PKGC_2R;
+		break;
+	case LTR_ISYS_OFF:
+		ltr_val   = LTR_DID_VAL_MAX;
+		did_val   = LTR_DID_VAL_MAX;
+		ltr_scale = LTR_SCALE_DEFAULT;
+		break;
+	case LTR_ENHANNCE_IWAKE:
+		if (ltr == LTR_DID_VAL_MAX && did == LTR_DID_VAL_MAX) {
+			ltr_val = LTR_DID_VAL_MAX;
+			did_val = LTR_DID_VAL_MAX;
+			ltr_scale = LTR_SCALE_DEFAULT;
+		} else if (did < ONE_THOUSAND_MICROSECOND) {
+			ltr_val = ltr;
+			did_val = did;
+		} else {
+			ltr_val = ltr;
+			/* div 90% value by 32 to account for scale change */
+			did_val = did / 32;
+			did_scale = DID_SCALE_32US;
+		}
+		break;
+	default:
+		ltr_val   = LTR_DID_VAL_MAX;
+		did_val   = LTR_DID_VAL_MAX;
+		ltr_scale = LTR_SCALE_DEFAULT;
+		break;
+	}
+
+	fc.value = readl(isp->base + IPU6_BUTTRESS_FABIC_CONTROL);
+	fc.bits.ltr_val = ltr_val;
+	fc.bits.ltr_scale = ltr_scale;
+	fc.bits.did_val = did_val;
+	fc.bits.did_scale = did_scale;
+
+	dev_dbg(dev, "ltr: value %u scale %u, did: value %u scale %u\n",
+		ltr_val, ltr_scale, did_val, did_scale);
+	writel(fc.value, isp->base + IPU6_BUTTRESS_FABIC_CONTROL);
+}
+
+/*
+ * Driver may clear register GDA_ENABLE_IWAKE before FW configures the
+ * stream for debug purpose. Otherwise driver should not access this register.
+ */
+static void enable_iwake(struct ipu6_isys *isys, bool enable)
+{
+	struct isys_iwake_watermark *iwake_watermark = &isys->iwake_watermark;
+	int ret;
+
+	mutex_lock(&iwake_watermark->mutex);
+
+	if (iwake_watermark->iwake_enabled == enable) {
+		mutex_unlock(&iwake_watermark->mutex);
+		return;
+	}
+
+	ret = set_iwake_register(isys, GDA_ENABLE_IWAKE_INDEX, enable);
+	if (!ret)
+		iwake_watermark->iwake_enabled = enable;
+
+	mutex_unlock(&iwake_watermark->mutex);
+}
+
+void update_watermark_setting(struct ipu6_isys *isys)
+{
+	struct isys_iwake_watermark *iwake_watermark = &isys->iwake_watermark;
+	u32 iwake_threshold, iwake_critical_threshold, page_num;
+	struct device *dev = &isys->adev->auxdev.dev;
+	u32 calc_fill_time_us = 0, ltr = 0, did = 0;
+	struct video_stream_watermark *p_watermark;
+	enum ltr_did_type ltr_did_type;
+	struct list_head *stream_node;
+	u64 isys_pb_datarate_mbs = 0;
+	u32 mem_open_threshold = 0;
+	struct ltr_did ltrdid;
+	u64 threshold_bytes;
+	u32 max_sram_size;
+	u32 shift;
+
+	shift = isys->pdata->ipdata->sram_gran_shift;
+	max_sram_size = isys->pdata->ipdata->max_sram_size;
+
+	mutex_lock(&iwake_watermark->mutex);
+	if (iwake_watermark->force_iwake_disable) {
+		set_iwake_ltrdid(isys, 0, 0, LTR_IWAKE_OFF);
+		set_iwake_register(isys, GDA_IRQ_CRITICAL_THRESHOLD_INDEX,
+				   CRITICAL_THRESHOLD_IWAKE_DISABLE);
+		goto unlock_exit;
+	}
+
+	if (list_empty(&iwake_watermark->video_list)) {
+		isys_pb_datarate_mbs = 0;
+	} else {
+		list_for_each(stream_node, &iwake_watermark->video_list) {
+			p_watermark = list_entry(stream_node,
+						 struct video_stream_watermark,
+						 stream_node);
+			isys_pb_datarate_mbs += p_watermark->stream_data_rate;
+		}
+	}
+	mutex_unlock(&iwake_watermark->mutex);
+
+	if (!isys_pb_datarate_mbs) {
+		enable_iwake(isys, false);
+		set_iwake_ltrdid(isys, 0, 0, LTR_IWAKE_OFF);
+		mutex_lock(&iwake_watermark->mutex);
+		set_iwake_register(isys, GDA_IRQ_CRITICAL_THRESHOLD_INDEX,
+				   CRITICAL_THRESHOLD_IWAKE_DISABLE);
+		goto unlock_exit;
+	}
+
+	enable_iwake(isys, true);
+	calc_fill_time_us = max_sram_size / isys_pb_datarate_mbs;
+
+	if (isys->pdata->ipdata->enhanced_iwake) {
+		ltr = isys->pdata->ipdata->ltr;
+		did = calc_fill_time_us * DEFAULT_DID_RATIO / 100;
+		ltr_did_type = LTR_ENHANNCE_IWAKE;
+	} else {
+		get_lut_ltrdid(isys, &ltrdid);
+
+		if (calc_fill_time_us <= ltrdid.lut_fill_time.bits.th0)
+			ltr = 0;
+		else if (calc_fill_time_us <= ltrdid.lut_fill_time.bits.th1)
+			ltr = ltrdid.lut_ltr.bits.val0;
+		else if (calc_fill_time_us <= ltrdid.lut_fill_time.bits.th2)
+			ltr = ltrdid.lut_ltr.bits.val1;
+		else if (calc_fill_time_us <= ltrdid.lut_fill_time.bits.th3)
+			ltr = ltrdid.lut_ltr.bits.val2;
+		else
+			ltr = ltrdid.lut_ltr.bits.val3;
+
+		did = calc_fill_time_us - ltr;
+		ltr_did_type = LTR_IWAKE_ON;
+	}
+
+	set_iwake_ltrdid(isys, ltr, did, ltr_did_type);
+
+	/* calculate iwake threshold with 2KB granularity pages */
+	threshold_bytes = did * isys_pb_datarate_mbs;
+	iwake_threshold = max_t(u32, 1, threshold_bytes >> shift);
+	iwake_threshold = min_t(u32, iwake_threshold, max_sram_size);
+
+	mutex_lock(&iwake_watermark->mutex);
+	if (isys->pdata->ipdata->enhanced_iwake) {
+		set_iwake_register(isys, GDA_IWAKE_THRESHOLD_INDEX,
+				   DEFAULT_IWAKE_THRESHOLD);
+		/* calculate number of pages that will be filled in 10 usec */
+		page_num = (DEFAULT_MEM_OPEN_TIME * isys_pb_datarate_mbs) /
+			ISF_DMA_TOP_GDA_PROFERTY_PAGE_SIZE;
+		page_num += ((DEFAULT_MEM_OPEN_TIME * isys_pb_datarate_mbs) %
+			     ISF_DMA_TOP_GDA_PROFERTY_PAGE_SIZE) ? 1 : 0;
+		mem_open_threshold = isys->pdata->ipdata->memopen_threshold;
+		mem_open_threshold = max_t(u32, mem_open_threshold, page_num);
+		dev_dbg(dev, "mem_open_threshold: %u\n", mem_open_threshold);
+		set_iwake_register(isys, GDA_MEMOPEN_THRESHOLD_INDEX,
+				   mem_open_threshold);
+	} else {
+		set_iwake_register(isys, GDA_IWAKE_THRESHOLD_INDEX,
+				   iwake_threshold);
+	}
+
+	iwake_critical_threshold = iwake_threshold +
+		(IS_PIXEL_BUFFER_PAGES - iwake_threshold) / 2;
+
+	dev_dbg(dev, "threshold: %u critical: %u\n", iwake_threshold,
+		iwake_critical_threshold);
+
+	set_iwake_register(isys, GDA_IRQ_CRITICAL_THRESHOLD_INDEX,
+			   iwake_critical_threshold);
+
+	writel(VAL_PKGC_PMON_CFG_RESET,
+	       isys->adev->isp->base + REG_PKGC_PMON_CFG);
+	writel(VAL_PKGC_PMON_CFG_START,
+	       isys->adev->isp->base + REG_PKGC_PMON_CFG);
+unlock_exit:
+	mutex_unlock(&iwake_watermark->mutex);
+}
+
+static void isys_iwake_watermark_init(struct ipu6_isys *isys)
+{
+	struct isys_iwake_watermark *iwake_watermark = &isys->iwake_watermark;
+
+	INIT_LIST_HEAD(&iwake_watermark->video_list);
+	mutex_init(&iwake_watermark->mutex);
+
+	iwake_watermark->ltrdid.lut_ltr.value = 0;
+	iwake_watermark->isys = isys;
+	iwake_watermark->iwake_enabled = false;
+	iwake_watermark->force_iwake_disable = false;
+}
+
+static void isys_iwake_watermark_cleanup(struct ipu6_isys *isys)
+{
+	struct isys_iwake_watermark *iwake_watermark = &isys->iwake_watermark;
+
+	mutex_lock(&iwake_watermark->mutex);
+	list_del(&iwake_watermark->video_list);
+	mutex_unlock(&iwake_watermark->mutex);
+
+	mutex_destroy(&iwake_watermark->mutex);
+}
+
+/* The .bound() notifier callback when a match is found */
+static int isys_notifier_bound(struct v4l2_async_notifier *notifier,
+			       struct v4l2_subdev *sd,
+			       struct v4l2_async_connection *asc)
+{
+	struct ipu6_isys *isys =
+		container_of(notifier, struct ipu6_isys, notifier);
+	struct sensor_async_sd *s_asd =
+		container_of(asc, struct sensor_async_sd, asc);
+	int ret;
+
+	dev_dbg(&isys->adev->auxdev.dev, "bind %s nlanes is %d port is %d\n",
+		sd->name, s_asd->csi2.nlanes, s_asd->csi2.port);
+	ret = isys_complete_ext_device_registration(isys, sd, &s_asd->csi2);
+	if (ret)
+		return ret;
+
+	return v4l2_device_register_subdev_nodes(&isys->v4l2_dev);
+}
+
+static int isys_notifier_complete(struct v4l2_async_notifier *notifier)
+{
+	struct ipu6_isys *isys =
+		container_of(notifier, struct ipu6_isys, notifier);
+
+	return v4l2_device_register_subdev_nodes(&isys->v4l2_dev);
+}
+
+static const struct v4l2_async_notifier_operations isys_async_ops = {
+	.bound = isys_notifier_bound,
+	.complete = isys_notifier_complete,
+};
+
+#define ISYS_MAX_PORTS 8
+static int isys_notifier_init(struct ipu6_isys *isys)
+{
+	struct ipu6_device *isp = isys->adev->isp;
+	struct device *dev = &isp->pdev->dev;
+	unsigned int i;
+	int ret;
+
+	v4l2_async_nf_init(&isys->notifier, &isys->v4l2_dev);
+
+	for (i = 0; i < ISYS_MAX_PORTS; i++) {
+		struct v4l2_fwnode_endpoint vep = {
+			.bus_type = V4L2_MBUS_CSI2_DPHY
+		};
+		struct sensor_async_sd *s_asd;
+		struct fwnode_handle *ep;
+
+		ep = fwnode_graph_get_endpoint_by_id(dev_fwnode(dev), i, 0,
+						FWNODE_GRAPH_ENDPOINT_NEXT);
+		if (!ep)
+			continue;
+
+		ret = v4l2_fwnode_endpoint_parse(ep, &vep);
+		if (ret) {
+			dev_err(dev, "fwnode endpoint parse failed: %d\n", ret);
+			goto err_parse;
+		}
+
+		s_asd = v4l2_async_nf_add_fwnode_remote(&isys->notifier, ep,
+							struct sensor_async_sd);
+		if (IS_ERR(s_asd)) {
+			ret = PTR_ERR(s_asd);
+			dev_err(dev, "add remove fwnode failed: %d\n", ret);
+			goto err_parse;
+		}
+
+		s_asd->csi2.port = vep.base.port;
+		s_asd->csi2.nlanes = vep.bus.mipi_csi2.num_data_lanes;
+
+		dev_dbg(dev, "remote endpoint port %d with %d lanes added\n",
+			s_asd->csi2.port, s_asd->csi2.nlanes);
+
+		fwnode_handle_put(ep);
+
+		continue;
+
+err_parse:
+		fwnode_handle_put(ep);
+		return ret;
+	}
+
+	isys->notifier.ops = &isys_async_ops;
+	ret = v4l2_async_nf_register(&isys->notifier);
+	if (ret) {
+		dev_err(dev, "failed to register async notifier : %d\n", ret);
+		v4l2_async_nf_cleanup(&isys->notifier);
+	}
+
+	return ret;
+}
+
+static void isys_notifier_cleanup(struct ipu6_isys *isys)
+{
+	v4l2_async_nf_unregister(&isys->notifier);
+	v4l2_async_nf_cleanup(&isys->notifier);
+}
+
+static int isys_register_devices(struct ipu6_isys *isys)
+{
+	struct device *dev = &isys->adev->auxdev.dev;
+	struct pci_dev *pdev = isys->adev->isp->pdev;
+	int ret;
+
+	isys->media_dev.dev = dev;
+	media_device_pci_init(&isys->media_dev,
+			      pdev, IPU6_MEDIA_DEV_MODEL_NAME);
+
+	strscpy(isys->v4l2_dev.name, isys->media_dev.model,
+		sizeof(isys->v4l2_dev.name));
+
+	ret = media_device_register(&isys->media_dev);
+	if (ret < 0)
+		goto out_media_device_unregister;
+
+	isys->v4l2_dev.mdev = &isys->media_dev;
+	isys->v4l2_dev.ctrl_handler = NULL;
+
+	ret = v4l2_device_register(dev->parent, &isys->v4l2_dev);
+	if (ret < 0)
+		goto out_media_device_unregister;
+
+	ret = isys_register_video_devices(isys);
+	if (ret)
+		goto out_v4l2_device_unregister;
+
+	ret = isys_csi2_register_subdevices(isys);
+	if (ret)
+		goto out_isys_unregister_video_device;
+
+	ret = isys_csi2_create_media_links(isys);
+	if (ret)
+		goto out_isys_unregister_subdevices;
+
+	ret = isys_notifier_init(isys);
+	if (ret)
+		goto out_isys_unregister_subdevices;
+
+	return 0;
+
+out_isys_unregister_subdevices:
+	isys_csi2_unregister_subdevices(isys);
+
+out_isys_unregister_video_device:
+	isys_unregister_video_devices(isys);
+
+out_v4l2_device_unregister:
+	v4l2_device_unregister(&isys->v4l2_dev);
+
+out_media_device_unregister:
+	media_device_unregister(&isys->media_dev);
+	media_device_cleanup(&isys->media_dev);
+
+	dev_err(dev, "failed to register isys devices\n");
+
+	return ret;
+}
+
+static void isys_unregister_devices(struct ipu6_isys *isys)
+{
+	isys_unregister_video_devices(isys);
+	isys_csi2_unregister_subdevices(isys);
+	v4l2_device_unregister(&isys->v4l2_dev);
+	media_device_unregister(&isys->media_dev);
+	media_device_cleanup(&isys->media_dev);
+}
+
+static int isys_runtime_pm_resume(struct device *dev)
+{
+	struct ipu6_bus_device *adev = to_ipu6_bus_device(dev);
+	struct ipu6_isys *isys = ipu6_bus_get_drvdata(adev);
+	struct ipu6_device *isp = adev->isp;
+	unsigned long flags;
+	int ret;
+
+	if (!isys)
+		return 0;
+
+	ret = ipu6_mmu_hw_init(adev->mmu);
+	if (ret)
+		return ret;
+
+	cpu_latency_qos_update_request(&isys->pm_qos, ISYS_PM_QOS_VALUE);
+
+	ret = ipu6_buttress_start_tsc_sync(isp);
+	if (ret)
+		return ret;
+
+	spin_lock_irqsave(&isys->power_lock, flags);
+	isys->power = 1;
+	spin_unlock_irqrestore(&isys->power_lock, flags);
+
+	isys_setup_hw(isys);
+
+	set_iwake_ltrdid(isys, 0, 0, LTR_ISYS_ON);
+
+	return 0;
+}
+
+static int isys_runtime_pm_suspend(struct device *dev)
+{
+	struct ipu6_bus_device *adev = to_ipu6_bus_device(dev);
+	struct ipu6_isys *isys;
+	unsigned long flags;
+
+	isys = dev_get_drvdata(dev);
+	if (!isys)
+		return 0;
+
+	spin_lock_irqsave(&isys->power_lock, flags);
+	isys->power = 0;
+	spin_unlock_irqrestore(&isys->power_lock, flags);
+
+	mutex_lock(&isys->mutex);
+	isys->need_reset = false;
+	mutex_unlock(&isys->mutex);
+
+	isys->phy_termcal_val = 0;
+	cpu_latency_qos_update_request(&isys->pm_qos, PM_QOS_DEFAULT_VALUE);
+
+	set_iwake_ltrdid(isys, 0, 0, LTR_ISYS_OFF);
+
+	ipu6_mmu_hw_cleanup(adev->mmu);
+
+	return 0;
+}
+
+static int isys_suspend(struct device *dev)
+{
+	struct ipu6_isys *isys = dev_get_drvdata(dev);
+
+	/* If stream is open, refuse to suspend */
+	if (isys->stream_opened)
+		return -EBUSY;
+
+	return 0;
+}
+
+static int isys_resume(struct device *dev)
+{
+	return 0;
+}
+
+static const struct dev_pm_ops isys_pm_ops = {
+	.runtime_suspend = isys_runtime_pm_suspend,
+	.runtime_resume = isys_runtime_pm_resume,
+	.suspend = isys_suspend,
+	.resume = isys_resume,
+};
+
+static void isys_remove(struct auxiliary_device *auxdev)
+{
+	struct ipu6_bus_device *adev = auxdev_to_adev(auxdev);
+	struct ipu6_isys *isys = dev_get_drvdata(&auxdev->dev);
+	struct ipu6_device *isp = adev->isp;
+	struct isys_fw_msgs *fwmsg, *safe;
+	unsigned int i;
+
+	for (i = 0; i < IPU6_ISYS_MAX_STREAMS; i++)
+		mutex_destroy(&isys->streams[i].mutex);
+
+	list_for_each_entry_safe(fwmsg, safe, &isys->framebuflist, head)
+		dma_free_attrs(&auxdev->dev, sizeof(struct isys_fw_msgs),
+			       fwmsg, fwmsg->dma_addr, 0);
+
+	list_for_each_entry_safe(fwmsg, safe, &isys->framebuflist_fw, head)
+		dma_free_attrs(&auxdev->dev, sizeof(struct isys_fw_msgs),
+			       fwmsg, fwmsg->dma_addr, 0);
+
+	isys_iwake_watermark_cleanup(isys);
+	isys_notifier_cleanup(isys);
+	isys_unregister_devices(isys);
+
+	cpu_latency_qos_remove_request(&isys->pm_qos);
+
+	if (!isp->secure_mode) {
+		ipu6_cpd_free_pkg_dir(adev);
+		ipu6_buttress_unmap_fw_image(adev, &adev->fw_sgt);
+		release_firmware(adev->fw);
+	}
+
+	mutex_destroy(&isys->stream_mutex);
+	mutex_destroy(&isys->mutex);
+}
+
+static int alloc_fw_msg_bufs(struct ipu6_isys *isys, int amount)
+{
+	struct device *dev = &isys->adev->auxdev.dev;
+	struct isys_fw_msgs *addr;
+	dma_addr_t dma_addr;
+	unsigned long flags;
+	unsigned int i;
+
+	for (i = 0; i < amount; i++) {
+		addr = dma_alloc_attrs(dev, sizeof(struct isys_fw_msgs),
+				       &dma_addr, GFP_KERNEL, 0);
+		if (!addr)
+			break;
+		addr->dma_addr = dma_addr;
+
+		spin_lock_irqsave(&isys->listlock, flags);
+		list_add(&addr->head, &isys->framebuflist);
+		spin_unlock_irqrestore(&isys->listlock, flags);
+	}
+
+	if (i == amount)
+		return 0;
+
+	spin_lock_irqsave(&isys->listlock, flags);
+	while (!list_empty(&isys->framebuflist)) {
+		addr = list_first_entry(&isys->framebuflist,
+					struct isys_fw_msgs, head);
+		list_del(&addr->head);
+		spin_unlock_irqrestore(&isys->listlock, flags);
+		dma_free_attrs(dev, sizeof(struct isys_fw_msgs), addr,
+			       addr->dma_addr, 0);
+		spin_lock_irqsave(&isys->listlock, flags);
+	}
+	spin_unlock_irqrestore(&isys->listlock, flags);
+
+	return -ENOMEM;
+}
+
+struct isys_fw_msgs *ipu6_get_fw_msg_buf(struct ipu6_isys_stream *stream)
+{
+	struct ipu6_isys *isys = stream->isys;
+	struct device *dev = &isys->adev->auxdev.dev;
+	struct isys_fw_msgs *msg;
+	unsigned long flags;
+	int ret;
+
+	spin_lock_irqsave(&isys->listlock, flags);
+	if (list_empty(&isys->framebuflist)) {
+		spin_unlock_irqrestore(&isys->listlock, flags);
+		dev_dbg(dev, "Frame list empty\n");
+
+		ret = alloc_fw_msg_bufs(isys, 5);
+		if (ret < 0)
+			return NULL;
+
+		spin_lock_irqsave(&isys->listlock, flags);
+		if (list_empty(&isys->framebuflist)) {
+			spin_unlock_irqrestore(&isys->listlock, flags);
+			dev_err(dev, "Frame list empty\n");
+			return NULL;
+		}
+	}
+	msg = list_last_entry(&isys->framebuflist, struct isys_fw_msgs, head);
+	list_move(&msg->head, &isys->framebuflist_fw);
+	spin_unlock_irqrestore(&isys->listlock, flags);
+	memset(&msg->fw_msg, 0, sizeof(msg->fw_msg));
+
+	return msg;
+}
+
+void ipu6_cleanup_fw_msg_bufs(struct ipu6_isys *isys)
+{
+	struct isys_fw_msgs *fwmsg, *fwmsg0;
+	unsigned long flags;
+
+	spin_lock_irqsave(&isys->listlock, flags);
+	list_for_each_entry_safe(fwmsg, fwmsg0, &isys->framebuflist_fw, head)
+		list_move(&fwmsg->head, &isys->framebuflist);
+	spin_unlock_irqrestore(&isys->listlock, flags);
+}
+
+void ipu6_put_fw_msg_buf(struct ipu6_isys *isys, u64 data)
+{
+	struct isys_fw_msgs *msg;
+	unsigned long flags;
+	u64 *ptr = (u64 *)data;
+
+	if (!ptr)
+		return;
+
+	spin_lock_irqsave(&isys->listlock, flags);
+	msg = container_of(ptr, struct isys_fw_msgs, fw_msg.dummy);
+	list_move(&msg->head, &isys->framebuflist);
+	spin_unlock_irqrestore(&isys->listlock, flags);
+}
+
+static int isys_probe(struct auxiliary_device *auxdev,
+		      const struct auxiliary_device_id *auxdev_id)
+{
+	struct ipu6_bus_device *adev = auxdev_to_adev(auxdev);
+	struct ipu6_device *isp = adev->isp;
+	const struct firmware *fw;
+	struct ipu6_isys *isys;
+	unsigned int i;
+	int ret;
+
+	if (!isp->bus_ready_to_probe)
+		return -EPROBE_DEFER;
+
+	isys = devm_kzalloc(&auxdev->dev, sizeof(*isys), GFP_KERNEL);
+	if (!isys)
+		return -ENOMEM;
+
+	ret = ipu6_mmu_hw_init(adev->mmu);
+	if (ret)
+		return ret;
+
+	adev->auxdrv_data =
+		(const struct ipu6_auxdrv_data *)auxdev_id->driver_data;
+	adev->auxdrv = to_auxiliary_drv(auxdev->dev.driver);
+	isys->adev = adev;
+	isys->pdata = adev->pdata;
+
+	/* initial sensor type */
+	isys->sensor_type = isys->pdata->ipdata->sensor_type_start;
+
+	spin_lock_init(&isys->streams_lock);
+	spin_lock_init(&isys->power_lock);
+	isys->power = 0;
+	isys->phy_termcal_val = 0;
+
+	mutex_init(&isys->mutex);
+	mutex_init(&isys->stream_mutex);
+
+	spin_lock_init(&isys->listlock);
+	INIT_LIST_HEAD(&isys->framebuflist);
+	INIT_LIST_HEAD(&isys->framebuflist_fw);
+
+	isys->line_align = IPU6_ISYS_2600_MEM_LINE_ALIGN;
+	isys->icache_prefetch = 0;
+
+	dev_set_drvdata(&auxdev->dev, isys);
+
+	isys_stream_init(isys);
+
+	if (!isp->secure_mode) {
+		fw = isp->cpd_fw;
+		ret = ipu6_buttress_map_fw_image(adev, fw, &adev->fw_sgt);
+		if (ret)
+			goto release_firmware;
+
+		ret = ipu6_cpd_create_pkg_dir(adev, isp->cpd_fw->data);
+		if (ret)
+			goto remove_shared_buffer;
+	}
+
+	cpu_latency_qos_add_request(&isys->pm_qos, PM_QOS_DEFAULT_VALUE);
+
+	ret = alloc_fw_msg_bufs(isys, 20);
+	if (ret < 0)
+		goto out_remove_pkg_dir_shared_buffer;
+
+	isys_iwake_watermark_init(isys);
+
+	if (is_ipu6se(adev->isp->hw_ver))
+		isys->phy_set_power = ipu6_isys_jsl_phy_set_power;
+	else if (is_ipu6ep_mtl(adev->isp->hw_ver))
+		isys->phy_set_power = ipu6_isys_dwc_phy_set_power;
+	else
+		isys->phy_set_power = ipu6_isys_mcd_phy_set_power;
+
+	ret = isys_register_devices(isys);
+	if (ret)
+		goto out_remove_pkg_dir_shared_buffer;
+
+	ipu6_mmu_hw_cleanup(adev->mmu);
+
+	return 0;
+
+out_remove_pkg_dir_shared_buffer:
+	if (!isp->secure_mode)
+		ipu6_cpd_free_pkg_dir(adev);
+remove_shared_buffer:
+	if (!isp->secure_mode)
+		ipu6_buttress_unmap_fw_image(adev, &adev->fw_sgt);
+release_firmware:
+	if (!isp->secure_mode)
+		release_firmware(adev->fw);
+
+	for (i = 0; i < IPU6_ISYS_MAX_STREAMS; i++)
+		mutex_destroy(&isys->streams[i].mutex);
+
+	mutex_destroy(&isys->mutex);
+	mutex_destroy(&isys->stream_mutex);
+
+	ipu6_mmu_hw_cleanup(adev->mmu);
+
+	return ret;
+}
+
+struct fwmsg {
+	int type;
+	char *msg;
+	bool valid_ts;
+};
+
+static const struct fwmsg fw_msg[] = {
+	{IPU6_FW_ISYS_RESP_TYPE_STREAM_OPEN_DONE, "STREAM_OPEN_DONE", 0},
+	{IPU6_FW_ISYS_RESP_TYPE_STREAM_CLOSE_ACK, "STREAM_CLOSE_ACK", 0},
+	{IPU6_FW_ISYS_RESP_TYPE_STREAM_START_ACK, "STREAM_START_ACK", 0},
+	{IPU6_FW_ISYS_RESP_TYPE_STREAM_START_AND_CAPTURE_ACK,
+	 "STREAM_START_AND_CAPTURE_ACK", 0},
+	{IPU6_FW_ISYS_RESP_TYPE_STREAM_STOP_ACK, "STREAM_STOP_ACK", 0},
+	{IPU6_FW_ISYS_RESP_TYPE_STREAM_FLUSH_ACK, "STREAM_FLUSH_ACK", 0},
+	{IPU6_FW_ISYS_RESP_TYPE_PIN_DATA_READY, "PIN_DATA_READY", 1},
+	{IPU6_FW_ISYS_RESP_TYPE_STREAM_CAPTURE_ACK, "STREAM_CAPTURE_ACK", 0},
+	{IPU6_FW_ISYS_RESP_TYPE_STREAM_START_AND_CAPTURE_DONE,
+	 "STREAM_START_AND_CAPTURE_DONE", 1},
+	{IPU6_FW_ISYS_RESP_TYPE_STREAM_CAPTURE_DONE, "STREAM_CAPTURE_DONE", 1},
+	{IPU6_FW_ISYS_RESP_TYPE_FRAME_SOF, "FRAME_SOF", 1},
+	{IPU6_FW_ISYS_RESP_TYPE_FRAME_EOF, "FRAME_EOF", 1},
+	{IPU6_FW_ISYS_RESP_TYPE_STATS_DATA_READY, "STATS_READY", 1},
+	{-1, "UNKNOWN MESSAGE", 0}
+};
+
+static int resp_type_to_index(int type)
+{
+	unsigned int i;
+
+	for (i = 0; i < ARRAY_SIZE(fw_msg); i++)
+		if (fw_msg[i].type == type)
+			return i;
+
+	return  ARRAY_SIZE(fw_msg) - 1;
+}
+
+static int isys_isr_one(struct ipu6_bus_device *adev)
+{
+	struct ipu6_isys *isys = ipu6_bus_get_drvdata(adev);
+	struct ipu6_fw_isys_resp_info_abi *resp;
+	struct ipu6_isys_stream *stream;
+	struct ipu6_isys_csi2 *csi2 = NULL;
+	u64 ts;
+
+	if (!isys->fwcom)
+		return 1;
+
+	resp = ipu6_fw_isys_get_resp(isys->fwcom, IPU6_BASE_MSG_RECV_QUEUES);
+	if (!resp)
+		return 1;
+
+	ts = (u64)resp->timestamp[1] << 32 | resp->timestamp[0];
+
+	if (resp->error_info.error == IPU6_FW_ISYS_ERROR_STREAM_IN_SUSPENSION)
+		/* Suspension is kind of special case: not enough buffers */
+		dev_dbg(&adev->auxdev.dev,
+			"FW error resp %02d %s, stream %u, error SUSPENSION, details %d, timestamp 0x%16.16llx, pin %d\n",
+			resp->type,
+			fw_msg[resp_type_to_index(resp->type)].msg,
+			resp->stream_handle,
+			resp->error_info.error_details,
+			fw_msg[resp_type_to_index(resp->type)].valid_ts ?
+			ts : 0, resp->pin_id);
+	else if (resp->error_info.error)
+		dev_dbg(&adev->auxdev.dev,
+			"FW error resp %02d %s, stream %u, error %d, details %d, timestamp 0x%16.16llx, pin %d\n",
+			resp->type,
+			fw_msg[resp_type_to_index(resp->type)].msg,
+			resp->stream_handle,
+			resp->error_info.error, resp->error_info.error_details,
+			fw_msg[resp_type_to_index(resp->type)].valid_ts ?
+			ts : 0, resp->pin_id);
+	else
+		dev_dbg(&adev->auxdev.dev,
+			"FW resp %02d %s, stream %u, timestamp 0x%16.16llx, pin %d\n",
+			resp->type,
+			fw_msg[resp_type_to_index(resp->type)].msg,
+			resp->stream_handle,
+			fw_msg[resp_type_to_index(resp->type)].valid_ts ?
+			ts : 0, resp->pin_id);
+
+	if (resp->stream_handle >= IPU6_ISYS_MAX_STREAMS) {
+		dev_err(&adev->auxdev.dev, "bad stream handle %u\n",
+			resp->stream_handle);
+		goto leave;
+	}
+
+	stream = ipu6_isys_query_stream_by_handle(isys, resp->stream_handle);
+	if (!stream) {
+		dev_err(&adev->auxdev.dev, "stream of stream_handle %u is unused\n",
+			resp->stream_handle);
+		goto leave;
+	}
+	stream->error = resp->error_info.error;
+
+	csi2 = ipu6_isys_subdev_to_csi2(stream->asd);
+
+	switch (resp->type) {
+	case IPU6_FW_ISYS_RESP_TYPE_STREAM_OPEN_DONE:
+		complete(&stream->stream_open_completion);
+		break;
+	case IPU6_FW_ISYS_RESP_TYPE_STREAM_CLOSE_ACK:
+		complete(&stream->stream_close_completion);
+		break;
+	case IPU6_FW_ISYS_RESP_TYPE_STREAM_START_ACK:
+		complete(&stream->stream_start_completion);
+		break;
+	case IPU6_FW_ISYS_RESP_TYPE_STREAM_START_AND_CAPTURE_ACK:
+		complete(&stream->stream_start_completion);
+		break;
+	case IPU6_FW_ISYS_RESP_TYPE_STREAM_STOP_ACK:
+		complete(&stream->stream_stop_completion);
+		break;
+	case IPU6_FW_ISYS_RESP_TYPE_STREAM_FLUSH_ACK:
+		complete(&stream->stream_stop_completion);
+		break;
+	case IPU6_FW_ISYS_RESP_TYPE_PIN_DATA_READY:
+		/*
+		 * firmware only release the capture msg until software
+		 * get pin_data_ready event
+		 */
+		ipu6_put_fw_msg_buf(ipu6_bus_get_drvdata(adev), resp->buf_id);
+		if (resp->pin_id < IPU6_ISYS_OUTPUT_PINS &&
+		    stream->output_pins[resp->pin_id].pin_ready)
+			stream->output_pins[resp->pin_id].pin_ready(stream,
+								    resp);
+		else
+			dev_warn(&adev->auxdev.dev,
+				 "%d:No data pin ready handler for pin id %d\n",
+				 resp->stream_handle, resp->pin_id);
+		if (csi2)
+			ipu6_isys_csi2_error(csi2);
+
+		break;
+	case IPU6_FW_ISYS_RESP_TYPE_STREAM_CAPTURE_ACK:
+		break;
+	case IPU6_FW_ISYS_RESP_TYPE_STREAM_START_AND_CAPTURE_DONE:
+	case IPU6_FW_ISYS_RESP_TYPE_STREAM_CAPTURE_DONE:
+		break;
+	case IPU6_FW_ISYS_RESP_TYPE_FRAME_SOF:
+
+		ipu6_isys_csi2_sof_event_by_stream(stream);
+		stream->seq[stream->seq_index].sequence =
+			atomic_read(&stream->sequence) - 1;
+		stream->seq[stream->seq_index].timestamp = ts;
+		dev_dbg(&adev->auxdev.dev,
+			"sof: handle %d: (index %u), timestamp 0x%16.16llx\n",
+			resp->stream_handle,
+			stream->seq[stream->seq_index].sequence, ts);
+		stream->seq_index = (stream->seq_index + 1)
+			% IPU6_ISYS_MAX_PARALLEL_SOF;
+		break;
+	case IPU6_FW_ISYS_RESP_TYPE_FRAME_EOF:
+		ipu6_isys_csi2_eof_event_by_stream(stream);
+		dev_dbg(&adev->auxdev.dev,
+			"eof: handle %d: (index %u), timestamp 0x%16.16llx\n",
+			resp->stream_handle,
+			stream->seq[stream->seq_index].sequence, ts);
+		break;
+	case IPU6_FW_ISYS_RESP_TYPE_STATS_DATA_READY:
+		break;
+	default:
+		dev_err(&adev->auxdev.dev, "%d:unknown response type %u\n",
+			resp->stream_handle, resp->type);
+		break;
+	}
+
+	ipu6_isys_put_stream(stream);
+leave:
+	ipu6_fw_isys_put_resp(isys->fwcom, IPU6_BASE_MSG_RECV_QUEUES);
+	return 0;
+}
+
+static const struct ipu6_auxdrv_data ipu6_isys_auxdrv_data = {
+	.isr = isys_isr,
+	.isr_threaded = NULL,
+	.wake_isr_thread = false,
+};
+
+static const struct auxiliary_device_id ipu6_isys_id_table[] = {
+	{
+		.name = "intel_ipu6.isys",
+		.driver_data = (kernel_ulong_t)&ipu6_isys_auxdrv_data,
+	},
+	{ }
+};
+MODULE_DEVICE_TABLE(auxiliary, ipu6_isys_id_table);
+
+static struct auxiliary_driver isys_driver = {
+	.name = IPU6_ISYS_NAME,
+	.probe = isys_probe,
+	.remove = isys_remove,
+	.id_table = ipu6_isys_id_table,
+	.driver = {
+		.pm = &isys_pm_ops,
+	},
+};
+
+module_auxiliary_driver(isys_driver);
+
+MODULE_AUTHOR("Sakari Ailus <sakari.ailus@linux.intel.com>");
+MODULE_AUTHOR("Tianshu Qiu <tian.shu.qiu@intel.com>");
+MODULE_AUTHOR("Bingbu Cao <bingbu.cao@intel.com>");
+MODULE_AUTHOR("Yunliang Ding <yunliang.ding@intel.com>");
+MODULE_AUTHOR("Hongju Wang <hongju.wang@intel.com>");
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("Intel IPU6 input system driver");
+MODULE_IMPORT_NS(INTEL_IPU6);
diff --git a/drivers/media/pci/intel/ipu6/ipu6-isys.h b/drivers/media/pci/intel/ipu6/ipu6-isys.h
new file mode 100644
index 000000000000..252f161bed39
--- /dev/null
+++ b/drivers/media/pci/intel/ipu6/ipu6-isys.h
@@ -0,0 +1,201 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/* Copyright (C) 2013 - 2023 Intel Corporation */
+
+#ifndef IPU6_ISYS_H
+#define IPU6_ISYS_H
+
+#include <linux/pm_qos.h>
+
+#include <media/media-device.h>
+#include <media/v4l2-async.h>
+#include <media/v4l2-device.h>
+
+#include "ipu6.h"
+#include "ipu6-bus.h"
+#include "ipu6-fw-isys.h"
+#include "ipu6-isys-csi2.h"
+#include "ipu6-isys-video.h"
+
+#define IPU6_ISYS_ENTITY_PREFIX		"Intel IPU6"
+/* FW support max 16 streams */
+#define IPU6_ISYS_MAX_STREAMS		16
+#define ISYS_UNISPART_IRQS	(IPU6_ISYS_UNISPART_IRQ_SW |	\
+				 IPU6_ISYS_UNISPART_IRQ_CSI0 |	\
+				 IPU6_ISYS_UNISPART_IRQ_CSI1)
+
+#define IPU6_ISYS_2600_MEM_LINE_ALIGN	64
+
+/*
+ * Current message queue configuration. These must be big enough
+ * so that they never gets full. Queues are located in system memory
+ */
+#define IPU6_ISYS_SIZE_RECV_QUEUE 40
+#define IPU6_ISYS_SIZE_SEND_QUEUE 40
+#define IPU6_ISYS_SIZE_PROXY_RECV_QUEUE 5
+#define IPU6_ISYS_SIZE_PROXY_SEND_QUEUE 5
+#define IPU6_ISYS_NUM_RECV_QUEUE 1
+
+#define IPU6_ISYS_MIN_WIDTH		1U
+#define IPU6_ISYS_MIN_HEIGHT		1U
+#define IPU6_ISYS_MAX_WIDTH		4672U
+#define IPU6_ISYS_MAX_HEIGHT		3416U
+
+/* the threshold granularity is 2KB on IPU6 */
+#define IPU6_SRAM_GRANULARITY_SHIFT	11
+#define IPU6_SRAM_GRANULARITY_SIZE	2048
+/* the threshold granularity is 1KB on IPU6SE */
+#define IPU6SE_SRAM_GRANULARITY_SHIFT	10
+#define IPU6SE_SRAM_GRANULARITY_SIZE	1024
+/* IS pixel buffer is 256KB, MaxSRAMSize is 200KB on IPU6 */
+#define IPU6_MAX_SRAM_SIZE			(200 << 10)
+/* IS pixel buffer is 128KB, MaxSRAMSize is 96KB on IPU6SE */
+#define IPU6SE_MAX_SRAM_SIZE			(96 << 10)
+
+#define IPU6EP_LTR_VALUE			200
+#define IPU6EP_MIN_MEMOPEN_TH			0x4
+#define IPU6EP_MTL_LTR_VALUE			1023
+#define IPU6EP_MTL_MIN_MEMOPEN_TH		0xc
+
+struct ltr_did {
+	union {
+		u32 value;
+		struct {
+			u8 val0;
+			u8 val1;
+			u8 val2;
+			u8 val3;
+		} bits;
+	} lut_ltr;
+	union {
+		u32 value;
+		struct {
+			u8 th0;
+			u8 th1;
+			u8 th2;
+			u8 th3;
+		} bits;
+	} lut_fill_time;
+};
+
+struct isys_iwake_watermark {
+	bool iwake_enabled;
+	bool force_iwake_disable;
+	u32 iwake_threshold;
+	u64 isys_pixelbuffer_datarate;
+	struct ltr_did ltrdid;
+	struct mutex mutex; /* protect whole struct */
+	struct ipu6_isys *isys;
+	struct list_head video_list;
+};
+
+struct ipu6_isys_csi2_config {
+	u32 nlanes;
+	u32 port;
+};
+
+struct sensor_async_sd {
+	struct v4l2_async_connection asc;
+	struct ipu6_isys_csi2_config csi2;
+};
+
+/*
+ * struct ipu6_isys
+ *
+ * @media_dev: Media device
+ * @v4l2_dev: V4L2 device
+ * @adev: ISYS bus device
+ * @power: Is ISYS powered on or not?
+ * @isr_bits: Which bits does the ISR handle?
+ * @power_lock: Serialise access to power (power state in general)
+ * @csi2_rx_ctrl_cached: cached shared value between all CSI2 receivers
+ * @streams_lock: serialise access to streams
+ * @streams: streams per firmware stream ID
+ * @fwcom: fw communication layer private pointer
+ *         or optional external library private pointer
+ * @line_align: line alignment in memory
+ * @phy_termcal_val: the termination calibration value, only used for DWC PHY
+ * @need_reset: Isys requires d0i0->i3 transition
+ * @ref_count: total number of callers fw open
+ * @mutex: serialise access isys video open/release related operations
+ * @stream_mutex: serialise stream start and stop, queueing requests
+ * @pdata: platform data pointer
+ * @csi2: CSI-2 receivers
+ */
+struct ipu6_isys {
+	struct media_device media_dev;
+	struct v4l2_device v4l2_dev;
+	struct ipu6_bus_device *adev;
+
+	int power;
+	spinlock_t power_lock;
+	u32 isr_csi2_bits;
+	u32 csi2_rx_ctrl_cached;
+	spinlock_t streams_lock;
+	struct ipu6_isys_stream streams[IPU6_ISYS_MAX_STREAMS];
+	int streams_ref_count[IPU6_ISYS_MAX_STREAMS];
+	void *fwcom;
+	unsigned int line_align;
+	u32 phy_termcal_val;
+	bool need_reset;
+	bool icache_prefetch;
+	bool csi2_cse_ipc_not_supported;
+	unsigned int ref_count;
+	unsigned int stream_opened;
+	unsigned int sensor_type;
+
+	struct mutex mutex;
+	struct mutex stream_mutex;
+
+	struct ipu6_isys_pdata *pdata;
+
+	int (*phy_set_power)(struct ipu6_isys *isys,
+			     struct ipu6_isys_csi2_config *cfg,
+			     const struct ipu6_isys_csi2_timing *timing,
+			     bool on);
+
+	struct ipu6_isys_csi2 *csi2;
+	struct ipu6_isys_video av[NR_OF_VIDEO_DEVICE];
+
+	struct pm_qos_request pm_qos;
+	spinlock_t listlock;	/* Protect framebuflist */
+	struct list_head framebuflist;
+	struct list_head framebuflist_fw;
+	struct v4l2_async_notifier notifier;
+	struct isys_iwake_watermark iwake_watermark;
+};
+
+struct isys_fw_msgs {
+	union {
+		u64 dummy;
+		struct ipu6_fw_isys_frame_buff_set_abi frame;
+		struct ipu6_fw_isys_stream_cfg_data_abi stream;
+	} fw_msg;
+	struct list_head head;
+	dma_addr_t dma_addr;
+};
+
+struct isys_fw_msgs *ipu6_get_fw_msg_buf(struct ipu6_isys_stream *stream);
+void ipu6_put_fw_msg_buf(struct ipu6_isys *isys, u64 data);
+void ipu6_cleanup_fw_msg_bufs(struct ipu6_isys *isys);
+
+extern const struct v4l2_ioctl_ops ipu6_isys_ioctl_ops;
+
+void isys_setup_hw(struct ipu6_isys *isys);
+irqreturn_t isys_isr(struct ipu6_bus_device *adev);
+void update_watermark_setting(struct ipu6_isys *isys);
+
+int ipu6_isys_mcd_phy_set_power(struct ipu6_isys *isys,
+				struct ipu6_isys_csi2_config *cfg,
+				const struct ipu6_isys_csi2_timing *timing,
+				bool on);
+
+int ipu6_isys_dwc_phy_set_power(struct ipu6_isys *isys,
+				struct ipu6_isys_csi2_config *cfg,
+				const struct ipu6_isys_csi2_timing *timing,
+				bool on);
+
+int ipu6_isys_jsl_phy_set_power(struct ipu6_isys *isys,
+				struct ipu6_isys_csi2_config *cfg,
+				const struct ipu6_isys_csi2_timing *timing,
+				bool on);
+#endif /* IPU6_ISYS_H */
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 86+ messages in thread

* [PATCH v2 11/15] media: intel/ipu6: input system video capture nodes
  2023-10-24 11:29 [PATCH v2 00/15] Intel IPU6 and IPU6 input system drivers bingbu.cao
                   ` (9 preceding siblings ...)
  2023-10-24 11:29 ` [PATCH v2 10/15] media: intel/ipu6: add input system driver bingbu.cao
@ 2023-10-24 11:29 ` bingbu.cao
  2023-11-05 16:59   ` Hans de Goede
  2024-01-09 13:35   ` Andreas Helbech Kleist
  2023-10-24 11:29 ` [PATCH v2 12/15] media: add Kconfig and Makefile for IPU6 bingbu.cao
                   ` (5 subsequent siblings)
  16 siblings, 2 replies; 86+ messages in thread
From: bingbu.cao @ 2023-10-24 11:29 UTC (permalink / raw)
  To: linux-media, sakari.ailus, laurent.pinchart
  Cc: andriy.shevchenko, hdegoede, ilpo.jarvinen, andreaskleist,
	claus.stovgaard, tfiga, senozhatsky, tomi.valkeinen, bingbu.cao,
	bingbu.cao, tian.shu.qiu, hongju.wang

From: Bingbu Cao <bingbu.cao@intel.com>

Register v4l2 video device and setup the vb2 queue to
support basic video capture. Video streaming callback
will trigger the input system driver to construct a
input system stream configuration for firmware based on
data type and stream ID and then queue buffers to firmware
to do capture.

Signed-off-by: Bingbu Cao <bingbu.cao@intel.com>
---
 .../media/pci/intel/ipu6/ipu6-isys-queue.c    |  846 +++++++++++
 .../media/pci/intel/ipu6/ipu6-isys-queue.h    |   94 ++
 .../media/pci/intel/ipu6/ipu6-isys-video.c    | 1239 +++++++++++++++++
 .../media/pci/intel/ipu6/ipu6-isys-video.h    |  129 ++
 4 files changed, 2308 insertions(+)
 create mode 100644 drivers/media/pci/intel/ipu6/ipu6-isys-queue.c
 create mode 100644 drivers/media/pci/intel/ipu6/ipu6-isys-queue.h
 create mode 100644 drivers/media/pci/intel/ipu6/ipu6-isys-video.c
 create mode 100644 drivers/media/pci/intel/ipu6/ipu6-isys-video.h

diff --git a/drivers/media/pci/intel/ipu6/ipu6-isys-queue.c b/drivers/media/pci/intel/ipu6/ipu6-isys-queue.c
new file mode 100644
index 000000000000..81727d4026a2
--- /dev/null
+++ b/drivers/media/pci/intel/ipu6/ipu6-isys-queue.c
@@ -0,0 +1,846 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2013 - 2023 Intel Corporation
+ */
+
+#include <media/videobuf2-dma-contig.h>
+
+#include "ipu6-isys.h"
+
+static int queue_setup(struct vb2_queue *q, unsigned int *num_buffers,
+		       unsigned int *num_planes, unsigned int sizes[],
+		       struct device *alloc_devs[])
+{
+	struct ipu6_isys_queue *aq = vb2_queue_to_isys_queue(q);
+	struct ipu6_isys_video *av = ipu6_isys_queue_to_video(aq);
+	struct device *dev = &av->isys->adev->auxdev.dev;
+	bool use_fmt = false;
+	unsigned int i;
+	u32 size;
+
+	/* num_planes == 0: we're being called through VIDIOC_REQBUFS */
+	if (!*num_planes) {
+		use_fmt = true;
+		*num_planes = av->mpix.num_planes;
+	}
+
+	for (i = 0; i < *num_planes; i++) {
+		size = av->mpix.plane_fmt[i].sizeimage;
+		if (use_fmt) {
+			sizes[i] = size;
+		} else if (sizes[i] < size) {
+			dev_err(dev, "%s: queue setup: plane %d size %u < %u\n",
+				av->vdev.name, i, sizes[i], size);
+			return -EINVAL;
+		}
+
+		alloc_devs[i] = aq->dev;
+	}
+
+	return 0;
+}
+
+int ipu6_isys_buf_prepare(struct vb2_buffer *vb)
+{
+	struct ipu6_isys_queue *aq = vb2_queue_to_isys_queue(vb->vb2_queue);
+	struct ipu6_isys_video *av = ipu6_isys_queue_to_video(aq);
+	struct device *dev = &av->isys->adev->auxdev.dev;
+
+	dev_dbg(dev, "buffer: %s: configured size %u, buffer size %lu\n",
+		av->vdev.name, av->mpix.plane_fmt[0].sizeimage,
+		vb2_plane_size(vb, 0));
+
+	if (av->mpix.plane_fmt[0].sizeimage > vb2_plane_size(vb, 0))
+		return -EINVAL;
+
+	vb2_set_plane_payload(vb, 0, av->mpix.plane_fmt[0].bytesperline *
+			      av->mpix.height);
+	vb->planes[0].data_offset = 0;
+
+	return 0;
+}
+
+static int buf_prepare(struct vb2_buffer *vb)
+{
+	struct ipu6_isys_queue *aq = vb2_queue_to_isys_queue(vb->vb2_queue);
+
+	return aq->buf_prepare(vb);
+}
+
+/*
+ * Queue a buffer list back to incoming or active queues. The buffers
+ * are removed from the buffer list.
+ */
+void ipu6_isys_buffer_list_queue(struct ipu6_isys_buffer_list *bl,
+				 unsigned long op_flags,
+				 enum vb2_buffer_state state)
+{
+	struct ipu6_isys_buffer *ib, *ib_safe;
+	unsigned long flags;
+	bool first = true;
+
+	if (!bl)
+		return;
+
+	WARN_ON_ONCE(!bl->nbufs);
+	WARN_ON_ONCE(op_flags & IPU6_ISYS_BUFFER_LIST_FL_ACTIVE &&
+		     op_flags & IPU6_ISYS_BUFFER_LIST_FL_INCOMING);
+
+	list_for_each_entry_safe(ib, ib_safe, &bl->head, head) {
+		struct ipu6_isys_video *av;
+		struct vb2_buffer *vb = ipu6_isys_buffer_to_vb2_buffer(ib);
+		struct ipu6_isys_queue *aq =
+			vb2_queue_to_isys_queue(vb->vb2_queue);
+		struct device *dev;
+
+		if (WARN_ON_ONCE(ib->type != IPU6_ISYS_VIDEO_BUFFER))
+			continue;
+
+		av = ipu6_isys_queue_to_video(aq);
+		dev = &av->isys->adev->auxdev.dev;
+		spin_lock_irqsave(&aq->lock, flags);
+		list_del(&ib->head);
+		if (op_flags & IPU6_ISYS_BUFFER_LIST_FL_ACTIVE)
+			list_add(&ib->head, &aq->active);
+		else if (op_flags & IPU6_ISYS_BUFFER_LIST_FL_INCOMING)
+			list_add_tail(&ib->head, &aq->incoming);
+		spin_unlock_irqrestore(&aq->lock, flags);
+
+		if (op_flags & IPU6_ISYS_BUFFER_LIST_FL_SET_STATE)
+			vb2_buffer_done(vb, state);
+
+		if (first) {
+			dev_dbg(dev,
+				"queue buf list %p flags %lx, s %d, %d bufs\n",
+				bl, op_flags, state, bl->nbufs);
+			first = false;
+		}
+
+		bl->nbufs--;
+	}
+
+	WARN_ON(bl->nbufs);
+}
+
+/*
+ * flush_firmware_streamon_fail() - Flush in cases where requests may
+ * have been queued to firmware and the *firmware streamon fails for a
+ * reason or another.
+ */
+static void flush_firmware_streamon_fail(struct ipu6_isys_stream *stream)
+{
+	struct device *dev = &stream->isys->adev->auxdev.dev;
+	struct ipu6_isys_queue *aq;
+	unsigned long flags;
+
+	lockdep_assert_held(&stream->mutex);
+
+	list_for_each_entry(aq, &stream->queues, node) {
+		struct ipu6_isys_video *av = ipu6_isys_queue_to_video(aq);
+		struct ipu6_isys_buffer *ib, *ib_safe;
+
+		spin_lock_irqsave(&aq->lock, flags);
+		list_for_each_entry_safe(ib, ib_safe, &aq->active, head) {
+			struct vb2_buffer *vb =
+				ipu6_isys_buffer_to_vb2_buffer(ib);
+
+			list_del(&ib->head);
+			if (av->streaming) {
+				dev_dbg(dev,
+					"%s: queue buffer %u back to incoming\n",
+					av->vdev.name, vb->index);
+				/* Queue already streaming, return to driver. */
+				list_add(&ib->head, &aq->incoming);
+				continue;
+			}
+			/* Queue not yet streaming, return to user. */
+			dev_dbg(dev, "%s: return %u back to videobuf2\n",
+				av->vdev.name, vb->index);
+			vb2_buffer_done(ipu6_isys_buffer_to_vb2_buffer(ib),
+					VB2_BUF_STATE_QUEUED);
+		}
+		spin_unlock_irqrestore(&aq->lock, flags);
+	}
+}
+
+/*
+ * Attempt obtaining a buffer list from the incoming queues, a list of buffers
+ * that contains one entry from each video buffer queue. If a buffer can't be
+ * obtained from every queue, the buffers are returned back to the queue.
+ */
+static int buffer_list_get(struct ipu6_isys_stream *stream,
+			   struct ipu6_isys_buffer_list *bl)
+{
+	struct device *dev = &stream->isys->adev->auxdev.dev;
+	struct ipu6_isys_queue *aq;
+	unsigned long flags;
+	unsigned long buf_flag = IPU6_ISYS_BUFFER_LIST_FL_INCOMING;
+
+	bl->nbufs = 0;
+	INIT_LIST_HEAD(&bl->head);
+
+	list_for_each_entry(aq, &stream->queues, node) {
+		struct ipu6_isys_buffer *ib;
+
+		spin_lock_irqsave(&aq->lock, flags);
+		if (list_empty(&aq->incoming)) {
+			spin_unlock_irqrestore(&aq->lock, flags);
+			if (!list_empty(&bl->head))
+				ipu6_isys_buffer_list_queue(bl, buf_flag, 0);
+			return -ENODATA;
+		}
+
+		ib = list_last_entry(&aq->incoming,
+				     struct ipu6_isys_buffer, head);
+
+		dev_dbg(dev, "buffer: %s: buffer %u\n",
+			ipu6_isys_queue_to_video(aq)->vdev.name,
+			ipu6_isys_buffer_to_vb2_buffer(ib)->index);
+		list_del(&ib->head);
+		list_add(&ib->head, &bl->head);
+		spin_unlock_irqrestore(&aq->lock, flags);
+
+		bl->nbufs++;
+	}
+
+	dev_dbg(dev, "get buffer list %p, %u buffers\n", bl, bl->nbufs);
+
+	return 0;
+}
+
+void
+ipu6_isys_buf_to_fw_frame_buf_pin(struct vb2_buffer *vb,
+				  struct ipu6_fw_isys_frame_buff_set_abi *set)
+{
+	struct ipu6_isys_queue *aq = vb2_queue_to_isys_queue(vb->vb2_queue);
+
+	set->output_pins[aq->fw_output].addr =
+		vb2_dma_contig_plane_dma_addr(vb, 0);
+	set->output_pins[aq->fw_output].out_buf_id = vb->index + 1;
+}
+
+/*
+ * Convert a buffer list to a isys fw ABI framebuffer set. The
+ * buffer list is not modified.
+ */
+#define IPU6_ISYS_FRAME_NUM_THRESHOLD  (30)
+void
+ipu6_isys_buf_to_fw_frame_buf(struct ipu6_fw_isys_frame_buff_set_abi *set,
+			      struct ipu6_isys_stream *stream,
+			      struct ipu6_isys_buffer_list *bl)
+{
+	struct ipu6_isys_buffer *ib;
+
+	WARN_ON(!bl->nbufs);
+
+	set->send_irq_sof = 1;
+	set->send_resp_sof = 1;
+	set->send_irq_eof = 0;
+	set->send_resp_eof = 0;
+
+	if (stream->streaming)
+		set->send_irq_capture_ack = 0;
+	else
+		set->send_irq_capture_ack = 1;
+	set->send_irq_capture_done = 0;
+
+	set->send_resp_capture_ack = 1;
+	set->send_resp_capture_done = 1;
+	if (atomic_read(&stream->sequence) >= IPU6_ISYS_FRAME_NUM_THRESHOLD) {
+		set->send_resp_capture_ack = 0;
+		set->send_resp_capture_done = 0;
+	}
+
+	list_for_each_entry(ib, &bl->head, head) {
+		struct vb2_buffer *vb = ipu6_isys_buffer_to_vb2_buffer(ib);
+		struct ipu6_isys_queue *aq =
+			vb2_queue_to_isys_queue(vb->vb2_queue);
+
+		if (WARN_ON_ONCE(ib->type != IPU6_ISYS_VIDEO_BUFFER))
+			continue;
+
+		if (aq->fill_frame_buf_set)
+			aq->fill_frame_buf_set(vb, set);
+	}
+}
+
+/* Start streaming for real. The buffer list must be available. */
+static int ipu6_isys_stream_start(struct ipu6_isys_video *av,
+				  struct ipu6_isys_buffer_list *bl, bool error)
+{
+	struct ipu6_isys_stream *stream = av->stream;
+	struct device *dev = &stream->isys->adev->auxdev.dev;
+	struct ipu6_isys_buffer_list __bl;
+	int ret;
+
+	mutex_lock(&stream->isys->stream_mutex);
+	ret = ipu6_isys_video_set_streaming(av, 1, bl);
+	mutex_unlock(&stream->isys->stream_mutex);
+	if (ret)
+		goto out_requeue;
+
+	stream->streaming = 1;
+
+	bl = &__bl;
+
+	do {
+		struct ipu6_fw_isys_frame_buff_set_abi *buf = NULL;
+		struct isys_fw_msgs *msg;
+		u16 send_type = IPU6_FW_ISYS_SEND_TYPE_STREAM_CAPTURE;
+
+		ret = buffer_list_get(stream, bl);
+		if (ret < 0)
+			break;
+
+		msg = ipu6_get_fw_msg_buf(stream);
+		if (!msg)
+			return -ENOMEM;
+
+		buf = &msg->fw_msg.frame;
+		ipu6_isys_buf_to_fw_frame_buf(buf, stream, bl);
+		ipu6_fw_isys_dump_frame_buff_set(dev, buf,
+						 stream->nr_output_pins);
+		ipu6_isys_buffer_list_queue(bl, IPU6_ISYS_BUFFER_LIST_FL_ACTIVE,
+					    0);
+
+		ret = ipu6_fw_isys_complex_cmd(stream->isys,
+					       stream->stream_handle, buf,
+					       msg->dma_addr, sizeof(*buf),
+					       send_type);
+	} while (!WARN_ON(ret));
+
+	return 0;
+
+out_requeue:
+	if (bl && bl->nbufs)
+		ipu6_isys_buffer_list_queue(bl,
+					    (IPU6_ISYS_BUFFER_LIST_FL_INCOMING |
+					     error) ?
+					    IPU6_ISYS_BUFFER_LIST_FL_SET_STATE :
+					    0, error ? VB2_BUF_STATE_ERROR :
+					    VB2_BUF_STATE_QUEUED);
+	flush_firmware_streamon_fail(stream);
+
+	return ret;
+}
+
+static void buf_queue(struct vb2_buffer *vb)
+{
+	struct ipu6_isys_queue *aq = vb2_queue_to_isys_queue(vb->vb2_queue);
+	struct ipu6_isys_video *av = ipu6_isys_queue_to_video(aq);
+	struct ipu6_isys_buffer *ib = vb2_buffer_to_ipu6_isys_buffer(vb);
+	struct device *dev = &av->isys->adev->auxdev.dev;
+	struct media_pipeline *media_pipe =
+		media_entity_pipeline(&av->vdev.entity);
+	struct ipu6_fw_isys_frame_buff_set_abi *buf = NULL;
+	struct ipu6_isys_stream *stream = av->stream;
+	struct ipu6_isys_buffer_list bl;
+	struct isys_fw_msgs *msg;
+	unsigned long flags;
+	dma_addr_t dma;
+	unsigned int i;
+	int ret;
+
+	dev_dbg(dev, "queue buffer %u for %s\n", vb->index, av->vdev.name);
+
+	for (i = 0; i < vb->num_planes; i++) {
+		dma = vb2_dma_contig_plane_dma_addr(vb, i);
+		dev_dbg(dev, "iova: plane %u iova %pad\n", i, &dma);
+	}
+
+	spin_lock_irqsave(&aq->lock, flags);
+	list_add(&ib->head, &aq->incoming);
+	spin_unlock_irqrestore(&aq->lock, flags);
+
+	if (!media_pipe || !vb->vb2_queue->start_streaming_called) {
+		dev_dbg(dev, "media pipeline is not ready for %s\n",
+			av->vdev.name);
+		return;
+	}
+
+	mutex_lock(&stream->mutex);
+
+	if (stream->nr_streaming != stream->nr_queues) {
+		dev_dbg(dev, "not streaming yet, adding to incoming\n");
+		goto out;
+	}
+
+	/*
+	 * We just put one buffer to the incoming list of this queue
+	 * (above). Let's see whether all queues in the pipeline would
+	 * have a buffer.
+	 */
+	ret = buffer_list_get(stream, &bl);
+	if (ret < 0) {
+		dev_warn(dev, "No buffers available\n");
+		goto out;
+	}
+
+	msg = ipu6_get_fw_msg_buf(stream);
+	if (!msg) {
+		ret = -ENOMEM;
+		goto out;
+	}
+
+	buf = &msg->fw_msg.frame;
+
+	ipu6_isys_buf_to_fw_frame_buf(buf, stream, &bl);
+
+	ipu6_fw_isys_dump_frame_buff_set(dev, buf, stream->nr_output_pins);
+
+	if (!stream->streaming) {
+		ret = ipu6_isys_stream_start(av, &bl, true);
+		if (ret)
+			dev_err(dev, "stream start failed.\n");
+		goto out;
+	}
+
+	/*
+	 * We must queue the buffers in the buffer list to the
+	 * appropriate video buffer queues BEFORE passing them to the
+	 * firmware since we could get a buffer event back before we
+	 * have queued them ourselves to the active queue.
+	 */
+	ipu6_isys_buffer_list_queue(&bl, IPU6_ISYS_BUFFER_LIST_FL_ACTIVE, 0);
+
+	ret = ipu6_fw_isys_complex_cmd(stream->isys, stream->stream_handle,
+				       buf, msg->dma_addr, sizeof(*buf),
+				       IPU6_FW_ISYS_SEND_TYPE_STREAM_CAPTURE);
+	if (ret < 0)
+		dev_err(dev, "send stream capture failed\n");
+
+out:
+	mutex_unlock(&stream->mutex);
+}
+
+int ipu6_isys_link_fmt_validate(struct ipu6_isys_queue *aq)
+{
+	struct v4l2_mbus_framefmt format;
+	struct ipu6_isys_video *av = ipu6_isys_queue_to_video(aq);
+	struct device *dev = &av->isys->adev->auxdev.dev;
+	struct media_pad *remote_pad =
+		media_pad_remote_pad_first(av->vdev.entity.pads);
+	struct v4l2_subdev *sd;
+	u32 r_stream;
+	int ret;
+
+	if (!remote_pad)
+		return -ENOTCONN;
+
+	sd = media_entity_to_v4l2_subdev(remote_pad->entity);
+	r_stream = ipu6_isys_get_src_stream_by_src_pad(sd, remote_pad->index);
+
+	ret = ipu6_isys_get_stream_pad_fmt(sd, remote_pad->index, r_stream,
+					   &format);
+
+	if (ret) {
+		dev_dbg(dev, "failed to get %s: pad %d, stream:%d format\n",
+			sd->entity.name, remote_pad->index, r_stream);
+		return ret;
+	}
+
+	if (format.width != av->mpix.width ||
+	    format.height != av->mpix.height) {
+		dev_dbg(dev, "wrong width or height %ux%u (%ux%u expected)\n",
+			av->mpix.width, av->mpix.height,
+			format.width, format.height);
+		return -EINVAL;
+	}
+
+	if (format.field != av->mpix.field) {
+		dev_dbg(dev, "wrong field value 0x%8.8x (0x%8.8x expected)\n",
+			av->mpix.field, format.field);
+		return -EINVAL;
+	}
+
+	if (format.code != av->pfmt->code) {
+		dev_dbg(dev, "wrong mbus code 0x%8.8x (0x%8.8x expected)\n",
+			av->pfmt->code, format.code);
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static void return_buffers(struct ipu6_isys_queue *aq,
+			   enum vb2_buffer_state state)
+{
+	struct ipu6_isys_video *av = ipu6_isys_queue_to_video(aq);
+	struct device *dev = &av->isys->adev->auxdev.dev;
+	struct ipu6_isys_buffer *ib;
+	bool need_reset = false;
+	unsigned long flags;
+
+	spin_lock_irqsave(&aq->lock, flags);
+	while (!list_empty(&aq->incoming)) {
+		struct vb2_buffer *vb;
+
+		ib = list_first_entry(&aq->incoming, struct ipu6_isys_buffer,
+				      head);
+		vb = ipu6_isys_buffer_to_vb2_buffer(ib);
+		list_del(&ib->head);
+		spin_unlock_irqrestore(&aq->lock, flags);
+
+		vb2_buffer_done(vb, state);
+
+		dev_dbg(dev, "%s: stop_streaming incoming %u\n",
+			ipu6_isys_queue_to_video(vb2_queue_to_isys_queue
+						 (vb->vb2_queue))->vdev.name,
+			vb->index);
+
+		spin_lock_irqsave(&aq->lock, flags);
+	}
+
+	/*
+	 * Something went wrong (FW crash / HW hang / not all buffers
+	 * returned from isys) if there are still buffers queued in active
+	 * queue. We have to clean up places a bit.
+	 */
+	while (!list_empty(&aq->active)) {
+		struct vb2_buffer *vb;
+
+		ib = list_first_entry(&aq->active, struct ipu6_isys_buffer,
+				      head);
+		vb = ipu6_isys_buffer_to_vb2_buffer(ib);
+
+		list_del(&ib->head);
+		spin_unlock_irqrestore(&aq->lock, flags);
+
+		vb2_buffer_done(vb, state);
+
+		dev_warn(dev, "%s: cleaning active queue %u\n",
+			 ipu6_isys_queue_to_video(vb2_queue_to_isys_queue
+						  (vb->vb2_queue))->vdev.name,
+			 vb->index);
+
+		spin_lock_irqsave(&aq->lock, flags);
+		need_reset = true;
+	}
+
+	spin_unlock_irqrestore(&aq->lock, flags);
+
+	if (need_reset) {
+		mutex_lock(&av->isys->mutex);
+		av->isys->need_reset = true;
+		mutex_unlock(&av->isys->mutex);
+	}
+}
+
+static void ipu6_isys_stream_cleanup(struct ipu6_isys_video *av)
+{
+	video_device_pipeline_stop(&av->vdev);
+	ipu6_isys_put_stream(av->stream);
+	av->stream = NULL;
+}
+
+static int start_streaming(struct vb2_queue *q, unsigned int count)
+{
+	struct ipu6_isys_queue *aq = vb2_queue_to_isys_queue(q);
+	struct ipu6_isys_video *av = ipu6_isys_queue_to_video(aq);
+	struct device *dev = &av->isys->adev->auxdev.dev;
+	struct ipu6_isys_buffer_list __bl, *bl = NULL;
+	struct ipu6_isys_stream *stream;
+	struct media_entity *source_entity = NULL;
+	int nr_queues, ret;
+
+	dev_dbg(dev, "stream: %s: width %u, height %u, css pixelformat %u\n",
+		av->vdev.name, av->mpix.width, av->mpix.height,
+		av->pfmt->css_pixelformat);
+
+	ret = ipu6_isys_setup_video(av, &source_entity, &nr_queues);
+	if (ret < 0) {
+		dev_err(dev, "failed to setup video\n");
+		goto out_return_buffers;
+	}
+
+	ret = aq->link_fmt_validate(aq);
+	if (ret) {
+		dev_err(dev,
+			"%s: link format validation failed (%d)\n",
+			av->vdev.name, ret);
+		goto out_pipeline_stop;
+	}
+
+	ret = ipu6_isys_fw_open(av->isys);
+	if (ret)
+		goto out_pipeline_stop;
+
+	stream = av->stream;
+	mutex_lock(&stream->mutex);
+	if (!stream->nr_streaming) {
+		ret = ipu6_isys_video_prepare_stream(av, source_entity,
+						     nr_queues);
+		if (ret)
+			goto out_fw_close;
+	}
+
+	stream->nr_streaming++;
+	dev_dbg(dev, "queue %u of %u\n", stream->nr_streaming,
+		stream->nr_queues);
+	list_add(&aq->node, &stream->queues);
+
+	ipu6_isys_set_csi2_streams_status(av, true);
+
+	ipu6_isys_configure_stream_watermark(av, true);
+	ipu6_isys_update_stream_watermark(av, true);
+
+	if (stream->nr_streaming != stream->nr_queues)
+		goto out;
+
+	bl = &__bl;
+	ret = buffer_list_get(stream, bl);
+	if (ret < 0) {
+		dev_dbg(dev,
+			"no buffer available, postponing streamon\n");
+		goto out;
+	}
+
+	ret = ipu6_isys_stream_start(av, bl, false);
+	if (ret)
+		goto out_stream_start;
+
+out:
+	mutex_unlock(&stream->mutex);
+
+	return 0;
+
+out_stream_start:
+	list_del(&aq->node);
+	stream->nr_streaming--;
+
+out_fw_close:
+	mutex_unlock(&stream->mutex);
+	ipu6_isys_fw_close(av->isys);
+
+out_pipeline_stop:
+	ipu6_isys_stream_cleanup(av);
+
+out_return_buffers:
+	return_buffers(aq, VB2_BUF_STATE_QUEUED);
+
+	return ret;
+}
+
+static void stop_streaming(struct vb2_queue *q)
+{
+	struct ipu6_isys_queue *aq = vb2_queue_to_isys_queue(q);
+	struct ipu6_isys_video *av = ipu6_isys_queue_to_video(aq);
+	struct ipu6_isys_stream *stream = av->stream;
+
+	ipu6_isys_set_csi2_streams_status(av, false);
+
+	mutex_lock(&stream->mutex);
+
+	ipu6_isys_update_stream_watermark(av, false);
+
+	mutex_lock(&av->isys->stream_mutex);
+	if (stream->nr_streaming == stream->nr_queues && stream->streaming)
+		ipu6_isys_video_set_streaming(av, 0, NULL);
+	mutex_unlock(&av->isys->stream_mutex);
+
+	stream->nr_streaming--;
+	list_del(&aq->node);
+	stream->streaming = 0;
+	mutex_unlock(&stream->mutex);
+
+	ipu6_isys_stream_cleanup(av);
+
+	return_buffers(aq, VB2_BUF_STATE_ERROR);
+
+	ipu6_isys_fw_close(av->isys);
+}
+
+static unsigned int
+get_sof_sequence_by_timestamp(struct ipu6_isys_stream *stream,
+			      struct ipu6_fw_isys_resp_info_abi *info)
+{
+	u64 time = (u64)info->timestamp[1] << 32 | info->timestamp[0];
+	struct ipu6_isys *isys = stream->isys;
+	struct device *dev = &isys->adev->auxdev.dev;
+	unsigned int i;
+
+	/*
+	 * The timestamp is invalid as no TSC in some FPGA platform,
+	 * so get the sequence from pipeline directly in this case.
+	 */
+	if (time == 0)
+		return atomic_read(&stream->sequence) - 1;
+
+	for (i = 0; i < IPU6_ISYS_MAX_PARALLEL_SOF; i++)
+		if (time == stream->seq[i].timestamp) {
+			dev_dbg(dev, "sof: using seq nr %u for ts %llu\n",
+				stream->seq[i].sequence, time);
+			return stream->seq[i].sequence;
+		}
+
+	for (i = 0; i < IPU6_ISYS_MAX_PARALLEL_SOF; i++)
+		dev_dbg(dev, "sof: sequence %u, timestamp value %llu\n",
+			stream->seq[i].sequence, stream->seq[i].timestamp);
+
+	return 0;
+}
+
+static u64 get_sof_ns_delta(struct ipu6_isys_video *av,
+			    struct ipu6_fw_isys_resp_info_abi *info)
+{
+	struct ipu6_bus_device *adev = av->isys->adev;
+	struct ipu6_device *isp = adev->isp;
+	u64 delta, tsc_now;
+
+	ipu6_buttress_tsc_read(isp, &tsc_now);
+	if (!tsc_now)
+		return 0;
+
+	delta = tsc_now - ((u64)info->timestamp[1] << 32 | info->timestamp[0]);
+
+	return ipu6_buttress_tsc_ticks_to_ns(delta, isp);
+}
+
+void ipu6_isys_buf_calc_sequence_time(struct ipu6_isys_buffer *ib,
+				      struct ipu6_fw_isys_resp_info_abi *info)
+{
+	struct vb2_buffer *vb = ipu6_isys_buffer_to_vb2_buffer(ib);
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
+	struct ipu6_isys_queue *aq = vb2_queue_to_isys_queue(vb->vb2_queue);
+	struct ipu6_isys_video *av = ipu6_isys_queue_to_video(aq);
+	struct device *dev = &av->isys->adev->auxdev.dev;
+	struct ipu6_isys_stream *stream = av->stream;
+	u64 ns;
+	u32 sequence;
+
+	ns = ktime_get_ns() - get_sof_ns_delta(av, info);
+	sequence = get_sof_sequence_by_timestamp(stream, info);
+
+	vbuf->vb2_buf.timestamp = ns;
+	vbuf->sequence = sequence;
+
+	dev_dbg(dev, "buf: %s: buffer done, CPU-timestamp:%lld, sequence:%d\n",
+		av->vdev.name, ktime_get_ns(), sequence);
+	dev_dbg(dev, "index:%d, vbuf timestamp:%lld\n", vb->index,
+		vbuf->vb2_buf.timestamp);
+}
+
+void ipu6_isys_queue_buf_done(struct ipu6_isys_buffer *ib)
+{
+	struct vb2_buffer *vb = ipu6_isys_buffer_to_vb2_buffer(ib);
+
+	if (atomic_read(&ib->str2mmio_flag)) {
+		vb2_buffer_done(vb, VB2_BUF_STATE_ERROR);
+		/*
+		 * Operation on buffer is ended with error and will be reported
+		 * to the userspace when it is de-queued
+		 */
+		atomic_set(&ib->str2mmio_flag, 0);
+	} else {
+		vb2_buffer_done(vb, VB2_BUF_STATE_DONE);
+	}
+}
+
+void ipu6_isys_queue_buf_ready(struct ipu6_isys_stream *stream,
+			       struct ipu6_fw_isys_resp_info_abi *info)
+{
+	struct ipu6_isys_queue *aq = stream->output_pins[info->pin_id].aq;
+	struct ipu6_isys *isys = stream->isys;
+	struct device *dev = &isys->adev->auxdev.dev;
+	struct ipu6_isys_buffer *ib;
+	struct vb2_buffer *vb;
+	unsigned long flags;
+	bool first = true;
+	struct vb2_v4l2_buffer *buf;
+
+	dev_dbg(dev, "buffer: %s: received buffer %8.8x\n",
+		ipu6_isys_queue_to_video(aq)->vdev.name, info->pin.addr);
+
+	spin_lock_irqsave(&aq->lock, flags);
+	if (list_empty(&aq->active)) {
+		spin_unlock_irqrestore(&aq->lock, flags);
+		dev_err(dev, "active queue empty\n");
+		return;
+	}
+
+	list_for_each_entry_reverse(ib, &aq->active, head) {
+		dma_addr_t addr;
+
+		vb = ipu6_isys_buffer_to_vb2_buffer(ib);
+		addr = vb2_dma_contig_plane_dma_addr(vb, 0);
+
+		if (info->pin.addr != addr) {
+			if (first)
+				dev_err(dev, "Unexpected buffer address %pad\n",
+					&addr);
+			first = false;
+			continue;
+		}
+
+		if (info->error_info.error ==
+		    IPU6_FW_ISYS_ERROR_HW_REPORTED_STR2MMIO) {
+			/*
+			 * Check for error message:
+			 * 'IPU6_FW_ISYS_ERROR_HW_REPORTED_STR2MMIO'
+			 */
+			atomic_set(&ib->str2mmio_flag, 1);
+		}
+		dev_dbg(dev, "buffer: found buffer %pad\n", &addr);
+
+		buf = to_vb2_v4l2_buffer(vb);
+		buf->field = V4L2_FIELD_NONE;
+
+		list_del(&ib->head);
+		spin_unlock_irqrestore(&aq->lock, flags);
+
+		ipu6_isys_buf_calc_sequence_time(ib, info);
+
+		ipu6_isys_queue_buf_done(ib);
+
+		return;
+	}
+
+	dev_err(dev, "Failed to find a matching video buffer");
+
+	spin_unlock_irqrestore(&aq->lock, flags);
+}
+
+static const struct vb2_ops ipu6_isys_queue_ops = {
+	.queue_setup = queue_setup,
+	.wait_prepare = vb2_ops_wait_prepare,
+	.wait_finish = vb2_ops_wait_finish,
+	.buf_prepare = buf_prepare,
+	.start_streaming = start_streaming,
+	.stop_streaming = stop_streaming,
+	.buf_queue = buf_queue,
+};
+
+int ipu6_isys_queue_init(struct ipu6_isys_queue *aq)
+{
+	struct ipu6_isys *isys = ipu6_isys_queue_to_video(aq)->isys;
+	struct ipu6_isys_video *av = ipu6_isys_queue_to_video(aq);
+	int ret;
+
+	/* no support for userptr */
+	if (!aq->vbq.io_modes)
+		aq->vbq.io_modes = VB2_MMAP | VB2_DMABUF;
+
+	aq->vbq.drv_priv = aq;
+	aq->vbq.ops = &ipu6_isys_queue_ops;
+	aq->vbq.lock = &av->mutex;
+	aq->vbq.mem_ops = &vb2_dma_contig_memops;
+	aq->vbq.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
+	aq->vbq.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
+
+	ret = vb2_queue_init(&aq->vbq);
+	if (ret)
+		return ret;
+
+	aq->dev = &isys->adev->auxdev.dev;
+	aq->vbq.dev = &isys->adev->auxdev.dev;
+	spin_lock_init(&aq->lock);
+	INIT_LIST_HEAD(&aq->active);
+	INIT_LIST_HEAD(&aq->incoming);
+
+	return 0;
+}
+
+void ipu6_isys_queue_cleanup(struct ipu6_isys_queue *aq)
+{
+	vb2_queue_release(&aq->vbq);
+}
diff --git a/drivers/media/pci/intel/ipu6/ipu6-isys-queue.h b/drivers/media/pci/intel/ipu6/ipu6-isys-queue.h
new file mode 100644
index 000000000000..bce8ca06cb9f
--- /dev/null
+++ b/drivers/media/pci/intel/ipu6/ipu6-isys-queue.h
@@ -0,0 +1,94 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/* Copyright (C) 2013 - 2023 Intel Corporation */
+
+#ifndef IPU6_ISYS_QUEUE_H
+#define IPU6_ISYS_QUEUE_H
+
+#include <media/videobuf2-v4l2.h>
+
+struct ipu6_isys_video;
+struct ipu6_isys_stream;
+struct ipu6_fw_isys_resp_info_abi;
+struct ipu6_fw_isys_frame_buff_set_abi;
+
+enum ipu6_isys_buffer_type {
+	IPU6_ISYS_VIDEO_BUFFER,
+};
+
+struct ipu6_isys_queue {
+	struct vb2_queue vbq;
+	struct list_head node;
+	struct device *dev;
+	/*
+	 * @lock: serialise access to queued and pre_streamon_queued
+	 */
+	spinlock_t lock;
+	struct list_head active;
+	struct list_head incoming;
+	unsigned int fw_output;
+	int (*buf_prepare)(struct vb2_buffer *vb);
+	void (*fill_frame_buf_set)(struct vb2_buffer *vb,
+				   struct ipu6_fw_isys_frame_buff_set_abi *set);
+	int (*link_fmt_validate)(struct ipu6_isys_queue *aq);
+};
+
+struct ipu6_isys_buffer {
+	struct list_head head;
+	enum ipu6_isys_buffer_type type;
+	atomic_t str2mmio_flag;
+};
+
+struct ipu6_isys_video_buffer {
+	struct vb2_v4l2_buffer vb_v4l2;
+	struct ipu6_isys_buffer ib;
+};
+
+#define IPU6_ISYS_BUFFER_LIST_FL_INCOMING	BIT(0)
+#define IPU6_ISYS_BUFFER_LIST_FL_ACTIVE	BIT(1)
+#define IPU6_ISYS_BUFFER_LIST_FL_SET_STATE	BIT(2)
+
+struct ipu6_isys_buffer_list {
+	struct list_head head;
+	unsigned int nbufs;
+};
+
+#define vb2_queue_to_isys_queue(__vb2) \
+	container_of(__vb2, struct ipu6_isys_queue, vbq)
+
+#define ipu6_isys_to_isys_video_buffer(__ib) \
+	container_of(__ib, struct ipu6_isys_video_buffer, ib)
+
+#define vb2_buffer_to_ipu6_isys_video_buffer(__vb) \
+	container_of(to_vb2_v4l2_buffer(__vb), \
+	struct ipu6_isys_video_buffer, vb_v4l2)
+
+#define ipu6_isys_buffer_to_vb2_buffer(__ib) \
+	(&ipu6_isys_to_isys_video_buffer(__ib)->vb_v4l2.vb2_buf)
+
+#define vb2_buffer_to_ipu6_isys_buffer(__vb) \
+	(&vb2_buffer_to_ipu6_isys_video_buffer(__vb)->ib)
+
+int ipu6_isys_buf_prepare(struct vb2_buffer *vb);
+
+void ipu6_isys_buffer_list_queue(struct ipu6_isys_buffer_list *bl,
+				 unsigned long op_flags,
+				 enum vb2_buffer_state state);
+void
+ipu6_isys_buf_to_fw_frame_buf_pin(struct vb2_buffer *vb,
+				  struct ipu6_fw_isys_frame_buff_set_abi *set);
+void
+ipu6_isys_buf_to_fw_frame_buf(struct ipu6_fw_isys_frame_buff_set_abi *set,
+			      struct ipu6_isys_stream *stream,
+			      struct ipu6_isys_buffer_list *bl);
+int ipu6_isys_link_fmt_validate(struct ipu6_isys_queue *aq);
+
+void
+ipu6_isys_buf_calc_sequence_time(struct ipu6_isys_buffer *ib,
+				 struct ipu6_fw_isys_resp_info_abi *info);
+void ipu6_isys_queue_buf_done(struct ipu6_isys_buffer *ib);
+void ipu6_isys_queue_buf_ready(struct ipu6_isys_stream *stream,
+			       struct ipu6_fw_isys_resp_info_abi *info);
+int ipu6_isys_queue_init(struct ipu6_isys_queue *aq);
+void ipu6_isys_queue_cleanup(struct ipu6_isys_queue *aq);
+
+#endif /* IPU6_ISYS_QUEUE_H */
diff --git a/drivers/media/pci/intel/ipu6/ipu6-isys-video.c b/drivers/media/pci/intel/ipu6/ipu6-isys-video.c
new file mode 100644
index 000000000000..f81934a301b4
--- /dev/null
+++ b/drivers/media/pci/intel/ipu6/ipu6-isys-video.c
@@ -0,0 +1,1239 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2013 - 2023 Intel Corporation
+ */
+
+#include <linux/delay.h>
+#include <linux/firmware.h>
+#include <linux/pm_runtime.h>
+
+#include <media/v4l2-device.h>
+#include <media/v4l2-ioctl.h>
+#include <media/v4l2-mc.h>
+
+#include "ipu6-bus.h"
+#include "ipu6-cpd.h"
+#include "ipu6-fw-com.h"
+#include "ipu6-isys.h"
+#include "ipu6-platform-buttress-regs.h"
+#include "ipu6-platform-isys-csi2-reg.h"
+#include "ipu6-platform-regs.h"
+
+const struct ipu6_isys_pixelformat ipu6_isys_pfmts[] = {
+	{V4L2_PIX_FMT_SBGGR12, 16, 12, MEDIA_BUS_FMT_SBGGR12_1X12,
+	 IPU6_FW_ISYS_FRAME_FORMAT_RAW16},
+	{V4L2_PIX_FMT_SGBRG12, 16, 12, MEDIA_BUS_FMT_SGBRG12_1X12,
+	 IPU6_FW_ISYS_FRAME_FORMAT_RAW16},
+	{V4L2_PIX_FMT_SGRBG12, 16, 12, MEDIA_BUS_FMT_SGRBG12_1X12,
+	 IPU6_FW_ISYS_FRAME_FORMAT_RAW16},
+	{V4L2_PIX_FMT_SRGGB12, 16, 12, MEDIA_BUS_FMT_SRGGB12_1X12,
+	 IPU6_FW_ISYS_FRAME_FORMAT_RAW16},
+	{V4L2_PIX_FMT_SBGGR10, 16, 10, MEDIA_BUS_FMT_SBGGR10_1X10,
+	 IPU6_FW_ISYS_FRAME_FORMAT_RAW16},
+	{V4L2_PIX_FMT_SGBRG10, 16, 10, MEDIA_BUS_FMT_SGBRG10_1X10,
+	 IPU6_FW_ISYS_FRAME_FORMAT_RAW16},
+	{V4L2_PIX_FMT_SGRBG10, 16, 10, MEDIA_BUS_FMT_SGRBG10_1X10,
+	 IPU6_FW_ISYS_FRAME_FORMAT_RAW16},
+	{V4L2_PIX_FMT_SRGGB10, 16, 10, MEDIA_BUS_FMT_SRGGB10_1X10,
+	 IPU6_FW_ISYS_FRAME_FORMAT_RAW16},
+	{V4L2_PIX_FMT_SBGGR8, 8, 8, MEDIA_BUS_FMT_SBGGR8_1X8,
+	 IPU6_FW_ISYS_FRAME_FORMAT_RAW8},
+	{V4L2_PIX_FMT_SGBRG8, 8, 8, MEDIA_BUS_FMT_SGBRG8_1X8,
+	 IPU6_FW_ISYS_FRAME_FORMAT_RAW8},
+	{V4L2_PIX_FMT_SGRBG8, 8, 8, MEDIA_BUS_FMT_SGRBG8_1X8,
+	 IPU6_FW_ISYS_FRAME_FORMAT_RAW8},
+	{V4L2_PIX_FMT_SRGGB8, 8, 8, MEDIA_BUS_FMT_SRGGB8_1X8,
+	 IPU6_FW_ISYS_FRAME_FORMAT_RAW8},
+	{V4L2_PIX_FMT_SBGGR12P, 12, 12, MEDIA_BUS_FMT_SBGGR12_1X12,
+	 IPU6_FW_ISYS_FRAME_FORMAT_RAW12},
+	{V4L2_PIX_FMT_SGBRG12P, 12, 12, MEDIA_BUS_FMT_SGBRG12_1X12,
+	 IPU6_FW_ISYS_FRAME_FORMAT_RAW12},
+	{V4L2_PIX_FMT_SGRBG12P, 12, 12, MEDIA_BUS_FMT_SGRBG12_1X12,
+	 IPU6_FW_ISYS_FRAME_FORMAT_RAW12},
+	{V4L2_PIX_FMT_SRGGB12P, 12, 12, MEDIA_BUS_FMT_SRGGB12_1X12,
+	 IPU6_FW_ISYS_FRAME_FORMAT_RAW12},
+	{V4L2_PIX_FMT_SBGGR10P, 10, 10, MEDIA_BUS_FMT_SBGGR10_1X10,
+	 IPU6_FW_ISYS_FRAME_FORMAT_RAW10},
+	{V4L2_PIX_FMT_SGBRG10P, 10, 10, MEDIA_BUS_FMT_SGBRG10_1X10,
+	 IPU6_FW_ISYS_FRAME_FORMAT_RAW10},
+	{V4L2_PIX_FMT_SGRBG10P, 10, 10, MEDIA_BUS_FMT_SGRBG10_1X10,
+	 IPU6_FW_ISYS_FRAME_FORMAT_RAW10},
+	{V4L2_PIX_FMT_SRGGB10P, 10, 10, MEDIA_BUS_FMT_SRGGB10_1X10,
+	 IPU6_FW_ISYS_FRAME_FORMAT_RAW10},
+	{V4L2_PIX_FMT_UYVY, 16, 16, MEDIA_BUS_FMT_UYVY8_1X16,
+	 IPU6_FW_ISYS_FRAME_FORMAT_UYVY},
+	{V4L2_PIX_FMT_YUYV, 16, 16, MEDIA_BUS_FMT_YUYV8_1X16,
+	 IPU6_FW_ISYS_FRAME_FORMAT_YUYV},
+	{V4L2_PIX_FMT_RGB565, 16, 16, MEDIA_BUS_FMT_RGB565_1X16,
+	 IPU6_FW_ISYS_FRAME_FORMAT_RGB565},
+	{V4L2_PIX_FMT_BGR24, 24, 24, MEDIA_BUS_FMT_RGB888_1X24,
+	 IPU6_FW_ISYS_FRAME_FORMAT_RGBA888},
+};
+
+static int video_open(struct file *file)
+{
+	struct ipu6_isys_video *av = video_drvdata(file);
+	struct ipu6_isys *isys = av->isys;
+	struct ipu6_bus_device *adev = isys->adev;
+
+	mutex_lock(&isys->mutex);
+	if (isys->need_reset) {
+		mutex_unlock(&isys->mutex);
+		dev_warn(&adev->auxdev.dev, "isys power cycle required\n");
+		return -EIO;
+	}
+	mutex_unlock(&isys->mutex);
+
+	return v4l2_fh_open(file);
+}
+
+static int video_release(struct file *file)
+{
+	return vb2_fop_release(file);
+}
+
+static const struct ipu6_isys_pixelformat *
+ipu6_isys_get_pixelformat(u32 pixelformat)
+{
+	unsigned int i;
+
+	for (i = 0; i < ARRAY_SIZE(ipu6_isys_pfmts); i++) {
+		const struct ipu6_isys_pixelformat *pfmt = &ipu6_isys_pfmts[i];
+
+		if (pfmt->pixelformat == pixelformat)
+			return pfmt;
+	}
+
+	return &ipu6_isys_pfmts[0];
+}
+
+int ipu6_isys_vidioc_querycap(struct file *file, void *fh,
+			      struct v4l2_capability *cap)
+{
+	struct ipu6_isys_video *av = video_drvdata(file);
+
+	strscpy(cap->driver, IPU6_ISYS_NAME, sizeof(cap->driver));
+	strscpy(cap->card, av->isys->media_dev.model, sizeof(cap->card));
+
+	return 0;
+}
+
+int ipu6_isys_vidioc_enum_fmt(struct file *file, void *fh,
+			      struct v4l2_fmtdesc *f)
+{
+	unsigned int i, found = 0;
+
+	if (f->index >= ARRAY_SIZE(ipu6_isys_pfmts))
+		return -EINVAL;
+
+	if (!f->mbus_code) {
+		f->flags = 0;
+		f->pixelformat = ipu6_isys_pfmts[f->index].pixelformat;
+		f->mbus_code = ipu6_isys_pfmts[f->index].code;
+		return 0;
+	}
+
+	for (i = 0; i < ARRAY_SIZE(ipu6_isys_pfmts); i++) {
+		if (f->mbus_code != ipu6_isys_pfmts[i].code)
+			continue;
+
+		if (f->index == found) {
+			f->flags = 0;
+			f->pixelformat = ipu6_isys_pfmts[i].pixelformat;
+			return 0;
+		}
+		found++;
+	}
+
+	return -EINVAL;
+}
+
+static int ipu6_isys_vidioc_enum_framesizes(struct file *file, void *fh,
+					    struct v4l2_frmsizeenum *fsize)
+{
+	if (fsize->index > 0)
+		return -EINVAL;
+
+	fsize->type = V4L2_FRMSIZE_TYPE_CONTINUOUS;
+	fsize->stepwise.min_width = IPU6_ISYS_MIN_WIDTH;
+	fsize->stepwise.max_width = IPU6_ISYS_MAX_WIDTH;
+	fsize->stepwise.min_height = IPU6_ISYS_MIN_HEIGHT;
+	fsize->stepwise.max_height = IPU6_ISYS_MAX_HEIGHT;
+	fsize->stepwise.step_width = 2;
+	fsize->stepwise.step_height = 2;
+
+	return 0;
+}
+
+static int vidioc_g_fmt_vid_cap_mplane(struct file *file, void *fh,
+				       struct v4l2_format *fmt)
+{
+	struct ipu6_isys_video *av = video_drvdata(file);
+
+	fmt->fmt.pix_mp = av->mpix;
+
+	return 0;
+}
+
+static const struct ipu6_isys_pixelformat *
+ipu6_isys_video_try_fmt_vid_mplane(struct ipu6_isys_video *av,
+				   struct v4l2_pix_format_mplane *mpix)
+{
+	const struct ipu6_isys_pixelformat *pfmt =
+		ipu6_isys_get_pixelformat(mpix->pixelformat);
+
+	mpix->pixelformat = pfmt->pixelformat;
+	mpix->num_planes = 1;
+
+	mpix->width = clamp(mpix->width, IPU6_ISYS_MIN_WIDTH,
+			    IPU6_ISYS_MAX_WIDTH);
+	mpix->height = clamp(mpix->height, IPU6_ISYS_MIN_HEIGHT,
+			     IPU6_ISYS_MAX_HEIGHT);
+
+	if (pfmt->bpp != pfmt->bpp_packed)
+		mpix->plane_fmt[0].bytesperline =
+			mpix->width * DIV_ROUND_UP(pfmt->bpp, BITS_PER_BYTE);
+	else
+		mpix->plane_fmt[0].bytesperline =
+			DIV_ROUND_UP((unsigned int)mpix->width * pfmt->bpp,
+				     BITS_PER_BYTE);
+
+	mpix->plane_fmt[0].bytesperline = ALIGN(mpix->plane_fmt[0].bytesperline,
+						av->isys->line_align);
+
+	/*
+	 * (height + 1) * bytesperline due to a hardware issue: the DMA unit
+	 * is a power of two, and a line should be transferred as few units
+	 * as possible. The result is that up to line length more data than
+	 * the image size may be transferred to memory after the image.
+	 * Another limitation is the GDA allocation unit size. For low
+	 * resolution it gives a bigger number. Use larger one to avoid
+	 * memory corruption.
+	 */
+	mpix->plane_fmt[0].sizeimage =
+		max(max(mpix->plane_fmt[0].sizeimage,
+			mpix->plane_fmt[0].bytesperline * mpix->height +
+			max(mpix->plane_fmt[0].bytesperline,
+			    av->isys->pdata->ipdata->isys_dma_overshoot)), 1U);
+
+	memset(mpix->plane_fmt[0].reserved, 0,
+	       sizeof(mpix->plane_fmt[0].reserved));
+
+	mpix->field = V4L2_FIELD_NONE;
+
+	mpix->colorspace = V4L2_COLORSPACE_RAW;
+	mpix->ycbcr_enc = V4L2_YCBCR_ENC_DEFAULT;
+	mpix->quantization = V4L2_QUANTIZATION_DEFAULT;
+	mpix->xfer_func = V4L2_XFER_FUNC_DEFAULT;
+
+	return pfmt;
+}
+
+static int vidioc_s_fmt_vid_cap_mplane(struct file *file, void *fh,
+				       struct v4l2_format *f)
+{
+	struct ipu6_isys_video *av = video_drvdata(file);
+
+	if (av->aq.vbq.streaming)
+		return -EBUSY;
+
+	av->pfmt = ipu6_isys_video_try_fmt_vid_mplane(av, &f->fmt.pix_mp);
+	av->mpix = f->fmt.pix_mp;
+
+	return 0;
+}
+
+static int vidioc_try_fmt_vid_cap_mplane(struct file *file, void *fh,
+					 struct v4l2_format *f)
+{
+	struct ipu6_isys_video *av = video_drvdata(file);
+
+	ipu6_isys_video_try_fmt_vid_mplane(av, &f->fmt.pix_mp);
+
+	return 0;
+}
+
+static int link_validate(struct media_link *link)
+{
+	struct ipu6_isys_video *av =
+		container_of(link->sink, struct ipu6_isys_video, pad);
+	struct device *dev = &av->isys->adev->auxdev.dev;
+	struct v4l2_subdev_state *s_state;
+	struct v4l2_subdev *s_sd;
+	struct v4l2_mbus_framefmt *s_fmt;
+	struct media_pad *s_pad;
+	u32 s_stream;
+	int ret = -EPIPE;
+
+	if (!link->source->entity)
+		return ret;
+
+	s_sd = media_entity_to_v4l2_subdev(link->source->entity);
+	s_state = v4l2_subdev_get_unlocked_active_state(s_sd);
+	if (!s_state)
+		return ret;
+
+	dev_dbg(dev, "validating link \"%s\":%u -> \"%s\"\n",
+		link->source->entity->name, link->source->index,
+		link->sink->entity->name);
+
+	s_pad = media_pad_remote_pad_first(&av->pad);
+	s_stream = ipu6_isys_get_src_stream_by_src_pad(s_sd, s_pad->index);
+
+	v4l2_subdev_lock_state(s_state);
+
+	s_fmt = v4l2_subdev_state_get_stream_format(s_state, s_pad->index,
+						    s_stream);
+	if (!s_fmt) {
+		dev_err(dev, "failed to get source pad format\n");
+		goto unlock;
+	}
+
+	if (s_fmt->width != av->mpix.width ||
+	    s_fmt->height != av->mpix.height || s_fmt->code != av->pfmt->code) {
+		dev_err(dev, "format mismatch %dx%d,%x != %dx%d,%x\n",
+			s_fmt->width, s_fmt->height, s_fmt->code,
+			av->mpix.width, av->mpix.height, av->pfmt->code);
+		goto unlock;
+	}
+
+	v4l2_subdev_unlock_state(s_state);
+
+	return 0;
+unlock:
+	v4l2_subdev_unlock_state(s_state);
+
+	return ret;
+}
+
+static void get_stream_opened(struct ipu6_isys_video *av)
+{
+	unsigned long flags;
+
+	spin_lock_irqsave(&av->isys->streams_lock, flags);
+	av->isys->stream_opened++;
+	spin_unlock_irqrestore(&av->isys->streams_lock, flags);
+}
+
+static void put_stream_opened(struct ipu6_isys_video *av)
+{
+	unsigned long flags;
+
+	spin_lock_irqsave(&av->isys->streams_lock, flags);
+	av->isys->stream_opened--;
+	spin_unlock_irqrestore(&av->isys->streams_lock, flags);
+}
+
+static int ipu6_isys_fw_pin_cfg(struct ipu6_isys_video *av,
+				struct ipu6_fw_isys_stream_cfg_data_abi *cfg)
+{
+	struct media_pad *src_pad = media_pad_remote_pad_first(&av->pad);
+	struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(src_pad->entity);
+	struct ipu6_fw_isys_input_pin_info_abi *input_pin;
+	struct ipu6_fw_isys_output_pin_info_abi *output_pin;
+	struct ipu6_isys_stream *stream = av->stream;
+	struct ipu6_isys_queue *aq = &av->aq;
+	struct v4l2_mbus_framefmt fmt;
+	struct v4l2_rect v4l2_crop;
+	struct ipu6_isys *isys = av->isys;
+	struct device *dev = &isys->adev->auxdev.dev;
+	int input_pins = cfg->nof_input_pins++;
+	int output_pins;
+	u32 src_stream;
+	int ret;
+
+	src_stream = ipu6_isys_get_src_stream_by_src_pad(sd, src_pad->index);
+	ret = ipu6_isys_get_stream_pad_fmt(sd, src_pad->index, src_stream,
+					   &fmt);
+	if (ret < 0) {
+		dev_err(dev, "can't get stream format (%d)\n", ret);
+		return ret;
+	}
+
+	ret = ipu6_isys_get_stream_pad_crop(sd, src_pad->index, src_stream,
+					    &v4l2_crop);
+	if (ret < 0) {
+		dev_err(dev, "can't get stream crop (%d)\n", ret);
+		return ret;
+	}
+
+	input_pin = &cfg->input_pins[input_pins];
+	input_pin->input_res.width = fmt.width;
+	input_pin->input_res.height = fmt.height;
+	input_pin->dt = av->dt;
+	input_pin->bits_per_pix = av->pfmt->bpp_packed;
+	input_pin->mapped_dt = 0x40; /* invalid mipi data type */
+	input_pin->mipi_decompression = 0;
+	input_pin->capture_mode = IPU6_FW_ISYS_CAPTURE_MODE_REGULAR;
+	input_pin->mipi_store_mode = av->pfmt->bpp == av->pfmt->bpp_packed ?
+		IPU6_FW_ISYS_MIPI_STORE_MODE_DISCARD_LONG_HEADER :
+		IPU6_FW_ISYS_MIPI_STORE_MODE_NORMAL;
+	input_pin->crop_first_and_last_lines = v4l2_crop.top & 1;
+
+	output_pins = cfg->nof_output_pins++;
+	aq->fw_output = output_pins;
+	stream->output_pins[output_pins].pin_ready = ipu6_isys_queue_buf_ready;
+	stream->output_pins[output_pins].aq = aq;
+
+	output_pin = &cfg->output_pins[output_pins];
+	output_pin->input_pin_id = input_pins;
+	output_pin->output_res.width = av->mpix.width;
+	output_pin->output_res.height = av->mpix.height;
+
+	output_pin->stride = av->mpix.plane_fmt[0].bytesperline;
+	if (av->pfmt->bpp != av->pfmt->bpp_packed)
+		output_pin->pt = IPU6_FW_ISYS_PIN_TYPE_RAW_SOC;
+	else
+		output_pin->pt = IPU6_FW_ISYS_PIN_TYPE_MIPI;
+	output_pin->ft = av->pfmt->css_pixelformat;
+	output_pin->send_irq = 1;
+	memset(output_pin->ts_offsets, 0, sizeof(output_pin->ts_offsets));
+	output_pin->s2m_pixel_soc_pixel_remapping =
+		S2M_PIXEL_SOC_PIXEL_REMAPPING_FLAG_NO_REMAPPING;
+	output_pin->csi_be_soc_pixel_remapping =
+		CSI_BE_SOC_PIXEL_REMAPPING_FLAG_NO_REMAPPING;
+
+	output_pin->snoopable = true;
+	output_pin->error_handling_enable = false;
+	output_pin->sensor_type = isys->sensor_type++;
+	if (isys->sensor_type > isys->pdata->ipdata->sensor_type_end)
+		isys->sensor_type = isys->pdata->ipdata->sensor_type_start;
+
+	return 0;
+}
+
+static int start_stream_firmware(struct ipu6_isys_video *av,
+				 struct ipu6_isys_buffer_list *bl)
+{
+	struct ipu6_fw_isys_stream_cfg_data_abi *stream_cfg;
+	struct ipu6_fw_isys_frame_buff_set_abi *buf = NULL;
+	struct ipu6_isys_stream *stream = av->stream;
+	struct device *dev = &av->isys->adev->auxdev.dev;
+	struct isys_fw_msgs *msg = NULL;
+	struct ipu6_isys_queue *aq;
+	int ret, retout, tout;
+	u16 send_type;
+
+	msg = ipu6_get_fw_msg_buf(stream);
+	if (!msg)
+		return -ENOMEM;
+
+	stream_cfg = &msg->fw_msg.stream;
+	stream_cfg->src = stream->stream_source;
+	stream_cfg->vc = stream->vc;
+	stream_cfg->isl_use = 0;
+	stream_cfg->sensor_type = IPU6_FW_ISYS_SENSOR_MODE_NORMAL;
+
+	list_for_each_entry(aq, &stream->queues, node) {
+		struct ipu6_isys_video *__av = ipu6_isys_queue_to_video(aq);
+
+		ret = ipu6_isys_fw_pin_cfg(__av, stream_cfg);
+		if (ret < 0) {
+			ipu6_put_fw_msg_buf(av->isys, (u64)stream_cfg);
+			return ret;
+		}
+	}
+
+	ipu6_fw_isys_dump_stream_cfg(dev, stream_cfg);
+
+	stream->nr_output_pins = stream_cfg->nof_output_pins;
+
+	reinit_completion(&stream->stream_open_completion);
+
+	ret = ipu6_fw_isys_complex_cmd(av->isys, stream->stream_handle,
+				       stream_cfg, msg->dma_addr,
+				       sizeof(*stream_cfg),
+				       IPU6_FW_ISYS_SEND_TYPE_STREAM_OPEN);
+	if (ret < 0) {
+		dev_err(dev, "can't open stream (%d)\n", ret);
+		ipu6_put_fw_msg_buf(av->isys, (u64)stream_cfg);
+		return ret;
+	}
+
+	get_stream_opened(av);
+
+	tout = wait_for_completion_timeout(&stream->stream_open_completion,
+					   IPU6_FW_CALL_TIMEOUT_JIFFIES);
+
+	ipu6_put_fw_msg_buf(av->isys, (u64)stream_cfg);
+
+	if (!tout) {
+		dev_err(dev, "stream open time out\n");
+		ret = -ETIMEDOUT;
+		goto out_put_stream_opened;
+	}
+	if (stream->error) {
+		dev_err(dev, "stream open error: %d\n", stream->error);
+		ret = -EIO;
+		goto out_put_stream_opened;
+	}
+	dev_dbg(dev, "start stream: open complete\n");
+
+	if (bl) {
+		msg = ipu6_get_fw_msg_buf(stream);
+		if (!msg) {
+			ret = -ENOMEM;
+			goto out_put_stream_opened;
+		}
+		buf = &msg->fw_msg.frame;
+		ipu6_isys_buf_to_fw_frame_buf(buf, stream, bl);
+		ipu6_isys_buffer_list_queue(bl,
+					    IPU6_ISYS_BUFFER_LIST_FL_ACTIVE, 0);
+	}
+
+	reinit_completion(&stream->stream_start_completion);
+
+	if (bl) {
+		send_type = IPU6_FW_ISYS_SEND_TYPE_STREAM_START_AND_CAPTURE;
+		ipu6_fw_isys_dump_frame_buff_set(dev, buf,
+						 stream_cfg->nof_output_pins);
+		ret = ipu6_fw_isys_complex_cmd(av->isys, stream->stream_handle,
+					       buf, msg->dma_addr,
+					       sizeof(*buf), send_type);
+	} else {
+		send_type = IPU6_FW_ISYS_SEND_TYPE_STREAM_START;
+		ret = ipu6_fw_isys_simple_cmd(av->isys, stream->stream_handle,
+					      send_type);
+	}
+
+	if (ret < 0) {
+		dev_err(dev, "can't start streaming (%d)\n", ret);
+		goto out_stream_close;
+	}
+
+	tout = wait_for_completion_timeout(&stream->stream_start_completion,
+					   IPU6_FW_CALL_TIMEOUT_JIFFIES);
+	if (!tout) {
+		dev_err(dev, "stream start time out\n");
+		ret = -ETIMEDOUT;
+		goto out_stream_close;
+	}
+	if (stream->error) {
+		dev_err(dev, "stream start error: %d\n", stream->error);
+		ret = -EIO;
+		goto out_stream_close;
+	}
+	dev_dbg(dev, "start stream: complete\n");
+
+	return 0;
+
+out_stream_close:
+	reinit_completion(&stream->stream_close_completion);
+
+	retout = ipu6_fw_isys_simple_cmd(av->isys,
+					 stream->stream_handle,
+					 IPU6_FW_ISYS_SEND_TYPE_STREAM_CLOSE);
+	if (retout < 0) {
+		dev_dbg(dev, "can't close stream (%d)\n", retout);
+		goto out_put_stream_opened;
+	}
+
+	tout = wait_for_completion_timeout(&stream->stream_close_completion,
+					   IPU6_FW_CALL_TIMEOUT_JIFFIES);
+	if (!tout)
+		dev_err(dev, "stream close time out\n");
+	else if (stream->error)
+		dev_err(dev, "stream close error: %d\n", stream->error);
+	else
+		dev_dbg(dev, "stream close complete\n");
+
+out_put_stream_opened:
+	put_stream_opened(av);
+
+	return ret;
+}
+
+static void stop_streaming_firmware(struct ipu6_isys_video *av)
+{
+	struct device *dev = &av->isys->adev->auxdev.dev;
+	struct ipu6_isys_stream *stream = av->stream;
+	int ret, tout;
+
+	reinit_completion(&stream->stream_stop_completion);
+
+	ret = ipu6_fw_isys_simple_cmd(av->isys, stream->stream_handle,
+				      IPU6_FW_ISYS_SEND_TYPE_STREAM_FLUSH);
+
+	if (ret < 0) {
+		dev_err(dev, "can't stop stream (%d)\n", ret);
+		return;
+	}
+
+	tout = wait_for_completion_timeout(&stream->stream_stop_completion,
+					   IPU6_FW_CALL_TIMEOUT_JIFFIES);
+	if (!tout)
+		dev_warn(dev, "stream stop time out\n");
+	else if (stream->error)
+		dev_warn(dev, "stream stop error: %d\n", stream->error);
+	else
+		dev_dbg(dev, "stop stream: complete\n");
+}
+
+static void close_streaming_firmware(struct ipu6_isys_video *av)
+{
+	struct ipu6_isys_stream *stream = av->stream;
+	struct device *dev = &av->isys->adev->auxdev.dev;
+	int ret, tout;
+
+	reinit_completion(&stream->stream_close_completion);
+
+	ret = ipu6_fw_isys_simple_cmd(av->isys, stream->stream_handle,
+				      IPU6_FW_ISYS_SEND_TYPE_STREAM_CLOSE);
+	if (ret < 0) {
+		dev_err(dev, "can't close stream (%d)\n", ret);
+		return;
+	}
+
+	tout = wait_for_completion_timeout(&stream->stream_close_completion,
+					   IPU6_FW_CALL_TIMEOUT_JIFFIES);
+	if (!tout)
+		dev_warn(dev, "stream close time out\n");
+	else if (stream->error)
+		dev_warn(dev, "stream close error: %d\n", stream->error);
+	else
+		dev_dbg(dev, "close stream: complete\n");
+
+	put_stream_opened(av);
+}
+
+int ipu6_isys_video_prepare_stream(struct ipu6_isys_video *av,
+				   struct media_entity *source_entity,
+				   int nr_queues)
+{
+	struct ipu6_isys_stream *stream = av->stream;
+	struct ipu6_isys_csi2 *csi2;
+
+	if (WARN_ON(stream->nr_streaming))
+		return -EINVAL;
+
+	stream->nr_queues = nr_queues;
+	atomic_set(&stream->sequence, 0);
+
+	stream->seq_index = 0;
+	memset(stream->seq, 0, sizeof(stream->seq));
+
+	if (WARN_ON(!list_empty(&stream->queues)))
+		return -EINVAL;
+
+	stream->stream_source = stream->asd->source;
+	csi2 = ipu6_isys_subdev_to_csi2(stream->asd);
+	csi2->receiver_errors = 0;
+	stream->source_entity = source_entity;
+
+	dev_dbg(&av->isys->adev->auxdev.dev,
+		"prepare stream: external entity %s\n",
+		stream->source_entity->name);
+
+	return 0;
+}
+
+void ipu6_isys_configure_stream_watermark(struct ipu6_isys_video *av,
+					  bool state)
+{
+	struct ipu6_isys *isys = av->isys;
+	struct ipu6_isys_csi2 *csi2 = NULL;
+	struct isys_iwake_watermark *iwake_watermark = &isys->iwake_watermark;
+	struct device *dev = &isys->adev->auxdev.dev;
+	struct v4l2_mbus_framefmt format;
+	struct v4l2_subdev *esd;
+	struct v4l2_control hb = { .id = V4L2_CID_HBLANK, .value = 0 };
+	unsigned int bpp, lanes;
+	s64 link_freq = 0;
+	u64 pixel_rate = 0;
+	int ret;
+
+	if (!state)
+		return;
+
+	esd = media_entity_to_v4l2_subdev(av->stream->source_entity);
+
+	av->watermark.width = av->mpix.width;
+	av->watermark.height = av->mpix.height;
+	av->watermark.sram_gran_shift = isys->pdata->ipdata->sram_gran_shift;
+	av->watermark.sram_gran_size = isys->pdata->ipdata->sram_gran_size;
+
+	ret = v4l2_g_ctrl(esd->ctrl_handler, &hb);
+	if (!ret && hb.value >= 0)
+		av->watermark.hblank = hb.value;
+	else
+		av->watermark.hblank = 0;
+
+	csi2 = ipu6_isys_subdev_to_csi2(av->stream->asd);
+	link_freq = ipu6_isys_csi2_get_link_freq(csi2);
+	if (link_freq > 0) {
+		lanes = csi2->nlanes;
+		ret = ipu6_isys_get_stream_pad_fmt(&csi2->asd.sd, 0,
+						   av->source_stream, &format);
+		if (!ret) {
+			bpp = ipu6_isys_mbus_code_to_bpp(format.code);
+			pixel_rate = mul_u64_u32_div(link_freq, lanes * 2, bpp);
+		}
+	}
+
+	av->watermark.pixel_rate = pixel_rate;
+
+	if (!pixel_rate) {
+		mutex_lock(&iwake_watermark->mutex);
+		iwake_watermark->force_iwake_disable = true;
+		mutex_unlock(&iwake_watermark->mutex);
+		dev_warn(dev, "unexpected pixel_rate from %s, disable iwake.\n",
+			 av->stream->source_entity->name);
+	}
+}
+
+static void calculate_stream_datarate(struct ipu6_isys_video *av)
+{
+	struct video_stream_watermark *watermark = &av->watermark;
+	u32 bpp = av->pfmt->bpp;
+	u32 pages_per_line, pb_bytes_per_line, pixels_per_line, bytes_per_line;
+	u64 line_time_ns, stream_data_rate;
+	u16 shift, size;
+
+	shift = watermark->sram_gran_shift;
+	size = watermark->sram_gran_size;
+
+	pixels_per_line = watermark->width + watermark->hblank;
+	line_time_ns =  div_u64(pixels_per_line * NSEC_PER_SEC,
+				watermark->pixel_rate);
+	bytes_per_line = watermark->width * bpp / 8;
+	pages_per_line = DIV_ROUND_UP(bytes_per_line, size);
+	pb_bytes_per_line = pages_per_line << shift;
+	stream_data_rate = div64_u64(pb_bytes_per_line * 1000, line_time_ns);
+
+	watermark->stream_data_rate = stream_data_rate;
+}
+
+void ipu6_isys_update_stream_watermark(struct ipu6_isys_video *av, bool state)
+{
+	struct isys_iwake_watermark *iwake_watermark =
+		&av->isys->iwake_watermark;
+
+	if (!av->watermark.pixel_rate)
+		return;
+
+	if (state) {
+		calculate_stream_datarate(av);
+		mutex_lock(&iwake_watermark->mutex);
+		list_add(&av->watermark.stream_node,
+			 &iwake_watermark->video_list);
+		mutex_unlock(&iwake_watermark->mutex);
+	} else {
+		av->watermark.stream_data_rate = 0;
+		mutex_lock(&iwake_watermark->mutex);
+		list_del(&av->watermark.stream_node);
+		mutex_unlock(&iwake_watermark->mutex);
+	}
+
+	update_watermark_setting(av->isys);
+}
+
+void ipu6_isys_put_stream(struct ipu6_isys_stream *stream)
+{
+	struct device *dev = &stream->isys->adev->auxdev.dev;
+	unsigned int i;
+	unsigned long flags;
+
+	if (!stream) {
+		dev_err(dev, "no available stream\n");
+		return;
+	}
+
+	spin_lock_irqsave(&stream->isys->streams_lock, flags);
+	for (i = 0; i < IPU6_ISYS_MAX_STREAMS; i++) {
+		if (&stream->isys->streams[i] == stream) {
+			if (stream->isys->streams_ref_count[i] > 0)
+				stream->isys->streams_ref_count[i]--;
+			else
+				dev_warn(dev, "invalid stream %d\n", i);
+
+			break;
+		}
+	}
+	spin_unlock_irqrestore(&stream->isys->streams_lock, flags);
+}
+
+static struct ipu6_isys_stream *
+ipu6_isys_get_stream(struct ipu6_isys_video *av, struct ipu6_isys_subdev *asd)
+{
+	struct ipu6_isys_stream *stream = NULL;
+	struct ipu6_isys *isys = av->isys;
+	unsigned long flags;
+	unsigned int i;
+	u8 vc = av->vc;
+
+	if (!isys)
+		return NULL;
+
+	spin_lock_irqsave(&isys->streams_lock, flags);
+	for (i = 0; i < IPU6_ISYS_MAX_STREAMS; i++) {
+		if (isys->streams_ref_count[i] && isys->streams[i].vc == vc &&
+		    isys->streams[i].asd == asd) {
+			isys->streams_ref_count[i]++;
+			stream = &isys->streams[i];
+			break;
+		}
+	}
+
+	if (!stream) {
+		for (i = 0; i < IPU6_ISYS_MAX_STREAMS; i++) {
+			if (!isys->streams_ref_count[i]) {
+				isys->streams_ref_count[i]++;
+				stream = &isys->streams[i];
+				stream->vc = vc;
+				stream->asd = asd;
+				break;
+			}
+		}
+	}
+	spin_unlock_irqrestore(&isys->streams_lock, flags);
+
+	return stream;
+}
+
+struct ipu6_isys_stream *
+ipu6_isys_query_stream_by_handle(struct ipu6_isys *isys, u8 stream_handle)
+{
+	unsigned long flags;
+	struct ipu6_isys_stream *stream = NULL;
+
+	if (!isys)
+		return NULL;
+
+	if (stream_handle >= IPU6_ISYS_MAX_STREAMS) {
+		dev_err(&isys->adev->auxdev.dev,
+			"stream_handle %d is invalid\n", stream_handle);
+		return NULL;
+	}
+
+	spin_lock_irqsave(&isys->streams_lock, flags);
+	if (isys->streams_ref_count[stream_handle] > 0) {
+		isys->streams_ref_count[stream_handle]++;
+		stream = &isys->streams[stream_handle];
+	}
+	spin_unlock_irqrestore(&isys->streams_lock, flags);
+
+	return stream;
+}
+
+struct ipu6_isys_stream *
+ipu6_isys_query_stream_by_source(struct ipu6_isys *isys, int source, u8 vc)
+{
+	struct ipu6_isys_stream *stream = NULL;
+	unsigned long flags;
+	unsigned int i;
+
+	if (!isys)
+		return NULL;
+
+	if (source < 0) {
+		dev_err(&stream->isys->adev->auxdev.dev,
+			"query stream with invalid port number\n");
+		return NULL;
+	}
+
+	spin_lock_irqsave(&isys->streams_lock, flags);
+	for (i = 0; i < IPU6_ISYS_MAX_STREAMS; i++) {
+		if (!isys->streams_ref_count[i])
+			continue;
+
+		if (isys->streams[i].stream_source == source &&
+		    isys->streams[i].vc == vc) {
+			stream = &isys->streams[i];
+			isys->streams_ref_count[i]++;
+			break;
+		}
+	}
+	spin_unlock_irqrestore(&isys->streams_lock, flags);
+
+	return stream;
+}
+
+static u64 get_stream_mask_by_pipeline(struct ipu6_isys_video *av)
+{
+	struct media_pipeline *pipeline =
+		media_entity_pipeline(&av->vdev.entity);
+	struct media_entity *entity;
+	unsigned int i;
+	u64 stream_mask = 0;
+
+	for (i = 0; i < NR_OF_VIDEO_DEVICE; i++) {
+		entity = &av->isys->av[i].vdev.entity;
+		if (pipeline == media_entity_pipeline(entity))
+			stream_mask |= BIT_ULL(av->isys->av[i].source_stream);
+	}
+
+	return stream_mask;
+}
+
+int ipu6_isys_video_set_streaming(struct ipu6_isys_video *av, int state,
+				  struct ipu6_isys_buffer_list *bl)
+{
+	struct v4l2_subdev_krouting *routing;
+	struct ipu6_isys_stream *stream = av->stream;
+	struct v4l2_subdev_state *subdev_state;
+	struct device *dev = &av->isys->adev->auxdev.dev;
+	struct v4l2_subdev *sd = NULL;
+	struct v4l2_subdev *ssd = NULL;
+	struct media_pad *r_pad;
+	struct media_pad *s_pad = NULL;
+	u32 sink_pad, sink_stream;
+	u64 r_stream;
+	u64 stream_mask = 0;
+	int ret = 0;
+
+	dev_dbg(dev, "set stream: %d\n", state);
+
+	if (WARN(!stream->source_entity, "No source entity for stream\n"))
+		return -ENODEV;
+
+	ssd = media_entity_to_v4l2_subdev(stream->source_entity);
+	sd = &stream->asd->sd;
+	r_pad = media_pad_remote_pad_first(&av->pad);
+	r_stream = ipu6_isys_get_src_stream_by_src_pad(sd, r_pad->index);
+
+	subdev_state = v4l2_subdev_lock_and_get_active_state(sd);
+	routing = &subdev_state->routing;
+	ret = v4l2_subdev_routing_find_opposite_end(routing, r_pad->index,
+						    r_stream, &sink_pad,
+						    &sink_stream);
+	v4l2_subdev_unlock_state(subdev_state);
+	if (ret)
+		return ret;
+
+	s_pad = media_pad_remote_pad_first(&stream->asd->pad[sink_pad]);
+
+	stream_mask = get_stream_mask_by_pipeline(av);
+	if (!state) {
+		stop_streaming_firmware(av);
+
+		/* stop external sub-device now. */
+		dev_dbg(dev, "disable streams 0x%llx of %s\n", stream_mask,
+			ssd->name);
+		ret = v4l2_subdev_disable_streams(ssd, s_pad->index,
+						  stream_mask);
+		if (ret) {
+			dev_err(dev, "disable streams of %s failed with %d\n",
+				ssd->name, ret);
+			return ret;
+		}
+
+		/* stop sub-device which connects with video */
+		dev_dbg(dev, "stream off entity %s pad:%d\n", sd->name,
+			r_pad->index);
+		ret = v4l2_subdev_call(sd, video, s_stream, state);
+		if (ret) {
+			dev_err(dev, "stream off %s failed with %d\n", sd->name,
+				ret);
+			return ret;
+		}
+		close_streaming_firmware(av);
+	} else {
+		ret = start_stream_firmware(av, bl);
+		if (ret) {
+			dev_err(dev, "start stream of firmware failed\n");
+			goto out_clear_stream_watermark;
+		}
+
+		/* start sub-device which connects with video */
+		dev_dbg(dev, "stream on %s pad %d\n", sd->name, r_pad->index);
+		ret = v4l2_subdev_call(sd, video, s_stream, state);
+		if (ret) {
+			dev_err(dev, "stream on %s failed with %d\n", sd->name,
+				ret);
+			goto out_media_entity_stop_streaming_firmware;
+		}
+
+		/* start external sub-device now. */
+		dev_dbg(dev, "enable streams 0x%llx of %s\n", stream_mask,
+			ssd->name);
+		ret = v4l2_subdev_enable_streams(ssd, s_pad->index,
+						 stream_mask);
+		if (ret) {
+			dev_err(dev,
+				"enable streams 0x%llx of %s failed with %d\n",
+				stream_mask, stream->source_entity->name, ret);
+			goto out_media_entity_stop_streaming;
+		}
+	}
+
+	av->streaming = state;
+
+	return 0;
+
+out_media_entity_stop_streaming:
+	v4l2_subdev_disable_streams(sd, r_pad->index, BIT(r_stream));
+
+out_media_entity_stop_streaming_firmware:
+	stop_streaming_firmware(av);
+
+out_clear_stream_watermark:
+	ipu6_isys_update_stream_watermark(av, 0);
+
+	return ret;
+}
+
+static const struct v4l2_ioctl_ops ioctl_ops_mplane = {
+	.vidioc_querycap = ipu6_isys_vidioc_querycap,
+	.vidioc_enum_fmt_vid_cap = ipu6_isys_vidioc_enum_fmt,
+	.vidioc_enum_framesizes = ipu6_isys_vidioc_enum_framesizes,
+	.vidioc_g_fmt_vid_cap_mplane = vidioc_g_fmt_vid_cap_mplane,
+	.vidioc_s_fmt_vid_cap_mplane = vidioc_s_fmt_vid_cap_mplane,
+	.vidioc_try_fmt_vid_cap_mplane = vidioc_try_fmt_vid_cap_mplane,
+	.vidioc_reqbufs = vb2_ioctl_reqbufs,
+	.vidioc_create_bufs = vb2_ioctl_create_bufs,
+	.vidioc_prepare_buf = vb2_ioctl_prepare_buf,
+	.vidioc_querybuf = vb2_ioctl_querybuf,
+	.vidioc_qbuf = vb2_ioctl_qbuf,
+	.vidioc_dqbuf = vb2_ioctl_dqbuf,
+	.vidioc_streamon = vb2_ioctl_streamon,
+	.vidioc_streamoff = vb2_ioctl_streamoff,
+	.vidioc_expbuf = vb2_ioctl_expbuf,
+};
+
+static const struct media_entity_operations entity_ops = {
+	.link_validate = link_validate,
+};
+
+static const struct v4l2_file_operations isys_fops = {
+	.owner = THIS_MODULE,
+	.poll = vb2_fop_poll,
+	.unlocked_ioctl = video_ioctl2,
+	.mmap = vb2_fop_mmap,
+	.open = video_open,
+	.release = video_release,
+};
+
+int ipu6_isys_fw_open(struct ipu6_isys *isys)
+{
+	struct ipu6_bus_device *adev = isys->adev;
+	const struct ipu6_isys_internal_pdata *ipdata = isys->pdata->ipdata;
+	int ret;
+
+	ret = pm_runtime_resume_and_get(&adev->auxdev.dev);
+	if (ret < 0)
+		return ret;
+
+	mutex_lock(&isys->mutex);
+
+	if (isys->ref_count++)
+		goto unlock;
+
+	ipu6_configure_spc(adev->isp, &ipdata->hw_variant,
+			   IPU6_CPD_PKG_DIR_ISYS_SERVER_IDX, isys->pdata->base,
+			   adev->pkg_dir, adev->pkg_dir_dma_addr);
+
+	/*
+	 * Buffers could have been left to wrong queue at last closure.
+	 * Move them now back to empty buffer queue.
+	 */
+	ipu6_cleanup_fw_msg_bufs(isys);
+
+	if (isys->fwcom) {
+		/*
+		 * Something went wrong in previous shutdown. As we are now
+		 * restarting isys we can safely delete old context.
+		 */
+		dev_info(&adev->auxdev.dev, "Clearing old context\n");
+		ipu6_fw_isys_cleanup(isys);
+	}
+
+	ret = ipu6_fw_isys_init(isys, ipdata->num_parallel_streams);
+	if (ret < 0)
+		goto out;
+
+unlock:
+	mutex_unlock(&isys->mutex);
+
+	return 0;
+
+out:
+	isys->ref_count--;
+	mutex_unlock(&isys->mutex);
+	pm_runtime_put(&adev->auxdev.dev);
+
+	return ret;
+}
+
+void ipu6_isys_fw_close(struct ipu6_isys *isys)
+{
+	mutex_lock(&isys->mutex);
+
+	isys->ref_count--;
+	if (!isys->ref_count) {
+		ipu6_fw_isys_close(isys);
+		if (isys->fwcom) {
+			isys->need_reset = true;
+			dev_warn(&isys->adev->auxdev.dev,
+				 "failed to close fw isys\n");
+		}
+	}
+
+	mutex_unlock(&isys->mutex);
+
+	if (isys->need_reset)
+		pm_runtime_put_sync(&isys->adev->auxdev.dev);
+	else
+		pm_runtime_put(&isys->adev->auxdev.dev);
+}
+
+int ipu6_isys_setup_video(struct ipu6_isys_video *av,
+			  struct media_entity **source_entity,
+			  int *nr_queues)
+{
+	struct device *dev = &av->isys->adev->auxdev.dev;
+	struct v4l2_mbus_frame_desc_entry entry;
+	struct v4l2_subdev_route *route = NULL;
+	struct v4l2_subdev_route *r;
+	struct v4l2_subdev_state *state;
+	struct ipu6_isys_subdev *asd;
+	struct v4l2_subdev *remote_sd;
+	struct media_pipeline *pipeline;
+	struct media_pad *source_pad, *remote_pad;
+	int ret = -EINVAL;
+
+	remote_pad = media_pad_remote_pad_first(&av->pad);
+	if (!remote_pad) {
+		dev_dbg(dev, "failed to get remote pad\n");
+		return -ENODEV;
+	}
+
+	remote_sd = media_entity_to_v4l2_subdev(remote_pad->entity);
+	asd = to_ipu6_isys_subdev(remote_sd);
+	source_pad = media_pad_remote_pad_first(&remote_pad->entity->pads[0]);
+	if (!source_pad) {
+		dev_dbg(dev, "No external source entity\n");
+		return -ENODEV;
+	}
+
+	*source_entity = source_pad->entity;
+
+	/* Find the root */
+	state = v4l2_subdev_lock_and_get_active_state(remote_sd);
+	for_each_active_route(&state->routing, r) {
+		if (r->source_pad != remote_pad->index)
+			continue;
+
+		route = r;
+		break;
+	}
+
+	if (!route) {
+		v4l2_subdev_unlock_state(state);
+		dev_dbg(dev, "Failed to find route\n");
+		return -ENODEV;
+	}
+	v4l2_subdev_unlock_state(state);
+	av->source_stream = route->sink_stream;
+
+	ret = ipu6_isys_csi2_get_remote_desc(av->source_stream,
+					     to_ipu6_isys_csi2(remote_sd),
+					     *source_entity, &entry,
+					     nr_queues);
+	if (ret == -ENOIOCTLCMD) {
+		av->vc = 0;
+		av->dt = ipu6_isys_mbus_code_to_mipi(av->pfmt->code);
+		*nr_queues = 1;
+	} else if (!ret) {
+		dev_dbg(dev, "Framedesc: stream %u, len %u, vc %u, dt %#x\n",
+			entry.stream, entry.length, entry.bus.csi2.vc,
+			entry.bus.csi2.dt);
+
+		av->vc = entry.bus.csi2.vc;
+		av->dt = entry.bus.csi2.dt;
+	} else {
+		dev_err(dev, "failed to get remote frame desc\n");
+		return ret;
+	}
+
+	pipeline = media_entity_pipeline(&av->vdev.entity);
+	if (!pipeline)
+		ret = video_device_pipeline_alloc_start(&av->vdev);
+	else
+		ret = video_device_pipeline_start(&av->vdev, pipeline);
+	if (ret < 0) {
+		dev_dbg(dev, "media pipeline start failed\n");
+		return ret;
+	}
+
+	av->stream = ipu6_isys_get_stream(av, asd);
+	if (!av->stream) {
+		video_device_pipeline_stop(&av->vdev);
+		dev_err(dev, "no available stream for firmware\n");
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+/*
+ * Do everything that's needed to initialise things related to video
+ * buffer queue, video node, and the related media entity. The caller
+ * is expected to assign isys field and set the name of the video
+ * device.
+ */
+int ipu6_isys_video_init(struct ipu6_isys_video *av)
+{
+	struct v4l2_format format = {
+		.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE,
+		.fmt.pix_mp = {
+			.width = 1920,
+			.height = 1080,
+		},
+	};
+	int ret;
+
+	mutex_init(&av->mutex);
+	av->vdev.device_caps = V4L2_CAP_STREAMING | V4L2_CAP_IO_MC |
+			       V4L2_CAP_VIDEO_CAPTURE_MPLANE;
+	av->vdev.vfl_dir = VFL_DIR_RX;
+
+	ret = ipu6_isys_queue_init(&av->aq);
+	if (ret)
+		goto out_free_watermark;
+
+	av->pad.flags = MEDIA_PAD_FL_SINK | MEDIA_PAD_FL_MUST_CONNECT;
+	ret = media_entity_pads_init(&av->vdev.entity, 1, &av->pad);
+	if (ret)
+		goto out_ipu6_isys_queue_cleanup;
+
+	av->vdev.entity.ops = &entity_ops;
+	av->vdev.release = video_device_release_empty;
+	av->vdev.fops = &isys_fops;
+	av->vdev.v4l2_dev = &av->isys->v4l2_dev;
+	if (!av->vdev.ioctl_ops)
+		av->vdev.ioctl_ops = &ioctl_ops_mplane;
+	av->vdev.queue = &av->aq.vbq;
+	av->vdev.lock = &av->mutex;
+
+	ipu6_isys_video_try_fmt_vid_mplane(av, &format.fmt.pix_mp);
+	av->mpix = format.fmt.pix_mp;
+
+	set_bit(V4L2_FL_USES_V4L2_FH, &av->vdev.flags);
+	video_set_drvdata(&av->vdev, av);
+
+	ret = video_register_device(&av->vdev, VFL_TYPE_VIDEO, -1);
+	if (ret)
+		goto out_media_entity_cleanup;
+
+	return ret;
+
+out_media_entity_cleanup:
+	video_unregister_device(&av->vdev);
+	media_entity_cleanup(&av->vdev.entity);
+
+out_ipu6_isys_queue_cleanup:
+	ipu6_isys_queue_cleanup(&av->aq);
+
+out_free_watermark:
+	mutex_destroy(&av->mutex);
+
+	return ret;
+}
+
+void ipu6_isys_video_cleanup(struct ipu6_isys_video *av)
+{
+	video_unregister_device(&av->vdev);
+	media_entity_cleanup(&av->vdev.entity);
+	mutex_destroy(&av->mutex);
+	ipu6_isys_queue_cleanup(&av->aq);
+}
diff --git a/drivers/media/pci/intel/ipu6/ipu6-isys-video.h b/drivers/media/pci/intel/ipu6/ipu6-isys-video.h
new file mode 100644
index 000000000000..24255fdb1558
--- /dev/null
+++ b/drivers/media/pci/intel/ipu6/ipu6-isys-video.h
@@ -0,0 +1,129 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/* Copyright (C) 2013 - 2023 Intel Corporation */
+
+#ifndef IPU6_ISYS_VIDEO_H
+#define IPU6_ISYS_VIDEO_H
+
+#include <media/v4l2-device.h>
+#include <media/v4l2-subdev.h>
+
+#include "ipu6-isys-queue.h"
+
+#define IPU6_ISYS_OUTPUT_PINS 11
+#define IPU6_ISYS_MAX_PARALLEL_SOF 2
+#define NR_OF_VIDEO_DEVICE 31
+
+struct ipu6_isys;
+struct ipu6_fw_isys_stream_cfg_data_abi;
+
+struct ipu6_isys_pixelformat {
+	u32 pixelformat;
+	u32 bpp;
+	u32 bpp_packed;
+	u32 code;
+	u32 css_pixelformat;
+};
+
+struct sequence_info {
+	unsigned int sequence;
+	u64 timestamp;
+};
+
+struct output_pin_data {
+	void (*pin_ready)(struct ipu6_isys_stream *stream,
+			  struct ipu6_fw_isys_resp_info_abi *info);
+	struct ipu6_isys_queue *aq;
+};
+
+/*
+ * Align with firmware stream. Each stream represents a CSI virtual channel.
+ * May map to multiple video devices
+ */
+struct ipu6_isys_stream {
+	struct mutex mutex;
+	struct media_entity *source_entity;
+	atomic_t sequence;
+	unsigned int seq_index;
+	struct sequence_info seq[IPU6_ISYS_MAX_PARALLEL_SOF];
+	int stream_source;
+	int stream_handle;
+	unsigned int nr_output_pins;
+	struct ipu6_isys_subdev *asd;
+
+	int nr_queues;	/* Number of capture queues */
+	int nr_streaming;
+	int streaming;	/* Has streaming been really started? */
+	struct list_head queues;
+	struct completion stream_open_completion;
+	struct completion stream_close_completion;
+	struct completion stream_start_completion;
+	struct completion stream_stop_completion;
+	struct ipu6_isys *isys;
+
+	struct output_pin_data output_pins[IPU6_ISYS_OUTPUT_PINS];
+	int error;
+	u8 vc;
+};
+
+struct video_stream_watermark {
+	u32 width;
+	u32 height;
+	u32 hblank;
+	u32 frame_rate;
+	u64 pixel_rate;
+	u64 stream_data_rate;
+	u16 sram_gran_shift;
+	u16 sram_gran_size;
+	struct list_head stream_node;
+};
+
+struct ipu6_isys_video {
+	struct ipu6_isys_queue aq;
+	/* Serialise access to other fields in the struct. */
+	struct mutex mutex;
+	struct media_pad pad;
+	struct video_device vdev;
+	struct v4l2_pix_format_mplane mpix;
+	const struct ipu6_isys_pixelformat *pfmt;
+	struct ipu6_isys *isys;
+	struct ipu6_isys_stream *stream;
+	unsigned int streaming;
+	struct video_stream_watermark watermark;
+	u32 source_stream;
+	u8 vc;
+	u8 dt;
+};
+
+#define ipu6_isys_queue_to_video(__aq) \
+	container_of(__aq, struct ipu6_isys_video, aq)
+
+extern const struct ipu6_isys_pixelformat ipu6_isys_pfmts[];
+extern const struct ipu6_isys_pixelformat ipu6_isys_pfmts_packed[];
+
+int ipu6_isys_vidioc_querycap(struct file *file, void *fh,
+			      struct v4l2_capability *cap);
+
+int ipu6_isys_vidioc_enum_fmt(struct file *file, void *fh,
+			      struct v4l2_fmtdesc *f);
+int ipu6_isys_video_prepare_stream(struct ipu6_isys_video *av,
+				   struct media_entity *source_entity,
+				   int nr_queues);
+int ipu6_isys_video_set_streaming(struct ipu6_isys_video *av, int state,
+				  struct ipu6_isys_buffer_list *bl);
+int ipu6_isys_fw_open(struct ipu6_isys *isys);
+void ipu6_isys_fw_close(struct ipu6_isys *isys);
+int ipu6_isys_setup_video(struct ipu6_isys_video *av,
+			  struct media_entity **source_entity, int *nr_queues);
+int ipu6_isys_video_init(struct ipu6_isys_video *av);
+void ipu6_isys_video_cleanup(struct ipu6_isys_video *av);
+void ipu6_isys_put_stream(struct ipu6_isys_stream *stream);
+struct ipu6_isys_stream *
+ipu6_isys_query_stream_by_handle(struct ipu6_isys *isys, u8 stream_handle);
+struct ipu6_isys_stream *
+ipu6_isys_query_stream_by_source(struct ipu6_isys *isys, int source, u8 vc);
+
+void ipu6_isys_configure_stream_watermark(struct ipu6_isys_video *av,
+					  bool state);
+void ipu6_isys_update_stream_watermark(struct ipu6_isys_video *av, bool state);
+
+#endif /* IPU6_ISYS_VIDEO_H */
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 86+ messages in thread

* [PATCH v2 12/15] media: add Kconfig and Makefile for IPU6
  2023-10-24 11:29 [PATCH v2 00/15] Intel IPU6 and IPU6 input system drivers bingbu.cao
                   ` (10 preceding siblings ...)
  2023-10-24 11:29 ` [PATCH v2 11/15] media: intel/ipu6: input system video capture nodes bingbu.cao
@ 2023-10-24 11:29 ` bingbu.cao
  2023-10-24 13:04   ` Andy Shevchenko
  2023-10-24 11:29 ` [PATCH v2 13/15] MAINTAINERS: add maintainers for Intel IPU6 input system driver bingbu.cao
                   ` (4 subsequent siblings)
  16 siblings, 1 reply; 86+ messages in thread
From: bingbu.cao @ 2023-10-24 11:29 UTC (permalink / raw)
  To: linux-media, sakari.ailus, laurent.pinchart
  Cc: andriy.shevchenko, hdegoede, ilpo.jarvinen, andreaskleist,
	claus.stovgaard, tfiga, senozhatsky, tomi.valkeinen, bingbu.cao,
	bingbu.cao, tian.shu.qiu, hongju.wang

From: Bingbu Cao <bingbu.cao@intel.com>

Add IPU6 support in Kconfig and Makefile, with this patch you can
build the Intel IPU6 and input system modules by select the
CONFIG_VIDEO_INTEL_IPU6 in config.

Signed-off-by: Bingbu Cao <bingbu.cao@intel.com>
Signed-off-by: Andreas Helbech Kleist <andreaskleist@gmail.com>
---
 drivers/media/pci/intel/Kconfig       |  1 +
 drivers/media/pci/intel/Makefile      |  1 +
 drivers/media/pci/intel/ipu6/Kconfig  | 17 +++++++++++++++++
 drivers/media/pci/intel/ipu6/Makefile | 23 +++++++++++++++++++++++
 4 files changed, 42 insertions(+)
 create mode 100644 drivers/media/pci/intel/ipu6/Kconfig
 create mode 100644 drivers/media/pci/intel/ipu6/Makefile

diff --git a/drivers/media/pci/intel/Kconfig b/drivers/media/pci/intel/Kconfig
index ee4684159d3d..04cb3d253486 100644
--- a/drivers/media/pci/intel/Kconfig
+++ b/drivers/media/pci/intel/Kconfig
@@ -1,6 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0-only
 
 source "drivers/media/pci/intel/ipu3/Kconfig"
+source "drivers/media/pci/intel/ipu6/Kconfig"
 source "drivers/media/pci/intel/ivsc/Kconfig"
 
 config IPU_BRIDGE
diff --git a/drivers/media/pci/intel/Makefile b/drivers/media/pci/intel/Makefile
index f199a97e1d78..3a2cc6567159 100644
--- a/drivers/media/pci/intel/Makefile
+++ b/drivers/media/pci/intel/Makefile
@@ -5,3 +5,4 @@
 obj-$(CONFIG_IPU_BRIDGE) += ipu-bridge.o
 obj-y	+= ipu3/
 obj-y	+= ivsc/
+obj-$(CONFIG_VIDEO_INTEL_IPU6)	+= ipu6/
diff --git a/drivers/media/pci/intel/ipu6/Kconfig b/drivers/media/pci/intel/ipu6/Kconfig
new file mode 100644
index 000000000000..5cb4f3c2d59f
--- /dev/null
+++ b/drivers/media/pci/intel/ipu6/Kconfig
@@ -0,0 +1,17 @@
+config VIDEO_INTEL_IPU6
+	tristate "Intel IPU6 driver"
+	depends on ACPI || COMPILE_TEST
+	depends on MEDIA_SUPPORT
+	depends on MEDIA_PCI_SUPPORT
+	depends on X86 && X86_64
+	select IOMMU_IOVA
+	select VIDEO_V4L2_SUBDEV_API
+	select VIDEOBUF2_DMA_CONTIG
+	select V4L2_FWNODE
+	select IPU_BRIDGE
+	help
+	  This is the 6th Gen Intel Image Processing Unit, found in Intel SoCs
+	  and used for capturing images and video from camera sensors.
+
+	  To compile this driver, say Y here! It contains 2 modules -
+	  intel_ipu6 and intel_ipu6_isys.
diff --git a/drivers/media/pci/intel/ipu6/Makefile b/drivers/media/pci/intel/ipu6/Makefile
new file mode 100644
index 000000000000..6a6339c84ef4
--- /dev/null
+++ b/drivers/media/pci/intel/ipu6/Makefile
@@ -0,0 +1,23 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+intel-ipu6-objs				+= ipu6.o \
+					ipu6-bus.o \
+					ipu6-dma.o \
+					ipu6-mmu.o \
+					ipu6-buttress.o \
+					ipu6-cpd.o \
+					ipu6-fw-com.o
+
+obj-$(CONFIG_VIDEO_INTEL_IPU6)		+= intel-ipu6.o
+
+intel-ipu6-isys-objs			+= ipu6-isys.o \
+					ipu6-isys-csi2.o \
+					ipu6-fw-isys.o \
+					ipu6-isys-video.o \
+					ipu6-isys-queue.o \
+					ipu6-isys-subdev.o \
+					ipu6-isys-mcd-phy.o \
+					ipu6-isys-jsl-phy.o \
+					ipu6-isys-dwc-phy.o
+
+obj-$(CONFIG_VIDEO_INTEL_IPU6)		+= intel-ipu6-isys.o
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 86+ messages in thread

* [PATCH v2 13/15] MAINTAINERS: add maintainers for Intel IPU6 input system driver
  2023-10-24 11:29 [PATCH v2 00/15] Intel IPU6 and IPU6 input system drivers bingbu.cao
                   ` (11 preceding siblings ...)
  2023-10-24 11:29 ` [PATCH v2 12/15] media: add Kconfig and Makefile for IPU6 bingbu.cao
@ 2023-10-24 11:29 ` bingbu.cao
  2023-10-24 11:29 ` [PATCH v2 14/15] Documentation: add Intel IPU6 ISYS driver admin-guide doc bingbu.cao
                   ` (3 subsequent siblings)
  16 siblings, 0 replies; 86+ messages in thread
From: bingbu.cao @ 2023-10-24 11:29 UTC (permalink / raw)
  To: linux-media, sakari.ailus, laurent.pinchart
  Cc: andriy.shevchenko, hdegoede, ilpo.jarvinen, andreaskleist,
	claus.stovgaard, tfiga, senozhatsky, tomi.valkeinen, bingbu.cao,
	bingbu.cao, tian.shu.qiu, hongju.wang

From: Bingbu Cao <bingbu.cao@intel.com>

Update MAINTAINERS file for Intel IPU6 input system driver.

Signed-off-by: Bingbu Cao <bingbu.cao@intel.com>
---
 MAINTAINERS | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 2894f0777537..b4b0626d43d5 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -10626,6 +10626,16 @@ F:	Documentation/admin-guide/media/ipu3_rcb.svg
 F:	Documentation/userspace-api/media/v4l/metafmt-intel-ipu3.rst
 F:	drivers/staging/media/ipu3/
 
+INTEL IPU6 INPUT SYSTEM DRIVER
+M:	Sakari Ailus <sakari.ailus@linux.intel.com>
+M:	Bingbu Cao <bingbu.cao@intel.com>
+R:	Tianshu Qiu <tian.shu.qiu@intel.com>
+L:	linux-media@vger.kernel.org
+S:	Maintained
+T:	git git://linuxtv.org/media_tree.git
+F:	Documentation/admin-guide/media/ipu6-isys.rst
+F:	drivers/media/pci/intel/ipu6/
+
 INTEL ISHTP ECLITE DRIVER
 M:	Sumesh K Naduvalath <sumesh.k.naduvalath@intel.com>
 L:	platform-driver-x86@vger.kernel.org
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 86+ messages in thread

* [PATCH v2 14/15] Documentation: add Intel IPU6 ISYS driver admin-guide doc
  2023-10-24 11:29 [PATCH v2 00/15] Intel IPU6 and IPU6 input system drivers bingbu.cao
                   ` (12 preceding siblings ...)
  2023-10-24 11:29 ` [PATCH v2 13/15] MAINTAINERS: add maintainers for Intel IPU6 input system driver bingbu.cao
@ 2023-10-24 11:29 ` bingbu.cao
  2023-10-25 12:15   ` Sakari Ailus
  2023-10-24 11:29 ` [PATCH v2 15/15] Documentation: add documentation of Intel IPU6 driver and hardware overview bingbu.cao
                   ` (2 subsequent siblings)
  16 siblings, 1 reply; 86+ messages in thread
From: bingbu.cao @ 2023-10-24 11:29 UTC (permalink / raw)
  To: linux-media, sakari.ailus, laurent.pinchart
  Cc: andriy.shevchenko, hdegoede, ilpo.jarvinen, andreaskleist,
	claus.stovgaard, tfiga, senozhatsky, tomi.valkeinen, bingbu.cao,
	bingbu.cao, tian.shu.qiu, hongju.wang

From: Bingbu Cao <bingbu.cao@intel.com>

This document mainly describe the functionality of IPU6 and
IPU6 isys driver, and gives an example that how user can do
imaging capture with tools.

Signed-off-by: Bingbu Cao <bingbu.cao@intel.com>
---
 Documentation/admin-guide/media/ipu6-isys.rst |  159 +++
 .../admin-guide/media/ipu6_isys_graph.svg     |  338 +++++
 .../admin-guide/media/ipu6_isys_multi.svg     | 1124 +++++++++++++++++
 .../admin-guide/media/v4l-drivers.rst         |    1 +
 4 files changed, 1622 insertions(+)
 create mode 100644 Documentation/admin-guide/media/ipu6-isys.rst
 create mode 100644 Documentation/admin-guide/media/ipu6_isys_graph.svg
 create mode 100644 Documentation/admin-guide/media/ipu6_isys_multi.svg

diff --git a/Documentation/admin-guide/media/ipu6-isys.rst b/Documentation/admin-guide/media/ipu6-isys.rst
new file mode 100644
index 000000000000..fb4d355e1522
--- /dev/null
+++ b/Documentation/admin-guide/media/ipu6-isys.rst
@@ -0,0 +1,159 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+.. include:: <isonum.txt>
+
+===============================================================
+Intel Image Processing Unit 6 (IPU6) Input System driver
+===============================================================
+
+Copyright |copy| 2023 Intel Corporation
+
+Introduction
+============
+
+This file documents the Intel IPU6 (6th generation Image Processing Unit)
+Input System (MIPI CSI2 receiver) drivers located under
+drivers/media/pci/intel/ipu6.
+
+The Intel IPU6 can be found in certain Intel Chipsets but not in all SKUs:
+
+* TigerLake
+* JasperLake
+* AlderLake
+* RaptorLake
+* MeteorLake
+
+Intel IPU6 is made up of two components - Input System (ISYS) and Processing
+System (PSYS).
+
+The Input System mainly works as MIPI CSI2 receiver which receives and
+processes the imaging data from the sensors and outputs the frames to memory.
+
+There are 2 driver modules - intel_ipu6 and intel_ipu6_isys. intel_ipu6 is an
+IPU6 common driver which does PCI configuration, firmware loading and parsing,
+firmware authentication, DMA mapping and IPU-MMU (internal Memory mapping Unit)
+configuration. intel_ipu6_isys implements V4L2, Media Controller and V4L2
+sub-device interfaces. The IPU6 ISYS driver supports camera sensors connected
+to the IPU6 ISYS through V4L2 sub-device sensor drivers.
+
+.. Note:: See Documentation/driver-api/media/drivers/ipu6.rst for more
+	  information about the IPU6 hardware.
+
+
+Input system driver
+===================
+
+The input System driver mainly configures CSI2 DPHY, constructs the firmware
+stream configuration, sends commands to firmware, gets response from hardware
+and firmware and then returns buffers to user.
+The ISYS is represented as several V4L2 sub-devices - 'Intel IPU6 CSI2 $port',
+which provide V4L2 subdev interfaces to the user space, there are also several
+video nodes for each CSI-2 stream capture - 'Intel IPU6 ISYS capture $num' which
+provide interface to user to set formats, queue buffers and streaming.
+
+.. kernel-figure::  ipu6_isys_graph.svg
+   :alt: ipu6 isys media graph without multiple streams support
+
+   ipu6 isys media graph without multiple streams support
+
+.. kernel-figure::  ipu6_isys_multi.svg
+   :alt: ipu6 isys media graph with multiple streams support
+
+   ipu6 isys media graph with multiple streams support
+
+Capturing frames by IPU6 ISYS
+------------------------------------
+
+IPU6 ISYS is used to capture frames from the camera sensors connected to the
+CSI2 ports. The supported input formats of ISYS are listed in table below:
+
+.. tabularcolumns:: |p{0.8cm}|p{4.0cm}|p{4.0cm}|
+
+.. flat-table::
+    :header-rows: 1
+
+    * - IPU6 ISYS supported input formats
+
+    * - RGB565, RGB888
+
+    * - UYVY8, YUYV8
+
+    * - RAW8, RAW10, RAW12
+
+Here is an example of IPU6 ISYS raw capture on Dell XPS 9315 laptop. On this
+machine, ov01a10 sensor is connected to IPU ISYS CSI2 port 2, which can
+generate images at sBGGR10 with resolution 1280x800.
+
+Using the media controller APIs, we can configure ov01a10 sensor by
+media-ctl [#f1]_ and yavta [#f2]_ to transmit frames to IPU6 ISYS.
+
+.. code-block:: none
+
+    # Example 1 capture frame from ov01a10 camera sensor
+    # This example assumes /dev/media0 as the IPU ISYS media device
+    export MDEV=/dev/media0
+
+    # Establish the link for the media devices using media-ctl
+    media-ctl -d $MDEV -l "\"ov01a10 3-0036\":0 -> \"Intel IPU6 CSI2 2\":0[1]"
+
+    # Set the format for the media devices
+    media-ctl -d $MDEV -V "ov01a10:0 [fmt:SBGGR10/1280x800]"
+    media-ctl -d $MDEV -V "Intel IPU6 CSI2 2:0 [fmt:SBGGR10/1280x800]"
+    media-ctl -d $MDEV -V "Intel IPU6 CSI2 2:1 [fmt:SBGGR10/1280x800]"
+
+Once the media pipeline is configured, desired sensor specific settings
+(such as exposure and gain settings) can be set, using the yavta tool.
+
+e.g
+
+.. code-block:: none
+
+    # and that ov01a10 sensor is connected to i2c bus 3 with address 0x36
+    export SDEV=$(media-ctl -d $MDEV -e "ov01a10 3-0036")
+
+    yavta -w 0x009e0903 400 $SDEV
+    yavta -w 0x009e0913 1000 $SDEV
+    yavta -w 0x009e0911 2000 $SDEV
+
+Once the desired sensor settings are set, frame captures can be done as below.
+
+e.g
+
+.. code-block:: none
+
+    yavta --data-prefix -u -c10 -n5 -I -s 1280x800 --file=/tmp/frame-#.bin \
+          -f SBGGR10 $(media-ctl -d $MDEV -e "Intel IPU6 ISYS Capture 0")
+
+With the above command, 10 frames are captured at 1280x800 resolution with
+sBGGR10 format. The captured frames are available as /tmp/frame-#.bin files.
+
+Here is another example of IPU6 ISYS RAW and metadata capture from camera
+sensor ov2740 on Lenovo X1 Yoga laptop.
+
+.. code-block:: none
+
+    media-ctl -l "\"ov2740 14-0036\":0 -> \"Intel IPU6 CSI2 1\":0[1]"
+    media-ctl -l "\"Intel IPU6 CSI2 1\":1 -> \"Intel IPU6 ISYS Capture 0\":0[5]"
+    media-ctl -l "\"Intel IPU6 CSI2 1\":2 -> \"Intel IPU6 ISYS Capture 1\":0[5]"
+
+    # set routing
+    media-ctl -v -R "\"Intel IPU6 CSI2 1\" [0/0->1/0[1],0/1->2/1[1]]"
+
+    media-ctl -v "\"Intel IPU6 CSI2 1\":0/0 [fmt:SGRBG10/1932x1092]"
+    media-ctl -v "\"Intel IPU6 CSI2 1\":0/1 [fmt:GENERIC_8/97x1]"
+    media-ctl -v "\"Intel IPU6 CSI2 1\":1/0 [fmt:SGRBG10/1932x1092]"
+    media-ctl -v "\"Intel IPU6 CSI2 1\":2/1 [fmt:GENERIC_8/97x1]"
+
+    CAPTURE_DEV=$(media-ctl -e "Intel IPU6 ISYS Capture 0")
+    ./yavta --data-prefix -c100 -n5 -I -s1932x1092 --file=/tmp/frame-#.bin \
+    -f SGRBG10 ${CAPTURE_DEV}
+
+    CAPTURE_META=$(media-ctl -e "Intel IPU6 ISYS Capture 1")
+    ./yavta --data-prefix -c100 -n5 -I -s97x1 -B meta-capture \
+    --file=/tmp/meta-#.bin -f GENERIC_8 ${CAPTURE_META}
+
+References
+==========
+
+.. [#f1] https://git.ideasonboard.org/?p=media-ctl.git;a=summary
+.. [#f2] https://git.ideasonboard.org/yavta.git
diff --git a/Documentation/admin-guide/media/ipu6_isys_graph.svg b/Documentation/admin-guide/media/ipu6_isys_graph.svg
new file mode 100644
index 000000000000..661aee18dbe2
--- /dev/null
+++ b/Documentation/admin-guide/media/ipu6_isys_graph.svg
@@ -0,0 +1,338 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
+ "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
+<!-- Generated by graphviz version 2.43.0 (0)
+ -->
+<!-- Title: board Pages: 1 -->
+<svg width="1270pt" height="288pt"
+ viewBox="0.00 0.00 1270.00 288.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
+<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 284)">
+<title>board</title>
+<polygon fill="white" stroke="transparent" points="-4,4 -4,-284 1266,-284 1266,4 -4,4"/>
+<!-- n00000001 -->
+<g id="node1" class="node">
+<title>n00000001</title>
+<polygon fill="yellow" stroke="black" points="842.5,-38 639.5,-38 639.5,0 842.5,0 842.5,-38"/>
+<text text-anchor="middle" x="741" y="-22.8" font-family="Times,serif" font-size="14.00">Intel IPU6 ISYS Capture 0</text>
+<text text-anchor="middle" x="741" y="-7.8" font-family="Times,serif" font-size="14.00">/dev/video0</text>
+</g>
+<!-- n00000005 -->
+<g id="node2" class="node">
+<title>n00000005</title>
+<polygon fill="yellow" stroke="black" points="1063.5,-38 860.5,-38 860.5,0 1063.5,0 1063.5,-38"/>
+<text text-anchor="middle" x="962" y="-22.8" font-family="Times,serif" font-size="14.00">Intel IPU6 ISYS Capture 1</text>
+<text text-anchor="middle" x="962" y="-7.8" font-family="Times,serif" font-size="14.00">/dev/video1</text>
+</g>
+<!-- n00000009 -->
+<g id="node3" class="node">
+<title>n00000009</title>
+<polygon fill="yellow" stroke="black" points="400.5,-38 197.5,-38 197.5,0 400.5,0 400.5,-38"/>
+<text text-anchor="middle" x="299" y="-22.8" font-family="Times,serif" font-size="14.00">Intel IPU6 ISYS Capture 2</text>
+<text text-anchor="middle" x="299" y="-7.8" font-family="Times,serif" font-size="14.00">/dev/video2</text>
+</g>
+<!-- n0000000d -->
+<g id="node4" class="node">
+<title>n0000000d</title>
+<polygon fill="yellow" stroke="black" points="621.5,-38 418.5,-38 418.5,0 621.5,0 621.5,-38"/>
+<text text-anchor="middle" x="520" y="-22.8" font-family="Times,serif" font-size="14.00">Intel IPU6 ISYS Capture 3</text>
+<text text-anchor="middle" x="520" y="-7.8" font-family="Times,serif" font-size="14.00">/dev/video3</text>
+</g>
+<!-- n00000011 -->
+<g id="node5" class="node">
+<title>n00000011</title>
+<path fill="green" stroke="black" d="M332,-74.5C332,-74.5 450,-74.5 450,-74.5 456,-74.5 462,-80.5 462,-86.5 462,-86.5 462,-146.5 462,-146.5 462,-152.5 456,-158.5 450,-158.5 450,-158.5 332,-158.5 332,-158.5 326,-158.5 320,-152.5 320,-146.5 320,-146.5 320,-86.5 320,-86.5 320,-80.5 326,-74.5 332,-74.5"/>
+<text text-anchor="middle" x="391" y="-143.3" font-family="Times,serif" font-size="14.00">0</text>
+<polyline fill="none" stroke="black" points="320,-135.5 462,-135.5 "/>
+<text text-anchor="middle" x="391" y="-120.3" font-family="Times,serif" font-size="14.00">Intel IPU6 CSI2 0</text>
+<text text-anchor="middle" x="391" y="-105.3" font-family="Times,serif" font-size="14.00">/dev/v4l&#45;subdev0</text>
+<polyline fill="none" stroke="black" points="320,-97.5 462,-97.5 "/>
+<text text-anchor="middle" x="391" y="-82.3" font-family="Times,serif" font-size="14.00">1</text>
+</g>
+<!-- n00000011&#45;&gt;n00000001 -->
+<g id="edge1" class="edge">
+<title>n00000011:port1&#45;&gt;n00000001</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M463,-85.5C469.23,-85.5 465.79,-77.41 471,-74 484.72,-65.01 561.34,-50.14 629.46,-38.27"/>
+<polygon fill="black" stroke="black" points="630.19,-41.7 639.45,-36.55 629,-34.8 630.19,-41.7"/>
+</g>
+<!-- n00000011&#45;&gt;n00000005 -->
+<g id="edge2" class="edge">
+<title>n00000011:port1&#45;&gt;n00000005</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M463,-85.5C469.23,-85.5 465.62,-77.14 471,-74 541.93,-32.58 752.57,-47.73 850.49,-38.01"/>
+<polygon fill="black" stroke="black" points="850.91,-41.48 860.45,-36.88 850.12,-34.52 850.91,-41.48"/>
+</g>
+<!-- n00000011&#45;&gt;n00000009 -->
+<g id="edge3" class="edge">
+<title>n00000011:port1&#45;&gt;n00000009</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M319,-85.5C314.85,-85.5 309.28,-66.02 305.07,-48.31"/>
+<polygon fill="black" stroke="black" points="308.41,-47.21 302.77,-38.25 301.59,-48.77 308.41,-47.21"/>
+</g>
+<!-- n00000011&#45;&gt;n0000000d -->
+<g id="edge4" class="edge">
+<title>n00000011:port1&#45;&gt;n0000000d</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M463,-85.5C469.23,-85.5 467.12,-78.87 471,-74 478.49,-64.6 487.16,-54.74 495.11,-46.06"/>
+<polygon fill="black" stroke="black" points="497.92,-48.18 502.15,-38.47 492.78,-43.42 497.92,-48.18"/>
+</g>
+<!-- n00000014 -->
+<g id="node6" class="node">
+<title>n00000014</title>
+<path fill="green" stroke="black" d="M492,-74.5C492,-74.5 610,-74.5 610,-74.5 616,-74.5 622,-80.5 622,-86.5 622,-86.5 622,-146.5 622,-146.5 622,-152.5 616,-158.5 610,-158.5 610,-158.5 492,-158.5 492,-158.5 486,-158.5 480,-152.5 480,-146.5 480,-146.5 480,-86.5 480,-86.5 480,-80.5 486,-74.5 492,-74.5"/>
+<text text-anchor="middle" x="551" y="-143.3" font-family="Times,serif" font-size="14.00">0</text>
+<polyline fill="none" stroke="black" points="480,-135.5 622,-135.5 "/>
+<text text-anchor="middle" x="551" y="-120.3" font-family="Times,serif" font-size="14.00">Intel IPU6 CSI2 1</text>
+<text text-anchor="middle" x="551" y="-105.3" font-family="Times,serif" font-size="14.00">/dev/v4l&#45;subdev1</text>
+<polyline fill="none" stroke="black" points="480,-97.5 622,-97.5 "/>
+<text text-anchor="middle" x="551" y="-82.3" font-family="Times,serif" font-size="14.00">1</text>
+</g>
+<!-- n00000014&#45;&gt;n00000001 -->
+<g id="edge5" class="edge">
+<title>n00000014:port1&#45;&gt;n00000001</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M623,-85.5C629.23,-85.5 626.28,-78.06 631,-74 645.84,-61.25 664.22,-50.69 681.67,-42.4"/>
+<polygon fill="black" stroke="black" points="683.6,-45.36 691.24,-38.02 680.69,-39 683.6,-45.36"/>
+</g>
+<!-- n00000014&#45;&gt;n00000005 -->
+<g id="edge6" class="edge">
+<title>n00000014:port1&#45;&gt;n00000005</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M623,-85.5C629.23,-85.5 625.73,-77.32 631,-74 712.48,-22.66 751.25,-51.99 850.31,-38.16"/>
+<polygon fill="black" stroke="black" points="851.05,-41.58 860.41,-36.63 850,-34.66 851.05,-41.58"/>
+</g>
+<!-- n00000014&#45;&gt;n00000009 -->
+<g id="edge7" class="edge">
+<title>n00000014:port1&#45;&gt;n00000009</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M479,-85.5C472.77,-85.5 476.02,-77.69 471,-74 451.38,-59.59 427.8,-48.95 404.49,-41.12"/>
+<polygon fill="black" stroke="black" points="405.47,-37.76 394.88,-38.04 403.33,-44.42 405.47,-37.76"/>
+</g>
+<!-- n00000014&#45;&gt;n0000000d -->
+<g id="edge8" class="edge">
+<title>n00000014:port1&#45;&gt;n0000000d</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M551,-74C551,-64.31 547.2,-54.79 542.27,-46.51"/>
+<polygon fill="black" stroke="black" points="545.07,-44.41 536.59,-38.06 539.26,-48.31 545.07,-44.41"/>
+</g>
+<!-- n00000017 -->
+<g id="node7" class="node">
+<title>n00000017</title>
+<path fill="green" stroke="black" d="M652,-74.5C652,-74.5 770,-74.5 770,-74.5 776,-74.5 782,-80.5 782,-86.5 782,-86.5 782,-146.5 782,-146.5 782,-152.5 776,-158.5 770,-158.5 770,-158.5 652,-158.5 652,-158.5 646,-158.5 640,-152.5 640,-146.5 640,-146.5 640,-86.5 640,-86.5 640,-80.5 646,-74.5 652,-74.5"/>
+<text text-anchor="middle" x="711" y="-143.3" font-family="Times,serif" font-size="14.00">0</text>
+<polyline fill="none" stroke="black" points="640,-135.5 782,-135.5 "/>
+<text text-anchor="middle" x="711" y="-120.3" font-family="Times,serif" font-size="14.00">Intel IPU6 CSI2 2</text>
+<text text-anchor="middle" x="711" y="-105.3" font-family="Times,serif" font-size="14.00">/dev/v4l&#45;subdev2</text>
+<polyline fill="none" stroke="black" points="640,-97.5 782,-97.5 "/>
+<text text-anchor="middle" x="711" y="-82.3" font-family="Times,serif" font-size="14.00">1</text>
+</g>
+<!-- n00000017&#45;&gt;n00000001 -->
+<g id="edge9" class="edge">
+<title>n00000017:port1&#45;&gt;n00000001</title>
+<path fill="none" stroke="black" d="M711,-74C711,-64.39 714.67,-54.89 719.45,-46.61"/>
+<polygon fill="black" stroke="black" points="722.44,-48.44 724.95,-38.14 716.57,-44.62 722.44,-48.44"/>
+</g>
+<!-- n00000017&#45;&gt;n00000005 -->
+<g id="edge10" class="edge">
+<title>n00000017:port1&#45;&gt;n00000005</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M783,-85.5C789.23,-85.5 785.99,-77.69 791,-74 810.5,-59.65 833.94,-49.03 857.12,-41.21"/>
+<polygon fill="black" stroke="black" points="858.23,-44.52 866.68,-38.13 856.09,-37.86 858.23,-44.52"/>
+</g>
+<!-- n00000017&#45;&gt;n00000009 -->
+<g id="edge11" class="edge">
+<title>n00000017:port1&#45;&gt;n00000009</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M639,-85.5C632.77,-85.5 636.27,-77.32 631,-74 630.85,-73.91 507.25,-53.82 410.92,-38.17"/>
+<polygon fill="black" stroke="black" points="411.24,-34.68 400.8,-36.53 410.11,-41.59 411.24,-34.68"/>
+</g>
+<!-- n00000017&#45;&gt;n0000000d -->
+<g id="edge12" class="edge">
+<title>n00000017:port1&#45;&gt;n0000000d</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M639,-85.5C632.77,-85.5 635.73,-78.05 631,-74 615.96,-61.13 597.31,-50.51 579.63,-42.2"/>
+<polygon fill="black" stroke="black" points="581.04,-39 570.49,-38.06 578.16,-45.38 581.04,-39"/>
+</g>
+<!-- n0000001a -->
+<g id="node8" class="node">
+<title>n0000001a</title>
+<path fill="green" stroke="black" d="M812,-74.5C812,-74.5 930,-74.5 930,-74.5 936,-74.5 942,-80.5 942,-86.5 942,-86.5 942,-146.5 942,-146.5 942,-152.5 936,-158.5 930,-158.5 930,-158.5 812,-158.5 812,-158.5 806,-158.5 800,-152.5 800,-146.5 800,-146.5 800,-86.5 800,-86.5 800,-80.5 806,-74.5 812,-74.5"/>
+<text text-anchor="middle" x="871" y="-143.3" font-family="Times,serif" font-size="14.00">0</text>
+<polyline fill="none" stroke="black" points="800,-135.5 942,-135.5 "/>
+<text text-anchor="middle" x="871" y="-120.3" font-family="Times,serif" font-size="14.00">Intel IPU6 CSI2 3</text>
+<text text-anchor="middle" x="871" y="-105.3" font-family="Times,serif" font-size="14.00">/dev/v4l&#45;subdev3</text>
+<polyline fill="none" stroke="black" points="800,-97.5 942,-97.5 "/>
+<text text-anchor="middle" x="871" y="-82.3" font-family="Times,serif" font-size="14.00">1</text>
+</g>
+<!-- n0000001a&#45;&gt;n00000001 -->
+<g id="edge13" class="edge">
+<title>n0000001a:port1&#45;&gt;n00000001</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M799,-85.5C792.77,-85.5 794.9,-78.85 791,-74 783.32,-64.45 774.38,-54.48 766.19,-45.74"/>
+<polygon fill="black" stroke="black" points="768.67,-43.27 759.25,-38.42 763.59,-48.08 768.67,-43.27"/>
+</g>
+<!-- n0000001a&#45;&gt;n00000005 -->
+<g id="edge14" class="edge">
+<title>n0000001a:port1&#45;&gt;n00000005</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M943,-85.5C947.13,-85.5 952.41,-66.02 956.35,-48.31"/>
+<polygon fill="black" stroke="black" points="959.83,-48.76 958.5,-38.25 952.99,-47.29 959.83,-48.76"/>
+</g>
+<!-- n0000001a&#45;&gt;n00000009 -->
+<g id="edge15" class="edge">
+<title>n0000001a:port1&#45;&gt;n00000009</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M799,-85.5C792.77,-85.5 796.38,-77.14 791,-74 720.07,-32.58 509.44,-47.67 410.64,-37.89"/>
+<polygon fill="black" stroke="black" points="410.91,-34.4 400.58,-36.75 410.13,-41.35 410.91,-34.4"/>
+</g>
+<!-- n0000001a&#45;&gt;n0000000d -->
+<g id="edge16" class="edge">
+<title>n0000001a:port1&#45;&gt;n0000000d</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M799,-85.5C792.77,-85.5 796.21,-77.41 791,-74 777.21,-64.97 700.06,-50.06 631.59,-38.19"/>
+<polygon fill="black" stroke="black" points="632.01,-34.72 621.56,-36.47 630.82,-41.61 632.01,-34.72"/>
+</g>
+<!-- n0000001d -->
+<g id="node9" class="node">
+<title>n0000001d</title>
+<path fill="green" stroke="black" d="M972,-74.5C972,-74.5 1090,-74.5 1090,-74.5 1096,-74.5 1102,-80.5 1102,-86.5 1102,-86.5 1102,-146.5 1102,-146.5 1102,-152.5 1096,-158.5 1090,-158.5 1090,-158.5 972,-158.5 972,-158.5 966,-158.5 960,-152.5 960,-146.5 960,-146.5 960,-86.5 960,-86.5 960,-80.5 966,-74.5 972,-74.5"/>
+<text text-anchor="middle" x="1031" y="-143.3" font-family="Times,serif" font-size="14.00">0</text>
+<polyline fill="none" stroke="black" points="960,-135.5 1102,-135.5 "/>
+<text text-anchor="middle" x="1031" y="-120.3" font-family="Times,serif" font-size="14.00">Intel IPU6 CSI2 4</text>
+<text text-anchor="middle" x="1031" y="-105.3" font-family="Times,serif" font-size="14.00">/dev/v4l&#45;subdev4</text>
+<polyline fill="none" stroke="black" points="960,-97.5 1102,-97.5 "/>
+<text text-anchor="middle" x="1031" y="-82.3" font-family="Times,serif" font-size="14.00">1</text>
+</g>
+<!-- n0000001d&#45;&gt;n00000001 -->
+<g id="edge17" class="edge">
+<title>n0000001d:port1&#45;&gt;n00000001</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M959,-85.5C952.77,-85.5 956.11,-77.55 951,-74 933.43,-61.79 890.08,-49.78 847.29,-40.2"/>
+<polygon fill="black" stroke="black" points="847.83,-36.73 837.32,-38 846.33,-43.57 847.83,-36.73"/>
+</g>
+<!-- n0000001d&#45;&gt;n00000005 -->
+<g id="edge18" class="edge">
+<title>n0000001d:port1&#45;&gt;n00000005</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M959,-85.5C951.05,-85.5 952.67,-66.02 955.78,-48.31"/>
+<polygon fill="black" stroke="black" points="959.26,-48.73 957.72,-38.25 952.39,-47.4 959.26,-48.73"/>
+</g>
+<!-- n0000001d&#45;&gt;n00000009 -->
+<g id="edge19" class="edge">
+<title>n0000001d:port1&#45;&gt;n00000009</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M959,-85.5C952.77,-85.5 956.42,-77.07 951,-74 848.79,-16.19 545.64,-49.84 410.76,-37.89"/>
+<polygon fill="black" stroke="black" points="410.87,-34.39 400.57,-36.86 410.17,-41.35 410.87,-34.39"/>
+</g>
+<!-- n0000001d&#45;&gt;n0000000d -->
+<g id="edge20" class="edge">
+<title>n0000001d:port1&#45;&gt;n0000000d</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M959,-85.5C952.77,-85.5 956.35,-77.19 951,-74 891.99,-38.83 716.72,-46.98 631.74,-37.91"/>
+<polygon fill="black" stroke="black" points="631.94,-34.41 621.59,-36.68 631.1,-41.36 631.94,-34.41"/>
+</g>
+<!-- n00000020 -->
+<g id="node10" class="node">
+<title>n00000020</title>
+<path fill="green" stroke="black" d="M1132,-74.5C1132,-74.5 1250,-74.5 1250,-74.5 1256,-74.5 1262,-80.5 1262,-86.5 1262,-86.5 1262,-146.5 1262,-146.5 1262,-152.5 1256,-158.5 1250,-158.5 1250,-158.5 1132,-158.5 1132,-158.5 1126,-158.5 1120,-152.5 1120,-146.5 1120,-146.5 1120,-86.5 1120,-86.5 1120,-80.5 1126,-74.5 1132,-74.5"/>
+<text text-anchor="middle" x="1191" y="-143.3" font-family="Times,serif" font-size="14.00">0</text>
+<polyline fill="none" stroke="black" points="1120,-135.5 1262,-135.5 "/>
+<text text-anchor="middle" x="1191" y="-120.3" font-family="Times,serif" font-size="14.00">Intel IPU6 CSI2 5</text>
+<text text-anchor="middle" x="1191" y="-105.3" font-family="Times,serif" font-size="14.00">/dev/v4l&#45;subdev5</text>
+<polyline fill="none" stroke="black" points="1120,-97.5 1262,-97.5 "/>
+<text text-anchor="middle" x="1191" y="-82.3" font-family="Times,serif" font-size="14.00">1</text>
+</g>
+<!-- n00000020&#45;&gt;n00000001 -->
+<g id="edge21" class="edge">
+<title>n00000020:port1&#45;&gt;n00000001</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M1119,-85.5C1112.77,-85.5 1116.31,-77.26 1111,-74 1014.66,-14.86 969.43,-53.08 852.63,-37.98"/>
+<polygon fill="black" stroke="black" points="853,-34.49 842.61,-36.57 852.03,-41.42 853,-34.49"/>
+</g>
+<!-- n00000020&#45;&gt;n00000005 -->
+<g id="edge22" class="edge">
+<title>n00000020:port1&#45;&gt;n00000005</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M1119,-85.5C1112.77,-85.5 1115.94,-77.79 1111,-74 1092.76,-59.98 1070.53,-49.35 1048.88,-41.41"/>
+<polygon fill="black" stroke="black" points="1049.91,-38.06 1039.31,-38.05 1047.59,-44.66 1049.91,-38.06"/>
+</g>
+<!-- n00000020&#45;&gt;n00000009 -->
+<g id="edge23" class="edge">
+<title>n00000020:port1&#45;&gt;n00000009</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M1119,-85.5C1112.77,-85.5 1116.44,-77.02 1111,-74 1045.09,-37.38 523.89,-45.63 410.74,-37.79"/>
+<polygon fill="black" stroke="black" points="410.82,-34.29 400.56,-36.93 410.23,-41.26 410.82,-34.29"/>
+</g>
+<!-- n00000020&#45;&gt;n0000000d -->
+<g id="edge24" class="edge">
+<title>n00000020:port1&#45;&gt;n0000000d</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M1119,-85.5C1112.77,-85.5 1116.41,-77.09 1111,-74 1020.75,-22.45 752.98,-48.96 631.79,-37.9"/>
+<polygon fill="black" stroke="black" points="631.88,-34.39 621.57,-36.83 631.16,-41.35 631.88,-34.39"/>
+</g>
+<!-- n00000023 -->
+<g id="node11" class="node">
+<title>n00000023</title>
+<path fill="green" stroke="black" d="M12,-74.5C12,-74.5 130,-74.5 130,-74.5 136,-74.5 142,-80.5 142,-86.5 142,-86.5 142,-146.5 142,-146.5 142,-152.5 136,-158.5 130,-158.5 130,-158.5 12,-158.5 12,-158.5 6,-158.5 0,-152.5 0,-146.5 0,-146.5 0,-86.5 0,-86.5 0,-80.5 6,-74.5 12,-74.5"/>
+<text text-anchor="middle" x="71" y="-143.3" font-family="Times,serif" font-size="14.00">0</text>
+<polyline fill="none" stroke="black" points="0,-135.5 142,-135.5 "/>
+<text text-anchor="middle" x="71" y="-120.3" font-family="Times,serif" font-size="14.00">Intel IPU6 CSI2 6</text>
+<text text-anchor="middle" x="71" y="-105.3" font-family="Times,serif" font-size="14.00">/dev/v4l&#45;subdev6</text>
+<polyline fill="none" stroke="black" points="0,-97.5 142,-97.5 "/>
+<text text-anchor="middle" x="71" y="-82.3" font-family="Times,serif" font-size="14.00">1</text>
+</g>
+<!-- n00000023&#45;&gt;n00000001 -->
+<g id="edge25" class="edge">
+<title>n00000023:port1&#45;&gt;n00000001</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M143,-85.5C149.23,-85.5 145.59,-77.09 151,-74 241.25,-22.45 509.02,-49.03 629.32,-38.01"/>
+<polygon fill="black" stroke="black" points="629.88,-41.47 639.46,-36.95 629.15,-34.51 629.88,-41.47"/>
+</g>
+<!-- n00000023&#45;&gt;n00000005 -->
+<g id="edge26" class="edge">
+<title>n00000023:port1&#45;&gt;n00000005</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M143,-85.5C149.23,-85.5 145.56,-77.02 151,-74 216.91,-37.38 738.12,-45.69 850.38,-37.9"/>
+<polygon fill="black" stroke="black" points="850.8,-41.37 860.47,-37.04 850.21,-34.4 850.8,-41.37"/>
+</g>
+<!-- n00000023&#45;&gt;n00000009 -->
+<g id="edge27" class="edge">
+<title>n00000023:port1&#45;&gt;n00000009</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M143,-85.5C149.23,-85.5 146.07,-77.8 151,-74 169.21,-59.97 191.42,-49.33 213.04,-41.37"/>
+<polygon fill="black" stroke="black" points="214.32,-44.63 222.58,-38.01 211.99,-38.03 214.32,-44.63"/>
+</g>
+<!-- n00000023&#45;&gt;n0000000d -->
+<g id="edge28" class="edge">
+<title>n00000023:port1&#45;&gt;n0000000d</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M143,-85.5C149.23,-85.5 145.69,-77.26 151,-74 247.34,-14.86 292.59,-53.16 408.48,-38.11"/>
+<polygon fill="black" stroke="black" points="409.01,-41.57 418.43,-36.71 408.04,-34.64 409.01,-41.57"/>
+</g>
+<!-- n00000026 -->
+<g id="node12" class="node">
+<title>n00000026</title>
+<path fill="green" stroke="black" d="M172,-74.5C172,-74.5 290,-74.5 290,-74.5 296,-74.5 302,-80.5 302,-86.5 302,-86.5 302,-146.5 302,-146.5 302,-152.5 296,-158.5 290,-158.5 290,-158.5 172,-158.5 172,-158.5 166,-158.5 160,-152.5 160,-146.5 160,-146.5 160,-86.5 160,-86.5 160,-80.5 166,-74.5 172,-74.5"/>
+<text text-anchor="middle" x="231" y="-143.3" font-family="Times,serif" font-size="14.00">0</text>
+<polyline fill="none" stroke="black" points="160,-135.5 302,-135.5 "/>
+<text text-anchor="middle" x="231" y="-120.3" font-family="Times,serif" font-size="14.00">Intel IPU6 CSI2 7</text>
+<text text-anchor="middle" x="231" y="-105.3" font-family="Times,serif" font-size="14.00">/dev/v4l&#45;subdev7</text>
+<polyline fill="none" stroke="black" points="160,-97.5 302,-97.5 "/>
+<text text-anchor="middle" x="231" y="-82.3" font-family="Times,serif" font-size="14.00">1</text>
+</g>
+<!-- n00000026&#45;&gt;n00000001 -->
+<g id="edge29" class="edge">
+<title>n00000026:port1&#45;&gt;n00000001</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M303,-85.5C309.23,-85.5 305.65,-77.19 311,-74 370.01,-38.83 545.29,-47.02 629.41,-38.03"/>
+<polygon fill="black" stroke="black" points="629.93,-41.49 639.44,-36.81 629.09,-34.54 629.93,-41.49"/>
+</g>
+<!-- n00000026&#45;&gt;n00000005 -->
+<g id="edge30" class="edge">
+<title>n00000026:port1&#45;&gt;n00000005</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M303,-85.5C309.23,-85.5 305.58,-77.07 311,-74 413.21,-16.19 716.37,-49.92 850.34,-38.01"/>
+<polygon fill="black" stroke="black" points="850.87,-41.47 860.46,-36.98 850.16,-34.51 850.87,-41.47"/>
+</g>
+<!-- n00000026&#45;&gt;n00000009 -->
+<g id="edge31" class="edge">
+<title>n00000026:port1&#45;&gt;n00000009</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M303,-85.5C310.95,-85.5 309.04,-66.02 305.66,-48.31"/>
+<polygon fill="black" stroke="black" points="309.03,-47.32 303.56,-38.25 302.18,-48.75 309.03,-47.32"/>
+</g>
+<!-- n00000026&#45;&gt;n0000000d -->
+<g id="edge32" class="edge">
+<title>n00000026:port1&#45;&gt;n0000000d</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M303,-85.5C309.23,-85.5 305.89,-77.56 311,-74 328.48,-61.84 371.63,-49.83 414.21,-40.24"/>
+<polygon fill="black" stroke="black" points="415.13,-43.62 424.14,-38.04 413.62,-36.79 415.13,-43.62"/>
+</g>
+<!-- n00000069 -->
+<g id="node13" class="node">
+<title>n00000069</title>
+<path fill="green" stroke="black" d="M654.5,-195.5C654.5,-195.5 767.5,-195.5 767.5,-195.5 773.5,-195.5 779.5,-201.5 779.5,-207.5 779.5,-207.5 779.5,-267.5 779.5,-267.5 779.5,-273.5 773.5,-279.5 767.5,-279.5 767.5,-279.5 654.5,-279.5 654.5,-279.5 648.5,-279.5 642.5,-273.5 642.5,-267.5 642.5,-267.5 642.5,-207.5 642.5,-207.5 642.5,-201.5 648.5,-195.5 654.5,-195.5"/>
+<text text-anchor="middle" x="711" y="-264.3" font-family="Times,serif" font-size="14.00"> </text>
+<polyline fill="none" stroke="black" points="642.5,-256.5 779.5,-256.5 "/>
+<text text-anchor="middle" x="711" y="-241.3" font-family="Times,serif" font-size="14.00">ov01a10 3&#45;0036</text>
+<text text-anchor="middle" x="711" y="-226.3" font-family="Times,serif" font-size="14.00">/dev/v4l&#45;subdev8</text>
+<polyline fill="none" stroke="black" points="642.5,-218.5 779.5,-218.5 "/>
+<text text-anchor="middle" x="711" y="-203.3" font-family="Times,serif" font-size="14.00">0</text>
+</g>
+<!-- n00000069&#45;&gt;n00000017 -->
+<g id="edge33" class="edge">
+<title>n00000069:port0&#45;&gt;n00000017:port0</title>
+<path fill="none" stroke="black" d="M711,-195C711,-183 711,-177.75 711,-169.12"/>
+<polygon fill="black" stroke="black" points="714.5,-169 711,-159 707.5,-169 714.5,-169"/>
+</g>
+</g>
+</svg>
diff --git a/Documentation/admin-guide/media/ipu6_isys_multi.svg b/Documentation/admin-guide/media/ipu6_isys_multi.svg
new file mode 100644
index 000000000000..5bd748d15c70
--- /dev/null
+++ b/Documentation/admin-guide/media/ipu6_isys_multi.svg
@@ -0,0 +1,1124 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
+ "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
+<!-- Generated by graphviz version 2.43.0 (0)
+ -->
+<!-- Title: board Pages: 1 -->
+<svg width="670pt" height="802pt"
+ viewBox="0.00 0.00 670.00 802.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
+<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 798)">
+<title>board</title>
+<polygon fill="white" stroke="transparent" points="-4,4 -4,-798 666,-798 666,4 -4,4"/>
+<!-- n00000001 -->
+<g id="node1" class="node">
+<title>n00000001</title>
+<polygon fill="yellow" stroke="black" points="657.5,-470.5 454.5,-470.5 454.5,-432.5 657.5,-432.5 657.5,-470.5"/>
+<text text-anchor="middle" x="556" y="-455.3" font-family="Times,serif" font-size="14.00">Intel IPU6 ISYS Capture 0</text>
+<text text-anchor="middle" x="556" y="-440.3" font-family="Times,serif" font-size="14.00">/dev/video0</text>
+</g>
+<!-- n00000005 -->
+<g id="node2" class="node">
+<title>n00000005</title>
+<polygon fill="yellow" stroke="black" points="657.5,-414.5 454.5,-414.5 454.5,-376.5 657.5,-376.5 657.5,-414.5"/>
+<text text-anchor="middle" x="556" y="-399.3" font-family="Times,serif" font-size="14.00">Intel IPU6 ISYS Capture 1</text>
+<text text-anchor="middle" x="556" y="-384.3" font-family="Times,serif" font-size="14.00">/dev/video1</text>
+</g>
+<!-- n00000009 -->
+<g id="node3" class="node">
+<title>n00000009</title>
+<polygon fill="yellow" stroke="black" points="660,-358.5 452,-358.5 452,-322.5 660,-322.5 660,-358.5"/>
+<text text-anchor="middle" x="556" y="-336.8" font-family="Times,serif" font-size="14.00">Intel IPU6 ISYS Capture ...</text>
+</g>
+<!-- n00000075 -->
+<g id="node4" class="node">
+<title>n00000075</title>
+<polygon fill="yellow" stroke="black" points="662,-304.5 450,-304.5 450,-266.5 662,-266.5 662,-304.5"/>
+<text text-anchor="middle" x="556" y="-289.3" font-family="Times,serif" font-size="14.00">Intel IPU6 ISYS Capture 29</text>
+<text text-anchor="middle" x="556" y="-274.3" font-family="Times,serif" font-size="14.00">/dev/video29</text>
+</g>
+<!-- n00000079 -->
+<g id="node5" class="node">
+<title>n00000079</title>
+<polygon fill="yellow" stroke="black" points="662,-526.5 450,-526.5 450,-488.5 662,-488.5 662,-526.5"/>
+<text text-anchor="middle" x="556" y="-511.3" font-family="Times,serif" font-size="14.00">Intel IPU6 ISYS Capture 30</text>
+<text text-anchor="middle" x="556" y="-496.3" font-family="Times,serif" font-size="14.00">/dev/video30</text>
+</g>
+<!-- n0000007d -->
+<g id="node6" class="node">
+<title>n0000007d</title>
+<path fill="chartreuse" stroke="black" d="M232,-203.5C232,-203.5 402,-203.5 402,-203.5 408,-203.5 414,-209.5 414,-215.5 414,-215.5 414,-375.5 414,-375.5 414,-381.5 408,-387.5 402,-387.5 402,-387.5 232,-387.5 232,-387.5 226,-387.5 220,-381.5 220,-375.5 220,-375.5 220,-215.5 220,-215.5 220,-209.5 226,-203.5 232,-203.5"/>
+<text text-anchor="middle" x="233" y="-291.8" font-family="Times,serif" font-size="14.00">0</text>
+<polyline fill="none" stroke="black" points="246,-203.5 246,-387.5 "/>
+<text text-anchor="middle" x="317" y="-299.3" font-family="Times,serif" font-size="14.00">Intel IPU6 CSI2 0</text>
+<text text-anchor="middle" x="317" y="-284.3" font-family="Times,serif" font-size="14.00">/dev/v4l&#45;subdev0</text>
+<polyline fill="none" stroke="black" points="388,-203.5 388,-387.5 "/>
+<text text-anchor="middle" x="401" y="-372.3" font-family="Times,serif" font-size="14.00">1</text>
+<polyline fill="none" stroke="black" points="388,-364.5 414,-364.5 "/>
+<text text-anchor="middle" x="401" y="-349.3" font-family="Times,serif" font-size="14.00">2</text>
+<polyline fill="none" stroke="black" points="388,-341.5 414,-341.5 "/>
+<text text-anchor="middle" x="401" y="-326.3" font-family="Times,serif" font-size="14.00">3</text>
+<polyline fill="none" stroke="black" points="388,-318.5 414,-318.5 "/>
+<text text-anchor="middle" x="401" y="-303.3" font-family="Times,serif" font-size="14.00">4</text>
+<polyline fill="none" stroke="black" points="388,-295.5 414,-295.5 "/>
+<text text-anchor="middle" x="401" y="-280.3" font-family="Times,serif" font-size="14.00">5</text>
+<polyline fill="none" stroke="black" points="388,-272.5 414,-272.5 "/>
+<text text-anchor="middle" x="401" y="-257.3" font-family="Times,serif" font-size="14.00">6</text>
+<polyline fill="none" stroke="black" points="388,-249.5 414,-249.5 "/>
+<text text-anchor="middle" x="401" y="-234.3" font-family="Times,serif" font-size="14.00">7</text>
+<polyline fill="none" stroke="black" points="388,-226.5 414,-226.5 "/>
+<text text-anchor="middle" x="401" y="-211.3" font-family="Times,serif" font-size="14.00">8</text>
+</g>
+<!-- n0000007d&#45;&gt;n00000001 -->
+<g id="edge1" class="edge">
+<title>n0000007d:port1&#45;&gt;n00000001</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-376.5C440.31,-376.5 428.12,-408.89 450,-423.5 452.27,-425.02 454.63,-426.46 457.05,-427.82"/>
+<polygon fill="black" stroke="black" points="455.54,-430.98 466.04,-432.41 458.72,-424.74 455.54,-430.98"/>
+</g>
+<!-- n0000007d&#45;&gt;n00000001 -->
+<g id="edge2" class="edge">
+<title>n0000007d:port2&#45;&gt;n00000001</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-353.5C448.98,-353.5 422.76,-401.55 450,-423.5 451.57,-424.77 453.19,-425.97 454.86,-427.13"/>
+<polygon fill="black" stroke="black" points="453.18,-430.2 463.53,-432.46 456.85,-424.24 453.18,-430.2"/>
+</g>
+<!-- n0000007d&#45;&gt;n00000001 -->
+<g id="edge3" class="edge">
+<title>n0000007d:port3&#45;&gt;n00000001</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-330.5C458.32,-330.5 417,-393.91 450,-423.5 451.14,-424.52 452.32,-425.51 453.52,-426.46"/>
+<polygon fill="black" stroke="black" points="451.66,-429.43 461.87,-432.24 455.64,-423.67 451.66,-429.43"/>
+</g>
+<!-- n0000007d&#45;&gt;n00000001 -->
+<g id="edge4" class="edge">
+<title>n0000007d:port4&#45;&gt;n00000001</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-307.5C467.98,-307.5 411.07,-386.11 450,-423.5 450.96,-424.42 451.94,-425.31 452.95,-426.17"/>
+<polygon fill="black" stroke="black" points="451,-429.08 461.12,-432.23 455.17,-423.46 451,-429.08"/>
+</g>
+<!-- n0000007d&#45;&gt;n00000001 -->
+<g id="edge5" class="edge">
+<title>n0000007d:port5&#45;&gt;n00000001</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-283.5C478.25,-283.5 404.77,-377.87 450,-423.5 450.93,-424.44 451.9,-425.35 452.88,-426.24"/>
+<polygon fill="black" stroke="black" points="450.86,-429.1 460.92,-432.43 455.14,-423.55 450.86,-429.1"/>
+</g>
+<!-- n0000007d&#45;&gt;n00000001 -->
+<g id="edge6" class="edge">
+<title>n0000007d:port6&#45;&gt;n00000001</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-260.5C488.19,-260.5 398.69,-369.92 450,-423.5 450.78,-424.32 451.59,-425.11 452.41,-425.88"/>
+<polygon fill="black" stroke="black" points="450.33,-428.7 460.31,-432.25 454.72,-423.25 450.33,-428.7"/>
+</g>
+<!-- n0000007d&#45;&gt;n00000001 -->
+<g id="edge7" class="edge">
+<title>n0000007d:port7&#45;&gt;n00000001</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-237.5C498.2,-237.5 392.56,-361.93 450,-423.5 450.77,-424.33 451.57,-425.13 452.38,-425.91"/>
+<polygon fill="black" stroke="black" points="450.26,-428.7 460.21,-432.35 454.71,-423.29 450.26,-428.7"/>
+</g>
+<!-- n0000007d&#45;&gt;n00000001 -->
+<g id="edge8" class="edge">
+<title>n0000007d:port8&#45;&gt;n00000001</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-214.5C461.13,-214.5 418.21,-388.71 450,-423.5 450.76,-424.34 451.55,-425.15 452.35,-425.94"/>
+<polygon fill="black" stroke="black" points="450.2,-428.7 460.12,-432.43 454.69,-423.33 450.2,-428.7"/>
+</g>
+<!-- n0000007d&#45;&gt;n00000005 -->
+<g id="edge9" class="edge">
+<title>n0000007d:port1&#45;&gt;n00000005</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-376.5C423.82,-376.5 433.99,-376.96 444.16,-377.73"/>
+<polygon fill="black" stroke="black" points="444.06,-381.24 454.32,-378.61 444.66,-374.26 444.06,-381.24"/>
+</g>
+<!-- n0000007d&#45;&gt;n00000005 -->
+<g id="edge10" class="edge">
+<title>n0000007d:port2&#45;&gt;n00000005</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-353.5C431.17,-353.5 433.68,-362.17 450,-367.5 456.39,-369.59 463.03,-371.63 469.73,-373.61"/>
+<polygon fill="black" stroke="black" points="468.99,-377.04 479.57,-376.46 470.94,-370.32 468.99,-377.04"/>
+</g>
+<!-- n0000007d&#45;&gt;n00000005 -->
+<g id="edge11" class="edge">
+<title>n0000007d:port3&#45;&gt;n00000005</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-330.5C436.94,-330.5 430.2,-355.9 450,-367.5 452.89,-369.19 455.88,-370.78 458.95,-372.28"/>
+<polygon fill="black" stroke="black" points="457.8,-375.6 468.36,-376.5 460.67,-369.22 457.8,-375.6"/>
+</g>
+<!-- n0000007d&#45;&gt;n00000005 -->
+<g id="edge12" class="edge">
+<title>n0000007d:port4&#45;&gt;n00000005</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-307.5C445.1,-307.5 425.16,-348.79 450,-367.5 451.81,-368.86 453.67,-370.15 455.59,-371.39"/>
+<polygon fill="black" stroke="black" points="453.89,-374.44 464.3,-376.39 457.38,-368.37 453.89,-374.44"/>
+</g>
+<!-- n0000007d&#45;&gt;n00000005 -->
+<g id="edge13" class="edge">
+<title>n0000007d:port5&#45;&gt;n00000005</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-283.5C454.62,-283.5 419.28,-340.92 450,-367.5 451.32,-368.65 452.69,-369.75 454.09,-370.8"/>
+<polygon fill="black" stroke="black" points="452.23,-373.77 462.5,-376.37 456.1,-367.93 452.23,-373.77"/>
+</g>
+<!-- n0000007d&#45;&gt;n00000005 -->
+<g id="edge14" class="edge">
+<title>n0000007d:port6&#45;&gt;n00000005</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-260.5C464.18,-260.5 413.4,-333.17 450,-367.5 451.12,-368.55 452.27,-369.56 453.46,-370.53"/>
+<polygon fill="black" stroke="black" points="451.53,-373.46 461.69,-376.43 455.6,-367.76 451.53,-373.46"/>
+</g>
+<!-- n0000007d&#45;&gt;n00000005 -->
+<g id="edge15" class="edge">
+<title>n0000007d:port7&#45;&gt;n00000005</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-237.5C473.95,-237.5 407.41,-325.31 450,-367.5 450.94,-368.43 451.91,-369.34 452.91,-370.21"/>
+<polygon fill="black" stroke="black" points="450.91,-373.09 460.99,-376.36 455.15,-367.52 450.91,-373.09"/>
+</g>
+<!-- n0000007d&#45;&gt;n00000005 -->
+<g id="edge16" class="edge">
+<title>n0000007d:port8&#45;&gt;n00000005</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-214.5C483.86,-214.5 401.34,-317.38 450,-367.5 450.79,-368.31 451.6,-369.1 452.43,-369.87"/>
+<polygon fill="black" stroke="black" points="450.36,-372.7 460.37,-376.2 454.73,-367.23 450.36,-372.7"/>
+</g>
+<!-- n0000007d&#45;&gt;n00000009 -->
+<g id="edge17" class="edge">
+<title>n0000007d:port1&#45;&gt;n00000009</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-376.5C414.46,-376.5 443.23,-369.17 474.66,-361.12"/>
+<polygon fill="black" stroke="black" points="475.65,-364.48 484.47,-358.61 473.91,-357.7 475.65,-364.48"/>
+</g>
+<!-- n0000007d&#45;&gt;n00000009 -->
+<g id="edge18" class="edge">
+<title>n0000007d:port2&#45;&gt;n00000009</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-353.5C423.03,-353.5 432.36,-353.23 441.74,-352.77"/>
+<polygon fill="black" stroke="black" points="442.12,-356.26 451.91,-352.21 441.73,-349.27 442.12,-356.26"/>
+</g>
+<!-- n0000007d&#45;&gt;n00000009 -->
+<g id="edge19" class="edge">
+<title>n0000007d:port3&#45;&gt;n00000009</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-330.5C423.01,-330.5 432.34,-330.71 441.7,-331.06"/>
+<polygon fill="black" stroke="black" points="441.73,-334.56 451.87,-331.5 442.03,-327.57 441.73,-334.56"/>
+</g>
+<!-- n0000007d&#45;&gt;n00000009 -->
+<g id="edge20" class="edge">
+<title>n0000007d:port4&#45;&gt;n00000009</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-307.5C420.75,-307.5 446.63,-313.3 474.41,-320.04"/>
+<polygon fill="black" stroke="black" points="473.74,-323.48 484.29,-322.46 475.4,-316.68 473.74,-323.48"/>
+</g>
+<!-- n0000007d&#45;&gt;n00000009 -->
+<g id="edge21" class="edge">
+<title>n0000007d:port5&#45;&gt;n00000009</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-283.5C434.83,-283.5 431.46,-304.01 450,-313.5 453.57,-315.33 457.28,-317.04 461.07,-318.64"/>
+<polygon fill="black" stroke="black" points="460.07,-322.01 470.65,-322.4 462.62,-315.49 460.07,-322.01"/>
+</g>
+<!-- n0000007d&#45;&gt;n00000009 -->
+<g id="edge22" class="edge">
+<title>n0000007d:port6&#45;&gt;n00000009</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-260.5C442.48,-260.5 426.71,-297.12 450,-313.5 452.12,-314.99 454.32,-316.4 456.58,-317.73"/>
+<polygon fill="black" stroke="black" points="455.09,-320.91 465.57,-322.49 458.37,-314.72 455.09,-320.91"/>
+</g>
+<!-- n0000007d&#45;&gt;n00000009 -->
+<g id="edge23" class="edge">
+<title>n0000007d:port7&#45;&gt;n00000009</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-237.5C451.38,-237.5 421.18,-289.71 450,-313.5 451.4,-314.65 452.84,-315.76 454.32,-316.82"/>
+<polygon fill="black" stroke="black" points="452.84,-320.02 463.17,-322.38 456.56,-314.1 452.84,-320.02"/>
+</g>
+<!-- n0000007d&#45;&gt;n00000009 -->
+<g id="edge24" class="edge">
+<title>n0000007d:port8&#45;&gt;n00000009</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-214.5C460.82,-214.5 415.33,-282.04 450,-313.5 451.13,-314.53 452.3,-315.52 453.5,-316.47"/>
+<polygon fill="black" stroke="black" points="451.6,-319.41 461.81,-322.24 455.59,-313.66 451.6,-319.41"/>
+</g>
+<!-- n0000007d&#45;&gt;n00000075 -->
+<g id="edge25" class="edge">
+<title>n0000007d:port1&#45;&gt;n00000075</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-376.5C446.25,-376.5 424.45,-333.17 450,-313.5 451.63,-312.25 453.3,-311.05 455.02,-309.91"/>
+<polygon fill="black" stroke="black" points="457.13,-312.73 463.96,-304.63 453.57,-306.7 457.13,-312.73"/>
+</g>
+<!-- n0000007d&#45;&gt;n00000075 -->
+<g id="edge26" class="edge">
+<title>n0000007d:port2&#45;&gt;n00000075</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-353.5C437.92,-353.5 429.6,-325.99 450,-313.5 452.65,-311.88 455.39,-310.35 458.21,-308.91"/>
+<polygon fill="black" stroke="black" points="459.84,-312.01 467.41,-304.59 456.87,-305.67 459.84,-312.01"/>
+</g>
+<!-- n0000007d&#45;&gt;n00000075 -->
+<g id="edge27" class="edge">
+<title>n0000007d:port3&#45;&gt;n00000075</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-330.5C431.69,-330.5 433.38,-319.58 450,-313.5 455.56,-311.46 461.34,-309.51 467.19,-307.64"/>
+<polygon fill="black" stroke="black" points="468.57,-310.88 477.1,-304.58 466.51,-304.19 468.57,-310.88"/>
+</g>
+<!-- n0000007d&#45;&gt;n00000075 -->
+<g id="edge28" class="edge">
+<title>n0000007d:port4&#45;&gt;n00000075</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-307.5C425.31,-307.5 437.06,-306.8 448.75,-305.65"/>
+<polygon fill="black" stroke="black" points="449.42,-309.1 458.98,-304.53 448.66,-302.14 449.42,-309.1"/>
+</g>
+<!-- n0000007d&#45;&gt;n00000075 -->
+<g id="edge29" class="edge">
+<title>n0000007d:port5&#45;&gt;n00000075</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-283.5C422.36,-283.5 430.99,-283.54 439.69,-283.6"/>
+<polygon fill="black" stroke="black" points="439.87,-287.1 449.9,-283.68 439.93,-280.1 439.87,-287.1"/>
+</g>
+<!-- n0000007d&#45;&gt;n00000075 -->
+<g id="edge30" class="edge">
+<title>n0000007d:port6&#45;&gt;n00000075</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-260.5C430.94,-260.5 448.85,-262.27 466.01,-264.87"/>
+<polygon fill="black" stroke="black" points="465.59,-268.35 476.02,-266.49 466.7,-261.44 465.59,-268.35"/>
+</g>
+<!-- n0000007d&#45;&gt;n00000075 -->
+<g id="edge31" class="edge">
+<title>n0000007d:port7&#45;&gt;n00000075</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-237.5C447.66,-237.5 483.54,-249.91 510.68,-262.11"/>
+<polygon fill="black" stroke="black" points="509.35,-265.35 519.9,-266.39 512.31,-259 509.35,-265.35"/>
+</g>
+<!-- n0000007d&#45;&gt;n00000075 -->
+<g id="edge32" class="edge">
+<title>n0000007d:port8&#45;&gt;n00000075</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-214.5C455.98,-214.5 498.19,-239.91 525.34,-260.33"/>
+<polygon fill="black" stroke="black" points="523.22,-263.11 533.26,-266.47 527.5,-257.58 523.22,-263.11"/>
+</g>
+<!-- n0000007d&#45;&gt;n00000079 -->
+<g id="edge33" class="edge">
+<title>n0000007d:port1&#45;&gt;n00000079</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-376.5C462.49,-376.5 414.44,-446.53 450,-479.5 451.12,-480.54 452.28,-481.55 453.47,-482.51"/>
+<polygon fill="black" stroke="black" points="451.56,-485.45 461.74,-488.38 455.61,-479.74 451.56,-485.45"/>
+</g>
+<!-- n0000007d&#45;&gt;n00000079 -->
+<g id="edge34" class="edge">
+<title>n0000007d:port2&#45;&gt;n00000079</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-353.5C472.24,-353.5 408.45,-438.68 450,-479.5 450.95,-480.43 451.92,-481.33 452.92,-482.2"/>
+<polygon fill="black" stroke="black" points="450.94,-485.09 461.03,-488.32 455.16,-479.5 450.94,-485.09"/>
+</g>
+<!-- n0000007d&#45;&gt;n00000079 -->
+<g id="edge35" class="edge">
+<title>n0000007d:port3&#45;&gt;n00000079</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-330.5C482.13,-330.5 402.4,-430.76 450,-479.5 450.93,-480.45 451.88,-481.37 452.86,-482.25"/>
+<polygon fill="black" stroke="black" points="450.82,-485.1 460.86,-488.49 455.13,-479.58 450.82,-485.1"/>
+</g>
+<!-- n0000007d&#45;&gt;n00000079 -->
+<g id="edge36" class="edge">
+<title>n0000007d:port4&#45;&gt;n00000079</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-307.5C492.1,-307.5 396.29,-422.8 450,-479.5 450.78,-480.32 451.58,-481.12 452.4,-481.9"/>
+<polygon fill="black" stroke="black" points="450.3,-484.7 460.27,-488.29 454.71,-479.27 450.3,-484.7"/>
+</g>
+<!-- n0000007d&#45;&gt;n00000079 -->
+<g id="edge37" class="edge">
+<title>n0000007d:port5&#45;&gt;n00000079</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-283.5C502.57,-283.5 389.89,-414.45 450,-479.5 450.77,-480.33 451.56,-481.14 452.37,-481.92"/>
+<polygon fill="black" stroke="black" points="450.23,-484.7 460.17,-488.39 454.7,-479.31 450.23,-484.7"/>
+</g>
+<!-- n0000007d&#45;&gt;n00000079 -->
+<g id="edge38" class="edge">
+<title>n0000007d:port6&#45;&gt;n00000079</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-260.5C463.32,-260.5 416.87,-442.96 450,-479.5 450.76,-480.34 451.54,-481.15 452.35,-481.94"/>
+<polygon fill="black" stroke="black" points="450.18,-484.7 460.09,-488.46 454.69,-479.34 450.18,-484.7"/>
+</g>
+<!-- n0000007d&#45;&gt;n00000079 -->
+<g id="edge39" class="edge">
+<title>n0000007d:port7&#45;&gt;n00000079</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-237.5C468.37,-237.5 413.79,-438.95 450,-479.5 450.63,-480.21 451.28,-480.9 451.94,-481.57"/>
+<polygon fill="black" stroke="black" points="449.72,-484.28 459.57,-488.18 454.3,-478.99 449.72,-484.28"/>
+</g>
+<!-- n0000007d&#45;&gt;n00000079 -->
+<g id="edge40" class="edge">
+<title>n0000007d:port8&#45;&gt;n00000079</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-214.5C473.43,-214.5 410.7,-434.92 450,-479.5 450.63,-480.21 451.27,-480.91 451.93,-481.58"/>
+<polygon fill="black" stroke="black" points="449.69,-484.28 459.52,-488.23 454.3,-479.01 449.69,-484.28"/>
+</g>
+<!-- n00000087 -->
+<g id="node7" class="node">
+<title>n00000087</title>
+<path fill="chartreuse" stroke="black" d="M232,-0.5C232,-0.5 402,-0.5 402,-0.5 408,-0.5 414,-6.5 414,-12.5 414,-12.5 414,-172.5 414,-172.5 414,-178.5 408,-184.5 402,-184.5 402,-184.5 232,-184.5 232,-184.5 226,-184.5 220,-178.5 220,-172.5 220,-172.5 220,-12.5 220,-12.5 220,-6.5 226,-0.5 232,-0.5"/>
+<text text-anchor="middle" x="233" y="-88.8" font-family="Times,serif" font-size="14.00">0</text>
+<polyline fill="none" stroke="black" points="246,-0.5 246,-184.5 "/>
+<text text-anchor="middle" x="317" y="-96.3" font-family="Times,serif" font-size="14.00">Intel IPU6 CSI2 1</text>
+<text text-anchor="middle" x="317" y="-81.3" font-family="Times,serif" font-size="14.00">/dev/v4l&#45;subdev1</text>
+<polyline fill="none" stroke="black" points="388,-0.5 388,-184.5 "/>
+<text text-anchor="middle" x="401" y="-169.3" font-family="Times,serif" font-size="14.00">1</text>
+<polyline fill="none" stroke="black" points="388,-161.5 414,-161.5 "/>
+<text text-anchor="middle" x="401" y="-146.3" font-family="Times,serif" font-size="14.00">2</text>
+<polyline fill="none" stroke="black" points="388,-138.5 414,-138.5 "/>
+<text text-anchor="middle" x="401" y="-123.3" font-family="Times,serif" font-size="14.00">3</text>
+<polyline fill="none" stroke="black" points="388,-115.5 414,-115.5 "/>
+<text text-anchor="middle" x="401" y="-100.3" font-family="Times,serif" font-size="14.00">4</text>
+<polyline fill="none" stroke="black" points="388,-92.5 414,-92.5 "/>
+<text text-anchor="middle" x="401" y="-77.3" font-family="Times,serif" font-size="14.00">5</text>
+<polyline fill="none" stroke="black" points="388,-69.5 414,-69.5 "/>
+<text text-anchor="middle" x="401" y="-54.3" font-family="Times,serif" font-size="14.00">6</text>
+<polyline fill="none" stroke="black" points="388,-46.5 414,-46.5 "/>
+<text text-anchor="middle" x="401" y="-31.3" font-family="Times,serif" font-size="14.00">7</text>
+<polyline fill="none" stroke="black" points="388,-23.5 414,-23.5 "/>
+<text text-anchor="middle" x="401" y="-8.3" font-family="Times,serif" font-size="14.00">8</text>
+</g>
+<!-- n00000087&#45;&gt;n00000001 -->
+<g id="edge41" class="edge">
+<title>n00000087:port1&#45;&gt;n00000001</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M401,-185.5C401,-192.53 410.26,-188.55 414,-194.5 468.78,-281.76 381.06,-346.94 450,-423.5 450.76,-424.34 451.54,-425.16 452.34,-425.95"/>
+<polygon fill="black" stroke="black" points="450.16,-428.7 460.06,-432.48 454.68,-423.35 450.16,-428.7"/>
+</g>
+<!-- n00000087&#45;&gt;n00000001 -->
+<g id="edge42" class="edge">
+<title>n00000087:port2&#45;&gt;n00000001</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-150.5C475.19,-150.5 409.62,-377.52 450,-423.5 450.63,-424.21 451.27,-424.91 451.93,-425.59"/>
+<polygon fill="black" stroke="black" points="449.68,-428.28 459.51,-432.24 454.3,-423.01 449.68,-428.28"/>
+</g>
+<!-- n00000087&#45;&gt;n00000001 -->
+<g id="edge43" class="edge">
+<title>n00000087:port3&#45;&gt;n00000001</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-127.5C480.26,-127.5 406.53,-373.49 450,-423.5 450.62,-424.22 451.26,-424.92 451.92,-425.6"/>
+<polygon fill="black" stroke="black" points="449.66,-428.27 459.47,-432.28 454.29,-423.03 449.66,-428.27"/>
+</g>
+<!-- n00000087&#45;&gt;n00000001 -->
+<g id="edge44" class="edge">
+<title>n00000087:port4&#45;&gt;n00000001</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-104.5C485.34,-104.5 403.43,-369.46 450,-423.5 450.62,-424.22 451.26,-424.92 451.91,-425.61"/>
+<polygon fill="black" stroke="black" points="449.63,-428.27 459.43,-432.31 454.29,-423.04 449.63,-428.27"/>
+</g>
+<!-- n00000087&#45;&gt;n00000001 -->
+<g id="edge45" class="edge">
+<title>n00000087:port5&#45;&gt;n00000001</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-80.5C490.64,-80.5 400.2,-365.25 450,-423.5 450.62,-424.22 451.25,-424.93 451.9,-425.61"/>
+<polygon fill="black" stroke="black" points="449.62,-428.27 459.4,-432.33 454.29,-423.05 449.62,-428.27"/>
+</g>
+<!-- n00000087&#45;&gt;n00000001 -->
+<g id="edge46" class="edge">
+<title>n00000087:port6&#45;&gt;n00000001</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-57.5C495.73,-57.5 397.09,-361.21 450,-423.5 450.61,-424.22 451.25,-424.93 451.89,-425.62"/>
+<polygon fill="black" stroke="black" points="449.6,-428.26 459.37,-432.36 454.28,-423.06 449.6,-428.26"/>
+</g>
+<!-- n00000087&#45;&gt;n00000001 -->
+<g id="edge47" class="edge">
+<title>n00000087:port7&#45;&gt;n00000001</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-34.5C500.81,-34.5 393.99,-357.17 450,-423.5 450.61,-424.23 451.24,-424.93 451.89,-425.62"/>
+<polygon fill="black" stroke="black" points="449.58,-428.26 459.35,-432.38 454.28,-423.07 449.58,-428.26"/>
+</g>
+<!-- n00000087&#45;&gt;n00000001 -->
+<g id="edge48" class="edge">
+<title>n00000087:port8&#45;&gt;n00000001</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-11.5C459.95,-11.5 420.44,-388.31 450,-423.5 450.61,-424.23 451.24,-424.94 451.88,-425.63"/>
+<polygon fill="black" stroke="black" points="449.57,-428.26 459.33,-432.39 454.28,-423.08 449.57,-428.26"/>
+</g>
+<!-- n00000087&#45;&gt;n00000005 -->
+<g id="edge49" class="edge">
+<title>n00000087:port1&#45;&gt;n00000005</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M401,-185.5C401,-192.53 410.12,-188.64 414,-194.5 457.38,-259.97 396.03,-310.45 450,-367.5 450.78,-368.32 451.58,-369.12 452.4,-369.9"/>
+<polygon fill="black" stroke="black" points="450.3,-372.7 460.26,-376.3 454.71,-367.27 450.3,-372.7"/>
+</g>
+<!-- n00000087&#45;&gt;n00000005 -->
+<g id="edge50" class="edge">
+<title>n00000087:port2&#45;&gt;n00000005</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-150.5C462.88,-150.5 417.14,-331.31 450,-367.5 450.76,-368.34 451.54,-369.15 452.35,-369.94"/>
+<polygon fill="black" stroke="black" points="450.19,-372.7 460.1,-376.45 454.69,-367.34 450.19,-372.7"/>
+</g>
+<!-- n00000087&#45;&gt;n00000005 -->
+<g id="edge51" class="edge">
+<title>n00000087:port3&#45;&gt;n00000005</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-127.5C467.93,-127.5 414.05,-327.3 450,-367.5 450.63,-368.21 451.28,-368.9 451.94,-369.57"/>
+<polygon fill="black" stroke="black" points="449.73,-372.28 459.58,-376.18 454.31,-366.99 449.73,-372.28"/>
+</g>
+<!-- n00000087&#45;&gt;n00000005 -->
+<g id="edge52" class="edge">
+<title>n00000087:port4&#45;&gt;n00000005</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-104.5C472.99,-104.5 410.97,-323.27 450,-367.5 450.63,-368.21 451.27,-368.91 451.93,-369.58"/>
+<polygon fill="black" stroke="black" points="449.69,-372.28 459.53,-376.22 454.3,-367.01 449.69,-372.28"/>
+</g>
+<!-- n00000087&#45;&gt;n00000005 -->
+<g id="edge53" class="edge">
+<title>n00000087:port5&#45;&gt;n00000005</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-80.5C478.28,-80.5 407.74,-319.07 450,-367.5 450.62,-368.22 451.26,-368.91 451.92,-369.59"/>
+<polygon fill="black" stroke="black" points="449.67,-372.27 459.48,-376.26 454.3,-367.02 449.67,-372.27"/>
+</g>
+<!-- n00000087&#45;&gt;n00000005 -->
+<g id="edge54" class="edge">
+<title>n00000087:port6&#45;&gt;n00000005</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-57.5C483.35,-57.5 404.64,-315.04 450,-367.5 450.62,-368.22 451.26,-368.92 451.91,-369.6"/>
+<polygon fill="black" stroke="black" points="449.64,-372.27 459.44,-376.29 454.29,-367.04 449.64,-372.27"/>
+</g>
+<!-- n00000087&#45;&gt;n00000005 -->
+<g id="edge55" class="edge">
+<title>n00000087:port7&#45;&gt;n00000005</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-34.5C488.43,-34.5 401.54,-311 450,-367.5 450.62,-368.22 451.25,-368.92 451.9,-369.61"/>
+<polygon fill="black" stroke="black" points="449.62,-372.27 459.41,-376.32 454.29,-367.05 449.62,-372.27"/>
+</g>
+<!-- n00000087&#45;&gt;n00000005 -->
+<g id="edge56" class="edge">
+<title>n00000087:port8&#45;&gt;n00000005</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-11.5C493.51,-11.5 398.44,-306.97 450,-367.5 450.62,-368.22 451.25,-368.93 451.89,-369.62"/>
+<polygon fill="black" stroke="black" points="449.61,-372.26 459.38,-376.35 454.29,-367.06 449.61,-372.26"/>
+</g>
+<!-- n00000087&#45;&gt;n00000009 -->
+<g id="edge57" class="edge">
+<title>n00000087:port1&#45;&gt;n00000009</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M401,-185.5C401,-192.53 409.86,-188.82 414,-194.5 446.53,-239.16 410.11,-275.26 450,-313.5 451.1,-314.56 452.24,-315.58 453.42,-316.56"/>
+<polygon fill="black" stroke="black" points="451.43,-319.44 461.58,-322.48 455.54,-313.78 451.43,-319.44"/>
+</g>
+<!-- n00000087&#45;&gt;n00000009 -->
+<g id="edge58" class="edge">
+<title>n00000087:port2&#45;&gt;n00000009</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-150.5C488.19,-150.5 398.45,-260.15 450,-313.5 450.92,-314.45 451.87,-315.37 452.84,-316.26"/>
+<polygon fill="black" stroke="black" points="450.76,-319.08 460.8,-322.49 455.08,-313.57 450.76,-319.08"/>
+</g>
+<!-- n00000087&#45;&gt;n00000009 -->
+<g id="edge59" class="edge">
+<title>n00000087:port3&#45;&gt;n00000009</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-127.5C498.2,-127.5 392.29,-252.19 450,-313.5 450.77,-314.32 451.57,-315.12 452.38,-315.9"/>
+<polygon fill="black" stroke="black" points="450.26,-318.68 460.22,-322.27 454.67,-313.25 450.26,-318.68"/>
+</g>
+<!-- n00000087&#45;&gt;n00000009 -->
+<g id="edge60" class="edge">
+<title>n00000087:port4&#45;&gt;n00000009</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-104.5C461.13,-104.5 418.05,-278.85 450,-313.5 450.77,-314.33 451.55,-315.14 452.36,-315.92"/>
+<polygon fill="black" stroke="black" points="450.2,-318.68 460.14,-322.35 454.66,-313.28 450.2,-318.68"/>
+</g>
+<!-- n00000087&#45;&gt;n00000009 -->
+<g id="edge61" class="edge">
+<title>n00000087:port5&#45;&gt;n00000009</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-80.5C466.39,-80.5 414.82,-274.68 450,-313.5 450.76,-314.34 451.54,-315.15 452.34,-315.94"/>
+<polygon fill="black" stroke="black" points="450.16,-318.67 460.07,-322.42 454.65,-313.31 450.16,-318.67"/>
+</g>
+<!-- n00000087&#45;&gt;n00000009 -->
+<g id="edge62" class="edge">
+<title>n00000087:port6&#45;&gt;n00000009</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-57.5C471.45,-57.5 411.71,-270.67 450,-313.5 450.75,-314.34 451.53,-315.16 452.32,-315.95"/>
+<polygon fill="black" stroke="black" points="450.12,-318.67 460.01,-322.47 454.64,-313.33 450.12,-318.67"/>
+</g>
+<!-- n00000087&#45;&gt;n00000009 -->
+<g id="edge63" class="edge">
+<title>n00000087:port7&#45;&gt;n00000009</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-34.5C476.51,-34.5 408.6,-266.66 450,-313.5 450.63,-314.21 451.27,-314.9 451.93,-315.58"/>
+<polygon fill="black" stroke="black" points="449.67,-318.25 459.51,-322.18 454.27,-312.97 449.67,-318.25"/>
+</g>
+<!-- n00000087&#45;&gt;n00000009 -->
+<g id="edge64" class="edge">
+<title>n00000087:port8&#45;&gt;n00000009</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-11.5C481.59,-11.5 405.49,-262.64 450,-313.5 450.62,-314.21 451.26,-314.91 451.92,-315.59"/>
+<polygon fill="black" stroke="black" points="449.65,-318.25 459.48,-322.21 454.26,-312.99 449.65,-318.25"/>
+</g>
+<!-- n00000087&#45;&gt;n00000075 -->
+<g id="edge65" class="edge">
+<title>n00000087:port1&#45;&gt;n00000075</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-173.5C468.09,-173.5 513.48,-224.67 537.22,-257.84"/>
+<polygon fill="black" stroke="black" points="534.48,-260.03 543.05,-266.25 540.23,-256.04 534.48,-260.03"/>
+</g>
+<!-- n00000087&#45;&gt;n00000075 -->
+<g id="edge66" class="edge">
+<title>n00000087:port2&#45;&gt;n00000075</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-150.5C475.34,-150.5 520.42,-217.98 541.58,-257.52"/>
+<polygon fill="black" stroke="black" points="538.49,-259.17 546.2,-266.44 544.71,-255.95 538.49,-259.17"/>
+</g>
+<!-- n00000087&#45;&gt;n00000075 -->
+<g id="edge67" class="edge">
+<title>n00000087:port3&#45;&gt;n00000075</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-127.5C482.67,-127.5 526.2,-211.62 544.71,-257.1"/>
+<polygon fill="black" stroke="black" points="541.47,-258.42 548.39,-266.44 547.98,-255.85 541.47,-258.42"/>
+</g>
+<!-- n00000087&#45;&gt;n00000075 -->
+<g id="edge68" class="edge">
+<title>n00000087:port4&#45;&gt;n00000075</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-104.5C490.21,-104.5 531.26,-205.59 547.14,-256.68"/>
+<polygon fill="black" stroke="black" points="543.85,-257.89 550.07,-266.47 550.56,-255.89 543.85,-257.89"/>
+</g>
+<!-- n00000087&#45;&gt;n00000075 -->
+<g id="edge69" class="edge">
+<title>n00000087:port5&#45;&gt;n00000075</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-80.5C498.38,-80.5 536.08,-199.86 549.21,-256.43"/>
+<polygon fill="black" stroke="black" points="545.8,-257.21 551.39,-266.21 552.64,-255.69 545.8,-257.21"/>
+</g>
+<!-- n00000087&#45;&gt;n00000075 -->
+<g id="edge70" class="edge">
+<title>n00000087:port6&#45;&gt;n00000075</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-57.5C506.42,-57.5 540.3,-194.69 550.85,-256.23"/>
+<polygon fill="black" stroke="black" points="547.45,-257.14 552.51,-266.45 554.36,-256.02 547.45,-257.14"/>
+</g>
+<!-- n00000087&#45;&gt;n00000075 -->
+<g id="edge71" class="edge">
+<title>n00000087:port7&#45;&gt;n00000075</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-34.5C514.61,-34.5 544.18,-189.69 552.22,-256.01"/>
+<polygon fill="black" stroke="black" points="548.77,-256.68 553.37,-266.22 555.73,-255.89 548.77,-256.68"/>
+</g>
+<!-- n00000087&#45;&gt;n00000075 -->
+<g id="edge72" class="edge">
+<title>n00000087:port8&#45;&gt;n00000075</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-11.5C523.15,-11.5 547.88,-185.54 553.42,-256.2"/>
+<polygon fill="black" stroke="black" points="549.93,-256.51 554.13,-266.23 556.92,-256.01 549.93,-256.51"/>
+</g>
+<!-- n00000087&#45;&gt;n00000079 -->
+<g id="edge73" class="edge">
+<title>n00000087:port1&#45;&gt;n00000079</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M401,-185.5C401,-192.53 410.35,-188.49 414,-194.5 480.24,-303.65 366.01,-383.34 450,-479.5 450.62,-480.21 451.26,-480.91 451.92,-481.59"/>
+<polygon fill="black" stroke="black" points="449.67,-484.27 459.48,-488.26 454.3,-479.02 449.67,-484.27"/>
+</g>
+<!-- n00000087&#45;&gt;n00000079 -->
+<g id="edge74" class="edge">
+<title>n00000087:port2&#45;&gt;n00000079</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-150.5C487.55,-150.5 402.08,-423.7 450,-479.5 450.62,-480.22 451.25,-480.92 451.9,-481.61"/>
+<polygon fill="black" stroke="black" points="449.63,-484.27 459.42,-488.32 454.29,-479.05 449.63,-484.27"/>
+</g>
+<!-- n00000087&#45;&gt;n00000079 -->
+<g id="edge75" class="edge">
+<title>n00000087:port3&#45;&gt;n00000079</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-127.5C492.63,-127.5 398.98,-419.67 450,-479.5 450.62,-480.22 451.25,-480.93 451.9,-481.61"/>
+<polygon fill="black" stroke="black" points="449.61,-484.26 459.39,-488.34 454.29,-479.06 449.61,-484.26"/>
+</g>
+<!-- n00000087&#45;&gt;n00000079 -->
+<g id="edge76" class="edge">
+<title>n00000087:port4&#45;&gt;n00000079</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-104.5C497.72,-104.5 395.88,-415.63 450,-479.5 450.61,-480.22 451.24,-480.93 451.89,-481.62"/>
+<polygon fill="black" stroke="black" points="449.59,-484.26 459.36,-488.36 454.28,-479.07 449.59,-484.26"/>
+</g>
+<!-- n00000087&#45;&gt;n00000079 -->
+<g id="edge77" class="edge">
+<title>n00000087:port5&#45;&gt;n00000079</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-80.5C458.51,-80.5 421.32,-445.46 450,-479.5 450.61,-480.23 451.24,-480.93 451.88,-481.63"/>
+<polygon fill="black" stroke="black" points="449.58,-484.26 459.34,-488.38 454.28,-479.07 449.58,-484.26"/>
+</g>
+<!-- n00000087&#45;&gt;n00000079 -->
+<g id="edge78" class="edge">
+<title>n00000087:port6&#45;&gt;n00000079</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-57.5C461.06,-57.5 419.77,-443.44 450,-479.5 450.61,-480.23 451.24,-480.94 451.88,-481.63"/>
+<polygon fill="black" stroke="black" points="449.57,-484.26 459.32,-488.4 454.28,-479.08 449.57,-484.26"/>
+</g>
+<!-- n00000087&#45;&gt;n00000079 -->
+<g id="edge79" class="edge">
+<title>n00000087:port7&#45;&gt;n00000079</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-34.5C463.61,-34.5 418.22,-441.41 450,-479.5 450.61,-480.23 451.23,-480.94 451.87,-481.63"/>
+<polygon fill="black" stroke="black" points="449.56,-484.26 459.3,-488.42 454.28,-479.09 449.56,-484.26"/>
+</g>
+<!-- n00000087&#45;&gt;n00000079 -->
+<g id="edge80" class="edge">
+<title>n00000087:port8&#45;&gt;n00000079</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-11.5C466.15,-11.5 416.66,-439.39 450,-479.5 450.61,-480.23 451.23,-480.94 451.87,-481.64"/>
+<polygon fill="black" stroke="black" points="449.55,-484.25 459.28,-488.43 454.28,-479.09 449.55,-484.25"/>
+</g>
+<!-- n00000091 -->
+<g id="node8" class="node">
+<title>n00000091</title>
+<path fill="chartreuse" stroke="black" d="M232,-609.5C232,-609.5 402,-609.5 402,-609.5 408,-609.5 414,-615.5 414,-621.5 414,-621.5 414,-781.5 414,-781.5 414,-787.5 408,-793.5 402,-793.5 402,-793.5 232,-793.5 232,-793.5 226,-793.5 220,-787.5 220,-781.5 220,-781.5 220,-621.5 220,-621.5 220,-615.5 226,-609.5 232,-609.5"/>
+<text text-anchor="middle" x="233" y="-697.8" font-family="Times,serif" font-size="14.00">0</text>
+<polyline fill="none" stroke="black" points="246,-609.5 246,-793.5 "/>
+<text text-anchor="middle" x="317" y="-705.3" font-family="Times,serif" font-size="14.00">Intel IPU6 CSI2 2</text>
+<text text-anchor="middle" x="317" y="-690.3" font-family="Times,serif" font-size="14.00">/dev/v4l&#45;subdev2</text>
+<polyline fill="none" stroke="black" points="388,-609.5 388,-793.5 "/>
+<text text-anchor="middle" x="401" y="-778.3" font-family="Times,serif" font-size="14.00">1</text>
+<polyline fill="none" stroke="black" points="388,-770.5 414,-770.5 "/>
+<text text-anchor="middle" x="401" y="-755.3" font-family="Times,serif" font-size="14.00">2</text>
+<polyline fill="none" stroke="black" points="388,-747.5 414,-747.5 "/>
+<text text-anchor="middle" x="401" y="-732.3" font-family="Times,serif" font-size="14.00">3</text>
+<polyline fill="none" stroke="black" points="388,-724.5 414,-724.5 "/>
+<text text-anchor="middle" x="401" y="-709.3" font-family="Times,serif" font-size="14.00">4</text>
+<polyline fill="none" stroke="black" points="388,-701.5 414,-701.5 "/>
+<text text-anchor="middle" x="401" y="-686.3" font-family="Times,serif" font-size="14.00">5</text>
+<polyline fill="none" stroke="black" points="388,-678.5 414,-678.5 "/>
+<text text-anchor="middle" x="401" y="-663.3" font-family="Times,serif" font-size="14.00">6</text>
+<polyline fill="none" stroke="black" points="388,-655.5 414,-655.5 "/>
+<text text-anchor="middle" x="401" y="-640.3" font-family="Times,serif" font-size="14.00">7</text>
+<polyline fill="none" stroke="black" points="388,-632.5 414,-632.5 "/>
+<text text-anchor="middle" x="401" y="-617.3" font-family="Times,serif" font-size="14.00">8</text>
+</g>
+<!-- n00000091&#45;&gt;n00000001 -->
+<g id="edge81" class="edge">
+<title>n00000091:port1&#45;&gt;n00000001</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-782.5C481.81,-782.5 405.58,-530.73 450,-479.5 450.62,-478.78 451.26,-478.08 451.91,-477.4"/>
+<polygon fill="black" stroke="black" points="454.29,-479.97 459.45,-470.71 449.65,-474.73 454.29,-479.97"/>
+</g>
+<!-- n00000091&#45;&gt;n00000001 -->
+<g id="edge82" class="edge">
+<title>n00000091:port2&#45;&gt;n00000001</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-759.5C476.73,-759.5 408.68,-526.7 450,-479.5 450.63,-478.79 451.27,-478.09 451.92,-477.41"/>
+<polygon fill="black" stroke="black" points="454.3,-479.98 459.49,-470.75 449.67,-474.73 454.3,-479.98"/>
+</g>
+<!-- n00000091&#45;&gt;n00000001 -->
+<g id="edge83" class="edge">
+<title>n00000091:port3&#45;&gt;n00000001</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-736.5C471.67,-736.5 411.77,-522.68 450,-479.5 450.63,-478.79 451.27,-478.1 451.93,-477.42"/>
+<polygon fill="black" stroke="black" points="454.3,-480 459.54,-470.79 449.7,-474.72 454.3,-480"/>
+</g>
+<!-- n00000091&#45;&gt;n00000001 -->
+<g id="edge84" class="edge">
+<title>n00000091:port4&#45;&gt;n00000001</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-713.5C466.61,-713.5 414.86,-518.66 450,-479.5 450.76,-478.66 451.53,-477.84 452.33,-477.04"/>
+<polygon fill="black" stroke="black" points="454.68,-479.64 460.05,-470.51 450.16,-474.3 454.68,-479.64"/>
+</g>
+<!-- n00000091&#45;&gt;n00000001 -->
+<g id="edge85" class="edge">
+<title>n00000091:port5&#45;&gt;n00000001</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-689.5C461.35,-689.5 418.07,-514.47 450,-479.5 450.76,-478.66 451.55,-477.85 452.35,-477.06"/>
+<polygon fill="black" stroke="black" points="454.69,-479.67 460.12,-470.57 450.2,-474.3 454.69,-479.67"/>
+</g>
+<!-- n00000091&#45;&gt;n00000001 -->
+<g id="edge86" class="edge">
+<title>n00000091:port6&#45;&gt;n00000001</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-666.5C498.64,-666.5 392.3,-541.42 450,-479.5 450.77,-478.67 451.57,-477.87 452.38,-477.09"/>
+<polygon fill="black" stroke="black" points="454.7,-479.7 460.2,-470.65 450.26,-474.3 454.7,-479.7"/>
+</g>
+<!-- n00000091&#45;&gt;n00000001 -->
+<g id="edge87" class="edge">
+<title>n00000091:port7&#45;&gt;n00000001</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-643.5C488.62,-643.5 398.42,-533.43 450,-479.5 450.78,-478.68 451.59,-477.89 452.41,-477.11"/>
+<polygon fill="black" stroke="black" points="454.72,-479.75 460.31,-470.75 450.33,-474.3 454.72,-479.75"/>
+</g>
+<!-- n00000091&#45;&gt;n00000001 -->
+<g id="edge88" class="edge">
+<title>n00000091:port8&#45;&gt;n00000001</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M401,-608.5C401,-601.72 409.87,-605.88 414,-600.5 448.14,-555.98 409.76,-518.6 450,-479.5 450.95,-478.58 451.93,-477.68 452.93,-476.81"/>
+<polygon fill="black" stroke="black" points="455.16,-479.52 461.07,-470.72 450.97,-473.91 455.16,-479.52"/>
+</g>
+<!-- n00000091&#45;&gt;n00000005 -->
+<g id="edge89" class="edge">
+<title>n00000091:port1&#45;&gt;n00000005</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-782.5C494.18,-782.5 398.04,-484.56 450,-423.5 450.62,-422.78 451.25,-422.07 451.89,-421.38"/>
+<polygon fill="black" stroke="black" points="454.29,-423.94 459.38,-414.65 449.6,-418.74 454.29,-423.94"/>
+</g>
+<!-- n00000091&#45;&gt;n00000005 -->
+<g id="edge90" class="edge">
+<title>n00000091:port2&#45;&gt;n00000005</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-759.5C489.09,-759.5 401.14,-480.52 450,-423.5 450.62,-422.78 451.25,-422.08 451.9,-421.39"/>
+<polygon fill="black" stroke="black" points="454.29,-423.95 459.41,-414.67 449.62,-418.73 454.29,-423.95"/>
+</g>
+<!-- n00000091&#45;&gt;n00000005 -->
+<g id="edge91" class="edge">
+<title>n00000091:port3&#45;&gt;n00000005</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-736.5C484.01,-736.5 404.24,-476.49 450,-423.5 450.62,-422.78 451.26,-422.08 451.91,-421.4"/>
+<polygon fill="black" stroke="black" points="454.29,-423.96 459.44,-414.7 449.64,-418.73 454.29,-423.96"/>
+</g>
+<!-- n00000091&#45;&gt;n00000005 -->
+<g id="edge92" class="edge">
+<title>n00000091:port4&#45;&gt;n00000005</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-713.5C478.94,-713.5 407.33,-472.46 450,-423.5 450.62,-422.78 451.26,-422.09 451.92,-421.4"/>
+<polygon fill="black" stroke="black" points="454.3,-423.98 459.48,-414.73 449.66,-418.73 454.3,-423.98"/>
+</g>
+<!-- n00000091&#45;&gt;n00000005 -->
+<g id="edge93" class="edge">
+<title>n00000091:port5&#45;&gt;n00000005</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-689.5C473.65,-689.5 410.56,-468.25 450,-423.5 450.63,-422.79 451.27,-422.09 451.93,-421.41"/>
+<polygon fill="black" stroke="black" points="454.3,-423.99 459.52,-414.77 449.69,-418.72 454.3,-423.99"/>
+</g>
+<!-- n00000091&#45;&gt;n00000005 -->
+<g id="edge94" class="edge">
+<title>n00000091:port6&#45;&gt;n00000005</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-666.5C468.59,-666.5 413.65,-464.23 450,-423.5 450.63,-422.79 451.28,-422.1 451.94,-421.43"/>
+<polygon fill="black" stroke="black" points="454.3,-424.01 459.57,-414.82 449.72,-418.72 454.3,-424.01"/>
+</g>
+<!-- n00000091&#45;&gt;n00000005 -->
+<g id="edge95" class="edge">
+<title>n00000091:port7&#45;&gt;n00000005</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-643.5C463.54,-643.5 416.74,-460.21 450,-423.5 450.76,-422.66 451.54,-421.85 452.34,-421.05"/>
+<polygon fill="black" stroke="black" points="454.69,-423.66 460.09,-414.54 450.18,-418.3 454.69,-423.66"/>
+</g>
+<!-- n00000091&#45;&gt;n00000005 -->
+<g id="edge96" class="edge">
+<title>n00000091:port8&#45;&gt;n00000005</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M401,-608.5C401,-601.72 410.11,-606.06 414,-600.5 459.98,-534.7 394.96,-481.94 450,-423.5 450.78,-422.68 451.57,-421.88 452.39,-421.1"/>
+<polygon fill="black" stroke="black" points="454.71,-423.72 460.24,-414.69 450.28,-418.3 454.71,-423.72"/>
+</g>
+<!-- n00000091&#45;&gt;n00000009 -->
+<g id="edge97" class="edge">
+<title>n00000091:port1&#45;&gt;n00000009</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-782.5C460.28,-782.5 420.08,-402.82 450,-367.5 450.61,-366.78 451.24,-366.07 451.88,-365.39"/>
+<polygon fill="black" stroke="black" points="454.25,-367.97 459.34,-358.68 449.57,-362.76 454.25,-367.97"/>
+</g>
+<!-- n00000091&#45;&gt;n00000009 -->
+<g id="edge98" class="edge">
+<title>n00000091:port2&#45;&gt;n00000009</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-759.5C501.48,-759.5 393.29,-434.1 450,-367.5 450.61,-366.78 451.24,-366.08 451.89,-365.39"/>
+<polygon fill="black" stroke="black" points="454.25,-367.97 459.37,-358.69 449.58,-362.76 454.25,-367.97"/>
+</g>
+<!-- n00000091&#45;&gt;n00000009 -->
+<g id="edge99" class="edge">
+<title>n00000091:port3&#45;&gt;n00000009</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-736.5C496.39,-736.5 396.41,-430.08 450,-367.5 450.62,-366.78 451.25,-366.08 451.9,-365.4"/>
+<polygon fill="black" stroke="black" points="454.25,-367.98 459.39,-358.71 449.6,-362.76 454.25,-367.98"/>
+</g>
+<!-- n00000091&#45;&gt;n00000009 -->
+<g id="edge100" class="edge">
+<title>n00000091:port4&#45;&gt;n00000009</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-713.5C491.3,-713.5 399.53,-426.05 450,-367.5 450.62,-366.78 451.25,-366.08 451.9,-365.4"/>
+<polygon fill="black" stroke="black" points="454.26,-367.99 459.41,-358.74 449.61,-362.75 454.26,-367.99"/>
+</g>
+<!-- n00000091&#45;&gt;n00000009 -->
+<g id="edge101" class="edge">
+<title>n00000091:port5&#45;&gt;n00000009</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-689.5C486,-689.5 402.78,-421.86 450,-367.5 450.62,-366.79 451.26,-366.09 451.91,-365.41"/>
+<polygon fill="black" stroke="black" points="454.26,-368 459.45,-358.76 449.63,-362.75 454.26,-368"/>
+</g>
+<!-- n00000091&#45;&gt;n00000009 -->
+<g id="edge102" class="edge">
+<title>n00000091:port6&#45;&gt;n00000009</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-666.5C480.92,-666.5 405.9,-417.84 450,-367.5 450.62,-366.79 451.26,-366.09 451.92,-365.42"/>
+<polygon fill="black" stroke="black" points="454.26,-368.01 459.48,-358.79 449.65,-362.75 454.26,-368.01"/>
+</g>
+<!-- n00000091&#45;&gt;n00000009 -->
+<g id="edge103" class="edge">
+<title>n00000091:port7&#45;&gt;n00000009</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-643.5C475.85,-643.5 409.01,-413.82 450,-367.5 450.63,-366.79 451.27,-366.1 451.93,-365.42"/>
+<polygon fill="black" stroke="black" points="454.27,-368.03 459.52,-358.83 449.68,-362.75 454.27,-368.03"/>
+</g>
+<!-- n00000091&#45;&gt;n00000009 -->
+<g id="edge104" class="edge">
+<title>n00000091:port8&#45;&gt;n00000009</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M401,-608.5C401,-601.72 410.25,-606.15 414,-600.5 471.97,-513.21 379.64,-445.15 450,-367.5 450.76,-366.66 451.54,-365.85 452.34,-365.06"/>
+<polygon fill="black" stroke="black" points="454.65,-367.69 460.07,-358.58 450.16,-362.33 454.65,-367.69"/>
+</g>
+<!-- n00000091&#45;&gt;n00000075 -->
+<g id="edge105" class="edge">
+<title>n00000091:port1&#45;&gt;n00000075</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-782.5C466.26,-782.5 416.59,-353.7 450,-313.5 450.61,-312.77 451.23,-312.06 451.87,-311.36"/>
+<polygon fill="black" stroke="black" points="454.28,-313.91 459.28,-304.57 449.55,-308.75 454.28,-313.91"/>
+</g>
+<!-- n00000091&#45;&gt;n00000075 -->
+<g id="edge106" class="edge">
+<title>n00000091:port2&#45;&gt;n00000075</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-759.5C463.72,-759.5 418.15,-351.67 450,-313.5 450.61,-312.77 451.23,-312.06 451.87,-311.37"/>
+<polygon fill="black" stroke="black" points="454.28,-313.91 459.3,-304.58 449.56,-308.74 454.28,-313.91"/>
+</g>
+<!-- n00000091&#45;&gt;n00000075 -->
+<g id="edge107" class="edge">
+<title>n00000091:port3&#45;&gt;n00000075</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-736.5C461.17,-736.5 419.7,-349.65 450,-313.5 450.61,-312.77 451.24,-312.06 451.88,-311.37"/>
+<polygon fill="black" stroke="black" points="454.28,-313.92 459.32,-304.6 449.57,-308.74 454.28,-313.92"/>
+</g>
+<!-- n00000091&#45;&gt;n00000075 -->
+<g id="edge108" class="edge">
+<title>n00000091:port4&#45;&gt;n00000075</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-713.5C458.62,-713.5 421.25,-347.63 450,-313.5 450.61,-312.77 451.24,-312.07 451.88,-311.37"/>
+<polygon fill="black" stroke="black" points="454.28,-313.93 459.34,-304.61 449.58,-308.74 454.28,-313.93"/>
+</g>
+<!-- n00000091&#45;&gt;n00000075 -->
+<g id="edge109" class="edge">
+<title>n00000091:port5&#45;&gt;n00000075</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-689.5C497.94,-689.5 395.74,-377.55 450,-313.5 450.61,-312.78 451.24,-312.07 451.89,-311.38"/>
+<polygon fill="black" stroke="black" points="454.28,-313.93 459.36,-304.63 449.59,-308.74 454.28,-313.93"/>
+</g>
+<!-- n00000091&#45;&gt;n00000075 -->
+<g id="edge110" class="edge">
+<title>n00000091:port6&#45;&gt;n00000075</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-666.5C492.85,-666.5 398.85,-373.51 450,-313.5 450.62,-312.78 451.25,-312.07 451.9,-311.39"/>
+<polygon fill="black" stroke="black" points="454.29,-313.94 459.39,-304.66 449.61,-308.74 454.29,-313.94"/>
+</g>
+<!-- n00000091&#45;&gt;n00000075 -->
+<g id="edge111" class="edge">
+<title>n00000091:port7&#45;&gt;n00000075</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-643.5C487.77,-643.5 401.95,-369.47 450,-313.5 450.62,-312.78 451.25,-312.08 451.9,-311.39"/>
+<polygon fill="black" stroke="black" points="454.29,-313.95 459.41,-304.68 449.63,-308.73 454.29,-313.95"/>
+</g>
+<!-- n00000091&#45;&gt;n00000075 -->
+<g id="edge112" class="edge">
+<title>n00000091:port8&#45;&gt;n00000075</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M401,-608.5C401,-601.72 410.33,-606.2 414,-600.5 483.58,-492.41 365.48,-410.36 450,-313.5 450.62,-312.78 451.26,-312.09 451.92,-311.41"/>
+<polygon fill="black" stroke="black" points="454.3,-313.98 459.48,-304.74 449.67,-308.73 454.3,-313.98"/>
+</g>
+<!-- n00000091&#45;&gt;n00000079 -->
+<g id="edge113" class="edge">
+<title>n00000091:port1&#45;&gt;n00000079</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-782.5C523.47,-782.5 548.01,-607.83 553.46,-536.9"/>
+<polygon fill="black" stroke="black" points="556.96,-537.06 554.16,-526.84 549.97,-536.57 556.96,-537.06"/>
+</g>
+<!-- n00000091&#45;&gt;n00000079 -->
+<g id="edge114" class="edge">
+<title>n00000091:port2&#45;&gt;n00000079</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-759.5C514.91,-759.5 544.31,-603.69 552.26,-537.11"/>
+<polygon fill="black" stroke="black" points="555.77,-537.18 553.4,-526.86 548.82,-536.41 555.77,-537.18"/>
+</g>
+<!-- n00000091&#45;&gt;n00000079 -->
+<g id="edge115" class="edge">
+<title>n00000091:port3&#45;&gt;n00000079</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-736.5C506.91,-736.5 540.57,-598.14 550.96,-536.51"/>
+<polygon fill="black" stroke="black" points="554.42,-537.06 552.53,-526.63 547.5,-535.95 554.42,-537.06"/>
+</g>
+<!-- n00000091&#45;&gt;n00000079 -->
+<g id="edge116" class="edge">
+<title>n00000091:port4&#45;&gt;n00000079</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-713.5C498.86,-713.5 536.4,-592.98 549.36,-536.31"/>
+<polygon fill="black" stroke="black" points="552.78,-537.03 551.5,-526.51 545.94,-535.53 552.78,-537.03"/>
+</g>
+<!-- n00000091&#45;&gt;n00000079 -->
+<g id="edge117" class="edge">
+<title>n00000091:port5&#45;&gt;n00000079</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-689.5C490.47,-689.5 531.39,-587.85 547.19,-536.48"/>
+<polygon fill="black" stroke="black" points="550.62,-537.22 550.1,-526.63 543.91,-535.23 550.62,-537.22"/>
+</g>
+<!-- n00000091&#45;&gt;n00000079 -->
+<g id="edge118" class="edge">
+<title>n00000091:port6&#45;&gt;n00000079</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-666.5C482.92,-666.5 526.33,-581.85 544.77,-536.08"/>
+<polygon fill="black" stroke="black" points="548.06,-537.27 548.42,-526.68 541.54,-534.73 548.06,-537.27"/>
+</g>
+<!-- n00000091&#45;&gt;n00000079 -->
+<g id="edge119" class="edge">
+<title>n00000091:port7&#45;&gt;n00000079</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-643.5C475.56,-643.5 520.55,-575.52 541.63,-535.69"/>
+<polygon fill="black" stroke="black" points="544.79,-537.19 546.24,-526.7 538.56,-534 544.79,-537.19"/>
+</g>
+<!-- n00000091&#45;&gt;n00000079 -->
+<g id="edge120" class="edge">
+<title>n00000091:port8&#45;&gt;n00000079</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-620.5C468.43,-620.5 513.84,-568.6 537.46,-535.15"/>
+<polygon fill="black" stroke="black" points="540.51,-536.9 543.26,-526.67 534.73,-532.94 540.51,-536.9"/>
+</g>
+<!-- n0000009b -->
+<g id="node9" class="node">
+<title>n0000009b</title>
+<path fill="chartreuse" stroke="black" d="M232,-406.5C232,-406.5 402,-406.5 402,-406.5 408,-406.5 414,-412.5 414,-418.5 414,-418.5 414,-578.5 414,-578.5 414,-584.5 408,-590.5 402,-590.5 402,-590.5 232,-590.5 232,-590.5 226,-590.5 220,-584.5 220,-578.5 220,-578.5 220,-418.5 220,-418.5 220,-412.5 226,-406.5 232,-406.5"/>
+<text text-anchor="middle" x="233" y="-494.8" font-family="Times,serif" font-size="14.00">0</text>
+<polyline fill="none" stroke="black" points="246,-406.5 246,-590.5 "/>
+<text text-anchor="middle" x="317" y="-502.3" font-family="Times,serif" font-size="14.00">Intel IPU6 CSI2 3</text>
+<text text-anchor="middle" x="317" y="-487.3" font-family="Times,serif" font-size="14.00">/dev/v4l&#45;subdev3</text>
+<polyline fill="none" stroke="black" points="388,-406.5 388,-590.5 "/>
+<text text-anchor="middle" x="401" y="-575.3" font-family="Times,serif" font-size="14.00">1</text>
+<polyline fill="none" stroke="black" points="388,-567.5 414,-567.5 "/>
+<text text-anchor="middle" x="401" y="-552.3" font-family="Times,serif" font-size="14.00">2</text>
+<polyline fill="none" stroke="black" points="388,-544.5 414,-544.5 "/>
+<text text-anchor="middle" x="401" y="-529.3" font-family="Times,serif" font-size="14.00">3</text>
+<polyline fill="none" stroke="black" points="388,-521.5 414,-521.5 "/>
+<text text-anchor="middle" x="401" y="-506.3" font-family="Times,serif" font-size="14.00">4</text>
+<polyline fill="none" stroke="black" points="388,-498.5 414,-498.5 "/>
+<text text-anchor="middle" x="401" y="-483.3" font-family="Times,serif" font-size="14.00">5</text>
+<polyline fill="none" stroke="black" points="388,-475.5 414,-475.5 "/>
+<text text-anchor="middle" x="401" y="-460.3" font-family="Times,serif" font-size="14.00">6</text>
+<polyline fill="none" stroke="black" points="388,-452.5 414,-452.5 "/>
+<text text-anchor="middle" x="401" y="-437.3" font-family="Times,serif" font-size="14.00">7</text>
+<polyline fill="none" stroke="black" points="388,-429.5 414,-429.5 "/>
+<text text-anchor="middle" x="401" y="-414.3" font-family="Times,serif" font-size="14.00">8</text>
+</g>
+<!-- n0000009b&#45;&gt;n00000001 -->
+<g id="edge121" class="edge">
+<title>n0000009b:port1&#45;&gt;n00000001</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-579.5C461.24,-579.5 415.21,-511.45 450,-479.5 451.13,-478.46 452.29,-477.46 453.49,-476.5"/>
+<polygon fill="black" stroke="black" points="455.62,-479.28 461.78,-470.66 451.59,-473.56 455.62,-479.28"/>
+</g>
+<!-- n0000009b&#45;&gt;n00000001 -->
+<g id="edge122" class="edge">
+<title>n0000009b:port2&#45;&gt;n00000001</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-556.5C451.78,-556.5 421.03,-503.75 450,-479.5 451.34,-478.38 452.73,-477.3 454.15,-476.26"/>
+<polygon fill="black" stroke="black" points="456.13,-479.15 462.63,-470.78 452.33,-473.26 456.13,-479.15"/>
+</g>
+<!-- n0000009b&#45;&gt;n00000001 -->
+<g id="edge123" class="edge">
+<title>n0000009b:port3&#45;&gt;n00000001</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-533.5C442.84,-533.5 426.55,-496.3 450,-479.5 451.9,-478.14 453.86,-476.84 455.88,-475.61"/>
+<polygon fill="black" stroke="black" points="457.92,-478.48 465,-470.6 454.55,-472.34 457.92,-478.48"/>
+</g>
+<!-- n0000009b&#45;&gt;n00000001 -->
+<g id="edge124" class="edge">
+<title>n0000009b:port4&#45;&gt;n00000001</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-510.5C435.11,-510.5 431.33,-489.36 450,-479.5 453.47,-477.67 457.06,-475.95 460.74,-474.34"/>
+<polygon fill="black" stroke="black" points="462.11,-477.57 470.05,-470.55 459.46,-471.08 462.11,-477.57"/>
+</g>
+<!-- n0000009b&#45;&gt;n00000001 -->
+<g id="edge125" class="edge">
+<title>n0000009b:port5&#45;&gt;n00000001</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-486.5C420.8,-486.5 446.87,-480.29 474.78,-473.11"/>
+<polygon fill="black" stroke="black" points="475.9,-476.44 484.7,-470.54 474.14,-469.66 475.9,-476.44"/>
+</g>
+<!-- n0000009b&#45;&gt;n00000001 -->
+<g id="edge126" class="edge">
+<title>n0000009b:port6&#45;&gt;n00000001</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-463.5C423.77,-463.5 433.9,-463.21 444.05,-462.72"/>
+<polygon fill="black" stroke="black" points="444.4,-466.21 454.19,-462.17 444.02,-459.22 444.4,-466.21"/>
+</g>
+<!-- n0000009b&#45;&gt;n00000001 -->
+<g id="edge127" class="edge">
+<title>n0000009b:port7&#45;&gt;n00000001</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-440.5C423.76,-440.5 433.89,-440.77 444.04,-441.21"/>
+<polygon fill="black" stroke="black" points="444.01,-444.72 454.18,-441.72 444.36,-437.73 444.01,-444.72"/>
+</g>
+<!-- n0000009b&#45;&gt;n00000001 -->
+<g id="edge128" class="edge">
+<title>n0000009b:port8&#45;&gt;n00000001</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-417.5C420.59,-417.5 445.35,-423.18 472.33,-429.9"/>
+<polygon fill="black" stroke="black" points="471.79,-433.37 482.34,-432.41 473.49,-426.58 471.79,-433.37"/>
+</g>
+<!-- n0000009b&#45;&gt;n00000005 -->
+<g id="edge129" class="edge">
+<title>n0000009b:port1&#45;&gt;n00000005</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-579.5C485.16,-579.5 400.54,-474.66 450,-423.5 450.79,-422.69 451.59,-421.9 452.42,-421.13"/>
+<polygon fill="black" stroke="black" points="454.72,-423.77 460.35,-414.79 450.35,-418.3 454.72,-423.77"/>
+</g>
+<!-- n0000009b&#45;&gt;n00000005 -->
+<g id="edge130" class="edge">
+<title>n0000009b:port2&#45;&gt;n00000005</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-556.5C475.24,-556.5 406.62,-466.72 450,-423.5 450.94,-422.56 451.91,-421.66 452.9,-420.78"/>
+<polygon fill="black" stroke="black" points="455.15,-423.47 460.97,-414.62 450.9,-417.91 455.15,-423.47"/>
+</g>
+<!-- n0000009b&#45;&gt;n00000005 -->
+<g id="edge131" class="edge">
+<title>n0000009b:port3&#45;&gt;n00000005</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-533.5C465.44,-533.5 412.63,-458.85 450,-423.5 451.11,-422.45 452.26,-421.43 453.44,-420.45"/>
+<polygon fill="black" stroke="black" points="455.59,-423.22 461.66,-414.53 451.5,-417.54 455.59,-423.22"/>
+</g>
+<!-- n0000009b&#45;&gt;n00000005 -->
+<g id="edge132" class="edge">
+<title>n0000009b:port4&#45;&gt;n00000005</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-510.5C455.85,-510.5 418.53,-451.08 450,-423.5 451.32,-422.35 452.68,-421.24 454.07,-420.18"/>
+<polygon fill="black" stroke="black" points="456.09,-423.04 462.45,-414.57 452.2,-417.22 456.09,-423.04"/>
+</g>
+<!-- n0000009b&#45;&gt;n00000005 -->
+<g id="edge133" class="edge">
+<title>n0000009b:port5&#45;&gt;n00000005</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-486.5C446.25,-486.5 424.45,-443.17 450,-423.5 451.63,-422.25 453.3,-421.05 455.02,-419.91"/>
+<polygon fill="black" stroke="black" points="457.13,-422.73 463.96,-414.63 453.57,-416.7 457.13,-422.73"/>
+</g>
+<!-- n0000009b&#45;&gt;n00000005 -->
+<g id="edge134" class="edge">
+<title>n0000009b:port6&#45;&gt;n00000005</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-463.5C437.92,-463.5 429.6,-435.99 450,-423.5 452.65,-421.88 455.39,-420.35 458.21,-418.91"/>
+<polygon fill="black" stroke="black" points="459.84,-422.01 467.41,-414.59 456.87,-415.67 459.84,-422.01"/>
+</g>
+<!-- n0000009b&#45;&gt;n00000005 -->
+<g id="edge135" class="edge">
+<title>n0000009b:port7&#45;&gt;n00000005</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-440.5C431.69,-440.5 433.38,-429.58 450,-423.5 455.56,-421.46 461.34,-419.51 467.19,-417.64"/>
+<polygon fill="black" stroke="black" points="468.57,-420.88 477.1,-414.58 466.51,-414.19 468.57,-420.88"/>
+</g>
+<!-- n0000009b&#45;&gt;n00000005 -->
+<g id="edge136" class="edge">
+<title>n0000009b:port8&#45;&gt;n00000005</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-417.5C425.31,-417.5 437.06,-416.8 448.75,-415.65"/>
+<polygon fill="black" stroke="black" points="449.42,-419.1 458.98,-414.53 448.66,-412.14 449.42,-419.1"/>
+</g>
+<!-- n0000009b&#45;&gt;n00000009 -->
+<g id="edge137" class="edge">
+<title>n0000009b:port1&#45;&gt;n00000009</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-579.5C461.79,-579.5 417.65,-402.67 450,-367.5 450.76,-366.67 451.55,-365.86 452.36,-365.08"/>
+<polygon fill="black" stroke="black" points="454.66,-367.71 460.13,-358.64 450.2,-362.32 454.66,-367.71"/>
+</g>
+<!-- n0000009b&#45;&gt;n00000009 -->
+<g id="edge138" class="edge">
+<title>n0000009b:port2&#45;&gt;n00000009</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-556.5C499.51,-556.5 391.48,-429.85 450,-367.5 450.77,-366.68 451.57,-365.88 452.38,-365.1"/>
+<polygon fill="black" stroke="black" points="454.67,-367.75 460.21,-358.72 450.25,-362.32 454.67,-367.75"/>
+</g>
+<!-- n0000009b&#45;&gt;n00000009 -->
+<g id="edge139" class="edge">
+<title>n0000009b:port3&#45;&gt;n00000009</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-533.5C489.49,-533.5 397.65,-421.89 450,-367.5 450.78,-366.69 451.59,-365.9 452.41,-365.13"/>
+<polygon fill="black" stroke="black" points="454.69,-367.79 460.31,-358.81 450.32,-362.32 454.69,-367.79"/>
+</g>
+<!-- n0000009b&#45;&gt;n00000009 -->
+<g id="edge140" class="edge">
+<title>n0000009b:port4&#45;&gt;n00000009</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-510.5C479.54,-510.5 403.77,-413.96 450,-367.5 450.93,-366.56 451.89,-365.65 452.88,-364.78"/>
+<polygon fill="black" stroke="black" points="455.1,-367.49 460.92,-358.63 450.85,-361.93 455.1,-367.49"/>
+</g>
+<!-- n0000009b&#45;&gt;n00000009 -->
+<g id="edge141" class="edge">
+<title>n0000009b:port5&#45;&gt;n00000009</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-486.5C469.26,-486.5 410.11,-405.74 450,-367.5 451.1,-366.44 452.24,-365.42 453.42,-364.44"/>
+<polygon fill="black" stroke="black" points="455.54,-367.22 461.58,-358.52 451.43,-361.56 455.54,-367.22"/>
+</g>
+<!-- n0000009b&#45;&gt;n00000009 -->
+<g id="edge142" class="edge">
+<title>n0000009b:port6&#45;&gt;n00000009</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-463.5C459.57,-463.5 416.1,-397.95 450,-367.5 451.3,-366.33 452.64,-365.21 454.03,-364.14"/>
+<polygon fill="black" stroke="black" points="456.02,-367.02 462.33,-358.51 452.09,-361.23 456.02,-367.02"/>
+</g>
+<!-- n0000009b&#45;&gt;n00000009 -->
+<g id="edge143" class="edge">
+<title>n0000009b:port7&#45;&gt;n00000009</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-440.5C450.18,-440.5 421.92,-390.31 450,-367.5 451.56,-366.23 453.18,-365.02 454.84,-363.87"/>
+<polygon fill="black" stroke="black" points="456.79,-366.77 463.48,-358.56 453.13,-360.81 456.79,-366.77"/>
+</g>
+<!-- n0000009b&#45;&gt;n00000009 -->
+<g id="edge144" class="edge">
+<title>n0000009b:port8&#45;&gt;n00000009</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-417.5C441.38,-417.5 427.39,-382.94 450,-367.5 452.18,-366.01 454.43,-364.61 456.74,-363.28"/>
+<polygon fill="black" stroke="black" points="458.65,-366.23 465.94,-358.54 455.44,-360.01 458.65,-366.23"/>
+</g>
+<!-- n0000009b&#45;&gt;n00000075 -->
+<g id="edge145" class="edge">
+<title>n0000009b:port1&#45;&gt;n00000075</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-579.5C473.65,-579.5 410.56,-358.25 450,-313.5 450.63,-312.79 451.27,-312.09 451.93,-311.41"/>
+<polygon fill="black" stroke="black" points="454.3,-313.99 459.52,-304.77 449.69,-308.72 454.3,-313.99"/>
+</g>
+<!-- n0000009b&#45;&gt;n00000075 -->
+<g id="edge146" class="edge">
+<title>n0000009b:port2&#45;&gt;n00000075</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-556.5C468.59,-556.5 413.65,-354.23 450,-313.5 450.63,-312.79 451.28,-312.1 451.94,-311.43"/>
+<polygon fill="black" stroke="black" points="454.3,-314.01 459.57,-304.82 449.72,-308.72 454.3,-314.01"/>
+</g>
+<!-- n0000009b&#45;&gt;n00000075 -->
+<g id="edge147" class="edge">
+<title>n0000009b:port3&#45;&gt;n00000075</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-533.5C463.54,-533.5 416.74,-350.21 450,-313.5 450.76,-312.66 451.54,-311.85 452.34,-311.05"/>
+<polygon fill="black" stroke="black" points="454.69,-313.66 460.09,-304.54 450.18,-308.3 454.69,-313.66"/>
+</g>
+<!-- n0000009b&#45;&gt;n00000075 -->
+<g id="edge148" class="edge">
+<title>n0000009b:port4&#45;&gt;n00000075</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-510.5C503.01,-510.5 389.63,-378.9 450,-313.5 450.77,-312.67 451.56,-311.86 452.37,-311.07"/>
+<polygon fill="black" stroke="black" points="454.7,-313.69 460.16,-304.61 450.23,-308.3 454.7,-313.69"/>
+</g>
+<!-- n0000009b&#45;&gt;n00000075 -->
+<g id="edge149" class="edge">
+<title>n0000009b:port5&#45;&gt;n00000075</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-486.5C492.54,-486.5 396.03,-370.55 450,-313.5 450.78,-312.68 451.58,-311.88 452.4,-311.1"/>
+<polygon fill="black" stroke="black" points="454.71,-313.73 460.26,-304.7 450.3,-308.3 454.71,-313.73"/>
+</g>
+<!-- n0000009b&#45;&gt;n00000075 -->
+<g id="edge150" class="edge">
+<title>n0000009b:port6&#45;&gt;n00000075</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-463.5C482.56,-463.5 402.13,-362.58 450,-313.5 450.93,-312.55 451.88,-311.63 452.86,-310.74"/>
+<polygon fill="black" stroke="black" points="455.12,-313.42 460.85,-304.5 450.82,-307.9 455.12,-313.42"/>
+</g>
+<!-- n0000009b&#45;&gt;n00000075 -->
+<g id="edge151" class="edge">
+<title>n0000009b:port7&#45;&gt;n00000075</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-440.5C472.67,-440.5 408.19,-354.66 450,-313.5 450.95,-312.57 451.92,-311.67 452.92,-310.8"/>
+<polygon fill="black" stroke="black" points="455.15,-313.49 461.02,-304.67 450.93,-307.91 455.15,-313.49"/>
+</g>
+<!-- n0000009b&#45;&gt;n00000075 -->
+<g id="edge152" class="edge">
+<title>n0000009b:port8&#45;&gt;n00000075</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-417.5C462.91,-417.5 414.18,-346.81 450,-313.5 451.12,-312.46 452.28,-311.45 453.47,-310.48"/>
+<polygon fill="black" stroke="black" points="455.61,-313.25 461.73,-304.6 451.55,-307.55 455.61,-313.25"/>
+</g>
+<!-- n0000009b&#45;&gt;n00000079 -->
+<g id="edge153" class="edge">
+<title>n0000009b:port1&#45;&gt;n00000079</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-579.5C456.1,-579.5 498.29,-553.73 525.4,-533.02"/>
+<polygon fill="black" stroke="black" points="527.62,-535.73 533.31,-526.79 523.29,-530.23 527.62,-535.73"/>
+</g>
+<!-- n0000009b&#45;&gt;n00000079 -->
+<g id="edge154" class="edge">
+<title>n0000009b:port2&#45;&gt;n00000079</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-556.5C448.08,-556.5 484.35,-543.57 511.57,-531"/>
+<polygon fill="black" stroke="black" points="513.29,-534.05 520.8,-526.58 510.27,-527.74 513.29,-534.05"/>
+</g>
+<!-- n0000009b&#45;&gt;n00000079 -->
+<g id="edge155" class="edge">
+<title>n0000009b:port3&#45;&gt;n00000079</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-533.5C432.27,-533.5 451.66,-531.36 470.02,-528.31"/>
+<polygon fill="black" stroke="black" points="470.86,-531.72 480.1,-526.53 469.64,-524.82 470.86,-531.72"/>
+</g>
+<!-- n0000009b&#45;&gt;n00000079 -->
+<g id="edge156" class="edge">
+<title>n0000009b:port4&#45;&gt;n00000079</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-510.5C422.36,-510.5 431,-510.45 439.69,-510.35"/>
+<polygon fill="black" stroke="black" points="439.95,-513.85 449.91,-510.23 439.86,-506.85 439.95,-513.85"/>
+</g>
+<!-- n0000009b&#45;&gt;n00000079 -->
+<g id="edge157" class="edge">
+<title>n0000009b:port5&#45;&gt;n00000079</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-486.5C422.72,-486.5 431.71,-486.9 440.74,-487.58"/>
+<polygon fill="black" stroke="black" points="440.66,-491.09 450.92,-488.48 441.27,-484.12 440.66,-491.09"/>
+</g>
+<!-- n0000009b&#45;&gt;n00000079 -->
+<g id="edge158" class="edge">
+<title>n0000009b:port6&#45;&gt;n00000079</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-463.5C431.51,-463.5 433.49,-473.67 450,-479.5 455.9,-481.58 462.02,-483.59 468.23,-485.52"/>
+<polygon fill="black" stroke="black" points="467.43,-488.93 478.01,-488.47 469.45,-482.23 467.43,-488.93"/>
+</g>
+<!-- n0000009b&#45;&gt;n00000079 -->
+<g id="edge159" class="edge">
+<title>n0000009b:port7&#45;&gt;n00000079</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-440.5C437.59,-440.5 429.8,-467.31 450,-479.5 452.79,-481.18 455.67,-482.76 458.64,-484.25"/>
+<polygon fill="black" stroke="black" points="457.18,-487.43 467.72,-488.44 460.11,-481.08 457.18,-487.43"/>
+</g>
+<!-- n0000009b&#45;&gt;n00000079 -->
+<g id="edge160" class="edge">
+<title>n0000009b:port8&#45;&gt;n00000079</title>
+<path fill="none" stroke="black" stroke-dasharray="5,2" d="M414,-417.5C445.86,-417.5 424.69,-460.15 450,-479.5 451.8,-480.87 453.65,-482.18 455.56,-483.42"/>
+<polygon fill="black" stroke="black" points="453.84,-486.47 464.25,-488.47 457.36,-480.42 453.84,-486.47"/>
+</g>
+<!-- n00000865 -->
+<g id="node10" class="node">
+<title>n00000865</title>
+<path fill="#00cdcd" stroke="black" d="M12,-682.5C12,-682.5 172,-682.5 172,-682.5 178,-682.5 184,-688.5 184,-694.5 184,-694.5 184,-708.5 184,-708.5 184,-714.5 178,-720.5 172,-720.5 172,-720.5 12,-720.5 12,-720.5 6,-720.5 0,-714.5 0,-708.5 0,-708.5 0,-694.5 0,-694.5 0,-688.5 6,-682.5 12,-682.5"/>
+<text text-anchor="middle" x="10.5" y="-697.8" font-family="Times,serif" font-size="14.00"> </text>
+<polyline fill="none" stroke="black" points="21,-682.5 21,-720.5 "/>
+<text text-anchor="middle" x="89.5" y="-705.3" font-family="Times,serif" font-size="14.00">ov01a10 3&#45;0036</text>
+<text text-anchor="middle" x="89.5" y="-690.3" font-family="Times,serif" font-size="14.00">/dev/v4l&#45;subdev4</text>
+<polyline fill="none" stroke="black" points="158,-682.5 158,-720.5 "/>
+<text text-anchor="middle" x="171" y="-697.8" font-family="Times,serif" font-size="14.00">0</text>
+</g>
+<!-- n00000865&#45;&gt;n00000091 -->
+<g id="edge161" class="edge">
+<title>n00000865:port0&#45;&gt;n00000091:port0</title>
+<path fill="none" stroke="black" d="M184,-701.5C196,-701.5 201.25,-701.5 209.88,-701.5"/>
+<polygon fill="black" stroke="black" points="210,-705 220,-701.5 210,-698 210,-705"/>
+</g>
+</g>
+</svg>
diff --git a/Documentation/admin-guide/media/v4l-drivers.rst b/Documentation/admin-guide/media/v4l-drivers.rst
index 1c41f87c3917..f6328a242cbe 100644
--- a/Documentation/admin-guide/media/v4l-drivers.rst
+++ b/Documentation/admin-guide/media/v4l-drivers.rst
@@ -16,6 +16,7 @@ Video4Linux (V4L) driver-specific documentation
 	imx
 	imx7
 	ipu3
+	ipu6-isys
 	ivtv
 	omap3isp
 	omap4_camera
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 86+ messages in thread

* [PATCH v2 15/15] Documentation: add documentation of Intel IPU6 driver and hardware overview
  2023-10-24 11:29 [PATCH v2 00/15] Intel IPU6 and IPU6 input system drivers bingbu.cao
                   ` (13 preceding siblings ...)
  2023-10-24 11:29 ` [PATCH v2 14/15] Documentation: add Intel IPU6 ISYS driver admin-guide doc bingbu.cao
@ 2023-10-24 11:29 ` bingbu.cao
  2023-10-25 12:09   ` Sakari Ailus
  2023-11-08 11:59 ` [PATCH v2 00/15] Intel IPU6 and IPU6 input system drivers Hans de Goede
  2024-02-07  7:00 ` Sakari Ailus
  16 siblings, 1 reply; 86+ messages in thread
From: bingbu.cao @ 2023-10-24 11:29 UTC (permalink / raw)
  To: linux-media, sakari.ailus, laurent.pinchart
  Cc: andriy.shevchenko, hdegoede, ilpo.jarvinen, andreaskleist,
	claus.stovgaard, tfiga, senozhatsky, tomi.valkeinen, bingbu.cao,
	bingbu.cao, tian.shu.qiu, hongju.wang

From: Bingbu Cao <bingbu.cao@intel.com>

Add a documentation for an overview of IPU6 hardware and describe the main
the components of IPU6 driver.

Signed-off-by: Bingbu Cao <bingbu.cao@intel.com>
---
 .../driver-api/media/drivers/index.rst        |   1 +
 .../driver-api/media/drivers/ipu6.rst         | 205 ++++++++++++++++++
 2 files changed, 206 insertions(+)
 create mode 100644 Documentation/driver-api/media/drivers/ipu6.rst

diff --git a/Documentation/driver-api/media/drivers/index.rst b/Documentation/driver-api/media/drivers/index.rst
index c4123a16b5f9..7f6f3dcd5c90 100644
--- a/Documentation/driver-api/media/drivers/index.rst
+++ b/Documentation/driver-api/media/drivers/index.rst
@@ -26,6 +26,7 @@ Video4Linux (V4L) drivers
 	vimc-devel
 	zoran
 	ccs/ccs
+	ipu6
 
 
 Digital TV drivers
diff --git a/Documentation/driver-api/media/drivers/ipu6.rst b/Documentation/driver-api/media/drivers/ipu6.rst
new file mode 100644
index 000000000000..2685e4a0d7ba
--- /dev/null
+++ b/Documentation/driver-api/media/drivers/ipu6.rst
@@ -0,0 +1,205 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+==================
+Intel IPU6 Driver
+==================
+
+Author: Bingbu Cao <bingbu.cao@intel.com>
+
+Overview
+=========
+
+Intel IPU6 is the sixth generation of Intel Image Processing Unit used in some
+Intel Chipsets such as Tiger Lake, Jasper Lake, Alder Lake, Raptor Lake and
+Meteor Lake. IPU6 consists of two major systems - Input System (IS) and
+Processing System (PS). IPU6 are visible on the PCI bus as a single device,
+it can be found by ``lspci``:
+
+``0000:00:05.0 Multimedia controller: Intel Corporation Device xxxx (rev xx)``
+
+IPU6 has a 16 MB BAR in PCI configuration Space for MMIO registers which is
+visible for driver.
+
+Buttress
+=========
+
+The IPU6 is connecting to the system fabric with ``Buttress`` which is enabling
+host driver to control the IPU6, it also allows IPU6 access the system memory to
+store and load frame pixel streams and any other metadata.
+
+``Buttress`` mainly manages several system functionalities - power management,
+interrupt handling, firmware authentication and global timer sync.
+
+IS and PS Power flow
+---------------------------
+
+IPU6 driver initialize the IS and PS power up or down request by setting the
+Buttress frequency control register for IS and PS -
+``IPU6_BUTTRESS_REG_IS_FREQ_CTL`` and ``IPU6_BUTTRESS_REG_PS_FREQ_CTL`` in
+function:
+
+.. c:function:: int ipu6_buttress_power(..., bool on)
+
+Buttress forwards the request to Punit, after Punit execute the power up flow,
+buttress indicates driver that IS or PS is powered up by updating the power
+status registers.
+
+.. Note:: IS power up needs take place prior to PS power up, IS power down needs
+	  take place after PS power down due to hardware limitation.
+
+
+Interrupt
+------------
+
+IPU6 interrupt can be generated as MSI or INTA, interrupt will be triggered
+when IS, PS, Buttress event or error happen, driver can get the interrupt
+cause by reading the interrupt status register ``BUTTRESS_REG_ISR_STATUS``,
+driver firstly clear the irq status and then call specific IS or PS irq handler.
+
+.. c:function:: irqreturn_t ipu6_buttress_isr(int irq, ...)
+
+Security and firmware authentication
+-------------------------------------
+To address the IPU6 firmware security concerns, the IPU6 firmware needs to
+undergo an authentication process before it is allowed to executed on the IPU6
+internal processors. Driver will work with Converged Security Engine (CSE) to
+complete authentication process. CSE is responsible of authenticating the
+IPU6 firmware, the authenticated firmware binary is copied into an isolated
+memory region. Firmware authentication process is implemented by CSE following
+an IPC handshake with driver. There are some Buttress registers used by CSE and
+driver to communicate with each other as IPC messages.
+
+.. c:function:: int ipu6_buttress_authenticate(...)
+
+Global timer sync
+------------------
+IPU driver initiates a Hammock Harbor synchronization flow each time it starts
+camera operation. IPU will synchronizes an internal counter in the Buttress
+with a copy of SoC time, this counter keeps the updated time until camera
+operation is stopped. Driver can use this time counter to calibrate the
+timestamp based on the timestamp in response event from firmware.
+
+.. c:function:: int ipu6_buttress_start_tsc_sync(...)
+
+
+DMA and MMU
+============
+
+IPU6 has its own scalar processor where the firmware run at, it has
+an internal 32-bits virtual address space. IPU6 has MMU address translation
+hardware to allow that scalar process access the internal memory and external
+system memory through IPU6 virtual address. The address translation is
+based on two levels of page lookup tables stored in system memory which are
+maintained by IPU6 driver. IPU6 driver sets the level-1 page table base address
+to MMU register and allow MMU to lookup the page table.
+
+IPU6 driver exports its own DMA operations. Driver will update the page table
+entries for each DMA operation and invalidate the MMU TLB after each unmap and
+free.
+
+.. code-block:: none
+
+    const struct dma_map_ops ipu6_dma_ops = {
+	   .alloc = ipu6_dma_alloc,
+	   .free = ipu6_dma_free,
+	   .mmap = ipu6_dma_mmap,
+	   .map_sg = ipu6_dma_map_sg,
+	   .unmap_sg = ipu6_dma_unmap_sg,
+	   ...
+    };
+
+.. Note:: IPU6 MMU works behind IOMMU, so for each IPU6 DMA ops, driver will
+	  call generic PCI DMA ops to ask IOMMU to do the additional mapping
+	  if VT-d enabled.
+
+
+Firmware file format
+=====================
+
+IPU6 release the firmware in Code Partition Directory (CPD) file format. The
+CPD firmware contains a CPD header, several CPD entries and CPD components.
+CPD component includes 3 entries - manifest, metadata and module data. Manifest
+and metadata are defined by CSE and used by CSE for authentication. Module data
+is defined by IPU6 which holds the binary data of firmware called package
+directory. IPU6 driver (``ipu6-cpd.c``) parses and validates the CPD firmware
+file and get the package directory binary data of IPU6 firmware, copy it to
+specific DMA buffer and sets its base address to Buttress ``FW_SOURCE_BASE``
+register, CSE will do authentication for this firmware binary.
+
+
+Syscom interface
+================
+
+IPU6 driver communicates with firmware via syscom ABI. Syscom is an
+inter-processor communication mechanism between IPU scalar processor and CPU.
+There are a number of resources shared between firmware and software.
+A system memory region where the message queues reside, firmware can access the
+memory region via IPU MMU. Syscom queues are FIFO fixed depth queues with
+configurable elements ``token`` (message). There is also a common IPU MMIO
+registers where the queue read and write indices reside. Software and firmware
+work as producer and consumer of tokens in queue, and update the write and read
+indices separately when sending or receiving each message.
+
+IPU6 driver must prepare and configure the number of input and output queues,
+configure the count of tokens per queue and the size of per token before
+initiate and start the communication with firmware, firmware and software must
+use same configurations. IPU6 Buttress has a number of firmware boot parameter
+registers which can be used to store the address of configuration and initiate
+the Syscom state, then driver can request firmware to start and run via setting
+the scalar processor control status register.
+
+
+Input System
+==============
+
+IPU6 input system consists of MIPI D-PHY and several CSI receiver controllers,
+it can capture image pixel data from camera sensors or other MIPI CSI output
+devices.
+
+DPHYs and CSI2 ports lane mapping
+---------------------------------
+
+IPU6 integrates different D-PHY IPs on different SoCs, on Tiger Lake and Alder
+Lake, IPU6 integrates MCD10 D-PHY, IPU6SE on Jasper Lake integrates JSL D-PHY
+and IPU6EP on Meteor Lake integrates a Synopsys DWC D-PHY. There is an adaption
+layer between D-PHY and CSI receiver controller which includes port
+configuration, PHY wrapper or private test interfaces for D-PHY. There are 3
+D-PHY drivers ``ipu6-isys-mcd-phy.c``, ``ipu6-isys-jsl-phy.c`` and
+``ipu6-isys-dwc-phy.c`` program the above 3 D-PHYs in IPU6.
+
+Different IPU6 version has different DPHY lanes mappings, On Tiger Lake, there
+are 12 data lanes and 8 clock lanes, IPU6 support maximum 8 CSI2 ports, see
+the ppi mmapping in ``ipu6-isys-mcd-phy.c`` for more information. On Jasper Lake
+and Alder Lake, DPHY has 8 data lanes and 4 clock lanes, IPU6 support maximum 4
+CSI2 ports. For Meteor Lake, DPHY has 12 data lanes and 6 clock lanes, IPU6
+support maximum 6 CSI2 ports.
+
+.. Note:: Each adjacent CSI ports work as a pair and share the data lanes.
+	  For example, for CSI port 0 and 1, CSI port 0 support maximum 4
+	  data lanes, CSI port 1 support maximum 2 data lanes, CSI port 0
+	  with 2 data lanes can work together with CSI port 1 with 2 data lanes.
+	  If trying to use CSI port 0 with 4 lanes, CSI port 1 will not be
+	  available as the 4 data lanes are shared by CSI port 0 and 1. Same
+	  scenario is also applied for CSI port 2/3, 4/5 and 7/8.
+
+IS firmware ABIs
+----------------
+
+IPU6 firmware define a series of ABIs to software. In general, software firstly
+prepare the stream configuration ``struct ipu6_fw_isys_stream_cfg_data_abi``
+and send the configuration to firmware via sending ``STREAM_OPEN`` command.
+Stream configuration includes input pins and output pins, input pin
+``struct ipu6_fw_isys_input_pin_info_abi`` defines the resolution and data type
+of input source, output pin ``struct ipu6_fw_isys_output_pin_info_abi``
+defines the output resolution, stride and frame format, etc. Once driver get the
+interrupt from firmware that indicates stream open successfully, driver will
+send the ``STREAM_START`` and ``STREAM_CAPTURE`` command to request firmware to
+start capturing image frames. ``STREAM_CAPTURE`` command queues the buffers to
+firmware with ``struct ipu6_fw_isys_frame_buff_set``, software then wait the
+interrupt and response from firmware, ``PIN_DATA_READY`` means data ready
+on specific output pin and then software return the buffers to user.
+
+.. Note:: See Documentation/admin-guide/media/ipu6-isys.rst for how to do
+	  capture by IPU6 IS driver.
+
+
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 86+ messages in thread

* Re: [PATCH v2 02/15] media: intel/ipu6: add IPU auxiliary devices
  2023-10-24 11:29 ` [PATCH v2 02/15] media: intel/ipu6: add IPU auxiliary devices bingbu.cao
@ 2023-10-24 12:58   ` Andy Shevchenko
  2023-10-25  7:14     ` Bingbu Cao
  0 siblings, 1 reply; 86+ messages in thread
From: Andy Shevchenko @ 2023-10-24 12:58 UTC (permalink / raw)
  To: bingbu.cao
  Cc: linux-media, sakari.ailus, laurent.pinchart, hdegoede,
	ilpo.jarvinen, andreaskleist, claus.stovgaard, tfiga,
	senozhatsky, tomi.valkeinen, bingbu.cao, tian.shu.qiu,
	hongju.wang

On Tue, Oct 24, 2023 at 07:29:11PM +0800, bingbu.cao@intel.com wrote:
> From: Bingbu Cao <bingbu.cao@intel.com>
> 
> Even the IPU input system and processing system are in a single PCI
> device, each system has its own power sequence, the processing system
> power up depends on the input system power up.
> 
> Besides, input system and processing system have their own MMU
> hardware for IPU DMA address mapping.
> 
> Register the IS/PS devices on auxiliary bus and attach power domain
> to implement the power sequence dependency.

...

Seems again poor / random list of header inclusions...
Please, go through your files and use IWYU (Include What You Use) principle
in them.

> +#include <linux/pci.h>

auxiliary_bus.h, err.h, list.h, mutex.h, dev_printk.h, slab.h, dma-mapping.h are missing.
You are lucky it does compile.

...

> +#ifndef IPU6_BUS_H
> +#define IPU6_BUS_H
> +
> +#include <linux/auxiliary_bus.h>

...Especially for headers which will affect the compilation time.

> +#include <linux/pci.h>

This is not used.

...

> +	struct list_head list;

+ types.h

> +	struct sg_table fw_sgt;

+ scatterlist.h

> +	dma_addr_t pkg_dir_dma_addr;

types.h

...

> +struct ipu6_auxdrv_data {
> +	irqreturn_t (*isr)(struct ipu6_bus_device *adev);
> +	irqreturn_t (*isr_threaded)(struct ipu6_bus_device *adev);

irqreturn.h

> +	bool wake_isr_thread;
> +};

...

> +#define to_ipu6_bus_device(_dev) container_of(to_auxiliary_dev(_dev), \
> +					      struct ipu6_bus_device, auxdev)
> +#define auxdev_to_adev(_auxdev) container_of(_auxdev, \
> +					     struct ipu6_bus_device, auxdev)

container_of.h

Also, can you reformat to be more readable like

#define auxdev_to_adev(_auxdev)					\
	container_of(_auxdev, struct ipu6_bus_device, auxdev)

> +#define ipu6_bus_get_drvdata(adev) dev_get_drvdata(&(adev)->auxdev.dev)

device.h

...

> +	ret = dma_set_max_seg_size(&pdev->dev, UINT_MAX);
> +	if (ret)
> +		return dev_err_probe(&pdev->dev, ret,
> +				     "Failed to set max_seg_size\n");

With the help of

	struct device *dev = &pdev->dev;

this and other lines become neater


	ret = dma_set_max_seg_size(dev, _DMA_SEGMENT_SIZE); // as I commented earlier about
	if (ret)
		return dev_err_probe(dev, ret, "Failed to set max_seg_size\n");

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 86+ messages in thread

* Re: [PATCH v2 12/15] media: add Kconfig and Makefile for IPU6
  2023-10-24 11:29 ` [PATCH v2 12/15] media: add Kconfig and Makefile for IPU6 bingbu.cao
@ 2023-10-24 13:04   ` Andy Shevchenko
  2023-10-25  8:43     ` Bingbu Cao
  2023-10-25 12:21     ` Sakari Ailus
  0 siblings, 2 replies; 86+ messages in thread
From: Andy Shevchenko @ 2023-10-24 13:04 UTC (permalink / raw)
  To: bingbu.cao
  Cc: linux-media, sakari.ailus, laurent.pinchart, hdegoede,
	ilpo.jarvinen, andreaskleist, claus.stovgaard, tfiga,
	senozhatsky, tomi.valkeinen, bingbu.cao, tian.shu.qiu,
	hongju.wang

On Tue, Oct 24, 2023 at 07:29:21PM +0800, bingbu.cao@intel.com wrote:
> From: Bingbu Cao <bingbu.cao@intel.com>
> 
> Add IPU6 support in Kconfig and Makefile, with this patch you can
> build the Intel IPU6 and input system modules by select the
> CONFIG_VIDEO_INTEL_IPU6 in config.

...

> +	depends on X86 && X86_64

How is that? One is a superset of the other IIUC.

...

> +intel-ipu6-objs				+= ipu6.o \

+= doesn't seem right.
Besides that 'objs' is for user space, in kernel we use 'y'.

> +					ipu6-bus.o \
> +					ipu6-dma.o \
> +					ipu6-mmu.o \
> +					ipu6-buttress.o \
> +					ipu6-cpd.o \
> +					ipu6-fw-com.o
> +
> +obj-$(CONFIG_VIDEO_INTEL_IPU6)		+= intel-ipu6.o
> +
> +intel-ipu6-isys-objs			+= ipu6-isys.o \

Ditto.

> +					ipu6-isys-csi2.o \
> +					ipu6-fw-isys.o \
> +					ipu6-isys-video.o \
> +					ipu6-isys-queue.o \
> +					ipu6-isys-subdev.o \
> +					ipu6-isys-mcd-phy.o \
> +					ipu6-isys-jsl-phy.o \
> +					ipu6-isys-dwc-phy.o
> +
> +obj-$(CONFIG_VIDEO_INTEL_IPU6)		+= intel-ipu6-isys.o

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 86+ messages in thread

* Re: [PATCH v2 02/15] media: intel/ipu6: add IPU auxiliary devices
  2023-10-24 12:58   ` Andy Shevchenko
@ 2023-10-25  7:14     ` Bingbu Cao
  2023-10-25  8:35       ` Hans de Goede
  2023-10-25 19:57       ` Andy Shevchenko
  0 siblings, 2 replies; 86+ messages in thread
From: Bingbu Cao @ 2023-10-25  7:14 UTC (permalink / raw)
  To: Andy Shevchenko, bingbu.cao
  Cc: linux-media, sakari.ailus, laurent.pinchart, hdegoede,
	ilpo.jarvinen, andreaskleist, claus.stovgaard, tfiga,
	senozhatsky, tomi.valkeinen, tian.shu.qiu, hongju.wang

Andy,

Thanks for your review.

On 10/24/23 8:58 PM, Andy Shevchenko wrote:
> On Tue, Oct 24, 2023 at 07:29:11PM +0800, bingbu.cao@intel.com wrote:
>> From: Bingbu Cao <bingbu.cao@intel.com>
>>
>> Even the IPU input system and processing system are in a single PCI
>> device, each system has its own power sequence, the processing system
>> power up depends on the input system power up.
>>
>> Besides, input system and processing system have their own MMU
>> hardware for IPU DMA address mapping.
>>
>> Register the IS/PS devices on auxiliary bus and attach power domain
>> to implement the power sequence dependency.
> 
> ...
> 
> Seems again poor / random list of header inclusions...
> Please, go through your files and use IWYU (Include What You Use) principle
> in them.
> 
>> +#include <linux/pci.h>
> 
> auxiliary_bus.h, err.h, list.h, mutex.h, dev_printk.h, slab.h, dma-mapping.h are missing.
> You are lucky it does compile.

auxiliary_bus.h is included in ipu6-bus.h, list.h, mutex.h dev_printk.h are
included in device.h, dma-mapping.h and scatterlist.h are included in pci.h.

I am a little confused about the rule, do you mean we need include the
generic headers we need even it is included in others header?

> 
> ...
> 
>> +#ifndef IPU6_BUS_H
>> +#define IPU6_BUS_H
>> +
>> +#include <linux/auxiliary_bus.h>
> 
> ...Especially for headers which will affect the compilation time.
> 
>> +#include <linux/pci.h>
> 
> This is not used.

Do you mean it just need a 'struct pci_dev;' ?
> 
> ...
> 
>> +	struct list_head list;
> 
> + types.h
> 
>> +	struct sg_table fw_sgt;
> 
> + scatterlist.h
> 
>> +	dma_addr_t pkg_dir_dma_addr;
> 
> types.h
> 
> ...
> 
>> +struct ipu6_auxdrv_data {
>> +	irqreturn_t (*isr)(struct ipu6_bus_device *adev);
>> +	irqreturn_t (*isr_threaded)(struct ipu6_bus_device *adev);
> 
> irqreturn.h
> 
>> +	bool wake_isr_thread;
>> +};
> 
> ...
> 
>> +#define to_ipu6_bus_device(_dev) container_of(to_auxiliary_dev(_dev), \
>> +					      struct ipu6_bus_device, auxdev)
>> +#define auxdev_to_adev(_auxdev) container_of(_auxdev, \
>> +					     struct ipu6_bus_device, auxdev)
> 
> container_of.h
> 
> Also, can you reformat to be more readable like
> 
> #define auxdev_to_adev(_auxdev)					\
> 	container_of(_auxdev, struct ipu6_bus_device, auxdev)

Ack.

> 
>> +#define ipu6_bus_get_drvdata(adev) dev_get_drvdata(&(adev)->auxdev.dev)
> 
> device.h
> 
> ...
> 
>> +	ret = dma_set_max_seg_size(&pdev->dev, UINT_MAX);
>> +	if (ret)
>> +		return dev_err_probe(&pdev->dev, ret,
>> +				     "Failed to set max_seg_size\n");
> 
> With the help of
> 
> 	struct device *dev = &pdev->dev;
> 
> this and other lines become neater
> 
> 
> 	ret = dma_set_max_seg_size(dev, _DMA_SEGMENT_SIZE); // as I commented earlier about
> 	if (ret)
> 		return dev_err_probe(dev, ret, "Failed to set max_seg_size\n");

Ack.

> 

-- 
Best regards,
Bingbu Cao

^ permalink raw reply	[flat|nested] 86+ messages in thread

* Re: [PATCH v2 02/15] media: intel/ipu6: add IPU auxiliary devices
  2023-10-25  7:14     ` Bingbu Cao
@ 2023-10-25  8:35       ` Hans de Goede
  2023-10-25 19:57       ` Andy Shevchenko
  1 sibling, 0 replies; 86+ messages in thread
From: Hans de Goede @ 2023-10-25  8:35 UTC (permalink / raw)
  To: Bingbu Cao, Andy Shevchenko, bingbu.cao
  Cc: linux-media, sakari.ailus, laurent.pinchart, ilpo.jarvinen,
	andreaskleist, claus.stovgaard, tfiga, senozhatsky,
	tomi.valkeinen, tian.shu.qiu, hongju.wang

Hi,

On 10/25/23 09:14, Bingbu Cao wrote:
> Andy,
> 
> Thanks for your review.
> 
> On 10/24/23 8:58 PM, Andy Shevchenko wrote:
>> On Tue, Oct 24, 2023 at 07:29:11PM +0800, bingbu.cao@intel.com wrote:
>>> From: Bingbu Cao <bingbu.cao@intel.com>
>>>
>>> Even the IPU input system and processing system are in a single PCI
>>> device, each system has its own power sequence, the processing system
>>> power up depends on the input system power up.
>>>
>>> Besides, input system and processing system have their own MMU
>>> hardware for IPU DMA address mapping.
>>>
>>> Register the IS/PS devices on auxiliary bus and attach power domain
>>> to implement the power sequence dependency.
>>
>> ...
>>
>> Seems again poor / random list of header inclusions...
>> Please, go through your files and use IWYU (Include What You Use) principle
>> in them.
>>
>>> +#include <linux/pci.h>
>>
>> auxiliary_bus.h, err.h, list.h, mutex.h, dev_printk.h, slab.h, dma-mapping.h are missing.
>> You are lucky it does compile.
> 
> auxiliary_bus.h is included in ipu6-bus.h, list.h, mutex.h dev_printk.h are
> included in device.h, dma-mapping.h and scatterlist.h are included in pci.h.
> 
> I am a little confused about the rule, do you mean we need include the
> generic headers we need even it is included in others header?

Yes you must *not* rely on other headers including headers from
which you directly use symbols.

People are working on reducing the number of includes inside headers
to speed up building the kernel because including unnecessary headers
inside another header has a big impact on build time.

Regards,

Hans





> 
>>
>> ...
>>
>>> +#ifndef IPU6_BUS_H
>>> +#define IPU6_BUS_H
>>> +
>>> +#include <linux/auxiliary_bus.h>
>>
>> ...Especially for headers which will affect the compilation time.
>>
>>> +#include <linux/pci.h>
>>
>> This is not used.
> 
> Do you mean it just need a 'struct pci_dev;' ?
>>
>> ...
>>
>>> +	struct list_head list;
>>
>> + types.h
>>
>>> +	struct sg_table fw_sgt;
>>
>> + scatterlist.h
>>
>>> +	dma_addr_t pkg_dir_dma_addr;
>>
>> types.h
>>
>> ...
>>
>>> +struct ipu6_auxdrv_data {
>>> +	irqreturn_t (*isr)(struct ipu6_bus_device *adev);
>>> +	irqreturn_t (*isr_threaded)(struct ipu6_bus_device *adev);
>>
>> irqreturn.h
>>
>>> +	bool wake_isr_thread;
>>> +};
>>
>> ...
>>
>>> +#define to_ipu6_bus_device(_dev) container_of(to_auxiliary_dev(_dev), \
>>> +					      struct ipu6_bus_device, auxdev)
>>> +#define auxdev_to_adev(_auxdev) container_of(_auxdev, \
>>> +					     struct ipu6_bus_device, auxdev)
>>
>> container_of.h
>>
>> Also, can you reformat to be more readable like
>>
>> #define auxdev_to_adev(_auxdev)					\
>> 	container_of(_auxdev, struct ipu6_bus_device, auxdev)
> 
> Ack.
> 
>>
>>> +#define ipu6_bus_get_drvdata(adev) dev_get_drvdata(&(adev)->auxdev.dev)
>>
>> device.h
>>
>> ...
>>
>>> +	ret = dma_set_max_seg_size(&pdev->dev, UINT_MAX);
>>> +	if (ret)
>>> +		return dev_err_probe(&pdev->dev, ret,
>>> +				     "Failed to set max_seg_size\n");
>>
>> With the help of
>>
>> 	struct device *dev = &pdev->dev;
>>
>> this and other lines become neater
>>
>>
>> 	ret = dma_set_max_seg_size(dev, _DMA_SEGMENT_SIZE); // as I commented earlier about
>> 	if (ret)
>> 		return dev_err_probe(dev, ret, "Failed to set max_seg_size\n");
> 
> Ack.
> 
>>
> 


^ permalink raw reply	[flat|nested] 86+ messages in thread

* Re: [PATCH v2 12/15] media: add Kconfig and Makefile for IPU6
  2023-10-24 13:04   ` Andy Shevchenko
@ 2023-10-25  8:43     ` Bingbu Cao
  2023-10-25 20:00       ` Andy Shevchenko
  2023-10-25 12:21     ` Sakari Ailus
  1 sibling, 1 reply; 86+ messages in thread
From: Bingbu Cao @ 2023-10-25  8:43 UTC (permalink / raw)
  To: Andy Shevchenko, bingbu.cao
  Cc: linux-media, sakari.ailus, laurent.pinchart, hdegoede,
	ilpo.jarvinen, andreaskleist, claus.stovgaard, tfiga,
	senozhatsky, tomi.valkeinen, tian.shu.qiu, hongju.wang

Andy,

Thanks for the review.

On 10/24/23 9:04 PM, Andy Shevchenko wrote:
> On Tue, Oct 24, 2023 at 07:29:21PM +0800, bingbu.cao@intel.com wrote:
>> From: Bingbu Cao <bingbu.cao@intel.com>
>>
>> Add IPU6 support in Kconfig and Makefile, with this patch you can
>> build the Intel IPU6 and input system modules by select the
>> CONFIG_VIDEO_INTEL_IPU6 in config.
> 
> ...
> 
>> +	depends on X86 && X86_64
> 
> How is that? One is a superset of the other IIUC.

It's trying to prevent build IPU6 with other arch such as 'UM'.

# make W=1 O=build_dir ARCH=um olddefconfig
ipu6-dma.c:... error: implicit declaration of function 'clflush_cache_range';

X86_64 looks like not an actual architecture.

> 
> ...
> 
>> +intel-ipu6-objs				+= ipu6.o \
> 
> += doesn't seem right.
> Besides that 'objs' is for user space, in kernel we use 'y'.
> 
>> +					ipu6-bus.o \
>> +					ipu6-dma.o \
>> +					ipu6-mmu.o \
>> +					ipu6-buttress.o \
>> +					ipu6-cpd.o \
>> +					ipu6-fw-com.o
>> +
>> +obj-$(CONFIG_VIDEO_INTEL_IPU6)		+= intel-ipu6.o
>> +
>> +intel-ipu6-isys-objs			+= ipu6-isys.o \
> 
> Ditto.

Ack.

> 
>> +					ipu6-isys-csi2.o \
>> +					ipu6-fw-isys.o \
>> +					ipu6-isys-video.o \
>> +					ipu6-isys-queue.o \
>> +					ipu6-isys-subdev.o \
>> +					ipu6-isys-mcd-phy.o \
>> +					ipu6-isys-jsl-phy.o \
>> +					ipu6-isys-dwc-phy.o
>> +
>> +obj-$(CONFIG_VIDEO_INTEL_IPU6)		+= intel-ipu6-isys.o
> 

-- 
Best regards,
Bingbu Cao

^ permalink raw reply	[flat|nested] 86+ messages in thread

* Re: [PATCH v2 15/15] Documentation: add documentation of Intel IPU6 driver and hardware overview
  2023-10-24 11:29 ` [PATCH v2 15/15] Documentation: add documentation of Intel IPU6 driver and hardware overview bingbu.cao
@ 2023-10-25 12:09   ` Sakari Ailus
  2023-10-26  3:38     ` Bingbu Cao
  0 siblings, 1 reply; 86+ messages in thread
From: Sakari Ailus @ 2023-10-25 12:09 UTC (permalink / raw)
  To: bingbu.cao
  Cc: linux-media, laurent.pinchart, andriy.shevchenko, hdegoede,
	ilpo.jarvinen, andreaskleist, claus.stovgaard, tfiga,
	senozhatsky, tomi.valkeinen, bingbu.cao, tian.shu.qiu,
	hongju.wang

Hi Bingbu,

Thanks for the patch. It's a nice piece of documentation for the most
complex CSI-2 receiver driver. :-)

On Tue, Oct 24, 2023 at 07:29:24PM +0800, bingbu.cao@intel.com wrote:
> From: Bingbu Cao <bingbu.cao@intel.com>
> 
> Add a documentation for an overview of IPU6 hardware and describe the main
> the components of IPU6 driver.
> 
> Signed-off-by: Bingbu Cao <bingbu.cao@intel.com>
> ---
>  .../driver-api/media/drivers/index.rst        |   1 +
>  .../driver-api/media/drivers/ipu6.rst         | 205 ++++++++++++++++++
>  2 files changed, 206 insertions(+)
>  create mode 100644 Documentation/driver-api/media/drivers/ipu6.rst
> 
> diff --git a/Documentation/driver-api/media/drivers/index.rst b/Documentation/driver-api/media/drivers/index.rst
> index c4123a16b5f9..7f6f3dcd5c90 100644
> --- a/Documentation/driver-api/media/drivers/index.rst
> +++ b/Documentation/driver-api/media/drivers/index.rst
> @@ -26,6 +26,7 @@ Video4Linux (V4L) drivers
>  	vimc-devel
>  	zoran
>  	ccs/ccs
> +	ipu6
>  
>  
>  Digital TV drivers
> diff --git a/Documentation/driver-api/media/drivers/ipu6.rst b/Documentation/driver-api/media/drivers/ipu6.rst
> new file mode 100644
> index 000000000000..2685e4a0d7ba
> --- /dev/null
> +++ b/Documentation/driver-api/media/drivers/ipu6.rst
> @@ -0,0 +1,205 @@
> +.. SPDX-License-Identifier: GPL-2.0
> +
> +==================
> +Intel IPU6 Driver
> +==================
> +
> +Author: Bingbu Cao <bingbu.cao@intel.com>
> +
> +Overview
> +=========
> +
> +Intel IPU6 is the sixth generation of Intel Image Processing Unit used in some
> +Intel Chipsets such as Tiger Lake, Jasper Lake, Alder Lake, Raptor Lake and
> +Meteor Lake. IPU6 consists of two major systems - Input System (IS) and

I'd use a semicolon:				  ^

> +Processing System (PS). IPU6 are visible on the PCI bus as a single device,
> +it can be found by ``lspci``:
> +
> +``0000:00:05.0 Multimedia controller: Intel Corporation Device xxxx (rev xx)``
> +
> +IPU6 has a 16 MB BAR in PCI configuration Space for MMIO registers which is
> +visible for driver.
> +
> +Buttress
> +=========
> +
> +The IPU6 is connecting to the system fabric with ``Buttress`` which is enabling
> +host driver to control the IPU6, it also allows IPU6 access the system memory to
> +store and load frame pixel streams and any other metadata.
> +
> +``Buttress`` mainly manages several system functionalities - power management,
> +interrupt handling, firmware authentication and global timer sync.
> +
> +IS and PS Power flow
> +---------------------------
> +
> +IPU6 driver initialize the IS and PS power up or down request by setting the
> +Buttress frequency control register for IS and PS -
> +``IPU6_BUTTRESS_REG_IS_FREQ_CTL`` and ``IPU6_BUTTRESS_REG_PS_FREQ_CTL`` in
> +function:
> +
> +.. c:function:: int ipu6_buttress_power(..., bool on)
> +
> +Buttress forwards the request to Punit, after Punit execute the power up flow,
> +buttress indicates driver that IS or PS is powered up by updating the power
> +status registers.
> +
> +.. Note:: IS power up needs take place prior to PS power up, IS power down needs
> +	  take place after PS power down due to hardware limitation.
> +
> +
> +Interrupt
> +------------
> +
> +IPU6 interrupt can be generated as MSI or INTA, interrupt will be triggered
> +when IS, PS, Buttress event or error happen, driver can get the interrupt
> +cause by reading the interrupt status register ``BUTTRESS_REG_ISR_STATUS``,
> +driver firstly clear the irq status and then call specific IS or PS irq handler.
> +
> +.. c:function:: irqreturn_t ipu6_buttress_isr(int irq, ...)
> +
> +Security and firmware authentication
> +-------------------------------------
> +To address the IPU6 firmware security concerns, the IPU6 firmware needs to
> +undergo an authentication process before it is allowed to executed on the IPU6
> +internal processors. Driver will work with Converged Security Engine (CSE) to
> +complete authentication process. CSE is responsible of authenticating the
> +IPU6 firmware, the authenticated firmware binary is copied into an isolated
> +memory region. Firmware authentication process is implemented by CSE following
> +an IPC handshake with driver. There are some Buttress registers used by CSE and
> +driver to communicate with each other as IPC messages.
> +
> +.. c:function:: int ipu6_buttress_authenticate(...)
> +
> +Global timer sync
> +------------------
> +IPU driver initiates a Hammock Harbor synchronization flow each time it starts
> +camera operation. IPU will synchronizes an internal counter in the Buttress
> +with a copy of SoC time, this counter keeps the updated time until camera
> +operation is stopped. Driver can use this time counter to calibrate the
> +timestamp based on the timestamp in response event from firmware.
> +
> +.. c:function:: int ipu6_buttress_start_tsc_sync(...)
> +
> +
> +DMA and MMU
> +============
> +
> +IPU6 has its own scalar processor where the firmware run at, it has
> +an internal 32-bits virtual address space. IPU6 has MMU address translation
> +hardware to allow that scalar process access the internal memory and external
> +system memory through IPU6 virtual address. The address translation is
> +based on two levels of page lookup tables stored in system memory which are
> +maintained by IPU6 driver. IPU6 driver sets the level-1 page table base address
> +to MMU register and allow MMU to lookup the page table.
> +
> +IPU6 driver exports its own DMA operations. Driver will update the page table
> +entries for each DMA operation and invalidate the MMU TLB after each unmap and
> +free.
> +
> +.. code-block:: none
> +
> +    const struct dma_map_ops ipu6_dma_ops = {
> +	   .alloc = ipu6_dma_alloc,
> +	   .free = ipu6_dma_free,
> +	   .mmap = ipu6_dma_mmap,
> +	   .map_sg = ipu6_dma_map_sg,
> +	   .unmap_sg = ipu6_dma_unmap_sg,
> +	   ...
> +    };
> +
> +.. Note:: IPU6 MMU works behind IOMMU, so for each IPU6 DMA ops, driver will
> +	  call generic PCI DMA ops to ask IOMMU to do the additional mapping
> +	  if VT-d enabled.
> +
> +
> +Firmware file format
> +=====================
> +
> +IPU6 release the firmware in Code Partition Directory (CPD) file format. The
> +CPD firmware contains a CPD header, several CPD entries and CPD components.
> +CPD component includes 3 entries - manifest, metadata and module data. Manifest
> +and metadata are defined by CSE and used by CSE for authentication. Module data
> +is defined by IPU6 which holds the binary data of firmware called package
> +directory. IPU6 driver (``ipu6-cpd.c``) parses and validates the CPD firmware
> +file and get the package directory binary data of IPU6 firmware, copy it to
> +specific DMA buffer and sets its base address to Buttress ``FW_SOURCE_BASE``
> +register, CSE will do authentication for this firmware binary.
> +
> +
> +Syscom interface
> +================
> +
> +IPU6 driver communicates with firmware via syscom ABI. Syscom is an
> +inter-processor communication mechanism between IPU scalar processor and CPU.
> +There are a number of resources shared between firmware and software.
> +A system memory region where the message queues reside, firmware can access the
> +memory region via IPU MMU. Syscom queues are FIFO fixed depth queues with
> +configurable elements ``token`` (message). There is also a common IPU MMIO
> +registers where the queue read and write indices reside. Software and firmware
> +work as producer and consumer of tokens in queue, and update the write and read
> +indices separately when sending or receiving each message.
> +
> +IPU6 driver must prepare and configure the number of input and output queues,
> +configure the count of tokens per queue and the size of per token before
> +initiate and start the communication with firmware, firmware and software must
> +use same configurations. IPU6 Buttress has a number of firmware boot parameter
> +registers which can be used to store the address of configuration and initiate
> +the Syscom state, then driver can request firmware to start and run via setting
> +the scalar processor control status register.
> +
> +
> +Input System
> +==============
> +
> +IPU6 input system consists of MIPI D-PHY and several CSI receiver controllers,
> +it can capture image pixel data from camera sensors or other MIPI CSI output
> +devices.
> +
> +DPHYs and CSI2 ports lane mapping

"D-PHY" and "CSI-2"

> +---------------------------------
> +
> +IPU6 integrates different D-PHY IPs on different SoCs, on Tiger Lake and Alder
> +Lake, IPU6 integrates MCD10 D-PHY, IPU6SE on Jasper Lake integrates JSL D-PHY
> +and IPU6EP on Meteor Lake integrates a Synopsys DWC D-PHY. There is an adaption
> +layer between D-PHY and CSI receiver controller which includes port
> +configuration, PHY wrapper or private test interfaces for D-PHY. There are 3
> +D-PHY drivers ``ipu6-isys-mcd-phy.c``, ``ipu6-isys-jsl-phy.c`` and
> +``ipu6-isys-dwc-phy.c`` program the above 3 D-PHYs in IPU6.
> +
> +Different IPU6 version has different DPHY lanes mappings, On Tiger Lake, there
> +are 12 data lanes and 8 clock lanes, IPU6 support maximum 8 CSI2 ports, see
> +the ppi mmapping in ``ipu6-isys-mcd-phy.c`` for more information. On Jasper Lake
> +and Alder Lake, DPHY has 8 data lanes and 4 clock lanes, IPU6 support maximum 4
> +CSI2 ports. For Meteor Lake, DPHY has 12 data lanes and 6 clock lanes, IPU6
> +support maximum 6 CSI2 ports.
> +
> +.. Note:: Each adjacent CSI ports work as a pair and share the data lanes.
> +	  For example, for CSI port 0 and 1, CSI port 0 support maximum 4
> +	  data lanes, CSI port 1 support maximum 2 data lanes, CSI port 0
> +	  with 2 data lanes can work together with CSI port 1 with 2 data lanes.
> +	  If trying to use CSI port 0 with 4 lanes, CSI port 1 will not be
> +	  available as the 4 data lanes are shared by CSI port 0 and 1. Same
> +	  scenario is also applied for CSI port 2/3, 4/5 and 7/8.
> +
> +IS firmware ABIs
> +----------------
> +
> +IPU6 firmware define a series of ABIs to software. In general, software firstly
> +prepare the stream configuration ``struct ipu6_fw_isys_stream_cfg_data_abi``
> +and send the configuration to firmware via sending ``STREAM_OPEN`` command.
> +Stream configuration includes input pins and output pins, input pin
> +``struct ipu6_fw_isys_input_pin_info_abi`` defines the resolution and data type
> +of input source, output pin ``struct ipu6_fw_isys_output_pin_info_abi``
> +defines the output resolution, stride and frame format, etc. Once driver get the
> +interrupt from firmware that indicates stream open successfully, driver will
> +send the ``STREAM_START`` and ``STREAM_CAPTURE`` command to request firmware to
> +start capturing image frames. ``STREAM_CAPTURE`` command queues the buffers to
> +firmware with ``struct ipu6_fw_isys_frame_buff_set``, software then wait the
> +interrupt and response from firmware, ``PIN_DATA_READY`` means data ready
> +on specific output pin and then software return the buffers to user.
> +
> +.. Note:: See Documentation/admin-guide/media/ipu6-isys.rst for how to do

Could you add a direct link instead? See e.g.
Documentation/driver-api/media/camera-sensor.rst for an example.

> +	  capture by IPU6 IS driver.
> +
> +

-- 
Regards,

Sakari Ailus

^ permalink raw reply	[flat|nested] 86+ messages in thread

* Re: [PATCH v2 14/15] Documentation: add Intel IPU6 ISYS driver admin-guide doc
  2023-10-24 11:29 ` [PATCH v2 14/15] Documentation: add Intel IPU6 ISYS driver admin-guide doc bingbu.cao
@ 2023-10-25 12:15   ` Sakari Ailus
  2024-01-08  3:51     ` Bingbu Cao
  0 siblings, 1 reply; 86+ messages in thread
From: Sakari Ailus @ 2023-10-25 12:15 UTC (permalink / raw)
  To: bingbu.cao
  Cc: linux-media, laurent.pinchart, andriy.shevchenko, hdegoede,
	ilpo.jarvinen, andreaskleist, claus.stovgaard, tfiga,
	senozhatsky, tomi.valkeinen, bingbu.cao, tian.shu.qiu,
	hongju.wang

Hi Bingbu,

On Tue, Oct 24, 2023 at 07:29:23PM +0800, bingbu.cao@intel.com wrote:
> From: Bingbu Cao <bingbu.cao@intel.com>
> 
> This document mainly describe the functionality of IPU6 and
> IPU6 isys driver, and gives an example that how user can do
> imaging capture with tools.
> 
> Signed-off-by: Bingbu Cao <bingbu.cao@intel.com>
> ---
>  Documentation/admin-guide/media/ipu6-isys.rst |  159 +++
>  .../admin-guide/media/ipu6_isys_graph.svg     |  338 +++++
>  .../admin-guide/media/ipu6_isys_multi.svg     | 1124 +++++++++++++++++
>  .../admin-guide/media/v4l-drivers.rst         |    1 +
>  4 files changed, 1622 insertions(+)
>  create mode 100644 Documentation/admin-guide/media/ipu6-isys.rst
>  create mode 100644 Documentation/admin-guide/media/ipu6_isys_graph.svg
>  create mode 100644 Documentation/admin-guide/media/ipu6_isys_multi.svg
> 
> diff --git a/Documentation/admin-guide/media/ipu6-isys.rst b/Documentation/admin-guide/media/ipu6-isys.rst
> new file mode 100644
> index 000000000000..fb4d355e1522
> --- /dev/null
> +++ b/Documentation/admin-guide/media/ipu6-isys.rst
> @@ -0,0 +1,159 @@
> +.. SPDX-License-Identifier: GPL-2.0
> +
> +.. include:: <isonum.txt>
> +
> +===============================================================
> +Intel Image Processing Unit 6 (IPU6) Input System driver
> +===============================================================

Too many '='s.

> +
> +Copyright |copy| 2023 Intel Corporation
> +
> +Introduction
> +============
> +
> +This file documents the Intel IPU6 (6th generation Image Processing Unit)
> +Input System (MIPI CSI2 receiver) drivers located under
> +drivers/media/pci/intel/ipu6.
> +
> +The Intel IPU6 can be found in certain Intel Chipsets but not in all SKUs:
> +
> +* TigerLake
> +* JasperLake
> +* AlderLake
> +* RaptorLake
> +* MeteorLake
> +
> +Intel IPU6 is made up of two components - Input System (ISYS) and Processing
> +System (PSYS).
> +
> +The Input System mainly works as MIPI CSI2 receiver which receives and
> +processes the imaging data from the sensors and outputs the frames to memory.
> +
> +There are 2 driver modules - intel_ipu6 and intel_ipu6_isys. intel_ipu6 is an
> +IPU6 common driver which does PCI configuration, firmware loading and parsing,
> +firmware authentication, DMA mapping and IPU-MMU (internal Memory mapping Unit)
> +configuration. intel_ipu6_isys implements V4L2, Media Controller and V4L2
> +sub-device interfaces. The IPU6 ISYS driver supports camera sensors connected
> +to the IPU6 ISYS through V4L2 sub-device sensor drivers.
> +
> +.. Note:: See Documentation/driver-api/media/drivers/ipu6.rst for more
> +	  information about the IPU6 hardware.

A direct reference would be nice.

> +
> +
> +Input system driver
> +===================
> +
> +The input System driver mainly configures CSI2 DPHY, constructs the firmware
> +stream configuration, sends commands to firmware, gets response from hardware
> +and firmware and then returns buffers to user.
> +The ISYS is represented as several V4L2 sub-devices - 'Intel IPU6 CSI2 $port',
> +which provide V4L2 subdev interfaces to the user space, there are also several
> +video nodes for each CSI-2 stream capture - 'Intel IPU6 ISYS capture $num' which
> +provide interface to user to set formats, queue buffers and streaming.
> +
> +.. kernel-figure::  ipu6_isys_graph.svg
> +   :alt: ipu6 isys media graph without multiple streams support
> +
> +   ipu6 isys media graph without multiple streams support
> +
> +.. kernel-figure::  ipu6_isys_multi.svg
> +   :alt: ipu6 isys media graph with multiple streams support
> +
> +   ipu6 isys media graph with multiple streams support

Is there a reason for having links from the CSI-2 receivers' source pads to
multiple video nodes? Isn't a single one enough?

> +
> +Capturing frames by IPU6 ISYS
> +------------------------------------
> +
> +IPU6 ISYS is used to capture frames from the camera sensors connected to the
> +CSI2 ports. The supported input formats of ISYS are listed in table below:
> +
> +.. tabularcolumns:: |p{0.8cm}|p{4.0cm}|p{4.0cm}|
> +
> +.. flat-table::
> +    :header-rows: 1
> +
> +    * - IPU6 ISYS supported input formats
> +
> +    * - RGB565, RGB888
> +
> +    * - UYVY8, YUYV8
> +
> +    * - RAW8, RAW10, RAW12
> +
> +Here is an example of IPU6 ISYS raw capture on Dell XPS 9315 laptop. On this
> +machine, ov01a10 sensor is connected to IPU ISYS CSI2 port 2, which can
> +generate images at sBGGR10 with resolution 1280x800.
> +
> +Using the media controller APIs, we can configure ov01a10 sensor by
> +media-ctl [#f1]_ and yavta [#f2]_ to transmit frames to IPU6 ISYS.
> +
> +.. code-block:: none
> +
> +    # Example 1 capture frame from ov01a10 camera sensor
> +    # This example assumes /dev/media0 as the IPU ISYS media device
> +    export MDEV=/dev/media0
> +
> +    # Establish the link for the media devices using media-ctl
> +    media-ctl -d $MDEV -l "\"ov01a10 3-0036\":0 -> \"Intel IPU6 CSI2 2\":0[1]"
> +
> +    # Set the format for the media devices
> +    media-ctl -d $MDEV -V "ov01a10:0 [fmt:SBGGR10/1280x800]"
> +    media-ctl -d $MDEV -V "Intel IPU6 CSI2 2:0 [fmt:SBGGR10/1280x800]"
> +    media-ctl -d $MDEV -V "Intel IPU6 CSI2 2:1 [fmt:SBGGR10/1280x800]"
> +
> +Once the media pipeline is configured, desired sensor specific settings
> +(such as exposure and gain settings) can be set, using the yavta tool.
> +
> +e.g
> +
> +.. code-block:: none
> +
> +    # and that ov01a10 sensor is connected to i2c bus 3 with address 0x36
> +    export SDEV=$(media-ctl -d $MDEV -e "ov01a10 3-0036")
> +
> +    yavta -w 0x009e0903 400 $SDEV
> +    yavta -w 0x009e0913 1000 $SDEV
> +    yavta -w 0x009e0911 2000 $SDEV
> +
> +Once the desired sensor settings are set, frame captures can be done as below.
> +
> +e.g
> +
> +.. code-block:: none
> +
> +    yavta --data-prefix -u -c10 -n5 -I -s 1280x800 --file=/tmp/frame-#.bin \
> +          -f SBGGR10 $(media-ctl -d $MDEV -e "Intel IPU6 ISYS Capture 0")
> +
> +With the above command, 10 frames are captured at 1280x800 resolution with
> +sBGGR10 format. The captured frames are available as /tmp/frame-#.bin files.
> +
> +Here is another example of IPU6 ISYS RAW and metadata capture from camera
> +sensor ov2740 on Lenovo X1 Yoga laptop.
> +
> +.. code-block:: none
> +
> +    media-ctl -l "\"ov2740 14-0036\":0 -> \"Intel IPU6 CSI2 1\":0[1]"
> +    media-ctl -l "\"Intel IPU6 CSI2 1\":1 -> \"Intel IPU6 ISYS Capture 0\":0[5]"
> +    media-ctl -l "\"Intel IPU6 CSI2 1\":2 -> \"Intel IPU6 ISYS Capture 1\":0[5]"
> +
> +    # set routing
> +    media-ctl -v -R "\"Intel IPU6 CSI2 1\" [0/0->1/0[1],0/1->2/1[1]]"
> +
> +    media-ctl -v "\"Intel IPU6 CSI2 1\":0/0 [fmt:SGRBG10/1932x1092]"
> +    media-ctl -v "\"Intel IPU6 CSI2 1\":0/1 [fmt:GENERIC_8/97x1]"
> +    media-ctl -v "\"Intel IPU6 CSI2 1\":1/0 [fmt:SGRBG10/1932x1092]"
> +    media-ctl -v "\"Intel IPU6 CSI2 1\":2/1 [fmt:GENERIC_8/97x1]"
> +
> +    CAPTURE_DEV=$(media-ctl -e "Intel IPU6 ISYS Capture 0")
> +    ./yavta --data-prefix -c100 -n5 -I -s1932x1092 --file=/tmp/frame-#.bin \
> +    -f SGRBG10 ${CAPTURE_DEV}
> +
> +    CAPTURE_META=$(media-ctl -e "Intel IPU6 ISYS Capture 1")
> +    ./yavta --data-prefix -c100 -n5 -I -s97x1 -B meta-capture \
> +    --file=/tmp/meta-#.bin -f GENERIC_8 ${CAPTURE_META}
> +
> +References
> +==========
> +
> +.. [#f1] https://git.ideasonboard.org/?p=media-ctl.git;a=summary
> +.. [#f2] https://git.ideasonboard.org/yavta.git

-- 
Regards,

Sakari Ailus

^ permalink raw reply	[flat|nested] 86+ messages in thread

* Re: [PATCH v2 12/15] media: add Kconfig and Makefile for IPU6
  2023-10-24 13:04   ` Andy Shevchenko
  2023-10-25  8:43     ` Bingbu Cao
@ 2023-10-25 12:21     ` Sakari Ailus
  2023-10-25 20:01       ` Andy Shevchenko
  1 sibling, 1 reply; 86+ messages in thread
From: Sakari Ailus @ 2023-10-25 12:21 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: bingbu.cao, linux-media, laurent.pinchart, hdegoede,
	ilpo.jarvinen, andreaskleist, claus.stovgaard, tfiga,
	senozhatsky, tomi.valkeinen, bingbu.cao, tian.shu.qiu,
	hongju.wang

Hi Andy,

On Tue, Oct 24, 2023 at 04:04:05PM +0300, Andy Shevchenko wrote:
> On Tue, Oct 24, 2023 at 07:29:21PM +0800, bingbu.cao@intel.com wrote:
> > From: Bingbu Cao <bingbu.cao@intel.com>
> > 
> > Add IPU6 support in Kconfig and Makefile, with this patch you can
> > build the Intel IPU6 and input system modules by select the
> > CONFIG_VIDEO_INTEL_IPU6 in config.
> 
> ...
> 
> > +	depends on X86 && X86_64
> 
> How is that? One is a superset of the other IIUC.
> 
> ...
> 
> > +intel-ipu6-objs				+= ipu6.o \
> 
> += doesn't seem right.
> Besides that 'objs' is for user space, in kernel we use 'y'.

This is a common pattern used in other Makefiles, too... I guess ":=" would
work, too.

How otherwise would you do this?

It'd be nice to align the object names starting after the column after
"+= ".

> 
> > +					ipu6-bus.o \
> > +					ipu6-dma.o \
> > +					ipu6-mmu.o \
> > +					ipu6-buttress.o \
> > +					ipu6-cpd.o \
> > +					ipu6-fw-com.o
> > +
> > +obj-$(CONFIG_VIDEO_INTEL_IPU6)		+= intel-ipu6.o
> > +
> > +intel-ipu6-isys-objs			+= ipu6-isys.o \
> 
> Ditto.
> 
> > +					ipu6-isys-csi2.o \
> > +					ipu6-fw-isys.o \
> > +					ipu6-isys-video.o \
> > +					ipu6-isys-queue.o \
> > +					ipu6-isys-subdev.o \
> > +					ipu6-isys-mcd-phy.o \
> > +					ipu6-isys-jsl-phy.o \
> > +					ipu6-isys-dwc-phy.o
> > +
> > +obj-$(CONFIG_VIDEO_INTEL_IPU6)		+= intel-ipu6-isys.o
> 

-- 
Regards,

Sakari Ailus

^ permalink raw reply	[flat|nested] 86+ messages in thread

* Re: [PATCH v2 01/15] media: intel/ipu6: add Intel IPU6 PCI device driver
  2023-10-24 11:29 ` [PATCH v2 01/15] media: intel/ipu6: add Intel IPU6 PCI device driver bingbu.cao
@ 2023-10-25 12:39   ` Andreas Helbech Kleist
  2023-10-25 20:03     ` Andy Shevchenko
  2023-11-05 14:43   ` Hans de Goede
                     ` (2 subsequent siblings)
  3 siblings, 1 reply; 86+ messages in thread
From: Andreas Helbech Kleist @ 2023-10-25 12:39 UTC (permalink / raw)
  To: bingbu.cao, linux-media, sakari.ailus, laurent.pinchart
  Cc: andriy.shevchenko, hdegoede, ilpo.jarvinen, claus.stovgaard,
	tfiga, senozhatsky, tomi.valkeinen, bingbu.cao, tian.shu.qiu,
	hongju.wang

Hi Bingbu,

Thanks for the updated series. I've rebased my work on this series, and
ran into the following issue.

On Tue, 2023-10-24 at 19:29 +0800, bingbu.cao@intel.com wrote:
> +static int ipu6_pci_config_setup(struct pci_dev *dev, u8 hw_ver)
...
> +       ret = pci_alloc_irq_vectors(dev, 1, 1, PCI_IRQ_MSI);
> +       if (ret)
> +               dev_err_probe(&dev->dev, ret, "Request msi failed");
> +
> +       return ret;
> +}

pci_alloc_irq_vectors returns number of irqs, so I think it should be
something like this instead:

       ret = pci_alloc_irq_vectors(dev, 1, 1, PCI_IRQ_MSI);
       if (ret<0) {
               dev_err_probe(&dev->dev, ret, "Request msi failed");
               return ret;
       }
       
       return 0;

/Andreas

^ permalink raw reply	[flat|nested] 86+ messages in thread

* Re: [PATCH v2 02/15] media: intel/ipu6: add IPU auxiliary devices
  2023-10-25  7:14     ` Bingbu Cao
  2023-10-25  8:35       ` Hans de Goede
@ 2023-10-25 19:57       ` Andy Shevchenko
  2023-10-26  3:04         ` Bingbu Cao
  1 sibling, 1 reply; 86+ messages in thread
From: Andy Shevchenko @ 2023-10-25 19:57 UTC (permalink / raw)
  To: Bingbu Cao
  Cc: bingbu.cao, linux-media, sakari.ailus, laurent.pinchart,
	hdegoede, ilpo.jarvinen, andreaskleist, claus.stovgaard, tfiga,
	senozhatsky, tomi.valkeinen, tian.shu.qiu, hongju.wang

On Wed, Oct 25, 2023 at 03:14:00PM +0800, Bingbu Cao wrote:
> On 10/24/23 8:58 PM, Andy Shevchenko wrote:
> > On Tue, Oct 24, 2023 at 07:29:11PM +0800, bingbu.cao@intel.com wrote:

> auxiliary_bus.h is included in ipu6-bus.h,

So, you have to include it explicitly as IWYU, strictly speaking ipu6-bus.h
does NOT guarantee that inclusion, even if you fully control it.

> list.h, mutex.h dev_printk.h are
> included in device.h,

I ack for dev_printk.h, but for the rest see above.

> dma-mapping.h and scatterlist.h are included in pci.h.

See above.


> I am a little confused about the rule, do you mean we need include the
> generic headers we need even it is included in others header?

Yes. There are only few guarantees in the kernel, strictly speaking. And having
spaghetti headers in your code is a bad idea from long run maintenance
perspective.

...

> >> +#ifndef IPU6_BUS_H
> >> +#define IPU6_BUS_H
> >> +
> >> +#include <linux/auxiliary_bus.h>
> > 
> > ...Especially for headers which will affect the compilation time.
> > 
> >> +#include <linux/pci.h>
> > 
> > This is not used.
> 
> Do you mean it just need a 'struct pci_dev;' ?

Yes.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 86+ messages in thread

* Re: [PATCH v2 12/15] media: add Kconfig and Makefile for IPU6
  2023-10-25  8:43     ` Bingbu Cao
@ 2023-10-25 20:00       ` Andy Shevchenko
  0 siblings, 0 replies; 86+ messages in thread
From: Andy Shevchenko @ 2023-10-25 20:00 UTC (permalink / raw)
  To: Bingbu Cao
  Cc: bingbu.cao, linux-media, sakari.ailus, laurent.pinchart,
	hdegoede, ilpo.jarvinen, andreaskleist, claus.stovgaard, tfiga,
	senozhatsky, tomi.valkeinen, tian.shu.qiu, hongju.wang

On Wed, Oct 25, 2023 at 04:43:16PM +0800, Bingbu Cao wrote:
> On 10/24/23 9:04 PM, Andy Shevchenko wrote:
> > On Tue, Oct 24, 2023 at 07:29:21PM +0800, bingbu.cao@intel.com wrote:

...
> > 
> >> +	depends on X86 && X86_64
> > 
> > How is that? One is a superset of the other IIUC.
> 
> It's trying to prevent build IPU6 with other arch such as 'UM'.
> 
> # make W=1 O=build_dir ARCH=um olddefconfig
> ipu6-dma.c:... error: implicit declaration of function 'clflush_cache_range';

Is UM ever supported 64-bit builds?

> X86_64 looks like not an actual architecture.

How comes?

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 86+ messages in thread

* Re: [PATCH v2 12/15] media: add Kconfig and Makefile for IPU6
  2023-10-25 12:21     ` Sakari Ailus
@ 2023-10-25 20:01       ` Andy Shevchenko
  0 siblings, 0 replies; 86+ messages in thread
From: Andy Shevchenko @ 2023-10-25 20:01 UTC (permalink / raw)
  To: Sakari Ailus
  Cc: bingbu.cao, linux-media, laurent.pinchart, hdegoede,
	ilpo.jarvinen, andreaskleist, claus.stovgaard, tfiga,
	senozhatsky, tomi.valkeinen, bingbu.cao, tian.shu.qiu,
	hongju.wang

On Wed, Oct 25, 2023 at 12:21:13PM +0000, Sakari Ailus wrote:
> On Tue, Oct 24, 2023 at 04:04:05PM +0300, Andy Shevchenko wrote:
> > On Tue, Oct 24, 2023 at 07:29:21PM +0800, bingbu.cao@intel.com wrote:

...

> > > +intel-ipu6-objs				+= ipu6.o \
> > 
> > += doesn't seem right.
> > Besides that 'objs' is for user space, in kernel we use 'y'.
> 
> This is a common pattern used in other Makefiles, too... I guess ":=" would
> work, too.
> 
> How otherwise would you do this?

:= has different meaning in make language. How you will guarantee somewhere
else somebody won't use same target, note that make is recursive.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 86+ messages in thread

* Re: [PATCH v2 01/15] media: intel/ipu6: add Intel IPU6 PCI device driver
  2023-10-25 12:39   ` Andreas Helbech Kleist
@ 2023-10-25 20:03     ` Andy Shevchenko
  0 siblings, 0 replies; 86+ messages in thread
From: Andy Shevchenko @ 2023-10-25 20:03 UTC (permalink / raw)
  To: Andreas Helbech Kleist
  Cc: bingbu.cao, linux-media, sakari.ailus, laurent.pinchart,
	hdegoede, ilpo.jarvinen, claus.stovgaard, tfiga, senozhatsky,
	tomi.valkeinen, bingbu.cao, tian.shu.qiu, hongju.wang

On Wed, Oct 25, 2023 at 02:39:16PM +0200, Andreas Helbech Kleist wrote:
> On Tue, 2023-10-24 at 19:29 +0800, bingbu.cao@intel.com wrote:

...

> > +       ret = pci_alloc_irq_vectors(dev, 1, 1, PCI_IRQ_MSI);
> > +       if (ret)
> > +               dev_err_probe(&dev->dev, ret, "Request msi failed");
> > +
> > +       return ret;
> > +}
> 
> pci_alloc_irq_vectors returns number of irqs, so I think it should be
> something like this instead:

Indeed, good catch!

>        ret = pci_alloc_irq_vectors(dev, 1, 1, PCI_IRQ_MSI);
>        if (ret<0) {
>                dev_err_probe(&dev->dev, ret, "Request msi failed");
>                return ret;

		return dev_err_probe();

saves a line.

>        }

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 86+ messages in thread

* Re: [PATCH v2 02/15] media: intel/ipu6: add IPU auxiliary devices
  2023-10-25 19:57       ` Andy Shevchenko
@ 2023-10-26  3:04         ` Bingbu Cao
  0 siblings, 0 replies; 86+ messages in thread
From: Bingbu Cao @ 2023-10-26  3:04 UTC (permalink / raw)
  To: Andy Shevchenko, hdegoede
  Cc: bingbu.cao, linux-media, sakari.ailus, laurent.pinchart,
	ilpo.jarvinen, andreaskleist, claus.stovgaard, tfiga,
	senozhatsky, tomi.valkeinen, tian.shu.qiu, hongju.wang

Andy and Hans,

Thanks.

On 10/26/23 3:57 AM, Andy Shevchenko wrote:
> On Wed, Oct 25, 2023 at 03:14:00PM +0800, Bingbu Cao wrote:
>> On 10/24/23 8:58 PM, Andy Shevchenko wrote:
>>> On Tue, Oct 24, 2023 at 07:29:11PM +0800, bingbu.cao@intel.com wrote:
> 
>> auxiliary_bus.h is included in ipu6-bus.h,
> 
> So, you have to include it explicitly as IWYU, strictly speaking ipu6-bus.h
> does NOT guarantee that inclusion, even if you fully control it.
> 
>> list.h, mutex.h dev_printk.h are
>> included in device.h,
> 
> I ack for dev_printk.h, but for the rest see above.
> 
>> dma-mapping.h and scatterlist.h are included in pci.h.
> 
> See above.
> 
> 
>> I am a little confused about the rule, do you mean we need include the
>> generic headers we need even it is included in others header?
> 
> Yes. There are only few guarantees in the kernel, strictly speaking. And having
> spaghetti headers in your code is a bad idea from long run maintenance
> perspective.
> 
> ...
> 
>>>> +#ifndef IPU6_BUS_H
>>>> +#define IPU6_BUS_H
>>>> +
>>>> +#include <linux/auxiliary_bus.h>
>>>
>>> ...Especially for headers which will affect the compilation time.
>>>
>>>> +#include <linux/pci.h>
>>>
>>> This is not used.
>>
>> Do you mean it just need a 'struct pci_dev;' ?
> 
> Yes.
>

Ack. Will address them in v3.
 

-- 
Best regards,
Bingbu Cao

^ permalink raw reply	[flat|nested] 86+ messages in thread

* Re: [PATCH v2 15/15] Documentation: add documentation of Intel IPU6 driver and hardware overview
  2023-10-25 12:09   ` Sakari Ailus
@ 2023-10-26  3:38     ` Bingbu Cao
  2023-10-26  5:27       ` Sakari Ailus
  0 siblings, 1 reply; 86+ messages in thread
From: Bingbu Cao @ 2023-10-26  3:38 UTC (permalink / raw)
  To: Sakari Ailus, bingbu.cao
  Cc: linux-media, laurent.pinchart, andriy.shevchenko, hdegoede,
	ilpo.jarvinen, andreaskleist, claus.stovgaard, tfiga,
	senozhatsky, tomi.valkeinen, tian.shu.qiu, hongju.wang

Sakari,

Thanks for the review.

On 10/25/23 8:09 PM, Sakari Ailus wrote:
> Hi Bingbu,
> 
> Thanks for the patch. It's a nice piece of documentation for the most
> complex CSI-2 receiver driver. :-)
> 
> On Tue, Oct 24, 2023 at 07:29:24PM +0800, bingbu.cao@intel.com wrote:
>> From: Bingbu Cao <bingbu.cao@intel.com>
>>
>> Add a documentation for an overview of IPU6 hardware and describe the main
>> the components of IPU6 driver.
>>
>> Signed-off-by: Bingbu Cao <bingbu.cao@intel.com>
>> ---
>>  .../driver-api/media/drivers/index.rst        |   1 +
>>  .../driver-api/media/drivers/ipu6.rst         | 205 ++++++++++++++++++
>>  2 files changed, 206 insertions(+)
>>  create mode 100644 Documentation/driver-api/media/drivers/ipu6.rst
>>
>> diff --git a/Documentation/driver-api/media/drivers/index.rst b/Documentation/driver-api/media/drivers/index.rst
>> index c4123a16b5f9..7f6f3dcd5c90 100644
>> --- a/Documentation/driver-api/media/drivers/index.rst
>> +++ b/Documentation/driver-api/media/drivers/index.rst
>> @@ -26,6 +26,7 @@ Video4Linux (V4L) drivers
>>  	vimc-devel
>>  	zoran
>>  	ccs/ccs
>> +	ipu6
>>  
>>  
>>  Digital TV drivers
>> diff --git a/Documentation/driver-api/media/drivers/ipu6.rst b/Documentation/driver-api/media/drivers/ipu6.rst
>> new file mode 100644
>> index 000000000000..2685e4a0d7ba
>> --- /dev/null
>> +++ b/Documentation/driver-api/media/drivers/ipu6.rst
>> @@ -0,0 +1,205 @@
>> +.. SPDX-License-Identifier: GPL-2.0
>> +
>> +==================
>> +Intel IPU6 Driver
>> +==================
>> +
>> +Author: Bingbu Cao <bingbu.cao@intel.com>
>> +
>> +Overview
>> +=========
>> +
>> +Intel IPU6 is the sixth generation of Intel Image Processing Unit used in some
>> +Intel Chipsets such as Tiger Lake, Jasper Lake, Alder Lake, Raptor Lake and
>> +Meteor Lake. IPU6 consists of two major systems - Input System (IS) and
> 
> I'd use a semicolon:				  ^

semicolon or colon? :)

> 
>> +Processing System (PS). IPU6 are visible on the PCI bus as a single device,
>> +it can be found by ``lspci``:
>> +
>> +``0000:00:05.0 Multimedia controller: Intel Corporation Device xxxx (rev xx)``
>> +
>> +IPU6 has a 16 MB BAR in PCI configuration Space for MMIO registers which is
>> +visible for driver.
>> +
>> +Buttress
>> +=========
>> +
>> +The IPU6 is connecting to the system fabric with ``Buttress`` which is enabling
>> +host driver to control the IPU6, it also allows IPU6 access the system memory to
>> +store and load frame pixel streams and any other metadata.
>> +
>> +``Buttress`` mainly manages several system functionalities - power management,
>> +interrupt handling, firmware authentication and global timer sync.
>> +
>> +IS and PS Power flow
>> +---------------------------
>> +
>> +IPU6 driver initialize the IS and PS power up or down request by setting the
>> +Buttress frequency control register for IS and PS -
>> +``IPU6_BUTTRESS_REG_IS_FREQ_CTL`` and ``IPU6_BUTTRESS_REG_PS_FREQ_CTL`` in
>> +function:
>> +
>> +.. c:function:: int ipu6_buttress_power(..., bool on)
>> +
>> +Buttress forwards the request to Punit, after Punit execute the power up flow,
>> +buttress indicates driver that IS or PS is powered up by updating the power
>> +status registers.
>> +
>> +.. Note:: IS power up needs take place prior to PS power up, IS power down needs
>> +	  take place after PS power down due to hardware limitation.
>> +
>> +
>> +Interrupt
>> +------------
>> +
>> +IPU6 interrupt can be generated as MSI or INTA, interrupt will be triggered
>> +when IS, PS, Buttress event or error happen, driver can get the interrupt
>> +cause by reading the interrupt status register ``BUTTRESS_REG_ISR_STATUS``,
>> +driver firstly clear the irq status and then call specific IS or PS irq handler.
>> +
>> +.. c:function:: irqreturn_t ipu6_buttress_isr(int irq, ...)
>> +
>> +Security and firmware authentication
>> +-------------------------------------
>> +To address the IPU6 firmware security concerns, the IPU6 firmware needs to
>> +undergo an authentication process before it is allowed to executed on the IPU6
>> +internal processors. Driver will work with Converged Security Engine (CSE) to
>> +complete authentication process. CSE is responsible of authenticating the
>> +IPU6 firmware, the authenticated firmware binary is copied into an isolated
>> +memory region. Firmware authentication process is implemented by CSE following
>> +an IPC handshake with driver. There are some Buttress registers used by CSE and
>> +driver to communicate with each other as IPC messages.
>> +
>> +.. c:function:: int ipu6_buttress_authenticate(...)
>> +
>> +Global timer sync
>> +------------------
>> +IPU driver initiates a Hammock Harbor synchronization flow each time it starts
>> +camera operation. IPU will synchronizes an internal counter in the Buttress
>> +with a copy of SoC time, this counter keeps the updated time until camera
>> +operation is stopped. Driver can use this time counter to calibrate the
>> +timestamp based on the timestamp in response event from firmware.
>> +
>> +.. c:function:: int ipu6_buttress_start_tsc_sync(...)
>> +
>> +
>> +DMA and MMU
>> +============
>> +
>> +IPU6 has its own scalar processor where the firmware run at, it has
>> +an internal 32-bits virtual address space. IPU6 has MMU address translation
>> +hardware to allow that scalar process access the internal memory and external
>> +system memory through IPU6 virtual address. The address translation is
>> +based on two levels of page lookup tables stored in system memory which are
>> +maintained by IPU6 driver. IPU6 driver sets the level-1 page table base address
>> +to MMU register and allow MMU to lookup the page table.
>> +
>> +IPU6 driver exports its own DMA operations. Driver will update the page table
>> +entries for each DMA operation and invalidate the MMU TLB after each unmap and
>> +free.
>> +
>> +.. code-block:: none
>> +
>> +    const struct dma_map_ops ipu6_dma_ops = {
>> +	   .alloc = ipu6_dma_alloc,
>> +	   .free = ipu6_dma_free,
>> +	   .mmap = ipu6_dma_mmap,
>> +	   .map_sg = ipu6_dma_map_sg,
>> +	   .unmap_sg = ipu6_dma_unmap_sg,
>> +	   ...
>> +    };
>> +
>> +.. Note:: IPU6 MMU works behind IOMMU, so for each IPU6 DMA ops, driver will
>> +	  call generic PCI DMA ops to ask IOMMU to do the additional mapping
>> +	  if VT-d enabled.
>> +
>> +
>> +Firmware file format
>> +=====================
>> +
>> +IPU6 release the firmware in Code Partition Directory (CPD) file format. The
>> +CPD firmware contains a CPD header, several CPD entries and CPD components.
>> +CPD component includes 3 entries - manifest, metadata and module data. Manifest
>> +and metadata are defined by CSE and used by CSE for authentication. Module data
>> +is defined by IPU6 which holds the binary data of firmware called package
>> +directory. IPU6 driver (``ipu6-cpd.c``) parses and validates the CPD firmware
>> +file and get the package directory binary data of IPU6 firmware, copy it to
>> +specific DMA buffer and sets its base address to Buttress ``FW_SOURCE_BASE``
>> +register, CSE will do authentication for this firmware binary.
>> +
>> +
>> +Syscom interface
>> +================
>> +
>> +IPU6 driver communicates with firmware via syscom ABI. Syscom is an
>> +inter-processor communication mechanism between IPU scalar processor and CPU.
>> +There are a number of resources shared between firmware and software.
>> +A system memory region where the message queues reside, firmware can access the
>> +memory region via IPU MMU. Syscom queues are FIFO fixed depth queues with
>> +configurable elements ``token`` (message). There is also a common IPU MMIO
>> +registers where the queue read and write indices reside. Software and firmware
>> +work as producer and consumer of tokens in queue, and update the write and read
>> +indices separately when sending or receiving each message.
>> +
>> +IPU6 driver must prepare and configure the number of input and output queues,
>> +configure the count of tokens per queue and the size of per token before
>> +initiate and start the communication with firmware, firmware and software must
>> +use same configurations. IPU6 Buttress has a number of firmware boot parameter
>> +registers which can be used to store the address of configuration and initiate
>> +the Syscom state, then driver can request firmware to start and run via setting
>> +the scalar processor control status register.
>> +
>> +
>> +Input System
>> +==============
>> +
>> +IPU6 input system consists of MIPI D-PHY and several CSI receiver controllers,
>> +it can capture image pixel data from camera sensors or other MIPI CSI output
>> +devices.
>> +
>> +DPHYs and CSI2 ports lane mapping
> 
> "D-PHY" and "CSI-2"

Ack.

> 
>> +---------------------------------
>> +
>> +IPU6 integrates different D-PHY IPs on different SoCs, on Tiger Lake and Alder
>> +Lake, IPU6 integrates MCD10 D-PHY, IPU6SE on Jasper Lake integrates JSL D-PHY
>> +and IPU6EP on Meteor Lake integrates a Synopsys DWC D-PHY. There is an adaption
>> +layer between D-PHY and CSI receiver controller which includes port
>> +configuration, PHY wrapper or private test interfaces for D-PHY. There are 3
>> +D-PHY drivers ``ipu6-isys-mcd-phy.c``, ``ipu6-isys-jsl-phy.c`` and
>> +``ipu6-isys-dwc-phy.c`` program the above 3 D-PHYs in IPU6.
>> +
>> +Different IPU6 version has different DPHY lanes mappings, On Tiger Lake, there
>> +are 12 data lanes and 8 clock lanes, IPU6 support maximum 8 CSI2 ports, see
>> +the ppi mmapping in ``ipu6-isys-mcd-phy.c`` for more information. On Jasper Lake
>> +and Alder Lake, DPHY has 8 data lanes and 4 clock lanes, IPU6 support maximum 4
>> +CSI2 ports. For Meteor Lake, DPHY has 12 data lanes and 6 clock lanes, IPU6
>> +support maximum 6 CSI2 ports.
>> +
>> +.. Note:: Each adjacent CSI ports work as a pair and share the data lanes.
>> +	  For example, for CSI port 0 and 1, CSI port 0 support maximum 4
>> +	  data lanes, CSI port 1 support maximum 2 data lanes, CSI port 0
>> +	  with 2 data lanes can work together with CSI port 1 with 2 data lanes.
>> +	  If trying to use CSI port 0 with 4 lanes, CSI port 1 will not be
>> +	  available as the 4 data lanes are shared by CSI port 0 and 1. Same
>> +	  scenario is also applied for CSI port 2/3, 4/5 and 7/8.
>> +
>> +IS firmware ABIs
>> +----------------
>> +
>> +IPU6 firmware define a series of ABIs to software. In general, software firstly
>> +prepare the stream configuration ``struct ipu6_fw_isys_stream_cfg_data_abi``
>> +and send the configuration to firmware via sending ``STREAM_OPEN`` command.
>> +Stream configuration includes input pins and output pins, input pin
>> +``struct ipu6_fw_isys_input_pin_info_abi`` defines the resolution and data type
>> +of input source, output pin ``struct ipu6_fw_isys_output_pin_info_abi``
>> +defines the output resolution, stride and frame format, etc. Once driver get the
>> +interrupt from firmware that indicates stream open successfully, driver will
>> +send the ``STREAM_START`` and ``STREAM_CAPTURE`` command to request firmware to
>> +start capturing image frames. ``STREAM_CAPTURE`` command queues the buffers to
>> +firmware with ``struct ipu6_fw_isys_frame_buff_set``, software then wait the
>> +interrupt and response from firmware, ``PIN_DATA_READY`` means data ready
>> +on specific output pin and then software return the buffers to user.
>> +
>> +.. Note:: See Documentation/admin-guide/media/ipu6-isys.rst for how to do
> 
> Could you add a direct link instead? See e.g.
> Documentation/driver-api/media/camera-sensor.rst for an example.

Good idea, thanks.

> 
>> +	  capture by IPU6 IS driver.
>> +
>> +
> 

-- 
Best regards,
Bingbu Cao

^ permalink raw reply	[flat|nested] 86+ messages in thread

* Re: [PATCH v2 15/15] Documentation: add documentation of Intel IPU6 driver and hardware overview
  2023-10-26  3:38     ` Bingbu Cao
@ 2023-10-26  5:27       ` Sakari Ailus
  0 siblings, 0 replies; 86+ messages in thread
From: Sakari Ailus @ 2023-10-26  5:27 UTC (permalink / raw)
  To: Bingbu Cao
  Cc: bingbu.cao, linux-media, laurent.pinchart, andriy.shevchenko,
	hdegoede, ilpo.jarvinen, andreaskleist, claus.stovgaard, tfiga,
	senozhatsky, tomi.valkeinen, tian.shu.qiu, hongju.wang

Hi Bingbu,

On Thu, Oct 26, 2023 at 11:38:14AM +0800, Bingbu Cao wrote:
> Sakari,
> 
> Thanks for the review.
> 
> On 10/25/23 8:09 PM, Sakari Ailus wrote:
> > Hi Bingbu,
> > 
> > Thanks for the patch. It's a nice piece of documentation for the most
> > complex CSI-2 receiver driver. :-)
> > 
> > On Tue, Oct 24, 2023 at 07:29:24PM +0800, bingbu.cao@intel.com wrote:
> >> From: Bingbu Cao <bingbu.cao@intel.com>
> >>
> >> Add a documentation for an overview of IPU6 hardware and describe the main
> >> the components of IPU6 driver.
> >>
> >> Signed-off-by: Bingbu Cao <bingbu.cao@intel.com>
> >> ---
> >>  .../driver-api/media/drivers/index.rst        |   1 +
> >>  .../driver-api/media/drivers/ipu6.rst         | 205 ++++++++++++++++++
> >>  2 files changed, 206 insertions(+)
> >>  create mode 100644 Documentation/driver-api/media/drivers/ipu6.rst
> >>
> >> diff --git a/Documentation/driver-api/media/drivers/index.rst b/Documentation/driver-api/media/drivers/index.rst
> >> index c4123a16b5f9..7f6f3dcd5c90 100644
> >> --- a/Documentation/driver-api/media/drivers/index.rst
> >> +++ b/Documentation/driver-api/media/drivers/index.rst
> >> @@ -26,6 +26,7 @@ Video4Linux (V4L) drivers
> >>  	vimc-devel
> >>  	zoran
> >>  	ccs/ccs
> >> +	ipu6
> >>  
> >>  
> >>  Digital TV drivers
> >> diff --git a/Documentation/driver-api/media/drivers/ipu6.rst b/Documentation/driver-api/media/drivers/ipu6.rst
> >> new file mode 100644
> >> index 000000000000..2685e4a0d7ba
> >> --- /dev/null
> >> +++ b/Documentation/driver-api/media/drivers/ipu6.rst
> >> @@ -0,0 +1,205 @@
> >> +.. SPDX-License-Identifier: GPL-2.0
> >> +
> >> +==================
> >> +Intel IPU6 Driver
> >> +==================
> >> +
> >> +Author: Bingbu Cao <bingbu.cao@intel.com>
> >> +
> >> +Overview
> >> +=========
> >> +
> >> +Intel IPU6 is the sixth generation of Intel Image Processing Unit used in some
> >> +Intel Chipsets such as Tiger Lake, Jasper Lake, Alder Lake, Raptor Lake and
> >> +Meteor Lake. IPU6 consists of two major systems - Input System (IS) and
> > 
> > I'd use a semicolon:				  ^
> 
> semicolon or colon? :)

A colon, yes, indeed.

-- 
Regards,

Sakari Ailus

^ permalink raw reply	[flat|nested] 86+ messages in thread

* Re: [PATCH v2 01/15] media: intel/ipu6: add Intel IPU6 PCI device driver
  2023-10-24 11:29 ` [PATCH v2 01/15] media: intel/ipu6: add Intel IPU6 PCI device driver bingbu.cao
  2023-10-25 12:39   ` Andreas Helbech Kleist
@ 2023-11-05 14:43   ` Hans de Goede
  2023-11-06  8:55     ` Bingbu Cao
  2023-11-08 11:25   ` Hans de Goede
  2023-11-23  9:17   ` Andreas Helbech Kleist
  3 siblings, 1 reply; 86+ messages in thread
From: Hans de Goede @ 2023-11-05 14:43 UTC (permalink / raw)
  To: bingbu.cao, linux-media, sakari.ailus, laurent.pinchart
  Cc: andriy.shevchenko, hdegoede, ilpo.jarvinen, andreaskleist,
	claus.stovgaard, tfiga, senozhatsky, tomi.valkeinen, bingbu.cao,
	tian.shu.qiu, hongju.wang

Hi,


On 10/24/23 13:29, bingbu.cao@intel.com wrote:
> From: Bingbu Cao <bingbu.cao@intel.com>
> 
> Intel Image Processing Unit 6th Gen includes input and processing systems
> but the hardware presents itself as a single PCI device in system.
> 
> IPU6 PCI device driver basically does PCI configurations and load
> the firmware binary, initialises IPU virtual bus, and sets up platform
> specific variants to support multiple IPU6 devices in single device
> driver.
> 
> Signed-off-by: Bingbu Cao <bingbu.cao@intel.com>
> Reported-by: Hans de Goede <hdegoede@redhat.com>
> Suggested-by: Andreas Helbech Kleist <andreaskleist@gmail.com>

Thank you. Just one small remark, not a full review:

<snip>

> diff --git a/drivers/media/pci/intel/ipu6/ipu6.c b/drivers/media/pci/intel/ipu6/ipu6.c
> new file mode 100644
> index 000000000000..84960a283daf
> --- /dev/null
> +++ b/drivers/media/pci/intel/ipu6/ipu6.c

<snip>

> +static struct ipu6_bus_device *
> +ipu6_isys_init(struct pci_dev *pdev, struct device *parent,
> +	       struct ipu6_buttress_ctrl *ctrl, void __iomem *base,
> +	       const struct ipu6_isys_internal_pdata *ipdata)
> +{
> +	struct fwnode_handle *fwnode = dev_fwnode(&pdev->dev);
> +	struct ipu6_bus_device *isys_adev;
> +	struct ipu6_isys_pdata *pdata;
> +	int ret;
> +
> +	/* check fwnode at first, fallback into bridge if no fwnode graph */
> +	ret = ipu6_isys_check_fwnode_graph(fwnode);
> +	if (ret) {
> +		if (fwnode && !IS_ERR_OR_NULL(fwnode->secondary)) {
> +			dev_err(&pdev->dev,
> +				"fwnode graph has no endpoints connection\n");
> +			return ERR_PTR(-EINVAL);
> +		}
> +
> +		ret = ipu_bridge_init(&pdev->dev, ipu_bridge_parse_ssdb);
> +		if (ret) {
> +			if (ret != -EPROBE_DEFER)
> +				dev_err_probe(&pdev->dev, ret,
> +					      "IPU6 bridge init failed\n");

dev_err_probe() already silences logging of -EPROBE_DEFER errors itself,
so this "if (ret != -EPROBE_DEFER)" guard here is not necessary.

Regards,

Hans





^ permalink raw reply	[flat|nested] 86+ messages in thread

* Re: [PATCH v2 11/15] media: intel/ipu6: input system video capture nodes
  2023-10-24 11:29 ` [PATCH v2 11/15] media: intel/ipu6: input system video capture nodes bingbu.cao
@ 2023-11-05 16:59   ` Hans de Goede
  2023-11-06  9:18     ` Bingbu Cao
  2024-01-09 13:35   ` Andreas Helbech Kleist
  1 sibling, 1 reply; 86+ messages in thread
From: Hans de Goede @ 2023-11-05 16:59 UTC (permalink / raw)
  To: bingbu.cao, linux-media, sakari.ailus, laurent.pinchart
  Cc: andriy.shevchenko, hdegoede, ilpo.jarvinen, andreaskleist,
	claus.stovgaard, tfiga, senozhatsky, tomi.valkeinen, bingbu.cao,
	tian.shu.qiu, hongju.wang

[-- Attachment #1: Type: text/plain, Size: 716 bytes --]

Hi Bingbu,

On 10/24/23 13:29, bingbu.cao@intel.com wrote:
> From: Bingbu Cao <bingbu.cao@intel.com>
> 
> Register v4l2 video device and setup the vb2 queue to
> support basic video capture. Video streaming callback
> will trigger the input system driver to construct a
> input system stream configuration for firmware based on
> data type and stream ID and then queue buffers to firmware
> to do capture.
> 
> Signed-off-by: Bingbu Cao <bingbu.cao@intel.com>

While testing this new version I found a small issue in the enum_fmt implementation caused by the mbus_code filtering support I suggested.

Attached is a single-line patch which fixes this, can you please fold this into the next version ?

Regards,

Hans

[-- Attachment #2: 0001-media-ipu6-isys-video-Do-not-set-mbus_code-from-vidi.patch --]
[-- Type: text/x-patch, Size: 1465 bytes --]

From 4c3b1445f51e8123ac3fb3fbf76b2c429a1c77fa Mon Sep 17 00:00:00 2001
From: Hans de Goede <hdegoede@redhat.com>
Date: Sun, 5 Nov 2023 17:46:52 +0100
Subject: [PATCH] media: ipu6-isys-video: Do not set mbus_code from
 vidioc_enum_fmt_vid_cap

When enumerating userspace will call vidioc_enum_fmt_vid_cap repeatedly
with higher v4l2_fmtdesc.index values until it returns -EINVAL to
indicate all formats have been enumerated.

Some userspace code such as e.g. v4l2-ctl only fills the v4l2_fmtdesc
struct once and then only increases v4l2_fmtdesc.index for subsequent
calls.

Setting v4l2_fmtdesc.mbus_code when it was 0 changes subsequent
vidioc_enum_fmt_vid_cap from unfiltered mode to mbus-code filtered mode
breaking unfiltered enumeration.

Do not set v4l2_fmtdesc.mbus_code in unfiltered mode to fix this.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 drivers/media/pci/intel/ipu6/ipu6-isys-video.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/media/pci/intel/ipu6/ipu6-isys-video.c b/drivers/media/pci/intel/ipu6/ipu6-isys-video.c
index f81934a301b4..e73a46eb7fd3 100644
--- a/drivers/media/pci/intel/ipu6/ipu6-isys-video.c
+++ b/drivers/media/pci/intel/ipu6/ipu6-isys-video.c
@@ -129,7 +129,6 @@ int ipu6_isys_vidioc_enum_fmt(struct file *file, void *fh,
 	if (!f->mbus_code) {
 		f->flags = 0;
 		f->pixelformat = ipu6_isys_pfmts[f->index].pixelformat;
-		f->mbus_code = ipu6_isys_pfmts[f->index].code;
 		return 0;
 	}
 
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 86+ messages in thread

* Re: [PATCH v2 01/15] media: intel/ipu6: add Intel IPU6 PCI device driver
  2023-11-05 14:43   ` Hans de Goede
@ 2023-11-06  8:55     ` Bingbu Cao
  0 siblings, 0 replies; 86+ messages in thread
From: Bingbu Cao @ 2023-11-06  8:55 UTC (permalink / raw)
  To: Hans de Goede, bingbu.cao, linux-media, sakari.ailus, laurent.pinchart
  Cc: andriy.shevchenko, hdegoede, ilpo.jarvinen, andreaskleist,
	claus.stovgaard, tfiga, senozhatsky, tomi.valkeinen,
	tian.shu.qiu, hongju.wang

Hans,

On 11/5/23 10:43 PM, Hans de Goede wrote:
> Hi,
> 
> 
> On 10/24/23 13:29, bingbu.cao@intel.com wrote:
>> From: Bingbu Cao <bingbu.cao@intel.com>
>>
>> Intel Image Processing Unit 6th Gen includes input and processing systems
>> but the hardware presents itself as a single PCI device in system.
>>
>> IPU6 PCI device driver basically does PCI configurations and load
>> the firmware binary, initialises IPU virtual bus, and sets up platform
>> specific variants to support multiple IPU6 devices in single device
>> driver.
>>
>> Signed-off-by: Bingbu Cao <bingbu.cao@intel.com>
>> Reported-by: Hans de Goede <hdegoede@redhat.com>
>> Suggested-by: Andreas Helbech Kleist <andreaskleist@gmail.com>
> 
> Thank you. Just one small remark, not a full review:
> 
> <snip>
> 
>> diff --git a/drivers/media/pci/intel/ipu6/ipu6.c b/drivers/media/pci/intel/ipu6/ipu6.c
>> new file mode 100644
>> index 000000000000..84960a283daf
>> --- /dev/null
>> +++ b/drivers/media/pci/intel/ipu6/ipu6.c
> 
> <snip>
> 
>> +static struct ipu6_bus_device *
>> +ipu6_isys_init(struct pci_dev *pdev, struct device *parent,
>> +	       struct ipu6_buttress_ctrl *ctrl, void __iomem *base,
>> +	       const struct ipu6_isys_internal_pdata *ipdata)
>> +{
>> +	struct fwnode_handle *fwnode = dev_fwnode(&pdev->dev);
>> +	struct ipu6_bus_device *isys_adev;
>> +	struct ipu6_isys_pdata *pdata;
>> +	int ret;
>> +
>> +	/* check fwnode at first, fallback into bridge if no fwnode graph */
>> +	ret = ipu6_isys_check_fwnode_graph(fwnode);
>> +	if (ret) {
>> +		if (fwnode && !IS_ERR_OR_NULL(fwnode->secondary)) {
>> +			dev_err(&pdev->dev,
>> +				"fwnode graph has no endpoints connection\n");
>> +			return ERR_PTR(-EINVAL);
>> +		}
>> +
>> +		ret = ipu_bridge_init(&pdev->dev, ipu_bridge_parse_ssdb);
>> +		if (ret) {
>> +			if (ret != -EPROBE_DEFER)
>> +				dev_err_probe(&pdev->dev, ret,
>> +					      "IPU6 bridge init failed\n");
> 
> dev_err_probe() already silences logging of -EPROBE_DEFER errors itself,
> so this "if (ret != -EPROBE_DEFER)" guard here is not necessary.

Good catch, thanks.

> 
> Regards,
> 
> Hans
> 
> 
> 
> 

-- 
Best regards,
Bingbu Cao

^ permalink raw reply	[flat|nested] 86+ messages in thread

* Re: [PATCH v2 11/15] media: intel/ipu6: input system video capture nodes
  2023-11-05 16:59   ` Hans de Goede
@ 2023-11-06  9:18     ` Bingbu Cao
  2023-11-06 11:17       ` Andy Shevchenko
  0 siblings, 1 reply; 86+ messages in thread
From: Bingbu Cao @ 2023-11-06  9:18 UTC (permalink / raw)
  To: Hans de Goede, bingbu.cao, linux-media, sakari.ailus, laurent.pinchart
  Cc: andriy.shevchenko, hdegoede, ilpo.jarvinen, andreaskleist,
	claus.stovgaard, tfiga, senozhatsky, tomi.valkeinen,
	tian.shu.qiu, hongju.wang

Hans,

On 11/6/23 12:59 AM, Hans de Goede wrote:
> Hi Bingbu,
> 
> On 10/24/23 13:29, bingbu.cao@intel.com wrote:
>> From: Bingbu Cao <bingbu.cao@intel.com>
>>
>> Register v4l2 video device and setup the vb2 queue to
>> support basic video capture. Video streaming callback
>> will trigger the input system driver to construct a
>> input system stream configuration for firmware based on
>> data type and stream ID and then queue buffers to firmware
>> to do capture.
>>
>> Signed-off-by: Bingbu Cao <bingbu.cao@intel.com>
> 
> While testing this new version I found a small issue in the enum_fmt implementation caused by the mbus_code filtering support I suggested.
> 
> Attached is a single-line patch which fixes this, can you please fold this into the next version ?

Yes, sure.

> 
> Regards,
> 
> Hans
> 

-- 
Best regards,
Bingbu Cao

^ permalink raw reply	[flat|nested] 86+ messages in thread

* Re: [PATCH v2 11/15] media: intel/ipu6: input system video capture nodes
  2023-11-06  9:18     ` Bingbu Cao
@ 2023-11-06 11:17       ` Andy Shevchenko
  2023-12-05  9:15         ` Bingbu Cao
  0 siblings, 1 reply; 86+ messages in thread
From: Andy Shevchenko @ 2023-11-06 11:17 UTC (permalink / raw)
  To: Bingbu Cao
  Cc: Hans de Goede, bingbu.cao, linux-media, sakari.ailus,
	laurent.pinchart, hdegoede, ilpo.jarvinen, andreaskleist,
	claus.stovgaard, tfiga, senozhatsky, tomi.valkeinen,
	tian.shu.qiu, hongju.wang

On Mon, Nov 06, 2023 at 05:18:55PM +0800, Bingbu Cao wrote:
> On 11/6/23 12:59 AM, Hans de Goede wrote:

...

> Yes, sure.

It's likely that I meant this series (it's under development, right?) to be
Cc'ed to me in its next version.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 86+ messages in thread

* Re: [PATCH v2 01/15] media: intel/ipu6: add Intel IPU6 PCI device driver
  2023-10-24 11:29 ` [PATCH v2 01/15] media: intel/ipu6: add Intel IPU6 PCI device driver bingbu.cao
  2023-10-25 12:39   ` Andreas Helbech Kleist
  2023-11-05 14:43   ` Hans de Goede
@ 2023-11-08 11:25   ` Hans de Goede
  2023-11-08 13:24     ` Andy Shevchenko
  2023-11-08 14:10     ` Andreas Helbech Kleist
  2023-11-23  9:17   ` Andreas Helbech Kleist
  3 siblings, 2 replies; 86+ messages in thread
From: Hans de Goede @ 2023-11-08 11:25 UTC (permalink / raw)
  To: bingbu.cao, linux-media, sakari.ailus, laurent.pinchart
  Cc: andriy.shevchenko, hdegoede, ilpo.jarvinen, andreaskleist,
	claus.stovgaard, tfiga, senozhatsky, tomi.valkeinen, bingbu.cao,
	tian.shu.qiu, hongju.wang

Hi,

On 10/24/23 13:29, bingbu.cao@intel.com wrote:
> From: Bingbu Cao <bingbu.cao@intel.com>
> 
> Intel Image Processing Unit 6th Gen includes input and processing systems
> but the hardware presents itself as a single PCI device in system.
> 
> IPU6 PCI device driver basically does PCI configurations and load
> the firmware binary, initialises IPU virtual bus, and sets up platform
> specific variants to support multiple IPU6 devices in single device
> driver.
> 
> Signed-off-by: Bingbu Cao <bingbu.cao@intel.com>
> Reported-by: Hans de Goede <hdegoede@redhat.com>
> Suggested-by: Andreas Helbech Kleist <andreaskleist@gmail.com>
> ---
>  .../media/pci/intel/ipu6/ipu6-platform-regs.h | 179 ++++
>  drivers/media/pci/intel/ipu6/ipu6.c           | 952 ++++++++++++++++++
>  drivers/media/pci/intel/ipu6/ipu6.h           | 352 +++++++
>  3 files changed, 1483 insertions(+)
>  create mode 100644 drivers/media/pci/intel/ipu6/ipu6-platform-regs.h
>  create mode 100644 drivers/media/pci/intel/ipu6/ipu6.c
>  create mode 100644 drivers/media/pci/intel/ipu6/ipu6.h

<snip>

> diff --git a/drivers/media/pci/intel/ipu6/ipu6.c b/drivers/media/pci/intel/ipu6/ipu6.c
> new file mode 100644
> index 000000000000..84960a283daf
> --- /dev/null
> +++ b/drivers/media/pci/intel/ipu6/ipu6.c
> @@ -0,0 +1,952 @@

<snip>

> +static int ipu6_pci_config_setup(struct pci_dev *dev, u8 hw_ver)
> +{
> +	int ret;
> +
> +	/* disable IPU6 PCI ATS on mtl ES2 */
> +	if (is_ipu6ep_mtl(hw_ver) && boot_cpu_data.x86_stepping == 0x2 &&
> +	    pci_ats_supported(dev))
> +		pci_disable_ats(dev);
> +
> +	/* No PCI msi capability for IPU6EP */
> +	if (is_ipu6ep(hw_ver) || is_ipu6ep_mtl(hw_ver)) {
> +		/* likely do nothing as msi not enabled by default */
> +		pci_disable_msi(dev);
> +		return 0;
> +	}
> +
> +	ret = pci_alloc_irq_vectors(dev, 1, 1, PCI_IRQ_MSI);

This does not work on TGL systems (and is not reached on ADL and RPL).

The out of tree driver instead uses:

        ret = pci_enable_msi(dev);

and that does work correctly on TGL.

Regards,

Hans



^ permalink raw reply	[flat|nested] 86+ messages in thread

* Re: [PATCH v2 08/15] media: intel/ipu6: add IPU6 CSI2 receiver v4l2 sub-device
  2023-10-24 11:29 ` [PATCH v2 08/15] media: intel/ipu6: add IPU6 CSI2 receiver v4l2 sub-device bingbu.cao
@ 2023-11-08 11:25   ` Andreas Helbech Kleist
  2023-11-08 14:50     ` Cao, Bingbu
  0 siblings, 1 reply; 86+ messages in thread
From: Andreas Helbech Kleist @ 2023-11-08 11:25 UTC (permalink / raw)
  To: bingbu.cao, linux-media, sakari.ailus, laurent.pinchart
  Cc: andriy.shevchenko, hdegoede, ilpo.jarvinen, claus.stovgaard,
	tfiga, senozhatsky, tomi.valkeinen, bingbu.cao, tian.shu.qiu,
	hongju.wang

Hi Bingbu,

On Tue, 2023-10-24 at 19:29 +0800, bingbu.cao@intel.com wrote:
> From: Bingbu Cao <bingbu.cao@intel.com>
> 
> Input system CSI2 receiver is exposed as a v4l2 sub-device.
> Each CSI2 sub-device represent one single CSI2 hardware port
> which be linked with external sub-device such camera sensor
> by linked with ISYS CSI2's sink pad. CSI2 source pad is linked
> to the sink pad of video capture device.
> 
> Signed-off-by: Bingbu Cao <bingbu.cao@intel.com>
> ---
>  drivers/media/pci/intel/ipu6/ipu6-isys-csi2.c | 654
> ++++++++++++++++++
>  drivers/media/pci/intel/ipu6/ipu6-isys-csi2.h |  81 +++
>  .../media/pci/intel/ipu6/ipu6-isys-subdev.c   | 379 ++++++++++
>  .../media/pci/intel/ipu6/ipu6-isys-subdev.h   |  58 ++
>  .../intel/ipu6/ipu6-platform-isys-csi2-reg.h  | 187 +++++
>  5 files changed, 1359 insertions(+)
>  create mode 100644 drivers/media/pci/intel/ipu6/ipu6-isys-csi2.c
>  create mode 100644 drivers/media/pci/intel/ipu6/ipu6-isys-csi2.h
>  create mode 100644 drivers/media/pci/intel/ipu6/ipu6-isys-subdev.c
>  create mode 100644 drivers/media/pci/intel/ipu6/ipu6-isys-subdev.h
>  create mode 100644 drivers/media/pci/intel/ipu6/ipu6-platform-isys-
> csi2-reg.h
> 
> diff --git a/drivers/media/pci/intel/ipu6/ipu6-isys-csi2.c
> b/drivers/media/pci/intel/ipu6/ipu6-isys-csi2.c
> new file mode 100644
> index 000000000000..0dedf3f51850
> --- /dev/null
> +++ b/drivers/media/pci/intel/ipu6/ipu6-isys-csi2.c
...
> 
> +
> +#define DIV_SHIFT      8
> +#define CSI2_ACCINV    8
> +
> +static u32 calc_timing(s32 a, s32 b, s64 link_freq, u32 accinv)
> +{
> +       return accinv * a + (accinv * b * (500000000 >> DIV_SHIFT)
> +                            / (int32_t)(link_freq >> DIV_SHIFT));
> +}

I think accinv should be s32 here. When accinv is unsigned, the
expression (accinv * b) becomes unsigned, and thus negative values of b
gives incorrect results. 

This is different from e.g. https://github.com/intel/ipu6-drivers.

/Andreas

^ permalink raw reply	[flat|nested] 86+ messages in thread

* Re: [PATCH v2 00/15] Intel IPU6 and IPU6 input system drivers
  2023-10-24 11:29 [PATCH v2 00/15] Intel IPU6 and IPU6 input system drivers bingbu.cao
                   ` (14 preceding siblings ...)
  2023-10-24 11:29 ` [PATCH v2 15/15] Documentation: add documentation of Intel IPU6 driver and hardware overview bingbu.cao
@ 2023-11-08 11:59 ` Hans de Goede
  2023-11-08 14:31   ` Cao, Bingbu
                     ` (3 more replies)
  2024-02-07  7:00 ` Sakari Ailus
  16 siblings, 4 replies; 86+ messages in thread
From: Hans de Goede @ 2023-11-08 11:59 UTC (permalink / raw)
  To: bingbu.cao, linux-media, sakari.ailus, laurent.pinchart
  Cc: andriy.shevchenko, hdegoede, ilpo.jarvinen, andreaskleist,
	claus.stovgaard, tfiga, senozhatsky, tomi.valkeinen, bingbu.cao,
	tian.shu.qiu, hongju.wang

Hi Bingbu,

On 10/24/23 13:29, bingbu.cao@intel.com wrote:
> From: Bingbu Cao <bingbu.cao@intel.com>
> 
> This patch series adds a driver for Intel IPU6 input system.
> IPU6 is the sixth generation of Imaging Processing Unit, it is a PCI
> device which can be found in some Intel Client Platforms. User can use
> IPU6 to capture images from MIPI camera sensors.
> 
> IPU6 has its own firmware which exposes ABIs to driver, and communicates
> with CSE to do firmware authentication. IPU6 has its MMU hardware, so
> the driver sets up a page table to allow IPU6 DMA to access the system
> memory.
> 
> IPU6 input system driver uses MC and V4L2 sub-device APIs besides V4L2.

I have been testing this on a TigerLake system, a Dell Latitude 9420
with ov01a1s and the packed 10 bit bayer pixel fmt: V4L2_PIX_FMT_SGRBG10P,
which libcamera together with (WIP) software debayer support picks
by default does not work. There are many many CSI errors in dmesg
and only the first 10 or so lines of the image show.

Disabling the packed format by removing it from ipu6_isys_pfmts[],
making libcamera pick the unpacked (every 10 bits per pixel data
stored in a 16 bit word in output buffer) fixes this.

Are the packed bayer formats supposed to work on Tiger Lake, or
is this a known issue which Intel's own userspace stack avoids
by always picking the unpacked format ?

Regards,

Hans



^ permalink raw reply	[flat|nested] 86+ messages in thread

* Re: [PATCH v2 01/15] media: intel/ipu6: add Intel IPU6 PCI device driver
  2023-11-08 11:25   ` Hans de Goede
@ 2023-11-08 13:24     ` Andy Shevchenko
  2023-11-08 14:10     ` Andreas Helbech Kleist
  1 sibling, 0 replies; 86+ messages in thread
From: Andy Shevchenko @ 2023-11-08 13:24 UTC (permalink / raw)
  To: Hans de Goede
  Cc: bingbu.cao, linux-media, sakari.ailus, laurent.pinchart,
	hdegoede, ilpo.jarvinen, andreaskleist, claus.stovgaard, tfiga,
	senozhatsky, tomi.valkeinen, bingbu.cao, tian.shu.qiu,
	hongju.wang

On Wed, Nov 08, 2023 at 12:25:19PM +0100, Hans de Goede wrote:
> On 10/24/23 13:29, bingbu.cao@intel.com wrote:

...

> > +	ret = pci_alloc_irq_vectors(dev, 1, 1, PCI_IRQ_MSI);
> 
> This does not work on TGL systems (and is not reached on ADL and RPL).
> 
> The out of tree driver instead uses:
> 
>         ret = pci_enable_msi(dev);
> 
> and that does work correctly on TGL.

Does it mean TGL uses legacy IRQ?
In that case we need to simply change the flag to allow that as the used API
is what documentation says needs to be used and pci_enable_msi() is deprecated.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 86+ messages in thread

* Re: [PATCH v2 01/15] media: intel/ipu6: add Intel IPU6 PCI device driver
  2023-11-08 11:25   ` Hans de Goede
  2023-11-08 13:24     ` Andy Shevchenko
@ 2023-11-08 14:10     ` Andreas Helbech Kleist
  2023-11-08 14:18       ` Cao, Bingbu
  2023-11-17 18:43       ` Hans de Goede
  1 sibling, 2 replies; 86+ messages in thread
From: Andreas Helbech Kleist @ 2023-11-08 14:10 UTC (permalink / raw)
  To: Hans de Goede, bingbu.cao, linux-media, sakari.ailus, laurent.pinchart
  Cc: andriy.shevchenko, hdegoede, ilpo.jarvinen, claus.stovgaard,
	tfiga, senozhatsky, tomi.valkeinen, bingbu.cao, tian.shu.qiu,
	hongju.wang

Hi Hans,

On Wed, 2023-11-08 at 12:25 +0100, Hans de Goede wrote:
> Hi,
> 
> On 10/24/23 13:29, bingbu.cao@intel.com wrote:
> > From: Bingbu Cao <bingbu.cao@intel.com>
> > 
> > Intel Image Processing Unit 6th Gen includes input and processing
> > systems
> > but the hardware presents itself as a single PCI device in system.
> > 
> > IPU6 PCI device driver basically does PCI configurations and load
> > the firmware binary, initialises IPU virtual bus, and sets up
> > platform
> > specific variants to support multiple IPU6 devices in single device
> > driver.
> > 
> > Signed-off-by: Bingbu Cao <bingbu.cao@intel.com>
> > Reported-by: Hans de Goede <hdegoede@redhat.com>
> > Suggested-by: Andreas Helbech Kleist <andreaskleist@gmail.com>
> > ---
> >  .../media/pci/intel/ipu6/ipu6-platform-regs.h | 179 ++++
> >  drivers/media/pci/intel/ipu6/ipu6.c           | 952
> > ++++++++++++++++++
> >  drivers/media/pci/intel/ipu6/ipu6.h           | 352 +++++++
> >  3 files changed, 1483 insertions(+)
> >  create mode 100644 drivers/media/pci/intel/ipu6/ipu6-platform-
> > regs.h
> >  create mode 100644 drivers/media/pci/intel/ipu6/ipu6.c
> >  create mode 100644 drivers/media/pci/intel/ipu6/ipu6.h
> 
> <snip>
> 
> > diff --git a/drivers/media/pci/intel/ipu6/ipu6.c
> > b/drivers/media/pci/intel/ipu6/ipu6.c
> > new file mode 100644
> > index 000000000000..84960a283daf
> > --- /dev/null
> > +++ b/drivers/media/pci/intel/ipu6/ipu6.c
> > @@ -0,0 +1,952 @@
> 
> <snip>
> 
> > +static int ipu6_pci_config_setup(struct pci_dev *dev, u8 hw_ver)
> > +{
> > +       int ret;
> > +
> > +       /* disable IPU6 PCI ATS on mtl ES2 */
> > +       if (is_ipu6ep_mtl(hw_ver) && boot_cpu_data.x86_stepping ==
> > 0x2 &&
> > +           pci_ats_supported(dev))
> > +               pci_disable_ats(dev);
> > +
> > +       /* No PCI msi capability for IPU6EP */
> > +       if (is_ipu6ep(hw_ver) || is_ipu6ep_mtl(hw_ver)) {
> > +               /* likely do nothing as msi not enabled by default
> > */
> > +               pci_disable_msi(dev);
> > +               return 0;
> > +       }
> > +
> > +       ret = pci_alloc_irq_vectors(dev, 1, 1, PCI_IRQ_MSI);
> 
> This does not work on TGL systems (and is not reached on ADL and
> RPL).
> 
> The out of tree driver instead uses:
> 
>         ret = pci_enable_msi(dev);
> 
> and that does work correctly on TGL.

Did you see my previous (25//10) comment on the same lines? 

pci_alloc_irq_vectors returns number of irqs, so the "if (ret)" check
following the quoted line is wrong.

/Andreas

^ permalink raw reply	[flat|nested] 86+ messages in thread

* RE: [PATCH v2 01/15] media: intel/ipu6: add Intel IPU6 PCI device driver
  2023-11-08 14:10     ` Andreas Helbech Kleist
@ 2023-11-08 14:18       ` Cao, Bingbu
  2023-11-17 18:43       ` Hans de Goede
  1 sibling, 0 replies; 86+ messages in thread
From: Cao, Bingbu @ 2023-11-08 14:18 UTC (permalink / raw)
  To: Andreas Helbech Kleist, Hans de Goede, linux-media, sakari.ailus,
	laurent.pinchart
  Cc: andriy.shevchenko, hdegoede, ilpo.jarvinen, claus.stovgaard,
	tfiga, senozhatsky, tomi.valkeinen, bingbu.cao, Qiu, Tian Shu,
	Wang, Hongju

Andreas,


------------------------------------------------------------------------
BRs,  
Bingbu Cao 

>-----Original Message-----
>From: Andreas Helbech Kleist <andreaskleist@gmail.com>
>Sent: Wednesday, November 8, 2023 10:11 PM
>To: Hans de Goede <hans@hansg.org>; Cao, Bingbu <bingbu.cao@intel.com>;
>linux-media@vger.kernel.org; sakari.ailus@linux.intel.com;
>laurent.pinchart@ideasonboard.com
>Cc: andriy.shevchenko@linux.intel.com; hdegoede@redhat.com;
>ilpo.jarvinen@linux.intel.com; claus.stovgaard@gmail.com;
>tfiga@chromium.org; senozhatsky@chromium.org;
>tomi.valkeinen@ideasonboard.com; bingbu.cao@linux.intel.com; Qiu, Tian Shu
><tian.shu.qiu@intel.com>; Wang, Hongju <hongju.wang@intel.com>
>Subject: Re: [PATCH v2 01/15] media: intel/ipu6: add Intel IPU6 PCI device
>driver
>
>Hi Hans,
>
>On Wed, 2023-11-08 at 12:25 +0100, Hans de Goede wrote:
>> Hi,
>>
>> On 10/24/23 13:29, bingbu.cao@intel.com wrote:
>> > From: Bingbu Cao <bingbu.cao@intel.com>
>> >
>> > Intel Image Processing Unit 6th Gen includes input and processing
>> > systems but the hardware presents itself as a single PCI device in
>> > system.
>> >
>> > IPU6 PCI device driver basically does PCI configurations and load
>> > the firmware binary, initialises IPU virtual bus, and sets up
>> > platform specific variants to support multiple IPU6 devices in
>> > single device driver.
>> >
>> > Signed-off-by: Bingbu Cao <bingbu.cao@intel.com>
>> > Reported-by: Hans de Goede <hdegoede@redhat.com>
>> > Suggested-by: Andreas Helbech Kleist <andreaskleist@gmail.com>
>> > ---
>> >  .../media/pci/intel/ipu6/ipu6-platform-regs.h | 179 ++++
>> >  drivers/media/pci/intel/ipu6/ipu6.c           | 952
>> > ++++++++++++++++++
>> >  drivers/media/pci/intel/ipu6/ipu6.h           | 352 +++++++
>> >  3 files changed, 1483 insertions(+)
>> >  create mode 100644 drivers/media/pci/intel/ipu6/ipu6-platform-
>> > regs.h
>> >  create mode 100644 drivers/media/pci/intel/ipu6/ipu6.c
>> >  create mode 100644 drivers/media/pci/intel/ipu6/ipu6.h
>>
>> <snip>
>>
>> > diff --git a/drivers/media/pci/intel/ipu6/ipu6.c
>> > b/drivers/media/pci/intel/ipu6/ipu6.c
>> > new file mode 100644
>> > index 000000000000..84960a283daf
>> > --- /dev/null
>> > +++ b/drivers/media/pci/intel/ipu6/ipu6.c
>> > @@ -0,0 +1,952 @@
>>
>> <snip>
>>
>> > +static int ipu6_pci_config_setup(struct pci_dev *dev, u8 hw_ver) {
>> > +       int ret;
>> > +
>> > +       /* disable IPU6 PCI ATS on mtl ES2 */
>> > +       if (is_ipu6ep_mtl(hw_ver) && boot_cpu_data.x86_stepping ==
>> > 0x2 &&
>> > +           pci_ats_supported(dev))
>> > +               pci_disable_ats(dev);
>> > +
>> > +       /* No PCI msi capability for IPU6EP */
>> > +       if (is_ipu6ep(hw_ver) || is_ipu6ep_mtl(hw_ver)) {
>> > +               /* likely do nothing as msi not enabled by default
>> > */
>> > +               pci_disable_msi(dev);
>> > +               return 0;
>> > +       }
>> > +
>> > +       ret = pci_alloc_irq_vectors(dev, 1, 1, PCI_IRQ_MSI);
>>
>> This does not work on TGL systems (and is not reached on ADL and RPL).
>>
>> The out of tree driver instead uses:
>>
>>         ret = pci_enable_msi(dev);
>>
>> and that does work correctly on TGL.
>
>Did you see my previous (25//10) comment on the same lines?
>
>pci_alloc_irq_vectors returns number of irqs, so the "if (ret)" check
>following the quoted line is wrong.

Andreas,

You are right, the actual problem is the return value checking is wrong.

Hans, thanks for your report. I don't have TGL device now. ☹
I will fix it in next version.


>
>/Andreas

^ permalink raw reply	[flat|nested] 86+ messages in thread

* RE: [PATCH v2 00/15] Intel IPU6 and IPU6 input system drivers
  2023-11-08 11:59 ` [PATCH v2 00/15] Intel IPU6 and IPU6 input system drivers Hans de Goede
@ 2023-11-08 14:31   ` Cao, Bingbu
  2023-11-08 15:15     ` Hans de Goede
  2023-11-10 12:04   ` Hans de Goede
                     ` (2 subsequent siblings)
  3 siblings, 1 reply; 86+ messages in thread
From: Cao, Bingbu @ 2023-11-08 14:31 UTC (permalink / raw)
  To: Hans de Goede, linux-media, sakari.ailus, laurent.pinchart
  Cc: andriy.shevchenko, hdegoede, ilpo.jarvinen, andreaskleist,
	claus.stovgaard, tfiga, senozhatsky, tomi.valkeinen, bingbu.cao,
	Qiu, Tian Shu, Wang, Hongju

Hans,

------------------------------------------------------------------------
BRs,  
Bingbu Cao 

>-----Original Message-----
>From: Hans de Goede <hans@hansg.org>
>Sent: Wednesday, November 8, 2023 8:00 PM
>To: Cao, Bingbu <bingbu.cao@intel.com>; linux-media@vger.kernel.org;
>sakari.ailus@linux.intel.com; laurent.pinchart@ideasonboard.com
>Cc: andriy.shevchenko@linux.intel.com; hdegoede@redhat.com;
>ilpo.jarvinen@linux.intel.com; andreaskleist@gmail.com;
>claus.stovgaard@gmail.com; tfiga@chromium.org; senozhatsky@chromium.org;
>tomi.valkeinen@ideasonboard.com; bingbu.cao@linux.intel.com; Qiu, Tian Shu
><tian.shu.qiu@intel.com>; Wang, Hongju <hongju.wang@intel.com>
>Subject: Re: [PATCH v2 00/15] Intel IPU6 and IPU6 input system drivers
>
>Hi Bingbu,
>
>On 10/24/23 13:29, bingbu.cao@intel.com wrote:
>> From: Bingbu Cao <bingbu.cao@intel.com>
>>
>> This patch series adds a driver for Intel IPU6 input system.
>> IPU6 is the sixth generation of Imaging Processing Unit, it is a PCI
>> device which can be found in some Intel Client Platforms. User can use
>> IPU6 to capture images from MIPI camera sensors.
>>
>> IPU6 has its own firmware which exposes ABIs to driver, and
>> communicates with CSE to do firmware authentication. IPU6 has its MMU
>> hardware, so the driver sets up a page table to allow IPU6 DMA to
>> access the system memory.
>>
>> IPU6 input system driver uses MC and V4L2 sub-device APIs besides V4L2.
>
>I have been testing this on a TigerLake system, a Dell Latitude 9420 with
>ov01a1s and the packed 10 bit bayer pixel fmt: V4L2_PIX_FMT_SGRBG10P, which
>libcamera together with (WIP) software debayer support picks by default
>does not work. There are many many CSI errors in dmesg and only the first
>10 or so lines of the image show.
>
>Disabling the packed format by removing it from ipu6_isys_pfmts[], making
>libcamera pick the unpacked (every 10 bits per pixel data stored in a 16
>bit word in output buffer) fixes this.
>
>Are the packed bayer formats supposed to work on Tiger Lake, or is this a
>known issue which Intel's own userspace stack avoids by always picking the
>unpacked format ?

Thanks for the test.

I remember I verified SGRBG10P format on my ADL device before, but I have
not tested that for a while, give me some time to test again and come back.

>
>Regards,
>
>Hans
>


^ permalink raw reply	[flat|nested] 86+ messages in thread

* RE: [PATCH v2 08/15] media: intel/ipu6: add IPU6 CSI2 receiver v4l2 sub-device
  2023-11-08 11:25   ` Andreas Helbech Kleist
@ 2023-11-08 14:50     ` Cao, Bingbu
  2023-11-08 14:51       ` Bingbu Cao
  2023-11-08 15:00       ` Andreas Helbech Kleist
  0 siblings, 2 replies; 86+ messages in thread
From: Cao, Bingbu @ 2023-11-08 14:50 UTC (permalink / raw)
  To: Andreas Helbech Kleist, linux-media, sakari.ailus, laurent.pinchart
  Cc: andriy.shevchenko, hdegoede, ilpo.jarvinen, claus.stovgaard,
	tfiga, senozhatsky, tomi.valkeinen, bingbu.cao, Qiu, Tian Shu,
	Wang, Hongju

Andreas,

------------------------------------------------------------------------
BRs,  
Bingbu Cao 

>-----Original Message-----
>From: Andreas Helbech Kleist <andreaskleist@gmail.com>
>Sent: Wednesday, November 8, 2023 7:26 PM
>To: Cao, Bingbu <bingbu.cao@intel.com>; linux-media@vger.kernel.org;
>sakari.ailus@linux.intel.com; laurent.pinchart@ideasonboard.com
>Cc: andriy.shevchenko@linux.intel.com; hdegoede@redhat.com;
>ilpo.jarvinen@linux.intel.com; claus.stovgaard@gmail.com;
>tfiga@chromium.org; senozhatsky@chromium.org;
>tomi.valkeinen@ideasonboard.com; bingbu.cao@linux.intel.com; Qiu, Tian Shu
><tian.shu.qiu@intel.com>; Wang, Hongju <hongju.wang@intel.com>
>Subject: Re: [PATCH v2 08/15] media: intel/ipu6: add IPU6 CSI2 receiver
>v4l2 sub-device
>
>Hi Bingbu,
>
>On Tue, 2023-10-24 at 19:29 +0800, bingbu.cao@intel.com wrote:
>> From: Bingbu Cao <bingbu.cao@intel.com>
>>
>> Input system CSI2 receiver is exposed as a v4l2 sub-device.
>> Each CSI2 sub-device represent one single CSI2 hardware port which be
>> linked with external sub-device such camera sensor by linked with ISYS
>> CSI2's sink pad. CSI2 source pad is linked to the sink pad of video
>> capture device.
>>
>> Signed-off-by: Bingbu Cao <bingbu.cao@intel.com>
>> ---
>>  drivers/media/pci/intel/ipu6/ipu6-isys-csi2.c | 654
>> ++++++++++++++++++
>>  drivers/media/pci/intel/ipu6/ipu6-isys-csi2.h |  81 +++
>>  .../media/pci/intel/ipu6/ipu6-isys-subdev.c   | 379 ++++++++++
>>  .../media/pci/intel/ipu6/ipu6-isys-subdev.h   |  58 ++
>>  .../intel/ipu6/ipu6-platform-isys-csi2-reg.h  | 187 +++++
>>  5 files changed, 1359 insertions(+)
>>  create mode 100644 drivers/media/pci/intel/ipu6/ipu6-isys-csi2.c
>>  create mode 100644 drivers/media/pci/intel/ipu6/ipu6-isys-csi2.h
>>  create mode 100644 drivers/media/pci/intel/ipu6/ipu6-isys-subdev.c
>>  create mode 100644 drivers/media/pci/intel/ipu6/ipu6-isys-subdev.h
>>  create mode 100644 drivers/media/pci/intel/ipu6/ipu6-platform-isys-
>> csi2-reg.h
>>
>> diff --git a/drivers/media/pci/intel/ipu6/ipu6-isys-csi2.c
>> b/drivers/media/pci/intel/ipu6/ipu6-isys-csi2.c
>> new file mode 100644
>> index 000000000000..0dedf3f51850
>> --- /dev/null
>> +++ b/drivers/media/pci/intel/ipu6/ipu6-isys-csi2.c
>...
>>
>> +
>> +#define DIV_SHIFT      8
>> +#define CSI2_ACCINV    8
>> +
>> +static u32 calc_timing(s32 a, s32 b, s64 link_freq, u32 accinv) {
>> +       return accinv * a + (accinv * b * (500000000 >> DIV_SHIFT)
>> +                            / (int32_t)(link_freq >> DIV_SHIFT)); }
>
>I think accinv should be s32 here. When accinv is unsigned, the expression
>(accinv * b) becomes unsigned, and thus negative values of b gives
>incorrect results.

accinv is always an unsigned value, so I think we don't need change the
type of argument. Following usual arithmetic conversions, I think it needs
a signed integer cast here. What do you think?


>
>This is different from e.g. https://github.com/intel/ipu6-drivers.
>
>/Andreas

^ permalink raw reply	[flat|nested] 86+ messages in thread

* Re: [PATCH v2 08/15] media: intel/ipu6: add IPU6 CSI2 receiver v4l2 sub-device
  2023-11-08 14:50     ` Cao, Bingbu
@ 2023-11-08 14:51       ` Bingbu Cao
  2023-11-08 15:00       ` Andreas Helbech Kleist
  1 sibling, 0 replies; 86+ messages in thread
From: Bingbu Cao @ 2023-11-08 14:51 UTC (permalink / raw)
  To: Cao, Bingbu, Andreas Helbech Kleist, linux-media, sakari.ailus,
	laurent.pinchart
  Cc: andriy.shevchenko, hdegoede, ilpo.jarvinen, claus.stovgaard,
	tfiga, senozhatsky, tomi.valkeinen, Qiu, Tian Shu, Wang, Hongju



On 11/8/23 10:50 PM, Cao, Bingbu wrote:
> Andreas,
> 
> ------------------------------------------------------------------------
> BRs,  
> Bingbu Cao 
> 
>> -----Original Message-----
>> From: Andreas Helbech Kleist <andreaskleist@gmail.com>
>> Sent: Wednesday, November 8, 2023 7:26 PM
>> To: Cao, Bingbu <bingbu.cao@intel.com>; linux-media@vger.kernel.org;
>> sakari.ailus@linux.intel.com; laurent.pinchart@ideasonboard.com
>> Cc: andriy.shevchenko@linux.intel.com; hdegoede@redhat.com;
>> ilpo.jarvinen@linux.intel.com; claus.stovgaard@gmail.com;
>> tfiga@chromium.org; senozhatsky@chromium.org;
>> tomi.valkeinen@ideasonboard.com; bingbu.cao@linux.intel.com; Qiu, Tian Shu
>> <tian.shu.qiu@intel.com>; Wang, Hongju <hongju.wang@intel.com>
>> Subject: Re: [PATCH v2 08/15] media: intel/ipu6: add IPU6 CSI2 receiver
>> v4l2 sub-device
>>
>> Hi Bingbu,
>>
>> On Tue, 2023-10-24 at 19:29 +0800, bingbu.cao@intel.com wrote:
>>> From: Bingbu Cao <bingbu.cao@intel.com>
>>>
>>> Input system CSI2 receiver is exposed as a v4l2 sub-device.
>>> Each CSI2 sub-device represent one single CSI2 hardware port which be
>>> linked with external sub-device such camera sensor by linked with ISYS
>>> CSI2's sink pad. CSI2 source pad is linked to the sink pad of video
>>> capture device.
>>>
>>> Signed-off-by: Bingbu Cao <bingbu.cao@intel.com>
>>> ---
>>>  drivers/media/pci/intel/ipu6/ipu6-isys-csi2.c | 654
>>> ++++++++++++++++++
>>>  drivers/media/pci/intel/ipu6/ipu6-isys-csi2.h |  81 +++
>>>  .../media/pci/intel/ipu6/ipu6-isys-subdev.c   | 379 ++++++++++
>>>  .../media/pci/intel/ipu6/ipu6-isys-subdev.h   |  58 ++
>>>  .../intel/ipu6/ipu6-platform-isys-csi2-reg.h  | 187 +++++
>>>  5 files changed, 1359 insertions(+)
>>>  create mode 100644 drivers/media/pci/intel/ipu6/ipu6-isys-csi2.c
>>>  create mode 100644 drivers/media/pci/intel/ipu6/ipu6-isys-csi2.h
>>>  create mode 100644 drivers/media/pci/intel/ipu6/ipu6-isys-subdev.c
>>>  create mode 100644 drivers/media/pci/intel/ipu6/ipu6-isys-subdev.h
>>>  create mode 100644 drivers/media/pci/intel/ipu6/ipu6-platform-isys-
>>> csi2-reg.h
>>>
>>> diff --git a/drivers/media/pci/intel/ipu6/ipu6-isys-csi2.c
>>> b/drivers/media/pci/intel/ipu6/ipu6-isys-csi2.c
>>> new file mode 100644
>>> index 000000000000..0dedf3f51850
>>> --- /dev/null
>>> +++ b/drivers/media/pci/intel/ipu6/ipu6-isys-csi2.c
>> ...
>>>
>>> +
>>> +#define DIV_SHIFT      8
>>> +#define CSI2_ACCINV    8
>>> +
>>> +static u32 calc_timing(s32 a, s32 b, s64 link_freq, u32 accinv) {
>>> +       return accinv * a + (accinv * b * (500000000 >> DIV_SHIFT)
>>> +                            / (int32_t)(link_freq >> DIV_SHIFT)); }
>>
>> I think accinv should be s32 here. When accinv is unsigned, the expression
>> (accinv * b) becomes unsigned, and thus negative values of b gives
>> incorrect results.
> 
> accinv is always an unsigned value, so I think we don't need change the
> type of argument. Following usual arithmetic conversions, I think it needs
> a signed integer cast here. What do you think?

However, I can also follow your comments to change to s32. Thanks!
> 
> 
>>
>> This is different from e.g. https://github.com/intel/ipu6-drivers.
>>
>> /Andreas

-- 
Best regards,
Bingbu Cao

^ permalink raw reply	[flat|nested] 86+ messages in thread

* Re: [PATCH v2 08/15] media: intel/ipu6: add IPU6 CSI2 receiver v4l2 sub-device
  2023-11-08 14:50     ` Cao, Bingbu
  2023-11-08 14:51       ` Bingbu Cao
@ 2023-11-08 15:00       ` Andreas Helbech Kleist
  2023-11-08 15:32         ` andriy.shevchenko
  1 sibling, 1 reply; 86+ messages in thread
From: Andreas Helbech Kleist @ 2023-11-08 15:00 UTC (permalink / raw)
  To: Cao, Bingbu, linux-media, sakari.ailus, laurent.pinchart
  Cc: andriy.shevchenko, hdegoede, ilpo.jarvinen, claus.stovgaard,
	tfiga, senozhatsky, tomi.valkeinen, bingbu.cao, Qiu, Tian Shu,
	Wang, Hongju

Bingbu,

On Wed, 2023-11-08 at 14:50 +0000, Cao, Bingbu wrote:
> > -----Original Message-----
> > On Tue, 2023-10-24 at 19:29 +0800, bingbu.cao@intel.com wrote:
> > 
> > > +#define DIV_SHIFT      8
> > > +#define CSI2_ACCINV    8
> > > +
> > > +static u32 calc_timing(s32 a, s32 b, s64 link_freq, u32 accinv)
> > > {
> > > +       return accinv * a + (accinv * b * (500000000 >>
> > > DIV_SHIFT)
> > > +                            / (int32_t)(link_freq >>
> > > DIV_SHIFT)); }
> > 
> > I think accinv should be s32 here. When accinv is unsigned, the
> > expression
> > (accinv * b) becomes unsigned, and thus negative values of b gives
> > incorrect results.
> 
> accinv is always an unsigned value, so I think we don't need change
> the
> type of argument. Following usual arithmetic conversions, I think it
> needs
> a signed integer cast here. What do you think?

I think changing the type of argument is clearer. A cast just adds
noise in my opinion. Of course the argument to
ipu6_isys_csi2_calc_timing should also be changed to match, which would
also remove any implicit casts as far as I can tell.

Now we're talking about casts. There is a cast to int32_t, but the rest
of the code uses the s32/u32 typedefs. I don't know if one or the other
is recommended for new code, but I think it should at least be
consistent across the driver.

/Andreas

^ permalink raw reply	[flat|nested] 86+ messages in thread

* Re: [PATCH v2 00/15] Intel IPU6 and IPU6 input system drivers
  2023-11-08 14:31   ` Cao, Bingbu
@ 2023-11-08 15:15     ` Hans de Goede
  0 siblings, 0 replies; 86+ messages in thread
From: Hans de Goede @ 2023-11-08 15:15 UTC (permalink / raw)
  To: Cao, Bingbu, linux-media, sakari.ailus, laurent.pinchart
  Cc: andriy.shevchenko, hdegoede, ilpo.jarvinen, andreaskleist,
	claus.stovgaard, tfiga, senozhatsky, tomi.valkeinen, bingbu.cao,
	Qiu, Tian Shu, Wang, Hongju

Hi Bingbu,
On 11/8/23 15:31, Cao, Bingbu wrote:
> Hans,
> 
> ------------------------------------------------------------------------
> BRs,  
> Bingbu Cao 
> 
>> -----Original Message-----
>> From: Hans de Goede <hans@hansg.org>
>> Sent: Wednesday, November 8, 2023 8:00 PM
>> To: Cao, Bingbu <bingbu.cao@intel.com>; linux-media@vger.kernel.org;
>> sakari.ailus@linux.intel.com; laurent.pinchart@ideasonboard.com
>> Cc: andriy.shevchenko@linux.intel.com; hdegoede@redhat.com;
>> ilpo.jarvinen@linux.intel.com; andreaskleist@gmail.com;
>> claus.stovgaard@gmail.com; tfiga@chromium.org; senozhatsky@chromium.org;
>> tomi.valkeinen@ideasonboard.com; bingbu.cao@linux.intel.com; Qiu, Tian Shu
>> <tian.shu.qiu@intel.com>; Wang, Hongju <hongju.wang@intel.com>
>> Subject: Re: [PATCH v2 00/15] Intel IPU6 and IPU6 input system drivers
>>
>> Hi Bingbu,
>>
>> On 10/24/23 13:29, bingbu.cao@intel.com wrote:
>>> From: Bingbu Cao <bingbu.cao@intel.com>
>>>
>>> This patch series adds a driver for Intel IPU6 input system.
>>> IPU6 is the sixth generation of Imaging Processing Unit, it is a PCI
>>> device which can be found in some Intel Client Platforms. User can use
>>> IPU6 to capture images from MIPI camera sensors.
>>>
>>> IPU6 has its own firmware which exposes ABIs to driver, and
>>> communicates with CSE to do firmware authentication. IPU6 has its MMU
>>> hardware, so the driver sets up a page table to allow IPU6 DMA to
>>> access the system memory.
>>>
>>> IPU6 input system driver uses MC and V4L2 sub-device APIs besides V4L2.
>>
>> I have been testing this on a TigerLake system, a Dell Latitude 9420 with
>> ov01a1s and the packed 10 bit bayer pixel fmt: V4L2_PIX_FMT_SGRBG10P, which
>> libcamera together with (WIP) software debayer support picks by default
>> does not work. There are many many CSI errors in dmesg and only the first
>> 10 or so lines of the image show.
>>
>> Disabling the packed format by removing it from ipu6_isys_pfmts[], making
>> libcamera pick the unpacked (every 10 bits per pixel data stored in a 16
>> bit word in output buffer) fixes this.
>>
>> Are the packed bayer formats supposed to work on Tiger Lake, or is this a
>> known issue which Intel's own userspace stack avoids by always picking the
>> unpacked format ?
> 
> Thanks for the test.
> 
> I remember I verified SGRBG10P format on my ADL device before, but I have
> not tested that for a while, give me some time to test again and come back.

I can confirm that SGRBG10P works on Alderlake it appears to be broken
on Tiger Lake though.

Regards,

Hans


^ permalink raw reply	[flat|nested] 86+ messages in thread

* Re: [PATCH v2 08/15] media: intel/ipu6: add IPU6 CSI2 receiver v4l2 sub-device
  2023-11-08 15:00       ` Andreas Helbech Kleist
@ 2023-11-08 15:32         ` andriy.shevchenko
  2023-11-09  1:48           ` Bingbu Cao
  0 siblings, 1 reply; 86+ messages in thread
From: andriy.shevchenko @ 2023-11-08 15:32 UTC (permalink / raw)
  To: Andreas Helbech Kleist
  Cc: Cao, Bingbu, linux-media, sakari.ailus, laurent.pinchart,
	hdegoede, ilpo.jarvinen, claus.stovgaard, tfiga, senozhatsky,
	tomi.valkeinen, bingbu.cao, Qiu, Tian Shu, Wang, Hongju

On Wed, Nov 08, 2023 at 04:00:02PM +0100, Andreas Helbech Kleist wrote:
> On Wed, 2023-11-08 at 14:50 +0000, Cao, Bingbu wrote:

...

> Now we're talking about casts. There is a cast to int32_t, but the rest
> of the code uses the s32/u32 typedefs. I don't know if one or the other
> is recommended for new code, but I think it should at least be
> consistent across the driver.

s32/u32 are preferable in the kernel code.

Also if you need to extend the sign bit, we have sign_extendXX() helpers.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 86+ messages in thread

* Re: [PATCH v2 08/15] media: intel/ipu6: add IPU6 CSI2 receiver v4l2 sub-device
  2023-11-08 15:32         ` andriy.shevchenko
@ 2023-11-09  1:48           ` Bingbu Cao
  0 siblings, 0 replies; 86+ messages in thread
From: Bingbu Cao @ 2023-11-09  1:48 UTC (permalink / raw)
  To: andriy.shevchenko, Andreas Helbech Kleist
  Cc: Cao, Bingbu, linux-media, sakari.ailus, laurent.pinchart,
	hdegoede, ilpo.jarvinen, claus.stovgaard, tfiga, senozhatsky,
	tomi.valkeinen, Qiu, Tian Shu, Wang, Hongju

Andy,

On 11/8/23 11:32 PM, andriy.shevchenko@linux.intel.com wrote:
> On Wed, Nov 08, 2023 at 04:00:02PM +0100, Andreas Helbech Kleist wrote:
>> On Wed, 2023-11-08 at 14:50 +0000, Cao, Bingbu wrote:
> 
> ...
> 
>> Now we're talking about casts. There is a cast to int32_t, but the rest
>> of the code uses the s32/u32 typedefs. I don't know if one or the other
>> is recommended for new code, but I think it should at least be
>> consistent across the driver.
> 
> s32/u32 are preferable in the kernel code.
> 
> Also if you need to extend the sign bit, we have sign_extendXX() helpers.

Ack, thanks. I will walk through the code and fix the casts in the driver.

> 

-- 
Best regards,
Bingbu Cao

^ permalink raw reply	[flat|nested] 86+ messages in thread

* Re: [PATCH v2 00/15] Intel IPU6 and IPU6 input system drivers
  2023-11-08 11:59 ` [PATCH v2 00/15] Intel IPU6 and IPU6 input system drivers Hans de Goede
  2023-11-08 14:31   ` Cao, Bingbu
@ 2023-11-10 12:04   ` Hans de Goede
  2023-11-13 10:37     ` Bingbu Cao
  2023-12-04 16:35   ` Hans de Goede
  2024-01-08  4:07   ` Bingbu Cao
  3 siblings, 1 reply; 86+ messages in thread
From: Hans de Goede @ 2023-11-10 12:04 UTC (permalink / raw)
  To: bingbu.cao, linux-media, sakari.ailus, laurent.pinchart,
	Martti Groenen (19174837)
  Cc: andriy.shevchenko, hdegoede, ilpo.jarvinen, andreaskleist,
	claus.stovgaard, tfiga, senozhatsky, tomi.valkeinen, bingbu.cao,
	tian.shu.qiu, hongju.wang

Hi,

On 11/8/23 12:59, Hans de Goede wrote:
> Hi Bingbu,
> 
> On 10/24/23 13:29, bingbu.cao@intel.com wrote:
>> From: Bingbu Cao <bingbu.cao@intel.com>
>>
>> This patch series adds a driver for Intel IPU6 input system.
>> IPU6 is the sixth generation of Imaging Processing Unit, it is a PCI
>> device which can be found in some Intel Client Platforms. User can use
>> IPU6 to capture images from MIPI camera sensors.
>>
>> IPU6 has its own firmware which exposes ABIs to driver, and communicates
>> with CSE to do firmware authentication. IPU6 has its MMU hardware, so
>> the driver sets up a page table to allow IPU6 DMA to access the system
>> memory.
>>
>> IPU6 input system driver uses MC and V4L2 sub-device APIs besides V4L2.
> 
> I have been testing this on a TigerLake system, a Dell Latitude 9420
> with ov01a1s and the packed 10 bit bayer pixel fmt: V4L2_PIX_FMT_SGRBG10P,
> which libcamera together with (WIP) software debayer support picks
> by default does not work. There are many many CSI errors in dmesg
> and only the first 10 or so lines of the image show.
> 
> Disabling the packed format by removing it from ipu6_isys_pfmts[],
> making libcamera pick the unpacked (every 10 bits per pixel data
> stored in a 16 bit word in output buffer) fixes this.
> 
> Are the packed bayer formats supposed to work on Tiger Lake, or
> is this a known issue which Intel's own userspace stack avoids
> by always picking the unpacked format ?

Bingbu, so we've been trying to get software debayering to work
on the Dell Latitude 9420 with ov01a1s and I have just learned
that this sensor has a non standard bayer grid.

https://github.com/intel/ipu6-camera-hal/blob/9fa05a90886d399ad3dda4c2ddc990642b3d20c9/config/linux/ipu6/gcss/graph_settings_ov01a1s.xml#L17

bayer_order="GRGB_IGIG_GBGR_IGIG"

I'm wondering how to interpret these 4 pixel orders? For the OV2740
this just says:

bayer_order="GRBG"

and this single quartet of letters describes a 2x2 block like this:

GR
BG

but now there are 4 quartets so how to interpret this,
I guess this is the correct way to interpret this? :

GRGB
IGIG
GBGR
IGIG

Regards,

Hans




^ permalink raw reply	[flat|nested] 86+ messages in thread

* Re: [PATCH v2 00/15] Intel IPU6 and IPU6 input system drivers
  2023-11-10 12:04   ` Hans de Goede
@ 2023-11-13 10:37     ` Bingbu Cao
  0 siblings, 0 replies; 86+ messages in thread
From: Bingbu Cao @ 2023-11-13 10:37 UTC (permalink / raw)
  To: Hans de Goede, bingbu.cao, linux-media, sakari.ailus,
	laurent.pinchart, Martti Groenen (19174837)
  Cc: andriy.shevchenko, ilpo.jarvinen, andreaskleist, claus.stovgaard,
	tfiga, senozhatsky, tomi.valkeinen, tian.shu.qiu, hongju.wang

Hans,

On 11/10/23 8:04 PM, Hans de Goede wrote:
> Hi,
> 
> On 11/8/23 12:59, Hans de Goede wrote:
>> Hi Bingbu,
>>
>> On 10/24/23 13:29, bingbu.cao@intel.com wrote:
>>> From: Bingbu Cao <bingbu.cao@intel.com>
>>>
>>> This patch series adds a driver for Intel IPU6 input system.
>>> IPU6 is the sixth generation of Imaging Processing Unit, it is a PCI
>>> device which can be found in some Intel Client Platforms. User can use
>>> IPU6 to capture images from MIPI camera sensors.
>>>
>>> IPU6 has its own firmware which exposes ABIs to driver, and communicates
>>> with CSE to do firmware authentication. IPU6 has its MMU hardware, so
>>> the driver sets up a page table to allow IPU6 DMA to access the system
>>> memory.
>>>
>>> IPU6 input system driver uses MC and V4L2 sub-device APIs besides V4L2.
>>
>> I have been testing this on a TigerLake system, a Dell Latitude 9420
>> with ov01a1s and the packed 10 bit bayer pixel fmt: V4L2_PIX_FMT_SGRBG10P,
>> which libcamera together with (WIP) software debayer support picks
>> by default does not work. There are many many CSI errors in dmesg
>> and only the first 10 or so lines of the image show.
>>
>> Disabling the packed format by removing it from ipu6_isys_pfmts[],
>> making libcamera pick the unpacked (every 10 bits per pixel data
>> stored in a 16 bit word in output buffer) fixes this.
>>
>> Are the packed bayer formats supposed to work on Tiger Lake, or
>> is this a known issue which Intel's own userspace stack avoids
>> by always picking the unpacked format ?
> 
> Bingbu, so we've been trying to get software debayering to work
> on the Dell Latitude 9420 with ov01a1s and I have just learned
> that this sensor has a non standard bayer grid.
> 
> https://github.com/intel/ipu6-camera-hal/blob/9fa05a90886d399ad3dda4c2ddc990642b3d20c9/config/linux/ipu6/gcss/graph_settings_ov01a1s.xml#L17
> 
> bayer_order="GRGB_IGIG_GBGR_IGIG"

The IR is not enabled in Linux camera stack yet if I remember correctly.
Current IPU6 processing system have a single hardware block extract the RGB
and IR separately - "rgb_ir_2_0" in xml.

> 
> I'm wondering how to interpret these 4 pixel orders? For the OV2740
> this just says:
> 
> bayer_order="GRBG"
> 
> and this single quartet of letters describes a 2x2 block like this:
> 
> GR
> BG
> 
> but now there are 4 quartets so how to interpret this,
> I guess this is the correct way to interpret this? :
> 
> GRGB
> IGIG
> GBGR
> IGIG

I have no idea how to interpret the output of ov01a1s. Maybe you can
try to zero(bypass) the IR data and interpret as SGRBG10.

> 
> Regards,
> 
> Hans
> 
> 
> 

-- 
Best regards,
Bingbu Cao

^ permalink raw reply	[flat|nested] 86+ messages in thread

* Re: [PATCH v2 01/15] media: intel/ipu6: add Intel IPU6 PCI device driver
  2023-11-08 14:10     ` Andreas Helbech Kleist
  2023-11-08 14:18       ` Cao, Bingbu
@ 2023-11-17 18:43       ` Hans de Goede
  2023-11-17 21:18         ` Andy Shevchenko
  1 sibling, 1 reply; 86+ messages in thread
From: Hans de Goede @ 2023-11-17 18:43 UTC (permalink / raw)
  To: Andreas Helbech Kleist, Hans de Goede, bingbu.cao, linux-media,
	sakari.ailus, laurent.pinchart
  Cc: andriy.shevchenko, ilpo.jarvinen, claus.stovgaard, tfiga,
	senozhatsky, tomi.valkeinen, bingbu.cao, tian.shu.qiu,
	hongju.wang

Hi,

On 11/8/23 15:10, Andreas Helbech Kleist wrote:
> Hi Hans,
> 
> On Wed, 2023-11-08 at 12:25 +0100, Hans de Goede wrote:
>> Hi,
>>
>> On 10/24/23 13:29, bingbu.cao@intel.com wrote:
>>> From: Bingbu Cao <bingbu.cao@intel.com>
>>>
>>> Intel Image Processing Unit 6th Gen includes input and processing
>>> systems
>>> but the hardware presents itself as a single PCI device in system.
>>>
>>> IPU6 PCI device driver basically does PCI configurations and load
>>> the firmware binary, initialises IPU virtual bus, and sets up
>>> platform
>>> specific variants to support multiple IPU6 devices in single device
>>> driver.
>>>
>>> Signed-off-by: Bingbu Cao <bingbu.cao@intel.com>
>>> Reported-by: Hans de Goede <hdegoede@redhat.com>
>>> Suggested-by: Andreas Helbech Kleist <andreaskleist@gmail.com>
>>> ---
>>>  .../media/pci/intel/ipu6/ipu6-platform-regs.h | 179 ++++
>>>  drivers/media/pci/intel/ipu6/ipu6.c           | 952
>>> ++++++++++++++++++
>>>  drivers/media/pci/intel/ipu6/ipu6.h           | 352 +++++++
>>>  3 files changed, 1483 insertions(+)
>>>  create mode 100644 drivers/media/pci/intel/ipu6/ipu6-platform-
>>> regs.h
>>>  create mode 100644 drivers/media/pci/intel/ipu6/ipu6.c
>>>  create mode 100644 drivers/media/pci/intel/ipu6/ipu6.h
>>
>> <snip>
>>
>>> diff --git a/drivers/media/pci/intel/ipu6/ipu6.c
>>> b/drivers/media/pci/intel/ipu6/ipu6.c
>>> new file mode 100644
>>> index 000000000000..84960a283daf
>>> --- /dev/null
>>> +++ b/drivers/media/pci/intel/ipu6/ipu6.c
>>> @@ -0,0 +1,952 @@
>>
>> <snip>
>>
>>> +static int ipu6_pci_config_setup(struct pci_dev *dev, u8 hw_ver)
>>> +{
>>> +       int ret;
>>> +
>>> +       /* disable IPU6 PCI ATS on mtl ES2 */
>>> +       if (is_ipu6ep_mtl(hw_ver) && boot_cpu_data.x86_stepping ==
>>> 0x2 &&
>>> +           pci_ats_supported(dev))
>>> +               pci_disable_ats(dev);
>>> +
>>> +       /* No PCI msi capability for IPU6EP */
>>> +       if (is_ipu6ep(hw_ver) || is_ipu6ep_mtl(hw_ver)) {
>>> +               /* likely do nothing as msi not enabled by default
>>> */
>>> +               pci_disable_msi(dev);
>>> +               return 0;
>>> +       }
>>> +
>>> +       ret = pci_alloc_irq_vectors(dev, 1, 1, PCI_IRQ_MSI);
>>
>> This does not work on TGL systems (and is not reached on ADL and
>> RPL).
>>
>> The out of tree driver instead uses:
>>
>>         ret = pci_enable_msi(dev);
>>
>> and that does work correctly on TGL.
> 
> Did you see my previous (25//10) comment on the same lines? 
> 
> pci_alloc_irq_vectors returns number of irqs, so the "if (ret)" check
> following the quoted line is wrong.

Ah right, so a proper fix for this would look something like this:


From 34de6611d3482d6695dd73eddf7bf3dc1f96883c Mon Sep 17 00:00:00 2001
From: Hans de Goede <hdegoede@redhat.com>
Date: Tue, 7 Nov 2023 11:40:29 +0100
Subject: [PATCH] media: ipu6: Fix interrupts not working on TGL

pci_alloc_irq_vectors() returns the number of successfully allocated
interrupts. Fix the error checking to handle this correctly.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 drivers/media/pci/intel/ipu6/ipu6.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/media/pci/intel/ipu6/ipu6.c b/drivers/media/pci/intel/ipu6/ipu6.c
index b652662fa72e..66565cfdb703 100644
--- a/drivers/media/pci/intel/ipu6/ipu6.c
+++ b/drivers/media/pci/intel/ipu6/ipu6.c
@@ -532,10 +532,12 @@ static int ipu6_pci_config_setup(struct pci_dev *dev, u8 hw_ver)
 	}
 
 	ret = pci_alloc_irq_vectors(dev, 1, 1, PCI_IRQ_MSI);
-	if (ret)
+	if (ret < 0) {
 		dev_err_probe(&dev->dev, ret, "Request msi failed");
+		return ret;
+	}
 
-	return ret;
+	return 0;
 }
 
 static void ipu6_configure_vc_mechanism(struct ipu6_device *isp)
-- 
2.41.0


Bingbu, please squash something like the above into the next
version of this series.

Regards,

Hans


^ permalink raw reply related	[flat|nested] 86+ messages in thread

* Re: [PATCH v2 01/15] media: intel/ipu6: add Intel IPU6 PCI device driver
  2023-11-17 18:43       ` Hans de Goede
@ 2023-11-17 21:18         ` Andy Shevchenko
  2023-11-20  3:54           ` Bingbu Cao
  0 siblings, 1 reply; 86+ messages in thread
From: Andy Shevchenko @ 2023-11-17 21:18 UTC (permalink / raw)
  To: Hans de Goede
  Cc: Andreas Helbech Kleist, Hans de Goede, bingbu.cao, linux-media,
	sakari.ailus, laurent.pinchart, ilpo.jarvinen, claus.stovgaard,
	tfiga, senozhatsky, tomi.valkeinen, bingbu.cao, tian.shu.qiu,
	hongju.wang

On Fri, Nov 17, 2023 at 07:43:04PM +0100, Hans de Goede wrote:
> On 11/8/23 15:10, Andreas Helbech Kleist wrote:
> > On Wed, 2023-11-08 at 12:25 +0100, Hans de Goede wrote:
> >> On 10/24/23 13:29, bingbu.cao@intel.com wrote:

...

>  	ret = pci_alloc_irq_vectors(dev, 1, 1, PCI_IRQ_MSI);
> -	if (ret)
> +	if (ret < 0) {
>  		dev_err_probe(&dev->dev, ret, "Request msi failed");
> +		return ret;

Even further:

		return dev_err_probe(&dev->dev, ret, "Request msi failed");

> +	}

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 86+ messages in thread

* Re: [PATCH v2 01/15] media: intel/ipu6: add Intel IPU6 PCI device driver
  2023-11-17 21:18         ` Andy Shevchenko
@ 2023-11-20  3:54           ` Bingbu Cao
  0 siblings, 0 replies; 86+ messages in thread
From: Bingbu Cao @ 2023-11-20  3:54 UTC (permalink / raw)
  To: Andy Shevchenko, Hans de Goede
  Cc: Andreas Helbech Kleist, Hans de Goede, bingbu.cao, linux-media,
	sakari.ailus, laurent.pinchart, ilpo.jarvinen, claus.stovgaard,
	tfiga, senozhatsky, tomi.valkeinen, tian.shu.qiu, hongju.wang


Andy and Hans,

Thanks.

On 11/18/23 5:18 AM, Andy Shevchenko wrote:
> On Fri, Nov 17, 2023 at 07:43:04PM +0100, Hans de Goede wrote:
>> On 11/8/23 15:10, Andreas Helbech Kleist wrote:
>>> On Wed, 2023-11-08 at 12:25 +0100, Hans de Goede wrote:
>>>> On 10/24/23 13:29, bingbu.cao@intel.com wrote:
> 
> ...
> 
>>  	ret = pci_alloc_irq_vectors(dev, 1, 1, PCI_IRQ_MSI);
>> -	if (ret)
>> +	if (ret < 0) {
>>  		dev_err_probe(&dev->dev, ret, "Request msi failed");
>> +		return ret;
> 
> Even further:
> 
> 		return dev_err_probe(&dev->dev, ret, "Request msi failed");

Yes, I have updated the code locally and will send in v3.

> 
>> +	}
> 

-- 
Best regards,
Bingbu Cao

^ permalink raw reply	[flat|nested] 86+ messages in thread

* Re: [PATCH v2 01/15] media: intel/ipu6: add Intel IPU6 PCI device driver
  2023-10-24 11:29 ` [PATCH v2 01/15] media: intel/ipu6: add Intel IPU6 PCI device driver bingbu.cao
                     ` (2 preceding siblings ...)
  2023-11-08 11:25   ` Hans de Goede
@ 2023-11-23  9:17   ` Andreas Helbech Kleist
  3 siblings, 0 replies; 86+ messages in thread
From: Andreas Helbech Kleist @ 2023-11-23  9:17 UTC (permalink / raw)
  To: bingbu.cao, linux-media, sakari.ailus, laurent.pinchart
  Cc: andriy.shevchenko, hdegoede, ilpo.jarvinen, claus.stovgaard,
	tfiga, senozhatsky, tomi.valkeinen, bingbu.cao, tian.shu.qiu,
	hongju.wang

Hi,

On Tue, 2023-10-24 at 19:29 +0800, bingbu.cao@intel.com wrote:
> From: Bingbu Cao <bingbu.cao@intel.com>
> 
> Intel Image Processing Unit 6th Gen includes input and processing
> systems
> but the hardware presents itself as a single PCI device in system.
> 
> IPU6 PCI device driver basically does PCI configurations and load
> the firmware binary, initialises IPU virtual bus, and sets up
> platform
> specific variants to support multiple IPU6 devices in single device
> driver.
> 
> Signed-off-by: Bingbu Cao <bingbu.cao@intel.com>
> Reported-by: Hans de Goede <hdegoede@redhat.com>
> Suggested-by: Andreas Helbech Kleist <andreaskleist@gmail.com>
> ---
>  .../media/pci/intel/ipu6/ipu6-platform-regs.h | 179 ++++
>  drivers/media/pci/intel/ipu6/ipu6.c           | 952
> ++++++++++++++++++
>  drivers/media/pci/intel/ipu6/ipu6.h           | 352 +++++++
>  3 files changed, 1483 insertions(+)
>  create mode 100644 drivers/media/pci/intel/ipu6/ipu6-platform-regs.h
>  create mode 100644 drivers/media/pci/intel/ipu6/ipu6.c
>  create mode 100644 drivers/media/pci/intel/ipu6/ipu6.h
...
> +static void ipu6_internal_pdata_init(struct ipu6_device *isp)
> +{
> +       u8 hw_ver = isp->hw_ver;
> +
> +       isys_ipdata.num_parallel_streams = IPU6_ISYS_NUM_STREAMS;
> +       isys_ipdata.sram_gran_shift = IPU6_SRAM_GRANULARITY_SHIFT;
> +       isys_ipdata.sram_gran_size = IPU6_SRAM_GRANULARITY_SIZE;
> +       isys_ipdata.max_sram_size = IPU6_MAX_SRAM_SIZE;
> +       isys_ipdata.sensor_type_start =
> IPU6_FW_ISYS_SENSOR_TYPE_START;
> +       isys_ipdata.sensor_type_end = IPU6_FW_ISYS_SENSOR_TYPE_END;
> +       isys_ipdata.max_streams = IPU6_ISYS_NUM_STREAMS;

num_parallel_streams and max_streams are set to the same value here and
to another (but also equal) value for ipu6se.

num_parallel_streams is then passed through ipu6_fw_isys_init to
ipu6_isys_fwcom_cfg_init to then be clamp'ed to 1..max_streams. It
seems like they are the same, and thus a lot of code could be removed.

/Andreas

^ permalink raw reply	[flat|nested] 86+ messages in thread

* Re: [PATCH v2 06/15] media: intel/ipu6: add syscom interfaces between firmware and driver
  2023-10-24 11:29 ` [PATCH v2 06/15] media: intel/ipu6: add syscom interfaces between firmware and driver bingbu.cao
@ 2023-11-23  9:33   ` Andreas Helbech Kleist
  2023-12-28  6:39     ` Bingbu Cao
  0 siblings, 1 reply; 86+ messages in thread
From: Andreas Helbech Kleist @ 2023-11-23  9:33 UTC (permalink / raw)
  To: bingbu.cao, linux-media, sakari.ailus, laurent.pinchart
  Cc: andriy.shevchenko, hdegoede, ilpo.jarvinen, claus.stovgaard,
	tfiga, senozhatsky, tomi.valkeinen, bingbu.cao, tian.shu.qiu,
	hongju.wang

Hi,

On Tue, 2023-10-24 at 19:29 +0800, bingbu.cao@intel.com wrote:
> From: Bingbu Cao <bingbu.cao@intel.com>
> 
> Syscom is an inter-process(or) communication mechanism between an IPU
> and host. Syscom uses message queues for message exchange between IPU
> and host. Each message queue has its consumer and producer, host
> queue
> messages to firmware as the producer and then firmware to dequeue the
> messages as consumer and vice versa. IPU and host use shared
> registers
> or memory to reside the read and write indices which are updated by
> consumer and producer.
> 
> Signed-off-by: Bingbu Cao <bingbu.cao@intel.com>
> ---
>  drivers/media/pci/intel/ipu6/ipu6-fw-com.c | 411
> +++++++++++++++++++++
>  drivers/media/pci/intel/ipu6/ipu6-fw-com.h |  47 +++
>  2 files changed, 458 insertions(+)
>  create mode 100644 drivers/media/pci/intel/ipu6/ipu6-fw-com.c
>  create mode 100644 drivers/media/pci/intel/ipu6/ipu6-fw-com.h
...
> +struct ipu6_fw_com_context {
> +       struct ipu6_bus_device *adev;
> +       void __iomem *dmem_addr;
> +       int (*cell_ready)(struct ipu6_bus_device *adev);
> +       void (*cell_start)(struct ipu6_bus_device *adev);

Why are cell_ready and cell_start function pointers? They seem to
always be set to query_sp and start_sp.

> +
> +       void *dma_buffer;
> +       dma_addr_t dma_addr;
> +       unsigned int dma_size;
> +       unsigned long attrs;
> +
> +       struct ipu6_fw_sys_queue *input_queue;  /* array of host to
> SP queues */
> +       struct ipu6_fw_sys_queue *output_queue; /* array of SP to
> host */
> +
> +       u32 config_vied_addr;
> +
> +       unsigned int buttress_boot_offset;
> +       void __iomem *base_addr;
> +};
> +
> +#define FW_COM_WR_REG 0
> +#define FW_COM_RD_REG 4
> +
> +#define REGMEM_OFFSET 0
> +#define TUNIT_MAGIC_PATTERN 0x5a5a5a5a
> +
> +enum regmem_id {
> +       /* pass pkg_dir address to SPC in non-secure mode */
> +       PKG_DIR_ADDR_REG = 0,
> +       /* Tunit CFG blob for secure - provided by host.*/
> +       TUNIT_CFG_DWR_REG = 1,
> +       /* syscom commands - modified by the host */
> +       SYSCOM_COMMAND_REG = 2,
> +       /* Store interrupt status - updated by SP */
> +       SYSCOM_IRQ_REG = 3,
> +       /* first syscom queue pointer register */
> +       SYSCOM_QPR_BASE_REG = 4
> +};
> +
> +enum message_direction {
> +       DIR_RECV = 0,
> +       DIR_SEND
> +};

Not used?


...
> +struct ipu6_fw_com_cfg {
> +       unsigned int num_input_queues;
> +       unsigned int num_output_queues;
> +       struct ipu6_fw_syscom_queue_config *input;
> +       struct ipu6_fw_syscom_queue_config *output;
> +
> +       unsigned int dmem_addr;
> +
> +       /* firmware-specific configuration data */
> +       void *specific_addr;
> +       unsigned int specific_size;
> +       int (*cell_ready)(struct ipu6_bus_device *adev);
> +       void (*cell_start)(struct ipu6_bus_device *adev);
> +
> +       unsigned int buttress_boot_offset;

This seems to always be 0 (set by ipu6-fw-isys.c), seems to be trivial
to remove.

/Andreas

^ permalink raw reply	[flat|nested] 86+ messages in thread

* Re: [PATCH v2 10/15] media: intel/ipu6: add input system driver
  2023-10-24 11:29 ` [PATCH v2 10/15] media: intel/ipu6: add input system driver bingbu.cao
@ 2023-11-23  9:37   ` Andreas Helbech Kleist
  2024-01-09 13:52   ` Andreas Helbech Kleist
  2024-01-10 12:47   ` Andreas Helbech Kleist
  2 siblings, 0 replies; 86+ messages in thread
From: Andreas Helbech Kleist @ 2023-11-23  9:37 UTC (permalink / raw)
  To: bingbu.cao, linux-media, sakari.ailus, laurent.pinchart
  Cc: andriy.shevchenko, hdegoede, ilpo.jarvinen, claus.stovgaard,
	tfiga, senozhatsky, tomi.valkeinen, bingbu.cao, tian.shu.qiu,
	hongju.wang

Hi Bingbu,

For some reason my mail client decided to add double > > below. Hope it
is not too confusing.

On Tue, 2023-10-24 at 19:29 +0800, bingbu.cao@intel.com wrote:
> > From: Bingbu Cao <bingbu.cao@intel.com>
> > 
> > Input system driver do basic isys hardware setup and irq handling
> > and work with fwnode and v4l2 to register the ISYS v4l2 devices.
> > 
> > Signed-off-by: Bingbu Cao <bingbu.cao@intel.com>
> > Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> > Reported-by: Claus Stovgaard <claus.stovgaard@gmail.com>
> > ---
> >  drivers/media/pci/intel/ipu6/ipu6-isys.c | 1345 >
> > ++++++++++++++++++++++
> >  drivers/media/pci/intel/ipu6/ipu6-isys.h |  201 ++++
> >  2 files changed, 1546 insertions(+)
> >  create mode 100644 drivers/media/pci/intel/ipu6/ipu6-isys.c
> >  create mode 100644 drivers/media/pci/intel/ipu6/ipu6-isys.h
> > 
...
> > +static int isys_register_video_devices(struct ipu6_isys *isys)
> > +{
> > +       unsigned int i;
> > +       int ret;
> > +
> > +       for (i = 0; i < NR_OF_VIDEO_DEVICE; i++) {
> > +               snprintf(isys->av[i].vdev.name, > sizeof(isys-
> > >av[i].vdev.name),
> > +                        IPU6_ISYS_ENTITY_PREFIX " ISYS Capture
> > %u", > i);
> > +               isys->av[i].isys = isys;
> > +               isys->av[i].aq.buf_prepare = ipu6_isys_buf_prepare;
> > +               isys->av[i].aq.fill_frame_buf_set =
> > +                       ipu6_isys_buf_to_fw_frame_buf_pin;
> > +               isys->av[i].aq.link_fmt_validate = >
> > ipu6_isys_link_fmt_validate;

These 3 function pointers are always set to the same value, is there
any point in that, or could they be called directly?
	
> > +               isys->av[i].aq.vbq.buf_struct_size =
> > +                       sizeof(struct ipu6_isys_video_buffer);
> > +               isys->av[i].pfmt = &ipu6_isys_pfmts[0];
> > +
> > +               ret = ipu6_isys_video_init(&isys->av[i]);
> > +               if (ret)
> > +                       goto fail;
> > +       }
> > +
> > +       return 0;
> > +
> > +fail:
> > +       while (i--)
> > +               ipu6_isys_video_cleanup(&isys->av[i]);
> > +
> > +       return ret;
> > +}

...

> > +       if (resp->error_info.error == >
> > IPU6_FW_ISYS_ERROR_STREAM_IN_SUSPENSION)
> > +               /* Suspension is kind of special case: not enough >
> > buffers */
> > +               dev_dbg(&adev->auxdev.dev,
> > +                       "FW error resp %02d %s, stream %u, error >
> > SUSPENSION, details %d, timestamp 0x%16.16llx, pin %d\n",
> > +                       resp->type,
> > +                       fw_msg[resp_type_to_index(resp->type)].msg,
> > +                       resp->stream_handle,
> > +                       resp->error_info.error_details,
> > +                       fw_msg[resp_type_to_index(resp-
> > >type)].valid_> ts ?
> > +                       ts : 0, resp->pin_id);
> > +       else if (resp->error_info.error)
> > +               dev_dbg(&adev->auxdev.dev,
> > +                       "FW error resp %02d %s, stream %u, error
> > %d, > details %d, timestamp 0x%16.16llx, pin %d\n",
> > +                       resp->type,
> > +                       fw_msg[resp_type_to_index(resp->type)].msg,
> > +                       resp->stream_handle,
> > +                       resp->error_info.error, > resp-
> > >error_info.error_details,
> > +                       fw_msg[resp_type_to_index(resp-
> > >type)].valid_> ts ?
> > +                       ts : 0, resp->pin_id);
> > +       else
> > +               dev_dbg(&adev->auxdev.dev,
> > +                       "FW resp %02d %s, stream %u, timestamp >
> > 0x%16.16llx, pin %d\n",
> > +                       resp->type,
> > +                       fw_msg[resp_type_to_index(resp->type)].msg,
> > +                       resp->stream_handle,
> > +                       fw_msg[resp_type_to_index(resp-
> > >type)].valid_> ts ?
> > +                       ts : 0, resp->pin_id);

fw_msg[resp_type_to_index(resp->type)] is duplicated 6 times above. It
would be a lot cleaner if you did the lookup once before the if/else
if/else block.

> 
/Andreas

^ permalink raw reply	[flat|nested] 86+ messages in thread

* Re: [PATCH v2 00/15] Intel IPU6 and IPU6 input system drivers
  2023-11-08 11:59 ` [PATCH v2 00/15] Intel IPU6 and IPU6 input system drivers Hans de Goede
  2023-11-08 14:31   ` Cao, Bingbu
  2023-11-10 12:04   ` Hans de Goede
@ 2023-12-04 16:35   ` Hans de Goede
  2023-12-04 16:49     ` Andy Shevchenko
  2024-01-08  4:07   ` Bingbu Cao
  3 siblings, 1 reply; 86+ messages in thread
From: Hans de Goede @ 2023-12-04 16:35 UTC (permalink / raw)
  To: bingbu.cao, linux-media, sakari.ailus, laurent.pinchart,
	Martti Groenen (19174837)
  Cc: andriy.shevchenko, hdegoede, ilpo.jarvinen, andreaskleist,
	claus.stovgaard, tfiga, senozhatsky, tomi.valkeinen, bingbu.cao,
	tian.shu.qiu, hongju.wang

[-- Attachment #1: Type: text/plain, Size: 1831 bytes --]

Hi,

On 11/8/23 12:59, Hans de Goede wrote:
> Hi Bingbu,
> 
> On 10/24/23 13:29, bingbu.cao@intel.com wrote:
>> From: Bingbu Cao <bingbu.cao@intel.com>
>>
>> This patch series adds a driver for Intel IPU6 input system.
>> IPU6 is the sixth generation of Imaging Processing Unit, it is a PCI
>> device which can be found in some Intel Client Platforms. User can use
>> IPU6 to capture images from MIPI camera sensors.
>>
>> IPU6 has its own firmware which exposes ABIs to driver, and communicates
>> with CSE to do firmware authentication. IPU6 has its MMU hardware, so
>> the driver sets up a page table to allow IPU6 DMA to access the system
>> memory.
>>
>> IPU6 input system driver uses MC and V4L2 sub-device APIs besides V4L2.
> 
> I have been testing this on a TigerLake system, a Dell Latitude 9420
> with ov01a1s and the packed 10 bit bayer pixel fmt: V4L2_PIX_FMT_SGRBG10P,
> which libcamera together with (WIP) software debayer support picks
> by default does not work. There are many many CSI errors in dmesg
> and only the first 10 or so lines of the image show.
> 
> Disabling the packed format by removing it from ipu6_isys_pfmts[],
> making libcamera pick the unpacked (every 10 bits per pixel data
> stored in a 16 bit word in output buffer) fixes this.
> 
> Are the packed bayer formats supposed to work on Tiger Lake, or
> is this a known issue which Intel's own userspace stack avoids
> by always picking the unpacked format ?

I have just rebased my personal tree with these patches in it
on top of media_staging. I had to make some changes to make
this series work on top of media_staging.

I'm attaching these changes here as a patch in case they
are useful for someone else. Feel free to squash these
into the next version.

Talking about a next version I would think it is about
time to post a v3 of this ?

[-- Attachment #2: 0001-media-ipu6-Add-support-for-kernel-6.8.patch --]
[-- Type: text/x-patch, Size: 6107 bytes --]

From 93d23e346aaa2e2ba59b4bc95ca029b674e01195 Mon Sep 17 00:00:00 2001
From: Hans de Goede <hdegoede@redhat.com>
Date: Mon, 4 Dec 2023 12:13:02 +0100
Subject: [PATCH] media: ipu6: Add support for kernel 6.8

Add support for the upcoming v4l2-subdev API changes in kernel 6.8.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 drivers/media/pci/intel/ipu6/ipu6-isys-csi2.c |  8 +++-----
 .../media/pci/intel/ipu6/ipu6-isys-subdev.c   | 19 +++++++++++--------
 .../media/pci/intel/ipu6/ipu6-isys-subdev.h   |  2 --
 .../media/pci/intel/ipu6/ipu6-isys-video.c    |  3 +--
 4 files changed, 15 insertions(+), 17 deletions(-)

diff --git a/drivers/media/pci/intel/ipu6/ipu6-isys-csi2.c b/drivers/media/pci/intel/ipu6/ipu6-isys-csi2.c
index 2da82a74fd18..1d40bfa992a6 100644
--- a/drivers/media/pci/intel/ipu6/ipu6-isys-csi2.c
+++ b/drivers/media/pci/intel/ipu6/ipu6-isys-csi2.c
@@ -386,12 +386,11 @@ static int ipu6_isys_csi2_set_sel(struct v4l2_subdev *sd,
 	if (!sink_ffmt)
 		return -EINVAL;
 
-	src_ffmt = v4l2_subdev_state_get_stream_format(state, sel->pad,
-						       sel->stream);
+	src_ffmt = v4l2_subdev_state_get_format(state, sel->pad, sel->stream);
 	if (!src_ffmt)
 		return -EINVAL;
 
-	crop = v4l2_subdev_state_get_stream_crop(state, sel->pad, sel->stream);
+	crop = v4l2_subdev_state_get_crop(state, sel->pad, sel->stream);
 	if (!crop)
 		return -EINVAL;
 
@@ -436,7 +435,7 @@ static int ipu6_isys_csi2_get_sel(struct v4l2_subdev *sd,
 	if (!sink_ffmt)
 		return -EINVAL;
 
-	crop = v4l2_subdev_state_get_stream_crop(state, sel->pad, sel->stream);
+	crop = v4l2_subdev_state_get_crop(state, sel->pad, sel->stream);
 	if (!crop)
 		return -EINVAL;
 
@@ -463,7 +462,6 @@ static const struct v4l2_subdev_video_ops csi2_sd_video_ops = {
 };
 
 static const struct v4l2_subdev_pad_ops csi2_sd_pad_ops = {
-	.init_cfg = ipu6_isys_subdev_init_cfg,
 	.get_fmt = v4l2_subdev_get_fmt,
 	.set_fmt = ipu6_isys_subdev_set_fmt,
 	.get_selection = ipu6_isys_csi2_get_sel,
diff --git a/drivers/media/pci/intel/ipu6/ipu6-isys-subdev.c b/drivers/media/pci/intel/ipu6/ipu6-isys-subdev.c
index 7f104205d153..598bdf69b364 100644
--- a/drivers/media/pci/intel/ipu6/ipu6-isys-subdev.c
+++ b/drivers/media/pci/intel/ipu6/ipu6-isys-subdev.c
@@ -143,8 +143,7 @@ int ipu6_isys_subdev_set_fmt(struct v4l2_subdev *sd,
 	format->format.field = V4L2_FIELD_NONE;
 
 	/* Store the format and propagate it to the source pad. */
-	fmt = v4l2_subdev_state_get_stream_format(state, format->pad,
-						  format->stream);
+	fmt = v4l2_subdev_state_get_format(state, format->pad, format->stream);
 	if (!fmt)
 		return -EINVAL;
 
@@ -169,8 +168,7 @@ int ipu6_isys_subdev_set_fmt(struct v4l2_subdev *sd,
 	if (ret)
 		return -EINVAL;
 
-	crop = v4l2_subdev_state_get_stream_crop(state, other_pad,
-						 other_stream);
+	crop = v4l2_subdev_state_get_crop(state, other_pad, other_stream);
 	/* reset crop */
 	crop->left = 0;
 	crop->top = 0;
@@ -229,7 +227,7 @@ int ipu6_isys_get_stream_pad_fmt(struct v4l2_subdev *sd, u32 pad, u32 stream,
 		return -EINVAL;
 
 	state = v4l2_subdev_lock_and_get_active_state(sd);
-	fmt = v4l2_subdev_state_get_stream_format(state, pad, stream);
+	fmt = v4l2_subdev_state_get_format(state, pad, stream);
 	if (fmt) {
 		*format = *fmt;
 		ret = 0;
@@ -250,7 +248,7 @@ int ipu6_isys_get_stream_pad_crop(struct v4l2_subdev *sd, u32 pad, u32 stream,
 		return -EINVAL;
 
 	state = v4l2_subdev_lock_and_get_active_state(sd);
-	rect = v4l2_subdev_state_get_stream_crop(state, pad, stream);
+	rect = v4l2_subdev_state_get_crop(state, pad, stream);
 	if (rect) {
 		*crop = *rect;
 		ret = 0;
@@ -284,8 +282,8 @@ u32 ipu6_isys_get_src_stream_by_src_pad(struct v4l2_subdev *sd, u32 pad)
 	return source_stream;
 }
 
-int ipu6_isys_subdev_init_cfg(struct v4l2_subdev *sd,
-			      struct v4l2_subdev_state *state)
+static int ipu6_isys_subdev_init_state(struct v4l2_subdev *sd,
+				       struct v4l2_subdev_state *state)
 {
 	struct v4l2_subdev_route route = {
 		.sink_pad = 0,
@@ -310,6 +308,10 @@ int ipu6_isys_subdev_set_routing(struct v4l2_subdev *sd,
 	return subdev_set_routing(sd, state, routing);
 }
 
+static const struct v4l2_subdev_internal_ops ipu6_isys_subdev_internal_ops = {
+	.init_state = ipu6_isys_subdev_init_state,
+};
+
 int ipu6_isys_subdev_init(struct ipu6_isys_subdev *asd,
 			  const struct v4l2_subdev_ops *ops,
 			  unsigned int nr_ctrls,
@@ -327,6 +329,7 @@ int ipu6_isys_subdev_init(struct ipu6_isys_subdev *asd,
 			 V4L2_SUBDEV_FL_STREAMS;
 	asd->sd.owner = THIS_MODULE;
 	asd->sd.entity.function = MEDIA_ENT_F_VID_IF_BRIDGE;
+	asd->sd.internal_ops = &ipu6_isys_subdev_internal_ops;
 
 	asd->pad = devm_kcalloc(&asd->isys->adev->auxdev.dev, num_pads,
 				sizeof(*asd->pad), GFP_KERNEL);
diff --git a/drivers/media/pci/intel/ipu6/ipu6-isys-subdev.h b/drivers/media/pci/intel/ipu6/ipu6-isys-subdev.h
index 13e2c57efaea..ef787102ed98 100644
--- a/drivers/media/pci/intel/ipu6/ipu6-isys-subdev.h
+++ b/drivers/media/pci/intel/ipu6/ipu6-isys-subdev.h
@@ -43,8 +43,6 @@ int ipu6_isys_get_stream_pad_fmt(struct v4l2_subdev *sd, u32 pad, u32 stream,
 				 struct v4l2_mbus_framefmt *format);
 int ipu6_isys_get_stream_pad_crop(struct v4l2_subdev *sd, u32 pad, u32 stream,
 				  struct v4l2_rect *crop);
-int ipu6_isys_subdev_init_cfg(struct v4l2_subdev *sd,
-			      struct v4l2_subdev_state *state);
 int ipu6_isys_subdev_set_routing(struct v4l2_subdev *sd,
 				 struct v4l2_subdev_state *state,
 				 enum v4l2_subdev_format_whence which,
diff --git a/drivers/media/pci/intel/ipu6/ipu6-isys-video.c b/drivers/media/pci/intel/ipu6/ipu6-isys-video.c
index e73a46eb7fd3..dc1dab713bb6 100644
--- a/drivers/media/pci/intel/ipu6/ipu6-isys-video.c
+++ b/drivers/media/pci/intel/ipu6/ipu6-isys-video.c
@@ -281,8 +281,7 @@ static int link_validate(struct media_link *link)
 
 	v4l2_subdev_lock_state(s_state);
 
-	s_fmt = v4l2_subdev_state_get_stream_format(s_state, s_pad->index,
-						    s_stream);
+	s_fmt = v4l2_subdev_state_get_format(s_state, s_pad->index, s_stream);
 	if (!s_fmt) {
 		dev_err(dev, "failed to get source pad format\n");
 		goto unlock;
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 86+ messages in thread

* Re: [PATCH v2 00/15] Intel IPU6 and IPU6 input system drivers
  2023-12-04 16:35   ` Hans de Goede
@ 2023-12-04 16:49     ` Andy Shevchenko
  0 siblings, 0 replies; 86+ messages in thread
From: Andy Shevchenko @ 2023-12-04 16:49 UTC (permalink / raw)
  To: Hans de Goede
  Cc: bingbu.cao, linux-media, sakari.ailus, laurent.pinchart,
	Martti Groenen (19174837),
	ilpo.jarvinen, andreaskleist, claus.stovgaard, tfiga,
	senozhatsky, tomi.valkeinen, bingbu.cao, tian.shu.qiu,
	hongju.wang

On Mon, Dec 04, 2023 at 05:35:16PM +0100, Hans de Goede wrote:
> On 11/8/23 12:59, Hans de Goede wrote:

...

> Talking about a next version I would think it is about
> time to post a v3 of this ?

Yes, would be wonderful to see v3 sooner than later.


-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 86+ messages in thread

* Re: [PATCH v2 11/15] media: intel/ipu6: input system video capture nodes
  2023-11-06 11:17       ` Andy Shevchenko
@ 2023-12-05  9:15         ` Bingbu Cao
  0 siblings, 0 replies; 86+ messages in thread
From: Bingbu Cao @ 2023-12-05  9:15 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Hans de Goede, bingbu.cao, linux-media, sakari.ailus,
	laurent.pinchart, hdegoede, ilpo.jarvinen, andreaskleist,
	claus.stovgaard, tfiga, senozhatsky, tomi.valkeinen,
	tian.shu.qiu, hongju.wang

Hans,
Thanks for your patch, I will squash them into v3.

Andy and Hans, thank you for your review and comments on v2.

Please give me some time to send v2, we have metadata capture support
change which depends on some v4l2 APIs update in kernel. I will send v3
ASAP.

On 11/6/23 7:17 PM, Andy Shevchenko wrote:
> On Mon, Nov 06, 2023 at 05:18:55PM +0800, Bingbu Cao wrote:
>> On 11/6/23 12:59 AM, Hans de Goede wrote:
> 
> ...
> 
>> Yes, sure.
> 
> It's likely that I meant this series (it's under development, right?) to be
> Cc'ed to me in its next version.
> 

-- 
Best regards,
Bingbu Cao

^ permalink raw reply	[flat|nested] 86+ messages in thread

* Re: [PATCH v2 05/15] media: intel/ipu6: add IPU6 DMA mapping API and MMU table
  2023-10-24 11:29 ` [PATCH v2 05/15] media: intel/ipu6: add IPU6 DMA mapping API and MMU table bingbu.cao
@ 2023-12-06 14:53   ` Andreas Helbech Kleist
  0 siblings, 0 replies; 86+ messages in thread
From: Andreas Helbech Kleist @ 2023-12-06 14:53 UTC (permalink / raw)
  To: bingbu.cao, linux-media, sakari.ailus, laurent.pinchart
  Cc: andriy.shevchenko, hdegoede, ilpo.jarvinen, claus.stovgaard,
	tfiga, senozhatsky, tomi.valkeinen, bingbu.cao, tian.shu.qiu,
	hongju.wang

Hi,

On Tue, 2023-10-24 at 19:29 +0800, bingbu.cao@intel.com wrote:
> From: Bingbu Cao <bingbu.cao@intel.com>
> 
> he Intel IPU6 has an internal microcontroller (scalar processor, SP)
> which
> is used to execute the firmware. The SP can access IPU internal
> memory and
> map system DRAM to its an internal 32-bit virtual address space.
> 
> This patch adds a driver for the IPU MMU and a DMA mapping
> implementation
> using the internal MMU. The system IOMMU may be used besides the IPU
> MMU.
> 
> Signed-off-by: Bingbu Cao <bingbu.cao@intel.com>
> ---
>  drivers/media/pci/intel/ipu6/ipu6-dma.c | 491 ++++++++++++++
>  drivers/media/pci/intel/ipu6/ipu6-dma.h |  20 +
>  drivers/media/pci/intel/ipu6/ipu6-mmu.c | 828
> ++++++++++++++++++++++++
>  drivers/media/pci/intel/ipu6/ipu6-mmu.h |  67 ++
>  4 files changed, 1406 insertions(+)
>  create mode 100644 drivers/media/pci/intel/ipu6/ipu6-dma.c
>  create mode 100644 drivers/media/pci/intel/ipu6/ipu6-dma.h
>  create mode 100644 drivers/media/pci/intel/ipu6/ipu6-mmu.c
>  create mode 100644 drivers/media/pci/intel/ipu6/ipu6-mmu.h
...

> +++ b/drivers/media/pci/intel/ipu6/ipu6-mmu.c
...
> +static struct ipu6_mmu_info *ipu6_mmu_alloc(struct ipu6_device *isp)
> +{
> +       struct ipu6_mmu_info *mmu_info;
> +       int ret;
> +
> +       mmu_info = kzalloc(sizeof(*mmu_info), GFP_KERNEL);
> +       if (!mmu_info)
> +               return NULL;
> +
> +       mmu_info->aperture_start = 0;
> +       mmu_info->aperture_end = DMA_BIT_MASK(isp->secure_mode ?
> +                                             IPU6_MMU_ADDR_BITS :
> +                                            
> IPU6_MMU_ADDR_BITS_NON_SECURE);
> +       mmu_info->pgsize_bitmap = SZ_4K;
> +       mmu_info->dev = &isp->pdev->dev;
> +
> +       ret = get_dummy_page(mmu_info);
> +       if (ret)
> +               goto err_free_info;
> +
> +       ret = alloc_dummy_l2_pt(mmu_info);
> +       if (ret)
> +               goto err_free_dummy_page;
> +
> +       mmu_info->l2_pts = vzalloc(ISP_L2PT_PTES * sizeof(*mmu_info-
> >l2_pts));
> +       if (!mmu_info->l2_pts)
> +               goto err_free_dummy_l2_pt;
> +
> +       /*
> +        * We always map the L1 page table (a single page as well as
> +        * the L2 page tables).
> +        */
> +       mmu_info->l1_pt = alloc_l1_pt(mmu_info);
> +       if (!mmu_info->l1_pt)
> +               goto err_free_l2_pts;
> +
> +       spin_lock_init(&mmu_info->lock);
> +
> +       dev_dbg(mmu_info->dev, "domain initialised\n");
> +
> +       return mmu_info;
> +
> +err_free_l2_pts:
> +       vfree(mmu_info->l2_pts);
> +err_free_dummy_l2_pt:
> +       free_dummy_l2_pt(mmu_info);
> +err_free_dummy_page:
> +       free_dummy_page(mmu_info);
> +err_free_info:
> +       kfree(mmu_info);
> +
> +       return NULL;
> +}

...


> +static void ipu6_mmu_destroy(struct ipu6_mmu *mmu)
> +{
> +       struct ipu6_dma_mapping *dmap = mmu->dmap;
> +       struct ipu6_mmu_info *mmu_info = dmap->mmu_info;
> +       struct iova *iova;
> +       u32 l1_idx;
> +
> +       if (mmu->iova_trash_page) {
> +               iova = find_iova(&dmap->iovad, PHYS_PFN(mmu-
> >iova_trash_page));
> +               if (iova) {
> +                       /* unmap and free the trash buffer iova */
> +                       ipu6_mmu_unmap(mmu_info, PFN_PHYS(iova-
> >pfn_lo),
> +                                      PFN_PHYS(iova_size(iova)));
> +                       __free_iova(&dmap->iovad, iova);
> +               } else {
> +                       dev_err(mmu->dev, "trash buffer iova not
> found.\n");
> +               }
> +
> +               mmu->iova_trash_page = 0;
> +               dma_unmap_page(mmu_info->dev, mmu->pci_trash_page,
> +                              PAGE_SIZE, DMA_BIDIRECTIONAL);
> +               mmu->pci_trash_page = 0;
> +               __free_page(mmu->trash_page);
> +       }
> +
> +       for (l1_idx = 0; l1_idx < ISP_L1PT_PTES; l1_idx++) {
> +               if (mmu_info->l1_pt[l1_idx] != mmu_info-
> >dummy_l2_pteval) {
> +                       dma_unmap_single(mmu_info->dev,
> +                                        TBL_PHYS_ADDR(mmu_info-
> >l1_pt[l1_idx]),
> +                                        PAGE_SIZE,
> DMA_BIDIRECTIONAL);
> +                       free_page((unsigned long)mmu_info-
> >l2_pts[l1_idx]);
> +               }
> +       }
> +
> +       free_dummy_page(mmu_info);
> +       dma_unmap_single(mmu_info->dev, TBL_PHYS_ADDR(mmu_info-
> >l1_pt_dma),
> +                        PAGE_SIZE, DMA_BIDIRECTIONAL);
> +       free_page((unsigned long)mmu_info->dummy_l2_pt);
> +       free_page((unsigned long)mmu_info->l1_pt);
> +       kfree(mmu_info);
> +}

mmu_info->l2_pts is leaked here. It is allocated in ipu6_mmu_alloc and
freed in the error path of that function along with the other stuff you
free here, but not anywhere else.

/Andreas

^ permalink raw reply	[flat|nested] 86+ messages in thread

* Re: [PATCH v2 06/15] media: intel/ipu6: add syscom interfaces between firmware and driver
  2023-11-23  9:33   ` Andreas Helbech Kleist
@ 2023-12-28  6:39     ` Bingbu Cao
  2024-01-03  9:25       ` Andreas Helbech Kleist
  0 siblings, 1 reply; 86+ messages in thread
From: Bingbu Cao @ 2023-12-28  6:39 UTC (permalink / raw)
  To: Andreas Helbech Kleist, bingbu.cao, linux-media, sakari.ailus,
	laurent.pinchart
  Cc: andriy.shevchenko, hdegoede, ilpo.jarvinen, claus.stovgaard,
	tfiga, senozhatsky, tomi.valkeinen, tian.shu.qiu, hongju.wang

Andreas,

On 11/23/23 5:33 PM, Andreas Helbech Kleist wrote:
> Hi,
> 
> On Tue, 2023-10-24 at 19:29 +0800, bingbu.cao@intel.com wrote:
>> From: Bingbu Cao <bingbu.cao@intel.com>
>>
>> Syscom is an inter-process(or) communication mechanism between an IPU
>> and host. Syscom uses message queues for message exchange between IPU
>> and host. Each message queue has its consumer and producer, host
>> queue
>> messages to firmware as the producer and then firmware to dequeue the
>> messages as consumer and vice versa. IPU and host use shared
>> registers
>> or memory to reside the read and write indices which are updated by
>> consumer and producer.
>>
>> Signed-off-by: Bingbu Cao <bingbu.cao@intel.com>
>> ---
>>  drivers/media/pci/intel/ipu6/ipu6-fw-com.c | 411
>> +++++++++++++++++++++
>>  drivers/media/pci/intel/ipu6/ipu6-fw-com.h |  47 +++
>>  2 files changed, 458 insertions(+)
>>  create mode 100644 drivers/media/pci/intel/ipu6/ipu6-fw-com.c
>>  create mode 100644 drivers/media/pci/intel/ipu6/ipu6-fw-com.h
> ...
>> +struct ipu6_fw_com_context {
>> +       struct ipu6_bus_device *adev;
>> +       void __iomem *dmem_addr;
>> +       int (*cell_ready)(struct ipu6_bus_device *adev);
>> +       void (*cell_start)(struct ipu6_bus_device *adev);
> 
> Why are cell_ready and cell_start function pointers? They seem to
> always be set to query_sp and start_sp.
> 
>> +
>> +       void *dma_buffer;
>> +       dma_addr_t dma_addr;
>> +       unsigned int dma_size;
>> +       unsigned long attrs;
>> +
>> +       struct ipu6_fw_sys_queue *input_queue;  /* array of host to
>> SP queues */
>> +       struct ipu6_fw_sys_queue *output_queue; /* array of SP to
>> host */
>> +
>> +       u32 config_vied_addr;
>> +
>> +       unsigned int buttress_boot_offset;
>> +       void __iomem *base_addr;
>> +};
>> +
>> +#define FW_COM_WR_REG 0
>> +#define FW_COM_RD_REG 4
>> +
>> +#define REGMEM_OFFSET 0
>> +#define TUNIT_MAGIC_PATTERN 0x5a5a5a5a
>> +
>> +enum regmem_id {
>> +       /* pass pkg_dir address to SPC in non-secure mode */
>> +       PKG_DIR_ADDR_REG = 0,
>> +       /* Tunit CFG blob for secure - provided by host.*/
>> +       TUNIT_CFG_DWR_REG = 1,
>> +       /* syscom commands - modified by the host */
>> +       SYSCOM_COMMAND_REG = 2,
>> +       /* Store interrupt status - updated by SP */
>> +       SYSCOM_IRQ_REG = 3,
>> +       /* first syscom queue pointer register */
>> +       SYSCOM_QPR_BASE_REG = 4
>> +};
>> +
>> +enum message_direction {
>> +       DIR_RECV = 0,
>> +       DIR_SEND
>> +};
> 
> Not used?

Ack, will remove.

> 
> 
> ...
>> +struct ipu6_fw_com_cfg {
>> +       unsigned int num_input_queues;
>> +       unsigned int num_output_queues;
>> +       struct ipu6_fw_syscom_queue_config *input;
>> +       struct ipu6_fw_syscom_queue_config *output;
>> +
>> +       unsigned int dmem_addr;
>> +
>> +       /* firmware-specific configuration data */
>> +       void *specific_addr;
>> +       unsigned int specific_size;
>> +       int (*cell_ready)(struct ipu6_bus_device *adev);
>> +       void (*cell_start)(struct ipu6_bus_device *adev);
>> +
>> +       unsigned int buttress_boot_offset;
> 
> This seems to always be 0 (set by ipu6-fw-isys.c), seems to be trivial
> to remove.

All these fields are all used to extend for psys driver.

> 
> /Andreas
> 

-- 
Best regards,
Bingbu Cao

^ permalink raw reply	[flat|nested] 86+ messages in thread

* Re: [PATCH v2 03/15] media: intel/ipu6: add IPU6 buttress interface driver
  2023-10-24 11:29 ` [PATCH v2 03/15] media: intel/ipu6: add IPU6 buttress interface driver bingbu.cao
@ 2024-01-03  9:22   ` Andreas Helbech Kleist
  2024-01-03 10:49     ` Laurent Pinchart
  2024-01-03 13:11     ` Bingbu Cao
  0 siblings, 2 replies; 86+ messages in thread
From: Andreas Helbech Kleist @ 2024-01-03  9:22 UTC (permalink / raw)
  To: bingbu.cao, linux-media, sakari.ailus, laurent.pinchart
  Cc: andriy.shevchenko, hdegoede, ilpo.jarvinen, claus.stovgaard,
	tfiga, senozhatsky, tomi.valkeinen, bingbu.cao, tian.shu.qiu,
	hongju.wang

Hi Bingbu,

On Tue, 2023-10-24 at 19:29 +0800, bingbu.cao@intel.com wrote:
> From: Bingbu Cao <bingbu.cao@intel.com>
> 
> The IPU6 buttress is the interface between IPU device (input system
> and processing system) with rest of the SoC. It contains overall IPU
> hardware control registers, these control registers are used as the
> interfaces with the Intel Converged Security Engine and Punit to do
> firmware authentication and power management.
> 
> Signed-off-by: Bingbu Cao <bingbu.cao@intel.com>
> ---

...

> +static irqreturn_t ipu6_buttress_call_isr(struct ipu6_bus_device *adev)
> +{
> +	irqreturn_t ret = IRQ_WAKE_THREAD;
> +
> +	if (!adev || !adev->auxdrv || !adev->auxdrv_data)
> +		return IRQ_NONE;
> +
> +	if (adev->auxdrv_data->isr)
> +		ret = adev->auxdrv_data->isr(adev);
> +
> +	if (ret == IRQ_WAKE_THREAD && !adev->auxdrv_data->isr_threaded)
> +		ret = IRQ_NONE;
> +
> +	return ret;
> +}
> +
> +irqreturn_t ipu6_buttress_isr(int irq, void *isp_ptr)
> +{
> +	struct ipu6_device *isp = isp_ptr;
> +	struct ipu6_bus_device *adev[] = { isp->isys, isp->psys };
> +	struct ipu6_buttress *b = &isp->buttress;
> +	u32 reg_irq_sts = BUTTRESS_REG_ISR_STATUS;
> +	irqreturn_t ret = IRQ_NONE;
> +	u32 disable_irqs = 0;
> +	u32 irq_status;
> +	u32 i, count = 0;
> +
> +	pm_runtime_get_noresume(&isp->pdev->dev);
> +
> +	irq_status = readl(isp->base + reg_irq_sts);
> +	if (!irq_status) {
> +		pm_runtime_put_noidle(&isp->pdev->dev);
> +		return IRQ_NONE;
> +	}
> +
> +	do {
> +		writel(irq_status, isp->base + BUTTRESS_REG_ISR_CLEAR);
> +
> +		for (i = 0; i < ARRAY_SIZE(ipu6_adev_irq_mask); i++) {
> +			irqreturn_t r = ipu6_buttress_call_isr(adev[i]);
> +
> +			if (!(irq_status & ipu6_adev_irq_mask[i]))
> +				continue;
> +
> +			if (r == IRQ_WAKE_THREAD) {
> +				ret = IRQ_WAKE_THREAD;
> +				disable_irqs |= ipu6_adev_irq_mask[i];
> +			} else if (ret == IRQ_NONE && r == IRQ_HANDLED) {
> +				ret = IRQ_HANDLED;
> +			}
> +		}

It seems wrong to call the ISR for a adev[i] before checking the
corresponding IRQ mask. If the mask is not set, the ISR is still
called, but the result is thrown away.

I started investigating this because I'm seeing "general protection
fault, probably for non-canonical address 0x6b6b6b6b6b6b6b6b" in this
function when unbinding the IPU4 driver.

How do you ensure that the ISR is not called on a ipu6-bus device that
has been deleted? Specifically in ipu6_pci_remove, ipu6_bus_del_devices
is called before ipu6_buttress_exit (which disables buttress IRQs).
Perhaps the above for loop should really be a "for each ipu6-bus
device" loop?

> +
> +		if ((irq_status & BUTTRESS_EVENT) && ret == IRQ_NONE)
> +			ret = IRQ_HANDLED;
> +
> +		if (irq_status & BUTTRESS_ISR_IPC_FROM_CSE_IS_WAITING) {
> +			dev_dbg(&isp->pdev->dev,
> +				"BUTTRESS_ISR_IPC_FROM_CSE_IS_WAITING\n");
> +			ipu6_buttress_ipc_recv(isp, &b->cse, &b->cse.recv_data);
> +			complete(&b->cse.recv_complete);
> +		}
> +
> +		if (irq_status & BUTTRESS_ISR_IPC_FROM_ISH_IS_WAITING) {
> +			dev_dbg(&isp->pdev->dev,
> +				"BUTTRESS_ISR_IPC_FROM_ISH_IS_WAITING\n");
> +			ipu6_buttress_ipc_recv(isp, &b->ish, &b->ish.recv_data);
> +			complete(&b->ish.recv_complete);
> +		}
> +
> +		if (irq_status & BUTTRESS_ISR_IPC_EXEC_DONE_BY_CSE) {
> +			dev_dbg(&isp->pdev->dev,
> +				"BUTTRESS_ISR_IPC_EXEC_DONE_BY_CSE\n");
> +			complete(&b->cse.send_complete);
> +		}
> +
> +		if (irq_status & BUTTRESS_ISR_IPC_EXEC_DONE_BY_ISH) {
> +			dev_dbg(&isp->pdev->dev,
> +				"BUTTRESS_ISR_IPC_EXEC_DONE_BY_CSE\n");
> +			complete(&b->ish.send_complete);
> +		}
> +
> +		if (irq_status & BUTTRESS_ISR_SAI_VIOLATION &&
> +		    ipu6_buttress_get_secure_mode(isp))
> +			dev_err(&isp->pdev->dev,
> +				"BUTTRESS_ISR_SAI_VIOLATION\n");
> +
> +		if (irq_status & (BUTTRESS_ISR_IS_FATAL_MEM_ERR |
> +				  BUTTRESS_ISR_PS_FATAL_MEM_ERR))
> +			dev_err(&isp->pdev->dev,
> +				"BUTTRESS_ISR_FATAL_MEM_ERR\n");
> +
> +		if (irq_status & BUTTRESS_ISR_UFI_ERROR)
> +			dev_err(&isp->pdev->dev, "BUTTRESS_ISR_UFI_ERROR\n");
> +
> +		if (++count == BUTTRESS_MAX_CONSECUTIVE_IRQS) {
> +			dev_err(&isp->pdev->dev, "too many consecutive IRQs\n");
> +			ret = IRQ_NONE;
> +			break;
> +		}
> +
> +		irq_status = readl(isp->base + reg_irq_sts);
> +	} while (irq_status);
> +
> +	if (disable_irqs)
> +		writel(BUTTRESS_IRQS & ~disable_irqs,
> +		       isp->base + BUTTRESS_REG_ISR_ENABLE);
> +
> +	pm_runtime_put(&isp->pdev->dev);
> +
> +	return ret;
> +}

...

/Andreas

^ permalink raw reply	[flat|nested] 86+ messages in thread

* Re: [PATCH v2 06/15] media: intel/ipu6: add syscom interfaces between firmware and driver
  2023-12-28  6:39     ` Bingbu Cao
@ 2024-01-03  9:25       ` Andreas Helbech Kleist
  2024-01-08  4:19         ` Bingbu Cao
  0 siblings, 1 reply; 86+ messages in thread
From: Andreas Helbech Kleist @ 2024-01-03  9:25 UTC (permalink / raw)
  To: Bingbu Cao, bingbu.cao, linux-media, sakari.ailus, laurent.pinchart
  Cc: andriy.shevchenko, hdegoede, ilpo.jarvinen, claus.stovgaard,
	tfiga, senozhatsky, tomi.valkeinen, tian.shu.qiu, hongju.wang

Hi, 

On Thu, 2023-12-28 at 14:39 +0800, Bingbu Cao wrote:
> Andreas,
> 
> On 11/23/23 5:33 PM, Andreas Helbech Kleist wrote:
> > Hi,
> > 
> > On Tue, 2023-10-24 at 19:29 +0800, bingbu.cao@intel.com wrote:
> > > From: Bingbu Cao <bingbu.cao@intel.com>
> > > 
> > > Syscom is an inter-process(or) communication mechanism between an IPU
> > > and host. Syscom uses message queues for message exchange between IPU
> > > and host. Each message queue has its consumer and producer, host
> > > queue
> > > messages to firmware as the producer and then firmware to dequeue the
> > > messages as consumer and vice versa. IPU and host use shared
> > > registers
> > > or memory to reside the read and write indices which are updated by
> > > consumer and producer.
> > > 
> > > Signed-off-by: Bingbu Cao <bingbu.cao@intel.com>
> > > ---
> > >  drivers/media/pci/intel/ipu6/ipu6-fw-com.c | 411
> > > +++++++++++++++++++++
> > >  drivers/media/pci/intel/ipu6/ipu6-fw-com.h |  47 +++
> > >  2 files changed, 458 insertions(+)
> > >  create mode 100644 drivers/media/pci/intel/ipu6/ipu6-fw-com.c
> > >  create mode 100644 drivers/media/pci/intel/ipu6/ipu6-fw-com.h
> > ...
> > > +struct ipu6_fw_com_context {
> > > +       struct ipu6_bus_device *adev;
> > > +       void __iomem *dmem_addr;
> > > +       int (*cell_ready)(struct ipu6_bus_device *adev);
> > > +       void (*cell_start)(struct ipu6_bus_device *adev);
> > 
> > Why are cell_ready and cell_start function pointers? They seem to
> > always be set to query_sp and start_sp.
> > 
> > > +
> > > +       void *dma_buffer;
> > > +       dma_addr_t dma_addr;
> > > +       unsigned int dma_size;
> > > +       unsigned long attrs;
> > > +
> > > +       struct ipu6_fw_sys_queue *input_queue;  /* array of host to
> > > SP queues */
> > > +       struct ipu6_fw_sys_queue *output_queue; /* array of SP to
> > > host */
> > > +
> > > +       u32 config_vied_addr;
> > > +
> > > +       unsigned int buttress_boot_offset;
> > > +       void __iomem *base_addr;
> > > +};
> > > +
> > > +#define FW_COM_WR_REG 0
> > > +#define FW_COM_RD_REG 4
> > > +
> > > +#define REGMEM_OFFSET 0
> > > +#define TUNIT_MAGIC_PATTERN 0x5a5a5a5a
> > > +
> > > +enum regmem_id {
> > > +       /* pass pkg_dir address to SPC in non-secure mode */
> > > +       PKG_DIR_ADDR_REG = 0,
> > > +       /* Tunit CFG blob for secure - provided by host.*/
> > > +       TUNIT_CFG_DWR_REG = 1,
> > > +       /* syscom commands - modified by the host */
> > > +       SYSCOM_COMMAND_REG = 2,
> > > +       /* Store interrupt status - updated by SP */
> > > +       SYSCOM_IRQ_REG = 3,
> > > +       /* first syscom queue pointer register */
> > > +       SYSCOM_QPR_BASE_REG = 4
> > > +};
> > > +
> > > +enum message_direction {
> > > +       DIR_RECV = 0,
> > > +       DIR_SEND
> > > +};
> > 
> > Not used?
> 
> Ack, will remove.
> 
> > 
> > 
> > ...
> > > +struct ipu6_fw_com_cfg {
> > > +       unsigned int num_input_queues;
> > > +       unsigned int num_output_queues;
> > > +       struct ipu6_fw_syscom_queue_config *input;
> > > +       struct ipu6_fw_syscom_queue_config *output;
> > > +
> > > +       unsigned int dmem_addr;
> > > +
> > > +       /* firmware-specific configuration data */
> > > +       void *specific_addr;
> > > +       unsigned int specific_size;
> > > +       int (*cell_ready)(struct ipu6_bus_device *adev);
> > > +       void (*cell_start)(struct ipu6_bus_device *adev);
> > > +
> > > +       unsigned int buttress_boot_offset;
> > 
> > This seems to always be 0 (set by ipu6-fw-isys.c), seems to be trivial
> > to remove.
> 
> All these fields are all used to extend for psys driver.

Then I suppose they can be added if a psys driver is submitted upstream
at some point.

Is is it the intention to submit a psys driver as well?

/Andreas


^ permalink raw reply	[flat|nested] 86+ messages in thread

* Re: [PATCH v2 03/15] media: intel/ipu6: add IPU6 buttress interface driver
  2024-01-03  9:22   ` Andreas Helbech Kleist
@ 2024-01-03 10:49     ` Laurent Pinchart
  2024-01-03 13:33       ` Bingbu Cao
  2024-01-03 13:11     ` Bingbu Cao
  1 sibling, 1 reply; 86+ messages in thread
From: Laurent Pinchart @ 2024-01-03 10:49 UTC (permalink / raw)
  To: Andreas Helbech Kleist
  Cc: bingbu.cao, linux-media, sakari.ailus, andriy.shevchenko,
	hdegoede, ilpo.jarvinen, claus.stovgaard, tfiga, senozhatsky,
	tomi.valkeinen, bingbu.cao, tian.shu.qiu, hongju.wang

On Wed, Jan 03, 2024 at 10:22:20AM +0100, Andreas Helbech Kleist wrote:
> Hi Bingbu,
> 
> On Tue, 2023-10-24 at 19:29 +0800, bingbu.cao@intel.com wrote:
> > From: Bingbu Cao <bingbu.cao@intel.com>
> > 
> > The IPU6 buttress is the interface between IPU device (input system
> > and processing system) with rest of the SoC. It contains overall IPU
> > hardware control registers, these control registers are used as the
> > interfaces with the Intel Converged Security Engine and Punit to do
> > firmware authentication and power management.
> > 
> > Signed-off-by: Bingbu Cao <bingbu.cao@intel.com>
> > ---
> 
> ...
> 
> > +static irqreturn_t ipu6_buttress_call_isr(struct ipu6_bus_device *adev)
> > +{
> > +	irqreturn_t ret = IRQ_WAKE_THREAD;
> > +
> > +	if (!adev || !adev->auxdrv || !adev->auxdrv_data)
> > +		return IRQ_NONE;
> > +
> > +	if (adev->auxdrv_data->isr)
> > +		ret = adev->auxdrv_data->isr(adev);
> > +
> > +	if (ret == IRQ_WAKE_THREAD && !adev->auxdrv_data->isr_threaded)
> > +		ret = IRQ_NONE;
> > +
> > +	return ret;
> > +}
> > +
> > +irqreturn_t ipu6_buttress_isr(int irq, void *isp_ptr)
> > +{
> > +	struct ipu6_device *isp = isp_ptr;
> > +	struct ipu6_bus_device *adev[] = { isp->isys, isp->psys };
> > +	struct ipu6_buttress *b = &isp->buttress;
> > +	u32 reg_irq_sts = BUTTRESS_REG_ISR_STATUS;
> > +	irqreturn_t ret = IRQ_NONE;
> > +	u32 disable_irqs = 0;
> > +	u32 irq_status;
> > +	u32 i, count = 0;
> > +
> > +	pm_runtime_get_noresume(&isp->pdev->dev);
> > +
> > +	irq_status = readl(isp->base + reg_irq_sts);

A drive-by comment: this seems dodgy. If someone calls pm_runtime_put*()
just before the pm_runtime_get_noresume() above, the device won't be
resumed when reading the register, which will likely not lead to the
desired result.

> > +	if (!irq_status) {
> > +		pm_runtime_put_noidle(&isp->pdev->dev);
> > +		return IRQ_NONE;
> > +	}
> > +
> > +	do {
> > +		writel(irq_status, isp->base + BUTTRESS_REG_ISR_CLEAR);
> > +
> > +		for (i = 0; i < ARRAY_SIZE(ipu6_adev_irq_mask); i++) {
> > +			irqreturn_t r = ipu6_buttress_call_isr(adev[i]);
> > +
> > +			if (!(irq_status & ipu6_adev_irq_mask[i]))
> > +				continue;
> > +
> > +			if (r == IRQ_WAKE_THREAD) {
> > +				ret = IRQ_WAKE_THREAD;
> > +				disable_irqs |= ipu6_adev_irq_mask[i];
> > +			} else if (ret == IRQ_NONE && r == IRQ_HANDLED) {
> > +				ret = IRQ_HANDLED;
> > +			}
> > +		}
> 
> It seems wrong to call the ISR for a adev[i] before checking the
> corresponding IRQ mask. If the mask is not set, the ISR is still
> called, but the result is thrown away.
> 
> I started investigating this because I'm seeing "general protection
> fault, probably for non-canonical address 0x6b6b6b6b6b6b6b6b" in this
> function when unbinding the IPU4 driver.
> 
> How do you ensure that the ISR is not called on a ipu6-bus device that
> has been deleted? Specifically in ipu6_pci_remove, ipu6_bus_del_devices
> is called before ipu6_buttress_exit (which disables buttress IRQs).
> Perhaps the above for loop should really be a "for each ipu6-bus
> device" loop?
> 
> > +
> > +		if ((irq_status & BUTTRESS_EVENT) && ret == IRQ_NONE)
> > +			ret = IRQ_HANDLED;
> > +
> > +		if (irq_status & BUTTRESS_ISR_IPC_FROM_CSE_IS_WAITING) {
> > +			dev_dbg(&isp->pdev->dev,
> > +				"BUTTRESS_ISR_IPC_FROM_CSE_IS_WAITING\n");
> > +			ipu6_buttress_ipc_recv(isp, &b->cse, &b->cse.recv_data);
> > +			complete(&b->cse.recv_complete);
> > +		}
> > +
> > +		if (irq_status & BUTTRESS_ISR_IPC_FROM_ISH_IS_WAITING) {
> > +			dev_dbg(&isp->pdev->dev,
> > +				"BUTTRESS_ISR_IPC_FROM_ISH_IS_WAITING\n");
> > +			ipu6_buttress_ipc_recv(isp, &b->ish, &b->ish.recv_data);
> > +			complete(&b->ish.recv_complete);
> > +		}
> > +
> > +		if (irq_status & BUTTRESS_ISR_IPC_EXEC_DONE_BY_CSE) {
> > +			dev_dbg(&isp->pdev->dev,
> > +				"BUTTRESS_ISR_IPC_EXEC_DONE_BY_CSE\n");
> > +			complete(&b->cse.send_complete);
> > +		}
> > +
> > +		if (irq_status & BUTTRESS_ISR_IPC_EXEC_DONE_BY_ISH) {
> > +			dev_dbg(&isp->pdev->dev,
> > +				"BUTTRESS_ISR_IPC_EXEC_DONE_BY_CSE\n");
> > +			complete(&b->ish.send_complete);
> > +		}
> > +
> > +		if (irq_status & BUTTRESS_ISR_SAI_VIOLATION &&
> > +		    ipu6_buttress_get_secure_mode(isp))
> > +			dev_err(&isp->pdev->dev,
> > +				"BUTTRESS_ISR_SAI_VIOLATION\n");
> > +
> > +		if (irq_status & (BUTTRESS_ISR_IS_FATAL_MEM_ERR |
> > +				  BUTTRESS_ISR_PS_FATAL_MEM_ERR))
> > +			dev_err(&isp->pdev->dev,
> > +				"BUTTRESS_ISR_FATAL_MEM_ERR\n");
> > +
> > +		if (irq_status & BUTTRESS_ISR_UFI_ERROR)
> > +			dev_err(&isp->pdev->dev, "BUTTRESS_ISR_UFI_ERROR\n");
> > +
> > +		if (++count == BUTTRESS_MAX_CONSECUTIVE_IRQS) {
> > +			dev_err(&isp->pdev->dev, "too many consecutive IRQs\n");
> > +			ret = IRQ_NONE;
> > +			break;
> > +		}
> > +
> > +		irq_status = readl(isp->base + reg_irq_sts);
> > +	} while (irq_status);
> > +
> > +	if (disable_irqs)
> > +		writel(BUTTRESS_IRQS & ~disable_irqs,
> > +		       isp->base + BUTTRESS_REG_ISR_ENABLE);
> > +
> > +	pm_runtime_put(&isp->pdev->dev);
> > +
> > +	return ret;
> > +}
> 
> ...
> 
> /Andreas

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 86+ messages in thread

* Re: [PATCH v2 03/15] media: intel/ipu6: add IPU6 buttress interface driver
  2024-01-03  9:22   ` Andreas Helbech Kleist
  2024-01-03 10:49     ` Laurent Pinchart
@ 2024-01-03 13:11     ` Bingbu Cao
  2024-01-03 13:18       ` Bingbu Cao
  1 sibling, 1 reply; 86+ messages in thread
From: Bingbu Cao @ 2024-01-03 13:11 UTC (permalink / raw)
  To: Andreas Helbech Kleist, bingbu.cao, linux-media, sakari.ailus,
	laurent.pinchart
  Cc: andriy.shevchenko, hdegoede, ilpo.jarvinen, claus.stovgaard,
	tfiga, senozhatsky, tomi.valkeinen, tian.shu.qiu, hongju.wang

Andreas,

On 1/3/24 5:22 PM, Andreas Helbech Kleist wrote:
> Hi Bingbu,
> 
> On Tue, 2023-10-24 at 19:29 +0800, bingbu.cao@intel.com wrote:
>> From: Bingbu Cao <bingbu.cao@intel.com>
>>
>> The IPU6 buttress is the interface between IPU device (input system
>> and processing system) with rest of the SoC. It contains overall IPU
>> hardware control registers, these control registers are used as the
>> interfaces with the Intel Converged Security Engine and Punit to do
>> firmware authentication and power management.
>>
>> Signed-off-by: Bingbu Cao <bingbu.cao@intel.com>
>> ---
> 
> ...
> 
>> +static irqreturn_t ipu6_buttress_call_isr(struct ipu6_bus_device *adev)
>> +{
>> +	irqreturn_t ret = IRQ_WAKE_THREAD;
>> +
>> +	if (!adev || !adev->auxdrv || !adev->auxdrv_data)
>> +		return IRQ_NONE;
>> +
>> +	if (adev->auxdrv_data->isr)
>> +		ret = adev->auxdrv_data->isr(adev);
>> +
>> +	if (ret == IRQ_WAKE_THREAD && !adev->auxdrv_data->isr_threaded)
>> +		ret = IRQ_NONE;
>> +
>> +	return ret;
>> +}
>> +
>> +irqreturn_t ipu6_buttress_isr(int irq, void *isp_ptr)
>> +{
>> +	struct ipu6_device *isp = isp_ptr;
>> +	struct ipu6_bus_device *adev[] = { isp->isys, isp->psys };
>> +	struct ipu6_buttress *b = &isp->buttress;
>> +	u32 reg_irq_sts = BUTTRESS_REG_ISR_STATUS;
>> +	irqreturn_t ret = IRQ_NONE;
>> +	u32 disable_irqs = 0;
>> +	u32 irq_status;
>> +	u32 i, count = 0;
>> +
>> +	pm_runtime_get_noresume(&isp->pdev->dev);
>> +
>> +	irq_status = readl(isp->base + reg_irq_sts);
>> +	if (!irq_status) {
>> +		pm_runtime_put_noidle(&isp->pdev->dev);
>> +		return IRQ_NONE;
>> +	}
>> +
>> +	do {
>> +		writel(irq_status, isp->base + BUTTRESS_REG_ISR_CLEAR);
>> +
>> +		for (i = 0; i < ARRAY_SIZE(ipu6_adev_irq_mask); i++) {
>> +			irqreturn_t r = ipu6_buttress_call_isr(adev[i]);
>> +
>> +			if (!(irq_status & ipu6_adev_irq_mask[i]))
>> +				continue;
>> +
>> +			if (r == IRQ_WAKE_THREAD) {
>> +				ret = IRQ_WAKE_THREAD;
>> +				disable_irqs |= ipu6_adev_irq_mask[i];
>> +			} else if (ret == IRQ_NONE && r == IRQ_HANDLED) {
>> +				ret = IRQ_HANDLED;
>> +			}
>> +		}
> 
> It seems wrong to call the ISR for a adev[i] before checking the
> corresponding IRQ mask. If the mask is not set, the ISR is still
> called, but the result is thrown away.
> 
> I started investigating this because I'm seeing "general protection
> fault, probably for non-canonical address 0x6b6b6b6b6b6b6b6b" in this
> function when unbinding the IPU4 driver.
> 
> How do you ensure that the ISR is not called on a ipu6-bus device that
> has been deleted? Specifically in ipu6_pci_remove, ipu6_bus_del_devices
> is called before ipu6_buttress_exit (which disables buttress IRQs).
> Perhaps the above for loop should really be a "for each ipu6-bus
> device" loop?

You are right, the buttress_exit() should be called before
ipu6_bus_del_devices().

Even with this, driver cannot guarantee that hardware irq was actually
disabled on IPU4. In some error cases, HW could report unmasked errors on
IPU4 (no such case on IPU6), if I remember correctly.

Have you check whether devm_free_irq() in ipu6_pci_remove() can help you?

> 
>> +
>> +		if ((irq_status & BUTTRESS_EVENT) && ret == IRQ_NONE)
>> +			ret = IRQ_HANDLED;
>> +
>> +		if (irq_status & BUTTRESS_ISR_IPC_FROM_CSE_IS_WAITING) {
>> +			dev_dbg(&isp->pdev->dev,
>> +				"BUTTRESS_ISR_IPC_FROM_CSE_IS_WAITING\n");
>> +			ipu6_buttress_ipc_recv(isp, &b->cse, &b->cse.recv_data);
>> +			complete(&b->cse.recv_complete);
>> +		}
>> +
>> +		if (irq_status & BUTTRESS_ISR_IPC_FROM_ISH_IS_WAITING) {
>> +			dev_dbg(&isp->pdev->dev,
>> +				"BUTTRESS_ISR_IPC_FROM_ISH_IS_WAITING\n");
>> +			ipu6_buttress_ipc_recv(isp, &b->ish, &b->ish.recv_data);
>> +			complete(&b->ish.recv_complete);
>> +		}
>> +
>> +		if (irq_status & BUTTRESS_ISR_IPC_EXEC_DONE_BY_CSE) {
>> +			dev_dbg(&isp->pdev->dev,
>> +				"BUTTRESS_ISR_IPC_EXEC_DONE_BY_CSE\n");
>> +			complete(&b->cse.send_complete);
>> +		}
>> +
>> +		if (irq_status & BUTTRESS_ISR_IPC_EXEC_DONE_BY_ISH) {
>> +			dev_dbg(&isp->pdev->dev,
>> +				"BUTTRESS_ISR_IPC_EXEC_DONE_BY_CSE\n");
>> +			complete(&b->ish.send_complete);
>> +		}
>> +
>> +		if (irq_status & BUTTRESS_ISR_SAI_VIOLATION &&
>> +		    ipu6_buttress_get_secure_mode(isp))
>> +			dev_err(&isp->pdev->dev,
>> +				"BUTTRESS_ISR_SAI_VIOLATION\n");
>> +
>> +		if (irq_status & (BUTTRESS_ISR_IS_FATAL_MEM_ERR |
>> +				  BUTTRESS_ISR_PS_FATAL_MEM_ERR))
>> +			dev_err(&isp->pdev->dev,
>> +				"BUTTRESS_ISR_FATAL_MEM_ERR\n");
>> +
>> +		if (irq_status & BUTTRESS_ISR_UFI_ERROR)
>> +			dev_err(&isp->pdev->dev, "BUTTRESS_ISR_UFI_ERROR\n");
>> +
>> +		if (++count == BUTTRESS_MAX_CONSECUTIVE_IRQS) {
>> +			dev_err(&isp->pdev->dev, "too many consecutive IRQs\n");
>> +			ret = IRQ_NONE;
>> +			break;
>> +		}
>> +
>> +		irq_status = readl(isp->base + reg_irq_sts);
>> +	} while (irq_status);
>> +
>> +	if (disable_irqs)
>> +		writel(BUTTRESS_IRQS & ~disable_irqs,
>> +		       isp->base + BUTTRESS_REG_ISR_ENABLE);
>> +
>> +	pm_runtime_put(&isp->pdev->dev);
>> +
>> +	return ret;
>> +}
> 
> ...
> 
> /Andreas
> 

-- 
Best regards,
Bingbu Cao

^ permalink raw reply	[flat|nested] 86+ messages in thread

* Re: [PATCH v2 03/15] media: intel/ipu6: add IPU6 buttress interface driver
  2024-01-03 13:11     ` Bingbu Cao
@ 2024-01-03 13:18       ` Bingbu Cao
  2024-01-08 10:27         ` Andreas Helbech Kleist
  0 siblings, 1 reply; 86+ messages in thread
From: Bingbu Cao @ 2024-01-03 13:18 UTC (permalink / raw)
  To: Andreas Helbech Kleist, bingbu.cao, linux-media, sakari.ailus,
	laurent.pinchart
  Cc: andriy.shevchenko, hdegoede, ilpo.jarvinen, claus.stovgaard,
	tfiga, senozhatsky, tomi.valkeinen, tian.shu.qiu, hongju.wang

Andreas,

On 1/3/24 9:11 PM, Bingbu Cao wrote:
> Andreas,
> 
> On 1/3/24 5:22 PM, Andreas Helbech Kleist wrote:
>> Hi Bingbu,
>>
>> On Tue, 2023-10-24 at 19:29 +0800, bingbu.cao@intel.com wrote:
>>> From: Bingbu Cao <bingbu.cao@intel.com>
>>>
>>> The IPU6 buttress is the interface between IPU device (input system
>>> and processing system) with rest of the SoC. It contains overall IPU
>>> hardware control registers, these control registers are used as the
>>> interfaces with the Intel Converged Security Engine and Punit to do
>>> firmware authentication and power management.
>>>
>>> Signed-off-by: Bingbu Cao <bingbu.cao@intel.com>
>>> ---
>>
>> ...
>>
>>> +static irqreturn_t ipu6_buttress_call_isr(struct ipu6_bus_device *adev)
>>> +{
>>> +	irqreturn_t ret = IRQ_WAKE_THREAD;
>>> +
>>> +	if (!adev || !adev->auxdrv || !adev->auxdrv_data)
>>> +		return IRQ_NONE;
>>> +
>>> +	if (adev->auxdrv_data->isr)
>>> +		ret = adev->auxdrv_data->isr(adev);
>>> +
>>> +	if (ret == IRQ_WAKE_THREAD && !adev->auxdrv_data->isr_threaded)
>>> +		ret = IRQ_NONE;
>>> +
>>> +	return ret;
>>> +}
>>> +
>>> +irqreturn_t ipu6_buttress_isr(int irq, void *isp_ptr)
>>> +{
>>> +	struct ipu6_device *isp = isp_ptr;
>>> +	struct ipu6_bus_device *adev[] = { isp->isys, isp->psys };
>>> +	struct ipu6_buttress *b = &isp->buttress;
>>> +	u32 reg_irq_sts = BUTTRESS_REG_ISR_STATUS;
>>> +	irqreturn_t ret = IRQ_NONE;
>>> +	u32 disable_irqs = 0;
>>> +	u32 irq_status;
>>> +	u32 i, count = 0;
>>> +
>>> +	pm_runtime_get_noresume(&isp->pdev->dev);
>>> +
>>> +	irq_status = readl(isp->base + reg_irq_sts);
>>> +	if (!irq_status) {
>>> +		pm_runtime_put_noidle(&isp->pdev->dev);
>>> +		return IRQ_NONE;
>>> +	}
>>> +
>>> +	do {
>>> +		writel(irq_status, isp->base + BUTTRESS_REG_ISR_CLEAR);
>>> +
>>> +		for (i = 0; i < ARRAY_SIZE(ipu6_adev_irq_mask); i++) {
>>> +			irqreturn_t r = ipu6_buttress_call_isr(adev[i]);
>>> +
>>> +			if (!(irq_status & ipu6_adev_irq_mask[i]))
>>> +				continue;
>>> +
>>> +			if (r == IRQ_WAKE_THREAD) {
>>> +				ret = IRQ_WAKE_THREAD;
>>> +				disable_irqs |= ipu6_adev_irq_mask[i];
>>> +			} else if (ret == IRQ_NONE && r == IRQ_HANDLED) {
>>> +				ret = IRQ_HANDLED;
>>> +			}
>>> +		}
>>
>> It seems wrong to call the ISR for a adev[i] before checking the
>> corresponding IRQ mask. If the mask is not set, the ISR is still
>> called, but the result is thrown away.
>>
>> I started investigating this because I'm seeing "general protection
>> fault, probably for non-canonical address 0x6b6b6b6b6b6b6b6b" in this
>> function when unbinding the IPU4 driver.
>>
>> How do you ensure that the ISR is not called on a ipu6-bus device that
>> has been deleted? Specifically in ipu6_pci_remove, ipu6_bus_del_devices
>> is called before ipu6_buttress_exit (which disables buttress IRQs).
>> Perhaps the above for loop should really be a "for each ipu6-bus
>> device" loop?
> 
> You are right, the buttress_exit() should be called before
> ipu6_bus_del_devices().
> 
> Even with this, driver cannot guarantee that hardware irq was actually
> disabled on IPU4. In some error cases, HW could report unmasked errors on
> IPU4 (no such case on IPU6), if I remember correctly.
> 
> Have you check whether devm_free_irq() in ipu6_pci_remove() can help you?

BTW, could you share the irq_status in your case?

> 
>>
>>> +
>>> +		if ((irq_status & BUTTRESS_EVENT) && ret == IRQ_NONE)
>>> +			ret = IRQ_HANDLED;
>>> +
>>> +		if (irq_status & BUTTRESS_ISR_IPC_FROM_CSE_IS_WAITING) {
>>> +			dev_dbg(&isp->pdev->dev,
>>> +				"BUTTRESS_ISR_IPC_FROM_CSE_IS_WAITING\n");
>>> +			ipu6_buttress_ipc_recv(isp, &b->cse, &b->cse.recv_data);
>>> +			complete(&b->cse.recv_complete);
>>> +		}
>>> +
>>> +		if (irq_status & BUTTRESS_ISR_IPC_FROM_ISH_IS_WAITING) {
>>> +			dev_dbg(&isp->pdev->dev,
>>> +				"BUTTRESS_ISR_IPC_FROM_ISH_IS_WAITING\n");
>>> +			ipu6_buttress_ipc_recv(isp, &b->ish, &b->ish.recv_data);
>>> +			complete(&b->ish.recv_complete);
>>> +		}
>>> +
>>> +		if (irq_status & BUTTRESS_ISR_IPC_EXEC_DONE_BY_CSE) {
>>> +			dev_dbg(&isp->pdev->dev,
>>> +				"BUTTRESS_ISR_IPC_EXEC_DONE_BY_CSE\n");
>>> +			complete(&b->cse.send_complete);
>>> +		}
>>> +
>>> +		if (irq_status & BUTTRESS_ISR_IPC_EXEC_DONE_BY_ISH) {
>>> +			dev_dbg(&isp->pdev->dev,
>>> +				"BUTTRESS_ISR_IPC_EXEC_DONE_BY_CSE\n");
>>> +			complete(&b->ish.send_complete);
>>> +		}
>>> +
>>> +		if (irq_status & BUTTRESS_ISR_SAI_VIOLATION &&
>>> +		    ipu6_buttress_get_secure_mode(isp))
>>> +			dev_err(&isp->pdev->dev,
>>> +				"BUTTRESS_ISR_SAI_VIOLATION\n");
>>> +
>>> +		if (irq_status & (BUTTRESS_ISR_IS_FATAL_MEM_ERR |
>>> +				  BUTTRESS_ISR_PS_FATAL_MEM_ERR))
>>> +			dev_err(&isp->pdev->dev,
>>> +				"BUTTRESS_ISR_FATAL_MEM_ERR\n");
>>> +
>>> +		if (irq_status & BUTTRESS_ISR_UFI_ERROR)
>>> +			dev_err(&isp->pdev->dev, "BUTTRESS_ISR_UFI_ERROR\n");
>>> +
>>> +		if (++count == BUTTRESS_MAX_CONSECUTIVE_IRQS) {
>>> +			dev_err(&isp->pdev->dev, "too many consecutive IRQs\n");
>>> +			ret = IRQ_NONE;
>>> +			break;
>>> +		}
>>> +
>>> +		irq_status = readl(isp->base + reg_irq_sts);
>>> +	} while (irq_status);
>>> +
>>> +	if (disable_irqs)
>>> +		writel(BUTTRESS_IRQS & ~disable_irqs,
>>> +		       isp->base + BUTTRESS_REG_ISR_ENABLE);
>>> +
>>> +	pm_runtime_put(&isp->pdev->dev);
>>> +
>>> +	return ret;
>>> +}
>>
>> ...
>>
>> /Andreas
>>
> 

-- 
Best regards,
Bingbu Cao

^ permalink raw reply	[flat|nested] 86+ messages in thread

* Re: [PATCH v2 03/15] media: intel/ipu6: add IPU6 buttress interface driver
  2024-01-03 10:49     ` Laurent Pinchart
@ 2024-01-03 13:33       ` Bingbu Cao
  2024-01-03 14:01         ` Laurent Pinchart
  0 siblings, 1 reply; 86+ messages in thread
From: Bingbu Cao @ 2024-01-03 13:33 UTC (permalink / raw)
  To: Laurent Pinchart, Andreas Helbech Kleist
  Cc: bingbu.cao, linux-media, sakari.ailus, andriy.shevchenko,
	hdegoede, ilpo.jarvinen, claus.stovgaard, tfiga, senozhatsky,
	tomi.valkeinen, tian.shu.qiu, hongju.wang

Laurent,

On 1/3/24 6:49 PM, Laurent Pinchart wrote:
> On Wed, Jan 03, 2024 at 10:22:20AM +0100, Andreas Helbech Kleist wrote:
>> Hi Bingbu,
>>
>> On Tue, 2023-10-24 at 19:29 +0800, bingbu.cao@intel.com wrote:
>>> From: Bingbu Cao <bingbu.cao@intel.com>
>>>
>>> The IPU6 buttress is the interface between IPU device (input system
>>> and processing system) with rest of the SoC. It contains overall IPU
>>> hardware control registers, these control registers are used as the
>>> interfaces with the Intel Converged Security Engine and Punit to do
>>> firmware authentication and power management.
>>>
>>> Signed-off-by: Bingbu Cao <bingbu.cao@intel.com>
>>> ---
>>
>> ...
>>
>>> +static irqreturn_t ipu6_buttress_call_isr(struct ipu6_bus_device *adev)
>>> +{
>>> +	irqreturn_t ret = IRQ_WAKE_THREAD;
>>> +
>>> +	if (!adev || !adev->auxdrv || !adev->auxdrv_data)
>>> +		return IRQ_NONE;
>>> +
>>> +	if (adev->auxdrv_data->isr)
>>> +		ret = adev->auxdrv_data->isr(adev);
>>> +
>>> +	if (ret == IRQ_WAKE_THREAD && !adev->auxdrv_data->isr_threaded)
>>> +		ret = IRQ_NONE;
>>> +
>>> +	return ret;
>>> +}
>>> +
>>> +irqreturn_t ipu6_buttress_isr(int irq, void *isp_ptr)
>>> +{
>>> +	struct ipu6_device *isp = isp_ptr;
>>> +	struct ipu6_bus_device *adev[] = { isp->isys, isp->psys };
>>> +	struct ipu6_buttress *b = &isp->buttress;
>>> +	u32 reg_irq_sts = BUTTRESS_REG_ISR_STATUS;
>>> +	irqreturn_t ret = IRQ_NONE;
>>> +	u32 disable_irqs = 0;
>>> +	u32 irq_status;
>>> +	u32 i, count = 0;
>>> +
>>> +	pm_runtime_get_noresume(&isp->pdev->dev);
>>> +
>>> +	irq_status = readl(isp->base + reg_irq_sts);
> 
> A drive-by comment: this seems dodgy. If someone calls pm_runtime_put*()
> just before the pm_runtime_get_noresume() above, the device won't be
> resumed when reading the register, which will likely not lead to the
> desired result.

Thanks for your review. 
What do you think using pm_runtime_get_if_in_use() here?
 
> 
>>> +	if (!irq_status) {
>>> +		pm_runtime_put_noidle(&isp->pdev->dev);
>>> +		return IRQ_NONE;
>>> +	}
>>> +
>>> +	do {
>>> +		writel(irq_status, isp->base + BUTTRESS_REG_ISR_CLEAR);
>>> +
>>> +		for (i = 0; i < ARRAY_SIZE(ipu6_adev_irq_mask); i++) {
>>> +			irqreturn_t r = ipu6_buttress_call_isr(adev[i]);
>>> +
>>> +			if (!(irq_status & ipu6_adev_irq_mask[i]))
>>> +				continue;
>>> +
>>> +			if (r == IRQ_WAKE_THREAD) {
>>> +				ret = IRQ_WAKE_THREAD;
>>> +				disable_irqs |= ipu6_adev_irq_mask[i];
>>> +			} else if (ret == IRQ_NONE && r == IRQ_HANDLED) {
>>> +				ret = IRQ_HANDLED;
>>> +			}
>>> +		}
>>
>> It seems wrong to call the ISR for a adev[i] before checking the
>> corresponding IRQ mask. If the mask is not set, the ISR is still
>> called, but the result is thrown away.
>>
>> I started investigating this because I'm seeing "general protection
>> fault, probably for non-canonical address 0x6b6b6b6b6b6b6b6b" in this
>> function when unbinding the IPU4 driver.
>>
>> How do you ensure that the ISR is not called on a ipu6-bus device that
>> has been deleted? Specifically in ipu6_pci_remove, ipu6_bus_del_devices
>> is called before ipu6_buttress_exit (which disables buttress IRQs).
>> Perhaps the above for loop should really be a "for each ipu6-bus
>> device" loop?
>>
>>> +
>>> +		if ((irq_status & BUTTRESS_EVENT) && ret == IRQ_NONE)
>>> +			ret = IRQ_HANDLED;
>>> +
>>> +		if (irq_status & BUTTRESS_ISR_IPC_FROM_CSE_IS_WAITING) {
>>> +			dev_dbg(&isp->pdev->dev,
>>> +				"BUTTRESS_ISR_IPC_FROM_CSE_IS_WAITING\n");
>>> +			ipu6_buttress_ipc_recv(isp, &b->cse, &b->cse.recv_data);
>>> +			complete(&b->cse.recv_complete);
>>> +		}
>>> +
>>> +		if (irq_status & BUTTRESS_ISR_IPC_FROM_ISH_IS_WAITING) {
>>> +			dev_dbg(&isp->pdev->dev,
>>> +				"BUTTRESS_ISR_IPC_FROM_ISH_IS_WAITING\n");
>>> +			ipu6_buttress_ipc_recv(isp, &b->ish, &b->ish.recv_data);
>>> +			complete(&b->ish.recv_complete);
>>> +		}
>>> +
>>> +		if (irq_status & BUTTRESS_ISR_IPC_EXEC_DONE_BY_CSE) {
>>> +			dev_dbg(&isp->pdev->dev,
>>> +				"BUTTRESS_ISR_IPC_EXEC_DONE_BY_CSE\n");
>>> +			complete(&b->cse.send_complete);
>>> +		}
>>> +
>>> +		if (irq_status & BUTTRESS_ISR_IPC_EXEC_DONE_BY_ISH) {
>>> +			dev_dbg(&isp->pdev->dev,
>>> +				"BUTTRESS_ISR_IPC_EXEC_DONE_BY_CSE\n");
>>> +			complete(&b->ish.send_complete);
>>> +		}
>>> +
>>> +		if (irq_status & BUTTRESS_ISR_SAI_VIOLATION &&
>>> +		    ipu6_buttress_get_secure_mode(isp))
>>> +			dev_err(&isp->pdev->dev,
>>> +				"BUTTRESS_ISR_SAI_VIOLATION\n");
>>> +
>>> +		if (irq_status & (BUTTRESS_ISR_IS_FATAL_MEM_ERR |
>>> +				  BUTTRESS_ISR_PS_FATAL_MEM_ERR))
>>> +			dev_err(&isp->pdev->dev,
>>> +				"BUTTRESS_ISR_FATAL_MEM_ERR\n");
>>> +
>>> +		if (irq_status & BUTTRESS_ISR_UFI_ERROR)
>>> +			dev_err(&isp->pdev->dev, "BUTTRESS_ISR_UFI_ERROR\n");
>>> +
>>> +		if (++count == BUTTRESS_MAX_CONSECUTIVE_IRQS) {
>>> +			dev_err(&isp->pdev->dev, "too many consecutive IRQs\n");
>>> +			ret = IRQ_NONE;
>>> +			break;
>>> +		}
>>> +
>>> +		irq_status = readl(isp->base + reg_irq_sts);
>>> +	} while (irq_status);
>>> +
>>> +	if (disable_irqs)
>>> +		writel(BUTTRESS_IRQS & ~disable_irqs,
>>> +		       isp->base + BUTTRESS_REG_ISR_ENABLE);
>>> +
>>> +	pm_runtime_put(&isp->pdev->dev);
>>> +
>>> +	return ret;
>>> +}
>>
>> ...
>>
>> /Andreas
> 

-- 
Best regards,
Bingbu Cao

^ permalink raw reply	[flat|nested] 86+ messages in thread

* Re: [PATCH v2 03/15] media: intel/ipu6: add IPU6 buttress interface driver
  2024-01-03 13:33       ` Bingbu Cao
@ 2024-01-03 14:01         ` Laurent Pinchart
  0 siblings, 0 replies; 86+ messages in thread
From: Laurent Pinchart @ 2024-01-03 14:01 UTC (permalink / raw)
  To: Bingbu Cao
  Cc: Andreas Helbech Kleist, bingbu.cao, linux-media, sakari.ailus,
	andriy.shevchenko, hdegoede, ilpo.jarvinen, claus.stovgaard,
	tfiga, senozhatsky, tomi.valkeinen, tian.shu.qiu, hongju.wang

Hi Bingbu,

On Wed, Jan 03, 2024 at 09:33:26PM +0800, Bingbu Cao wrote:
> On 1/3/24 6:49 PM, Laurent Pinchart wrote:
> > On Wed, Jan 03, 2024 at 10:22:20AM +0100, Andreas Helbech Kleist wrote:
> >> On Tue, 2023-10-24 at 19:29 +0800, bingbu.cao@intel.com wrote:
> >>> From: Bingbu Cao <bingbu.cao@intel.com>
> >>>
> >>> The IPU6 buttress is the interface between IPU device (input system
> >>> and processing system) with rest of the SoC. It contains overall IPU
> >>> hardware control registers, these control registers are used as the
> >>> interfaces with the Intel Converged Security Engine and Punit to do
> >>> firmware authentication and power management.
> >>>
> >>> Signed-off-by: Bingbu Cao <bingbu.cao@intel.com>
> >>> ---
> >>
> >> ...
> >>
> >>> +static irqreturn_t ipu6_buttress_call_isr(struct ipu6_bus_device *adev)
> >>> +{
> >>> +	irqreturn_t ret = IRQ_WAKE_THREAD;
> >>> +
> >>> +	if (!adev || !adev->auxdrv || !adev->auxdrv_data)
> >>> +		return IRQ_NONE;
> >>> +
> >>> +	if (adev->auxdrv_data->isr)
> >>> +		ret = adev->auxdrv_data->isr(adev);
> >>> +
> >>> +	if (ret == IRQ_WAKE_THREAD && !adev->auxdrv_data->isr_threaded)
> >>> +		ret = IRQ_NONE;
> >>> +
> >>> +	return ret;
> >>> +}
> >>> +
> >>> +irqreturn_t ipu6_buttress_isr(int irq, void *isp_ptr)
> >>> +{
> >>> +	struct ipu6_device *isp = isp_ptr;
> >>> +	struct ipu6_bus_device *adev[] = { isp->isys, isp->psys };
> >>> +	struct ipu6_buttress *b = &isp->buttress;
> >>> +	u32 reg_irq_sts = BUTTRESS_REG_ISR_STATUS;
> >>> +	irqreturn_t ret = IRQ_NONE;
> >>> +	u32 disable_irqs = 0;
> >>> +	u32 irq_status;
> >>> +	u32 i, count = 0;
> >>> +
> >>> +	pm_runtime_get_noresume(&isp->pdev->dev);
> >>> +
> >>> +	irq_status = readl(isp->base + reg_irq_sts);
> > 
> > A drive-by comment: this seems dodgy. If someone calls pm_runtime_put*()
> > just before the pm_runtime_get_noresume() above, the device won't be
> > resumed when reading the register, which will likely not lead to the
> > desired result.
> 
> Thanks for your review. 
> What do you think using pm_runtime_get_if_in_use() here?

This is the second discussion in a few weeks about this topic. See
https://lore.kernel.org/linux-media/60b3aec2-294f-4ab0-8a4b-0c32a52c84a0@ideasonboard.com

Sakari, should we try to handle this issue with shared helpers ?

> >>> +	if (!irq_status) {
> >>> +		pm_runtime_put_noidle(&isp->pdev->dev);
> >>> +		return IRQ_NONE;
> >>> +	}
> >>> +
> >>> +	do {
> >>> +		writel(irq_status, isp->base + BUTTRESS_REG_ISR_CLEAR);
> >>> +
> >>> +		for (i = 0; i < ARRAY_SIZE(ipu6_adev_irq_mask); i++) {
> >>> +			irqreturn_t r = ipu6_buttress_call_isr(adev[i]);
> >>> +
> >>> +			if (!(irq_status & ipu6_adev_irq_mask[i]))
> >>> +				continue;
> >>> +
> >>> +			if (r == IRQ_WAKE_THREAD) {
> >>> +				ret = IRQ_WAKE_THREAD;
> >>> +				disable_irqs |= ipu6_adev_irq_mask[i];
> >>> +			} else if (ret == IRQ_NONE && r == IRQ_HANDLED) {
> >>> +				ret = IRQ_HANDLED;
> >>> +			}
> >>> +		}
> >>
> >> It seems wrong to call the ISR for a adev[i] before checking the
> >> corresponding IRQ mask. If the mask is not set, the ISR is still
> >> called, but the result is thrown away.
> >>
> >> I started investigating this because I'm seeing "general protection
> >> fault, probably for non-canonical address 0x6b6b6b6b6b6b6b6b" in this
> >> function when unbinding the IPU4 driver.
> >>
> >> How do you ensure that the ISR is not called on a ipu6-bus device that
> >> has been deleted? Specifically in ipu6_pci_remove, ipu6_bus_del_devices
> >> is called before ipu6_buttress_exit (which disables buttress IRQs).
> >> Perhaps the above for loop should really be a "for each ipu6-bus
> >> device" loop?
> >>
> >>> +
> >>> +		if ((irq_status & BUTTRESS_EVENT) && ret == IRQ_NONE)
> >>> +			ret = IRQ_HANDLED;
> >>> +
> >>> +		if (irq_status & BUTTRESS_ISR_IPC_FROM_CSE_IS_WAITING) {
> >>> +			dev_dbg(&isp->pdev->dev,
> >>> +				"BUTTRESS_ISR_IPC_FROM_CSE_IS_WAITING\n");
> >>> +			ipu6_buttress_ipc_recv(isp, &b->cse, &b->cse.recv_data);
> >>> +			complete(&b->cse.recv_complete);
> >>> +		}
> >>> +
> >>> +		if (irq_status & BUTTRESS_ISR_IPC_FROM_ISH_IS_WAITING) {
> >>> +			dev_dbg(&isp->pdev->dev,
> >>> +				"BUTTRESS_ISR_IPC_FROM_ISH_IS_WAITING\n");
> >>> +			ipu6_buttress_ipc_recv(isp, &b->ish, &b->ish.recv_data);
> >>> +			complete(&b->ish.recv_complete);
> >>> +		}
> >>> +
> >>> +		if (irq_status & BUTTRESS_ISR_IPC_EXEC_DONE_BY_CSE) {
> >>> +			dev_dbg(&isp->pdev->dev,
> >>> +				"BUTTRESS_ISR_IPC_EXEC_DONE_BY_CSE\n");
> >>> +			complete(&b->cse.send_complete);
> >>> +		}
> >>> +
> >>> +		if (irq_status & BUTTRESS_ISR_IPC_EXEC_DONE_BY_ISH) {
> >>> +			dev_dbg(&isp->pdev->dev,
> >>> +				"BUTTRESS_ISR_IPC_EXEC_DONE_BY_CSE\n");
> >>> +			complete(&b->ish.send_complete);
> >>> +		}
> >>> +
> >>> +		if (irq_status & BUTTRESS_ISR_SAI_VIOLATION &&
> >>> +		    ipu6_buttress_get_secure_mode(isp))
> >>> +			dev_err(&isp->pdev->dev,
> >>> +				"BUTTRESS_ISR_SAI_VIOLATION\n");
> >>> +
> >>> +		if (irq_status & (BUTTRESS_ISR_IS_FATAL_MEM_ERR |
> >>> +				  BUTTRESS_ISR_PS_FATAL_MEM_ERR))
> >>> +			dev_err(&isp->pdev->dev,
> >>> +				"BUTTRESS_ISR_FATAL_MEM_ERR\n");
> >>> +
> >>> +		if (irq_status & BUTTRESS_ISR_UFI_ERROR)
> >>> +			dev_err(&isp->pdev->dev, "BUTTRESS_ISR_UFI_ERROR\n");
> >>> +
> >>> +		if (++count == BUTTRESS_MAX_CONSECUTIVE_IRQS) {
> >>> +			dev_err(&isp->pdev->dev, "too many consecutive IRQs\n");
> >>> +			ret = IRQ_NONE;
> >>> +			break;
> >>> +		}
> >>> +
> >>> +		irq_status = readl(isp->base + reg_irq_sts);
> >>> +	} while (irq_status);
> >>> +
> >>> +	if (disable_irqs)
> >>> +		writel(BUTTRESS_IRQS & ~disable_irqs,
> >>> +		       isp->base + BUTTRESS_REG_ISR_ENABLE);
> >>> +
> >>> +	pm_runtime_put(&isp->pdev->dev);
> >>> +
> >>> +	return ret;
> >>> +}
> >>
> >> ...

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 86+ messages in thread

* Re: [PATCH v2 14/15] Documentation: add Intel IPU6 ISYS driver admin-guide doc
  2023-10-25 12:15   ` Sakari Ailus
@ 2024-01-08  3:51     ` Bingbu Cao
  2024-01-08  9:14       ` Sakari Ailus
  0 siblings, 1 reply; 86+ messages in thread
From: Bingbu Cao @ 2024-01-08  3:51 UTC (permalink / raw)
  To: Sakari Ailus, bingbu.cao
  Cc: linux-media, laurent.pinchart, andriy.shevchenko, hdegoede,
	ilpo.jarvinen, andreaskleist, claus.stovgaard, tfiga,
	senozhatsky, tomi.valkeinen, tian.shu.qiu, hongju.wang

Sakari,

On 10/25/23 8:15 PM, Sakari Ailus wrote:
> Hi Bingbu,
> 
> On Tue, Oct 24, 2023 at 07:29:23PM +0800, bingbu.cao@intel.com wrote:
>> From: Bingbu Cao <bingbu.cao@intel.com>
>>
>> This document mainly describe the functionality of IPU6 and
>> IPU6 isys driver, and gives an example that how user can do
>> imaging capture with tools.
>>
>> Signed-off-by: Bingbu Cao <bingbu.cao@intel.com>
>> ---
>>  Documentation/admin-guide/media/ipu6-isys.rst |  159 +++
>>  .../admin-guide/media/ipu6_isys_graph.svg     |  338 +++++
>>  .../admin-guide/media/ipu6_isys_multi.svg     | 1124 +++++++++++++++++
>>  .../admin-guide/media/v4l-drivers.rst         |    1 +
>>  4 files changed, 1622 insertions(+)
>>  create mode 100644 Documentation/admin-guide/media/ipu6-isys.rst
>>  create mode 100644 Documentation/admin-guide/media/ipu6_isys_graph.svg
>>  create mode 100644 Documentation/admin-guide/media/ipu6_isys_multi.svg
>>
>> diff --git a/Documentation/admin-guide/media/ipu6-isys.rst b/Documentation/admin-guide/media/ipu6-isys.rst
>> new file mode 100644
>> index 000000000000..fb4d355e1522
>> --- /dev/null
>> +++ b/Documentation/admin-guide/media/ipu6-isys.rst
>> @@ -0,0 +1,159 @@
>> +.. SPDX-License-Identifier: GPL-2.0
>> +
>> +.. include:: <isonum.txt>
>> +
>> +===============================================================
>> +Intel Image Processing Unit 6 (IPU6) Input System driver
>> +===============================================================
> 
> Too many '='s.
> 
>> +
>> +Copyright |copy| 2023 Intel Corporation
>> +
>> +Introduction
>> +============
>> +
>> +This file documents the Intel IPU6 (6th generation Image Processing Unit)
>> +Input System (MIPI CSI2 receiver) drivers located under
>> +drivers/media/pci/intel/ipu6.
>> +
>> +The Intel IPU6 can be found in certain Intel Chipsets but not in all SKUs:
>> +
>> +* TigerLake
>> +* JasperLake
>> +* AlderLake
>> +* RaptorLake
>> +* MeteorLake
>> +
>> +Intel IPU6 is made up of two components - Input System (ISYS) and Processing
>> +System (PSYS).
>> +
>> +The Input System mainly works as MIPI CSI2 receiver which receives and
>> +processes the imaging data from the sensors and outputs the frames to memory.
>> +
>> +There are 2 driver modules - intel_ipu6 and intel_ipu6_isys. intel_ipu6 is an
>> +IPU6 common driver which does PCI configuration, firmware loading and parsing,
>> +firmware authentication, DMA mapping and IPU-MMU (internal Memory mapping Unit)
>> +configuration. intel_ipu6_isys implements V4L2, Media Controller and V4L2
>> +sub-device interfaces. The IPU6 ISYS driver supports camera sensors connected
>> +to the IPU6 ISYS through V4L2 sub-device sensor drivers.
>> +
>> +.. Note:: See Documentation/driver-api/media/drivers/ipu6.rst for more
>> +	  information about the IPU6 hardware.
> 
> A direct reference would be nice.
> 
>> +
>> +
>> +Input system driver
>> +===================
>> +
>> +The input System driver mainly configures CSI2 DPHY, constructs the firmware
>> +stream configuration, sends commands to firmware, gets response from hardware
>> +and firmware and then returns buffers to user.
>> +The ISYS is represented as several V4L2 sub-devices - 'Intel IPU6 CSI2 $port',
>> +which provide V4L2 subdev interfaces to the user space, there are also several
>> +video nodes for each CSI-2 stream capture - 'Intel IPU6 ISYS capture $num' which
>> +provide interface to user to set formats, queue buffers and streaming.
>> +
>> +.. kernel-figure::  ipu6_isys_graph.svg
>> +   :alt: ipu6 isys media graph without multiple streams support
>> +
>> +   ipu6 isys media graph without multiple streams support
>> +
>> +.. kernel-figure::  ipu6_isys_multi.svg
>> +   :alt: ipu6 isys media graph with multiple streams support
>> +
>> +   ipu6 isys media graph with multiple streams support
> 
> Is there a reason for having links from the CSI-2 receivers' source pads to
> multiple video nodes? Isn't a single one enough?
>

Sorry, I forgot to reply before. Firmware sees each MIPI VC as a single
stream, for multiple VCs case, SW need create multiple firmware streams.

<snip>

-- 
Best regards,
Bingbu Cao

^ permalink raw reply	[flat|nested] 86+ messages in thread

* Re: [PATCH v2 00/15] Intel IPU6 and IPU6 input system drivers
  2023-11-08 11:59 ` [PATCH v2 00/15] Intel IPU6 and IPU6 input system drivers Hans de Goede
                     ` (2 preceding siblings ...)
  2023-12-04 16:35   ` Hans de Goede
@ 2024-01-08  4:07   ` Bingbu Cao
  2024-01-08 14:23     ` Hans de Goede
  3 siblings, 1 reply; 86+ messages in thread
From: Bingbu Cao @ 2024-01-08  4:07 UTC (permalink / raw)
  To: Hans de Goede, bingbu.cao, linux-media, sakari.ailus, laurent.pinchart
  Cc: andriy.shevchenko, hdegoede, ilpo.jarvinen, andreaskleist,
	claus.stovgaard, tfiga, senozhatsky, tomi.valkeinen,
	tian.shu.qiu, hongju.wang

Hans,

On 11/8/23 7:59 PM, Hans de Goede wrote:
> Hi Bingbu,
> 
> On 10/24/23 13:29, bingbu.cao@intel.com wrote:
>> From: Bingbu Cao <bingbu.cao@intel.com>
>>
>> This patch series adds a driver for Intel IPU6 input system.
>> IPU6 is the sixth generation of Imaging Processing Unit, it is a PCI
>> device which can be found in some Intel Client Platforms. User can use
>> IPU6 to capture images from MIPI camera sensors.
>>
>> IPU6 has its own firmware which exposes ABIs to driver, and communicates
>> with CSE to do firmware authentication. IPU6 has its MMU hardware, so
>> the driver sets up a page table to allow IPU6 DMA to access the system
>> memory.
>>
>> IPU6 input system driver uses MC and V4L2 sub-device APIs besides V4L2.
> 
> I have been testing this on a TigerLake system, a Dell Latitude 9420
> with ov01a1s and the packed 10 bit bayer pixel fmt: V4L2_PIX_FMT_SGRBG10P,
> which libcamera together with (WIP) software debayer support picks
> by default does not work. There are many many CSI errors in dmesg
> and only the first 10 or so lines of the image show.
> 
> Disabling the packed format by removing it from ipu6_isys_pfmts[],
> making libcamera pick the unpacked (every 10 bits per pixel data
> stored in a 16 bit word in output buffer) fixes this.
> 
> Are the packed bayer formats supposed to work on Tiger Lake, or
> is this a known issue which Intel's own userspace stack avoids
> by always picking the unpacked format ?

I just tested the packed bayer on my device (ov01a10) and did not
observe the problems like yours, could you share the isys kernel log?

> 
> Regards,
> 
> Hans
> 
> 

-- 
Best regards,
Bingbu Cao

^ permalink raw reply	[flat|nested] 86+ messages in thread

* Re: [PATCH v2 06/15] media: intel/ipu6: add syscom interfaces between firmware and driver
  2024-01-03  9:25       ` Andreas Helbech Kleist
@ 2024-01-08  4:19         ` Bingbu Cao
  0 siblings, 0 replies; 86+ messages in thread
From: Bingbu Cao @ 2024-01-08  4:19 UTC (permalink / raw)
  To: Andreas Helbech Kleist, bingbu.cao, linux-media, sakari.ailus,
	laurent.pinchart
  Cc: andriy.shevchenko, hdegoede, ilpo.jarvinen, claus.stovgaard,
	tfiga, senozhatsky, tomi.valkeinen, tian.shu.qiu, hongju.wang

Andreas,

On 1/3/24 5:25 PM, Andreas Helbech Kleist wrote:
> Hi, 
> 
> On Thu, 2023-12-28 at 14:39 +0800, Bingbu Cao wrote:
>> Andreas,
>>
>> On 11/23/23 5:33 PM, Andreas Helbech Kleist wrote:
>>> Hi,
>>>
>>> On Tue, 2023-10-24 at 19:29 +0800, bingbu.cao@intel.com wrote:
>>>> From: Bingbu Cao <bingbu.cao@intel.com>
>>>>
>>>> Syscom is an inter-process(or) communication mechanism between an IPU
>>>> and host. Syscom uses message queues for message exchange between IPU
>>>> and host. Each message queue has its consumer and producer, host
>>>> queue
>>>> messages to firmware as the producer and then firmware to dequeue the
>>>> messages as consumer and vice versa. IPU and host use shared
>>>> registers
>>>> or memory to reside the read and write indices which are updated by
>>>> consumer and producer.
>>>>
>>>> Signed-off-by: Bingbu Cao <bingbu.cao@intel.com>
>>>> ---
>>>>  drivers/media/pci/intel/ipu6/ipu6-fw-com.c | 411
>>>> +++++++++++++++++++++
>>>>  drivers/media/pci/intel/ipu6/ipu6-fw-com.h |  47 +++
>>>>  2 files changed, 458 insertions(+)
>>>>  create mode 100644 drivers/media/pci/intel/ipu6/ipu6-fw-com.c
>>>>  create mode 100644 drivers/media/pci/intel/ipu6/ipu6-fw-com.h
>>> ...
>>>> +struct ipu6_fw_com_context {
>>>> +       struct ipu6_bus_device *adev;
>>>> +       void __iomem *dmem_addr;
>>>> +       int (*cell_ready)(struct ipu6_bus_device *adev);
>>>> +       void (*cell_start)(struct ipu6_bus_device *adev);
>>>
>>> Why are cell_ready and cell_start function pointers? They seem to
>>> always be set to query_sp and start_sp.
>>>
>>>> +
>>>> +       void *dma_buffer;
>>>> +       dma_addr_t dma_addr;
>>>> +       unsigned int dma_size;
>>>> +       unsigned long attrs;
>>>> +
>>>> +       struct ipu6_fw_sys_queue *input_queue;  /* array of host to
>>>> SP queues */
>>>> +       struct ipu6_fw_sys_queue *output_queue; /* array of SP to
>>>> host */
>>>> +
>>>> +       u32 config_vied_addr;
>>>> +
>>>> +       unsigned int buttress_boot_offset;
>>>> +       void __iomem *base_addr;
>>>> +};
>>>> +
>>>> +#define FW_COM_WR_REG 0
>>>> +#define FW_COM_RD_REG 4
>>>> +
>>>> +#define REGMEM_OFFSET 0
>>>> +#define TUNIT_MAGIC_PATTERN 0x5a5a5a5a
>>>> +
>>>> +enum regmem_id {
>>>> +       /* pass pkg_dir address to SPC in non-secure mode */
>>>> +       PKG_DIR_ADDR_REG = 0,
>>>> +       /* Tunit CFG blob for secure - provided by host.*/
>>>> +       TUNIT_CFG_DWR_REG = 1,
>>>> +       /* syscom commands - modified by the host */
>>>> +       SYSCOM_COMMAND_REG = 2,
>>>> +       /* Store interrupt status - updated by SP */
>>>> +       SYSCOM_IRQ_REG = 3,
>>>> +       /* first syscom queue pointer register */
>>>> +       SYSCOM_QPR_BASE_REG = 4
>>>> +};
>>>> +
>>>> +enum message_direction {
>>>> +       DIR_RECV = 0,
>>>> +       DIR_SEND
>>>> +};
>>>
>>> Not used?
>>
>> Ack, will remove.
>>
>>>
>>>
>>> ...
>>>> +struct ipu6_fw_com_cfg {
>>>> +       unsigned int num_input_queues;
>>>> +       unsigned int num_output_queues;
>>>> +       struct ipu6_fw_syscom_queue_config *input;
>>>> +       struct ipu6_fw_syscom_queue_config *output;
>>>> +
>>>> +       unsigned int dmem_addr;
>>>> +
>>>> +       /* firmware-specific configuration data */
>>>> +       void *specific_addr;
>>>> +       unsigned int specific_size;
>>>> +       int (*cell_ready)(struct ipu6_bus_device *adev);
>>>> +       void (*cell_start)(struct ipu6_bus_device *adev);
>>>> +
>>>> +       unsigned int buttress_boot_offset;
>>>
>>> This seems to always be 0 (set by ipu6-fw-isys.c), seems to be trivial
>>> to remove.
>>
>> All these fields are all used to extend for psys driver.
> 
> Then I suppose they can be added if a psys driver is submitted upstream
> at some point.

For IPU subsystem, the fwcom interface (IPU6 driver) is a common
interface for both isys and psys. It makes sense that making the
common interface scalable even it is only set by isys driver now.

> 
> Is is it the intention to submit a psys driver as well?

Yes, we are going to submit a IPU6 psys driver, but it will take more
time to get ready.

> 
> /Andreas
> 
> 

-- 
Best regards,
Bingbu Cao

^ permalink raw reply	[flat|nested] 86+ messages in thread

* Re: [PATCH v2 14/15] Documentation: add Intel IPU6 ISYS driver admin-guide doc
  2024-01-08  3:51     ` Bingbu Cao
@ 2024-01-08  9:14       ` Sakari Ailus
  2024-01-09  6:34         ` Bingbu Cao
  0 siblings, 1 reply; 86+ messages in thread
From: Sakari Ailus @ 2024-01-08  9:14 UTC (permalink / raw)
  To: Bingbu Cao
  Cc: bingbu.cao, linux-media, laurent.pinchart, andriy.shevchenko,
	hdegoede, ilpo.jarvinen, andreaskleist, claus.stovgaard, tfiga,
	senozhatsky, tomi.valkeinen, tian.shu.qiu, hongju.wang

Hi Bingbu,

On Mon, Jan 08, 2024 at 11:51:50AM +0800, Bingbu Cao wrote:
> Sakari,
> 
> On 10/25/23 8:15 PM, Sakari Ailus wrote:
> > Hi Bingbu,
> > 
> > On Tue, Oct 24, 2023 at 07:29:23PM +0800, bingbu.cao@intel.com wrote:
> >> From: Bingbu Cao <bingbu.cao@intel.com>
> >>
> >> This document mainly describe the functionality of IPU6 and
> >> IPU6 isys driver, and gives an example that how user can do
> >> imaging capture with tools.
> >>
> >> Signed-off-by: Bingbu Cao <bingbu.cao@intel.com>
> >> ---
> >>  Documentation/admin-guide/media/ipu6-isys.rst |  159 +++
> >>  .../admin-guide/media/ipu6_isys_graph.svg     |  338 +++++
> >>  .../admin-guide/media/ipu6_isys_multi.svg     | 1124 +++++++++++++++++
> >>  .../admin-guide/media/v4l-drivers.rst         |    1 +
> >>  4 files changed, 1622 insertions(+)
> >>  create mode 100644 Documentation/admin-guide/media/ipu6-isys.rst
> >>  create mode 100644 Documentation/admin-guide/media/ipu6_isys_graph.svg
> >>  create mode 100644 Documentation/admin-guide/media/ipu6_isys_multi.svg
> >>
> >> diff --git a/Documentation/admin-guide/media/ipu6-isys.rst b/Documentation/admin-guide/media/ipu6-isys.rst
> >> new file mode 100644
> >> index 000000000000..fb4d355e1522
> >> --- /dev/null
> >> +++ b/Documentation/admin-guide/media/ipu6-isys.rst
> >> @@ -0,0 +1,159 @@
> >> +.. SPDX-License-Identifier: GPL-2.0
> >> +
> >> +.. include:: <isonum.txt>
> >> +
> >> +===============================================================
> >> +Intel Image Processing Unit 6 (IPU6) Input System driver
> >> +===============================================================
> > 
> > Too many '='s.
> > 
> >> +
> >> +Copyright |copy| 2023 Intel Corporation
> >> +
> >> +Introduction
> >> +============
> >> +
> >> +This file documents the Intel IPU6 (6th generation Image Processing Unit)
> >> +Input System (MIPI CSI2 receiver) drivers located under
> >> +drivers/media/pci/intel/ipu6.
> >> +
> >> +The Intel IPU6 can be found in certain Intel Chipsets but not in all SKUs:
> >> +
> >> +* TigerLake
> >> +* JasperLake
> >> +* AlderLake
> >> +* RaptorLake
> >> +* MeteorLake
> >> +
> >> +Intel IPU6 is made up of two components - Input System (ISYS) and Processing
> >> +System (PSYS).
> >> +
> >> +The Input System mainly works as MIPI CSI2 receiver which receives and
> >> +processes the imaging data from the sensors and outputs the frames to memory.
> >> +
> >> +There are 2 driver modules - intel_ipu6 and intel_ipu6_isys. intel_ipu6 is an
> >> +IPU6 common driver which does PCI configuration, firmware loading and parsing,
> >> +firmware authentication, DMA mapping and IPU-MMU (internal Memory mapping Unit)
> >> +configuration. intel_ipu6_isys implements V4L2, Media Controller and V4L2
> >> +sub-device interfaces. The IPU6 ISYS driver supports camera sensors connected
> >> +to the IPU6 ISYS through V4L2 sub-device sensor drivers.
> >> +
> >> +.. Note:: See Documentation/driver-api/media/drivers/ipu6.rst for more
> >> +	  information about the IPU6 hardware.
> > 
> > A direct reference would be nice.
> > 
> >> +
> >> +
> >> +Input system driver
> >> +===================
> >> +
> >> +The input System driver mainly configures CSI2 DPHY, constructs the firmware
> >> +stream configuration, sends commands to firmware, gets response from hardware
> >> +and firmware and then returns buffers to user.
> >> +The ISYS is represented as several V4L2 sub-devices - 'Intel IPU6 CSI2 $port',
> >> +which provide V4L2 subdev interfaces to the user space, there are also several
> >> +video nodes for each CSI-2 stream capture - 'Intel IPU6 ISYS capture $num' which
> >> +provide interface to user to set formats, queue buffers and streaming.
> >> +
> >> +.. kernel-figure::  ipu6_isys_graph.svg
> >> +   :alt: ipu6 isys media graph without multiple streams support
> >> +
> >> +   ipu6 isys media graph without multiple streams support
> >> +
> >> +.. kernel-figure::  ipu6_isys_multi.svg
> >> +   :alt: ipu6 isys media graph with multiple streams support
> >> +
> >> +   ipu6 isys media graph with multiple streams support
> > 
> > Is there a reason for having links from the CSI-2 receivers' source pads to
> > multiple video nodes? Isn't a single one enough?
> >
> 
> Sorry, I forgot to reply before. Firmware sees each MIPI VC as a single
> stream, for multiple VCs case, SW need create multiple firmware streams.

Yes, I understand that, but this does not explain why you have multiple
links between the source pads and video nodes. You can only capture one
stream at a time from a video node. The user needs to select the correct
video node related to a source pad, not to pick a random video node and
then figure out which link to enable.

The media graph does look impressive though. :-)

-- 
Regards,

Sakari Ailus

^ permalink raw reply	[flat|nested] 86+ messages in thread

* Re: [PATCH v2 03/15] media: intel/ipu6: add IPU6 buttress interface driver
  2024-01-03 13:18       ` Bingbu Cao
@ 2024-01-08 10:27         ` Andreas Helbech Kleist
  0 siblings, 0 replies; 86+ messages in thread
From: Andreas Helbech Kleist @ 2024-01-08 10:27 UTC (permalink / raw)
  To: Bingbu Cao, bingbu.cao, linux-media, sakari.ailus, laurent.pinchart
  Cc: andriy.shevchenko, hdegoede, ilpo.jarvinen, claus.stovgaard,
	tfiga, senozhatsky, tomi.valkeinen, tian.shu.qiu, hongju.wang

Bingbu,

On Wed, 2024-01-03 at 21:18 +0800, Bingbu Cao wrote:
> Andreas,
> 
> On 1/3/24 9:11 PM, Bingbu Cao wrote:
> > Andreas,
> > 
> > On 1/3/24 5:22 PM, Andreas Helbech Kleist wrote:
> > > Hi Bingbu,
> > > 
> > > On Tue, 2023-10-24 at 19:29 +0800, bingbu.cao@intel.com wrote:
> > > > From: Bingbu Cao <bingbu.cao@intel.com>
> > > > 
> > > > The IPU6 buttress is the interface between IPU device (input system
> > > > and processing system) with rest of the SoC. It contains overall IPU
> > > > hardware control registers, these control registers are used as the
> > > > interfaces with the Intel Converged Security Engine and Punit to do
> > > > firmware authentication and power management.
> > > > 
> > > > Signed-off-by: Bingbu Cao <bingbu.cao@intel.com>
> > > > ---
> > > 
> > > ...
> > > 
> > > > +static irqreturn_t ipu6_buttress_call_isr(struct ipu6_bus_device *adev)
> > > > +{
> > > > +	irqreturn_t ret = IRQ_WAKE_THREAD;
> > > > +
> > > > +	if (!adev || !adev->auxdrv || !adev->auxdrv_data)
> > > > +		return IRQ_NONE;
> > > > +
> > > > +	if (adev->auxdrv_data->isr)
> > > > +		ret = adev->auxdrv_data->isr(adev);
> > > > +
> > > > +	if (ret == IRQ_WAKE_THREAD && !adev->auxdrv_data->isr_threaded)
> > > > +		ret = IRQ_NONE;
> > > > +
> > > > +	return ret;
> > > > +}
> > > > +
> > > > +irqreturn_t ipu6_buttress_isr(int irq, void *isp_ptr)
> > > > +{
> > > > +	struct ipu6_device *isp = isp_ptr;
> > > > +	struct ipu6_bus_device *adev[] = { isp->isys, isp->psys };
> > > > +	struct ipu6_buttress *b = &isp->buttress;
> > > > +	u32 reg_irq_sts = BUTTRESS_REG_ISR_STATUS;
> > > > +	irqreturn_t ret = IRQ_NONE;
> > > > +	u32 disable_irqs = 0;
> > > > +	u32 irq_status;
> > > > +	u32 i, count = 0;
> > > > +
> > > > +	pm_runtime_get_noresume(&isp->pdev->dev);
> > > > +
> > > > +	irq_status = readl(isp->base + reg_irq_sts);
> > > > +	if (!irq_status) {
> > > > +		pm_runtime_put_noidle(&isp->pdev->dev);
> > > > +		return IRQ_NONE;
> > > > +	}
> > > > +
> > > > +	do {
> > > > +		writel(irq_status, isp->base + BUTTRESS_REG_ISR_CLEAR);
> > > > +
> > > > +		for (i = 0; i < ARRAY_SIZE(ipu6_adev_irq_mask); i++) {
> > > > +			irqreturn_t r = ipu6_buttress_call_isr(adev[i]);
> > > > +
> > > > +			if (!(irq_status & ipu6_adev_irq_mask[i]))
> > > > +				continue;
> > > > +
> > > > +			if (r == IRQ_WAKE_THREAD) {
> > > > +				ret = IRQ_WAKE_THREAD;
> > > > +				disable_irqs |= ipu6_adev_irq_mask[i];
> > > > +			} else if (ret == IRQ_NONE && r == IRQ_HANDLED) {
> > > > +				ret = IRQ_HANDLED;
> > > > +			}
> > > > +		}
> > > 
> > > It seems wrong to call the ISR for a adev[i] before checking the
> > > corresponding IRQ mask. If the mask is not set, the ISR is still
> > > called, but the result is thrown away.
> > > 
> > > I started investigating this because I'm seeing "general protection
> > > fault, probably for non-canonical address 0x6b6b6b6b6b6b6b6b" in this
> > > function when unbinding the IPU4 driver.
> > > 
> > > How do you ensure that the ISR is not called on a ipu6-bus device that
> > > has been deleted? Specifically in ipu6_pci_remove, ipu6_bus_del_devices
> > > is called before ipu6_buttress_exit (which disables buttress IRQs).
> > > Perhaps the above for loop should really be a "for each ipu6-bus
> > > device" loop?
> > 
> > You are right, the buttress_exit() should be called before
> > ipu6_bus_del_devices().
> > 
> > Even with this, driver cannot guarantee that hardware irq was actually
> > disabled on IPU4. In some error cases, HW could report unmasked errors on
> > IPU4 (no such case on IPU6), if I remember correctly.

Thanks for the info, that's good to know.

> > Have you check whether devm_free_irq() in ipu6_pci_remove() can help you?

It looks like it might help.

> BTW, could you share the irq_status in your case?

Sorry, I don't have a log of it. And it seems to be a bit heisenbug-
like - it doesn't always happen when I add logging :/

/Andreas

^ permalink raw reply	[flat|nested] 86+ messages in thread

* Re: [PATCH v2 00/15] Intel IPU6 and IPU6 input system drivers
  2024-01-08  4:07   ` Bingbu Cao
@ 2024-01-08 14:23     ` Hans de Goede
  2024-01-09  3:51       ` Bingbu Cao
  0 siblings, 1 reply; 86+ messages in thread
From: Hans de Goede @ 2024-01-08 14:23 UTC (permalink / raw)
  To: Bingbu Cao, Hans de Goede, bingbu.cao, linux-media, sakari.ailus,
	laurent.pinchart
  Cc: andriy.shevchenko, ilpo.jarvinen, andreaskleist, claus.stovgaard,
	tfiga, senozhatsky, tomi.valkeinen, tian.shu.qiu, hongju.wang

Hi Bingbu,

On 1/8/24 05:07, Bingbu Cao wrote:
> Hans,
> 
> On 11/8/23 7:59 PM, Hans de Goede wrote:
>> Hi Bingbu,
>>
>> On 10/24/23 13:29, bingbu.cao@intel.com wrote:
>>> From: Bingbu Cao <bingbu.cao@intel.com>
>>>
>>> This patch series adds a driver for Intel IPU6 input system.
>>> IPU6 is the sixth generation of Imaging Processing Unit, it is a PCI
>>> device which can be found in some Intel Client Platforms. User can use
>>> IPU6 to capture images from MIPI camera sensors.
>>>
>>> IPU6 has its own firmware which exposes ABIs to driver, and communicates
>>> with CSE to do firmware authentication. IPU6 has its MMU hardware, so
>>> the driver sets up a page table to allow IPU6 DMA to access the system
>>> memory.
>>>
>>> IPU6 input system driver uses MC and V4L2 sub-device APIs besides V4L2.
>>
>> I have been testing this on a TigerLake system, a Dell Latitude 9420
>> with ov01a1s and the packed 10 bit bayer pixel fmt: V4L2_PIX_FMT_SGRBG10P,
>> which libcamera together with (WIP) software debayer support picks
>> by default does not work. There are many many CSI errors in dmesg
>> and only the first 10 or so lines of the image show.
>>
>> Disabling the packed format by removing it from ipu6_isys_pfmts[],
>> making libcamera pick the unpacked (every 10 bits per pixel data
>> stored in a 16 bit word in output buffer) fixes this.
>>
>> Are the packed bayer formats supposed to work on Tiger Lake, or
>> is this a known issue which Intel's own userspace stack avoids
>> by always picking the unpacked format ?
> 
> I just tested the packed bayer on my device (ov01a10) and did not
> observe the problems like yours, could you share the isys kernel log?

Was this on a device with a Tiger Lake CPU / plain ipu6 (not ipu6ep) ?

Regards,

Hans


^ permalink raw reply	[flat|nested] 86+ messages in thread

* Re: [PATCH v2 00/15] Intel IPU6 and IPU6 input system drivers
  2024-01-08 14:23     ` Hans de Goede
@ 2024-01-09  3:51       ` Bingbu Cao
  2024-01-15 13:13         ` Hans de Goede
  0 siblings, 1 reply; 86+ messages in thread
From: Bingbu Cao @ 2024-01-09  3:51 UTC (permalink / raw)
  To: Hans de Goede, Hans de Goede, bingbu.cao, linux-media,
	sakari.ailus, laurent.pinchart
  Cc: andriy.shevchenko, ilpo.jarvinen, andreaskleist, claus.stovgaard,
	tfiga, senozhatsky, tomi.valkeinen, tian.shu.qiu, hongju.wang


Hans,

On 1/8/24 10:23 PM, Hans de Goede wrote:
> Hi Bingbu,
> 
> On 1/8/24 05:07, Bingbu Cao wrote:
>> Hans,
>>
>> On 11/8/23 7:59 PM, Hans de Goede wrote:
>>> Hi Bingbu,
>>>
>>> On 10/24/23 13:29, bingbu.cao@intel.com wrote:
>>>> From: Bingbu Cao <bingbu.cao@intel.com>
>>>>
>>>> This patch series adds a driver for Intel IPU6 input system.
>>>> IPU6 is the sixth generation of Imaging Processing Unit, it is a PCI
>>>> device which can be found in some Intel Client Platforms. User can use
>>>> IPU6 to capture images from MIPI camera sensors.
>>>>
>>>> IPU6 has its own firmware which exposes ABIs to driver, and communicates
>>>> with CSE to do firmware authentication. IPU6 has its MMU hardware, so
>>>> the driver sets up a page table to allow IPU6 DMA to access the system
>>>> memory.
>>>>
>>>> IPU6 input system driver uses MC and V4L2 sub-device APIs besides V4L2.
>>>
>>> I have been testing this on a TigerLake system, a Dell Latitude 9420
>>> with ov01a1s and the packed 10 bit bayer pixel fmt: V4L2_PIX_FMT_SGRBG10P,
>>> which libcamera together with (WIP) software debayer support picks
>>> by default does not work. There are many many CSI errors in dmesg
>>> and only the first 10 or so lines of the image show.
>>>
>>> Disabling the packed format by removing it from ipu6_isys_pfmts[],
>>> making libcamera pick the unpacked (every 10 bits per pixel data
>>> stored in a 16 bit word in output buffer) fixes this.
>>>
>>> Are the packed bayer formats supposed to work on Tiger Lake, or
>>> is this a known issue which Intel's own userspace stack avoids
>>> by always picking the unpacked format ?
>>
>> I just tested the packed bayer on my device (ov01a10) and did not
>> observe the problems like yours, could you share the isys kernel log?
> 
> Was this on a device with a Tiger Lake CPU / plain ipu6 (not ipu6ep) ?

Sorry, it's ipu6ep.

I have no TigerLake so far.
The difference between ipu6 and ipu6ep is the MIPI CSI-2 D-PHY. But it
should not have no impact on the packed format.

Could you share the debug log on TigerLake?

> 
> Regards,
> 
> Hans
> 
> 

-- 
Best regards,
Bingbu Cao

^ permalink raw reply	[flat|nested] 86+ messages in thread

* Re: [PATCH v2 14/15] Documentation: add Intel IPU6 ISYS driver admin-guide doc
  2024-01-08  9:14       ` Sakari Ailus
@ 2024-01-09  6:34         ` Bingbu Cao
  2024-01-09  8:55           ` Sakari Ailus
  0 siblings, 1 reply; 86+ messages in thread
From: Bingbu Cao @ 2024-01-09  6:34 UTC (permalink / raw)
  To: Sakari Ailus
  Cc: bingbu.cao, linux-media, laurent.pinchart, andriy.shevchenko,
	hdegoede, ilpo.jarvinen, andreaskleist, claus.stovgaard, tfiga,
	senozhatsky, tomi.valkeinen, tian.shu.qiu, hongju.wang

Sakari,

On 1/8/24 5:14 PM, Sakari Ailus wrote:
> Hi Bingbu,
> 
> On Mon, Jan 08, 2024 at 11:51:50AM +0800, Bingbu Cao wrote:
>> Sakari,
>>
>> On 10/25/23 8:15 PM, Sakari Ailus wrote:
>>> Hi Bingbu,
>>>
>>> On Tue, Oct 24, 2023 at 07:29:23PM +0800, bingbu.cao@intel.com wrote:
>>>> From: Bingbu Cao <bingbu.cao@intel.com>
>>>>
>>>> This document mainly describe the functionality of IPU6 and
>>>> IPU6 isys driver, and gives an example that how user can do
>>>> imaging capture with tools.
>>>>
>>>> Signed-off-by: Bingbu Cao <bingbu.cao@intel.com>
>>>> ---
>>>>  Documentation/admin-guide/media/ipu6-isys.rst |  159 +++
>>>>  .../admin-guide/media/ipu6_isys_graph.svg     |  338 +++++
>>>>  .../admin-guide/media/ipu6_isys_multi.svg     | 1124 +++++++++++++++++
>>>>  .../admin-guide/media/v4l-drivers.rst         |    1 +
>>>>  4 files changed, 1622 insertions(+)
>>>>  create mode 100644 Documentation/admin-guide/media/ipu6-isys.rst
>>>>  create mode 100644 Documentation/admin-guide/media/ipu6_isys_graph.svg
>>>>  create mode 100644 Documentation/admin-guide/media/ipu6_isys_multi.svg
>>>>
>>>> diff --git a/Documentation/admin-guide/media/ipu6-isys.rst b/Documentation/admin-guide/media/ipu6-isys.rst
>>>> new file mode 100644
>>>> index 000000000000..fb4d355e1522
>>>> --- /dev/null
>>>> +++ b/Documentation/admin-guide/media/ipu6-isys.rst
>>>> @@ -0,0 +1,159 @@
>>>> +.. SPDX-License-Identifier: GPL-2.0
>>>> +
>>>> +.. include:: <isonum.txt>
>>>> +
>>>> +===============================================================
>>>> +Intel Image Processing Unit 6 (IPU6) Input System driver
>>>> +===============================================================
>>>
>>> Too many '='s.
>>>
>>>> +
>>>> +Copyright |copy| 2023 Intel Corporation
>>>> +
>>>> +Introduction
>>>> +============
>>>> +
>>>> +This file documents the Intel IPU6 (6th generation Image Processing Unit)
>>>> +Input System (MIPI CSI2 receiver) drivers located under
>>>> +drivers/media/pci/intel/ipu6.
>>>> +
>>>> +The Intel IPU6 can be found in certain Intel Chipsets but not in all SKUs:
>>>> +
>>>> +* TigerLake
>>>> +* JasperLake
>>>> +* AlderLake
>>>> +* RaptorLake
>>>> +* MeteorLake
>>>> +
>>>> +Intel IPU6 is made up of two components - Input System (ISYS) and Processing
>>>> +System (PSYS).
>>>> +
>>>> +The Input System mainly works as MIPI CSI2 receiver which receives and
>>>> +processes the imaging data from the sensors and outputs the frames to memory.
>>>> +
>>>> +There are 2 driver modules - intel_ipu6 and intel_ipu6_isys. intel_ipu6 is an
>>>> +IPU6 common driver which does PCI configuration, firmware loading and parsing,
>>>> +firmware authentication, DMA mapping and IPU-MMU (internal Memory mapping Unit)
>>>> +configuration. intel_ipu6_isys implements V4L2, Media Controller and V4L2
>>>> +sub-device interfaces. The IPU6 ISYS driver supports camera sensors connected
>>>> +to the IPU6 ISYS through V4L2 sub-device sensor drivers.
>>>> +
>>>> +.. Note:: See Documentation/driver-api/media/drivers/ipu6.rst for more
>>>> +	  information about the IPU6 hardware.
>>>
>>> A direct reference would be nice.
>>>
>>>> +
>>>> +
>>>> +Input system driver
>>>> +===================
>>>> +
>>>> +The input System driver mainly configures CSI2 DPHY, constructs the firmware
>>>> +stream configuration, sends commands to firmware, gets response from hardware
>>>> +and firmware and then returns buffers to user.
>>>> +The ISYS is represented as several V4L2 sub-devices - 'Intel IPU6 CSI2 $port',
>>>> +which provide V4L2 subdev interfaces to the user space, there are also several
>>>> +video nodes for each CSI-2 stream capture - 'Intel IPU6 ISYS capture $num' which
>>>> +provide interface to user to set formats, queue buffers and streaming.
>>>> +
>>>> +.. kernel-figure::  ipu6_isys_graph.svg
>>>> +   :alt: ipu6 isys media graph without multiple streams support
>>>> +
>>>> +   ipu6 isys media graph without multiple streams support
>>>> +
>>>> +.. kernel-figure::  ipu6_isys_multi.svg
>>>> +   :alt: ipu6 isys media graph with multiple streams support
>>>> +
>>>> +   ipu6 isys media graph with multiple streams support
>>>
>>> Is there a reason for having links from the CSI-2 receivers' source pads to
>>> multiple video nodes? Isn't a single one enough?
>>>
>>
>> Sorry, I forgot to reply before. Firmware sees each MIPI VC as a single
>> stream, for multiple VCs case, SW need create multiple firmware streams.
> 
> Yes, I understand that, but this does not explain why you have multiple
> links between the source pads and video nodes. You can only capture one
> stream at a time from a video node. The user needs to select the correct
> video node related to a source pad, not to pick a random video node and
> then figure out which link to enable.

The user can select any of the video nodes to one source pad.
This figure shows that user have the capability to link any source pad
to any of the video node (in dotted line). In reality, only 1 link is
active (solid line).

> 
> The media graph does look impressive though. :-)
> 

-- 
Best regards,
Bingbu Cao

^ permalink raw reply	[flat|nested] 86+ messages in thread

* Re: [PATCH v2 14/15] Documentation: add Intel IPU6 ISYS driver admin-guide doc
  2024-01-09  6:34         ` Bingbu Cao
@ 2024-01-09  8:55           ` Sakari Ailus
  2024-01-09 11:00             ` Bingbu Cao
  0 siblings, 1 reply; 86+ messages in thread
From: Sakari Ailus @ 2024-01-09  8:55 UTC (permalink / raw)
  To: Bingbu Cao
  Cc: bingbu.cao, linux-media, laurent.pinchart, andriy.shevchenko,
	hdegoede, ilpo.jarvinen, andreaskleist, claus.stovgaard, tfiga,
	senozhatsky, tomi.valkeinen, tian.shu.qiu, hongju.wang

Hi Bingbu,

On Tue, Jan 09, 2024 at 02:34:48PM +0800, Bingbu Cao wrote:
> Sakari,
> 
> On 1/8/24 5:14 PM, Sakari Ailus wrote:
> > Hi Bingbu,
> > 
> > On Mon, Jan 08, 2024 at 11:51:50AM +0800, Bingbu Cao wrote:
> >> Sakari,
> >>
> >> On 10/25/23 8:15 PM, Sakari Ailus wrote:
> >>> Hi Bingbu,
> >>>
> >>> On Tue, Oct 24, 2023 at 07:29:23PM +0800, bingbu.cao@intel.com wrote:
> >>>> From: Bingbu Cao <bingbu.cao@intel.com>
> >>>>
> >>>> This document mainly describe the functionality of IPU6 and
> >>>> IPU6 isys driver, and gives an example that how user can do
> >>>> imaging capture with tools.
> >>>>
> >>>> Signed-off-by: Bingbu Cao <bingbu.cao@intel.com>
> >>>> ---
> >>>>  Documentation/admin-guide/media/ipu6-isys.rst |  159 +++
> >>>>  .../admin-guide/media/ipu6_isys_graph.svg     |  338 +++++
> >>>>  .../admin-guide/media/ipu6_isys_multi.svg     | 1124 +++++++++++++++++
> >>>>  .../admin-guide/media/v4l-drivers.rst         |    1 +
> >>>>  4 files changed, 1622 insertions(+)
> >>>>  create mode 100644 Documentation/admin-guide/media/ipu6-isys.rst
> >>>>  create mode 100644 Documentation/admin-guide/media/ipu6_isys_graph.svg
> >>>>  create mode 100644 Documentation/admin-guide/media/ipu6_isys_multi.svg
> >>>>
> >>>> diff --git a/Documentation/admin-guide/media/ipu6-isys.rst b/Documentation/admin-guide/media/ipu6-isys.rst
> >>>> new file mode 100644
> >>>> index 000000000000..fb4d355e1522
> >>>> --- /dev/null
> >>>> +++ b/Documentation/admin-guide/media/ipu6-isys.rst
> >>>> @@ -0,0 +1,159 @@
> >>>> +.. SPDX-License-Identifier: GPL-2.0
> >>>> +
> >>>> +.. include:: <isonum.txt>
> >>>> +
> >>>> +===============================================================
> >>>> +Intel Image Processing Unit 6 (IPU6) Input System driver
> >>>> +===============================================================
> >>>
> >>> Too many '='s.
> >>>
> >>>> +
> >>>> +Copyright |copy| 2023 Intel Corporation
> >>>> +
> >>>> +Introduction
> >>>> +============
> >>>> +
> >>>> +This file documents the Intel IPU6 (6th generation Image Processing Unit)
> >>>> +Input System (MIPI CSI2 receiver) drivers located under
> >>>> +drivers/media/pci/intel/ipu6.
> >>>> +
> >>>> +The Intel IPU6 can be found in certain Intel Chipsets but not in all SKUs:
> >>>> +
> >>>> +* TigerLake
> >>>> +* JasperLake
> >>>> +* AlderLake
> >>>> +* RaptorLake
> >>>> +* MeteorLake
> >>>> +
> >>>> +Intel IPU6 is made up of two components - Input System (ISYS) and Processing
> >>>> +System (PSYS).
> >>>> +
> >>>> +The Input System mainly works as MIPI CSI2 receiver which receives and
> >>>> +processes the imaging data from the sensors and outputs the frames to memory.
> >>>> +
> >>>> +There are 2 driver modules - intel_ipu6 and intel_ipu6_isys. intel_ipu6 is an
> >>>> +IPU6 common driver which does PCI configuration, firmware loading and parsing,
> >>>> +firmware authentication, DMA mapping and IPU-MMU (internal Memory mapping Unit)
> >>>> +configuration. intel_ipu6_isys implements V4L2, Media Controller and V4L2
> >>>> +sub-device interfaces. The IPU6 ISYS driver supports camera sensors connected
> >>>> +to the IPU6 ISYS through V4L2 sub-device sensor drivers.
> >>>> +
> >>>> +.. Note:: See Documentation/driver-api/media/drivers/ipu6.rst for more
> >>>> +	  information about the IPU6 hardware.
> >>>
> >>> A direct reference would be nice.
> >>>
> >>>> +
> >>>> +
> >>>> +Input system driver
> >>>> +===================
> >>>> +
> >>>> +The input System driver mainly configures CSI2 DPHY, constructs the firmware
> >>>> +stream configuration, sends commands to firmware, gets response from hardware
> >>>> +and firmware and then returns buffers to user.
> >>>> +The ISYS is represented as several V4L2 sub-devices - 'Intel IPU6 CSI2 $port',
> >>>> +which provide V4L2 subdev interfaces to the user space, there are also several
> >>>> +video nodes for each CSI-2 stream capture - 'Intel IPU6 ISYS capture $num' which
> >>>> +provide interface to user to set formats, queue buffers and streaming.
> >>>> +
> >>>> +.. kernel-figure::  ipu6_isys_graph.svg
> >>>> +   :alt: ipu6 isys media graph without multiple streams support
> >>>> +
> >>>> +   ipu6 isys media graph without multiple streams support
> >>>> +
> >>>> +.. kernel-figure::  ipu6_isys_multi.svg
> >>>> +   :alt: ipu6 isys media graph with multiple streams support
> >>>> +
> >>>> +   ipu6 isys media graph with multiple streams support
> >>>
> >>> Is there a reason for having links from the CSI-2 receivers' source pads to
> >>> multiple video nodes? Isn't a single one enough?
> >>>
> >>
> >> Sorry, I forgot to reply before. Firmware sees each MIPI VC as a single
> >> stream, for multiple VCs case, SW need create multiple firmware streams.
> > 
> > Yes, I understand that, but this does not explain why you have multiple
> > links between the source pads and video nodes. You can only capture one
> > stream at a time from a video node. The user needs to select the correct
> > video node related to a source pad, not to pick a random video node and
> > then figure out which link to enable.
> 
> The user can select any of the video nodes to one source pad.
> This figure shows that user have the capability to link any source pad
> to any of the video node (in dotted line). In reality, only 1 link is
> active (solid line).

Yes, that's how it's currently implemented but I don't think there's really
a reason to do that. Could you remove all but one link to each video node?

-- 
Regards,

Sakari Ailus

^ permalink raw reply	[flat|nested] 86+ messages in thread

* Re: [PATCH v2 14/15] Documentation: add Intel IPU6 ISYS driver admin-guide doc
  2024-01-09  8:55           ` Sakari Ailus
@ 2024-01-09 11:00             ` Bingbu Cao
  0 siblings, 0 replies; 86+ messages in thread
From: Bingbu Cao @ 2024-01-09 11:00 UTC (permalink / raw)
  To: Sakari Ailus
  Cc: bingbu.cao, linux-media, laurent.pinchart, andriy.shevchenko,
	hdegoede, ilpo.jarvinen, andreaskleist, claus.stovgaard, tfiga,
	senozhatsky, tomi.valkeinen, tian.shu.qiu, hongju.wang

Sakari,

On 1/9/24 4:55 PM, Sakari Ailus wrote:
> Hi Bingbu,
> 
> On Tue, Jan 09, 2024 at 02:34:48PM +0800, Bingbu Cao wrote:
>> Sakari,
>>
>> On 1/8/24 5:14 PM, Sakari Ailus wrote:
>>> Hi Bingbu,
>>>
>>> On Mon, Jan 08, 2024 at 11:51:50AM +0800, Bingbu Cao wrote:
>>>> Sakari,
>>>>
>>>> On 10/25/23 8:15 PM, Sakari Ailus wrote:
>>>>> Hi Bingbu,
>>>>>
>>>>> On Tue, Oct 24, 2023 at 07:29:23PM +0800, bingbu.cao@intel.com wrote:
>>>>>> From: Bingbu Cao <bingbu.cao@intel.com>
>>>>>>
>>>>>> This document mainly describe the functionality of IPU6 and
>>>>>> IPU6 isys driver, and gives an example that how user can do
>>>>>> imaging capture with tools.
>>>>>>
>>>>>> Signed-off-by: Bingbu Cao <bingbu.cao@intel.com>
>>>>>> ---
>>>>>>  Documentation/admin-guide/media/ipu6-isys.rst |  159 +++
>>>>>>  .../admin-guide/media/ipu6_isys_graph.svg     |  338 +++++
>>>>>>  .../admin-guide/media/ipu6_isys_multi.svg     | 1124 +++++++++++++++++
>>>>>>  .../admin-guide/media/v4l-drivers.rst         |    1 +
>>>>>>  4 files changed, 1622 insertions(+)
>>>>>>  create mode 100644 Documentation/admin-guide/media/ipu6-isys.rst
>>>>>>  create mode 100644 Documentation/admin-guide/media/ipu6_isys_graph.svg
>>>>>>  create mode 100644 Documentation/admin-guide/media/ipu6_isys_multi.svg
>>>>>>
>>>>>> diff --git a/Documentation/admin-guide/media/ipu6-isys.rst b/Documentation/admin-guide/media/ipu6-isys.rst
>>>>>> new file mode 100644
>>>>>> index 000000000000..fb4d355e1522
>>>>>> --- /dev/null
>>>>>> +++ b/Documentation/admin-guide/media/ipu6-isys.rst
>>>>>> @@ -0,0 +1,159 @@
>>>>>> +.. SPDX-License-Identifier: GPL-2.0
>>>>>> +
>>>>>> +.. include:: <isonum.txt>
>>>>>> +
>>>>>> +===============================================================
>>>>>> +Intel Image Processing Unit 6 (IPU6) Input System driver
>>>>>> +===============================================================
>>>>>
>>>>> Too many '='s.
>>>>>
>>>>>> +
>>>>>> +Copyright |copy| 2023 Intel Corporation
>>>>>> +
>>>>>> +Introduction
>>>>>> +============
>>>>>> +
>>>>>> +This file documents the Intel IPU6 (6th generation Image Processing Unit)
>>>>>> +Input System (MIPI CSI2 receiver) drivers located under
>>>>>> +drivers/media/pci/intel/ipu6.
>>>>>> +
>>>>>> +The Intel IPU6 can be found in certain Intel Chipsets but not in all SKUs:
>>>>>> +
>>>>>> +* TigerLake
>>>>>> +* JasperLake
>>>>>> +* AlderLake
>>>>>> +* RaptorLake
>>>>>> +* MeteorLake
>>>>>> +
>>>>>> +Intel IPU6 is made up of two components - Input System (ISYS) and Processing
>>>>>> +System (PSYS).
>>>>>> +
>>>>>> +The Input System mainly works as MIPI CSI2 receiver which receives and
>>>>>> +processes the imaging data from the sensors and outputs the frames to memory.
>>>>>> +
>>>>>> +There are 2 driver modules - intel_ipu6 and intel_ipu6_isys. intel_ipu6 is an
>>>>>> +IPU6 common driver which does PCI configuration, firmware loading and parsing,
>>>>>> +firmware authentication, DMA mapping and IPU-MMU (internal Memory mapping Unit)
>>>>>> +configuration. intel_ipu6_isys implements V4L2, Media Controller and V4L2
>>>>>> +sub-device interfaces. The IPU6 ISYS driver supports camera sensors connected
>>>>>> +to the IPU6 ISYS through V4L2 sub-device sensor drivers.
>>>>>> +
>>>>>> +.. Note:: See Documentation/driver-api/media/drivers/ipu6.rst for more
>>>>>> +	  information about the IPU6 hardware.
>>>>>
>>>>> A direct reference would be nice.
>>>>>
>>>>>> +
>>>>>> +
>>>>>> +Input system driver
>>>>>> +===================
>>>>>> +
>>>>>> +The input System driver mainly configures CSI2 DPHY, constructs the firmware
>>>>>> +stream configuration, sends commands to firmware, gets response from hardware
>>>>>> +and firmware and then returns buffers to user.
>>>>>> +The ISYS is represented as several V4L2 sub-devices - 'Intel IPU6 CSI2 $port',
>>>>>> +which provide V4L2 subdev interfaces to the user space, there are also several
>>>>>> +video nodes for each CSI-2 stream capture - 'Intel IPU6 ISYS capture $num' which
>>>>>> +provide interface to user to set formats, queue buffers and streaming.
>>>>>> +
>>>>>> +.. kernel-figure::  ipu6_isys_graph.svg
>>>>>> +   :alt: ipu6 isys media graph without multiple streams support
>>>>>> +
>>>>>> +   ipu6 isys media graph without multiple streams support
>>>>>> +
>>>>>> +.. kernel-figure::  ipu6_isys_multi.svg
>>>>>> +   :alt: ipu6 isys media graph with multiple streams support
>>>>>> +
>>>>>> +   ipu6 isys media graph with multiple streams support
>>>>>
>>>>> Is there a reason for having links from the CSI-2 receivers' source pads to
>>>>> multiple video nodes? Isn't a single one enough?
>>>>>
>>>>
>>>> Sorry, I forgot to reply before. Firmware sees each MIPI VC as a single
>>>> stream, for multiple VCs case, SW need create multiple firmware streams.
>>>
>>> Yes, I understand that, but this does not explain why you have multiple
>>> links between the source pads and video nodes. You can only capture one
>>> stream at a time from a video node. The user needs to select the correct
>>> video node related to a source pad, not to pick a random video node and
>>> then figure out which link to enable.
>>
>> The user can select any of the video nodes to one source pad.
>> This figure shows that user have the capability to link any source pad
>> to any of the video node (in dotted line). In reality, only 1 link is
>> active (solid line).
> 
> Yes, that's how it's currently implemented but I don't think there's really
> a reason to do that. Could you remove all but one link to each video node?
>

Ack. I generated this graph by media-ctl and dot automatically.
Let me try to draw a new one.

Thanks!

-- 
Best regards,
Bingbu Cao

^ permalink raw reply	[flat|nested] 86+ messages in thread

* Re: [PATCH v2 11/15] media: intel/ipu6: input system video capture nodes
  2023-10-24 11:29 ` [PATCH v2 11/15] media: intel/ipu6: input system video capture nodes bingbu.cao
  2023-11-05 16:59   ` Hans de Goede
@ 2024-01-09 13:35   ` Andreas Helbech Kleist
  1 sibling, 0 replies; 86+ messages in thread
From: Andreas Helbech Kleist @ 2024-01-09 13:35 UTC (permalink / raw)
  To: bingbu.cao, linux-media, sakari.ailus, laurent.pinchart
  Cc: andriy.shevchenko, hdegoede, ilpo.jarvinen, claus.stovgaard,
	tfiga, senozhatsky, tomi.valkeinen, bingbu.cao, tian.shu.qiu,
	hongju.wang

Hi Bingbu,

On Tue, 2023-10-24 at 19:29 +0800, bingbu.cao@intel.com wrote:
> From: Bingbu Cao <bingbu.cao@intel.com>
> 
> Register v4l2 video device and setup the vb2 queue to
> support basic video capture. Video streaming callback
> will trigger the input system driver to construct a
> input system stream configuration for firmware based on
> data type and stream ID and then queue buffers to firmware
> to do capture.
> 
> Signed-off-by: Bingbu Cao <bingbu.cao@intel.com>
> ---

...

> +++ b/drivers/media/pci/intel/ipu6/ipu6-isys-video.c

...

> +static int video_release(struct file *file)
> +{
> +	return vb2_fop_release(file);
> +}

...


> +/*
> + * Do everything that's needed to initialise things related to video
> + * buffer queue, video node, and the related media entity. The caller
> + * is expected to assign isys field and set the name of the video
> + * device.
> + */
> +int ipu6_isys_video_init(struct ipu6_isys_video *av)
> +{
> +	struct v4l2_format format = {
> +		.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE,
> +		.fmt.pix_mp = {
> +			.width = 1920,
> +			.height = 1080,
> +		},
> +	};
> +	int ret;
> +
> +	mutex_init(&av->mutex);
> +	av->vdev.device_caps = V4L2_CAP_STREAMING | V4L2_CAP_IO_MC |
> +			       V4L2_CAP_VIDEO_CAPTURE_MPLANE;
> +	av->vdev.vfl_dir = VFL_DIR_RX;
> +
> +	ret = ipu6_isys_queue_init(&av->aq);
> +	if (ret)
> +		goto out_free_watermark;
> +
> +	av->pad.flags = MEDIA_PAD_FL_SINK | MEDIA_PAD_FL_MUST_CONNECT;
> +	ret = media_entity_pads_init(&av->vdev.entity, 1, &av->pad);
> +	if (ret)
> +		goto out_ipu6_isys_queue_cleanup;
> +
> +	av->vdev.entity.ops = &entity_ops;
> +	av->vdev.release = video_device_release_empty;
> +	av->vdev.fops = &isys_fops;
> +	av->vdev.v4l2_dev = &av->isys->v4l2_dev;
> +	if (!av->vdev.ioctl_ops)
> +		av->vdev.ioctl_ops = &ioctl_ops_mplane;
> +	av->vdev.queue = &av->aq.vbq;
> +	av->vdev.lock = &av->mutex;
> +
> +	ipu6_isys_video_try_fmt_vid_mplane(av, &format.fmt.pix_mp);
> +	av->mpix = format.fmt.pix_mp;
> +
> +	set_bit(V4L2_FL_USES_V4L2_FH, &av->vdev.flags);
> +	video_set_drvdata(&av->vdev, av);
> +
> +	ret = video_register_device(&av->vdev, VFL_TYPE_VIDEO, -1);
> +	if (ret)
> +		goto out_media_entity_cleanup;
> +
> +	return ret;
> +
> +out_media_entity_cleanup:
> +	video_unregister_device(&av->vdev);
> +	media_entity_cleanup(&av->vdev.entity);
> +
> +out_ipu6_isys_queue_cleanup:
> +	ipu6_isys_queue_cleanup(&av->aq);
> +
> +out_free_watermark:
> +	mutex_destroy(&av->mutex);
> +
> +	return ret;
> +}
> +
> +void ipu6_isys_video_cleanup(struct ipu6_isys_video *av)
> +{
> +	video_unregister_device(&av->vdev);
> +	media_entity_cleanup(&av->vdev.entity);
> +	mutex_destroy(&av->mutex);
> +	ipu6_isys_queue_cleanup(&av->aq);
> +}

I believe you should use vb2_video_unregister_device here instead of
video_unregister_device in both ipu6_isys_video_init and
ipu6_isys_video_cleanup, and remove the call to
ipu6_isys_queue_cleanup.

Commit f729ef5796d8 from Hans Verkuil that added
vb2_video_unregister_device states: "If a driver calls
(_)vb2_fop_release(), then such a driver should also call
vb2_video_unregister_device() instead of video_unregister_device().
This helper will call vb2_queue_release() if a filehandle is marked as
 owner of the queue. This ensures that at unregister time any streaming
 is cancelled and all buffers are returned to userspace."


In my testing, using IPU4, this prevents some crashes when unbinding
the PCI device while streaming.

/Andreas

^ permalink raw reply	[flat|nested] 86+ messages in thread

* Re: [PATCH v2 10/15] media: intel/ipu6: add input system driver
  2023-10-24 11:29 ` [PATCH v2 10/15] media: intel/ipu6: add input system driver bingbu.cao
  2023-11-23  9:37   ` Andreas Helbech Kleist
@ 2024-01-09 13:52   ` Andreas Helbech Kleist
  2024-01-10 12:47   ` Andreas Helbech Kleist
  2 siblings, 0 replies; 86+ messages in thread
From: Andreas Helbech Kleist @ 2024-01-09 13:52 UTC (permalink / raw)
  To: bingbu.cao, linux-media, sakari.ailus, laurent.pinchart
  Cc: andriy.shevchenko, hdegoede, ilpo.jarvinen, claus.stovgaard,
	tfiga, senozhatsky, tomi.valkeinen, bingbu.cao, tian.shu.qiu,
	hongju.wang

Hi Bingbu,

On Tue, 2023-10-24 at 19:29 +0800, bingbu.cao@intel.com wrote:
> From: Bingbu Cao <bingbu.cao@intel.com>
> 
> Input system driver do basic isys hardware setup and irq handling
> and work with fwnode and v4l2 to register the ISYS v4l2 devices.
> 
> Signed-off-by: Bingbu Cao <bingbu.cao@intel.com>
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> Reported-by: Claus Stovgaard <claus.stovgaard@gmail.com>
> ---
>  drivers/media/pci/intel/ipu6/ipu6-isys.c | 1345 ++++++++++++++++++++++
>  drivers/media/pci/intel/ipu6/ipu6-isys.h |  201 ++++
>  2 files changed, 1546 insertions(+)
>  create mode 100644 drivers/media/pci/intel/ipu6/ipu6-isys.c
>  create mode 100644 drivers/media/pci/intel/ipu6/ipu6-isys.h
> 
> diff --git a/drivers/media/pci/intel/ipu6/ipu6-isys.c b/drivers/media/pci/intel/ipu6/ipu6-isys.c

...

> +static void isys_notifier_cleanup(struct ipu6_isys *isys)
> +{
> +	v4l2_async_nf_unregister(&isys->notifier);
> +	v4l2_async_nf_cleanup(&isys->notifier);
> +}
> +
> +static int isys_register_devices(struct ipu6_isys *isys)
> +{
> +	struct device *dev = &isys->adev->auxdev.dev;
> +	struct pci_dev *pdev = isys->adev->isp->pdev;
> +	int ret;
> +
> +	isys->media_dev.dev = dev;
> +	media_device_pci_init(&isys->media_dev,
> +			      pdev, IPU6_MEDIA_DEV_MODEL_NAME);
> +
> +	strscpy(isys->v4l2_dev.name, isys->media_dev.model,
> +		sizeof(isys->v4l2_dev.name));
> +
> +	ret = media_device_register(&isys->media_dev);
> +	if (ret < 0)
> +		goto out_media_device_unregister;
> +
> +	isys->v4l2_dev.mdev = &isys->media_dev;
> +	isys->v4l2_dev.ctrl_handler = NULL;
> +
> +	ret = v4l2_device_register(dev->parent, &isys->v4l2_dev);
> +	if (ret < 0)
> +		goto out_media_device_unregister;
> +
> +	ret = isys_register_video_devices(isys);
> +	if (ret)
> +		goto out_v4l2_device_unregister;
> +
> +	ret = isys_csi2_register_subdevices(isys);
> +	if (ret)
> +		goto out_isys_unregister_video_device;
> +
> +	ret = isys_csi2_create_media_links(isys);
> +	if (ret)
> +		goto out_isys_unregister_subdevices;
> +
> +	ret = isys_notifier_init(isys);
> +	if (ret)
> +		goto out_isys_unregister_subdevices;
> +
> +	return 0;
> +
> +out_isys_unregister_subdevices:
> +	isys_csi2_unregister_subdevices(isys);
> +
> +out_isys_unregister_video_device:
> +	isys_unregister_video_devices(isys);
> +
> +out_v4l2_device_unregister:
> +	v4l2_device_unregister(&isys->v4l2_dev);
> +
> +out_media_device_unregister:
> +	media_device_unregister(&isys->media_dev);
> +	media_device_cleanup(&isys->media_dev);
> +
> +	dev_err(dev, "failed to register isys devices\n");
> +
> +	return ret;
> +}
> +
> +static void isys_unregister_devices(struct ipu6_isys *isys)
> +{
> +	isys_unregister_video_devices(isys);
> +	isys_csi2_unregister_subdevices(isys);
> +	v4l2_device_unregister(&isys->v4l2_dev);
> +	media_device_unregister(&isys->media_dev);
> +	media_device_cleanup(&isys->media_dev);
> +}

...

> +static void isys_remove(struct auxiliary_device *auxdev)
> +{
> +	struct ipu6_bus_device *adev = auxdev_to_adev(auxdev);
> +	struct ipu6_isys *isys = dev_get_drvdata(&auxdev->dev);
> +	struct ipu6_device *isp = adev->isp;
> +	struct isys_fw_msgs *fwmsg, *safe;
> +	unsigned int i;
> +
> +	for (i = 0; i < IPU6_ISYS_MAX_STREAMS; i++)
> +		mutex_destroy(&isys->streams[i].mutex);

In my testing with IPU4, I had to move these mutex_destroy's to the end
of isys_remove. If we're streaming, they are needed, presumably until
isys_unregister_devices is called.

> +
> +	list_for_each_entry_safe(fwmsg, safe, &isys->framebuflist, head)
> +		dma_free_attrs(&auxdev->dev, sizeof(struct isys_fw_msgs),
> +			       fwmsg, fwmsg->dma_addr, 0);
> +
> +	list_for_each_entry_safe(fwmsg, safe, &isys->framebuflist_fw, head)
> +		dma_free_attrs(&auxdev->dev, sizeof(struct isys_fw_msgs),
> +			       fwmsg, fwmsg->dma_addr, 0);
> +
> +	isys_iwake_watermark_cleanup(isys);
> +	isys_notifier_cleanup(isys);
> +	isys_unregister_devices(isys);

Again in IPU4 testing:
I get crashing in `stop_streaming` when unbinding during streaming. If
I move isys_unregister_devices before isys_notifier_cleanup, this no
longer happens.

> +
> +	cpu_latency_qos_remove_request(&isys->pm_qos);
> +
> +	if (!isp->secure_mode) {
> +		ipu6_cpd_free_pkg_dir(adev);
> +		ipu6_buttress_unmap_fw_image(adev, &adev->fw_sgt);
> +		release_firmware(adev->fw);
> +	}
> +
> +	mutex_destroy(&isys->stream_mutex);
> +	mutex_destroy(&isys->mutex);
> +}

/Andreas

^ permalink raw reply	[flat|nested] 86+ messages in thread

* Re: [PATCH v2 10/15] media: intel/ipu6: add input system driver
  2023-10-24 11:29 ` [PATCH v2 10/15] media: intel/ipu6: add input system driver bingbu.cao
  2023-11-23  9:37   ` Andreas Helbech Kleist
  2024-01-09 13:52   ` Andreas Helbech Kleist
@ 2024-01-10 12:47   ` Andreas Helbech Kleist
  2 siblings, 0 replies; 86+ messages in thread
From: Andreas Helbech Kleist @ 2024-01-10 12:47 UTC (permalink / raw)
  To: bingbu.cao, linux-media, sakari.ailus, laurent.pinchart
  Cc: andriy.shevchenko, hdegoede, ilpo.jarvinen, claus.stovgaard,
	tfiga, senozhatsky, tomi.valkeinen, bingbu.cao, tian.shu.qiu,
	hongju.wang

Hi Bingbu,

On Tue, 2023-10-24 at 19:29 +0800, bingbu.cao@intel.com wrote:
> From: Bingbu Cao <bingbu.cao@intel.com>
> 
> Input system driver do basic isys hardware setup and irq handling
> and work with fwnode and v4l2 to register the ISYS v4l2 devices.
> 
> Signed-off-by: Bingbu Cao <bingbu.cao@intel.com>
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> Reported-by: Claus Stovgaard <claus.stovgaard@gmail.com>
> ---
>  drivers/media/pci/intel/ipu6/ipu6-isys.c | 1345 ++++++++++++++++++++++
>  drivers/media/pci/intel/ipu6/ipu6-isys.h |  201 ++++
>  2 files changed, 1546 insertions(+)
>  create mode 100644 drivers/media/pci/intel/ipu6/ipu6-isys.c
>  create mode 100644 drivers/media/pci/intel/ipu6/ipu6-isys.h
> 
> diff --git a/drivers/media/pci/intel/ipu6/ipu6-isys.c b/drivers/media/pci/intel/ipu6/ipu6-isys.c
> new file mode 100644
> index 000000000000..2ea0c9ad6f16
> --- /dev/null
> +++ b/drivers/media/pci/intel/ipu6/ipu6-isys.c

...

> +struct isys_fw_msgs *ipu6_get_fw_msg_buf(struct ipu6_isys_stream *stream)
> +{
> +	struct ipu6_isys *isys = stream->isys;
> +	struct device *dev = &isys->adev->auxdev.dev;
> +	struct isys_fw_msgs *msg;
> +	unsigned long flags;
> +	int ret;
> +
> +	spin_lock_irqsave(&isys->listlock, flags);
> +	if (list_empty(&isys->framebuflist)) {
> +		spin_unlock_irqrestore(&isys->listlock, flags);
> +		dev_dbg(dev, "Frame list empty\n");
> +
> +		ret = alloc_fw_msg_bufs(isys, 5);
> +		if (ret < 0)
> +			return NULL;
> +
> +		spin_lock_irqsave(&isys->listlock, flags);
> +		if (list_empty(&isys->framebuflist)) {
> +			spin_unlock_irqrestore(&isys->listlock, flags);
> +			dev_err(dev, "Frame list empty\n");
> +			return NULL;
> +		}
> +	}
> +	msg = list_last_entry(&isys->framebuflist, struct isys_fw_msgs, head);
> +	list_move(&msg->head, &isys->framebuflist_fw);
> +	spin_unlock_irqrestore(&isys->listlock, flags);
> +	memset(&msg->fw_msg, 0, sizeof(msg->fw_msg));
> +
> +	return msg;
> +}
> +
> +void ipu6_cleanup_fw_msg_bufs(struct ipu6_isys *isys)
> +{
> +	struct isys_fw_msgs *fwmsg, *fwmsg0;
> +	unsigned long flags;
> +
> +	spin_lock_irqsave(&isys->listlock, flags);
> +	list_for_each_entry_safe(fwmsg, fwmsg0, &isys->framebuflist_fw, head)
> +		list_move(&fwmsg->head, &isys->framebuflist);
> +	spin_unlock_irqrestore(&isys->listlock, flags);
> +}
> +
> +void ipu6_put_fw_msg_buf(struct ipu6_isys *isys, u64 data)
> +{
> +	struct isys_fw_msgs *msg;
> +	unsigned long flags;
> +	u64 *ptr = (u64 *)data;
> +
> +	if (!ptr)
> +		return;
> +
> +	spin_lock_irqsave(&isys->listlock, flags);
> +	msg = container_of(ptr, struct isys_fw_msgs, fw_msg.dummy);

The dummy field is only there to do this container_of, but ptr and msg
point to the same address, since the union dummy is in is the first
field. So the container_of is exactly the same as simply casting the
pointer.

> +	list_move(&msg->head, &isys->framebuflist);
> +	spin_unlock_irqrestore(&isys->listlock, flags);
> +}
...

> +static int isys_isr_one(struct ipu6_bus_device *adev)
> +{
> +	struct ipu6_isys *isys = ipu6_bus_get_drvdata(adev);
> +	struct ipu6_fw_isys_resp_info_abi *resp;
> +	struct ipu6_isys_stream *stream;
> +	struct ipu6_isys_csi2 *csi2 = NULL;
> +	u64 ts;
> +
> +	if (!isys->fwcom)
> +		return 1;
> +
> +	resp = ipu6_fw_isys_get_resp(isys->fwcom, IPU6_BASE_MSG_RECV_QUEUES);
> +	if (!resp)
> +		return 1;
> +
> +	ts = (u64)resp->timestamp[1] << 32 | resp->timestamp[0];
> +
> +	if (resp->error_info.error == IPU6_FW_ISYS_ERROR_STREAM_IN_SUSPENSION)
> +		/* Suspension is kind of special case: not enough buffers */
> +		dev_dbg(&adev->auxdev.dev,
> +			"FW error resp %02d %s, stream %u, error SUSPENSION, details %d, timestamp 0x%16.16llx, pin %d\n",
> +			resp->type,
> +			fw_msg[resp_type_to_index(resp->type)].msg,
> +			resp->stream_handle,
> +			resp->error_info.error_details,
> +			fw_msg[resp_type_to_index(resp->type)].valid_ts ?
> +			ts : 0, resp->pin_id);
> +	else if (resp->error_info.error)
> +		dev_dbg(&adev->auxdev.dev,
> +			"FW error resp %02d %s, stream %u, error %d, details %d, timestamp 0x%16.16llx, pin %d\n",
> +			resp->type,
> +			fw_msg[resp_type_to_index(resp->type)].msg,
> +			resp->stream_handle,
> +			resp->error_info.error, resp->error_info.error_details,
> +			fw_msg[resp_type_to_index(resp->type)].valid_ts ?
> +			ts : 0, resp->pin_id);
> +	else
> +		dev_dbg(&adev->auxdev.dev,
> +			"FW resp %02d %s, stream %u, timestamp 0x%16.16llx, pin %d\n",
> +			resp->type,
> +			fw_msg[resp_type_to_index(resp->type)].msg,
> +			resp->stream_handle,
> +			fw_msg[resp_type_to_index(resp->type)].valid_ts ?
> +			ts : 0, resp->pin_id);
> +
> +	if (resp->stream_handle >= IPU6_ISYS_MAX_STREAMS) {
> +		dev_err(&adev->auxdev.dev, "bad stream handle %u\n",
> +			resp->stream_handle);
> +		goto leave;
> +	}
> +
> +	stream = ipu6_isys_query_stream_by_handle(isys, resp->stream_handle);
> +	if (!stream) {
> +		dev_err(&adev->auxdev.dev, "stream of stream_handle %u is unused\n",
> +			resp->stream_handle);
> +		goto leave;
> +	}
> +	stream->error = resp->error_info.error;
> +
> +	csi2 = ipu6_isys_subdev_to_csi2(stream->asd);
> +
> +	switch (resp->type) {
> +	case IPU6_FW_ISYS_RESP_TYPE_STREAM_OPEN_DONE:
> +		complete(&stream->stream_open_completion);
> +		break;
> +	case IPU6_FW_ISYS_RESP_TYPE_STREAM_CLOSE_ACK:
> +		complete(&stream->stream_close_completion);
> +		break;
> +	case IPU6_FW_ISYS_RESP_TYPE_STREAM_START_ACK:
> +		complete(&stream->stream_start_completion);
> +		break;
> +	case IPU6_FW_ISYS_RESP_TYPE_STREAM_START_AND_CAPTURE_ACK:
> +		complete(&stream->stream_start_completion);
> +		break;
> +	case IPU6_FW_ISYS_RESP_TYPE_STREAM_STOP_ACK:
> +		complete(&stream->stream_stop_completion);
> +		break;
> +	case IPU6_FW_ISYS_RESP_TYPE_STREAM_FLUSH_ACK:
> +		complete(&stream->stream_stop_completion);
> +		break;
> +	case IPU6_FW_ISYS_RESP_TYPE_PIN_DATA_READY:
> +		/*
> +		 * firmware only release the capture msg until software
> +		 * get pin_data_ready event
> +		 */
> +		ipu6_put_fw_msg_buf(ipu6_bus_get_drvdata(adev), resp->buf_id);

Is there a difference between IPU4 and IPU6 here? `buf_id` is always 0
on IPU4, so this doesn't release anything.

The PIN_DATA_READY response is sent multiple times per call to
ipu6_get_fw_msg_buf, so if I'm not mistaken, this can only be correct
if the firmware only sends the buf_id in one of the PIN_DATA_READY
responses.

The correct pointer to release seems to be passed in the various _ACK
responses on IPU4. I think it would make a lot more sense to release
the buffer there. But of course, if there is a bug in the firmware we
might have to do something else.

> +		if (resp->pin_id < IPU6_ISYS_OUTPUT_PINS &&
> +		    stream->output_pins[resp->pin_id].pin_ready)
> +			stream->output_pins[resp->pin_id].pin_ready(stream,
> +								    resp);
> +		else
> +			dev_warn(&adev->auxdev.dev,
> +				 "%d:No data pin ready handler for pin id %d\n",
> +				 resp->stream_handle, resp->pin_id);
> +		if (csi2)
> +			ipu6_isys_csi2_error(csi2);
> +
> +		break;
> +	case IPU6_FW_ISYS_RESP_TYPE_STREAM_CAPTURE_ACK:
> +		break;
> +	case IPU6_FW_ISYS_RESP_TYPE_STREAM_START_AND_CAPTURE_DONE:
> +	case IPU6_FW_ISYS_RESP_TYPE_STREAM_CAPTURE_DONE:
> +		break;
> +	case IPU6_FW_ISYS_RESP_TYPE_FRAME_SOF:
> +
> +		ipu6_isys_csi2_sof_event_by_stream(stream);
> +		stream->seq[stream->seq_index].sequence =
> +			atomic_read(&stream->sequence) - 1;
> +		stream->seq[stream->seq_index].timestamp = ts;
> +		dev_dbg(&adev->auxdev.dev,
> +			"sof: handle %d: (index %u), timestamp 0x%16.16llx\n",
> +			resp->stream_handle,
> +			stream->seq[stream->seq_index].sequence, ts);
> +		stream->seq_index = (stream->seq_index + 1)
> +			% IPU6_ISYS_MAX_PARALLEL_SOF;
> +		break;
> +	case IPU6_FW_ISYS_RESP_TYPE_FRAME_EOF:
> +		ipu6_isys_csi2_eof_event_by_stream(stream);
> +		dev_dbg(&adev->auxdev.dev,
> +			"eof: handle %d: (index %u), timestamp 0x%16.16llx\n",
> +			resp->stream_handle,
> +			stream->seq[stream->seq_index].sequence, ts);
> +		break;
> +	case IPU6_FW_ISYS_RESP_TYPE_STATS_DATA_READY:
> +		break;
> +	default:
> +		dev_err(&adev->auxdev.dev, "%d:unknown response type %u\n",
> +			resp->stream_handle, resp->type);
> +		break;
> +	}
> +
> +	ipu6_isys_put_stream(stream);
> +leave:
> +	ipu6_fw_isys_put_resp(isys->fwcom, IPU6_BASE_MSG_RECV_QUEUES);
> +	return 0;
> +}
...
> +++ b/drivers/media/pci/intel/ipu6/ipu6-isys.h
...
> +struct isys_fw_msgs {
> +	union {
> +		u64 dummy;
> +		struct ipu6_fw_isys_frame_buff_set_abi frame;
> +		struct ipu6_fw_isys_stream_cfg_data_abi stream;
> +	} fw_msg;
> +	struct list_head head;
> +	dma_addr_t dma_addr;
> +};
> +
> +struct isys_fw_msgs *ipu6_get_fw_msg_buf(struct ipu6_isys_stream *stream);
> +void ipu6_put_fw_msg_buf(struct ipu6_isys *isys, u64 data);

I it would be easier to understand these functions if the
ipu6_put_fw_msg_buf function, took the same type that the get function
returns. 

/Andreas


^ permalink raw reply	[flat|nested] 86+ messages in thread

* Re: [PATCH v2 00/15] Intel IPU6 and IPU6 input system drivers
  2024-01-09  3:51       ` Bingbu Cao
@ 2024-01-15 13:13         ` Hans de Goede
  0 siblings, 0 replies; 86+ messages in thread
From: Hans de Goede @ 2024-01-15 13:13 UTC (permalink / raw)
  To: Bingbu Cao, Hans de Goede, bingbu.cao, linux-media, sakari.ailus,
	laurent.pinchart
  Cc: andriy.shevchenko, ilpo.jarvinen, andreaskleist, claus.stovgaard,
	tfiga, senozhatsky, tomi.valkeinen, tian.shu.qiu, hongju.wang

Hi Bingbu,

On 1/9/24 04:51, Bingbu Cao wrote:
> 
> Hans,
> 
> On 1/8/24 10:23 PM, Hans de Goede wrote:
>> Hi Bingbu,
>>
>> On 1/8/24 05:07, Bingbu Cao wrote:
>>> Hans,
>>>
>>> On 11/8/23 7:59 PM, Hans de Goede wrote:
>>>> Hi Bingbu,
>>>>
>>>> On 10/24/23 13:29, bingbu.cao@intel.com wrote:
>>>>> From: Bingbu Cao <bingbu.cao@intel.com>
>>>>>
>>>>> This patch series adds a driver for Intel IPU6 input system.
>>>>> IPU6 is the sixth generation of Imaging Processing Unit, it is a PCI
>>>>> device which can be found in some Intel Client Platforms. User can use
>>>>> IPU6 to capture images from MIPI camera sensors.
>>>>>
>>>>> IPU6 has its own firmware which exposes ABIs to driver, and communicates
>>>>> with CSE to do firmware authentication. IPU6 has its MMU hardware, so
>>>>> the driver sets up a page table to allow IPU6 DMA to access the system
>>>>> memory.
>>>>>
>>>>> IPU6 input system driver uses MC and V4L2 sub-device APIs besides V4L2.
>>>>
>>>> I have been testing this on a TigerLake system, a Dell Latitude 9420
>>>> with ov01a1s and the packed 10 bit bayer pixel fmt: V4L2_PIX_FMT_SGRBG10P,
>>>> which libcamera together with (WIP) software debayer support picks
>>>> by default does not work. There are many many CSI errors in dmesg
>>>> and only the first 10 or so lines of the image show.
>>>>
>>>> Disabling the packed format by removing it from ipu6_isys_pfmts[],
>>>> making libcamera pick the unpacked (every 10 bits per pixel data
>>>> stored in a 16 bit word in output buffer) fixes this.
>>>>
>>>> Are the packed bayer formats supposed to work on Tiger Lake, or
>>>> is this a known issue which Intel's own userspace stack avoids
>>>> by always picking the unpacked format ?
>>>
>>> I just tested the packed bayer on my device (ov01a10) and did not
>>> observe the problems like yours, could you share the isys kernel log?
>>
>> Was this on a device with a Tiger Lake CPU / plain ipu6 (not ipu6ep) ?
> 
> Sorry, it's ipu6ep.
> 
> I have no TigerLake so far.
> The difference between ipu6 and ipu6ep is the MIPI CSI-2 D-PHY. But it
> should not have no impact on the packed format.
> 
> Could you share the debug log on TigerLake?

I don't have access to the machine atm, but I should get it back
in 2 weeks from now. I'll email you debug logs then.

Regards,

Hans


^ permalink raw reply	[flat|nested] 86+ messages in thread

* Re: [PATCH v2 00/15] Intel IPU6 and IPU6 input system drivers
  2023-10-24 11:29 [PATCH v2 00/15] Intel IPU6 and IPU6 input system drivers bingbu.cao
                   ` (15 preceding siblings ...)
  2023-11-08 11:59 ` [PATCH v2 00/15] Intel IPU6 and IPU6 input system drivers Hans de Goede
@ 2024-02-07  7:00 ` Sakari Ailus
  2024-02-14  9:28   ` Sakari Ailus
  16 siblings, 1 reply; 86+ messages in thread
From: Sakari Ailus @ 2024-02-07  7:00 UTC (permalink / raw)
  To: bingbu.cao
  Cc: linux-media, laurent.pinchart, andriy.shevchenko, hdegoede,
	ilpo.jarvinen, andreaskleist, claus.stovgaard, tfiga,
	senozhatsky, tomi.valkeinen, bingbu.cao, tian.shu.qiu,
	hongju.wang

Hi folks,

On Tue, Oct 24, 2023 at 07:29:09PM +0800, bingbu.cao@intel.com wrote:
> From: Bingbu Cao <bingbu.cao@intel.com>
> 
> This patch series adds a driver for Intel IPU6 input system.
> IPU6 is the sixth generation of Imaging Processing Unit, it is a PCI
> device which can be found in some Intel Client Platforms. User can use
> IPU6 to capture images from MIPI camera sensors.
> 
> IPU6 has its own firmware which exposes ABIs to driver, and communicates
> with CSE to do firmware authentication. IPU6 has its MMU hardware, so
> the driver sets up a page table to allow IPU6 DMA to access the system
> memory.
> 
> IPU6 input system driver uses MC and V4L2 sub-device APIs besides V4L2.

I've made some changes on top of this (besides some done by Bingbu). I've
pushed the current patches here
<URL:https://git.linuxtv.org/sailus/media_tree.git/log/?h=ipu6>. What's
changed:

- CSI-2 port address calculation simplification.

- Tested (and fixed) driver probing on a Dell XPS 9315 that has IVSC and
  Linux camera description that ignores the IVSC. This works if the
  intel-ipu6 driver is first removed and then re-probed. I'm not quite sure
  why it doesn't re-probe on its own yet. I haven't tried streaming yet.

- The patches are on top of the metadata set. If you want to try without,
  just drop the metadata patches (and the last functional driver patch). It
  might compile. I'll test this soon, too.

So overall there's some progress but work remains to do. I'll post the IVSC
and ACPI patches after a little bit more testing.

-- 
Regards,

Sakari Ailus

^ permalink raw reply	[flat|nested] 86+ messages in thread

* Re: [PATCH v2 00/15] Intel IPU6 and IPU6 input system drivers
  2024-02-07  7:00 ` Sakari Ailus
@ 2024-02-14  9:28   ` Sakari Ailus
  0 siblings, 0 replies; 86+ messages in thread
From: Sakari Ailus @ 2024-02-14  9:28 UTC (permalink / raw)
  To: bingbu.cao
  Cc: linux-media, laurent.pinchart, andriy.shevchenko, hdegoede,
	ilpo.jarvinen, andreaskleist, claus.stovgaard, tfiga,
	senozhatsky, tomi.valkeinen, bingbu.cao, tian.shu.qiu,
	hongju.wang

On Wed, Feb 07, 2024 at 07:00:27AM +0000, Sakari Ailus wrote:
> Hi folks,
> 
> On Tue, Oct 24, 2023 at 07:29:09PM +0800, bingbu.cao@intel.com wrote:
> > From: Bingbu Cao <bingbu.cao@intel.com>
> > 
> > This patch series adds a driver for Intel IPU6 input system.
> > IPU6 is the sixth generation of Imaging Processing Unit, it is a PCI
> > device which can be found in some Intel Client Platforms. User can use
> > IPU6 to capture images from MIPI camera sensors.
> > 
> > IPU6 has its own firmware which exposes ABIs to driver, and communicates
> > with CSE to do firmware authentication. IPU6 has its MMU hardware, so
> > the driver sets up a page table to allow IPU6 DMA to access the system
> > memory.
> > 
> > IPU6 input system driver uses MC and V4L2 sub-device APIs besides V4L2.
> 
> I've made some changes on top of this (besides some done by Bingbu). I've
> pushed the current patches here
> <URL:https://git.linuxtv.org/sailus/media_tree.git/log/?h=ipu6>. What's
> changed:
> 
> - CSI-2 port address calculation simplification.
> 
> - Tested (and fixed) driver probing on a Dell XPS 9315 that has IVSC and
>   Linux camera description that ignores the IVSC. This works if the
>   intel-ipu6 driver is first removed and then re-probed. I'm not quite sure
>   why it doesn't re-probe on its own yet. I haven't tried streaming yet.
> 
> - The patches are on top of the metadata set. If you want to try without,
>   just drop the metadata patches (and the last functional driver patch). It
>   might compile. I'll test this soon, too.
> 
> So overall there's some progress but work remains to do. I'll post the IVSC
> and ACPI patches after a little bit more testing.

I've added further patches to the branch and dropped some... Capturing
works now on Dell XPS 9315 with ov01a10 without issues (AFAICT), and that
pipeline includes IVSC. I'm upstreaming the un-media patches to the
respective trees so some of this is going to take a while to merged back to
the media tree.

I've also removed the massive number of extra links from the CSI-2 receiver
subdevs and video nodes. This part remains untested though, the ov01a10
sensor doesn't have support for embedded data (!).

Just FYI.

-- 
Sakari Ailus

^ permalink raw reply	[flat|nested] 86+ messages in thread

end of thread, other threads:[~2024-02-14  9:28 UTC | newest]

Thread overview: 86+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-24 11:29 [PATCH v2 00/15] Intel IPU6 and IPU6 input system drivers bingbu.cao
2023-10-24 11:29 ` [PATCH v2 01/15] media: intel/ipu6: add Intel IPU6 PCI device driver bingbu.cao
2023-10-25 12:39   ` Andreas Helbech Kleist
2023-10-25 20:03     ` Andy Shevchenko
2023-11-05 14:43   ` Hans de Goede
2023-11-06  8:55     ` Bingbu Cao
2023-11-08 11:25   ` Hans de Goede
2023-11-08 13:24     ` Andy Shevchenko
2023-11-08 14:10     ` Andreas Helbech Kleist
2023-11-08 14:18       ` Cao, Bingbu
2023-11-17 18:43       ` Hans de Goede
2023-11-17 21:18         ` Andy Shevchenko
2023-11-20  3:54           ` Bingbu Cao
2023-11-23  9:17   ` Andreas Helbech Kleist
2023-10-24 11:29 ` [PATCH v2 02/15] media: intel/ipu6: add IPU auxiliary devices bingbu.cao
2023-10-24 12:58   ` Andy Shevchenko
2023-10-25  7:14     ` Bingbu Cao
2023-10-25  8:35       ` Hans de Goede
2023-10-25 19:57       ` Andy Shevchenko
2023-10-26  3:04         ` Bingbu Cao
2023-10-24 11:29 ` [PATCH v2 03/15] media: intel/ipu6: add IPU6 buttress interface driver bingbu.cao
2024-01-03  9:22   ` Andreas Helbech Kleist
2024-01-03 10:49     ` Laurent Pinchart
2024-01-03 13:33       ` Bingbu Cao
2024-01-03 14:01         ` Laurent Pinchart
2024-01-03 13:11     ` Bingbu Cao
2024-01-03 13:18       ` Bingbu Cao
2024-01-08 10:27         ` Andreas Helbech Kleist
2023-10-24 11:29 ` [PATCH v2 04/15] media: intel/ipu6: CPD parsing for get firmware components bingbu.cao
2023-10-24 11:29 ` [PATCH v2 05/15] media: intel/ipu6: add IPU6 DMA mapping API and MMU table bingbu.cao
2023-12-06 14:53   ` Andreas Helbech Kleist
2023-10-24 11:29 ` [PATCH v2 06/15] media: intel/ipu6: add syscom interfaces between firmware and driver bingbu.cao
2023-11-23  9:33   ` Andreas Helbech Kleist
2023-12-28  6:39     ` Bingbu Cao
2024-01-03  9:25       ` Andreas Helbech Kleist
2024-01-08  4:19         ` Bingbu Cao
2023-10-24 11:29 ` [PATCH v2 07/15] media: intel/ipu6: input system ABI " bingbu.cao
2023-10-24 11:29 ` [PATCH v2 08/15] media: intel/ipu6: add IPU6 CSI2 receiver v4l2 sub-device bingbu.cao
2023-11-08 11:25   ` Andreas Helbech Kleist
2023-11-08 14:50     ` Cao, Bingbu
2023-11-08 14:51       ` Bingbu Cao
2023-11-08 15:00       ` Andreas Helbech Kleist
2023-11-08 15:32         ` andriy.shevchenko
2023-11-09  1:48           ` Bingbu Cao
2023-10-24 11:29 ` [PATCH v2 09/15] media: intel/ipu6: add the CSI2 DPHY implementation bingbu.cao
2023-10-24 11:29 ` [PATCH v2 10/15] media: intel/ipu6: add input system driver bingbu.cao
2023-11-23  9:37   ` Andreas Helbech Kleist
2024-01-09 13:52   ` Andreas Helbech Kleist
2024-01-10 12:47   ` Andreas Helbech Kleist
2023-10-24 11:29 ` [PATCH v2 11/15] media: intel/ipu6: input system video capture nodes bingbu.cao
2023-11-05 16:59   ` Hans de Goede
2023-11-06  9:18     ` Bingbu Cao
2023-11-06 11:17       ` Andy Shevchenko
2023-12-05  9:15         ` Bingbu Cao
2024-01-09 13:35   ` Andreas Helbech Kleist
2023-10-24 11:29 ` [PATCH v2 12/15] media: add Kconfig and Makefile for IPU6 bingbu.cao
2023-10-24 13:04   ` Andy Shevchenko
2023-10-25  8:43     ` Bingbu Cao
2023-10-25 20:00       ` Andy Shevchenko
2023-10-25 12:21     ` Sakari Ailus
2023-10-25 20:01       ` Andy Shevchenko
2023-10-24 11:29 ` [PATCH v2 13/15] MAINTAINERS: add maintainers for Intel IPU6 input system driver bingbu.cao
2023-10-24 11:29 ` [PATCH v2 14/15] Documentation: add Intel IPU6 ISYS driver admin-guide doc bingbu.cao
2023-10-25 12:15   ` Sakari Ailus
2024-01-08  3:51     ` Bingbu Cao
2024-01-08  9:14       ` Sakari Ailus
2024-01-09  6:34         ` Bingbu Cao
2024-01-09  8:55           ` Sakari Ailus
2024-01-09 11:00             ` Bingbu Cao
2023-10-24 11:29 ` [PATCH v2 15/15] Documentation: add documentation of Intel IPU6 driver and hardware overview bingbu.cao
2023-10-25 12:09   ` Sakari Ailus
2023-10-26  3:38     ` Bingbu Cao
2023-10-26  5:27       ` Sakari Ailus
2023-11-08 11:59 ` [PATCH v2 00/15] Intel IPU6 and IPU6 input system drivers Hans de Goede
2023-11-08 14:31   ` Cao, Bingbu
2023-11-08 15:15     ` Hans de Goede
2023-11-10 12:04   ` Hans de Goede
2023-11-13 10:37     ` Bingbu Cao
2023-12-04 16:35   ` Hans de Goede
2023-12-04 16:49     ` Andy Shevchenko
2024-01-08  4:07   ` Bingbu Cao
2024-01-08 14:23     ` Hans de Goede
2024-01-09  3:51       ` Bingbu Cao
2024-01-15 13:13         ` Hans de Goede
2024-02-07  7:00 ` Sakari Ailus
2024-02-14  9:28   ` Sakari Ailus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).