Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /* Copyright (C) 2017 Intel Corporation */
0003 
0004 #ifndef __IPU3_CIO2_H
0005 #define __IPU3_CIO2_H
0006 
0007 #include <linux/bits.h>
0008 #include <linux/dma-mapping.h>
0009 #include <linux/kernel.h>
0010 #include <linux/mutex.h>
0011 #include <linux/types.h>
0012 
0013 #include <asm/page.h>
0014 
0015 #include <media/media-device.h>
0016 #include <media/media-entity.h>
0017 #include <media/v4l2-async.h>
0018 #include <media/v4l2-dev.h>
0019 #include <media/v4l2-device.h>
0020 #include <media/v4l2-subdev.h>
0021 #include <media/videobuf2-core.h>
0022 #include <media/videobuf2-v4l2.h>
0023 
0024 struct cio2_fbpt_entry;     /* defined here, after the first usage */
0025 struct pci_dev;
0026 
0027 #define CIO2_NAME                   "ipu3-cio2"
0028 #define CIO2_DEVICE_NAME                "Intel IPU3 CIO2"
0029 #define CIO2_ENTITY_NAME                "ipu3-csi2"
0030 #define CIO2_PCI_ID                 0x9d32
0031 #define CIO2_PCI_BAR                    0
0032 #define CIO2_DMA_MASK                   DMA_BIT_MASK(39)
0033 
0034 #define CIO2_IMAGE_MAX_WIDTH                4224U
0035 #define CIO2_IMAGE_MAX_HEIGHT               3136U
0036 
0037 /* 32MB = 8xFBPT_entry */
0038 #define CIO2_MAX_LOPS                   8
0039 #define CIO2_MAX_BUFFERS            (PAGE_SIZE / 16 / CIO2_MAX_LOPS)
0040 #define CIO2_LOP_ENTRIES            (PAGE_SIZE / sizeof(u32))
0041 
0042 #define CIO2_PAD_SINK                   0U
0043 #define CIO2_PAD_SOURCE                 1U
0044 #define CIO2_PADS                   2U
0045 
0046 #define CIO2_NUM_DMA_CHAN               20U
0047 #define CIO2_NUM_PORTS                  4U /* DPHYs */
0048 
0049 /* 1 for each sensor */
0050 #define CIO2_QUEUES                 CIO2_NUM_PORTS
0051 
0052 /* Register and bit field definitions */
0053 #define CIO2_REG_PIPE_BASE(n)           ((n) * 0x0400)  /* n = 0..3 */
0054 #define CIO2_REG_CSIRX_BASE             0x000
0055 #define CIO2_REG_MIPIBE_BASE                0x100
0056 #define CIO2_REG_PIXELGEN_BAS               0x200
0057 #define CIO2_REG_IRQCTRL_BASE               0x300
0058 #define CIO2_REG_GPREG_BASE             0x1000
0059 
0060 /* base register: CIO2_REG_PIPE_BASE(pipe) * CIO2_REG_CSIRX_BASE */
0061 #define CIO2_REG_CSIRX_ENABLE           (CIO2_REG_CSIRX_BASE + 0x0)
0062 #define CIO2_REG_CSIRX_NOF_ENABLED_LANES    (CIO2_REG_CSIRX_BASE + 0x4)
0063 #define CIO2_REG_CSIRX_SP_IF_CONFIG     (CIO2_REG_CSIRX_BASE + 0x10)
0064 #define CIO2_REG_CSIRX_LP_IF_CONFIG     (CIO2_REG_CSIRX_BASE + 0x14)
0065 #define CIO2_CSIRX_IF_CONFIG_FILTEROUT          0x00
0066 #define CIO2_CSIRX_IF_CONFIG_FILTEROUT_VC_INACTIVE  0x01
0067 #define CIO2_CSIRX_IF_CONFIG_PASS           0x02
0068 #define CIO2_CSIRX_IF_CONFIG_FLAG_ERROR         BIT(2)
0069 #define CIO2_REG_CSIRX_STATUS           (CIO2_REG_CSIRX_BASE + 0x18)
0070 #define CIO2_REG_CSIRX_STATUS_DLANE_HS      (CIO2_REG_CSIRX_BASE + 0x1c)
0071 #define CIO2_CSIRX_STATUS_DLANE_HS_MASK         0xff
0072 #define CIO2_REG_CSIRX_STATUS_DLANE_LP      (CIO2_REG_CSIRX_BASE + 0x20)
0073 #define CIO2_CSIRX_STATUS_DLANE_LP_MASK         0xffffff
0074 /* Termination enable and settle in 0.0625ns units, lane=0..3 or -1 for clock */
0075 #define CIO2_REG_CSIRX_DLY_CNT_TERMEN(lane) \
0076                 (CIO2_REG_CSIRX_BASE + 0x2c + 8 * (lane))
0077 #define CIO2_REG_CSIRX_DLY_CNT_SETTLE(lane) \
0078                 (CIO2_REG_CSIRX_BASE + 0x30 + 8 * (lane))
0079 /* base register: CIO2_REG_PIPE_BASE(pipe) * CIO2_REG_MIPIBE_BASE */
0080 #define CIO2_REG_MIPIBE_ENABLE      (CIO2_REG_MIPIBE_BASE + 0x0)
0081 #define CIO2_REG_MIPIBE_STATUS      (CIO2_REG_MIPIBE_BASE + 0x4)
0082 #define CIO2_REG_MIPIBE_COMP_FORMAT(vc) \
0083                 (CIO2_REG_MIPIBE_BASE + 0x8 + 0x4 * (vc))
0084 #define CIO2_REG_MIPIBE_FORCE_RAW8  (CIO2_REG_MIPIBE_BASE + 0x20)
0085 #define CIO2_REG_MIPIBE_FORCE_RAW8_ENABLE       BIT(0)
0086 #define CIO2_REG_MIPIBE_FORCE_RAW8_USE_TYPEID       BIT(1)
0087 #define CIO2_REG_MIPIBE_FORCE_RAW8_TYPEID_SHIFT     2U
0088 
0089 #define CIO2_REG_MIPIBE_IRQ_STATUS  (CIO2_REG_MIPIBE_BASE + 0x24)
0090 #define CIO2_REG_MIPIBE_IRQ_CLEAR   (CIO2_REG_MIPIBE_BASE + 0x28)
0091 #define CIO2_REG_MIPIBE_GLOBAL_LUT_DISREGARD (CIO2_REG_MIPIBE_BASE + 0x68)
0092 #define CIO2_MIPIBE_GLOBAL_LUT_DISREGARD        1U
0093 #define CIO2_REG_MIPIBE_PKT_STALL_STATUS (CIO2_REG_MIPIBE_BASE + 0x6c)
0094 #define CIO2_REG_MIPIBE_PARSE_GSP_THROUGH_LP_LUT_REG_IDX \
0095                     (CIO2_REG_MIPIBE_BASE + 0x70)
0096 #define CIO2_REG_MIPIBE_SP_LUT_ENTRY(vc) \
0097                        (CIO2_REG_MIPIBE_BASE + 0x74 + 4 * (vc))
0098 #define CIO2_REG_MIPIBE_LP_LUT_ENTRY(m) /* m = 0..15 */ \
0099                     (CIO2_REG_MIPIBE_BASE + 0x84 + 4 * (m))
0100 #define CIO2_MIPIBE_LP_LUT_ENTRY_DISREGARD      1U
0101 #define CIO2_MIPIBE_LP_LUT_ENTRY_SID_SHIFT      1U
0102 #define CIO2_MIPIBE_LP_LUT_ENTRY_VC_SHIFT       5U
0103 #define CIO2_MIPIBE_LP_LUT_ENTRY_FORMAT_TYPE_SHIFT  7U
0104 
0105 /* base register: CIO2_REG_PIPE_BASE(pipe) * CIO2_REG_IRQCTRL_BASE */
0106 /* IRQ registers are 18-bit wide, see cio2_irq_error for bit definitions */
0107 #define CIO2_REG_IRQCTRL_EDGE       (CIO2_REG_IRQCTRL_BASE + 0x00)
0108 #define CIO2_REG_IRQCTRL_MASK       (CIO2_REG_IRQCTRL_BASE + 0x04)
0109 #define CIO2_REG_IRQCTRL_STATUS     (CIO2_REG_IRQCTRL_BASE + 0x08)
0110 #define CIO2_REG_IRQCTRL_CLEAR      (CIO2_REG_IRQCTRL_BASE + 0x0c)
0111 #define CIO2_REG_IRQCTRL_ENABLE     (CIO2_REG_IRQCTRL_BASE + 0x10)
0112 #define CIO2_REG_IRQCTRL_LEVEL_NOT_PULSE    (CIO2_REG_IRQCTRL_BASE + 0x14)
0113 
0114 #define CIO2_REG_GPREG_SRST     (CIO2_REG_GPREG_BASE + 0x0)
0115 #define CIO2_GPREG_SRST_ALL             0xffff  /* Reset all */
0116 #define CIO2_REG_FB_HPLL_FREQ       (CIO2_REG_GPREG_BASE + 0x08)
0117 #define CIO2_REG_ISCLK_RATIO        (CIO2_REG_GPREG_BASE + 0xc)
0118 
0119 #define CIO2_REG_CGC                    0x1400
0120 #define CIO2_CGC_CSI2_TGE               BIT(0)
0121 #define CIO2_CGC_PRIM_TGE               BIT(1)
0122 #define CIO2_CGC_SIDE_TGE               BIT(2)
0123 #define CIO2_CGC_XOSC_TGE               BIT(3)
0124 #define CIO2_CGC_MPLL_SHUTDOWN_EN           BIT(4)
0125 #define CIO2_CGC_D3I3_TGE               BIT(5)
0126 #define CIO2_CGC_CSI2_INTERFRAME_TGE            BIT(6)
0127 #define CIO2_CGC_CSI2_PORT_DCGE             BIT(8)
0128 #define CIO2_CGC_CSI2_DCGE              BIT(9)
0129 #define CIO2_CGC_SIDE_DCGE              BIT(10)
0130 #define CIO2_CGC_PRIM_DCGE              BIT(11)
0131 #define CIO2_CGC_ROSC_DCGE              BIT(12)
0132 #define CIO2_CGC_XOSC_DCGE              BIT(13)
0133 #define CIO2_CGC_FLIS_DCGE              BIT(14)
0134 #define CIO2_CGC_CLKGATE_HOLDOFF_SHIFT          20U
0135 #define CIO2_CGC_CSI_CLKGATE_HOLDOFF_SHIFT      24U
0136 #define CIO2_REG_D0I3C                  0x1408
0137 #define CIO2_D0I3C_I3                   BIT(2)  /* Set D0I3 */
0138 #define CIO2_D0I3C_RR                   BIT(3)  /* Restore? */
0139 #define CIO2_REG_SWRESET                0x140c
0140 #define CIO2_SWRESET_SWRESET                1U
0141 #define CIO2_REG_SENSOR_ACTIVE              0x1410
0142 #define CIO2_REG_INT_STS                0x1414
0143 #define CIO2_REG_INT_STS_EXT_OE             0x1418
0144 #define CIO2_INT_EXT_OE_DMAOE_SHIFT         0U
0145 #define CIO2_INT_EXT_OE_DMAOE_MASK          0x7ffff
0146 #define CIO2_INT_EXT_OE_OES_SHIFT           24U
0147 #define CIO2_INT_EXT_OE_OES_MASK    (0xf << CIO2_INT_EXT_OE_OES_SHIFT)
0148 #define CIO2_REG_INT_EN                 0x1420
0149 #define CIO2_REG_INT_EN_IRQ             (1 << 24)
0150 #define CIO2_REG_INT_EN_IOS(dma)    (1U << (((dma) >> 1U) + 12U))
0151 /*
0152  * Interrupt on completion bit, Eg. DMA 0-3 maps to bit 0-3,
0153  * DMA4 & DMA5 map to bit 4 ... DMA18 & DMA19 map to bit 11 Et cetera
0154  */
0155 #define CIO2_INT_IOC(dma)   (1U << ((dma) < 4U ? (dma) : ((dma) >> 1U) + 2U))
0156 #define CIO2_INT_IOC_SHIFT              0
0157 #define CIO2_INT_IOC_MASK       (0x7ff << CIO2_INT_IOC_SHIFT)
0158 #define CIO2_INT_IOS_IOLN(dma)      (1U << (((dma) >> 1U) + 12U))
0159 #define CIO2_INT_IOS_IOLN_SHIFT             12
0160 #define CIO2_INT_IOS_IOLN_MASK      (0x3ff << CIO2_INT_IOS_IOLN_SHIFT)
0161 #define CIO2_INT_IOIE                   BIT(22)
0162 #define CIO2_INT_IOOE                   BIT(23)
0163 #define CIO2_INT_IOIRQ                  BIT(24)
0164 #define CIO2_REG_INT_EN_EXT_OE              0x1424
0165 #define CIO2_REG_DMA_DBG                0x1448
0166 #define CIO2_REG_DMA_DBG_DMA_INDEX_SHIFT        0U
0167 #define CIO2_REG_PBM_ARB_CTRL               0x1460
0168 #define CIO2_PBM_ARB_CTRL_LANES_DIV         0U /* 4-4-2-2 lanes */
0169 #define CIO2_PBM_ARB_CTRL_LANES_DIV_SHIFT       0U
0170 #define CIO2_PBM_ARB_CTRL_LE_EN             BIT(7)
0171 #define CIO2_PBM_ARB_CTRL_PLL_POST_SHTDN        2U
0172 #define CIO2_PBM_ARB_CTRL_PLL_POST_SHTDN_SHIFT      8U
0173 #define CIO2_PBM_ARB_CTRL_PLL_AHD_WK_UP         480U
0174 #define CIO2_PBM_ARB_CTRL_PLL_AHD_WK_UP_SHIFT       16U
0175 #define CIO2_REG_PBM_WMCTRL1                0x1464
0176 #define CIO2_PBM_WMCTRL1_MIN_2CK_SHIFT          0U
0177 #define CIO2_PBM_WMCTRL1_MID1_2CK_SHIFT         8U
0178 #define CIO2_PBM_WMCTRL1_MID2_2CK_SHIFT         16U
0179 #define CIO2_PBM_WMCTRL1_TS_COUNT_DISABLE       BIT(31)
0180 #define CIO2_PBM_WMCTRL1_MIN_2CK    (4 << CIO2_PBM_WMCTRL1_MIN_2CK_SHIFT)
0181 #define CIO2_PBM_WMCTRL1_MID1_2CK   (16 << CIO2_PBM_WMCTRL1_MID1_2CK_SHIFT)
0182 #define CIO2_PBM_WMCTRL1_MID2_2CK   (21 << CIO2_PBM_WMCTRL1_MID2_2CK_SHIFT)
0183 #define CIO2_REG_PBM_WMCTRL2                0x1468
0184 #define CIO2_PBM_WMCTRL2_HWM_2CK            40U
0185 #define CIO2_PBM_WMCTRL2_HWM_2CK_SHIFT          0U
0186 #define CIO2_PBM_WMCTRL2_LWM_2CK            22U
0187 #define CIO2_PBM_WMCTRL2_LWM_2CK_SHIFT          8U
0188 #define CIO2_PBM_WMCTRL2_OBFFWM_2CK         2U
0189 #define CIO2_PBM_WMCTRL2_OBFFWM_2CK_SHIFT       16U
0190 #define CIO2_PBM_WMCTRL2_TRANSDYN           1U
0191 #define CIO2_PBM_WMCTRL2_TRANSDYN_SHIFT         24U
0192 #define CIO2_PBM_WMCTRL2_DYNWMEN            BIT(28)
0193 #define CIO2_PBM_WMCTRL2_OBFF_MEM_EN            BIT(29)
0194 #define CIO2_PBM_WMCTRL2_OBFF_CPU_EN            BIT(30)
0195 #define CIO2_PBM_WMCTRL2_DRAINNOW           BIT(31)
0196 #define CIO2_REG_PBM_TS_COUNT               0x146c
0197 #define CIO2_REG_PBM_FOPN_ABORT             0x1474
0198 /* below n = 0..3 */
0199 #define CIO2_PBM_FOPN_ABORT(n)              (0x1 << 8U * (n))
0200 #define CIO2_PBM_FOPN_FORCE_ABORT(n)            (0x2 << 8U * (n))
0201 #define CIO2_PBM_FOPN_FRAMEOPEN(n)          (0x8 << 8U * (n))
0202 #define CIO2_REG_LTRCTRL                0x1480
0203 #define CIO2_LTRCTRL_LTRDYNEN               BIT(16)
0204 #define CIO2_LTRCTRL_LTRSTABLETIME_SHIFT        8U
0205 #define CIO2_LTRCTRL_LTRSTABLETIME_MASK         0xff
0206 #define CIO2_LTRCTRL_LTRSEL1S3              BIT(7)
0207 #define CIO2_LTRCTRL_LTRSEL1S2              BIT(6)
0208 #define CIO2_LTRCTRL_LTRSEL1S1              BIT(5)
0209 #define CIO2_LTRCTRL_LTRSEL1S0              BIT(4)
0210 #define CIO2_LTRCTRL_LTRSEL2S3              BIT(3)
0211 #define CIO2_LTRCTRL_LTRSEL2S2              BIT(2)
0212 #define CIO2_LTRCTRL_LTRSEL2S1              BIT(1)
0213 #define CIO2_LTRCTRL_LTRSEL2S0              BIT(0)
0214 #define CIO2_REG_LTRVAL23               0x1484
0215 #define CIO2_REG_LTRVAL01               0x1488
0216 #define CIO2_LTRVAL02_VAL_SHIFT             0U
0217 #define CIO2_LTRVAL02_SCALE_SHIFT           10U
0218 #define CIO2_LTRVAL13_VAL_SHIFT             16U
0219 #define CIO2_LTRVAL13_SCALE_SHIFT           26U
0220 
0221 #define CIO2_LTRVAL0_VAL                175U
0222 /* Value times 1024 ns */
0223 #define CIO2_LTRVAL0_SCALE              2U
0224 #define CIO2_LTRVAL1_VAL                90U
0225 #define CIO2_LTRVAL1_SCALE              2U
0226 #define CIO2_LTRVAL2_VAL                90U
0227 #define CIO2_LTRVAL2_SCALE              2U
0228 #define CIO2_LTRVAL3_VAL                90U
0229 #define CIO2_LTRVAL3_SCALE              2U
0230 
0231 #define CIO2_REG_CDMABA(n)      (0x1500 + 0x10 * (n))   /* n = 0..19 */
0232 #define CIO2_REG_CDMARI(n)      (0x1504 + 0x10 * (n))
0233 #define CIO2_CDMARI_FBPT_RP_SHIFT           0U
0234 #define CIO2_CDMARI_FBPT_RP_MASK            0xff
0235 #define CIO2_REG_CDMAC0(n)      (0x1508 + 0x10 * (n))
0236 #define CIO2_CDMAC0_FBPT_LEN_SHIFT          0U
0237 #define CIO2_CDMAC0_FBPT_WIDTH_SHIFT            8U
0238 #define CIO2_CDMAC0_FBPT_NS             BIT(25)
0239 #define CIO2_CDMAC0_DMA_INTR_ON_FS          BIT(26)
0240 #define CIO2_CDMAC0_DMA_INTR_ON_FE          BIT(27)
0241 #define CIO2_CDMAC0_FBPT_UPDATE_FIFO_FULL       BIT(28)
0242 #define CIO2_CDMAC0_FBPT_FIFO_FULL_FIX_DIS      BIT(29)
0243 #define CIO2_CDMAC0_DMA_EN              BIT(30)
0244 #define CIO2_CDMAC0_DMA_HALTED              BIT(31)
0245 #define CIO2_REG_CDMAC1(n)      (0x150c + 0x10 * (n))
0246 #define CIO2_CDMAC1_LINENUMINT_SHIFT            0U
0247 #define CIO2_CDMAC1_LINENUMUPDATE_SHIFT         16U
0248 /* n = 0..3 */
0249 #define CIO2_REG_PXM_PXF_FMT_CFG0(n)    (0x1700 + 0x30 * (n))
0250 #define CIO2_PXM_PXF_FMT_CFG_SID0_SHIFT         0U
0251 #define CIO2_PXM_PXF_FMT_CFG_SID1_SHIFT         16U
0252 #define CIO2_PXM_PXF_FMT_CFG_PCK_64B            (0 << 0)
0253 #define CIO2_PXM_PXF_FMT_CFG_PCK_32B            (1 << 0)
0254 #define CIO2_PXM_PXF_FMT_CFG_BPP_08         (0 << 2)
0255 #define CIO2_PXM_PXF_FMT_CFG_BPP_10         (1 << 2)
0256 #define CIO2_PXM_PXF_FMT_CFG_BPP_12         (2 << 2)
0257 #define CIO2_PXM_PXF_FMT_CFG_BPP_14         (3 << 2)
0258 #define CIO2_PXM_PXF_FMT_CFG_SPEC_4PPC          (0 << 4)
0259 #define CIO2_PXM_PXF_FMT_CFG_SPEC_3PPC_RGBA     (1 << 4)
0260 #define CIO2_PXM_PXF_FMT_CFG_SPEC_3PPC_ARGB     (2 << 4)
0261 #define CIO2_PXM_PXF_FMT_CFG_SPEC_PLANAR2       (3 << 4)
0262 #define CIO2_PXM_PXF_FMT_CFG_SPEC_PLANAR3       (4 << 4)
0263 #define CIO2_PXM_PXF_FMT_CFG_SPEC_NV16          (5 << 4)
0264 #define CIO2_PXM_PXF_FMT_CFG_PSWAP4_1ST_AB      (1 << 7)
0265 #define CIO2_PXM_PXF_FMT_CFG_PSWAP4_1ST_CD      (1 << 8)
0266 #define CIO2_PXM_PXF_FMT_CFG_PSWAP4_2ND_AC      (1 << 9)
0267 #define CIO2_PXM_PXF_FMT_CFG_PSWAP4_2ND_BD      (1 << 10)
0268 #define CIO2_REG_INT_STS_EXT_IE             0x17e4
0269 #define CIO2_REG_INT_EN_EXT_IE              0x17e8
0270 #define CIO2_INT_EXT_IE_ECC_RE(n)           (0x01 << (8U * (n)))
0271 #define CIO2_INT_EXT_IE_DPHY_NR(n)          (0x02 << (8U * (n)))
0272 #define CIO2_INT_EXT_IE_ECC_NR(n)           (0x04 << (8U * (n)))
0273 #define CIO2_INT_EXT_IE_CRCERR(n)           (0x08 << (8U * (n)))
0274 #define CIO2_INT_EXT_IE_INTERFRAMEDATA(n)       (0x10 << (8U * (n)))
0275 #define CIO2_INT_EXT_IE_PKT2SHORT(n)            (0x20 << (8U * (n)))
0276 #define CIO2_INT_EXT_IE_PKT2LONG(n)         (0x40 << (8U * (n)))
0277 #define CIO2_INT_EXT_IE_IRQ(n)              (0x80 << (8U * (n)))
0278 #define CIO2_REG_PXM_FRF_CFG(n)             (0x1720 + 0x30 * (n))
0279 #define CIO2_PXM_FRF_CFG_FNSEL              BIT(0)
0280 #define CIO2_PXM_FRF_CFG_FN_RST             BIT(1)
0281 #define CIO2_PXM_FRF_CFG_ABORT              BIT(2)
0282 #define CIO2_PXM_FRF_CFG_CRC_TH_SHIFT           3U
0283 #define CIO2_PXM_FRF_CFG_MSK_ECC_DPHY_NR        BIT(8)
0284 #define CIO2_PXM_FRF_CFG_MSK_ECC_RE         BIT(9)
0285 #define CIO2_PXM_FRF_CFG_MSK_ECC_DPHY_NE        BIT(10)
0286 #define CIO2_PXM_FRF_CFG_EVEN_ODD_MODE_SHIFT        11U
0287 #define CIO2_PXM_FRF_CFG_MASK_CRC_THRES         BIT(13)
0288 #define CIO2_PXM_FRF_CFG_MASK_CSI_ACCEPT        BIT(14)
0289 #define CIO2_PXM_FRF_CFG_CIOHC_FS_MODE          BIT(15)
0290 #define CIO2_PXM_FRF_CFG_CIOHC_FRST_FRM_SHIFT       16U
0291 #define CIO2_REG_PXM_SID2BID0(n)            (0x1724 + 0x30 * (n))
0292 #define CIO2_FB_HPLL_FREQ               0x2
0293 #define CIO2_ISCLK_RATIO                0xc
0294 
0295 #define CIO2_IRQCTRL_MASK               0x3ffff
0296 
0297 #define CIO2_INT_EN_EXT_OE_MASK             0x8f0fffff
0298 
0299 #define CIO2_CGC_CLKGATE_HOLDOFF            3U
0300 #define CIO2_CGC_CSI_CLKGATE_HOLDOFF            5U
0301 
0302 #define CIO2_PXM_FRF_CFG_CRC_TH             16
0303 
0304 #define CIO2_INT_EN_EXT_IE_MASK             0xffffffff
0305 
0306 #define CIO2_DMA_CHAN                   0U
0307 
0308 #define CIO2_CSIRX_DLY_CNT_CLANE_IDX            -1
0309 
0310 #define CIO2_CSIRX_DLY_CNT_TERMEN_CLANE_A       0
0311 #define CIO2_CSIRX_DLY_CNT_TERMEN_CLANE_B       0
0312 #define CIO2_CSIRX_DLY_CNT_SETTLE_CLANE_A       95
0313 #define CIO2_CSIRX_DLY_CNT_SETTLE_CLANE_B       -8
0314 
0315 #define CIO2_CSIRX_DLY_CNT_TERMEN_DLANE_A       0
0316 #define CIO2_CSIRX_DLY_CNT_TERMEN_DLANE_B       0
0317 #define CIO2_CSIRX_DLY_CNT_SETTLE_DLANE_A       85
0318 #define CIO2_CSIRX_DLY_CNT_SETTLE_DLANE_B       -2
0319 
0320 #define CIO2_CSIRX_DLY_CNT_TERMEN_DEFAULT       0x4
0321 #define CIO2_CSIRX_DLY_CNT_SETTLE_DEFAULT       0x570
0322 
0323 #define CIO2_PMCSR_OFFSET               4U
0324 #define CIO2_PMCSR_D0D3_SHIFT               2U
0325 #define CIO2_PMCSR_D3                   0x3
0326 
0327 struct cio2_csi2_timing {
0328     s32 clk_termen;
0329     s32 clk_settle;
0330     s32 dat_termen;
0331     s32 dat_settle;
0332 };
0333 
0334 struct cio2_buffer {
0335     struct vb2_v4l2_buffer vbb;
0336     u32 *lop[CIO2_MAX_LOPS];
0337     dma_addr_t lop_bus_addr[CIO2_MAX_LOPS];
0338     unsigned int offset;
0339 };
0340 
0341 #define to_cio2_buffer(vb)  container_of(vb, struct cio2_buffer, vbb.vb2_buf)
0342 
0343 struct csi2_bus_info {
0344     u32 port;
0345     u32 lanes;
0346 };
0347 
0348 struct cio2_queue {
0349     /* mutex to be used by vb2_queue */
0350     struct mutex lock;
0351     struct media_pipeline pipe;
0352     struct csi2_bus_info csi2;
0353     struct v4l2_subdev *sensor;
0354     void __iomem *csi_rx_base;
0355 
0356     /* Subdev, /dev/v4l-subdevX */
0357     struct v4l2_subdev subdev;
0358     struct mutex subdev_lock; /* Serialise acces to subdev_fmt field */
0359     struct media_pad subdev_pads[CIO2_PADS];
0360     struct v4l2_mbus_framefmt subdev_fmt;
0361     atomic_t frame_sequence;
0362 
0363     /* Video device, /dev/videoX */
0364     struct video_device vdev;
0365     struct media_pad vdev_pad;
0366     struct v4l2_pix_format_mplane format;
0367     struct vb2_queue vbq;
0368 
0369     /* Buffer queue handling */
0370     struct cio2_fbpt_entry *fbpt;   /* Frame buffer pointer table */
0371     dma_addr_t fbpt_bus_addr;
0372     struct cio2_buffer *bufs[CIO2_MAX_BUFFERS];
0373     unsigned int bufs_first;    /* Index of the first used entry */
0374     unsigned int bufs_next; /* Index of the first unused entry */
0375     atomic_t bufs_queued;
0376 };
0377 
0378 struct cio2_device {
0379     struct pci_dev *pci_dev;
0380     void __iomem *base;
0381     struct v4l2_device v4l2_dev;
0382     struct cio2_queue queue[CIO2_QUEUES];
0383     struct cio2_queue *cur_queue;
0384     /* mutex to be used by video_device */
0385     struct mutex lock;
0386 
0387     bool streaming;
0388     struct v4l2_async_notifier notifier;
0389     struct media_device media_dev;
0390 
0391     /*
0392      * Safety net to catch DMA fetch ahead
0393      * when reaching the end of LOP
0394      */
0395     void *dummy_page;
0396     /* DMA handle of dummy_page */
0397     dma_addr_t dummy_page_bus_addr;
0398     /* single List of Pointers (LOP) page */
0399     u32 *dummy_lop;
0400     /* DMA handle of dummy_lop */
0401     dma_addr_t dummy_lop_bus_addr;
0402 };
0403 
0404 #define to_cio2_device(n)   container_of(n, struct cio2_device, notifier)
0405 
0406 /**************** Virtual channel ****************/
0407 /*
0408  * This should come from sensor driver. No
0409  * driver interface nor requirement yet.
0410  */
0411 #define SENSOR_VIR_CH_DFLT      0
0412 
0413 /**************** FBPT operations ****************/
0414 #define CIO2_FBPT_SIZE          (CIO2_MAX_BUFFERS * CIO2_MAX_LOPS * \
0415                      sizeof(struct cio2_fbpt_entry))
0416 
0417 #define CIO2_FBPT_SUBENTRY_UNIT     4
0418 
0419 /* cio2 fbpt first_entry ctrl status */
0420 #define CIO2_FBPT_CTRL_VALID        BIT(0)
0421 #define CIO2_FBPT_CTRL_IOC      BIT(1)
0422 #define CIO2_FBPT_CTRL_IOS      BIT(2)
0423 #define CIO2_FBPT_CTRL_SUCCXFAIL    BIT(3)
0424 #define CIO2_FBPT_CTRL_CMPLCODE_SHIFT   4
0425 
0426 /*
0427  * Frame Buffer Pointer Table(FBPT) entry
0428  * each entry describe an output buffer and consists of
0429  * several sub-entries
0430  */
0431 struct __packed cio2_fbpt_entry {
0432     union {
0433         struct __packed {
0434             u32 ctrl; /* status ctrl */
0435             u16 cur_line_num; /* current line # written to DDR */
0436             u16 frame_num; /* updated by DMA upon FE */
0437             u32 first_page_offset; /* offset for 1st page in LOP */
0438         } first_entry;
0439         /* Second entry per buffer */
0440         struct __packed {
0441             u32 timestamp;
0442             u32 num_of_bytes;
0443             /* the number of bytes for write on last page */
0444             u16 last_page_available_bytes;
0445             /* the number of pages allocated for this buf */
0446             u16 num_of_pages;
0447         } second_entry;
0448     };
0449     u32 lop_page_addr;  /* Points to list of pointers (LOP) table */
0450 };
0451 
0452 static inline struct cio2_queue *file_to_cio2_queue(struct file *file)
0453 {
0454     return container_of(video_devdata(file), struct cio2_queue, vdev);
0455 }
0456 
0457 static inline struct cio2_queue *vb2q_to_cio2_queue(struct vb2_queue *vq)
0458 {
0459     return container_of(vq, struct cio2_queue, vbq);
0460 }
0461 
0462 #if IS_ENABLED(CONFIG_CIO2_BRIDGE)
0463 int cio2_bridge_init(struct pci_dev *cio2);
0464 #else
0465 static inline int cio2_bridge_init(struct pci_dev *cio2) { return 0; }
0466 #endif
0467 
0468 #endif