18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* Copyright (C) 2017 Intel Corporation */ 38c2ecf20Sopenharmony_ci 48c2ecf20Sopenharmony_ci#ifndef __IPU3_CIO2_H 58c2ecf20Sopenharmony_ci#define __IPU3_CIO2_H 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci#include <linux/types.h> 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#define CIO2_NAME "ipu3-cio2" 108c2ecf20Sopenharmony_ci#define CIO2_DEVICE_NAME "Intel IPU3 CIO2" 118c2ecf20Sopenharmony_ci#define CIO2_ENTITY_NAME "ipu3-csi2" 128c2ecf20Sopenharmony_ci#define CIO2_PCI_ID 0x9d32 138c2ecf20Sopenharmony_ci#define CIO2_PCI_BAR 0 148c2ecf20Sopenharmony_ci#define CIO2_DMA_MASK DMA_BIT_MASK(39) 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_ci#define CIO2_IMAGE_MAX_WIDTH 4224 178c2ecf20Sopenharmony_ci#define CIO2_IMAGE_MAX_LENGTH 3136 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ci/* 32MB = 8xFBPT_entry */ 208c2ecf20Sopenharmony_ci#define CIO2_MAX_LOPS 8 218c2ecf20Sopenharmony_ci#define CIO2_MAX_BUFFERS (PAGE_SIZE / 16 / CIO2_MAX_LOPS) 228c2ecf20Sopenharmony_ci#define CIO2_LOP_ENTRIES (PAGE_SIZE / sizeof(u32)) 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci#define CIO2_PAD_SINK 0 258c2ecf20Sopenharmony_ci#define CIO2_PAD_SOURCE 1 268c2ecf20Sopenharmony_ci#define CIO2_PADS 2 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ci#define CIO2_NUM_DMA_CHAN 20 298c2ecf20Sopenharmony_ci#define CIO2_NUM_PORTS 4 /* DPHYs */ 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ci/* 1 for each sensor */ 328c2ecf20Sopenharmony_ci#define CIO2_QUEUES CIO2_NUM_PORTS 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ci/* Register and bit field definitions */ 358c2ecf20Sopenharmony_ci#define CIO2_REG_PIPE_BASE(n) ((n) * 0x0400) /* n = 0..3 */ 368c2ecf20Sopenharmony_ci#define CIO2_REG_CSIRX_BASE 0x000 378c2ecf20Sopenharmony_ci#define CIO2_REG_MIPIBE_BASE 0x100 388c2ecf20Sopenharmony_ci#define CIO2_REG_PIXELGEN_BAS 0x200 398c2ecf20Sopenharmony_ci#define CIO2_REG_IRQCTRL_BASE 0x300 408c2ecf20Sopenharmony_ci#define CIO2_REG_GPREG_BASE 0x1000 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci/* base register: CIO2_REG_PIPE_BASE(pipe) * CIO2_REG_CSIRX_BASE */ 438c2ecf20Sopenharmony_ci#define CIO2_REG_CSIRX_ENABLE (CIO2_REG_CSIRX_BASE + 0x0) 448c2ecf20Sopenharmony_ci#define CIO2_REG_CSIRX_NOF_ENABLED_LANES (CIO2_REG_CSIRX_BASE + 0x4) 458c2ecf20Sopenharmony_ci#define CIO2_REG_CSIRX_SP_IF_CONFIG (CIO2_REG_CSIRX_BASE + 0x10) 468c2ecf20Sopenharmony_ci#define CIO2_REG_CSIRX_LP_IF_CONFIG (CIO2_REG_CSIRX_BASE + 0x14) 478c2ecf20Sopenharmony_ci#define CIO2_CSIRX_IF_CONFIG_FILTEROUT 0x00 488c2ecf20Sopenharmony_ci#define CIO2_CSIRX_IF_CONFIG_FILTEROUT_VC_INACTIVE 0x01 498c2ecf20Sopenharmony_ci#define CIO2_CSIRX_IF_CONFIG_PASS 0x02 508c2ecf20Sopenharmony_ci#define CIO2_CSIRX_IF_CONFIG_FLAG_ERROR BIT(2) 518c2ecf20Sopenharmony_ci#define CIO2_REG_CSIRX_STATUS (CIO2_REG_CSIRX_BASE + 0x18) 528c2ecf20Sopenharmony_ci#define CIO2_REG_CSIRX_STATUS_DLANE_HS (CIO2_REG_CSIRX_BASE + 0x1c) 538c2ecf20Sopenharmony_ci#define CIO2_CSIRX_STATUS_DLANE_HS_MASK 0xff 548c2ecf20Sopenharmony_ci#define CIO2_REG_CSIRX_STATUS_DLANE_LP (CIO2_REG_CSIRX_BASE + 0x20) 558c2ecf20Sopenharmony_ci#define CIO2_CSIRX_STATUS_DLANE_LP_MASK 0xffffff 568c2ecf20Sopenharmony_ci/* Termination enable and settle in 0.0625ns units, lane=0..3 or -1 for clock */ 578c2ecf20Sopenharmony_ci#define CIO2_REG_CSIRX_DLY_CNT_TERMEN(lane) \ 588c2ecf20Sopenharmony_ci (CIO2_REG_CSIRX_BASE + 0x2c + 8 * (lane)) 598c2ecf20Sopenharmony_ci#define CIO2_REG_CSIRX_DLY_CNT_SETTLE(lane) \ 608c2ecf20Sopenharmony_ci (CIO2_REG_CSIRX_BASE + 0x30 + 8 * (lane)) 618c2ecf20Sopenharmony_ci/* base register: CIO2_REG_PIPE_BASE(pipe) * CIO2_REG_MIPIBE_BASE */ 628c2ecf20Sopenharmony_ci#define CIO2_REG_MIPIBE_ENABLE (CIO2_REG_MIPIBE_BASE + 0x0) 638c2ecf20Sopenharmony_ci#define CIO2_REG_MIPIBE_STATUS (CIO2_REG_MIPIBE_BASE + 0x4) 648c2ecf20Sopenharmony_ci#define CIO2_REG_MIPIBE_COMP_FORMAT(vc) \ 658c2ecf20Sopenharmony_ci (CIO2_REG_MIPIBE_BASE + 0x8 + 0x4 * (vc)) 668c2ecf20Sopenharmony_ci#define CIO2_REG_MIPIBE_FORCE_RAW8 (CIO2_REG_MIPIBE_BASE + 0x20) 678c2ecf20Sopenharmony_ci#define CIO2_REG_MIPIBE_FORCE_RAW8_ENABLE BIT(0) 688c2ecf20Sopenharmony_ci#define CIO2_REG_MIPIBE_FORCE_RAW8_USE_TYPEID BIT(1) 698c2ecf20Sopenharmony_ci#define CIO2_REG_MIPIBE_FORCE_RAW8_TYPEID_SHIFT 2 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_ci#define CIO2_REG_MIPIBE_IRQ_STATUS (CIO2_REG_MIPIBE_BASE + 0x24) 728c2ecf20Sopenharmony_ci#define CIO2_REG_MIPIBE_IRQ_CLEAR (CIO2_REG_MIPIBE_BASE + 0x28) 738c2ecf20Sopenharmony_ci#define CIO2_REG_MIPIBE_GLOBAL_LUT_DISREGARD (CIO2_REG_MIPIBE_BASE + 0x68) 748c2ecf20Sopenharmony_ci#define CIO2_MIPIBE_GLOBAL_LUT_DISREGARD 1 758c2ecf20Sopenharmony_ci#define CIO2_REG_MIPIBE_PKT_STALL_STATUS (CIO2_REG_MIPIBE_BASE + 0x6c) 768c2ecf20Sopenharmony_ci#define CIO2_REG_MIPIBE_PARSE_GSP_THROUGH_LP_LUT_REG_IDX \ 778c2ecf20Sopenharmony_ci (CIO2_REG_MIPIBE_BASE + 0x70) 788c2ecf20Sopenharmony_ci#define CIO2_REG_MIPIBE_SP_LUT_ENTRY(vc) \ 798c2ecf20Sopenharmony_ci (CIO2_REG_MIPIBE_BASE + 0x74 + 4 * (vc)) 808c2ecf20Sopenharmony_ci#define CIO2_REG_MIPIBE_LP_LUT_ENTRY(m) /* m = 0..15 */ \ 818c2ecf20Sopenharmony_ci (CIO2_REG_MIPIBE_BASE + 0x84 + 4 * (m)) 828c2ecf20Sopenharmony_ci#define CIO2_MIPIBE_LP_LUT_ENTRY_DISREGARD 1 838c2ecf20Sopenharmony_ci#define CIO2_MIPIBE_LP_LUT_ENTRY_SID_SHIFT 1 848c2ecf20Sopenharmony_ci#define CIO2_MIPIBE_LP_LUT_ENTRY_VC_SHIFT 5 858c2ecf20Sopenharmony_ci#define CIO2_MIPIBE_LP_LUT_ENTRY_FORMAT_TYPE_SHIFT 7 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_ci/* base register: CIO2_REG_PIPE_BASE(pipe) * CIO2_REG_IRQCTRL_BASE */ 888c2ecf20Sopenharmony_ci/* IRQ registers are 18-bit wide, see cio2_irq_error for bit definitions */ 898c2ecf20Sopenharmony_ci#define CIO2_REG_IRQCTRL_EDGE (CIO2_REG_IRQCTRL_BASE + 0x00) 908c2ecf20Sopenharmony_ci#define CIO2_REG_IRQCTRL_MASK (CIO2_REG_IRQCTRL_BASE + 0x04) 918c2ecf20Sopenharmony_ci#define CIO2_REG_IRQCTRL_STATUS (CIO2_REG_IRQCTRL_BASE + 0x08) 928c2ecf20Sopenharmony_ci#define CIO2_REG_IRQCTRL_CLEAR (CIO2_REG_IRQCTRL_BASE + 0x0c) 938c2ecf20Sopenharmony_ci#define CIO2_REG_IRQCTRL_ENABLE (CIO2_REG_IRQCTRL_BASE + 0x10) 948c2ecf20Sopenharmony_ci#define CIO2_REG_IRQCTRL_LEVEL_NOT_PULSE (CIO2_REG_IRQCTRL_BASE + 0x14) 958c2ecf20Sopenharmony_ci 968c2ecf20Sopenharmony_ci#define CIO2_REG_GPREG_SRST (CIO2_REG_GPREG_BASE + 0x0) 978c2ecf20Sopenharmony_ci#define CIO2_GPREG_SRST_ALL 0xffff /* Reset all */ 988c2ecf20Sopenharmony_ci#define CIO2_REG_FB_HPLL_FREQ (CIO2_REG_GPREG_BASE + 0x08) 998c2ecf20Sopenharmony_ci#define CIO2_REG_ISCLK_RATIO (CIO2_REG_GPREG_BASE + 0xc) 1008c2ecf20Sopenharmony_ci 1018c2ecf20Sopenharmony_ci#define CIO2_REG_CGC 0x1400 1028c2ecf20Sopenharmony_ci#define CIO2_CGC_CSI2_TGE BIT(0) 1038c2ecf20Sopenharmony_ci#define CIO2_CGC_PRIM_TGE BIT(1) 1048c2ecf20Sopenharmony_ci#define CIO2_CGC_SIDE_TGE BIT(2) 1058c2ecf20Sopenharmony_ci#define CIO2_CGC_XOSC_TGE BIT(3) 1068c2ecf20Sopenharmony_ci#define CIO2_CGC_MPLL_SHUTDOWN_EN BIT(4) 1078c2ecf20Sopenharmony_ci#define CIO2_CGC_D3I3_TGE BIT(5) 1088c2ecf20Sopenharmony_ci#define CIO2_CGC_CSI2_INTERFRAME_TGE BIT(6) 1098c2ecf20Sopenharmony_ci#define CIO2_CGC_CSI2_PORT_DCGE BIT(8) 1108c2ecf20Sopenharmony_ci#define CIO2_CGC_CSI2_DCGE BIT(9) 1118c2ecf20Sopenharmony_ci#define CIO2_CGC_SIDE_DCGE BIT(10) 1128c2ecf20Sopenharmony_ci#define CIO2_CGC_PRIM_DCGE BIT(11) 1138c2ecf20Sopenharmony_ci#define CIO2_CGC_ROSC_DCGE BIT(12) 1148c2ecf20Sopenharmony_ci#define CIO2_CGC_XOSC_DCGE BIT(13) 1158c2ecf20Sopenharmony_ci#define CIO2_CGC_FLIS_DCGE BIT(14) 1168c2ecf20Sopenharmony_ci#define CIO2_CGC_CLKGATE_HOLDOFF_SHIFT 20 1178c2ecf20Sopenharmony_ci#define CIO2_CGC_CSI_CLKGATE_HOLDOFF_SHIFT 24 1188c2ecf20Sopenharmony_ci#define CIO2_REG_D0I3C 0x1408 1198c2ecf20Sopenharmony_ci#define CIO2_D0I3C_I3 BIT(2) /* Set D0I3 */ 1208c2ecf20Sopenharmony_ci#define CIO2_D0I3C_RR BIT(3) /* Restore? */ 1218c2ecf20Sopenharmony_ci#define CIO2_REG_SWRESET 0x140c 1228c2ecf20Sopenharmony_ci#define CIO2_SWRESET_SWRESET 1 1238c2ecf20Sopenharmony_ci#define CIO2_REG_SENSOR_ACTIVE 0x1410 1248c2ecf20Sopenharmony_ci#define CIO2_REG_INT_STS 0x1414 1258c2ecf20Sopenharmony_ci#define CIO2_REG_INT_STS_EXT_OE 0x1418 1268c2ecf20Sopenharmony_ci#define CIO2_INT_EXT_OE_DMAOE_SHIFT 0 1278c2ecf20Sopenharmony_ci#define CIO2_INT_EXT_OE_DMAOE_MASK 0x7ffff 1288c2ecf20Sopenharmony_ci#define CIO2_INT_EXT_OE_OES_SHIFT 24 1298c2ecf20Sopenharmony_ci#define CIO2_INT_EXT_OE_OES_MASK (0xf << CIO2_INT_EXT_OE_OES_SHIFT) 1308c2ecf20Sopenharmony_ci#define CIO2_REG_INT_EN 0x1420 1318c2ecf20Sopenharmony_ci#define CIO2_REG_INT_EN_IRQ (1 << 24) 1328c2ecf20Sopenharmony_ci#define CIO2_REG_INT_EN_IOS(dma) (1 << (((dma) >> 1) + 12)) 1338c2ecf20Sopenharmony_ci/* 1348c2ecf20Sopenharmony_ci * Interrupt on completion bit, Eg. DMA 0-3 maps to bit 0-3, 1358c2ecf20Sopenharmony_ci * DMA4 & DMA5 map to bit 4 ... DMA18 & DMA19 map to bit 11 Et cetera 1368c2ecf20Sopenharmony_ci */ 1378c2ecf20Sopenharmony_ci#define CIO2_INT_IOC(dma) (1 << ((dma) < 4 ? (dma) : ((dma) >> 1) + 2)) 1388c2ecf20Sopenharmony_ci#define CIO2_INT_IOC_SHIFT 0 1398c2ecf20Sopenharmony_ci#define CIO2_INT_IOC_MASK (0x7ff << CIO2_INT_IOC_SHIFT) 1408c2ecf20Sopenharmony_ci#define CIO2_INT_IOS_IOLN(dma) (1 << (((dma) >> 1) + 12)) 1418c2ecf20Sopenharmony_ci#define CIO2_INT_IOS_IOLN_SHIFT 12 1428c2ecf20Sopenharmony_ci#define CIO2_INT_IOS_IOLN_MASK (0x3ff << CIO2_INT_IOS_IOLN_SHIFT) 1438c2ecf20Sopenharmony_ci#define CIO2_INT_IOIE BIT(22) 1448c2ecf20Sopenharmony_ci#define CIO2_INT_IOOE BIT(23) 1458c2ecf20Sopenharmony_ci#define CIO2_INT_IOIRQ BIT(24) 1468c2ecf20Sopenharmony_ci#define CIO2_REG_INT_EN_EXT_OE 0x1424 1478c2ecf20Sopenharmony_ci#define CIO2_REG_DMA_DBG 0x1448 1488c2ecf20Sopenharmony_ci#define CIO2_REG_DMA_DBG_DMA_INDEX_SHIFT 0 1498c2ecf20Sopenharmony_ci#define CIO2_REG_PBM_ARB_CTRL 0x1460 1508c2ecf20Sopenharmony_ci#define CIO2_PBM_ARB_CTRL_LANES_DIV 0 /* 4-4-2-2 lanes */ 1518c2ecf20Sopenharmony_ci#define CIO2_PBM_ARB_CTRL_LANES_DIV_SHIFT 0 1528c2ecf20Sopenharmony_ci#define CIO2_PBM_ARB_CTRL_LE_EN BIT(7) 1538c2ecf20Sopenharmony_ci#define CIO2_PBM_ARB_CTRL_PLL_POST_SHTDN 2 1548c2ecf20Sopenharmony_ci#define CIO2_PBM_ARB_CTRL_PLL_POST_SHTDN_SHIFT 8 1558c2ecf20Sopenharmony_ci#define CIO2_PBM_ARB_CTRL_PLL_AHD_WK_UP 480 1568c2ecf20Sopenharmony_ci#define CIO2_PBM_ARB_CTRL_PLL_AHD_WK_UP_SHIFT 16 1578c2ecf20Sopenharmony_ci#define CIO2_REG_PBM_WMCTRL1 0x1464 1588c2ecf20Sopenharmony_ci#define CIO2_PBM_WMCTRL1_MIN_2CK_SHIFT 0 1598c2ecf20Sopenharmony_ci#define CIO2_PBM_WMCTRL1_MID1_2CK_SHIFT 8 1608c2ecf20Sopenharmony_ci#define CIO2_PBM_WMCTRL1_MID2_2CK_SHIFT 16 1618c2ecf20Sopenharmony_ci#define CIO2_PBM_WMCTRL1_TS_COUNT_DISABLE BIT(31) 1628c2ecf20Sopenharmony_ci#define CIO2_PBM_WMCTRL1_MIN_2CK (4 << CIO2_PBM_WMCTRL1_MIN_2CK_SHIFT) 1638c2ecf20Sopenharmony_ci#define CIO2_PBM_WMCTRL1_MID1_2CK (16 << CIO2_PBM_WMCTRL1_MID1_2CK_SHIFT) 1648c2ecf20Sopenharmony_ci#define CIO2_PBM_WMCTRL1_MID2_2CK (21 << CIO2_PBM_WMCTRL1_MID2_2CK_SHIFT) 1658c2ecf20Sopenharmony_ci#define CIO2_REG_PBM_WMCTRL2 0x1468 1668c2ecf20Sopenharmony_ci#define CIO2_PBM_WMCTRL2_HWM_2CK 40 1678c2ecf20Sopenharmony_ci#define CIO2_PBM_WMCTRL2_HWM_2CK_SHIFT 0 1688c2ecf20Sopenharmony_ci#define CIO2_PBM_WMCTRL2_LWM_2CK 22 1698c2ecf20Sopenharmony_ci#define CIO2_PBM_WMCTRL2_LWM_2CK_SHIFT 8 1708c2ecf20Sopenharmony_ci#define CIO2_PBM_WMCTRL2_OBFFWM_2CK 2 1718c2ecf20Sopenharmony_ci#define CIO2_PBM_WMCTRL2_OBFFWM_2CK_SHIFT 16 1728c2ecf20Sopenharmony_ci#define CIO2_PBM_WMCTRL2_TRANSDYN 1 1738c2ecf20Sopenharmony_ci#define CIO2_PBM_WMCTRL2_TRANSDYN_SHIFT 24 1748c2ecf20Sopenharmony_ci#define CIO2_PBM_WMCTRL2_DYNWMEN BIT(28) 1758c2ecf20Sopenharmony_ci#define CIO2_PBM_WMCTRL2_OBFF_MEM_EN BIT(29) 1768c2ecf20Sopenharmony_ci#define CIO2_PBM_WMCTRL2_OBFF_CPU_EN BIT(30) 1778c2ecf20Sopenharmony_ci#define CIO2_PBM_WMCTRL2_DRAINNOW BIT(31) 1788c2ecf20Sopenharmony_ci#define CIO2_REG_PBM_TS_COUNT 0x146c 1798c2ecf20Sopenharmony_ci#define CIO2_REG_PBM_FOPN_ABORT 0x1474 1808c2ecf20Sopenharmony_ci/* below n = 0..3 */ 1818c2ecf20Sopenharmony_ci#define CIO2_PBM_FOPN_ABORT(n) (0x1 << 8 * (n)) 1828c2ecf20Sopenharmony_ci#define CIO2_PBM_FOPN_FORCE_ABORT(n) (0x2 << 8 * (n)) 1838c2ecf20Sopenharmony_ci#define CIO2_PBM_FOPN_FRAMEOPEN(n) (0x8 << 8 * (n)) 1848c2ecf20Sopenharmony_ci#define CIO2_REG_LTRCTRL 0x1480 1858c2ecf20Sopenharmony_ci#define CIO2_LTRCTRL_LTRDYNEN BIT(16) 1868c2ecf20Sopenharmony_ci#define CIO2_LTRCTRL_LTRSTABLETIME_SHIFT 8 1878c2ecf20Sopenharmony_ci#define CIO2_LTRCTRL_LTRSTABLETIME_MASK 0xff 1888c2ecf20Sopenharmony_ci#define CIO2_LTRCTRL_LTRSEL1S3 BIT(7) 1898c2ecf20Sopenharmony_ci#define CIO2_LTRCTRL_LTRSEL1S2 BIT(6) 1908c2ecf20Sopenharmony_ci#define CIO2_LTRCTRL_LTRSEL1S1 BIT(5) 1918c2ecf20Sopenharmony_ci#define CIO2_LTRCTRL_LTRSEL1S0 BIT(4) 1928c2ecf20Sopenharmony_ci#define CIO2_LTRCTRL_LTRSEL2S3 BIT(3) 1938c2ecf20Sopenharmony_ci#define CIO2_LTRCTRL_LTRSEL2S2 BIT(2) 1948c2ecf20Sopenharmony_ci#define CIO2_LTRCTRL_LTRSEL2S1 BIT(1) 1958c2ecf20Sopenharmony_ci#define CIO2_LTRCTRL_LTRSEL2S0 BIT(0) 1968c2ecf20Sopenharmony_ci#define CIO2_REG_LTRVAL23 0x1484 1978c2ecf20Sopenharmony_ci#define CIO2_REG_LTRVAL01 0x1488 1988c2ecf20Sopenharmony_ci#define CIO2_LTRVAL02_VAL_SHIFT 0 1998c2ecf20Sopenharmony_ci#define CIO2_LTRVAL02_SCALE_SHIFT 10 2008c2ecf20Sopenharmony_ci#define CIO2_LTRVAL13_VAL_SHIFT 16 2018c2ecf20Sopenharmony_ci#define CIO2_LTRVAL13_SCALE_SHIFT 26 2028c2ecf20Sopenharmony_ci 2038c2ecf20Sopenharmony_ci#define CIO2_LTRVAL0_VAL 175 2048c2ecf20Sopenharmony_ci/* Value times 1024 ns */ 2058c2ecf20Sopenharmony_ci#define CIO2_LTRVAL0_SCALE 2 2068c2ecf20Sopenharmony_ci#define CIO2_LTRVAL1_VAL 90 2078c2ecf20Sopenharmony_ci#define CIO2_LTRVAL1_SCALE 2 2088c2ecf20Sopenharmony_ci#define CIO2_LTRVAL2_VAL 90 2098c2ecf20Sopenharmony_ci#define CIO2_LTRVAL2_SCALE 2 2108c2ecf20Sopenharmony_ci#define CIO2_LTRVAL3_VAL 90 2118c2ecf20Sopenharmony_ci#define CIO2_LTRVAL3_SCALE 2 2128c2ecf20Sopenharmony_ci 2138c2ecf20Sopenharmony_ci#define CIO2_REG_CDMABA(n) (0x1500 + 0x10 * (n)) /* n = 0..19 */ 2148c2ecf20Sopenharmony_ci#define CIO2_REG_CDMARI(n) (0x1504 + 0x10 * (n)) 2158c2ecf20Sopenharmony_ci#define CIO2_CDMARI_FBPT_RP_SHIFT 0 2168c2ecf20Sopenharmony_ci#define CIO2_CDMARI_FBPT_RP_MASK 0xff 2178c2ecf20Sopenharmony_ci#define CIO2_REG_CDMAC0(n) (0x1508 + 0x10 * (n)) 2188c2ecf20Sopenharmony_ci#define CIO2_CDMAC0_FBPT_LEN_SHIFT 0 2198c2ecf20Sopenharmony_ci#define CIO2_CDMAC0_FBPT_WIDTH_SHIFT 8 2208c2ecf20Sopenharmony_ci#define CIO2_CDMAC0_FBPT_NS BIT(25) 2218c2ecf20Sopenharmony_ci#define CIO2_CDMAC0_DMA_INTR_ON_FS BIT(26) 2228c2ecf20Sopenharmony_ci#define CIO2_CDMAC0_DMA_INTR_ON_FE BIT(27) 2238c2ecf20Sopenharmony_ci#define CIO2_CDMAC0_FBPT_UPDATE_FIFO_FULL BIT(28) 2248c2ecf20Sopenharmony_ci#define CIO2_CDMAC0_FBPT_FIFO_FULL_FIX_DIS BIT(29) 2258c2ecf20Sopenharmony_ci#define CIO2_CDMAC0_DMA_EN BIT(30) 2268c2ecf20Sopenharmony_ci#define CIO2_CDMAC0_DMA_HALTED BIT(31) 2278c2ecf20Sopenharmony_ci#define CIO2_REG_CDMAC1(n) (0x150c + 0x10 * (n)) 2288c2ecf20Sopenharmony_ci#define CIO2_CDMAC1_LINENUMINT_SHIFT 0 2298c2ecf20Sopenharmony_ci#define CIO2_CDMAC1_LINENUMUPDATE_SHIFT 16 2308c2ecf20Sopenharmony_ci/* n = 0..3 */ 2318c2ecf20Sopenharmony_ci#define CIO2_REG_PXM_PXF_FMT_CFG0(n) (0x1700 + 0x30 * (n)) 2328c2ecf20Sopenharmony_ci#define CIO2_PXM_PXF_FMT_CFG_SID0_SHIFT 0 2338c2ecf20Sopenharmony_ci#define CIO2_PXM_PXF_FMT_CFG_SID1_SHIFT 16 2348c2ecf20Sopenharmony_ci#define CIO2_PXM_PXF_FMT_CFG_PCK_64B (0 << 0) 2358c2ecf20Sopenharmony_ci#define CIO2_PXM_PXF_FMT_CFG_PCK_32B (1 << 0) 2368c2ecf20Sopenharmony_ci#define CIO2_PXM_PXF_FMT_CFG_BPP_08 (0 << 2) 2378c2ecf20Sopenharmony_ci#define CIO2_PXM_PXF_FMT_CFG_BPP_10 (1 << 2) 2388c2ecf20Sopenharmony_ci#define CIO2_PXM_PXF_FMT_CFG_BPP_12 (2 << 2) 2398c2ecf20Sopenharmony_ci#define CIO2_PXM_PXF_FMT_CFG_BPP_14 (3 << 2) 2408c2ecf20Sopenharmony_ci#define CIO2_PXM_PXF_FMT_CFG_SPEC_4PPC (0 << 4) 2418c2ecf20Sopenharmony_ci#define CIO2_PXM_PXF_FMT_CFG_SPEC_3PPC_RGBA (1 << 4) 2428c2ecf20Sopenharmony_ci#define CIO2_PXM_PXF_FMT_CFG_SPEC_3PPC_ARGB (2 << 4) 2438c2ecf20Sopenharmony_ci#define CIO2_PXM_PXF_FMT_CFG_SPEC_PLANAR2 (3 << 4) 2448c2ecf20Sopenharmony_ci#define CIO2_PXM_PXF_FMT_CFG_SPEC_PLANAR3 (4 << 4) 2458c2ecf20Sopenharmony_ci#define CIO2_PXM_PXF_FMT_CFG_SPEC_NV16 (5 << 4) 2468c2ecf20Sopenharmony_ci#define CIO2_PXM_PXF_FMT_CFG_PSWAP4_1ST_AB (1 << 7) 2478c2ecf20Sopenharmony_ci#define CIO2_PXM_PXF_FMT_CFG_PSWAP4_1ST_CD (1 << 8) 2488c2ecf20Sopenharmony_ci#define CIO2_PXM_PXF_FMT_CFG_PSWAP4_2ND_AC (1 << 9) 2498c2ecf20Sopenharmony_ci#define CIO2_PXM_PXF_FMT_CFG_PSWAP4_2ND_BD (1 << 10) 2508c2ecf20Sopenharmony_ci#define CIO2_REG_INT_STS_EXT_IE 0x17e4 2518c2ecf20Sopenharmony_ci#define CIO2_REG_INT_EN_EXT_IE 0x17e8 2528c2ecf20Sopenharmony_ci#define CIO2_INT_EXT_IE_ECC_RE(n) (0x01 << (8 * (n))) 2538c2ecf20Sopenharmony_ci#define CIO2_INT_EXT_IE_DPHY_NR(n) (0x02 << (8 * (n))) 2548c2ecf20Sopenharmony_ci#define CIO2_INT_EXT_IE_ECC_NR(n) (0x04 << (8 * (n))) 2558c2ecf20Sopenharmony_ci#define CIO2_INT_EXT_IE_CRCERR(n) (0x08 << (8 * (n))) 2568c2ecf20Sopenharmony_ci#define CIO2_INT_EXT_IE_INTERFRAMEDATA(n) (0x10 << (8 * (n))) 2578c2ecf20Sopenharmony_ci#define CIO2_INT_EXT_IE_PKT2SHORT(n) (0x20 << (8 * (n))) 2588c2ecf20Sopenharmony_ci#define CIO2_INT_EXT_IE_PKT2LONG(n) (0x40 << (8 * (n))) 2598c2ecf20Sopenharmony_ci#define CIO2_INT_EXT_IE_IRQ(n) (0x80 << (8 * (n))) 2608c2ecf20Sopenharmony_ci#define CIO2_REG_PXM_FRF_CFG(n) (0x1720 + 0x30 * (n)) 2618c2ecf20Sopenharmony_ci#define CIO2_PXM_FRF_CFG_FNSEL BIT(0) 2628c2ecf20Sopenharmony_ci#define CIO2_PXM_FRF_CFG_FN_RST BIT(1) 2638c2ecf20Sopenharmony_ci#define CIO2_PXM_FRF_CFG_ABORT BIT(2) 2648c2ecf20Sopenharmony_ci#define CIO2_PXM_FRF_CFG_CRC_TH_SHIFT 3 2658c2ecf20Sopenharmony_ci#define CIO2_PXM_FRF_CFG_MSK_ECC_DPHY_NR BIT(8) 2668c2ecf20Sopenharmony_ci#define CIO2_PXM_FRF_CFG_MSK_ECC_RE BIT(9) 2678c2ecf20Sopenharmony_ci#define CIO2_PXM_FRF_CFG_MSK_ECC_DPHY_NE BIT(10) 2688c2ecf20Sopenharmony_ci#define CIO2_PXM_FRF_CFG_EVEN_ODD_MODE_SHIFT 11 2698c2ecf20Sopenharmony_ci#define CIO2_PXM_FRF_CFG_MASK_CRC_THRES BIT(13) 2708c2ecf20Sopenharmony_ci#define CIO2_PXM_FRF_CFG_MASK_CSI_ACCEPT BIT(14) 2718c2ecf20Sopenharmony_ci#define CIO2_PXM_FRF_CFG_CIOHC_FS_MODE BIT(15) 2728c2ecf20Sopenharmony_ci#define CIO2_PXM_FRF_CFG_CIOHC_FRST_FRM_SHIFT 16 2738c2ecf20Sopenharmony_ci#define CIO2_REG_PXM_SID2BID0(n) (0x1724 + 0x30 * (n)) 2748c2ecf20Sopenharmony_ci#define CIO2_FB_HPLL_FREQ 0x2 2758c2ecf20Sopenharmony_ci#define CIO2_ISCLK_RATIO 0xc 2768c2ecf20Sopenharmony_ci 2778c2ecf20Sopenharmony_ci#define CIO2_IRQCTRL_MASK 0x3ffff 2788c2ecf20Sopenharmony_ci 2798c2ecf20Sopenharmony_ci#define CIO2_INT_EN_EXT_OE_MASK 0x8f0fffff 2808c2ecf20Sopenharmony_ci 2818c2ecf20Sopenharmony_ci#define CIO2_CGC_CLKGATE_HOLDOFF 3 2828c2ecf20Sopenharmony_ci#define CIO2_CGC_CSI_CLKGATE_HOLDOFF 5 2838c2ecf20Sopenharmony_ci 2848c2ecf20Sopenharmony_ci#define CIO2_PXM_FRF_CFG_CRC_TH 16 2858c2ecf20Sopenharmony_ci 2868c2ecf20Sopenharmony_ci#define CIO2_INT_EN_EXT_IE_MASK 0xffffffff 2878c2ecf20Sopenharmony_ci 2888c2ecf20Sopenharmony_ci#define CIO2_DMA_CHAN 0 2898c2ecf20Sopenharmony_ci 2908c2ecf20Sopenharmony_ci#define CIO2_CSIRX_DLY_CNT_CLANE_IDX -1 2918c2ecf20Sopenharmony_ci 2928c2ecf20Sopenharmony_ci#define CIO2_CSIRX_DLY_CNT_TERMEN_CLANE_A 0 2938c2ecf20Sopenharmony_ci#define CIO2_CSIRX_DLY_CNT_TERMEN_CLANE_B 0 2948c2ecf20Sopenharmony_ci#define CIO2_CSIRX_DLY_CNT_SETTLE_CLANE_A 95 2958c2ecf20Sopenharmony_ci#define CIO2_CSIRX_DLY_CNT_SETTLE_CLANE_B -8 2968c2ecf20Sopenharmony_ci 2978c2ecf20Sopenharmony_ci#define CIO2_CSIRX_DLY_CNT_TERMEN_DLANE_A 0 2988c2ecf20Sopenharmony_ci#define CIO2_CSIRX_DLY_CNT_TERMEN_DLANE_B 0 2998c2ecf20Sopenharmony_ci#define CIO2_CSIRX_DLY_CNT_SETTLE_DLANE_A 85 3008c2ecf20Sopenharmony_ci#define CIO2_CSIRX_DLY_CNT_SETTLE_DLANE_B -2 3018c2ecf20Sopenharmony_ci 3028c2ecf20Sopenharmony_ci#define CIO2_CSIRX_DLY_CNT_TERMEN_DEFAULT 0x4 3038c2ecf20Sopenharmony_ci#define CIO2_CSIRX_DLY_CNT_SETTLE_DEFAULT 0x570 3048c2ecf20Sopenharmony_ci 3058c2ecf20Sopenharmony_ci#define CIO2_PMCSR_OFFSET 4 3068c2ecf20Sopenharmony_ci#define CIO2_PMCSR_D0D3_SHIFT 2 3078c2ecf20Sopenharmony_ci#define CIO2_PMCSR_D3 0x3 3088c2ecf20Sopenharmony_ci 3098c2ecf20Sopenharmony_cistruct cio2_csi2_timing { 3108c2ecf20Sopenharmony_ci s32 clk_termen; 3118c2ecf20Sopenharmony_ci s32 clk_settle; 3128c2ecf20Sopenharmony_ci s32 dat_termen; 3138c2ecf20Sopenharmony_ci s32 dat_settle; 3148c2ecf20Sopenharmony_ci}; 3158c2ecf20Sopenharmony_ci 3168c2ecf20Sopenharmony_cistruct cio2_buffer { 3178c2ecf20Sopenharmony_ci struct vb2_v4l2_buffer vbb; 3188c2ecf20Sopenharmony_ci u32 *lop[CIO2_MAX_LOPS]; 3198c2ecf20Sopenharmony_ci dma_addr_t lop_bus_addr[CIO2_MAX_LOPS]; 3208c2ecf20Sopenharmony_ci unsigned int offset; 3218c2ecf20Sopenharmony_ci}; 3228c2ecf20Sopenharmony_ci 3238c2ecf20Sopenharmony_cistruct csi2_bus_info { 3248c2ecf20Sopenharmony_ci u32 port; 3258c2ecf20Sopenharmony_ci u32 lanes; 3268c2ecf20Sopenharmony_ci}; 3278c2ecf20Sopenharmony_ci 3288c2ecf20Sopenharmony_cistruct cio2_queue { 3298c2ecf20Sopenharmony_ci /* mutex to be used by vb2_queue */ 3308c2ecf20Sopenharmony_ci struct mutex lock; 3318c2ecf20Sopenharmony_ci struct media_pipeline pipe; 3328c2ecf20Sopenharmony_ci struct csi2_bus_info csi2; 3338c2ecf20Sopenharmony_ci struct v4l2_subdev *sensor; 3348c2ecf20Sopenharmony_ci void __iomem *csi_rx_base; 3358c2ecf20Sopenharmony_ci 3368c2ecf20Sopenharmony_ci /* Subdev, /dev/v4l-subdevX */ 3378c2ecf20Sopenharmony_ci struct v4l2_subdev subdev; 3388c2ecf20Sopenharmony_ci struct mutex subdev_lock; /* Serialise acces to subdev_fmt field */ 3398c2ecf20Sopenharmony_ci struct media_pad subdev_pads[CIO2_PADS]; 3408c2ecf20Sopenharmony_ci struct v4l2_mbus_framefmt subdev_fmt; 3418c2ecf20Sopenharmony_ci atomic_t frame_sequence; 3428c2ecf20Sopenharmony_ci 3438c2ecf20Sopenharmony_ci /* Video device, /dev/videoX */ 3448c2ecf20Sopenharmony_ci struct video_device vdev; 3458c2ecf20Sopenharmony_ci struct media_pad vdev_pad; 3468c2ecf20Sopenharmony_ci struct v4l2_pix_format_mplane format; 3478c2ecf20Sopenharmony_ci struct vb2_queue vbq; 3488c2ecf20Sopenharmony_ci 3498c2ecf20Sopenharmony_ci /* Buffer queue handling */ 3508c2ecf20Sopenharmony_ci struct cio2_fbpt_entry *fbpt; /* Frame buffer pointer table */ 3518c2ecf20Sopenharmony_ci dma_addr_t fbpt_bus_addr; 3528c2ecf20Sopenharmony_ci struct cio2_buffer *bufs[CIO2_MAX_BUFFERS]; 3538c2ecf20Sopenharmony_ci unsigned int bufs_first; /* Index of the first used entry */ 3548c2ecf20Sopenharmony_ci unsigned int bufs_next; /* Index of the first unused entry */ 3558c2ecf20Sopenharmony_ci atomic_t bufs_queued; 3568c2ecf20Sopenharmony_ci}; 3578c2ecf20Sopenharmony_ci 3588c2ecf20Sopenharmony_cistruct cio2_device { 3598c2ecf20Sopenharmony_ci struct pci_dev *pci_dev; 3608c2ecf20Sopenharmony_ci void __iomem *base; 3618c2ecf20Sopenharmony_ci struct v4l2_device v4l2_dev; 3628c2ecf20Sopenharmony_ci struct cio2_queue queue[CIO2_QUEUES]; 3638c2ecf20Sopenharmony_ci struct cio2_queue *cur_queue; 3648c2ecf20Sopenharmony_ci /* mutex to be used by video_device */ 3658c2ecf20Sopenharmony_ci struct mutex lock; 3668c2ecf20Sopenharmony_ci 3678c2ecf20Sopenharmony_ci bool streaming; 3688c2ecf20Sopenharmony_ci struct v4l2_async_notifier notifier; 3698c2ecf20Sopenharmony_ci struct media_device media_dev; 3708c2ecf20Sopenharmony_ci 3718c2ecf20Sopenharmony_ci /* 3728c2ecf20Sopenharmony_ci * Safety net to catch DMA fetch ahead 3738c2ecf20Sopenharmony_ci * when reaching the end of LOP 3748c2ecf20Sopenharmony_ci */ 3758c2ecf20Sopenharmony_ci void *dummy_page; 3768c2ecf20Sopenharmony_ci /* DMA handle of dummy_page */ 3778c2ecf20Sopenharmony_ci dma_addr_t dummy_page_bus_addr; 3788c2ecf20Sopenharmony_ci /* single List of Pointers (LOP) page */ 3798c2ecf20Sopenharmony_ci u32 *dummy_lop; 3808c2ecf20Sopenharmony_ci /* DMA handle of dummy_lop */ 3818c2ecf20Sopenharmony_ci dma_addr_t dummy_lop_bus_addr; 3828c2ecf20Sopenharmony_ci}; 3838c2ecf20Sopenharmony_ci 3848c2ecf20Sopenharmony_ci/**************** Virtual channel ****************/ 3858c2ecf20Sopenharmony_ci/* 3868c2ecf20Sopenharmony_ci * This should come from sensor driver. No 3878c2ecf20Sopenharmony_ci * driver interface nor requirement yet. 3888c2ecf20Sopenharmony_ci */ 3898c2ecf20Sopenharmony_ci#define SENSOR_VIR_CH_DFLT 0 3908c2ecf20Sopenharmony_ci 3918c2ecf20Sopenharmony_ci/**************** FBPT operations ****************/ 3928c2ecf20Sopenharmony_ci#define CIO2_FBPT_SIZE (CIO2_MAX_BUFFERS * CIO2_MAX_LOPS * \ 3938c2ecf20Sopenharmony_ci sizeof(struct cio2_fbpt_entry)) 3948c2ecf20Sopenharmony_ci 3958c2ecf20Sopenharmony_ci#define CIO2_FBPT_SUBENTRY_UNIT 4 3968c2ecf20Sopenharmony_ci 3978c2ecf20Sopenharmony_ci/* cio2 fbpt first_entry ctrl status */ 3988c2ecf20Sopenharmony_ci#define CIO2_FBPT_CTRL_VALID BIT(0) 3998c2ecf20Sopenharmony_ci#define CIO2_FBPT_CTRL_IOC BIT(1) 4008c2ecf20Sopenharmony_ci#define CIO2_FBPT_CTRL_IOS BIT(2) 4018c2ecf20Sopenharmony_ci#define CIO2_FBPT_CTRL_SUCCXFAIL BIT(3) 4028c2ecf20Sopenharmony_ci#define CIO2_FBPT_CTRL_CMPLCODE_SHIFT 4 4038c2ecf20Sopenharmony_ci 4048c2ecf20Sopenharmony_ci/* 4058c2ecf20Sopenharmony_ci * Frame Buffer Pointer Table(FBPT) entry 4068c2ecf20Sopenharmony_ci * each entry describe an output buffer and consists of 4078c2ecf20Sopenharmony_ci * several sub-entries 4088c2ecf20Sopenharmony_ci */ 4098c2ecf20Sopenharmony_cistruct __packed cio2_fbpt_entry { 4108c2ecf20Sopenharmony_ci union { 4118c2ecf20Sopenharmony_ci struct __packed { 4128c2ecf20Sopenharmony_ci u32 ctrl; /* status ctrl */ 4138c2ecf20Sopenharmony_ci u16 cur_line_num; /* current line # written to DDR */ 4148c2ecf20Sopenharmony_ci u16 frame_num; /* updated by DMA upon FE */ 4158c2ecf20Sopenharmony_ci u32 first_page_offset; /* offset for 1st page in LOP */ 4168c2ecf20Sopenharmony_ci } first_entry; 4178c2ecf20Sopenharmony_ci /* Second entry per buffer */ 4188c2ecf20Sopenharmony_ci struct __packed { 4198c2ecf20Sopenharmony_ci u32 timestamp; 4208c2ecf20Sopenharmony_ci u32 num_of_bytes; 4218c2ecf20Sopenharmony_ci /* the number of bytes for write on last page */ 4228c2ecf20Sopenharmony_ci u16 last_page_available_bytes; 4238c2ecf20Sopenharmony_ci /* the number of pages allocated for this buf */ 4248c2ecf20Sopenharmony_ci u16 num_of_pages; 4258c2ecf20Sopenharmony_ci } second_entry; 4268c2ecf20Sopenharmony_ci }; 4278c2ecf20Sopenharmony_ci u32 lop_page_addr; /* Points to list of pointers (LOP) table */ 4288c2ecf20Sopenharmony_ci}; 4298c2ecf20Sopenharmony_ci 4308c2ecf20Sopenharmony_cistatic inline struct cio2_queue *file_to_cio2_queue(struct file *file) 4318c2ecf20Sopenharmony_ci{ 4328c2ecf20Sopenharmony_ci return container_of(video_devdata(file), struct cio2_queue, vdev); 4338c2ecf20Sopenharmony_ci} 4348c2ecf20Sopenharmony_ci 4358c2ecf20Sopenharmony_cistatic inline struct cio2_queue *vb2q_to_cio2_queue(struct vb2_queue *vq) 4368c2ecf20Sopenharmony_ci{ 4378c2ecf20Sopenharmony_ci return container_of(vq, struct cio2_queue, vbq); 4388c2ecf20Sopenharmony_ci} 4398c2ecf20Sopenharmony_ci 4408c2ecf20Sopenharmony_ci#endif 441