ipu3-cio2.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /* Copyright (C) 2017 Intel Corporation */
  3. #ifndef __IPU3_CIO2_H
  4. #define __IPU3_CIO2_H
  5. #define CIO2_NAME "ipu3-cio2"
  6. #define CIO2_DEVICE_NAME "Intel IPU3 CIO2"
  7. #define CIO2_ENTITY_NAME "ipu3-csi2"
  8. #define CIO2_PCI_ID 0x9d32
  9. #define CIO2_PCI_BAR 0
  10. #define CIO2_DMA_MASK DMA_BIT_MASK(39)
  11. #define CIO2_IMAGE_MAX_WIDTH 4224
  12. #define CIO2_IMAGE_MAX_LENGTH 3136
  13. #define CIO2_IMAGE_MAX_WIDTH 4224
  14. #define CIO2_IMAGE_MAX_LENGTH 3136
  15. /* 32MB = 8xFBPT_entry */
  16. #define CIO2_MAX_LOPS 8
  17. #define CIO2_MAX_BUFFERS (PAGE_SIZE / 16 / CIO2_MAX_LOPS)
  18. #define CIO2_PAD_SINK 0
  19. #define CIO2_PAD_SOURCE 1
  20. #define CIO2_PADS 2
  21. #define CIO2_NUM_DMA_CHAN 20
  22. #define CIO2_NUM_PORTS 4 /* DPHYs */
  23. /* 1 for each sensor */
  24. #define CIO2_QUEUES CIO2_NUM_PORTS
  25. /* Register and bit field definitions */
  26. #define CIO2_REG_PIPE_BASE(n) ((n) * 0x0400) /* n = 0..3 */
  27. #define CIO2_REG_CSIRX_BASE 0x000
  28. #define CIO2_REG_MIPIBE_BASE 0x100
  29. #define CIO2_REG_PIXELGEN_BAS 0x200
  30. #define CIO2_REG_IRQCTRL_BASE 0x300
  31. #define CIO2_REG_GPREG_BASE 0x1000
  32. /* base register: CIO2_REG_PIPE_BASE(pipe) * CIO2_REG_CSIRX_BASE */
  33. #define CIO2_REG_CSIRX_ENABLE (CIO2_REG_CSIRX_BASE + 0x0)
  34. #define CIO2_REG_CSIRX_NOF_ENABLED_LANES (CIO2_REG_CSIRX_BASE + 0x4)
  35. #define CIO2_REG_CSIRX_SP_IF_CONFIG (CIO2_REG_CSIRX_BASE + 0x10)
  36. #define CIO2_REG_CSIRX_LP_IF_CONFIG (CIO2_REG_CSIRX_BASE + 0x14)
  37. #define CIO2_CSIRX_IF_CONFIG_FILTEROUT 0x00
  38. #define CIO2_CSIRX_IF_CONFIG_FILTEROUT_VC_INACTIVE 0x01
  39. #define CIO2_CSIRX_IF_CONFIG_PASS 0x02
  40. #define CIO2_CSIRX_IF_CONFIG_FLAG_ERROR BIT(2)
  41. #define CIO2_REG_CSIRX_STATUS (CIO2_REG_CSIRX_BASE + 0x18)
  42. #define CIO2_REG_CSIRX_STATUS_DLANE_HS (CIO2_REG_CSIRX_BASE + 0x1c)
  43. #define CIO2_CSIRX_STATUS_DLANE_HS_MASK 0xff
  44. #define CIO2_REG_CSIRX_STATUS_DLANE_LP (CIO2_REG_CSIRX_BASE + 0x20)
  45. #define CIO2_CSIRX_STATUS_DLANE_LP_MASK 0xffffff
  46. /* Termination enable and settle in 0.0625ns units, lane=0..3 or -1 for clock */
  47. #define CIO2_REG_CSIRX_DLY_CNT_TERMEN(lane) \
  48. (CIO2_REG_CSIRX_BASE + 0x2c + 8 * (lane))
  49. #define CIO2_REG_CSIRX_DLY_CNT_SETTLE(lane) \
  50. (CIO2_REG_CSIRX_BASE + 0x30 + 8 * (lane))
  51. /* base register: CIO2_REG_PIPE_BASE(pipe) * CIO2_REG_MIPIBE_BASE */
  52. #define CIO2_REG_MIPIBE_ENABLE (CIO2_REG_MIPIBE_BASE + 0x0)
  53. #define CIO2_REG_MIPIBE_STATUS (CIO2_REG_MIPIBE_BASE + 0x4)
  54. #define CIO2_REG_MIPIBE_COMP_FORMAT(vc) \
  55. (CIO2_REG_MIPIBE_BASE + 0x8 + 0x4 * (vc))
  56. #define CIO2_REG_MIPIBE_FORCE_RAW8 (CIO2_REG_MIPIBE_BASE + 0x20)
  57. #define CIO2_REG_MIPIBE_FORCE_RAW8_ENABLE BIT(0)
  58. #define CIO2_REG_MIPIBE_FORCE_RAW8_USE_TYPEID BIT(1)
  59. #define CIO2_REG_MIPIBE_FORCE_RAW8_TYPEID_SHIFT 2
  60. #define CIO2_REG_MIPIBE_IRQ_STATUS (CIO2_REG_MIPIBE_BASE + 0x24)
  61. #define CIO2_REG_MIPIBE_IRQ_CLEAR (CIO2_REG_MIPIBE_BASE + 0x28)
  62. #define CIO2_REG_MIPIBE_GLOBAL_LUT_DISREGARD (CIO2_REG_MIPIBE_BASE + 0x68)
  63. #define CIO2_MIPIBE_GLOBAL_LUT_DISREGARD 1
  64. #define CIO2_REG_MIPIBE_PKT_STALL_STATUS (CIO2_REG_MIPIBE_BASE + 0x6c)
  65. #define CIO2_REG_MIPIBE_PARSE_GSP_THROUGH_LP_LUT_REG_IDX \
  66. (CIO2_REG_MIPIBE_BASE + 0x70)
  67. #define CIO2_REG_MIPIBE_SP_LUT_ENTRY(vc) \
  68. (CIO2_REG_MIPIBE_BASE + 0x74 + 4 * (vc))
  69. #define CIO2_REG_MIPIBE_LP_LUT_ENTRY(m) /* m = 0..15 */ \
  70. (CIO2_REG_MIPIBE_BASE + 0x84 + 4 * (m))
  71. #define CIO2_MIPIBE_LP_LUT_ENTRY_DISREGARD 1
  72. #define CIO2_MIPIBE_LP_LUT_ENTRY_SID_SHIFT 1
  73. #define CIO2_MIPIBE_LP_LUT_ENTRY_VC_SHIFT 5
  74. #define CIO2_MIPIBE_LP_LUT_ENTRY_FORMAT_TYPE_SHIFT 7
  75. /* base register: CIO2_REG_PIPE_BASE(pipe) * CIO2_REG_IRQCTRL_BASE */
  76. /* IRQ registers are 18-bit wide, see cio2_irq_error for bit definitions */
  77. #define CIO2_REG_IRQCTRL_EDGE (CIO2_REG_IRQCTRL_BASE + 0x00)
  78. #define CIO2_REG_IRQCTRL_MASK (CIO2_REG_IRQCTRL_BASE + 0x04)
  79. #define CIO2_REG_IRQCTRL_STATUS (CIO2_REG_IRQCTRL_BASE + 0x08)
  80. #define CIO2_REG_IRQCTRL_CLEAR (CIO2_REG_IRQCTRL_BASE + 0x0c)
  81. #define CIO2_REG_IRQCTRL_ENABLE (CIO2_REG_IRQCTRL_BASE + 0x10)
  82. #define CIO2_REG_IRQCTRL_LEVEL_NOT_PULSE (CIO2_REG_IRQCTRL_BASE + 0x14)
  83. #define CIO2_REG_GPREG_SRST (CIO2_REG_GPREG_BASE + 0x0)
  84. #define CIO2_GPREG_SRST_ALL 0xffff /* Reset all */
  85. #define CIO2_REG_FB_HPLL_FREQ (CIO2_REG_GPREG_BASE + 0x08)
  86. #define CIO2_REG_ISCLK_RATIO (CIO2_REG_GPREG_BASE + 0xc)
  87. #define CIO2_REG_CGC 0x1400
  88. #define CIO2_CGC_CSI2_TGE BIT(0)
  89. #define CIO2_CGC_PRIM_TGE BIT(1)
  90. #define CIO2_CGC_SIDE_TGE BIT(2)
  91. #define CIO2_CGC_XOSC_TGE BIT(3)
  92. #define CIO2_CGC_MPLL_SHUTDOWN_EN BIT(4)
  93. #define CIO2_CGC_D3I3_TGE BIT(5)
  94. #define CIO2_CGC_CSI2_INTERFRAME_TGE BIT(6)
  95. #define CIO2_CGC_CSI2_PORT_DCGE BIT(8)
  96. #define CIO2_CGC_CSI2_DCGE BIT(9)
  97. #define CIO2_CGC_SIDE_DCGE BIT(10)
  98. #define CIO2_CGC_PRIM_DCGE BIT(11)
  99. #define CIO2_CGC_ROSC_DCGE BIT(12)
  100. #define CIO2_CGC_XOSC_DCGE BIT(13)
  101. #define CIO2_CGC_FLIS_DCGE BIT(14)
  102. #define CIO2_CGC_CLKGATE_HOLDOFF_SHIFT 20
  103. #define CIO2_CGC_CSI_CLKGATE_HOLDOFF_SHIFT 24
  104. #define CIO2_REG_D0I3C 0x1408
  105. #define CIO2_D0I3C_I3 BIT(2) /* Set D0I3 */
  106. #define CIO2_D0I3C_RR BIT(3) /* Restore? */
  107. #define CIO2_REG_SWRESET 0x140c
  108. #define CIO2_SWRESET_SWRESET 1
  109. #define CIO2_REG_SENSOR_ACTIVE 0x1410
  110. #define CIO2_REG_INT_STS 0x1414
  111. #define CIO2_REG_INT_STS_EXT_OE 0x1418
  112. #define CIO2_INT_EXT_OE_DMAOE_SHIFT 0
  113. #define CIO2_INT_EXT_OE_DMAOE_MASK 0x7ffff
  114. #define CIO2_INT_EXT_OE_OES_SHIFT 24
  115. #define CIO2_INT_EXT_OE_OES_MASK (0xf << CIO2_INT_EXT_OE_OES_SHIFT)
  116. #define CIO2_REG_INT_EN 0x1420
  117. #define CIO2_REG_INT_EN_IRQ (1 << 24)
  118. #define CIO2_REG_INT_EN_IOS(dma) (1 << (((dma) >> 1) + 12))
  119. /*
  120. * Interrupt on completion bit, Eg. DMA 0-3 maps to bit 0-3,
  121. * DMA4 & DMA5 map to bit 4 ... DMA18 & DMA19 map to bit 11 Et cetera
  122. */
  123. #define CIO2_INT_IOC(dma) (1 << ((dma) < 4 ? (dma) : ((dma) >> 1) + 2))
  124. #define CIO2_INT_IOC_SHIFT 0
  125. #define CIO2_INT_IOC_MASK (0x7ff << CIO2_INT_IOC_SHIFT)
  126. #define CIO2_INT_IOS_IOLN(dma) (1 << (((dma) >> 1) + 12))
  127. #define CIO2_INT_IOS_IOLN_SHIFT 12
  128. #define CIO2_INT_IOS_IOLN_MASK (0x3ff << CIO2_INT_IOS_IOLN_SHIFT)
  129. #define CIO2_INT_IOIE BIT(22)
  130. #define CIO2_INT_IOOE BIT(23)
  131. #define CIO2_INT_IOIRQ BIT(24)
  132. #define CIO2_REG_INT_EN_EXT_OE 0x1424
  133. #define CIO2_REG_DMA_DBG 0x1448
  134. #define CIO2_REG_DMA_DBG_DMA_INDEX_SHIFT 0
  135. #define CIO2_REG_PBM_ARB_CTRL 0x1460
  136. #define CIO2_PBM_ARB_CTRL_LANES_DIV 0 /* 4-4-2-2 lanes */
  137. #define CIO2_PBM_ARB_CTRL_LANES_DIV_SHIFT 0
  138. #define CIO2_PBM_ARB_CTRL_LE_EN BIT(7)
  139. #define CIO2_PBM_ARB_CTRL_PLL_POST_SHTDN 2
  140. #define CIO2_PBM_ARB_CTRL_PLL_POST_SHTDN_SHIFT 8
  141. #define CIO2_PBM_ARB_CTRL_PLL_AHD_WK_UP 480
  142. #define CIO2_PBM_ARB_CTRL_PLL_AHD_WK_UP_SHIFT 16
  143. #define CIO2_REG_PBM_WMCTRL1 0x1464
  144. #define CIO2_PBM_WMCTRL1_MIN_2CK_SHIFT 0
  145. #define CIO2_PBM_WMCTRL1_MID1_2CK_SHIFT 8
  146. #define CIO2_PBM_WMCTRL1_MID2_2CK_SHIFT 16
  147. #define CIO2_PBM_WMCTRL1_TS_COUNT_DISABLE BIT(31)
  148. #define CIO2_PBM_WMCTRL1_MIN_2CK (4 << CIO2_PBM_WMCTRL1_MIN_2CK_SHIFT)
  149. #define CIO2_PBM_WMCTRL1_MID1_2CK (16 << CIO2_PBM_WMCTRL1_MID1_2CK_SHIFT)
  150. #define CIO2_PBM_WMCTRL1_MID2_2CK (21 << CIO2_PBM_WMCTRL1_MID2_2CK_SHIFT)
  151. #define CIO2_REG_PBM_WMCTRL2 0x1468
  152. #define CIO2_PBM_WMCTRL2_HWM_2CK 40
  153. #define CIO2_PBM_WMCTRL2_HWM_2CK_SHIFT 0
  154. #define CIO2_PBM_WMCTRL2_LWM_2CK 22
  155. #define CIO2_PBM_WMCTRL2_LWM_2CK_SHIFT 8
  156. #define CIO2_PBM_WMCTRL2_OBFFWM_2CK 2
  157. #define CIO2_PBM_WMCTRL2_OBFFWM_2CK_SHIFT 16
  158. #define CIO2_PBM_WMCTRL2_TRANSDYN 1
  159. #define CIO2_PBM_WMCTRL2_TRANSDYN_SHIFT 24
  160. #define CIO2_PBM_WMCTRL2_DYNWMEN BIT(28)
  161. #define CIO2_PBM_WMCTRL2_OBFF_MEM_EN BIT(29)
  162. #define CIO2_PBM_WMCTRL2_OBFF_CPU_EN BIT(30)
  163. #define CIO2_PBM_WMCTRL2_DRAINNOW BIT(31)
  164. #define CIO2_REG_PBM_TS_COUNT 0x146c
  165. #define CIO2_REG_PBM_FOPN_ABORT 0x1474
  166. /* below n = 0..3 */
  167. #define CIO2_PBM_FOPN_ABORT(n) (0x1 << 8 * (n))
  168. #define CIO2_PBM_FOPN_FORCE_ABORT(n) (0x2 << 8 * (n))
  169. #define CIO2_PBM_FOPN_FRAMEOPEN(n) (0x8 << 8 * (n))
  170. #define CIO2_REG_LTRCTRL 0x1480
  171. #define CIO2_LTRCTRL_LTRDYNEN BIT(16)
  172. #define CIO2_LTRCTRL_LTRSTABLETIME_SHIFT 8
  173. #define CIO2_LTRCTRL_LTRSTABLETIME_MASK 0xff
  174. #define CIO2_LTRCTRL_LTRSEL1S3 BIT(7)
  175. #define CIO2_LTRCTRL_LTRSEL1S2 BIT(6)
  176. #define CIO2_LTRCTRL_LTRSEL1S1 BIT(5)
  177. #define CIO2_LTRCTRL_LTRSEL1S0 BIT(4)
  178. #define CIO2_LTRCTRL_LTRSEL2S3 BIT(3)
  179. #define CIO2_LTRCTRL_LTRSEL2S2 BIT(2)
  180. #define CIO2_LTRCTRL_LTRSEL2S1 BIT(1)
  181. #define CIO2_LTRCTRL_LTRSEL2S0 BIT(0)
  182. #define CIO2_REG_LTRVAL23 0x1484
  183. #define CIO2_REG_LTRVAL01 0x1488
  184. #define CIO2_LTRVAL02_VAL_SHIFT 0
  185. #define CIO2_LTRVAL02_SCALE_SHIFT 10
  186. #define CIO2_LTRVAL13_VAL_SHIFT 16
  187. #define CIO2_LTRVAL13_SCALE_SHIFT 26
  188. #define CIO2_LTRVAL0_VAL 175
  189. /* Value times 1024 ns */
  190. #define CIO2_LTRVAL0_SCALE 2
  191. #define CIO2_LTRVAL1_VAL 90
  192. #define CIO2_LTRVAL1_SCALE 2
  193. #define CIO2_LTRVAL2_VAL 90
  194. #define CIO2_LTRVAL2_SCALE 2
  195. #define CIO2_LTRVAL3_VAL 90
  196. #define CIO2_LTRVAL3_SCALE 2
  197. #define CIO2_REG_CDMABA(n) (0x1500 + 0x10 * (n)) /* n = 0..19 */
  198. #define CIO2_REG_CDMARI(n) (0x1504 + 0x10 * (n))
  199. #define CIO2_CDMARI_FBPT_RP_SHIFT 0
  200. #define CIO2_CDMARI_FBPT_RP_MASK 0xff
  201. #define CIO2_REG_CDMAC0(n) (0x1508 + 0x10 * (n))
  202. #define CIO2_CDMAC0_FBPT_LEN_SHIFT 0
  203. #define CIO2_CDMAC0_FBPT_WIDTH_SHIFT 8
  204. #define CIO2_CDMAC0_FBPT_NS BIT(25)
  205. #define CIO2_CDMAC0_DMA_INTR_ON_FS BIT(26)
  206. #define CIO2_CDMAC0_DMA_INTR_ON_FE BIT(27)
  207. #define CIO2_CDMAC0_FBPT_UPDATE_FIFO_FULL BIT(28)
  208. #define CIO2_CDMAC0_FBPT_FIFO_FULL_FIX_DIS BIT(29)
  209. #define CIO2_CDMAC0_DMA_EN BIT(30)
  210. #define CIO2_CDMAC0_DMA_HALTED BIT(31)
  211. #define CIO2_REG_CDMAC1(n) (0x150c + 0x10 * (n))
  212. #define CIO2_CDMAC1_LINENUMINT_SHIFT 0
  213. #define CIO2_CDMAC1_LINENUMUPDATE_SHIFT 16
  214. /* n = 0..3 */
  215. #define CIO2_REG_PXM_PXF_FMT_CFG0(n) (0x1700 + 0x30 * (n))
  216. #define CIO2_PXM_PXF_FMT_CFG_SID0_SHIFT 0
  217. #define CIO2_PXM_PXF_FMT_CFG_SID1_SHIFT 16
  218. #define CIO2_PXM_PXF_FMT_CFG_PCK_64B (0 << 0)
  219. #define CIO2_PXM_PXF_FMT_CFG_PCK_32B (1 << 0)
  220. #define CIO2_PXM_PXF_FMT_CFG_BPP_08 (0 << 2)
  221. #define CIO2_PXM_PXF_FMT_CFG_BPP_10 (1 << 2)
  222. #define CIO2_PXM_PXF_FMT_CFG_BPP_12 (2 << 2)
  223. #define CIO2_PXM_PXF_FMT_CFG_BPP_14 (3 << 2)
  224. #define CIO2_PXM_PXF_FMT_CFG_SPEC_4PPC (0 << 4)
  225. #define CIO2_PXM_PXF_FMT_CFG_SPEC_3PPC_RGBA (1 << 4)
  226. #define CIO2_PXM_PXF_FMT_CFG_SPEC_3PPC_ARGB (2 << 4)
  227. #define CIO2_PXM_PXF_FMT_CFG_SPEC_PLANAR2 (3 << 4)
  228. #define CIO2_PXM_PXF_FMT_CFG_SPEC_PLANAR3 (4 << 4)
  229. #define CIO2_PXM_PXF_FMT_CFG_SPEC_NV16 (5 << 4)
  230. #define CIO2_PXM_PXF_FMT_CFG_PSWAP4_1ST_AB (1 << 7)
  231. #define CIO2_PXM_PXF_FMT_CFG_PSWAP4_1ST_CD (1 << 8)
  232. #define CIO2_PXM_PXF_FMT_CFG_PSWAP4_2ND_AC (1 << 9)
  233. #define CIO2_PXM_PXF_FMT_CFG_PSWAP4_2ND_BD (1 << 10)
  234. #define CIO2_REG_INT_STS_EXT_IE 0x17e4
  235. #define CIO2_REG_INT_EN_EXT_IE 0x17e8
  236. #define CIO2_INT_EXT_IE_ECC_RE(n) (0x01 << (8 * (n)))
  237. #define CIO2_INT_EXT_IE_DPHY_NR(n) (0x02 << (8 * (n)))
  238. #define CIO2_INT_EXT_IE_ECC_NR(n) (0x04 << (8 * (n)))
  239. #define CIO2_INT_EXT_IE_CRCERR(n) (0x08 << (8 * (n)))
  240. #define CIO2_INT_EXT_IE_INTERFRAMEDATA(n) (0x10 << (8 * (n)))
  241. #define CIO2_INT_EXT_IE_PKT2SHORT(n) (0x20 << (8 * (n)))
  242. #define CIO2_INT_EXT_IE_PKT2LONG(n) (0x40 << (8 * (n)))
  243. #define CIO2_INT_EXT_IE_IRQ(n) (0x80 << (8 * (n)))
  244. #define CIO2_REG_PXM_FRF_CFG(n) (0x1720 + 0x30 * (n))
  245. #define CIO2_PXM_FRF_CFG_FNSEL BIT(0)
  246. #define CIO2_PXM_FRF_CFG_FN_RST BIT(1)
  247. #define CIO2_PXM_FRF_CFG_ABORT BIT(2)
  248. #define CIO2_PXM_FRF_CFG_CRC_TH_SHIFT 3
  249. #define CIO2_PXM_FRF_CFG_MSK_ECC_DPHY_NR BIT(8)
  250. #define CIO2_PXM_FRF_CFG_MSK_ECC_RE BIT(9)
  251. #define CIO2_PXM_FRF_CFG_MSK_ECC_DPHY_NE BIT(10)
  252. #define CIO2_PXM_FRF_CFG_EVEN_ODD_MODE_SHIFT 11
  253. #define CIO2_PXM_FRF_CFG_MASK_CRC_THRES BIT(13)
  254. #define CIO2_PXM_FRF_CFG_MASK_CSI_ACCEPT BIT(14)
  255. #define CIO2_PXM_FRF_CFG_CIOHC_FS_MODE BIT(15)
  256. #define CIO2_PXM_FRF_CFG_CIOHC_FRST_FRM_SHIFT 16
  257. #define CIO2_REG_PXM_SID2BID0(n) (0x1724 + 0x30 * (n))
  258. #define CIO2_FB_HPLL_FREQ 0x2
  259. #define CIO2_ISCLK_RATIO 0xc
  260. #define CIO2_IRQCTRL_MASK 0x3ffff
  261. #define CIO2_INT_EN_EXT_OE_MASK 0x8f0fffff
  262. #define CIO2_CGC_CLKGATE_HOLDOFF 3
  263. #define CIO2_CGC_CSI_CLKGATE_HOLDOFF 5
  264. #define CIO2_PXM_FRF_CFG_CRC_TH 16
  265. #define CIO2_INT_EN_EXT_IE_MASK 0xffffffff
  266. #define CIO2_DMA_CHAN 0
  267. #define CIO2_CSIRX_DLY_CNT_CLANE_IDX -1
  268. #define CIO2_CSIRX_DLY_CNT_TERMEN_CLANE_A 0
  269. #define CIO2_CSIRX_DLY_CNT_TERMEN_CLANE_B 0
  270. #define CIO2_CSIRX_DLY_CNT_SETTLE_CLANE_A 95
  271. #define CIO2_CSIRX_DLY_CNT_SETTLE_CLANE_B -8
  272. #define CIO2_CSIRX_DLY_CNT_TERMEN_DLANE_A 0
  273. #define CIO2_CSIRX_DLY_CNT_TERMEN_DLANE_B 0
  274. #define CIO2_CSIRX_DLY_CNT_SETTLE_DLANE_A 85
  275. #define CIO2_CSIRX_DLY_CNT_SETTLE_DLANE_B -2
  276. #define CIO2_CSIRX_DLY_CNT_TERMEN_DEFAULT 0x4
  277. #define CIO2_CSIRX_DLY_CNT_SETTLE_DEFAULT 0x570
  278. #define CIO2_PMCSR_OFFSET 4
  279. #define CIO2_PMCSR_D0D3_SHIFT 2
  280. #define CIO2_PMCSR_D3 0x3
  281. struct cio2_csi2_timing {
  282. s32 clk_termen;
  283. s32 clk_settle;
  284. s32 dat_termen;
  285. s32 dat_settle;
  286. };
  287. struct cio2_buffer {
  288. struct vb2_v4l2_buffer vbb;
  289. u32 *lop[CIO2_MAX_LOPS];
  290. dma_addr_t lop_bus_addr[CIO2_MAX_LOPS];
  291. unsigned int offset;
  292. };
  293. struct csi2_bus_info {
  294. u32 port;
  295. u32 lanes;
  296. };
  297. struct cio2_queue {
  298. /* mutex to be used by vb2_queue */
  299. struct mutex lock;
  300. struct media_pipeline pipe;
  301. struct csi2_bus_info csi2;
  302. struct v4l2_subdev *sensor;
  303. void __iomem *csi_rx_base;
  304. /* Subdev, /dev/v4l-subdevX */
  305. struct v4l2_subdev subdev;
  306. struct media_pad subdev_pads[CIO2_PADS];
  307. struct v4l2_mbus_framefmt subdev_fmt;
  308. atomic_t frame_sequence;
  309. /* Video device, /dev/videoX */
  310. struct video_device vdev;
  311. struct media_pad vdev_pad;
  312. struct v4l2_pix_format_mplane format;
  313. struct vb2_queue vbq;
  314. /* Buffer queue handling */
  315. struct cio2_fbpt_entry *fbpt; /* Frame buffer pointer table */
  316. dma_addr_t fbpt_bus_addr;
  317. struct cio2_buffer *bufs[CIO2_MAX_BUFFERS];
  318. unsigned int bufs_first; /* Index of the first used entry */
  319. unsigned int bufs_next; /* Index of the first unused entry */
  320. atomic_t bufs_queued;
  321. };
  322. struct cio2_device {
  323. struct pci_dev *pci_dev;
  324. void __iomem *base;
  325. struct v4l2_device v4l2_dev;
  326. struct cio2_queue queue[CIO2_QUEUES];
  327. struct cio2_queue *cur_queue;
  328. /* mutex to be used by video_device */
  329. struct mutex lock;
  330. bool streaming;
  331. struct v4l2_async_notifier notifier;
  332. struct media_device media_dev;
  333. /*
  334. * Safety net to catch DMA fetch ahead
  335. * when reaching the end of LOP
  336. */
  337. void *dummy_page;
  338. /* DMA handle of dummy_page */
  339. dma_addr_t dummy_page_bus_addr;
  340. /* single List of Pointers (LOP) page */
  341. u32 *dummy_lop;
  342. /* DMA handle of dummy_lop */
  343. dma_addr_t dummy_lop_bus_addr;
  344. };
  345. /**************** Virtual channel ****************/
  346. /*
  347. * This should come from sensor driver. No
  348. * driver interface nor requirement yet.
  349. */
  350. #define SENSOR_VIR_CH_DFLT 0
  351. /**************** FBPT operations ****************/
  352. #define CIO2_FBPT_SIZE (CIO2_MAX_BUFFERS * CIO2_MAX_LOPS * \
  353. sizeof(struct cio2_fbpt_entry))
  354. #define CIO2_FBPT_SUBENTRY_UNIT 4
  355. #define CIO2_PAGE_SIZE 4096
  356. /* cio2 fbpt first_entry ctrl status */
  357. #define CIO2_FBPT_CTRL_VALID BIT(0)
  358. #define CIO2_FBPT_CTRL_IOC BIT(1)
  359. #define CIO2_FBPT_CTRL_IOS BIT(2)
  360. #define CIO2_FBPT_CTRL_SUCCXFAIL BIT(3)
  361. #define CIO2_FBPT_CTRL_CMPLCODE_SHIFT 4
  362. /*
  363. * Frame Buffer Pointer Table(FBPT) entry
  364. * each entry describe an output buffer and consists of
  365. * several sub-entries
  366. */
  367. struct __packed cio2_fbpt_entry {
  368. union {
  369. struct __packed {
  370. u32 ctrl; /* status ctrl */
  371. u16 cur_line_num; /* current line # written to DDR */
  372. u16 frame_num; /* updated by DMA upon FE */
  373. u32 first_page_offset; /* offset for 1st page in LOP */
  374. } first_entry;
  375. /* Second entry per buffer */
  376. struct __packed {
  377. u32 timestamp;
  378. u32 num_of_bytes;
  379. /* the number of bytes for write on last page */
  380. u16 last_page_available_bytes;
  381. /* the number of pages allocated for this buf */
  382. u16 num_of_pages;
  383. } second_entry;
  384. };
  385. u32 lop_page_addr; /* Points to list of pointers (LOP) table */
  386. };
  387. static inline struct cio2_queue *file_to_cio2_queue(struct file *file)
  388. {
  389. return container_of(video_devdata(file), struct cio2_queue, vdev);
  390. }
  391. static inline struct cio2_queue *vb2q_to_cio2_queue(struct vb2_queue *vq)
  392. {
  393. return container_of(vq, struct cio2_queue, vbq);
  394. }
  395. #endif