Intel IPU6 and IPU6 input system drivers
Subsystems (2)
cover Intel IPU6 and IPU6 input system drivers
From: Bingbu Cao <[email protected]>
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.
---
TODOs:
- Add support for multiplexed streams
- Add firmware CSI2 lanes configuration verification and documentation
---
Bingbu Cao (13):
media: intel/ipu6: add Intel IPU6 PCI device driver
media: intel/ipu6: add IPU virtual bus driver
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
MAINTAINERS | 10 + drivers/media/pci/Kconfig | 1 + drivers/media/pci/intel/Makefile | 3 +- drivers/media/pci/intel/ipu6/Kconfig | 15 + drivers/media/pci/intel/ipu6/Makefile | 23 + drivers/media/pci/intel/ipu6/ipu6-bus.c | 263 ++++ drivers/media/pci/intel/ipu6/ipu6-bus.h | 69 + drivers/media/pci/intel/ipu6/ipu6-buttress.c | 916 ++++++++++++ drivers/media/pci/intel/ipu6/ipu6-buttress.h | 109 ++ drivers/media/pci/intel/ipu6/ipu6-cpd.c | 359 +++++ drivers/media/pci/intel/ipu6/ipu6-cpd.h | 107 ++ drivers/media/pci/intel/ipu6/ipu6-dma.c | 497 ++++++ drivers/media/pci/intel/ipu6/ipu6-dma.h | 19 + drivers/media/pci/intel/ipu6/ipu6-fw-com.c | 417 ++++++ drivers/media/pci/intel/ipu6/ipu6-fw-com.h | 47 + drivers/media/pci/intel/ipu6/ipu6-fw-isys.c | 566 +++++++ drivers/media/pci/intel/ipu6/ipu6-fw-isys.h | 574 +++++++ drivers/media/pci/intel/ipu6/ipu6-isys-csi2.c | 575 +++++++ drivers/media/pci/intel/ipu6/ipu6-isys-csi2.h | 75 + .../media/pci/intel/ipu6/ipu6-isys-dwc-phy.c | 549 +++++++ .../media/pci/intel/ipu6/ipu6-isys-jsl-phy.c | 245 +++ .../media/pci/intel/ipu6/ipu6-isys-mcd-phy.c | 735 +++++++++ drivers/media/pci/intel/ipu6/ipu6-isys-phy.h | 24 + .../media/pci/intel/ipu6/ipu6-isys-queue.c | 869 +++++++++++ .../media/pci/intel/ipu6/ipu6-isys-queue.h | 97 ++ .../media/pci/intel/ipu6/ipu6-isys-subdev.c | 309 ++++ .../media/pci/intel/ipu6/ipu6-isys-subdev.h | 70 + .../media/pci/intel/ipu6/ipu6-isys-video.c | 1132 ++++++++++++++ .../media/pci/intel/ipu6/ipu6-isys-video.h | 120 ++ drivers/media/pci/intel/ipu6/ipu6-isys.c | 1326 +++++++++++++++++ drivers/media/pci/intel/ipu6/ipu6-isys.h | 190 +++ drivers/media/pci/intel/ipu6/ipu6-mmu.c | 833 +++++++++++ drivers/media/pci/intel/ipu6/ipu6-mmu.h | 65 + .../intel/ipu6/ipu6-platform-buttress-regs.h | 231 +++ .../intel/ipu6/ipu6-platform-isys-csi2-reg.h | 187 +++ .../media/pci/intel/ipu6/ipu6-platform-regs.h | 177 +++ drivers/media/pci/intel/ipu6/ipu6-platform.h | 31 + drivers/media/pci/intel/ipu6/ipu6.c | 969 ++++++++++++ drivers/media/pci/intel/ipu6/ipu6.h | 344 +++++ 39 files changed, 13147 insertions(+), 1 deletion(-) 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-phy.h 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-platform.h create mode 100644 drivers/media/pci/intel/ipu6/ipu6.c create mode 100644 drivers/media/pci/intel/ipu6/ipu6.h
Signature · 1 line
2.39.1
RFC PATCH 1/14 media: intel/ipu6: add Intel IPU6 PCI device driver
From: Bingbu Cao <[email protected]>
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.
--- .../media/pci/intel/ipu6/ipu6-platform-regs.h | 177 ++++ drivers/media/pci/intel/ipu6/ipu6-platform.h | 31 + drivers/media/pci/intel/ipu6/ipu6.c | 969 ++++++++++++++++++ drivers/media/pci/intel/ipu6/ipu6.h | 344 +++++++ 4 files changed, 1521 insertions(+) create mode 100644 drivers/media/pci/intel/ipu6/ipu6-platform-regs.h create mode 100644 drivers/media/pci/intel/ipu6/ipu6-platform.h create mode 100644 drivers/media/pci/intel/ipu6/ipu6.c create mode 100644 drivers/media/pci/intel/ipu6/ipu6.h
drivers/media/pci/intel/ipu6/ipu6-platform-regs.h new file +177 -0
@@ -0,0 +1,177 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* Copyright (C) 2018 - 2023 Intel Corporation */ + +#ifndef IPU6_PLATFORM_REGS_H +#define IPU6_PLATFORM_REGS_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) (1 << (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) (1 << (n)) +#define IPU6_REG_PSYS_GPDEV_FWIRQ (n) (4 * (n) + 0x1aa100) + +#endif /* IPU6_PLATFORM_REGS_H */
drivers/media/pci/intel/ipu6/ipu6-platform.h new file +31 -0
@@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* Copyright (C) 2013 - 2023 Intel Corporation */ + +#ifndef IPU6_PLATFORM_H +#define IPU6_PLATFORM_H + +#include "ipu6-fw-isys.h" + +#define IPU6_NAME "intel-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" + +/* +* The following definitions are encoded to the media_device's model field so +* that the software components which uses IPU6 driver can get the hw stepping +* information. +*/ +#define IPU6_MEDIA_DEV_MODEL_NAME "ipu6" + +#define IPU6SE_ISYS_NUM_STREAMS IPU6SE_NONSECURE_STREAM_ID_MAX +#define IPU6_ISYS_NUM_STREAMS IPU6_NONSECURE_STREAM_ID_MAX + +extern struct ipu6_isys_internal_pdata isys_ipdata; +extern struct ipu6_psys_internal_pdata psys_ipdata; +extern const struct ipu6_buttress_ctrl isys_buttress_ctrl; +extern const struct ipu6_buttress_ctrl psys_buttress_ctrl; + +#endif
drivers/media/pci/intel/ipu6/ipu6.c new file +969 -0
969 lines not on this page · raw message
drivers/media/pci/intel/ipu6/ipu6.h new file +344 -0
344 lines not on this page · raw message
Signature · 1 line
2.39.1
RFC PATCH 2/14 media: intel/ipu6: add IPU virtual bus driver
In reply to [email protected]From: Bingbu Cao <[email protected]>
Even the IPU input system and processing system are 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.
Define a virtual bus to help us to implement the power sequence dependency and DMA mapping requirement on specific device.
--- drivers/media/pci/intel/ipu6/ipu6-bus.c | 263 ++++++++++++++++++++++++ drivers/media/pci/intel/ipu6/ipu6-bus.h | 68 ++++++ 2 files changed, 331 insertions(+) create mode 100644 drivers/media/pci/intel/ipu6/ipu6-bus.c create mode 100644 drivers/media/pci/intel/ipu6/ipu6-bus.h
drivers/media/pci/intel/ipu6/ipu6-bus.c new file +263 -0
@@ -0,0 +1,263 @@ +// SPDX-License-Identifier: GPL-2.0-only +// Copyright (C) 2013 - 2023 Intel Corporation + +#include <linux/delay.h> +#include <linux/device.h> +#include <linux/interrupt.h> +#include <linux/list.h> +#include <linux/module.h> +#include <linux/mutex.h> +#include <linux/pci.h> +#include <linux/pm_runtime.h> + +#include "ipu6.h" +#include "ipu6-bus.h" +#include "ipu6-buttress.h" +#include "ipu6-dma.h" +#include "ipu6-platform.h" + +static struct bus_type ipu6_bus; + +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); +dev_dbg (dev,"buttress power down %d\n" , ret); +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); +dev_dbg (dev,"buttress power up %d\n" , ret); +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 const struct dev_pm_ops ipu6_bus_pm_ops = { + .runtime_suspend = bus_pm_runtime_suspend, + .runtime_resume = bus_pm_runtime_resume, +}; + +static int ipu6_bus_match (struct device *dev,struct device_driver *drv) +{ +struct ipu6_bus_driver *adrv =to_ipu6_bus_driver (drv); +struct pci_dev *pci_dev =to_pci_dev (dev->parent); +const struct pci_device_id *found_id; + + found_id =pci_match_id (adrv->id_table, pci_dev); +if (found_id) +dev_dbg (dev,"%s %x:%x matched\n" ,dev_name (dev), + found_id->vendor, found_id->device); + +return found_id ?1 :0 ; +} + +static int ipu6_bus_probe (struct device *dev) +{ +struct ipu6_bus_device *adev =to_ipu6_bus_device (dev); +struct ipu6_bus_driver *adrv =to_ipu6_bus_driver (dev->driver); +int ret; + +if (!adev->isp->bus_ready_to_probe) +return -EPROBE_DEFER ; + +dev_dbg (dev,"bus probe dev %s\n" ,dev_name (dev)); + + adev->adrv = adrv; +if (!adrv->probe) { + ret = -ENODEV ; + goto out_err; + } + + ret =pm_runtime_resume_and_get (&adev->dev); +if (ret <0 ) { +dev_err (&adev->dev,"Failed to get runtime PM\n" ); + goto out_err; + } + + ret = adrv->probe (adev); +pm_runtime_put (&adev->dev); + +if (ret) + goto out_err; + +return 0 ; + +out_err: +ipu6_bus_set_drvdata (adev,NULL ); + adev->adrv =NULL ; + +return ret; +} + +static void ipu6_bus_remove (struct device *dev) +{ +struct ipu6_bus_device *adev =to_ipu6_bus_device (dev); +struct ipu6_bus_driver *adrv =to_ipu6_bus_driver (dev->driver); + +if (adrv->remove) + adrv->remove (adev); +} + +static struct bus_type ipu6_bus = { + .name =IPU6_BUS_NAME , + .match = ipu6_bus_match, + .probe = ipu6_bus_probe, + .remove = ipu6_bus_remove, + .pm = &ipu6_bus_pm_ops, +}; + +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); +} + +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 ipu6_bus_device *adev; +struct ipu6_device *isp =pci_get_drvdata (pdev); + + adev =kzalloc (sizeof (*adev),GFP_KERNEL ); +if (!adev) +return ERR_PTR (-ENOMEM ); + + adev->dev.parent = parent; + adev->dev.bus = &ipu6_bus; + adev->dev.release = ipu6_bus_release; + adev->dev.dma_ops = &ipu6_dma_ops; + adev->dma_mask =DMA_BIT_MASK (isp->secure_mode ?IPU6_MMU_ADDR_BITS : +IPU6_MMU_ADDR_BITS_NON_SECURE ); + adev->dev.dma_mask = &adev->dma_mask; + adev->dev.dma_parms = pdev->dev.dma_parms; + adev->dev.coherent_dma_mask = adev->dma_mask; + adev->ctrl = ctrl; + adev->pdata = pdata; + adev->isp = isp; +dev_set_name (&adev->dev,"%s" , name); + +device_initialize (&adev->dev); +pm_runtime_forbid (&adev->dev); +pm_runtime_enable (&adev->dev); + +return adev; +} + +int ipu6_bus_add_device (struct ipu6_bus_device *adev) +{ +int ret; + + ret =device_add (&adev->dev); +if (ret) { +put_device (&adev->dev); +return ret; + } + +mutex_lock (&ipu6_bus_mutex); +list_add (&adev->list, &adev->isp->devices); +mutex_unlock (&ipu6_bus_mutex); + +pm_runtime_allow (&adev->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->dev); +list_del (&adev->list); +device_unregister (&adev->dev); + } + +mutex_unlock (&ipu6_bus_mutex); +} + +int ipu6_bus_register_driver (struct ipu6_bus_driver *adrv) +{ + adrv->drv.bus = &ipu6_bus; +return driver_register (&adrv->drv); +} +EXPORT_SYMBOL_NS_GPL (ipu6_bus_register_driver,INTEL_IPU6 ); + +int ipu6_bus_unregister_driver (struct ipu6_bus_driver *adrv) +{ +driver_unregister (&adrv->drv); +return 0 ; +} +EXPORT_SYMBOL_NS_GPL (ipu6_bus_unregister_driver,INTEL_IPU6 ); + +int ipu6_bus_register (void ) +{ +return bus_register (&ipu6_bus); +} + +void ipu6_bus_unregister (void ) +{ +return bus_unregister (&ipu6_bus); +} + +static int flr_rpm_recovery (struct device *dev,void *p) +{ +/* +* We are not necessarily going through device from child to +* parent. runtime PM refuses to change state for parent if the child +* is still active. At FLR (full reset for whole IPU6) that doesn't +* matter. Everything has been power gated by HW during the FLR cycle +* and we are just cleaning up SW state. Thus, ignore child during +* set_suspended. +*/ +dev_dbg (dev,"FLR recovery call\n" ); +pm_suspend_ignore_children (dev, true); +pm_runtime_set_suspended (dev); +pm_suspend_ignore_children (dev, false); + +return 0 ; +} + +int ipu6_bus_flr_recovery (void ) +{ +bus_for_each_dev (&ipu6_bus,NULL ,NULL , flr_rpm_recovery); +return 0 ; +}
drivers/media/pci/intel/ipu6/ipu6-bus.h new file +68 -0
68 lines not on this page · raw message
Signature · 1 line
2.39.1
Re: [RFC PATCH 02/14] media: intel/ipu6: add IPU virtual bus driver
Hi Bingbu,
Thank you for the patch.
Quoted 11 lines · On Thu, Apr 13, 2023 at 06:04:17PM +0800, [email protected] wrote:
From: Bingbu Cao <[email protected]>
Even the IPU input system and processing system are 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.
Define a virtual bus to help us to implement the power sequence dependency and DMA mapping requirement on specific device.
Have you considered using the aux bus instead of creating a custom bus type (see [1]) ?
[1] https://lore.kernel.org/lkml/Y862WTT03%[email protected]/
Quoted 302 lines
Signed-off-by Bingbu Cao <[email protected]>--- drivers/media/pci/intel/ipu6/ipu6-bus.c | 263 ++++++++++++++++++++++++ drivers/media/pci/intel/ipu6/ipu6-bus.h | 68 ++++++ 2 files changed, 331 insertions(+) create mode 100644 drivers/media/pci/intel/ipu6/ipu6-bus.c create mode 100644 drivers/media/pci/intel/ipu6/ipu6-bus.hdrivers/media/pci/intel/ipu6/ipu6-bus.c new file +263
-0@@ -0,0 +1,263 @@ +// SPDX-License-Identifier: GPL-2.0-only +// Copyright (C) 2013 - 2023 Intel Corporation + +#include <linux/delay.h> +#include <linux/device.h> +#include <linux/interrupt.h> +#include <linux/list.h> +#include <linux/module.h> +#include <linux/mutex.h> +#include <linux/pci.h> +#include <linux/pm_runtime.h> + +#include "ipu6.h" +#include "ipu6-bus.h" +#include "ipu6-buttress.h" +#include "ipu6-dma.h" +#include "ipu6-platform.h" + +static struct bus_type ipu6_bus; + +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); +dev_dbg (dev,"buttress power down %d\n" , ret); +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); +dev_dbg (dev,"buttress power up %d\n" , ret); +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 const struct dev_pm_ops ipu6_bus_pm_ops = { + .runtime_suspend = bus_pm_runtime_suspend, + .runtime_resume = bus_pm_runtime_resume, +}; + +static int ipu6_bus_match (struct device *dev,struct device_driver *drv) +{ +struct ipu6_bus_driver *adrv =to_ipu6_bus_driver (drv); +struct pci_dev *pci_dev =to_pci_dev (dev->parent); +const struct pci_device_id *found_id; + + found_id =pci_match_id (adrv->id_table, pci_dev); +if (found_id) +dev_dbg (dev,"%s %x:%x matched\n" ,dev_name (dev), + found_id->vendor, found_id->device); + +return found_id ?1 :0 ; +} + +static int ipu6_bus_probe (struct device *dev) +{ +struct ipu6_bus_device *adev =to_ipu6_bus_device (dev); +struct ipu6_bus_driver *adrv =to_ipu6_bus_driver (dev->driver); +int ret; + +if (!adev->isp->bus_ready_to_probe) +return -EPROBE_DEFER ; + +dev_dbg (dev,"bus probe dev %s\n" ,dev_name (dev)); + + adev->adrv = adrv; +if (!adrv->probe) { + ret = -ENODEV ; + goto out_err; + } + + ret =pm_runtime_resume_and_get (&adev->dev); +if (ret <0 ) { +dev_err (&adev->dev,"Failed to get runtime PM\n" ); + goto out_err; + } + + ret = adrv->probe (adev); +pm_runtime_put (&adev->dev); + +if (ret) + goto out_err; + +return 0 ; + +out_err: +ipu6_bus_set_drvdata (adev,NULL ); + adev->adrv =NULL ; + +return ret; +} + +static void ipu6_bus_remove (struct device *dev) +{ +struct ipu6_bus_device *adev =to_ipu6_bus_device (dev); +struct ipu6_bus_driver *adrv =to_ipu6_bus_driver (dev->driver); + +if (adrv->remove) + adrv->remove (adev); +} + +static struct bus_type ipu6_bus = { + .name =IPU6_BUS_NAME , + .match = ipu6_bus_match, + .probe = ipu6_bus_probe, + .remove = ipu6_bus_remove, + .pm = &ipu6_bus_pm_ops, +}; + +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); +} + +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 ipu6_bus_device *adev; +struct ipu6_device *isp =pci_get_drvdata (pdev); + + adev =kzalloc (sizeof (*adev),GFP_KERNEL ); +if (!adev) +return ERR_PTR (-ENOMEM ); + + adev->dev.parent = parent; + adev->dev.bus = &ipu6_bus; + adev->dev.release = ipu6_bus_release; + adev->dev.dma_ops = &ipu6_dma_ops; + adev->dma_mask =DMA_BIT_MASK (isp->secure_mode ?IPU6_MMU_ADDR_BITS : +IPU6_MMU_ADDR_BITS_NON_SECURE ); + adev->dev.dma_mask = &adev->dma_mask; + adev->dev.dma_parms = pdev->dev.dma_parms; + adev->dev.coherent_dma_mask = adev->dma_mask; + adev->ctrl = ctrl; + adev->pdata = pdata; + adev->isp = isp; +dev_set_name (&adev->dev,"%s" , name); + +device_initialize (&adev->dev); +pm_runtime_forbid (&adev->dev); +pm_runtime_enable (&adev->dev); + +return adev; +} + +int ipu6_bus_add_device (struct ipu6_bus_device *adev) +{ +int ret; + + ret =device_add (&adev->dev); +if (ret) { +put_device (&adev->dev); +return ret; + } + +mutex_lock (&ipu6_bus_mutex); +list_add (&adev->list, &adev->isp->devices); +mutex_unlock (&ipu6_bus_mutex); + +pm_runtime_allow (&adev->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->dev); +list_del (&adev->list); +device_unregister (&adev->dev); + } + +mutex_unlock (&ipu6_bus_mutex); +} + +int ipu6_bus_register_driver (struct ipu6_bus_driver *adrv) +{ + adrv->drv.bus = &ipu6_bus; +return driver_register (&adrv->drv); +} +EXPORT_SYMBOL_NS_GPL (ipu6_bus_register_driver,INTEL_IPU6 ); + +int ipu6_bus_unregister_driver (struct ipu6_bus_driver *adrv) +{ +driver_unregister (&adrv->drv); +return 0 ; +} +EXPORT_SYMBOL_NS_GPL (ipu6_bus_unregister_driver,INTEL_IPU6 ); + +int ipu6_bus_register (void ) +{ +return bus_register (&ipu6_bus); +} + +void ipu6_bus_unregister (void ) +{ +return bus_unregister (&ipu6_bus); +} + +static int flr_rpm_recovery (struct device *dev,void *p) +{ +/* +* We are not necessarily going through device from child to +* parent. runtime PM refuses to change state for parent if the child +* is still active. At FLR (full reset for whole IPU6) that doesn't +* matter. Everything has been power gated by HW during the FLR cycle +* and we are just cleaning up SW state. Thus, ignore child during +* set_suspended. +*/ +dev_dbg (dev,"FLR recovery call\n" ); +pm_suspend_ignore_children (dev, true); +pm_runtime_set_suspended (dev); +pm_suspend_ignore_children (dev, false); + +return 0 ; +} + +int ipu6_bus_flr_recovery (void ) +{ +bus_for_each_dev (&ipu6_bus,NULL ,NULL , flr_rpm_recovery); +return 0 ; +}drivers/media/pci/intel/ipu6/ipu6-bus.h new file +19
-0@@ -0,0 +1,68 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* Copyright (C) 2013 - 2023 Intel Corporation */ + +#ifndef IPU6_BUS_H +#define IPU6_BUS_H + +#include <linux/device.h> +#include <linux/irqreturn.h> +#include <linux/list.h> +#include <linux/mm.h> +#include <linux/pci.h> + +#define IPU6_BUS_NAME IPU6_NAME "-bus" + +struct ipu6_buttress_ctrl; +struct ipu6_subsystem_trace_config; + +struct ipu6_bus_device { + struct device dev;
drivers/media/pci/intel/ipu6/ipu6-bus.h line 29
Quoted 10 lines
drivers/media/pci/intel/ipu6/ipu6-bus.h new file +10
-0+struct list_head list; +void *pdata; +struct ipu6_bus_driver *adrv; +struct ipu6_mmu *mmu; +struct ipu6_device *isp; +struct ipu6_subsystem_trace_config *trace_cfg; +struct ipu6_buttress_ctrl *ctrl; +u64 dma_mask; + +const struct firmware *fw;
Is there a firmware per device ? I may have understood things wrong, but I thought the whole point of this architecture was to have a base PCI device running a firmware, exposing multiple functions (ISYS and PSYS), and implementing separate drivers for those functions.
drivers/media/pci/intel/ipu6/ipu6-bus.h line 40
Quoted 11 lines
drivers/media/pci/intel/ipu6/ipu6-bus.h new file +11
-0+struct sg_table fw_sgt; +u64 *pkg_dir; +dma_addr_t pkg_dir_dma_addr; +unsigned int pkg_dir_size; +}; + +#define to_ipu6_bus_device (_dev) container_of(_dev, struct ipu6_bus_device, dev) + +struct ipu6_bus_driver { +struct device_driver drv; +const struct pci_device_id *id_table;
Why do you need the PCI ID table here ? The table from ipu6-isys.c is the same as the one in ipu6.c.
Quoted 28 lines
drivers/media/pci/intel/ipu6/ipu6-bus.h new file +28
-0+int (*probe)(struct ipu6_bus_device *adev); +void (*remove)(struct ipu6_bus_device *adev); +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_driver (_drv) container_of(_drv, struct ipu6_bus_driver, drv) + +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); + +int ipu6_bus_register_driver (struct ipu6_bus_driver *adrv); +int ipu6_bus_unregister_driver (struct ipu6_bus_driver *adrv); + +int ipu6_bus_register (void ); +void ipu6_bus_unregister (void ); + +#define ipu6_bus_set_drvdata (adev, data) dev_set_drvdata(&(adev)->dev, data) +#define ipu6_bus_get_drvdata (adev) dev_get_drvdata(&(adev)->dev) + +int ipu6_bus_flr_recovery (void ); + +#endif
Signature · 3 lines
Regards, Laurent Pinchart
Sakari Ailus
maintainerRe: [RFC PATCH 02/14] media: intel/ipu6: add IPU virtual bus driver
Hi Laurent,
Quoted 9 lines · Laurent Pinchart
Quoted 9 lines
drivers/media/pci/intel/ipu6/ipu6-bus.h new file +9
-0+struct ipu6_bus_device { +struct device dev; +struct list_head list; +void *pdata; +struct ipu6_bus_driver *adrv; +struct ipu6_mmu *mmu; +struct ipu6_device *isp; +struct ipu6_subsystem_trace_config *trace_cfg; +struct ipu6_buttress_ctrl *ctrl;
Quoted 8 lines
drivers/media/pci/intel/ipu6/ipu6-bus.h line 29
Quoted 3 lines
drivers/media/pci/intel/ipu6/ipu6-bus.h new file +3
-0+u64 dma_mask; + +const struct firmware *fw;Is there a firmware per device ? I may have understood things wrong, but I thought the whole point of this architecture was to have a base PCI device running a firmware, exposing multiple functions (ISYS and PSYS), and implementing separate drivers for those functions.
Ah, no. There's one for ISYS and another for PSYS. Because why would you have just one when you can have two? :-)
Signature · 1 line
Sakari Ailus
RFC PATCH 3/14 media: intel/ipu6: add IPU6 buttress interface driver
In reply to [email protected]From: Bingbu Cao <[email protected]>
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.
--- drivers/media/pci/intel/ipu6/ipu6-buttress.c | 916 ++++++++++++++++++ drivers/media/pci/intel/ipu6/ipu6-buttress.h | 109 +++ .../intel/ipu6/ipu6-platform-buttress-regs.h | 231 +++++ 3 files changed, 1256 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
drivers/media/pci/intel/ipu6/ipu6-buttress.c new file +916 -0
@@ -0,0 +1,916 @@ +// SPDX-License-Identifier: GPL-2.0-only +// Copyright (C) 2013 - 2023 Intel Corporation + +#include <linux/bitfield.h> +#include <linux/completion.h> +#include <linux/debugfs.h> +#include <linux/device.h> +#include <linux/delay.h> +#include <linux/errno.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-cpd.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[] = { +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_info (&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->adrv) +return IRQ_NONE ; + +if (adev->adrv->isr) + ret = adev->adrv->isr (adev); + +if (ret ==IRQ_WAKE_THREAD && !adev->adrv->isr_threaded) + ret =IRQ_NONE ; + + adev->adrv->wake_isr_thread = (ret ==IRQ_WAKE_THREAD ); + +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 && !isp->flr_done); + +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 }; +irqreturn_t ret =IRQ_NONE ; +unsigned int i; + +for (i =0 ; i <ARRAY_SIZE (ipu6_adev_irq_mask); i++) { +if (adev[i] && adev[i]->adrv && + adev[i]->adrv->wake_isr_thread && + adev[i]->adrv->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 =0 ; + +if (!ctrl) +return 0 ; + +/* Until FLR completion nothing is expected to work */ +if (isp->flr_done) +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 ); + +return (val &BUTTRESS_SECURITY_CTL_FW_SETUP_MASK ) == +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" ); + }else { +dev_info (&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 ret; +} + +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 =PAGE_ALIGN (fw->size) >>PAGE_SHIFT ; + + 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->dev, sgt,DMA_TO_DEVICE ,0 ); +if (ret <0 ) { + ret = -ENOMEM ; +sg_free_table (sgt); + goto out; + } + +dma_sync_sgtable_for_device (&sys->dev, sgt,DMA_TO_DEVICE ); + +out: +kfree (pages); + +return ret; +} +EXPORT_SYMBOL_NS_GPL (ipu6_buttress_map_fw_image,INTEL_IPU6 ); + +int ipu6_buttress_unmap_fw_image (struct ipu6_bus_device *sys, +struct sg_table *sgt) +{ +dma_unmap_sgtable (&sys->dev, sgt,DMA_TO_DEVICE ,0 ); +sg_free_table (sgt); + +return 0 ; +} +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 ); + +int 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); + +return 0 ; +} +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 ); + +int 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 ); + +return 0 ; +} + +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\n" , + isp->secure_mode ?"secure" :"non-secure" ); + +dev_info (&isp->pdev->dev,"IPU6 secure touch = 0x%x\n" , +readl (isp->base +BUTTRESS_REG_SECURITY_TOUCH )); + +dev_info (&isp->pdev->dev,"IPU6 camera mask = 0x%x\n" , +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_info (&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); +}
drivers/media/pci/intel/ipu6/ipu6-buttress.h new file +109 -0
109 lines not on this page · raw message
drivers/media/pci/intel/ipu6/ipu6-platform-buttress-regs.h new file +231 -0
231 lines not on this page · raw message
Signature · 1 line
2.39.1
RFC PATCH 4/14 media: intel/ipu6: CPD parsing for get firmware components
In reply to [email protected]From: Bingbu Cao <[email protected]>
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.
--- drivers/media/pci/intel/ipu6/ipu6-cpd.c | 359 ++++++++++++++++++++++++ drivers/media/pci/intel/ipu6/ipu6-cpd.h | 107 +++++++ 2 files changed, 466 insertions(+) create mode 100644 drivers/media/pci/intel/ipu6/ipu6-cpd.c create mode 100644 drivers/media/pci/intel/ipu6/ipu6-cpd.h
drivers/media/pci/intel/ipu6/ipu6-cpd.c new file +359 -0
@@ -0,0 +1,359 @@ +// SPDX-License-Identifier: GPL-2.0-only +// Copyright (C) 2015 - 2023 Intel Corporation + +#include <linux/bitfield.h> +#include <linux/dma-mapping.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 0x5f4955504b44525f + +/* $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 = +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 = +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 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 (&adev->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 (&isp->psys->dev, adev->pkg_dir_size, + adev->pkg_dir, adev->pkg_dir_dma_addr,0 ); +return -EINVAL ; + } + +/* 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 (&adev->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->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 -EINVAL ; + } + +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 -EINVAL ; + } + +/* 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; + } + +return 0 ; +}
drivers/media/pci/intel/ipu6/ipu6-cpd.h new file +107 -0
107 lines not on this page · raw message
Signature · 1 line
2.39.1
RFC PATCH 5/14 media: intel/ipu6: add IPU6 DMA mapping API and MMU table
In reply to [email protected]From: Bingbu Cao <[email protected]>
IPU has its own scalar processor which the firmware run at, it has internal 32-bits virtual address mapping, it allows that scalar process can access the IPU internal memory directly and also access the external system memory by IPU virtual address. So IPU DMA and MMU driver define its DMA mapping ops expose by IPU virtual bus.
MMU driver do MMU hardware configuration and setup IPU MMU lookup table. IPU MMU and DMA mapping works behind the IOMMU hardware, it may do nested mapping - PCI(IOMMU) mapping and IPU-MMU mapping.
--- drivers/media/pci/intel/ipu6/ipu6-dma.c | 497 ++++++++++++++ drivers/media/pci/intel/ipu6/ipu6-dma.h | 19 + drivers/media/pci/intel/ipu6/ipu6-mmu.c | 833 ++++++++++++++++++++++++ drivers/media/pci/intel/ipu6/ipu6-mmu.h | 65 ++ 4 files changed, 1414 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
drivers/media/pci/intel/ipu6/ipu6-dma.c new file +497 -0
@@ -0,0 +1,497 @@ +// SPDX-License-Identifier: GPL-2.0-only +// Copyright (C) 2013 - 2023 Intel Corporation + +#include <linux/cacheflush.h> +#include <linux/device.h> +#include <linux/dma-mapping.h> +#include <linux/dma-map-ops.h> +#include <linux/gfp.h> +#include <linux/highmem.h> +#include <linux/iova.h> +#include <linux/scatterlist.h> +#include <linux/slab.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) +{ +struct page **pages; +int count = size >>PAGE_SHIFT ; +int array_size = count *sizeof (struct page *); +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 int __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); +return 0 ; +} + +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 = size >>PAGE_SHIFT ; + + iova =alloc_iova (&mmu->dmap->iovad, count, +dma_get_mask (dev) >>PAGE_SHIFT ,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: iova low pfn %lu, high pfn %lu\n" , + 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, + (iova->pfn_lo + i) <<PAGE_SHIFT , + 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 = iova->pfn_lo <<PAGE_SHIFT ; + + info->pages = pages; + info->ipu6_iova = *dma_handle; + info->size = size; +list_add (&info->list, &mmu->vma_list); + +return info->vaddr; + +out_unmap: +for (i--; i >=0 ; i--) { + ipu6_iova = (iova->pfn_lo + i) <<PAGE_SHIFT ; + 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, + dma_handle >>PAGE_SHIFT ); +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 < size >>PAGE_SHIFT ; i++) { + ipu6_iova = (iova->pfn_lo + i) <<PAGE_SHIFT ; + 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, iova->pfn_lo <<PAGE_SHIFT , +iova_size (iova) <<PAGE_SHIFT ); + +__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 =PAGE_ALIGN (size) >>PAGE_SHIFT ; +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 + (i <<PAGE_SHIFT ), + 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, +sg_dma_address (sglist) >>PAGE_SHIFT ); +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 -=PAGE_ALIGN (sg_dma_len (sg)) >>PAGE_SHIFT ; + 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,"ipu6_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, iova->pfn_lo <<PAGE_SHIFT , +iova_size (iova) <<PAGE_SHIFT ); + + 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 ; +u32 iova_addr; +int i, count; + +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 +=PAGE_ALIGN (sg_dma_len (sg)) >>PAGE_SHIFT ; + + iova =alloc_iova (&mmu->dmap->iovad, npages, +dma_get_mask (dev) >>PAGE_SHIFT ,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%lx phy %pad size %d\n" , + i, (unsigned long )iova_addr <<PAGE_SHIFT , + &sg_dma_address (sg),sg_dma_len (sg)); + +dev_dbg (dev,"mapping entry %d: sg->length = %d\n" , i, + sg->length); + + ret =ipu6_mmu_map (mmu->dmap->mmu_info, + iova_addr <<PAGE_SHIFT , +sg_dma_address (sg), +PAGE_ALIGN (sg_dma_len (sg))); +if (ret) + goto out_fail; + +sg_dma_address (sg) = iova_addr <<PAGE_SHIFT ; + + iova_addr +=PAGE_ALIGN (sg_dma_len (sg)) >>PAGE_SHIFT ; + } + +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 =PAGE_ALIGN (size) >>PAGE_SHIFT ; + + 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, +};
drivers/media/pci/intel/ipu6/ipu6-dma.h new file +19 -0
@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* Copyright (C) 2013 - 2023 Intel Corporation */ + +#ifndef IPU6_DMA_H +#define IPU6_DMA_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 */
drivers/media/pci/intel/ipu6/ipu6-mmu.c new file +833 -0
833 lines not on this page · raw message
drivers/media/pci/intel/ipu6/ipu6-mmu.h new file +65 -0
65 lines not on this page · raw message
Signature · 1 line
2.39.1
RFC PATCH 6/14 media: intel/ipu6: add syscom interfaces between firmware and driver
In reply to [email protected]From: Bingbu Cao <[email protected]>
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.
--- drivers/media/pci/intel/ipu6/ipu6-fw-com.c | 417 +++++++++++++++++++++ drivers/media/pci/intel/ipu6/ipu6-fw-com.h | 47 +++ 2 files changed, 464 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
drivers/media/pci/intel/ipu6/ipu6-fw-com.c new file +417 -0
@@ -0,0 +1,417 @@ +// SPDX-License-Identifier: GPL-2.0-only +// Copyright (C) 2013 - 2023 Intel Corporation + +#include <linux/cacheflush.h> +#include <linux/device.h> +#include <linux/kernel.h> +#include <linux/slab.h> +#include <linux/dma-mapping.h> + +#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; +} __packed; + +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 +#ifdef IPU_TRACE_SUPPORT +#define TUNIT_MAGIC_PATTERN 0x5a5a5a5a +#endif + +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 BUTRESS_FW_BOOT_PARAMS_0 0x4000 +#define BUTTRESS_FW_BOOT_PARAM_REG (base, offset, id) \ + ((base) + BUTRESS_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; +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 (&ctx->adev->dev, sizeall, + &ctx->dma_addr,GFP_KERNEL , attrs); + ctx->attrs = attrs; +if (!ctx->dma_buffer) { +dev_err (&ctx->adev->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) +{ +/* 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->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; +void *addr; + + 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 ; + + addr = (void *)(q->host_address + rd * q->token_size); + +return addr; +} +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 );
drivers/media/pci/intel/ipu6/ipu6-fw-com.h new file +47 -0
47 lines not on this page · raw message
Signature · 1 line
2.39.1
RFC PATCH 7/14 media: intel/ipu6: input system ABI between firmware and driver
In reply to [email protected]From: Bingbu Cao <[email protected]>
Implement the input system firmware ABIs between the firmware and driver - include stream configuration, control command, capture request and response, etc.
--- drivers/media/pci/intel/ipu6/ipu6-fw-isys.c | 566 +++++++++++++++++++ drivers/media/pci/intel/ipu6/ipu6-fw-isys.h | 574 ++++++++++++++++++++ 2 files changed, 1140 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
drivers/media/pci/intel/ipu6/ipu6-fw-isys.c new file +566 -0
@@ -0,0 +1,566 @@ +// SPDX-License-Identifier: GPL-2.0-only +// Copyright (C) 2013 - 2023 Intel Corporation + +#include <linux/cacheflush.h> +#include <linux/delay.h> +#include <linux/types.h> + +#include "ipu6.h" +#include "ipu6-bus.h" +#include "ipu6-fw-com.h" +#include "ipu6-fw-isys.h" +#include "ipu6-isys.h" +#include "ipu6-platform.h" +#include "ipu6-platform-isys-csi2-reg.h" +#include "ipu6-platform-regs.h" + +#define IPU6_FW_UNSUPPORTED_DATA_TYPE 0 +static const u8 extracted_bits_per_pixel_per_mipi_data_type[64 ] = { +64 ,/* [0x00] MIPI_DATA_TYPE_FRAME_START_CODE */ +64 ,/* [0x01] MIPI_DATA_TYPE_FRAME_END_CODE */ +64 ,/* [0x02] MIPI_DATA_TYPE_LINE_START_CODE */ +64 ,/* [0x03] MIPI_DATA_TYPE_LINE_END_CODE */ +IPU6_FW_UNSUPPORTED_DATA_TYPE ,/* [0x04] */ +IPU6_FW_UNSUPPORTED_DATA_TYPE ,/* [0x05] */ +IPU6_FW_UNSUPPORTED_DATA_TYPE ,/* [0x06] */ +IPU6_FW_UNSUPPORTED_DATA_TYPE ,/* [0x07] */ +64 ,/* [0x08] MIPI_DATA_TYPE_GENERIC_SHORT1 */ +64 ,/* [0x09] MIPI_DATA_TYPE_GENERIC_SHORT2 */ +64 ,/* [0x0A] MIPI_DATA_TYPE_GENERIC_SHORT3 */ +64 ,/* [0x0B] MIPI_DATA_TYPE_GENERIC_SHORT4 */ +64 ,/* [0x0C] MIPI_DATA_TYPE_GENERIC_SHORT5 */ +64 ,/* [0x0D] MIPI_DATA_TYPE_GENERIC_SHORT6 */ +64 ,/* [0x0E] MIPI_DATA_TYPE_GENERIC_SHORT7 */ +64 ,/* [0x0F] MIPI_DATA_TYPE_GENERIC_SHORT8 */ +IPU6_FW_UNSUPPORTED_DATA_TYPE ,/* [0x10] */ +IPU6_FW_UNSUPPORTED_DATA_TYPE ,/* [0x11] */ +8 ,/* [0x12] MIPI_DATA_TYPE_EMBEDDED */ +IPU6_FW_UNSUPPORTED_DATA_TYPE ,/* [0x13] */ +IPU6_FW_UNSUPPORTED_DATA_TYPE ,/* [0x14] */ +IPU6_FW_UNSUPPORTED_DATA_TYPE ,/* [0x15] */ +IPU6_FW_UNSUPPORTED_DATA_TYPE ,/* [0x16] */ +IPU6_FW_UNSUPPORTED_DATA_TYPE ,/* [0x17] */ +12 ,/* [0x18] MIPI_DATA_TYPE_YUV420_8 */ +15 ,/* [0x19] MIPI_DATA_TYPE_YUV420_10 */ +12 ,/* [0x1A] MIPI_DATA_TYPE_YUV420_8_LEGACY */ +IPU6_FW_UNSUPPORTED_DATA_TYPE ,/* [0x1B] */ +12 ,/* [0x1C] MIPI_DATA_TYPE_YUV420_8_SHIFT */ +15 ,/* [0x1D] MIPI_DATA_TYPE_YUV420_10_SHIFT */ +16 ,/* [0x1E] MIPI_DATA_TYPE_YUV422_8 */ +20 ,/* [0x1F] MIPI_DATA_TYPE_YUV422_10 */ +16 ,/* [0x20] MIPI_DATA_TYPE_RGB_444 */ +16 ,/* [0x21] MIPI_DATA_TYPE_RGB_555 */ +16 ,/* [0x22] MIPI_DATA_TYPE_RGB_565 */ +18 ,/* [0x23] MIPI_DATA_TYPE_RGB_666 */ +24 ,/* [0x24] MIPI_DATA_TYPE_RGB_888 */ +IPU6_FW_UNSUPPORTED_DATA_TYPE ,/* [0x25] */ +IPU6_FW_UNSUPPORTED_DATA_TYPE ,/* [0x26] */ +IPU6_FW_UNSUPPORTED_DATA_TYPE ,/* [0x27] */ +6 ,/* [0x28] MIPI_DATA_TYPE_RAW_6 */ +7 ,/* [0x29] MIPI_DATA_TYPE_RAW_7 */ +8 ,/* [0x2A] MIPI_DATA_TYPE_RAW_8 */ +10 ,/* [0x2B] MIPI_DATA_TYPE_RAW_10 */ +12 ,/* [0x2C] MIPI_DATA_TYPE_RAW_12 */ +14 ,/* [0x2D] MIPI_DATA_TYPE_RAW_14 */ +16 ,/* [0x2E] MIPI_DATA_TYPE_RAW_16 */ +8 ,/* [0x2F] MIPI_DATA_TYPE_BINARY_8 */ +8 ,/* [0x30] MIPI_DATA_TYPE_USER_DEF1 */ +8 ,/* [0x31] MIPI_DATA_TYPE_USER_DEF2 */ +8 ,/* [0x32] MIPI_DATA_TYPE_USER_DEF3 */ +8 ,/* [0x33] MIPI_DATA_TYPE_USER_DEF4 */ +8 ,/* [0x34] MIPI_DATA_TYPE_USER_DEF5 */ +8 ,/* [0x35] MIPI_DATA_TYPE_USER_DEF6 */ +8 ,/* [0x36] MIPI_DATA_TYPE_USER_DEF7 */ +8 ,/* [0x37] MIPI_DATA_TYPE_USER_DEF8 */ +IPU6_FW_UNSUPPORTED_DATA_TYPE ,/* [0x38] */ +IPU6_FW_UNSUPPORTED_DATA_TYPE ,/* [0x39] */ +IPU6_FW_UNSUPPORTED_DATA_TYPE ,/* [0x3A] */ +IPU6_FW_UNSUPPORTED_DATA_TYPE ,/* [0x3B] */ +IPU6_FW_UNSUPPORTED_DATA_TYPE ,/* [0x3C] */ +IPU6_FW_UNSUPPORTED_DATA_TYPE ,/* [0x3D] */ +IPU6_FW_UNSUPPORTED_DATA_TYPE ,/* [0x3E] */ +IPU6_FW_UNSUPPORTED_DATA_TYPE /* [0x3F] */ +}; + +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" +}; + +u8 ipu6_fw_isys_get_bpp_by_dt (u8 dt) +{ +return extracted_bits_per_pixel_per_mipi_data_type[dt]; +} + +static int handle_proxy_response (struct ipu6_isys *isys,unsigned int req_id) +{ +struct ipu6_fw_isys_proxy_resp_info_abi *resp; +int ret = -EIO ; + + resp = (struct ipu6_fw_isys_proxy_resp_info_abi *) +ipu6_recv_get_token (isys->fwcom,IPU6_BASE_PROXY_RECV_QUEUES ); +if (!resp) +return 1 ; + +dev_dbg (&isys->adev->dev, +"Proxy response: id 0x%x, error %d, details %d\n" , + resp->request_id, resp->error_info.error, + resp->error_info.error_details); + +if (req_id == resp->request_id) + ret =0 ; + +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 ipu6_fw_proxy_send_queue_token *token; +unsigned int timeout =1000 ; +int ret; + +dev_dbg (&isys->adev->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 (&isys->adev->dev, +"Proxy response received with unexpected id\n" ); +break ; + } + timeout--; + }while (ret && timeout); + +if (!timeout) +dev_err (&isys->adev->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 ipu6_fw_send_queue_token *token; + +if (send_type >=N_IPU6_FW_ISYS_SEND_TYPE ) +return -EINVAL ; + +dev_dbg (&isys->adev->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->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_err (&isys->adev->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; +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 (&isys->adev->dev,sizeof (*isys_fw_cfg), +GFP_KERNEL ); +if (!isys_fw_cfg) +return -ENOMEM ; + + isys_fw_cfg->num_send_queues[IPU6_FW_ISYS_QUEUE_TYPE_PROXY ] = +IPU6_N_MAX_PROXY_SEND_QUEUES ; + isys_fw_cfg->num_send_queues[IPU6_FW_ISYS_QUEUE_TYPE_DEV ] = +IPU6_N_MAX_DEV_SEND_QUEUES ; + isys_fw_cfg->num_send_queues[IPU6_FW_ISYS_QUEUE_TYPE_MSG ] = + num_in_message_queues; + isys_fw_cfg->num_recv_queues[IPU6_FW_ISYS_QUEUE_TYPE_PROXY ] = +IPU6_N_MAX_PROXY_RECV_QUEUES ; +/* Common msg/dev return queue */ + isys_fw_cfg->num_recv_queues[IPU6_FW_ISYS_QUEUE_TYPE_DEV ] =0 ; + isys_fw_cfg->num_recv_queues[IPU6_FW_ISYS_QUEUE_TYPE_MSG ] =1 ; + + size =sizeof (*input_queue_cfg) * max_send_queues; + input_queue_cfg =devm_kzalloc (&isys->adev->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 (&isys->adev->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->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 && ret) { +dev_err (dev,"isys port open ready failed %d\n" , ret); +ipu6_fw_isys_close (isys); + } + +return ret; +} + +struct ipu6_fw_isys_resp_info_abi * +ipu6_fw_isys_get_resp (void *context,unsigned int queue) +{ +return (struct ipu6_fw_isys_resp_info_abi *) +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" ); +}
drivers/media/pci/intel/ipu6/ipu6-fw-isys.h new file +574 -0
574 lines not on this page · raw message
Signature · 1 line
2.39.1
RFC PATCH 8/14 media: intel/ipu6: add IPU6 CSI2 receiver v4l2 sub-device
In reply to [email protected]From: Bingbu Cao <[email protected]>
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.
--- drivers/media/pci/intel/ipu6/ipu6-isys-csi2.c | 579 ++++++++++++++++++ drivers/media/pci/intel/ipu6/ipu6-isys-csi2.h | 75 +++ .../media/pci/intel/ipu6/ipu6-isys-subdev.c | 309 ++++++++++ .../media/pci/intel/ipu6/ipu6-isys-subdev.h | 70 +++ .../intel/ipu6/ipu6-platform-isys-csi2-reg.h | 187 ++++++ 5 files changed, 1220 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
drivers/media/pci/intel/ipu6/ipu6-isys-csi2.c new file +579 -0
@@ -0,0 +1,579 @@ +// SPDX-License-Identifier: GPL-2.0-only +// Copyright (C) 2013 - 2023 Intel Corporation + +#include <linux/bitfield.h> +#include <linux/delay.h> +#include <linux/device.h> +#include <linux/spinlock.h> + +#include <media/media-entity.h> +#include <media/v4l2-device.h> +#include <media/v4l2-event.h> + +#include "ipu6.h" +#include "ipu6-bus.h" +#include "ipu6-buttress.h" +#include "ipu6-isys.h" +#include "ipu6-isys-csi2.h" +#include "ipu6-isys-phy.h" +#include "ipu6-isys-subdev.h" +#include "ipu6-isys-video.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 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} +}; + +int ipu6_isys_csi2_get_link_freq (struct ipu6_isys_csi2 *csi2,s64 *link_freq) +{ +struct media_pad *src_pad; +struct v4l2_subdev *ext_sd; +unsigned int bpp, lanes; +struct device *dev; +s64 ret; + +if (!csi2 || !link_freq) +return -EINVAL ; + + dev = &csi2->isys->adev->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 ; + + bpp =ipu6_isys_mbus_code_to_bpp (csi2->asd.ffmt->code); + lanes = csi2->nlanes; + + ret =v4l2_get_link_freq (ext_sd->ctrl_handler, bpp, lanes *2 ); +if (ret <0 ) { +dev_err (dev,"can't get link frequency (%lld)\n" , ret); +return ret; + } + +dev_dbg (dev,"link freq of %s is %lld\n" , ext_sd->name, ret); + *link_freq = ret; + +return 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); + +dev_dbg (&csi2->isys->adev->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) +{ +s64 link_freq; +int ret; + + ret =ipu6_isys_csi2_get_link_freq (csi2, &link_freq); +if (ret) +return ret; + + 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); +dev_dbg (&csi2->isys->adev->dev,"ctermen %u\n" , timing->ctermen); +dev_dbg (&csi2->isys->adev->dev,"csettle %u\n" , timing->csettle); + + 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 (&csi2->isys->adev->dev,"dtermen %u\n" , timing->dtermen); +dev_dbg (&csi2->isys->adev->dev,"dsettle %u\n" , 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 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 (&csi2->isys->adev->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 ipu6_isys_stream *stream; +struct ipu6_isys_csi2_config cfg; +unsigned int port, nports; +int ret =0 ; +u32 mask =0 ; +u32 i; + + stream =ipu6_isys_query_stream_by_source (isys, csi2->asd.source); +if (!stream) { +dev_err (&isys->adev->dev,"no available stream\n" ); +return -EINVAL ; + } + +ipu6_isys_put_stream (stream); + + port = csi2->port; +dev_dbg (&isys->adev->dev,"for port %u with %u lanes\n" , port, nlanes); + + cfg.port = 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, port)); +writel (0 , isys->pdata->base + +CSI_REG_HUB_DRV_ACCESS_PORT (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 (&isys->adev->dev,"csi-%d phy power up failed %d\n" , + port, ret); +return ret; + } + +return 0 ; +} + +static int set_stream (struct v4l2_subdev *sd,int enable) +{ +struct ipu6_isys_csi2 *csi2 =to_ipu6_isys_csi2 (sd); +struct ipu6_isys_csi2_timing timing = {0 }; +struct ipu6_isys_stream *stream; +unsigned int nlanes; +int ret; + +dev_dbg (&csi2->isys->adev->dev,"csi2 s_stream %d\n" , enable); + + stream =ipu6_isys_query_stream_by_source (csi2->isys, csi2->asd.source); +if (!stream) { +dev_err (&csi2->isys->adev->dev,"no available stream\n" ); +return -ENODEV ; + } + +if (!stream->source_entity) { +dev_err (&csi2->isys->adev->dev,"source_entity is NULL\n" ); +return -ENODEV ; + } + +ipu6_isys_put_stream (stream); + +if (!enable) { +ipu6_isys_csi2_set_stream (sd, &timing,0 , enable); +return 0 ; + } + + nlanes = csi2->nlanes; +dev_dbg (&csi2->isys->adev->dev,"lane nr %d.\n" , nlanes); + + ret =ipu6_isys_csi2_calc_timing (csi2, &timing,CSI2_ACCINV ); +if (ret) +return ret; + +return ipu6_isys_csi2_set_stream (sd, &timing, nlanes, enable); +} + +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 v4l2_mbus_framefmt *sink_ffmt = +ipu6_isys_get_ffmt (sd, state,CSI2_PAD_SINK , sel->which); +struct v4l2_mbus_framefmt *src_ffmt = +ipu6_isys_get_ffmt (sd, state, sel->pad, sel->which); + +if (sel->pad ==CSI2_PAD_SINK || sel->target !=V4L2_SEL_TGT_CROP ) +return -EINVAL ; + +mutex_lock (&asd->mutex); +/* 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); + *ipu6_isys_get_crop (sd, state, sel->pad, sel->which) = 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 (&asd->isys->adev->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); +mutex_unlock (&asd->mutex); + +return 0 ; +} + +static int ipu6_isys_csi2_get_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 v4l2_mbus_framefmt *sink_ffmt = +ipu6_isys_get_ffmt (sd, state,CSI2_PAD_SINK , sel->which); +struct v4l2_rect *crop = +ipu6_isys_get_crop (sd, state, sel->pad, sel->which); +int ret =0 ; + +if (sd->entity.pads[sel->pad].flags &MEDIA_PAD_FL_SINK ) +return -EINVAL ; + +mutex_lock (&asd->mutex); +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 ; + } +mutex_unlock (&asd->mutex); + +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, + .link_validate = v4l2_subdev_link_validate_default, + .get_fmt = ipu6_isys_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, +}; + +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 struct media_entity_operations csi2_entity_ops = { + .link_validate = v4l2_subdev_link_validate, +}; + +void ipu6_isys_csi2_cleanup (struct ipu6_isys_csi2 *csi2) +{ +if (!csi2->isys) +return ; + +v4l2_device_unregister_subdev (&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 v4l2_subdev_format fmt = { + .which =V4L2_SUBDEV_FORMAT_ACTIVE , + .pad =CSI2_PAD_SINK , + .format = { + .width =4096 , + .height =3072 , + .code =MEDIA_BUS_FMT_SGRBG10_1X10 , + }, + }; +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_PADS ); +if (ret) + goto fail; + + csi2->asd.pad[CSI2_PAD_SINK ].flags =MEDIA_PAD_FL_SINK + |MEDIA_PAD_FL_MUST_CONNECT ; + csi2->asd.pad[CSI2_PAD_SOURCE ].flags =MEDIA_PAD_FL_SOURCE ; + + csi2->asd.source =IPU6_FW_ISYS_STREAM_SRC_CSI2_PORT0 + index; + csi2->asd.supported_codes = csi2_supported_codes; +ipu6_isys_subdev_set_fmt (&csi2->asd.sd,NULL , &fmt); +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_device_register_subdev (&isys->v4l2_dev, &csi2->asd.sd); +if (ret) { +dev_info (&isys->adev->dev,"can't 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->csi2->asd.sd.devnode; +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 (&stream->isys->adev->dev, +"sof_event::csi2-%i sequence: %i\n" , + stream->csi2->port, ev.u.frame_sync.frame_sequence); +} + +void ipu6_isys_csi2_eof_event_by_stream (struct ipu6_isys_stream *stream) +{ +u32 frame_sequence =atomic_read (&stream->sequence); + +dev_dbg (&stream->isys->adev->dev,"eof_event::csi2-%i sequence: %i\n" , + stream->csi2->port, frame_sequence); +}
drivers/media/pci/intel/ipu6/ipu6-isys-csi2.h new file +75 -0
75 lines not on this page · raw message
drivers/media/pci/intel/ipu6/ipu6-isys-subdev.c new file +309 -0
309 lines not on this page · raw message
drivers/media/pci/intel/ipu6/ipu6-isys-subdev.h new file +70 -0
70 lines not on this page · raw message
drivers/media/pci/intel/ipu6/ipu6-platform-isys-csi2-reg.h new file +187 -0
187 lines not on this page · raw message
Signature · 1 line
2.39.1
RFC PATCH 9/14 media: intel/ipu6: add the CSI2 DPHY implementation
In reply to [email protected]From: Bingbu Cao <[email protected]>
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().
--- .../media/pci/intel/ipu6/ipu6-isys-dwc-phy.c | 549 +++++++++++++ .../media/pci/intel/ipu6/ipu6-isys-jsl-phy.c | 245 ++++++ .../media/pci/intel/ipu6/ipu6-isys-mcd-phy.c | 733 ++++++++++++++++++ drivers/media/pci/intel/ipu6/ipu6-isys-phy.h | 24 + 4 files changed, 1551 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 create mode 100644 drivers/media/pci/intel/ipu6/ipu6-isys-phy.h
drivers/media/pci/intel/ipu6/ipu6-isys-dwc-phy.c new file +549 -0
@@ -0,0 +1,549 @@ +// 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.h" +#include "ipu6-bus.h" +#include "ipu6-buttress.h" +#include "ipu6-isys.h" +#include "ipu6-isys-csi2.h" +#include "ipu6-isys-phy.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) +{ +void __iomem *isys_base = isys->pdata->base; +void __iomem *base = isys_base +IPU6_DWC_DPHY_BASE (phy_id); + +dev_dbg (&isys->adev->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) +{ +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 (&isys->adev->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) +{ +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 (&isys->adev->dev,"ifc request read timeout\n" ); +return ret; + } + + *val = completion >>8 &0xff ; + *val =FIELD_GET (GENMASK (15 ,8 ), completion); +dev_dbg (&isys->adev->dev,"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) +{ +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 (&isys->adev->dev,"ifc request write timeout\n" ); +return ret; + } + +return 0 ; +} + +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) { +dev_err (&isys->adev->dev, +"dphy proxy read failed with %d" , ret); +return ; + } + + mask = (1 << width) -1 ; + temp &= ~(mask << shift); + temp |= (data & mask) << shift; + ret =dwc_dphy_ifc_write (isys, phy_id, addr, temp); +if (ret) +dev_err (&isys->adev->dev,"dphy proxy write failed(%d)" , ret); +} + +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) { +dev_err (&isys->adev->dev,"dphy proxy read failed with %d" , + ret); +return 0 ; + } + +return ((val >> shift) & ((1 << width) -1 )); +} + +static int dwc_dphy_pwr_up (struct ipu6_isys *isys,u32 phy_id) +{ +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 (&isys->adev->dev,"DPHY%d power up failed, state 0x%x" , + phy_id, fsm_state); +return ret; + } + +return 0 ; +} + +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) +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; + +for (i =DPHY_FREQ_RANGE_NUM -1 ; i >=0 ; 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 =to_ipu6_bus_device (&isys->adev->dev); +struct ipu6_device *isp = adev->isp; +u32 cfg_clk_freqrange; +u32 osc_freq_target; +u32 index; + +dev_dbg (&isys->adev->dev,"config phy %u with %u mbps" , phy_id, mbps); + + index =get_hsfreq_by_mbps (mbps); +if (index ==DPHY_FREQ_RANGE_INVALID_INDEX ) { +dev_err (&isys->adev->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 (&isys->adev->dev,"ref_clk = %u clf_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) +{ +u32 rescal_done; +int ret; + + ret =dwc_dphy_pwr_up (isys, phy_id); +if (ret !=0 ) { +dev_err (&isys->adev->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 (&isys->adev->dev,"phy %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 (&isys->adev->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->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) +{ +void __iomem *isys_base = isys->pdata->base; +u32 phy_id, primary, secondary; +u32 nlanes, port, mbps; +s64 link_freq; +int ret =0 ; + + port = cfg->port; + +if (!isys_base || port >= isys->pdata->ipdata->csi2.nports) { +dev_warn (&isys->adev->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 (&isys->adev->dev,"invalid csi-port %u with %u lanes\n" , + port, nlanes); +return -EINVAL ; + } + + ret =ipu6_isys_csi2_get_link_freq (&isys->csi2[port], &link_freq); +if (ret) { +dev_err (&isys->adev->dev, +"get link freq failed(%d).\n" , ret); +return ret; + } + + mbps =div_u64 (link_freq,500000 ); + + phy_id = port; + primary = port & ~1 ; + secondary = primary +1 ; +if (on) { +if (nlanes ==4 ) { +dev_dbg (&isys->adev->dev, +"config phy %u and %u in aggregation mode" , + 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 (&isys->adev->dev, +"config phy %u with %u lanes in non-aggr mode" , + 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 (&isys->adev->dev, +"Powerdown phy %u and phy %u for port %u" , + primary, secondary, port); +ipu6_isys_dwc_phy_reset (isys, secondary); +ipu6_isys_dwc_phy_reset (isys, primary); + +return 0 ; + } + +dev_dbg (&isys->adev->dev, +"Powerdown phy %u with %u lanes" , phy_id, nlanes); + +ipu6_isys_dwc_phy_reset (isys, phy_id); + +return 0 ; +}
drivers/media/pci/intel/ipu6/ipu6-isys-jsl-phy.c new file +245 -0
245 lines not on this page · raw message
drivers/media/pci/intel/ipu6/ipu6-isys-mcd-phy.c new file +733 -0
733 lines not on this page · raw message
drivers/media/pci/intel/ipu6/ipu6-isys-phy.h new file +24 -0
@@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Copyright (C) 2013 - 2023 Intel Corporation +*/ + +#ifndef IPU6_ISYS_PHY_H +#define IPU6_ISYS_PHY_H + +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
Signature · 1 line
2.39.1
RFC PATCH 10/14 media: intel/ipu6: add input system driver
In reply to [email protected]From: Bingbu Cao <[email protected]>
Input system driver do basic isys hardware setup and irq handling and work with fwnode and v4l2 to register the ISYS v4l2 devices.
--- drivers/media/pci/intel/ipu6/ipu6-isys.c | 1325 ++++++++++++++++++++++ drivers/media/pci/intel/ipu6/ipu6-isys.h | 190 ++++ 2 files changed, 1515 insertions(+) create mode 100644 drivers/media/pci/intel/ipu6/ipu6-isys.c create mode 100644 drivers/media/pci/intel/ipu6/ipu6-isys.h
drivers/media/pci/intel/ipu6/ipu6-isys.c new file +1325 -0
@@ -0,0 +1,1325 @@ +// SPDX-License-Identifier: GPL-2.0-only +// Copyright (C) 2013 - 2023 Intel Corporation + +#include <linux/bitfield.h> +#include <linux/debugfs.h> +#include <linux/delay.h> +#include <linux/device.h> +#include <linux/dma-mapping.h> +#include <linux/firmware.h> +#include <linux/module.h> +#include <linux/pm_runtime.h> +#include <linux/string.h> + +#include <media/v4l2-mc.h> +#include <media/v4l2-subdev.h> +#include <media/v4l2-fwnode.h> +#include <media/v4l2-ctrls.h> +#include <media/v4l2-device.h> +#include <media/v4l2-event.h> +#include <media/v4l2-ioctl.h> +#include <media/v4l2-async.h> + +#include "ipu6.h" +#include "ipu6-bus.h" +#include "ipu6-buttress.h" +#include "ipu6-cpd.h" +#include "ipu6-dma.h" +#include "ipu6-isys.h" +#include "ipu6-isys-csi2.h" +#include "ipu6-isys-phy.h" +#include "ipu6-isys-video.h" +#include "ipu6-mmu.h" +#include "ipu6-platform.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_complete_ext_device_registration (struct ipu6_isys *isys, +struct v4l2_subdev *sd, +struct ipu6_isys_csi2_config *csi2) +{ +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 (&isys->adev->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 (&isys->adev->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; + } +} + +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; +unsigned int i; +int ret; + + isys->csi2 =devm_kcalloc (&isys->adev->dev, csi2_pdata->nports, +sizeof (*isys->csi2),GFP_KERNEL ); +if (!isys->csi2) { + ret = -ENOMEM ; + goto fail; + } + +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 ipu6_isys_csi2 *csi2; +unsigned int i, j; +int ret; + +for (i =0 ; i < csi2_pdata->nports; i++) { +for (j =0 ; j <NR_OF_VIDEO_DEVICE ; j++) { + csi2 = &isys->csi2[i]; + ret =media_create_pad_link (&csi2->asd.sd.entity, +CSI2_PAD_SOURCE , + &isys->av[j].vdev.entity, +0 ,MEDIA_LNK_FL_DYNAMIC ); +if (ret) { +dev_info (&isys->adev->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; +u32 status; + +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 ); + + stream =ipu6_isys_query_stream_by_source (csi2->isys, csi2->asd.source); +if (!stream) +return ; + +if (status &IPU6_CSI_RX_IRQ_FS_VC ) +ipu6_isys_csi2_sof_event_by_stream (stream); +if (status &IPU6_CSI_RX_IRQ_FE_VC ) +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 )) && + !isys->adev->isp->flr_done); + +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) +{ +u32 req_id = index; +u32 offset =0 ; +int ret =0 ; + + ret =ipu6_fw_isys_send_proxy_token (isys, req_id, index, offset, value); +if (ret) +dev_err (&isys->adev->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) +{ +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 (&isys->adev->dev,"ltr: %d did: %d" , ltr_val, did_val); +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; +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, <rdid); + +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 (&isys->adev->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 (&isys->adev->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 int 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; + +return 0 ; +} + +static int 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); + +return 0 ; +} + +/* 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_subdev *asd) +{ +struct ipu6_isys *isys = + container_of(notifier, struct ipu6_isys, notifier); +struct sensor_async_subdev *s_asd = + container_of(asd, struct sensor_async_subdev, asd); + +dev_dbg (&isys->adev->dev,"bind %s nlanes is %d port is %d\n" , + sd->name, s_asd->csi2.nlanes, s_asd->csi2.port); +isys_complete_ext_device_registration (isys, sd, &s_asd->csi2); + +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, +}; + +static int isys_fwnode_parse (struct device *dev, +struct v4l2_fwnode_endpoint *vep, +struct v4l2_async_subdev *asd) +{ +struct sensor_async_subdev *s_asd = + container_of(asd, struct sensor_async_subdev, asd); + + s_asd->csi2.port = vep->base.port; + s_asd->csi2.nlanes = vep->bus.mipi_csi2.num_data_lanes; + +return 0 ; +} + +static int isys_notifier_init (struct ipu6_isys *isys) +{ +size_t asd_struct_size =sizeof (struct sensor_async_subdev ); +struct ipu6_device *isp = isys->adev->isp; +int ret; + +v4l2_async_nf_init (&isys->notifier); + ret =v4l2_async_nf_parse_fwnode_endpoints (&isp->pdev->dev, + &isys->notifier, + asd_struct_size, + isys_fwnode_parse); +if (ret <0 ) { +dev_err (&isys->adev->dev, +"parse fwnode endpoints failed: %d\n" , ret); +return ret; + } + +if (list_empty (&isys->notifier.asd_list)) { +/* isys probe could continue with async subdevs missing */ +dev_warn (&isys->adev->dev,"no subdev found in graph\n" ); +return 0 ; + } + + isys->notifier.ops = &isys_async_ops; + ret =v4l2_async_nf_register (&isys->v4l2_dev, &isys->notifier); +if (ret) { +dev_err (&isys->adev->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 pci_dev *pdev = isys->adev->isp->pdev; +int ret; + + isys->media_dev.dev = &isys->adev->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 ) { +dev_err (&isys->adev->dev,"can't register media device\n" ); + goto out_media_device_unregister; + } + + isys->v4l2_dev.mdev = &isys->media_dev; + isys->v4l2_dev.ctrl_handler =NULL ; + + ret =v4l2_device_register (&isys->adev->dev, &isys->v4l2_dev); +if (ret <0 ) { +dev_err (&isys->adev->dev,"can't register v4l2 device\n" ); + 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; + + ret =v4l2_device_register_subdev_nodes (&isys->v4l2_dev); +if (ret) + goto out_isys_notifier_cleanup; + +return 0 ; + +out_isys_notifier_cleanup: +isys_notifier_cleanup (isys); + +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); + +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 =ipu6_bus_get_drvdata (adev); +unsigned long flags; + +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_bus_device *adev =to_ipu6_bus_device (dev); +struct ipu6_isys *isys =ipu6_bus_get_drvdata (adev); + +/* 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 ipu6_bus_device *adev) +{ +struct ipu6_isys *isys =ipu6_bus_get_drvdata (adev); +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 (&adev->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 (&adev->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 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 (&isys->adev->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 (&isys->adev->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 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 (&isys->adev->dev,"Frame list empty - Allocate more" ); + + 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 (&isys->adev->dev,"Frame list empty" ); +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 ipu6_bus_device *adev) +{ +struct ipu6_isys *isys; +struct ipu6_device *isp = adev->isp; +const struct firmware *fw; +unsigned int i; +int ret =0 ; + + isys =devm_kzalloc (&adev->dev,sizeof (*isys),GFP_KERNEL ); +if (!isys) +return -ENOMEM ; + + ret =ipu6_mmu_hw_init (adev->mmu); +if (ret) +return ret; + + 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); + +ipu6_bus_set_drvdata (adev, isys); + + isys->line_align =IPU6_ISYS_2600_MEM_LINE_ALIGN ; + isys->icache_prefetch =0 ; + +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; + + ret =isys_register_devices (isys); +if (ret) + goto out_remove_pkg_dir_shared_buffer; + +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_iwake_watermark_init (isys); +if (ret) + goto out_unregister_devices; + +ipu6_mmu_hw_cleanup (adev->mmu); + +return 0 ; + +out_unregister_devices: +isys_unregister_devices (isys); +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 i -1 ; +} + +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; +u64 ts; + +if (!isys->fwcom) +return 0 ; + + 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->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->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->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->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->dev,"stream of stream_handle %u is unused\n" , + resp->stream_handle); + goto leave; + } + stream->error = resp->error_info.error; + +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_err (&adev->dev, +"%d:No data pin ready handler for pin id %d\n" , + resp->stream_handle, resp->pin_id); +if (stream->csi2) +ipu6_isys_csi2_error (stream->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 : +if (stream->csi2) +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->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 : +if (stream->csi2) +ipu6_isys_csi2_eof_event_by_stream (stream); + +dev_dbg (&adev->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->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 pci_device_id ipu6_pci_tbl[] = { + {PCI_VDEVICE (INTEL ,IPU6_PCI_ID ) }, + {PCI_VDEVICE (INTEL ,IPU6SE_PCI_ID ) }, + {PCI_VDEVICE (INTEL ,IPU6EP_ADL_P_PCI_ID ) }, + {PCI_VDEVICE (INTEL ,IPU6EP_ADL_N_PCI_ID ) }, + {PCI_VDEVICE (INTEL ,IPU6EP_RPL_P_PCI_ID ) }, + {PCI_VDEVICE (INTEL ,IPU6EP_MTL_PCI_ID ) }, + { } +}; + +static struct ipu6_bus_driver isys_driver = { + .probe = isys_probe, + .remove = isys_remove, + .isr = isys_isr, + .id_table = ipu6_pci_tbl, + .drv = { + .name =IPU6_ISYS_NAME , + .owner =THIS_MODULE , + .pm = &isys_pm_ops, + }, +}; + +module_driver (isys_driver, ipu6_bus_register_driver, + ipu6_bus_unregister_driver); + +MODULE_DEVICE_TABLE (pci, ipu6_pci_tbl); + +MODULE_AUTHOR ("Sakari Ailus <[email protected]>" ); +MODULE_AUTHOR ("Tianshu Qiu <[email protected]>" ); +MODULE_AUTHOR ("Bingbu Cao <[email protected]>" ); +MODULE_AUTHOR ("Yunliang Ding <[email protected]>" ); +MODULE_AUTHOR ("Hongju Wang <[email protected]>" ); +MODULE_LICENSE ("GPL" ); +MODULE_DESCRIPTION ("Intel IPU6 input system driver" ); +MODULE_IMPORT_NS (INTEL_IPU6 );
drivers/media/pci/intel/ipu6/ipu6-isys.h new file +190 -0
190 lines not on this page · raw message
Signature · 1 line
2.39.1
RFC PATCH 11/14 media: intel/ipu6: input system video capture nodes
In reply to [email protected]From: Bingbu Cao <[email protected]>
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.
--- .../media/pci/intel/ipu6/ipu6-isys-queue.c | 869 +++++++++++++ .../media/pci/intel/ipu6/ipu6-isys-queue.h | 97 ++ .../media/pci/intel/ipu6/ipu6-isys-video.c | 1132 +++++++++++++++++ .../media/pci/intel/ipu6/ipu6-isys-video.h | 120 ++ 4 files changed, 2218 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
drivers/media/pci/intel/ipu6/ipu6-isys-queue.c new file +869 -0
@@ -0,0 +1,869 @@ +// SPDX-License-Identifier: GPL-2.0-only +// Copyright (C) 2013 - 2023 Intel Corporation + +#include <linux/completion.h> +#include <linux/device.h> +#include <linux/module.h> +#include <linux/string.h> + +#include <media/media-entity.h> +#include <media/videobuf2-dma-contig.h> +#include <media/v4l2-ioctl.h> + +#include "ipu6.h" +#include "ipu6-bus.h" +#include "ipu6-buttress.h" +#include "ipu6-isys.h" +#include "ipu6-isys-csi2.h" +#include "ipu6-isys-video.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_ipu6_isys_queue (q); +struct ipu6_isys_video *av =ipu6_isys_queue_to_video (aq); +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_dbg (&av->isys->adev->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_ipu6_isys_queue (vb->vb2_queue); +struct ipu6_isys_video *av =ipu6_isys_queue_to_video (aq); + +dev_dbg (&av->isys->adev->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_ipu6_isys_queue (vb->vb2_queue); +struct ipu6_isys_video *av =ipu6_isys_queue_to_video (aq); + +if (av->isys->adev->isp->flr_done) +return -EIO ; + +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_ipu6_isys_queue (vb->vb2_queue); + +if (WARN_ON_ONCE (ib->type !=IPU6_ISYS_VIDEO_BUFFER )) +continue ; + + av =ipu6_isys_queue_to_video (aq); +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 (&av->isys->adev->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 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 (&av->isys->adev->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 (&av->isys->adev->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 +* all queues have no buffers, the buffers that were already dequeued +* are returned to their queues. +*/ +static int buffer_list_get (struct ipu6_isys_stream *stream, +struct ipu6_isys_buffer_list *bl) +{ +struct ipu6_isys_queue *aq; +unsigned long flags; +int ret =0 ; + + 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); + ret = -ENODATA ; + goto error; + } + + ib =list_last_entry (&aq->incoming, + struct ipu6_isys_buffer, head); + +dev_dbg (&stream->isys->adev->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 (&stream->isys->adev->dev,"get buffer list %p, %u buffers\n" , + bl, bl->nbufs); + +return ret; + +error: +if (!list_empty (&bl->head)) +ipu6_isys_buffer_list_queue (bl, +IPU6_ISYS_BUFFER_LIST_FL_INCOMING , +0 ); + +return ret; +} + +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_ipu6_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_ipu6_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 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; +enum ipu6_fw_isys_send_type 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 (&stream->isys->adev->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_ipu6_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 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; +unsigned int i; +int ret; + +dev_dbg (&av->isys->adev->dev,"queue buffer %u for %s\n" , + vb->index, av->vdev.name); + +for (i =0 ; i < vb->num_planes; i++) +dev_dbg (&av->isys->adev->dev,"iova: plane %u iova 0x%x\n" , i, + (u32 )vb2_dma_contig_plane_dma_addr (vb, i)); + +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 (&av->isys->adev->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 (&av->isys->adev->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 (&av->isys->adev->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 (&stream->isys->adev->dev, buf, + stream->nr_output_pins); + +if (!stream->streaming) { +dev_dbg (&av->isys->adev->dev, +"got a buffer to start streaming!\n" ); + ret =ipu6_isys_stream_start (av, &bl, true); +if (ret) +dev_err (&av->isys->adev->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 (&av->isys->adev->dev,"send stream capture failed\n" ); + +out: +mutex_unlock (&stream->mutex); +} + +int ipu6_isys_link_fmt_validate (struct ipu6_isys_queue *aq) +{ +struct ipu6_isys_video *av =ipu6_isys_queue_to_video (aq); +struct v4l2_subdev_format fmt = {0 }; +struct media_pad *pad = +media_pad_remote_pad_first (av->vdev.entity.pads); +struct v4l2_subdev *sd; +int ret; + +if (!pad) { +dev_dbg (&av->isys->adev->dev, +"video node %s pad not connected\n" , av->vdev.name); +return -ENOTCONN ; + } + + sd =media_entity_to_v4l2_subdev (pad->entity); + + fmt.which =V4L2_SUBDEV_FORMAT_ACTIVE ; + fmt.pad = pad->index; + ret =v4l2_subdev_call (sd, pad, get_fmt,NULL , &fmt); +if (ret) +return ret; + +if (fmt.format.width != av->mpix.width || + fmt.format.height != av->mpix.height) { +dev_dbg (&av->isys->adev->dev, +"wrong width or height %ux%u (%ux%u expected)\n" , + av->mpix.width, av->mpix.height, + fmt.format.width, fmt.format.height); +return -EINVAL ; + } + +if (fmt.format.field != av->mpix.field) { +dev_dbg (&av->isys->adev->dev, +"wrong field value 0x%8.8x (0x%8.8x expected)\n" , + av->mpix.field, fmt.format.field); +return -EINVAL ; + } + +if (fmt.format.code != av->pfmt->code) { +dev_dbg (&av->isys->adev->dev, +"wrong media bus code 0x%8.8x (0x%8.8x expected)\n" , + av->pfmt->code, fmt.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); +bool need_reset = false; +unsigned long flags; + +spin_lock_irqsave (&aq->lock, flags); +while (!list_empty (&aq->incoming)) { +struct ipu6_isys_buffer *ib =list_first_entry (&aq->incoming, + struct + ipu6_isys_buffer, + head); +struct vb2_buffer *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 (&av->isys->adev->dev, +"%s: stop_streaming incoming %u\n" , +ipu6_isys_queue_to_video (vb2_queue_to_ipu6_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 ipu6_isys_buffer *ib = + list_first_entry(&aq->active, struct ipu6_isys_buffer, + head); +struct vb2_buffer *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 (&av->isys->adev->dev,"%s: cleaning active queue %u\n" , +ipu6_isys_queue_to_video (vb2_queue_to_ipu6_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 int start_streaming (struct vb2_queue *q,unsigned int count) +{ +struct ipu6_isys_queue *aq =vb2_queue_to_ipu6_isys_queue (q); +struct ipu6_isys_video *av =ipu6_isys_queue_to_video (aq); +struct ipu6_isys_buffer_list __bl, *bl =NULL ; +struct ipu6_isys_stream *stream; +int ret; + +dev_dbg (&av->isys->adev->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 =video_device_pipeline_alloc_start (&av->vdev); +if (ret <0 ) { +dev_dbg (&av->isys->adev->dev,"media pipeline start failed\n" ); + goto out_return_buffers; + } + + ret = aq->link_fmt_validate (aq); +if (ret) { +dev_dbg (&av->isys->adev->dev, +"%s: link format validation failed (%d)\n" , + av->vdev.name, ret); + goto out_pipeline_stop; + } + +/* every ipu6_isys_stream is only enabled once */ + av->stream =ipu6_isys_get_stream (av->isys); +if (!av->stream) { +dev_err (&av->isys->adev->dev, +"no available stream for firmware\n" ); + goto out_pipeline_stop; + } + + stream = av->stream; +mutex_lock (&stream->mutex); +if (!stream->nr_streaming) { + ret =ipu6_isys_video_prepare_streaming (av); +if (ret) + goto out_put_stream; + } + + stream->nr_streaming++; +dev_dbg (&av->isys->adev->dev,"queue %u of %u\n" , stream->nr_streaming, + stream->nr_queues); +list_add (&aq->node, &stream->queues); +if (stream->nr_streaming != stream->nr_queues) + goto out; + + bl = &__bl; + ret =buffer_list_get (stream, bl); +if (ret <0 ) { +dev_dbg (&av->isys->adev->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_put_stream: +mutex_unlock (&stream->mutex); +ipu6_isys_put_stream (stream); + av->stream =NULL ; + +out_pipeline_stop: +video_device_pipeline_stop (&av->vdev); + +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_ipu6_isys_queue (q); +struct ipu6_isys_video *av =ipu6_isys_queue_to_video (aq); +struct ipu6_isys_stream *stream = av->stream; + +mutex_lock (&stream->mutex); + +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); + +video_device_pipeline_stop (&av->vdev); + av->stream =NULL ; + + stream->nr_streaming--; +list_del (&aq->node); + stream->streaming =0 ; + +mutex_unlock (&stream->mutex); +ipu6_isys_put_stream (stream); + +return_buffers (aq,VB2_BUF_STATE_ERROR ); +} + +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; +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 (&isys->adev->dev, +"sof: using seq nr %u for ts %llu\n" , + stream->seq[i].sequence, time); +return stream->seq[i].sequence; + } + +dev_dbg (&isys->adev->dev,"SOF: looking for %llu\n" , time); +for (i =0 ; i <IPU6_ISYS_MAX_PARALLEL_SOF ; i++) +dev_dbg (&isys->adev->dev, +"SOF: sequence %u, timestamp value %llu\n" , + stream->seq[i].sequence, stream->seq[i].timestamp); +dev_dbg (&isys->adev->dev,"SOF sequence number not found\n" ); + +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 =to_ipu6_bus_device (&av->isys->adev->dev); +struct ipu6_device *isp = adev->isp; +u64 delta, tsc_now; + +if (!ipu6_buttress_tsc_read (isp, &tsc_now)) + delta = tsc_now - + ((u64 )info->timestamp[1 ] <<32 | info->timestamp[0 ]); +else + delta =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_ipu6_isys_queue (vb->vb2_queue); +struct ipu6_isys_video *av =ipu6_isys_queue_to_video (aq); +struct device *dev = &av->isys->adev->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, endl\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 ipu6_isys_buffer *ib; +struct vb2_buffer *vb; +unsigned long flags; +bool first = true; +struct vb2_v4l2_buffer *buf; + +dev_dbg (&isys->adev->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 (&isys->adev->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 (&isys->adev->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 (&isys->adev->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 (&isys->adev->dev, +"WARNING: cannot find a matching video buffer!\n" ); + +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->dev; + aq->vbq.dev = &isys->adev->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); +}
drivers/media/pci/intel/ipu6/ipu6-isys-queue.h new file +97 -0
97 lines not on this page · raw message
drivers/media/pci/intel/ipu6/ipu6-isys-video.c new file +1132 -0
1,132 lines not on this page · raw message
drivers/media/pci/intel/ipu6/ipu6-isys-video.h new file +120 -0
120 lines not on this page · raw message
Signature · 1 line
2.39.1
RFC PATCH 12/14 media: add Kconfig and Makefile for IPU6
In reply to [email protected]From: Bingbu Cao <[email protected]>
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.
--- drivers/media/pci/Kconfig | 1 + drivers/media/pci/intel/Makefile | 3 ++- drivers/media/pci/intel/ipu6/Kconfig | 15 +++++++++++++++ drivers/media/pci/intel/ipu6/Makefile | 23 +++++++++++++++++++++++ 4 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 drivers/media/pci/intel/ipu6/Kconfig create mode 100644 drivers/media/pci/intel/ipu6/Makefile
drivers/media/pci/Kconfig +1 -0
@@ -74,6 +74,7 @@ config VIDEO_PCI_SKELETON when developing new drivers. source "drivers/media/pci/intel/ipu3/Kconfig" +source "drivers/media/pci/intel/ipu6/Kconfig" endif #MEDIA_PCI_SUPPORT endif #PCI
drivers/media/pci/intel/Makefile +2 -1
@@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only # -# Makefile for the IPU3 cio2 and ImGU drivers +# Makefile for the Intel IPU drivers # obj-y += ipu3/ +obj-$(CONFIG_VIDEO_INTEL_IPU6) += ipu6/
drivers/media/pci/intel/ipu6/Kconfig new file +15 -0
@@ -0,0 +1,15 @@ +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_64 + select IOMMU_IOVA + select VIDEOBUF2_DMA_CONTIG + select V4L2_FWNODE + 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.
drivers/media/pci/intel/ipu6/Makefile new file +23 -0
@@ -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
Signature · 1 line
2.39.1
kernel test robot
build botRe: [RFC PATCH 12/14] media: add Kconfig and Makefile for IPU6
kernel test robot noticed the following build errors:
Hi,
[This is a private test report for your RFC patch.] kernel test robot noticed the following build errors:
[auto build test ERROR on media-tree/master]
[also build test ERROR on linus/master sailus-media-tree/streams v6.3-rc6] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/bingbu-cao-intel-com/media-intel-ipu6-add-Intel-IPU6-PCI-device-driver/20230413-175746 base: git://linuxtv.org/media_tree.git master patch link: https://lore.kernel.org/r/20230413100429.919622-13-bingbu.cao%40intel.com patch subject: [RFC PATCH 12/14] media: add Kconfig and Makefile for IPU6 config: um-allyesconfig (https://download.01.org/0day-ci/archive/20230417/[email protected]/config) compiler: gcc-11 (Debian 11.3.0-8) 11.3.0
reproduce (this is a W=1 build):
# https://github.com/intel-lab-lkp/linux/commit/845e01f6490aadbb154545367590d2dc73e08014
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review bingbu-cao-intel-com/media-intel-ipu6-add-Intel-IPU6-PCI-device-driver/20230413-175746 git checkout 845e01f6490aadbb154545367590d2dc73e08014
# save the config file
mkdir build_dir && cp config build_dir/.config
make W=1 O=build_dir ARCH=um olddefconfig
make W=1 O=build_dir ARCH=um SHELL=/bin/bash
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
drivers/media/pci/intel/ipu6/ipu6-fw-isys.c: In function 'ipu6_fw_isys_complex_cmd':
>> drivers/media/pci/intel/ipu6/ipu6-fw-isys.c:185:17: error: implicit declaration of function 'clflush_cache_range'; did you mean 'flush_cache_range'? [-Werror=implicit-function-declaration]
185 | clflush_cache_range(cpu_mapped_buf, size);
| ^~~~~~~~~~~~~~~~~~~
| flush_cache_range
cc1: some warnings being treated as errors
--
drivers/media/pci/intel/ipu6/ipu6-dma.c: In function '__dma_clear_buffer':
>> drivers/media/pci/intel/ipu6/ipu6-dma.c:55:17: error: implicit declaration of function 'clflush_cache_range'; did you mean 'flush_cache_range'? [-Werror=implicit-function-declaration]
55 | clflush_cache_range(ptr, size);
| ^~~~~~~~~~~~~~~~~~~
| flush_cache_range
cc1: some warnings being treated as errors
--
drivers/media/pci/intel/ipu6/ipu6-mmu.c: In function 'l2_map':
>> drivers/media/pci/intel/ipu6/ipu6-mmu.c:280:17: error: implicit declaration of function 'clflush_cache_range'; did you mean 'flush_cache_range'? [-Werror=implicit-function-declaration]
280 | clflush_cache_range(&mmu_info->l1_pt[l1_idx],
| ^~~~~~~~~~~~~~~~~~~
| flush_cache_rangecc1: some warnings being treated as errors
vim +185 drivers/media/pci/intel/ipu6/ipu6-fw-isys.c
25a1e8d166c011 Bingbu Cao 2023-04-13 164
25a1e8d166c011 Bingbu Cao 2023-04-13 165 int ipu6_fw_isys_complex_cmd(struct ipu6_isys *isys,
25a1e8d166c011 Bingbu Cao 2023-04-13 166 const unsigned int stream_handle,
25a1e8d166c011 Bingbu Cao 2023-04-13 167 void *cpu_mapped_buf,
25a1e8d166c011 Bingbu Cao 2023-04-13 168 dma_addr_t dma_mapped_buf,
25a1e8d166c011 Bingbu Cao 2023-04-13 169 size_t size, u16 send_type)
25a1e8d166c011 Bingbu Cao 2023-04-13 170 {
25a1e8d166c011 Bingbu Cao 2023-04-13 171 struct ipu6_fw_com_context *ctx = isys->fwcom;
25a1e8d166c011 Bingbu Cao 2023-04-13 172 struct ipu6_fw_send_queue_token *token;
25a1e8d166c011 Bingbu Cao 2023-04-13 173
25a1e8d166c011 Bingbu Cao 2023-04-13 174 if (send_type >= N_IPU6_FW_ISYS_SEND_TYPE)
25a1e8d166c011 Bingbu Cao 2023-04-13 175 return -EINVAL;
25a1e8d166c011 Bingbu Cao 2023-04-13 176
25a1e8d166c011 Bingbu Cao 2023-04-13 177 dev_dbg(&isys->adev->dev, "send_token: %s\n",
25a1e8d166c011 Bingbu Cao 2023-04-13 178 send_msg_types[send_type]);
25a1e8d166c011 Bingbu Cao 2023-04-13 179
25a1e8d166c011 Bingbu Cao 2023-04-13 180 /*
25a1e8d166c011 Bingbu Cao 2023-04-13 181 * Time to flush cache in case we have some payload. Not all messages
25a1e8d166c011 Bingbu Cao 2023-04-13 182 * have that
25a1e8d166c011 Bingbu Cao 2023-04-13 183 */
25a1e8d166c011 Bingbu Cao 2023-04-13 184 if (cpu_mapped_buf)
25a1e8d166c011 Bingbu Cao 2023-04-13 @185 clflush_cache_range(cpu_mapped_buf, size);
25a1e8d166c011 Bingbu Cao 2023-04-13 186
25a1e8d166c011 Bingbu Cao 2023-04-13 187 token = ipu6_send_get_token(ctx,
25a1e8d166c011 Bingbu Cao 2023-04-13 188 stream_handle + IPU6_BASE_MSG_SEND_QUEUES);
25a1e8d166c011 Bingbu Cao 2023-04-13 189 if (!token)
25a1e8d166c011 Bingbu Cao 2023-04-13 190 return -EBUSY;
25a1e8d166c011 Bingbu Cao 2023-04-13 191
25a1e8d166c011 Bingbu Cao 2023-04-13 192 token->payload = dma_mapped_buf;
25a1e8d166c011 Bingbu Cao 2023-04-13 193 token->buf_handle = (unsigned long)cpu_mapped_buf;
25a1e8d166c011 Bingbu Cao 2023-04-13 194 token->send_type = send_type;
25a1e8d166c011 Bingbu Cao 2023-04-13 195
25a1e8d166c011 Bingbu Cao 2023-04-13 196 ipu6_send_put_token(ctx, stream_handle + IPU6_BASE_MSG_SEND_QUEUES);
25a1e8d166c011 Bingbu Cao 2023-04-13 197
25a1e8d166c011 Bingbu Cao 2023-04-13 198 return 0;
25a1e8d166c011 Bingbu Cao 2023-04-13 199 }
25a1e8d166c011 Bingbu Cao 2023-04-13 200 Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests
Re: [RFC PATCH 12/14] media: add Kconfig and Makefile for IPU6
In reply to [email protected]Hi Bingbu,
Thank you for the patch. I'm happy to see this series landing on the mailing list. I'm starting the review with the easy pieces :-)
Quoted 47 lines · On Thu, Apr 13, 2023 at 06:04:27PM +0800, [email protected] wrote:
From: Bingbu Cao <[email protected]>
Add IPU6 support in
KconfigandMakefile, with this patch you can build the Intel IPU6 and input system modules by select theCONFIG_VIDEO_INTEL_IPU6in config.Signed-off-by Bingbu Cao <[email protected]>--- drivers/media/pci/Kconfig | 1 + drivers/media/pci/intel/Makefile | 3 ++- drivers/media/pci/intel/ipu6/Kconfig | 15 +++++++++++++++ drivers/media/pci/intel/ipu6/Makefile | 23 +++++++++++++++++++++++ 4 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 drivers/media/pci/intel/ipu6/Kconfig create mode 100644 drivers/media/pci/intel/ipu6/Makefiledrivers/media/pci/Kconfig +1
-0@@ -74,6 +74,7 @@ config VIDEO_PCI_SKELETON when developing new drivers. source "drivers/media/pci/intel/ipu3/Kconfig" +source "drivers/media/pci/intel/ipu6/Kconfig" endif #MEDIA_PCI_SUPPORT endif #PCIdrivers/media/pci/intel/Makefile +2
-1@@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only # -# Makefile for the IPU3 cio2 and ImGU drivers +# Makefile for the Intel IPU drivers # obj-y += ipu3/ +obj-$(CONFIG_VIDEO_INTEL_IPU6) += ipu6/drivers/media/pci/intel/ipu6/Kconfig new file +0
-0
drivers/media/pci/intel/ipu6/Kconfig line 1
Quoted 1 line
drivers/media/pci/intel/ipu6/Kconfig new file +1
-0@@ -0,0 +1,15 @@ +config VIDEO_INTEL_IPU6
As there will (hopefully) be a driver for the processing system in the future, should this Kconfig symbol be named with a reference to the input system already (and the help text be updated accordingly) ? The name "IPU6" covers both. Or do you envision that we would have a single Kconfig symbol to select both drivers ?
drivers/media/pci/intel/ipu6/Kconfig line 6
Quoted 5 lines
drivers/media/pci/intel/ipu6/Kconfig new file +5
-0+ tristate "Intel IPU6 driver" + depends on ACPI || COMPILE_TEST + depends on MEDIA_SUPPORT + depends on MEDIA_PCI_SUPPORT + depends on X86_64
Do you use any x86-64 API, or could this be
depends on X86_64 || COMPILE_TEST
?
Quoted 38 lines
drivers/media/pci/intel/ipu6/Kconfig new file +9
-0+ select IOMMU_IOVA + select VIDEOBUF2_DMA_CONTIG + select V4L2_FWNODE + 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.drivers/media/pci/intel/ipu6/Makefile new file +23
-0@@ -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
Signature · 3 lines
Regards, Laurent Pinchart
Sakari Ailus
maintainerRe: [RFC PATCH 12/14] media: add Kconfig and Makefile for IPU6
Hi Laurent,
Quoted 45 lines · Laurent Pinchart
Hi Bingbu,
Thank you for the patch. I'm happy to see this series landing on the mailing list. I'm starting the review with the easy pieces :-)
Quoted 39 lines · On Thu, Apr 13, 2023 at 06:04:27PM +0800, [email protected] wrote:
From: Bingbu Cao <[email protected]>
Add IPU6 support in
KconfigandMakefile, with this patch you can build the Intel IPU6 and input system modules by select theCONFIG_VIDEO_INTEL_IPU6in config.Signed-off-by Bingbu Cao <[email protected]>--- drivers/media/pci/Kconfig | 1 + drivers/media/pci/intel/Makefile | 3 ++- drivers/media/pci/intel/ipu6/Kconfig | 15 +++++++++++++++ drivers/media/pci/intel/ipu6/Makefile | 23 +++++++++++++++++++++++ 4 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 drivers/media/pci/intel/ipu6/Kconfig create mode 100644 drivers/media/pci/intel/ipu6/Makefiledrivers/media/pci/Kconfig +1
-0@@ -74,6 +74,7 @@ config VIDEO_PCI_SKELETON when developing new drivers. source "drivers/media/pci/intel/ipu3/Kconfig" +source "drivers/media/pci/intel/ipu6/Kconfig" endif #MEDIA_PCI_SUPPORT endif #PCIdrivers/media/pci/intel/Makefile +1
-1@@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only # -# Makefile for the IPU3 cio2 and ImGU drivers +# Makefile for the Intel IPU drivers #
Quoted 15 lines
drivers/media/pci/intel/ipu6/Kconfig line 1
Quoted 9 lines
drivers/media/pci/intel/Makefile +1
-0obj-y += ipu3/ +obj-$(CONFIG_VIDEO_INTEL_IPU6) += ipu6/drivers/media/pci/intel/ipu6/Kconfig new file +1
-0@@ -0,0 +1,15 @@ +config VIDEO_INTEL_IPU6As there will (hopefully) be a driver for the processing system in the future, should this
Kconfigsymbol be named with a reference to the input system already (and the help text be updated accordingly) ? The name "IPU6" covers both. Or do you envision that we would have a singleKconfigsymbol to select both drivers ?
I'm fine with just one option. Much of the code is shared by both drivers.
I don't object adding an option for both (starting with ISYS) though.
Quoted 9 lines
drivers/media/pci/intel/ipu6/Kconfig line 6
Quoted 6 lines
drivers/media/pci/intel/ipu6/Kconfig new file +5
-0+ tristate "Intel IPU6 driver" + depends on ACPI || COMPILE_TEST + depends on MEDIA_SUPPORT + depends on MEDIA_PCI_SUPPORT + depends on X86_64Do you use any x86-64 API, or could this be
Quoted 3 lines
depends on X86_64 || COMPILE_TEST?
The driver uses cache related APIs that are available on x86 only.
I think in the long run we should have better non-coherent memory support for x86 API-wise but I don't think this driver should wait for that. But once we do, this dependency can be removed.
Signature · 3 lines
Kind regards, Sakari Ailus
RFC PATCH 13/14 Documentation: add Intel IPU6 ISYS driver admin-guide doc
In reply to [email protected]From: Bingbu Cao <[email protected]>
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.
--- Documentation/admin-guide/media/ipu6-isys.rst | 128 +++++++ .../admin-guide/media/ipu6_isys_graph.svg | 338 ++++++++++++++++++ .../admin-guide/media/v4l-drivers.rst | 1 + 3 files changed, 467 insertions(+) create mode 100644 Documentation/admin-guide/media/ipu6-isys.rst create mode 100644 Documentation/admin-guide/media/ipu6_isys_graph.svg
Documentation/admin-guide/media/ipu6-isys.rst new file +128 -0
@@ -0,0 +1,128 @@ +.. 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 work as MIPI CSI2 receiver which receive and process 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 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. + +Input system driver +=================== + +Input System driver mainly configure CSI2 DPHY, construct the firmware stream +configuration and send commands to firmware and get response from hardware and +firmware and then return 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 + +Capturing frames by IPU6 ISYS +------------------------------------ + +IPU6 ISYS is used to capture frames from the camera sensors connected to the +CSI2 port. 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 + + # 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]" + + # 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]" + media-ctl -d $MDEV -l "\"Intel IPU6 CSI2 2\":1 ->\"Intel IPU6 ISYS Capture 0\":0[5]" + +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. + + +References +========== + +.. [#f1] https://git.ideasonboard.org/?p=media-ctl.git;a=summary +.. [#f2] https://git.ideasonboard.org/yavta.git
Documentation/admin-guide/media/ipu6_isys_graph.svg new file +338 -0
338 lines not on this page · raw message
Documentation/admin-guide/media/v4l-drivers.rst +1 -0
@@ -16,6 +16,7 @@ Video4Linux (V4L) driver-specific documentation imx imx7 ipu3 + ipu6-isys ivtv omap3isp omap4_camera
Signature · 1 line
2.39.1
Re: [RFC PATCH 13/14] Documentation: add Intel IPU6 ISYS driver admin-guide doc
Hi Bingbu,
Thank you for the patch.
Quoted 41 lines · On Thu, Apr 13, 2023 at 06:04:28PM +0800, [email protected] wrote:
From: Bingbu Cao <[email protected]>
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 <[email protected]>--- Documentation/admin-guide/media/ipu6-isys.rst | 128 +++++++ .../admin-guide/media/ipu6_isys_graph.svg | 338 ++++++++++++++++++ .../admin-guide/media/v4l-drivers.rst | 1 + 3 files changed, 467 insertions(+) create mode 100644 Documentation/admin-guide/media/ipu6-isys.rst create mode 100644 Documentation/admin-guide/media/ipu6_isys_graph.svgDocumentation/admin-guide/media/ipu6-isys.rst new file +20
-0@@ -0,0 +1,128 @@ +.. 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: +
Documentation/admin-guide/media/ipu6-isys.rst line 30
Quoted 10 lines
Documentation/admin-guide/media/ipu6-isys.rst new file +10
-0+* TigerLake +* JasperLake +* AlderLake +* RaptorLake +* MeteorLake + +Intel IPU6 is made up of two components - Input System (ISYS) and Processing +System (PSYS). + +The Input System mainly work as MIPI CSI2 receiver which receive and process the
s/work/works/
s/receive/receives/
s/process/processes/
Documentation/admin-guide/media/ipu6-isys.rst line 33
Quoted 3 lines
Documentation/admin-guide/media/ipu6-isys.rst new file +3
-0+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 IPU6
s/is IPU6/is an IPU6/
Documentation/admin-guide/media/ipu6-isys.rst line 38
Quoted 5 lines
Documentation/admin-guide/media/ipu6-isys.rst new file +5
-0+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.
Will the intel_ipu6 driver also serve a future intel_ipu6_psys driver, or is it specific to the ISYS ?
Documentation/admin-guide/media/ipu6-isys.rst line 43
Quoted 5 lines
Documentation/admin-guide/media/ipu6-isys.rst new file +5
-0+ +Input system driver +=================== + +Input System driver mainly configure CSI2 DPHY, construct the firmware stream
s/^Input/The Input/
s/configure/configures the/
s/construct/constructs/
Documentation/admin-guide/media/ipu6-isys.rst line 44
Quoted 1 line
Documentation/admin-guide/media/ipu6-isys.rst new file +1
-0+configuration and send commands to firmware and get response from hardware and
s/send/sends/
s/get response/gets responses/
Documentation/admin-guide/media/ipu6-isys.rst line 45
Quoted 1 line
Documentation/admin-guide/media/ipu6-isys.rst new file +1
-0+firmware and then return buffers to user.
s/return/returns/
So control of the ISYS goes through the firmware, the driver doesn't access the hardware directly ?
Documentation/admin-guide/media/ipu6-isys.rst line 52
Quoted 7 lines
Documentation/admin-guide/media/ipu6-isys.rst new file +7
-0+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
I see in the figure 6 CSI-2 receivers and 4 video nodes. Are those CSI-2 receivers independent of each other, or do they share SoCs pins ? For instance, I'm thinking about a use case where you would have 4 data lanes and 2 clock lanes, and support capturing from 2x 2-lanes sensors with 2 CSI-2 RX, or 1x 4-lanes sensor with 1 CSI-2 RX. More generally, can you document the input options of the ISYS ? For DT-based systems I'd expect this information to be in the DT bindings, here it needs to be documented separately.
On the video device node side, are there 4 independent hardware DMA engines that can be dynamically connected to the different CSI-2 receivers, or is that what the current firmware version provide, with the hardware able to capture more than 4 streams with firmware modifications ?
Documentation/admin-guide/media/ipu6-isys.rst line 58
Quoted 6 lines
Documentation/admin-guide/media/ipu6-isys.rst new file +6
-0+ +Capturing frames by IPU6 ISYS +------------------------------------ + +IPU6 ISYS is used to capture frames from the camera sensors connected to the +CSI2 port. The supported input formats of ISYS are listed in table below:
s/port/ports/
Documentation/admin-guide/media/ipu6-isys.rst line 69
Quoted 11 lines
Documentation/admin-guide/media/ipu6-isys.rst new file +11
-0+ +.. tabularcolumns:: |p{0.8cm}|p{4.0cm}|p{4.0cm}| + +.. flat-table:: + :header-rows: 1 + + * - IPU6 ISYS supported input formats + + * - RGB565, RGB888 + + * - UYVY8, YUYV8
Unless I'm mistaken, CSI-2 doesn't have separate UYVY and YUYV formats. Am I missing something ?
Documentation/admin-guide/media/ipu6-isys.rst line 71
Quoted 2 lines
Documentation/admin-guide/media/ipu6-isys.rst new file +2
-0+ + * - RAW8, RAW10, RAW12
Is embedded data capture supported ? More generically, can we capture different data types and/or virtual channels from the same CSI-2 input ?
What's the maximum resolution supported by the ISYS ? Are the DMA engines independent, or would the maximum resolution be different if you capture from a single camera sensor or multiple camera sensors at the same time ?
Quoted 413 lines
Documentation/admin-guide/media/ipu6-isys.rst new file +57
-0+ +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 + + # 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]" + + # 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]" + media-ctl -d $MDEV -l "\"Intel IPU6 CSI2 2\":1 ->\"Intel IPU6 ISYS Capture 0\":0[5]" + +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. + + +References +========== + +.. [#f1] https://git.ideasonboard.org/?p=media-ctl.git;a=summary +.. [#f2] https://git.ideasonboard.org/yavta.gitDocumentation/admin-guide/media/ipu6_isys_graph.svg new file +338
-0@@ -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-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->n00000001 --> +<g id="edge1" class="edge"> +<title>n00000011:port1->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->n00000005 --> +<g id="edge2" class="edge"> +<title>n00000011:port1->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->n00000009 --> +<g id="edge3" class="edge"> +<title>n00000011:port1->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->n0000000d --> +<g id="edge4" class="edge"> +<title>n00000011:port1->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-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->n00000001 --> +<g id="edge5" class="edge"> +<title>n00000014:port1->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->n00000005 --> +<g id="edge6" class="edge"> +<title>n00000014:port1->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->n00000009 --> +<g id="edge7" class="edge"> +<title>n00000014:port1->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->n0000000d --> +<g id="edge8" class="edge"> +<title>n00000014:port1->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-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->n00000001 --> +<g id="edge9" class="edge"> +<title>n00000017:port1->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->n00000005 --> +<g id="edge10" class="edge"> +<title>n00000017:port1->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->n00000009 --> +<g id="edge11" class="edge"> +<title>n00000017:port1->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->n0000000d --> +<g id="edge12" class="edge"> +<title>n00000017:port1->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-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->n00000001 --> +<g id="edge13" class="edge"> +<title>n0000001a:port1->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->n00000005 --> +<g id="edge14" class="edge"> +<title>n0000001a:port1->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->n00000009 --> +<g id="edge15" class="edge"> +<title>n0000001a:port1->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->n0000000d --> +<g id="edge16" class="edge"> +<title>n0000001a:port1->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-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->n00000001 --> +<g id="edge17" class="edge"> +<title>n0000001d:port1->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->n00000005 --> +<g id="edge18" class="edge"> +<title>n0000001d:port1->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->n00000009 --> +<g id="edge19" class="edge"> +<title>n0000001d:port1->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->n0000000d --> +<g id="edge20" class="edge"> +<title>n0000001d:port1->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-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->n00000001 --> +<g id="edge21" class="edge"> +<title>n00000020:port1->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->n00000005 --> +<g id="edge22" class="edge"> +<title>n00000020:port1->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->n00000009 --> +<g id="edge23" class="edge"> +<title>n00000020:port1->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->n0000000d --> +<g id="edge24" class="edge"> +<title>n00000020:port1->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-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->n00000001 --> +<g id="edge25" class="edge"> +<title>n00000023:port1->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->n00000005 --> +<g id="edge26" class="edge"> +<title>n00000023:port1->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->n00000009 --> +<g id="edge27" class="edge"> +<title>n00000023:port1->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->n0000000d --> +<g id="edge28" class="edge"> +<title>n00000023:port1->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-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->n00000001 --> +<g id="edge29" class="edge"> +<title>n00000026:port1->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->n00000005 --> +<g id="edge30" class="edge"> +<title>n00000026:port1->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->n00000009 --> +<g id="edge31" class="edge"> +<title>n00000026:port1->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->n0000000d --> +<g id="edge32" class="edge"> +<title>n00000026:port1->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-0036</text> +<text text-anchor="middle" x="711" y="-226.3" font-family="Times,serif" font-size="14.00">/dev/v4l-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->n00000017 --> +<g id="edge33" class="edge"> +<title>n00000069:port0->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>Documentation/admin-guide/media/v4l-drivers.rst +1
-0@@ -16,6 +16,7 @@ Video4Linux (V4L) driver-specific documentation imx imx7 ipu3 + ipu6-isys ivtv omap3isp omap4_camera
Signature · 3 lines
Regards, Laurent Pinchart
Sakari Ailus
maintainerRe: [RFC PATCH 13/14] Documentation: add Intel IPU6 ISYS driver admin-guide doc
Hi Laurent,
On Thu, Apr 20, 2023 at 05:49:17PM +0300, Laurent Pinchart wrote:
...
Quoted 8 lines
Documentation/admin-guide/media/ipu6-isys.rst line 38
Quoted 5 lines
Documentation/admin-guide/media/ipu6-isys.rst new file +5
-0+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.Will the
intel_ipu6driver also serve a futureintel_ipu6_psysdriver, or is it specific to the ISYS ?
intel-ipu6 contains common parts required by both ISYS and PSYS drivers.
Quoted 16 lines
Documentation/admin-guide/media/ipu6-isys.rst line 43
Quoted 6 lines
Documentation/admin-guide/media/ipu6-isys.rst new file +5
-0+ +Input system driver +=================== + +Input System driver mainly configure CSI2 DPHY, construct the firmware streams/^Input/The Input/
s/configure/configures the/
s/construct/constructs/Quoted 1 line
+configuration and send commands to firmware and get response from hardware and
s/send/sends/
s/get response/gets responses/
Quoted 6 lines
Quoted 1 line
+firmware and then return buffers to user.
s/return/returns/
So control of the ISYS goes through the firmware, the driver doesn't access the hardware directly ?
Must of the low-level hardware control takes place through firmware, the ISYS driver uses direct register access mainly for the communication with the ISYS firmware and PHY configuration.
Quoted 17 lines
Documentation/admin-guide/media/ipu6-isys.rst line 52
Quoted 8 lines
Documentation/admin-guide/media/ipu6-isys.rst new file +7
-0+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 graphI see in the figure 6 CSI-2 receivers and 4 video nodes. Are those CSI-2 receivers independent of each other, or do they share SoCs pins ? For instance, I'm thinking about a use case where you would have 4 data lanes and 2 clock lanes, and support capturing from 2x 2-lanes sensors with 2 CSI-2 RX, or 1x 4-lanes sensor with 1 CSI-2 RX. More generally, can you document the input options of the ISYS ? For DT-based systems I'd expect this information to be in the DT bindings, here it needs to be documented separately.
This is a to-do item (as noted on the cover page).
The number of video nodes is also going to change with streams support.
Quoted 31 lines
On the video device node side, are there 4 independent hardware DMA engines that can be dynamically connected to the different CSI-2 receivers, or is that what the current firmware version provide, with the hardware able to capture more than 4 streams with firmware modifications ?
Documentation/admin-guide/media/ipu6-isys.rst line 58
Quoted 6 lines
Documentation/admin-guide/media/ipu6-isys.rst new file +6
-0+ +Capturing frames by IPU6 ISYS +------------------------------------ + +IPU6 ISYS is used to capture frames from the camera sensors connected to the +CSI2 port. The supported input formats of ISYS are listed in table below:s/port/ports/
Documentation/admin-guide/media/ipu6-isys.rst line 69
Quoted 11 lines
Documentation/admin-guide/media/ipu6-isys.rst new file +11
-0+ +.. tabularcolumns:: |p{0.8cm}|p{4.0cm}|p{4.0cm}| + +.. flat-table:: + :header-rows: 1 + + * - IPU6 ISYS supported input formats + + * - RGB565, RGB888 + + * - UYVY8, YUYV8Unless I'm mistaken, CSI-2 doesn't have separate UYVY and YUYV formats. Am I missing something ?
Quoted 5 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ + * - RAW8, RAW10, RAW12Is embedded data capture supported ? More generically, can we capture different data types and/or virtual channels from the same CSI-2 input ?
Yes but not quite yet (streams support is pending).
Quoted 5 lines
What's the maximum resolution supported by the ISYS ? Are the DMA engines independent, or would the maximum resolution be different if you capture from a single camera sensor or multiple camera sensors at the same time ?
My understanding is they're independent, i.e. the maximum resolution isn't affected by what else is happening in the device.
Signature · 3 lines
Regards, Sakari Ailus
RFC PATCH 14/14 MAINTAINERS: add maintainers for Intel IPU6 input system driver
In reply to [email protected]From: Bingbu Cao <[email protected]>
Update MAINTAINERS file for Intel IPU6 input system driver.
--- MAINTAINERS | 10 ++++++++++ 1 file changed, 10 insertions(+)
MAINTAINERS +10 -0
@@ -10376,6 +10376,16 @@ F: Documentation/admin-guide/media/ipu3_rcb.svg F: Documentation/userspace-api/media/v4l/pixfmt-meta-intel-ipu3.rst F: drivers/staging/media/ipu3/ +INTEL IPU6 INPUT SYSTEM DRIVER +M: Sakari Ailus <[email protected]> +M: Bingbu Cao <[email protected]> +R: Tianshu Qiu <[email protected]> +L: [email protected] +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 IXP4XX CRYPTO SUPPORT M: Corentin Labbe <[email protected]> L: [email protected]
Signature · 1 line
2.39.1
Re: [RFC PATCH 14/14] MAINTAINERS: add maintainers for Intel IPU6 input system driver
Hi Bingbu,
Thank you for the patch.
Quoted 5 lines · On Thu, Apr 13, 2023 at 06:04:29PM +0800, [email protected] wrote:
From: Bingbu Cao <[email protected]>
Update
MAINTAINERSfile for Intel IPU6 input system driver.Signed-off-by Bingbu Cao <[email protected]>
Quoted 25 lines
--- MAINTAINERS | 10 ++++++++++ 1 file changed, 10 insertions(+)MAINTAINERS +10
-0@@ -10376,6 +10376,16 @@ F: Documentation/admin-guide/media/ipu3_rcb.svg F: Documentation/userspace-api/media/v4l/pixfmt-meta-intel-ipu3.rst F: drivers/staging/media/ipu3/ +INTEL IPU6 INPUT SYSTEM DRIVER +M: Sakari Ailus <[email protected]> +M: Bingbu Cao <[email protected]> +R: Tianshu Qiu <[email protected]> +L: [email protected] +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 IXP4XX CRYPTO SUPPORT M: Corentin Labbe <[email protected]> L: [email protected]
Signature · 3 lines
Regards, Laurent Pinchart
Hi Bingbu,
Thank you for the patches.
Quoted 7 lines · On Thu, Apr 13, 2023 at 06:04:15PM +0800, [email protected] wrote:
From: Bingbu Cao <[email protected]>
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.
Quoted 6 lines
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 had a look through the series, and it's a bit difficult to understand how the different pieces interact with each other. Would it be possible to provide some high-level documentation for the driver design, as well as a high-level view of the hardware (and firmware) components ? It would help the review process. Documentation/driver-api/media/drivers/ would be a good location for that.
Quoted 98 lines
---
TODOs:
- Add support for multiplexed streams
- Add firmware CSI2 lanes configuration verification and documentation---
Bingbu Cao (13):
media: intel/ipu6: add Intel IPU6 PCI device driver
media: intel/ipu6: add IPU virtual bus driver
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: addKconfigandMakefilefor IPU6
MAINTAINERS: add maintainers for Intel IPU6 input system driverMAINTAINERS | 10 + drivers/media/pci/Kconfig | 1 + drivers/media/pci/intel/Makefile | 3 +- drivers/media/pci/intel/ipu6/Kconfig | 15 + drivers/media/pci/intel/ipu6/Makefile | 23 + drivers/media/pci/intel/ipu6/ipu6-bus.c | 263 ++++ drivers/media/pci/intel/ipu6/ipu6-bus.h | 69 + drivers/media/pci/intel/ipu6/ipu6-buttress.c | 916 ++++++++++++ drivers/media/pci/intel/ipu6/ipu6-buttress.h | 109 ++ drivers/media/pci/intel/ipu6/ipu6-cpd.c | 359 +++++ drivers/media/pci/intel/ipu6/ipu6-cpd.h | 107 ++ drivers/media/pci/intel/ipu6/ipu6-dma.c | 497 ++++++ drivers/media/pci/intel/ipu6/ipu6-dma.h | 19 + drivers/media/pci/intel/ipu6/ipu6-fw-com.c | 417 ++++++ drivers/media/pci/intel/ipu6/ipu6-fw-com.h | 47 + drivers/media/pci/intel/ipu6/ipu6-fw-isys.c | 566 +++++++ drivers/media/pci/intel/ipu6/ipu6-fw-isys.h | 574 +++++++ drivers/media/pci/intel/ipu6/ipu6-isys-csi2.c | 575 +++++++ drivers/media/pci/intel/ipu6/ipu6-isys-csi2.h | 75 + .../media/pci/intel/ipu6/ipu6-isys-dwc-phy.c | 549 +++++++ .../media/pci/intel/ipu6/ipu6-isys-jsl-phy.c | 245 +++ .../media/pci/intel/ipu6/ipu6-isys-mcd-phy.c | 735 +++++++++ drivers/media/pci/intel/ipu6/ipu6-isys-phy.h | 24 + .../media/pci/intel/ipu6/ipu6-isys-queue.c | 869 +++++++++++ .../media/pci/intel/ipu6/ipu6-isys-queue.h | 97 ++ .../media/pci/intel/ipu6/ipu6-isys-subdev.c | 309 ++++ .../media/pci/intel/ipu6/ipu6-isys-subdev.h | 70 + .../media/pci/intel/ipu6/ipu6-isys-video.c | 1132 ++++++++++++++ .../media/pci/intel/ipu6/ipu6-isys-video.h | 120 ++ drivers/media/pci/intel/ipu6/ipu6-isys.c | 1326 +++++++++++++++++ drivers/media/pci/intel/ipu6/ipu6-isys.h | 190 +++ drivers/media/pci/intel/ipu6/ipu6-mmu.c | 833 +++++++++++ drivers/media/pci/intel/ipu6/ipu6-mmu.h | 65 + .../intel/ipu6/ipu6-platform-buttress-regs.h | 231 +++ .../intel/ipu6/ipu6-platform-isys-csi2-reg.h | 187 +++ .../media/pci/intel/ipu6/ipu6-platform-regs.h | 177 +++ drivers/media/pci/intel/ipu6/ipu6-platform.h | 31 + drivers/media/pci/intel/ipu6/ipu6.c | 969 ++++++++++++ drivers/media/pci/intel/ipu6/ipu6.h | 344 +++++ 39 files changed, 13147 insertions(+), 1 deletion(-) 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-phy.h 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-platform.h create mode 100644 drivers/media/pci/intel/ipu6/ipu6.c create mode 100644 drivers/media/pci/intel/ipu6/ipu6.h
Signature · 3 lines
Regards, Laurent Pinchart
Re: [RFC PATCH 00/14] Intel IPU6 and IPU6 input system drivers API)
In reply to [email protected]I tried to build the ipu6 patch series on top of v6.4. I need the following change to be able to build it,
Otherwise I get compilation errors on v4l2_subdev_get_try_format.
drivers/media/pci/intel/ipu6/Kconfig +1 -0
@@ -6,6 +6,7 @@ config VIDEO_INTEL_IPU6 depends on X86_64 select IOMMU_IOVA select VIDEOBUF2_DMA_CONTIG + select VIDEO_V4L2_SUBDEV_API select V4L2_FWNODE help This is the 6th Gen Intel Image Processing Unit, found in Intel SoCs
Signature · 1 line
2.34.1