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