xref: /linux/drivers/media/platform/ti/davinci/vpif.h (revision 4f2c0a4acffbec01079c28f839422e64ddeff004)
12aec85b2SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
2d24a170bSMauro Carvalho Chehab /*
3d24a170bSMauro Carvalho Chehab  * VPIF header file
4d24a170bSMauro Carvalho Chehab  *
5d24a170bSMauro Carvalho Chehab  * Copyright (C) 2009 Texas Instruments Incorporated - https://www.ti.com/
6d24a170bSMauro Carvalho Chehab  */
7d24a170bSMauro Carvalho Chehab 
8d24a170bSMauro Carvalho Chehab #ifndef VPIF_H
9d24a170bSMauro Carvalho Chehab #define VPIF_H
10d24a170bSMauro Carvalho Chehab 
11d24a170bSMauro Carvalho Chehab #include <linux/io.h>
12d24a170bSMauro Carvalho Chehab #include <linux/videodev2.h>
13d24a170bSMauro Carvalho Chehab #include <media/davinci/vpif_types.h>
14d24a170bSMauro Carvalho Chehab 
15d24a170bSMauro Carvalho Chehab /* Maximum channel allowed */
16d24a170bSMauro Carvalho Chehab #define VPIF_NUM_CHANNELS		(4)
17d24a170bSMauro Carvalho Chehab #define VPIF_CAPTURE_NUM_CHANNELS	(2)
18d24a170bSMauro Carvalho Chehab #define VPIF_DISPLAY_NUM_CHANNELS	(2)
19d24a170bSMauro Carvalho Chehab 
20d24a170bSMauro Carvalho Chehab /* Macros to read/write registers */
21d24a170bSMauro Carvalho Chehab extern void __iomem *vpif_base;
22d24a170bSMauro Carvalho Chehab extern spinlock_t vpif_lock;
23d24a170bSMauro Carvalho Chehab 
24d24a170bSMauro Carvalho Chehab #define regr(reg)               readl((reg) + vpif_base)
25d24a170bSMauro Carvalho Chehab #define regw(value, reg)        writel(value, (reg + vpif_base))
26d24a170bSMauro Carvalho Chehab 
27d24a170bSMauro Carvalho Chehab /* Register Address Offsets */
28d24a170bSMauro Carvalho Chehab #define VPIF_PID			(0x0000)
29d24a170bSMauro Carvalho Chehab #define VPIF_CH0_CTRL			(0x0004)
30d24a170bSMauro Carvalho Chehab #define VPIF_CH1_CTRL			(0x0008)
31d24a170bSMauro Carvalho Chehab #define VPIF_CH2_CTRL			(0x000C)
32d24a170bSMauro Carvalho Chehab #define VPIF_CH3_CTRL			(0x0010)
33d24a170bSMauro Carvalho Chehab 
34d24a170bSMauro Carvalho Chehab #define VPIF_INTEN			(0x0020)
35d24a170bSMauro Carvalho Chehab #define VPIF_INTEN_SET			(0x0024)
36d24a170bSMauro Carvalho Chehab #define VPIF_INTEN_CLR			(0x0028)
37d24a170bSMauro Carvalho Chehab #define VPIF_STATUS			(0x002C)
38d24a170bSMauro Carvalho Chehab #define VPIF_STATUS_CLR			(0x0030)
39d24a170bSMauro Carvalho Chehab #define VPIF_EMULATION_CTRL		(0x0034)
40d24a170bSMauro Carvalho Chehab #define VPIF_REQ_SIZE			(0x0038)
41d24a170bSMauro Carvalho Chehab 
42d24a170bSMauro Carvalho Chehab #define VPIF_CH0_TOP_STRT_ADD_LUMA	(0x0040)
43d24a170bSMauro Carvalho Chehab #define VPIF_CH0_BTM_STRT_ADD_LUMA	(0x0044)
44d24a170bSMauro Carvalho Chehab #define VPIF_CH0_TOP_STRT_ADD_CHROMA	(0x0048)
45d24a170bSMauro Carvalho Chehab #define VPIF_CH0_BTM_STRT_ADD_CHROMA	(0x004c)
46d24a170bSMauro Carvalho Chehab #define VPIF_CH0_TOP_STRT_ADD_HANC	(0x0050)
47d24a170bSMauro Carvalho Chehab #define VPIF_CH0_BTM_STRT_ADD_HANC	(0x0054)
48d24a170bSMauro Carvalho Chehab #define VPIF_CH0_TOP_STRT_ADD_VANC	(0x0058)
49d24a170bSMauro Carvalho Chehab #define VPIF_CH0_BTM_STRT_ADD_VANC	(0x005c)
50d24a170bSMauro Carvalho Chehab #define VPIF_CH0_SP_CFG			(0x0060)
51d24a170bSMauro Carvalho Chehab #define VPIF_CH0_IMG_ADD_OFST		(0x0064)
52d24a170bSMauro Carvalho Chehab #define VPIF_CH0_HANC_ADD_OFST		(0x0068)
53d24a170bSMauro Carvalho Chehab #define VPIF_CH0_H_CFG			(0x006c)
54d24a170bSMauro Carvalho Chehab #define VPIF_CH0_V_CFG_00		(0x0070)
55d24a170bSMauro Carvalho Chehab #define VPIF_CH0_V_CFG_01		(0x0074)
56d24a170bSMauro Carvalho Chehab #define VPIF_CH0_V_CFG_02		(0x0078)
57d24a170bSMauro Carvalho Chehab #define VPIF_CH0_V_CFG_03		(0x007c)
58d24a170bSMauro Carvalho Chehab 
59d24a170bSMauro Carvalho Chehab #define VPIF_CH1_TOP_STRT_ADD_LUMA	(0x0080)
60d24a170bSMauro Carvalho Chehab #define VPIF_CH1_BTM_STRT_ADD_LUMA	(0x0084)
61d24a170bSMauro Carvalho Chehab #define VPIF_CH1_TOP_STRT_ADD_CHROMA	(0x0088)
62d24a170bSMauro Carvalho Chehab #define VPIF_CH1_BTM_STRT_ADD_CHROMA	(0x008c)
63d24a170bSMauro Carvalho Chehab #define VPIF_CH1_TOP_STRT_ADD_HANC	(0x0090)
64d24a170bSMauro Carvalho Chehab #define VPIF_CH1_BTM_STRT_ADD_HANC	(0x0094)
65d24a170bSMauro Carvalho Chehab #define VPIF_CH1_TOP_STRT_ADD_VANC	(0x0098)
66d24a170bSMauro Carvalho Chehab #define VPIF_CH1_BTM_STRT_ADD_VANC	(0x009c)
67d24a170bSMauro Carvalho Chehab #define VPIF_CH1_SP_CFG			(0x00a0)
68d24a170bSMauro Carvalho Chehab #define VPIF_CH1_IMG_ADD_OFST		(0x00a4)
69d24a170bSMauro Carvalho Chehab #define VPIF_CH1_HANC_ADD_OFST		(0x00a8)
70d24a170bSMauro Carvalho Chehab #define VPIF_CH1_H_CFG			(0x00ac)
71d24a170bSMauro Carvalho Chehab #define VPIF_CH1_V_CFG_00		(0x00b0)
72d24a170bSMauro Carvalho Chehab #define VPIF_CH1_V_CFG_01		(0x00b4)
73d24a170bSMauro Carvalho Chehab #define VPIF_CH1_V_CFG_02		(0x00b8)
74d24a170bSMauro Carvalho Chehab #define VPIF_CH1_V_CFG_03		(0x00bc)
75d24a170bSMauro Carvalho Chehab 
76d24a170bSMauro Carvalho Chehab #define VPIF_CH2_TOP_STRT_ADD_LUMA	(0x00c0)
77d24a170bSMauro Carvalho Chehab #define VPIF_CH2_BTM_STRT_ADD_LUMA	(0x00c4)
78d24a170bSMauro Carvalho Chehab #define VPIF_CH2_TOP_STRT_ADD_CHROMA	(0x00c8)
79d24a170bSMauro Carvalho Chehab #define VPIF_CH2_BTM_STRT_ADD_CHROMA	(0x00cc)
80d24a170bSMauro Carvalho Chehab #define VPIF_CH2_TOP_STRT_ADD_HANC	(0x00d0)
81d24a170bSMauro Carvalho Chehab #define VPIF_CH2_BTM_STRT_ADD_HANC	(0x00d4)
82d24a170bSMauro Carvalho Chehab #define VPIF_CH2_TOP_STRT_ADD_VANC	(0x00d8)
83d24a170bSMauro Carvalho Chehab #define VPIF_CH2_BTM_STRT_ADD_VANC	(0x00dc)
84d24a170bSMauro Carvalho Chehab #define VPIF_CH2_SP_CFG			(0x00e0)
85d24a170bSMauro Carvalho Chehab #define VPIF_CH2_IMG_ADD_OFST		(0x00e4)
86d24a170bSMauro Carvalho Chehab #define VPIF_CH2_HANC_ADD_OFST		(0x00e8)
87d24a170bSMauro Carvalho Chehab #define VPIF_CH2_H_CFG			(0x00ec)
88d24a170bSMauro Carvalho Chehab #define VPIF_CH2_V_CFG_00		(0x00f0)
89d24a170bSMauro Carvalho Chehab #define VPIF_CH2_V_CFG_01		(0x00f4)
90d24a170bSMauro Carvalho Chehab #define VPIF_CH2_V_CFG_02		(0x00f8)
91d24a170bSMauro Carvalho Chehab #define VPIF_CH2_V_CFG_03		(0x00fc)
92d24a170bSMauro Carvalho Chehab #define VPIF_CH2_HANC0_STRT		(0x0100)
93d24a170bSMauro Carvalho Chehab #define VPIF_CH2_HANC0_SIZE		(0x0104)
94d24a170bSMauro Carvalho Chehab #define VPIF_CH2_HANC1_STRT		(0x0108)
95d24a170bSMauro Carvalho Chehab #define VPIF_CH2_HANC1_SIZE		(0x010c)
96d24a170bSMauro Carvalho Chehab #define VPIF_CH2_VANC0_STRT		(0x0110)
97d24a170bSMauro Carvalho Chehab #define VPIF_CH2_VANC0_SIZE		(0x0114)
98d24a170bSMauro Carvalho Chehab #define VPIF_CH2_VANC1_STRT		(0x0118)
99d24a170bSMauro Carvalho Chehab #define VPIF_CH2_VANC1_SIZE		(0x011c)
100d24a170bSMauro Carvalho Chehab 
101d24a170bSMauro Carvalho Chehab #define VPIF_CH3_TOP_STRT_ADD_LUMA	(0x0140)
102d24a170bSMauro Carvalho Chehab #define VPIF_CH3_BTM_STRT_ADD_LUMA	(0x0144)
103d24a170bSMauro Carvalho Chehab #define VPIF_CH3_TOP_STRT_ADD_CHROMA	(0x0148)
104d24a170bSMauro Carvalho Chehab #define VPIF_CH3_BTM_STRT_ADD_CHROMA	(0x014c)
105d24a170bSMauro Carvalho Chehab #define VPIF_CH3_TOP_STRT_ADD_HANC	(0x0150)
106d24a170bSMauro Carvalho Chehab #define VPIF_CH3_BTM_STRT_ADD_HANC	(0x0154)
107d24a170bSMauro Carvalho Chehab #define VPIF_CH3_TOP_STRT_ADD_VANC	(0x0158)
108d24a170bSMauro Carvalho Chehab #define VPIF_CH3_BTM_STRT_ADD_VANC	(0x015c)
109d24a170bSMauro Carvalho Chehab #define VPIF_CH3_SP_CFG			(0x0160)
110d24a170bSMauro Carvalho Chehab #define VPIF_CH3_IMG_ADD_OFST		(0x0164)
111d24a170bSMauro Carvalho Chehab #define VPIF_CH3_HANC_ADD_OFST		(0x0168)
112d24a170bSMauro Carvalho Chehab #define VPIF_CH3_H_CFG			(0x016c)
113d24a170bSMauro Carvalho Chehab #define VPIF_CH3_V_CFG_00		(0x0170)
114d24a170bSMauro Carvalho Chehab #define VPIF_CH3_V_CFG_01		(0x0174)
115d24a170bSMauro Carvalho Chehab #define VPIF_CH3_V_CFG_02		(0x0178)
116d24a170bSMauro Carvalho Chehab #define VPIF_CH3_V_CFG_03		(0x017c)
117d24a170bSMauro Carvalho Chehab #define VPIF_CH3_HANC0_STRT		(0x0180)
118d24a170bSMauro Carvalho Chehab #define VPIF_CH3_HANC0_SIZE		(0x0184)
119d24a170bSMauro Carvalho Chehab #define VPIF_CH3_HANC1_STRT		(0x0188)
120d24a170bSMauro Carvalho Chehab #define VPIF_CH3_HANC1_SIZE		(0x018c)
121d24a170bSMauro Carvalho Chehab #define VPIF_CH3_VANC0_STRT		(0x0190)
122d24a170bSMauro Carvalho Chehab #define VPIF_CH3_VANC0_SIZE		(0x0194)
123d24a170bSMauro Carvalho Chehab #define VPIF_CH3_VANC1_STRT		(0x0198)
124d24a170bSMauro Carvalho Chehab #define VPIF_CH3_VANC1_SIZE		(0x019c)
125d24a170bSMauro Carvalho Chehab 
126d24a170bSMauro Carvalho Chehab #define VPIF_IODFT_CTRL			(0x01c0)
127d24a170bSMauro Carvalho Chehab 
128d24a170bSMauro Carvalho Chehab /* Functions for bit Manipulation */
vpif_set_bit(u32 reg,u32 bit)129d24a170bSMauro Carvalho Chehab static inline void vpif_set_bit(u32 reg, u32 bit)
130d24a170bSMauro Carvalho Chehab {
131d24a170bSMauro Carvalho Chehab 	regw((regr(reg)) | (0x01 << bit), reg);
132d24a170bSMauro Carvalho Chehab }
133d24a170bSMauro Carvalho Chehab 
vpif_clr_bit(u32 reg,u32 bit)134d24a170bSMauro Carvalho Chehab static inline void vpif_clr_bit(u32 reg, u32 bit)
135d24a170bSMauro Carvalho Chehab {
136d24a170bSMauro Carvalho Chehab 	regw(((regr(reg)) & ~(0x01 << bit)), reg);
137d24a170bSMauro Carvalho Chehab }
138d24a170bSMauro Carvalho Chehab 
139d24a170bSMauro Carvalho Chehab /* Macro for Generating mask */
140d24a170bSMauro Carvalho Chehab #ifdef GENERATE_MASK
141d24a170bSMauro Carvalho Chehab #undef GENERATE_MASK
142d24a170bSMauro Carvalho Chehab #endif
143d24a170bSMauro Carvalho Chehab 
144d24a170bSMauro Carvalho Chehab #define GENERATE_MASK(bits, pos) \
145d24a170bSMauro Carvalho Chehab 		((((0xFFFFFFFF) << (32 - bits)) >> (32 - bits)) << pos)
146d24a170bSMauro Carvalho Chehab 
147d24a170bSMauro Carvalho Chehab /* Bit positions in the channel control registers */
148d24a170bSMauro Carvalho Chehab #define VPIF_CH_DATA_MODE_BIT	(2)
149d24a170bSMauro Carvalho Chehab #define VPIF_CH_YC_MUX_BIT	(3)
150d24a170bSMauro Carvalho Chehab #define VPIF_CH_SDR_FMT_BIT	(4)
151d24a170bSMauro Carvalho Chehab #define VPIF_CH_HANC_EN_BIT	(8)
152d24a170bSMauro Carvalho Chehab #define VPIF_CH_VANC_EN_BIT	(9)
153d24a170bSMauro Carvalho Chehab 
154d24a170bSMauro Carvalho Chehab #define VPIF_CAPTURE_CH_NIP	(10)
155d24a170bSMauro Carvalho Chehab #define VPIF_DISPLAY_CH_NIP	(11)
156d24a170bSMauro Carvalho Chehab 
157d24a170bSMauro Carvalho Chehab #define VPIF_DISPLAY_PIX_EN_BIT	(10)
158d24a170bSMauro Carvalho Chehab 
159d24a170bSMauro Carvalho Chehab #define VPIF_CH_INPUT_FIELD_FRAME_BIT	(12)
160d24a170bSMauro Carvalho Chehab 
161d24a170bSMauro Carvalho Chehab #define VPIF_CH_FID_POLARITY_BIT	(15)
162d24a170bSMauro Carvalho Chehab #define VPIF_CH_V_VALID_POLARITY_BIT	(14)
163d24a170bSMauro Carvalho Chehab #define VPIF_CH_H_VALID_POLARITY_BIT	(13)
164d24a170bSMauro Carvalho Chehab #define VPIF_CH_DATA_WIDTH_BIT		(28)
165d24a170bSMauro Carvalho Chehab 
166d24a170bSMauro Carvalho Chehab #define VPIF_CH_CLK_EDGE_CTRL_BIT	(31)
167d24a170bSMauro Carvalho Chehab 
168d24a170bSMauro Carvalho Chehab /* Mask various length */
169d24a170bSMauro Carvalho Chehab #define VPIF_CH_EAVSAV_MASK	GENERATE_MASK(13, 0)
170d24a170bSMauro Carvalho Chehab #define VPIF_CH_LEN_MASK	GENERATE_MASK(12, 0)
171d24a170bSMauro Carvalho Chehab #define VPIF_CH_WIDTH_MASK	GENERATE_MASK(13, 0)
172d24a170bSMauro Carvalho Chehab #define VPIF_CH_LEN_SHIFT	(16)
173d24a170bSMauro Carvalho Chehab 
174d24a170bSMauro Carvalho Chehab /* VPIF masks for registers */
175d24a170bSMauro Carvalho Chehab #define VPIF_REQ_SIZE_MASK	(0x1ff)
176d24a170bSMauro Carvalho Chehab 
177d24a170bSMauro Carvalho Chehab /* bit posotion of interrupt vpif_ch_intr register */
178d24a170bSMauro Carvalho Chehab #define VPIF_INTEN_FRAME_CH0	(0x00000001)
179d24a170bSMauro Carvalho Chehab #define VPIF_INTEN_FRAME_CH1	(0x00000002)
180d24a170bSMauro Carvalho Chehab #define VPIF_INTEN_FRAME_CH2	(0x00000004)
181d24a170bSMauro Carvalho Chehab #define VPIF_INTEN_FRAME_CH3	(0x00000008)
182d24a170bSMauro Carvalho Chehab 
183d24a170bSMauro Carvalho Chehab /* bit position of clock and channel enable in vpif_chn_ctrl register */
184d24a170bSMauro Carvalho Chehab 
185d24a170bSMauro Carvalho Chehab #define VPIF_CH0_CLK_EN		(0x00000002)
186d24a170bSMauro Carvalho Chehab #define VPIF_CH0_EN		(0x00000001)
187d24a170bSMauro Carvalho Chehab #define VPIF_CH1_CLK_EN		(0x00000002)
188d24a170bSMauro Carvalho Chehab #define VPIF_CH1_EN		(0x00000001)
189d24a170bSMauro Carvalho Chehab #define VPIF_CH2_CLK_EN		(0x00000002)
190d24a170bSMauro Carvalho Chehab #define VPIF_CH2_EN		(0x00000001)
191d24a170bSMauro Carvalho Chehab #define VPIF_CH3_CLK_EN		(0x00000002)
192d24a170bSMauro Carvalho Chehab #define VPIF_CH3_EN		(0x00000001)
193d24a170bSMauro Carvalho Chehab #define VPIF_CH_CLK_EN		(0x00000002)
194d24a170bSMauro Carvalho Chehab #define VPIF_CH_EN		(0x00000001)
195d24a170bSMauro Carvalho Chehab 
196d24a170bSMauro Carvalho Chehab #define VPIF_INT_TOP	(0x00)
197d24a170bSMauro Carvalho Chehab #define VPIF_INT_BOTTOM	(0x01)
198d24a170bSMauro Carvalho Chehab #define VPIF_INT_BOTH	(0x02)
199d24a170bSMauro Carvalho Chehab 
200d24a170bSMauro Carvalho Chehab #define VPIF_CH0_INT_CTRL_SHIFT	(6)
201d24a170bSMauro Carvalho Chehab #define VPIF_CH1_INT_CTRL_SHIFT	(6)
202d24a170bSMauro Carvalho Chehab #define VPIF_CH2_INT_CTRL_SHIFT	(6)
203d24a170bSMauro Carvalho Chehab #define VPIF_CH3_INT_CTRL_SHIFT	(6)
204d24a170bSMauro Carvalho Chehab #define VPIF_CH_INT_CTRL_SHIFT	(6)
205d24a170bSMauro Carvalho Chehab 
206d24a170bSMauro Carvalho Chehab #define VPIF_CH2_CLIP_ANC_EN	14
207d24a170bSMauro Carvalho Chehab #define VPIF_CH2_CLIP_ACTIVE_EN	13
208d24a170bSMauro Carvalho Chehab 
209d24a170bSMauro Carvalho Chehab #define VPIF_CH3_CLIP_ANC_EN	14
210d24a170bSMauro Carvalho Chehab #define VPIF_CH3_CLIP_ACTIVE_EN	13
211d24a170bSMauro Carvalho Chehab 
212d24a170bSMauro Carvalho Chehab /* enabled interrupt on both the fields on vpid_ch0_ctrl register */
213d24a170bSMauro Carvalho Chehab #define channel0_intr_assert()	(regw((regr(VPIF_CH0_CTRL)|\
214d24a170bSMauro Carvalho Chehab 	(VPIF_INT_BOTH << VPIF_CH0_INT_CTRL_SHIFT)), VPIF_CH0_CTRL))
215d24a170bSMauro Carvalho Chehab 
216d24a170bSMauro Carvalho Chehab /* enabled interrupt on both the fields on vpid_ch1_ctrl register */
217d24a170bSMauro Carvalho Chehab #define channel1_intr_assert()	(regw((regr(VPIF_CH1_CTRL)|\
218d24a170bSMauro Carvalho Chehab 	(VPIF_INT_BOTH << VPIF_CH1_INT_CTRL_SHIFT)), VPIF_CH1_CTRL))
219d24a170bSMauro Carvalho Chehab 
220d24a170bSMauro Carvalho Chehab /* enabled interrupt on both the fields on vpid_ch0_ctrl register */
221d24a170bSMauro Carvalho Chehab #define channel2_intr_assert()	(regw((regr(VPIF_CH2_CTRL)|\
222d24a170bSMauro Carvalho Chehab 	(VPIF_INT_BOTH << VPIF_CH2_INT_CTRL_SHIFT)), VPIF_CH2_CTRL))
223d24a170bSMauro Carvalho Chehab 
224d24a170bSMauro Carvalho Chehab /* enabled interrupt on both the fields on vpid_ch1_ctrl register */
225d24a170bSMauro Carvalho Chehab #define channel3_intr_assert()	(regw((regr(VPIF_CH3_CTRL)|\
226d24a170bSMauro Carvalho Chehab 	(VPIF_INT_BOTH << VPIF_CH3_INT_CTRL_SHIFT)), VPIF_CH3_CTRL))
227d24a170bSMauro Carvalho Chehab 
228d24a170bSMauro Carvalho Chehab #define VPIF_CH_FID_MASK	(0x20)
229d24a170bSMauro Carvalho Chehab #define VPIF_CH_FID_SHIFT	(5)
230d24a170bSMauro Carvalho Chehab 
231d24a170bSMauro Carvalho Chehab #define VPIF_NTSC_VBI_START_FIELD0	(1)
232d24a170bSMauro Carvalho Chehab #define VPIF_NTSC_VBI_START_FIELD1	(263)
233d24a170bSMauro Carvalho Chehab #define VPIF_PAL_VBI_START_FIELD0	(624)
234d24a170bSMauro Carvalho Chehab #define VPIF_PAL_VBI_START_FIELD1	(311)
235d24a170bSMauro Carvalho Chehab 
236d24a170bSMauro Carvalho Chehab #define VPIF_NTSC_HBI_START_FIELD0	(1)
237d24a170bSMauro Carvalho Chehab #define VPIF_NTSC_HBI_START_FIELD1	(263)
238d24a170bSMauro Carvalho Chehab #define VPIF_PAL_HBI_START_FIELD0	(624)
239d24a170bSMauro Carvalho Chehab #define VPIF_PAL_HBI_START_FIELD1	(311)
240d24a170bSMauro Carvalho Chehab 
241d24a170bSMauro Carvalho Chehab #define VPIF_NTSC_VBI_COUNT_FIELD0	(20)
242d24a170bSMauro Carvalho Chehab #define VPIF_NTSC_VBI_COUNT_FIELD1	(19)
243d24a170bSMauro Carvalho Chehab #define VPIF_PAL_VBI_COUNT_FIELD0	(24)
244d24a170bSMauro Carvalho Chehab #define VPIF_PAL_VBI_COUNT_FIELD1	(25)
245d24a170bSMauro Carvalho Chehab 
246d24a170bSMauro Carvalho Chehab #define VPIF_NTSC_HBI_COUNT_FIELD0	(263)
247d24a170bSMauro Carvalho Chehab #define VPIF_NTSC_HBI_COUNT_FIELD1	(262)
248d24a170bSMauro Carvalho Chehab #define VPIF_PAL_HBI_COUNT_FIELD0	(312)
249d24a170bSMauro Carvalho Chehab #define VPIF_PAL_HBI_COUNT_FIELD1	(313)
250d24a170bSMauro Carvalho Chehab 
251d24a170bSMauro Carvalho Chehab #define VPIF_NTSC_VBI_SAMPLES_PER_LINE	(720)
252d24a170bSMauro Carvalho Chehab #define VPIF_PAL_VBI_SAMPLES_PER_LINE	(720)
253d24a170bSMauro Carvalho Chehab #define VPIF_NTSC_HBI_SAMPLES_PER_LINE	(268)
254d24a170bSMauro Carvalho Chehab #define VPIF_PAL_HBI_SAMPLES_PER_LINE	(280)
255d24a170bSMauro Carvalho Chehab 
256d24a170bSMauro Carvalho Chehab #define VPIF_CH_VANC_EN			(0x20)
257d24a170bSMauro Carvalho Chehab #define VPIF_DMA_REQ_SIZE		(0x080)
258d24a170bSMauro Carvalho Chehab #define VPIF_EMULATION_DISABLE		(0x01)
259d24a170bSMauro Carvalho Chehab 
260d24a170bSMauro Carvalho Chehab extern u8 irq_vpif_capture_channel[VPIF_NUM_CHANNELS];
261d24a170bSMauro Carvalho Chehab 
262d24a170bSMauro Carvalho Chehab /* inline function to enable/disable channel0 */
enable_channel0(int enable)263d24a170bSMauro Carvalho Chehab static inline void enable_channel0(int enable)
264d24a170bSMauro Carvalho Chehab {
265d24a170bSMauro Carvalho Chehab 	if (enable)
266d24a170bSMauro Carvalho Chehab 		regw((regr(VPIF_CH0_CTRL) | (VPIF_CH0_EN)), VPIF_CH0_CTRL);
267d24a170bSMauro Carvalho Chehab 	else
268d24a170bSMauro Carvalho Chehab 		regw((regr(VPIF_CH0_CTRL) & (~VPIF_CH0_EN)), VPIF_CH0_CTRL);
269d24a170bSMauro Carvalho Chehab }
270d24a170bSMauro Carvalho Chehab 
271d24a170bSMauro Carvalho Chehab /* inline function to enable/disable channel1 */
enable_channel1(int enable)272d24a170bSMauro Carvalho Chehab static inline void enable_channel1(int enable)
273d24a170bSMauro Carvalho Chehab {
274d24a170bSMauro Carvalho Chehab 	if (enable)
275d24a170bSMauro Carvalho Chehab 		regw((regr(VPIF_CH1_CTRL) | (VPIF_CH1_EN)), VPIF_CH1_CTRL);
276d24a170bSMauro Carvalho Chehab 	else
277d24a170bSMauro Carvalho Chehab 		regw((regr(VPIF_CH1_CTRL) & (~VPIF_CH1_EN)), VPIF_CH1_CTRL);
278d24a170bSMauro Carvalho Chehab }
279d24a170bSMauro Carvalho Chehab 
280d24a170bSMauro Carvalho Chehab /* inline function to enable interrupt for channel0 */
channel0_intr_enable(int enable)281d24a170bSMauro Carvalho Chehab static inline void channel0_intr_enable(int enable)
282d24a170bSMauro Carvalho Chehab {
283d24a170bSMauro Carvalho Chehab 	unsigned long flags;
284d24a170bSMauro Carvalho Chehab 
285d24a170bSMauro Carvalho Chehab 	spin_lock_irqsave(&vpif_lock, flags);
286d24a170bSMauro Carvalho Chehab 
287d24a170bSMauro Carvalho Chehab 	if (enable) {
288d24a170bSMauro Carvalho Chehab 		regw((regr(VPIF_INTEN) | 0x10), VPIF_INTEN);
289d24a170bSMauro Carvalho Chehab 		regw((regr(VPIF_INTEN_SET) | 0x10), VPIF_INTEN_SET);
290d24a170bSMauro Carvalho Chehab 
291d24a170bSMauro Carvalho Chehab 		regw((regr(VPIF_INTEN) | VPIF_INTEN_FRAME_CH0), VPIF_INTEN);
292d24a170bSMauro Carvalho Chehab 		regw((regr(VPIF_INTEN_SET) | VPIF_INTEN_FRAME_CH0),
293d24a170bSMauro Carvalho Chehab 							VPIF_INTEN_SET);
294d24a170bSMauro Carvalho Chehab 	} else {
295d24a170bSMauro Carvalho Chehab 		regw((regr(VPIF_INTEN) & (~VPIF_INTEN_FRAME_CH0)), VPIF_INTEN);
296d24a170bSMauro Carvalho Chehab 		regw((regr(VPIF_INTEN_SET) | VPIF_INTEN_FRAME_CH0),
297d24a170bSMauro Carvalho Chehab 							VPIF_INTEN_SET);
298d24a170bSMauro Carvalho Chehab 	}
299d24a170bSMauro Carvalho Chehab 	spin_unlock_irqrestore(&vpif_lock, flags);
300d24a170bSMauro Carvalho Chehab }
301d24a170bSMauro Carvalho Chehab 
302d24a170bSMauro Carvalho Chehab /* inline function to enable interrupt for channel1 */
channel1_intr_enable(int enable)303d24a170bSMauro Carvalho Chehab static inline void channel1_intr_enable(int enable)
304d24a170bSMauro Carvalho Chehab {
305d24a170bSMauro Carvalho Chehab 	unsigned long flags;
306d24a170bSMauro Carvalho Chehab 
307d24a170bSMauro Carvalho Chehab 	spin_lock_irqsave(&vpif_lock, flags);
308d24a170bSMauro Carvalho Chehab 
309d24a170bSMauro Carvalho Chehab 	if (enable) {
310d24a170bSMauro Carvalho Chehab 		regw((regr(VPIF_INTEN) | 0x10), VPIF_INTEN);
311d24a170bSMauro Carvalho Chehab 		regw((regr(VPIF_INTEN_SET) | 0x10), VPIF_INTEN_SET);
312d24a170bSMauro Carvalho Chehab 
313d24a170bSMauro Carvalho Chehab 		regw((regr(VPIF_INTEN) | VPIF_INTEN_FRAME_CH1), VPIF_INTEN);
314d24a170bSMauro Carvalho Chehab 		regw((regr(VPIF_INTEN_SET) | VPIF_INTEN_FRAME_CH1),
315d24a170bSMauro Carvalho Chehab 							VPIF_INTEN_SET);
316d24a170bSMauro Carvalho Chehab 	} else {
317d24a170bSMauro Carvalho Chehab 		regw((regr(VPIF_INTEN) & (~VPIF_INTEN_FRAME_CH1)), VPIF_INTEN);
318d24a170bSMauro Carvalho Chehab 		regw((regr(VPIF_INTEN_SET) | VPIF_INTEN_FRAME_CH1),
319d24a170bSMauro Carvalho Chehab 							VPIF_INTEN_SET);
320d24a170bSMauro Carvalho Chehab 	}
321d24a170bSMauro Carvalho Chehab 	spin_unlock_irqrestore(&vpif_lock, flags);
322d24a170bSMauro Carvalho Chehab }
323d24a170bSMauro Carvalho Chehab 
324d24a170bSMauro Carvalho Chehab /* inline function to set buffer addresses in case of Y/C non mux mode */
ch0_set_video_buf_addr_yc_nmux(unsigned long top_strt_luma,unsigned long btm_strt_luma,unsigned long top_strt_chroma,unsigned long btm_strt_chroma)325*6be95480SHans Verkuil static inline void ch0_set_video_buf_addr_yc_nmux(unsigned long top_strt_luma,
326d24a170bSMauro Carvalho Chehab 						  unsigned long btm_strt_luma,
327d24a170bSMauro Carvalho Chehab 						  unsigned long top_strt_chroma,
328d24a170bSMauro Carvalho Chehab 						  unsigned long btm_strt_chroma)
329d24a170bSMauro Carvalho Chehab {
330d24a170bSMauro Carvalho Chehab 	regw(top_strt_luma, VPIF_CH0_TOP_STRT_ADD_LUMA);
331d24a170bSMauro Carvalho Chehab 	regw(btm_strt_luma, VPIF_CH0_BTM_STRT_ADD_LUMA);
332d24a170bSMauro Carvalho Chehab 	regw(top_strt_chroma, VPIF_CH1_TOP_STRT_ADD_CHROMA);
333d24a170bSMauro Carvalho Chehab 	regw(btm_strt_chroma, VPIF_CH1_BTM_STRT_ADD_CHROMA);
334d24a170bSMauro Carvalho Chehab }
335d24a170bSMauro Carvalho Chehab 
336d24a170bSMauro Carvalho Chehab /* inline function to set buffer addresses in VPIF registers for video data */
ch0_set_video_buf_addr(unsigned long top_strt_luma,unsigned long btm_strt_luma,unsigned long top_strt_chroma,unsigned long btm_strt_chroma)337*6be95480SHans Verkuil static inline void ch0_set_video_buf_addr(unsigned long top_strt_luma,
338d24a170bSMauro Carvalho Chehab 					  unsigned long btm_strt_luma,
339d24a170bSMauro Carvalho Chehab 					  unsigned long top_strt_chroma,
340d24a170bSMauro Carvalho Chehab 					  unsigned long btm_strt_chroma)
341d24a170bSMauro Carvalho Chehab {
342d24a170bSMauro Carvalho Chehab 	regw(top_strt_luma, VPIF_CH0_TOP_STRT_ADD_LUMA);
343d24a170bSMauro Carvalho Chehab 	regw(btm_strt_luma, VPIF_CH0_BTM_STRT_ADD_LUMA);
344d24a170bSMauro Carvalho Chehab 	regw(top_strt_chroma, VPIF_CH0_TOP_STRT_ADD_CHROMA);
345d24a170bSMauro Carvalho Chehab 	regw(btm_strt_chroma, VPIF_CH0_BTM_STRT_ADD_CHROMA);
346d24a170bSMauro Carvalho Chehab }
347d24a170bSMauro Carvalho Chehab 
ch1_set_video_buf_addr(unsigned long top_strt_luma,unsigned long btm_strt_luma,unsigned long top_strt_chroma,unsigned long btm_strt_chroma)348*6be95480SHans Verkuil static inline void ch1_set_video_buf_addr(unsigned long top_strt_luma,
349d24a170bSMauro Carvalho Chehab 					  unsigned long btm_strt_luma,
350d24a170bSMauro Carvalho Chehab 					  unsigned long top_strt_chroma,
351d24a170bSMauro Carvalho Chehab 					  unsigned long btm_strt_chroma)
352d24a170bSMauro Carvalho Chehab {
353d24a170bSMauro Carvalho Chehab 
354d24a170bSMauro Carvalho Chehab 	regw(top_strt_luma, VPIF_CH1_TOP_STRT_ADD_LUMA);
355d24a170bSMauro Carvalho Chehab 	regw(btm_strt_luma, VPIF_CH1_BTM_STRT_ADD_LUMA);
356d24a170bSMauro Carvalho Chehab 	regw(top_strt_chroma, VPIF_CH1_TOP_STRT_ADD_CHROMA);
357d24a170bSMauro Carvalho Chehab 	regw(btm_strt_chroma, VPIF_CH1_BTM_STRT_ADD_CHROMA);
358d24a170bSMauro Carvalho Chehab }
359d24a170bSMauro Carvalho Chehab 
ch0_set_vbi_addr(unsigned long top_vbi,unsigned long btm_vbi,unsigned long a,unsigned long b)360d24a170bSMauro Carvalho Chehab static inline void ch0_set_vbi_addr(unsigned long top_vbi,
361d24a170bSMauro Carvalho Chehab 	unsigned long btm_vbi, unsigned long a, unsigned long b)
362d24a170bSMauro Carvalho Chehab {
363d24a170bSMauro Carvalho Chehab 	regw(top_vbi, VPIF_CH0_TOP_STRT_ADD_VANC);
364d24a170bSMauro Carvalho Chehab 	regw(btm_vbi, VPIF_CH0_BTM_STRT_ADD_VANC);
365d24a170bSMauro Carvalho Chehab }
366d24a170bSMauro Carvalho Chehab 
ch0_set_hbi_addr(unsigned long top_vbi,unsigned long btm_vbi,unsigned long a,unsigned long b)367d24a170bSMauro Carvalho Chehab static inline void ch0_set_hbi_addr(unsigned long top_vbi,
368d24a170bSMauro Carvalho Chehab 	unsigned long btm_vbi, unsigned long a, unsigned long b)
369d24a170bSMauro Carvalho Chehab {
370d24a170bSMauro Carvalho Chehab 	regw(top_vbi, VPIF_CH0_TOP_STRT_ADD_HANC);
371d24a170bSMauro Carvalho Chehab 	regw(btm_vbi, VPIF_CH0_BTM_STRT_ADD_HANC);
372d24a170bSMauro Carvalho Chehab }
373d24a170bSMauro Carvalho Chehab 
ch1_set_vbi_addr(unsigned long top_vbi,unsigned long btm_vbi,unsigned long a,unsigned long b)374d24a170bSMauro Carvalho Chehab static inline void ch1_set_vbi_addr(unsigned long top_vbi,
375d24a170bSMauro Carvalho Chehab 	unsigned long btm_vbi, unsigned long a, unsigned long b)
376d24a170bSMauro Carvalho Chehab {
377d24a170bSMauro Carvalho Chehab 	regw(top_vbi, VPIF_CH1_TOP_STRT_ADD_VANC);
378d24a170bSMauro Carvalho Chehab 	regw(btm_vbi, VPIF_CH1_BTM_STRT_ADD_VANC);
379d24a170bSMauro Carvalho Chehab }
380d24a170bSMauro Carvalho Chehab 
ch1_set_hbi_addr(unsigned long top_vbi,unsigned long btm_vbi,unsigned long a,unsigned long b)381d24a170bSMauro Carvalho Chehab static inline void ch1_set_hbi_addr(unsigned long top_vbi,
382d24a170bSMauro Carvalho Chehab 	unsigned long btm_vbi, unsigned long a, unsigned long b)
383d24a170bSMauro Carvalho Chehab {
384d24a170bSMauro Carvalho Chehab 	regw(top_vbi, VPIF_CH1_TOP_STRT_ADD_HANC);
385d24a170bSMauro Carvalho Chehab 	regw(btm_vbi, VPIF_CH1_BTM_STRT_ADD_HANC);
386d24a170bSMauro Carvalho Chehab }
387d24a170bSMauro Carvalho Chehab 
388d24a170bSMauro Carvalho Chehab /* Inline function to enable raw vbi in the given channel */
disable_raw_feature(u8 channel_id,u8 index)389d24a170bSMauro Carvalho Chehab static inline void disable_raw_feature(u8 channel_id, u8 index)
390d24a170bSMauro Carvalho Chehab {
391d24a170bSMauro Carvalho Chehab 	u32 ctrl_reg;
392d24a170bSMauro Carvalho Chehab 	if (0 == channel_id)
393d24a170bSMauro Carvalho Chehab 		ctrl_reg = VPIF_CH0_CTRL;
394d24a170bSMauro Carvalho Chehab 	else
395d24a170bSMauro Carvalho Chehab 		ctrl_reg = VPIF_CH1_CTRL;
396d24a170bSMauro Carvalho Chehab 
397d24a170bSMauro Carvalho Chehab 	if (1 == index)
398d24a170bSMauro Carvalho Chehab 		vpif_clr_bit(ctrl_reg, VPIF_CH_VANC_EN_BIT);
399d24a170bSMauro Carvalho Chehab 	else
400d24a170bSMauro Carvalho Chehab 		vpif_clr_bit(ctrl_reg, VPIF_CH_HANC_EN_BIT);
401d24a170bSMauro Carvalho Chehab }
402d24a170bSMauro Carvalho Chehab 
enable_raw_feature(u8 channel_id,u8 index)403d24a170bSMauro Carvalho Chehab static inline void enable_raw_feature(u8 channel_id, u8 index)
404d24a170bSMauro Carvalho Chehab {
405d24a170bSMauro Carvalho Chehab 	u32 ctrl_reg;
406d24a170bSMauro Carvalho Chehab 	if (0 == channel_id)
407d24a170bSMauro Carvalho Chehab 		ctrl_reg = VPIF_CH0_CTRL;
408d24a170bSMauro Carvalho Chehab 	else
409d24a170bSMauro Carvalho Chehab 		ctrl_reg = VPIF_CH1_CTRL;
410d24a170bSMauro Carvalho Chehab 
411d24a170bSMauro Carvalho Chehab 	if (1 == index)
412d24a170bSMauro Carvalho Chehab 		vpif_set_bit(ctrl_reg, VPIF_CH_VANC_EN_BIT);
413d24a170bSMauro Carvalho Chehab 	else
414d24a170bSMauro Carvalho Chehab 		vpif_set_bit(ctrl_reg, VPIF_CH_HANC_EN_BIT);
415d24a170bSMauro Carvalho Chehab }
416d24a170bSMauro Carvalho Chehab 
417d24a170bSMauro Carvalho Chehab /* inline function to enable/disable channel2 */
enable_channel2(int enable)418d24a170bSMauro Carvalho Chehab static inline void enable_channel2(int enable)
419d24a170bSMauro Carvalho Chehab {
420d24a170bSMauro Carvalho Chehab 	if (enable) {
421d24a170bSMauro Carvalho Chehab 		regw((regr(VPIF_CH2_CTRL) | (VPIF_CH2_CLK_EN)), VPIF_CH2_CTRL);
422d24a170bSMauro Carvalho Chehab 		regw((regr(VPIF_CH2_CTRL) | (VPIF_CH2_EN)), VPIF_CH2_CTRL);
423d24a170bSMauro Carvalho Chehab 	} else {
424d24a170bSMauro Carvalho Chehab 		regw((regr(VPIF_CH2_CTRL) & (~VPIF_CH2_CLK_EN)), VPIF_CH2_CTRL);
425d24a170bSMauro Carvalho Chehab 		regw((regr(VPIF_CH2_CTRL) & (~VPIF_CH2_EN)), VPIF_CH2_CTRL);
426d24a170bSMauro Carvalho Chehab 	}
427d24a170bSMauro Carvalho Chehab }
428d24a170bSMauro Carvalho Chehab 
429d24a170bSMauro Carvalho Chehab /* inline function to enable/disable channel3 */
enable_channel3(int enable)430d24a170bSMauro Carvalho Chehab static inline void enable_channel3(int enable)
431d24a170bSMauro Carvalho Chehab {
432d24a170bSMauro Carvalho Chehab 	if (enable) {
433d24a170bSMauro Carvalho Chehab 		regw((regr(VPIF_CH3_CTRL) | (VPIF_CH3_CLK_EN)), VPIF_CH3_CTRL);
434d24a170bSMauro Carvalho Chehab 		regw((regr(VPIF_CH3_CTRL) | (VPIF_CH3_EN)), VPIF_CH3_CTRL);
435d24a170bSMauro Carvalho Chehab 	} else {
436d24a170bSMauro Carvalho Chehab 		regw((regr(VPIF_CH3_CTRL) & (~VPIF_CH3_CLK_EN)), VPIF_CH3_CTRL);
437d24a170bSMauro Carvalho Chehab 		regw((regr(VPIF_CH3_CTRL) & (~VPIF_CH3_EN)), VPIF_CH3_CTRL);
438d24a170bSMauro Carvalho Chehab 	}
439d24a170bSMauro Carvalho Chehab }
440d24a170bSMauro Carvalho Chehab 
441d24a170bSMauro Carvalho Chehab /* inline function to enable interrupt for channel2 */
channel2_intr_enable(int enable)442d24a170bSMauro Carvalho Chehab static inline void channel2_intr_enable(int enable)
443d24a170bSMauro Carvalho Chehab {
444d24a170bSMauro Carvalho Chehab 	unsigned long flags;
445d24a170bSMauro Carvalho Chehab 
446d24a170bSMauro Carvalho Chehab 	spin_lock_irqsave(&vpif_lock, flags);
447d24a170bSMauro Carvalho Chehab 
448d24a170bSMauro Carvalho Chehab 	if (enable) {
449d24a170bSMauro Carvalho Chehab 		regw((regr(VPIF_INTEN) | 0x10), VPIF_INTEN);
450d24a170bSMauro Carvalho Chehab 		regw((regr(VPIF_INTEN_SET) | 0x10), VPIF_INTEN_SET);
451d24a170bSMauro Carvalho Chehab 		regw((regr(VPIF_INTEN) | VPIF_INTEN_FRAME_CH2), VPIF_INTEN);
452d24a170bSMauro Carvalho Chehab 		regw((regr(VPIF_INTEN_SET) | VPIF_INTEN_FRAME_CH2),
453d24a170bSMauro Carvalho Chehab 							VPIF_INTEN_SET);
454d24a170bSMauro Carvalho Chehab 	} else {
455d24a170bSMauro Carvalho Chehab 		regw((regr(VPIF_INTEN) & (~VPIF_INTEN_FRAME_CH2)), VPIF_INTEN);
456d24a170bSMauro Carvalho Chehab 		regw((regr(VPIF_INTEN_SET) | VPIF_INTEN_FRAME_CH2),
457d24a170bSMauro Carvalho Chehab 							VPIF_INTEN_SET);
458d24a170bSMauro Carvalho Chehab 	}
459d24a170bSMauro Carvalho Chehab 	spin_unlock_irqrestore(&vpif_lock, flags);
460d24a170bSMauro Carvalho Chehab }
461d24a170bSMauro Carvalho Chehab 
462d24a170bSMauro Carvalho Chehab /* inline function to enable interrupt for channel3 */
channel3_intr_enable(int enable)463d24a170bSMauro Carvalho Chehab static inline void channel3_intr_enable(int enable)
464d24a170bSMauro Carvalho Chehab {
465d24a170bSMauro Carvalho Chehab 	unsigned long flags;
466d24a170bSMauro Carvalho Chehab 
467d24a170bSMauro Carvalho Chehab 	spin_lock_irqsave(&vpif_lock, flags);
468d24a170bSMauro Carvalho Chehab 
469d24a170bSMauro Carvalho Chehab 	if (enable) {
470d24a170bSMauro Carvalho Chehab 		regw((regr(VPIF_INTEN) | 0x10), VPIF_INTEN);
471d24a170bSMauro Carvalho Chehab 		regw((regr(VPIF_INTEN_SET) | 0x10), VPIF_INTEN_SET);
472d24a170bSMauro Carvalho Chehab 
473d24a170bSMauro Carvalho Chehab 		regw((regr(VPIF_INTEN) | VPIF_INTEN_FRAME_CH3), VPIF_INTEN);
474d24a170bSMauro Carvalho Chehab 		regw((regr(VPIF_INTEN_SET) | VPIF_INTEN_FRAME_CH3),
475d24a170bSMauro Carvalho Chehab 							VPIF_INTEN_SET);
476d24a170bSMauro Carvalho Chehab 	} else {
477d24a170bSMauro Carvalho Chehab 		regw((regr(VPIF_INTEN) & (~VPIF_INTEN_FRAME_CH3)), VPIF_INTEN);
478d24a170bSMauro Carvalho Chehab 		regw((regr(VPIF_INTEN_SET) | VPIF_INTEN_FRAME_CH3),
479d24a170bSMauro Carvalho Chehab 							VPIF_INTEN_SET);
480d24a170bSMauro Carvalho Chehab 	}
481d24a170bSMauro Carvalho Chehab 	spin_unlock_irqrestore(&vpif_lock, flags);
482d24a170bSMauro Carvalho Chehab }
483d24a170bSMauro Carvalho Chehab 
484d24a170bSMauro Carvalho Chehab /* inline function to enable raw vbi data for channel2 */
channel2_raw_enable(int enable,u8 index)485d24a170bSMauro Carvalho Chehab static inline void channel2_raw_enable(int enable, u8 index)
486d24a170bSMauro Carvalho Chehab {
487d24a170bSMauro Carvalho Chehab 	u32 mask;
488d24a170bSMauro Carvalho Chehab 
489d24a170bSMauro Carvalho Chehab 	if (1 == index)
490d24a170bSMauro Carvalho Chehab 		mask = VPIF_CH_VANC_EN_BIT;
491d24a170bSMauro Carvalho Chehab 	else
492d24a170bSMauro Carvalho Chehab 		mask = VPIF_CH_HANC_EN_BIT;
493d24a170bSMauro Carvalho Chehab 
494d24a170bSMauro Carvalho Chehab 	if (enable)
495d24a170bSMauro Carvalho Chehab 		vpif_set_bit(VPIF_CH2_CTRL, mask);
496d24a170bSMauro Carvalho Chehab 	else
497d24a170bSMauro Carvalho Chehab 		vpif_clr_bit(VPIF_CH2_CTRL, mask);
498d24a170bSMauro Carvalho Chehab }
499d24a170bSMauro Carvalho Chehab 
500d24a170bSMauro Carvalho Chehab /* inline function to enable raw vbi data for channel3*/
channel3_raw_enable(int enable,u8 index)501d24a170bSMauro Carvalho Chehab static inline void channel3_raw_enable(int enable, u8 index)
502d24a170bSMauro Carvalho Chehab {
503d24a170bSMauro Carvalho Chehab 	u32 mask;
504d24a170bSMauro Carvalho Chehab 
505d24a170bSMauro Carvalho Chehab 	if (1 == index)
506d24a170bSMauro Carvalho Chehab 		mask = VPIF_CH_VANC_EN_BIT;
507d24a170bSMauro Carvalho Chehab 	else
508d24a170bSMauro Carvalho Chehab 		mask = VPIF_CH_HANC_EN_BIT;
509d24a170bSMauro Carvalho Chehab 
510d24a170bSMauro Carvalho Chehab 	if (enable)
511d24a170bSMauro Carvalho Chehab 		vpif_set_bit(VPIF_CH3_CTRL, mask);
512d24a170bSMauro Carvalho Chehab 	else
513d24a170bSMauro Carvalho Chehab 		vpif_clr_bit(VPIF_CH3_CTRL, mask);
514d24a170bSMauro Carvalho Chehab }
515d24a170bSMauro Carvalho Chehab 
516d24a170bSMauro Carvalho Chehab /* function to enable clipping (for both active and blanking regions) on ch 2 */
channel2_clipping_enable(int enable)517d24a170bSMauro Carvalho Chehab static inline void channel2_clipping_enable(int enable)
518d24a170bSMauro Carvalho Chehab {
519d24a170bSMauro Carvalho Chehab 	if (enable) {
520d24a170bSMauro Carvalho Chehab 		vpif_set_bit(VPIF_CH2_CTRL, VPIF_CH2_CLIP_ANC_EN);
521d24a170bSMauro Carvalho Chehab 		vpif_set_bit(VPIF_CH2_CTRL, VPIF_CH2_CLIP_ACTIVE_EN);
522d24a170bSMauro Carvalho Chehab 	} else {
523d24a170bSMauro Carvalho Chehab 		vpif_clr_bit(VPIF_CH2_CTRL, VPIF_CH2_CLIP_ANC_EN);
524d24a170bSMauro Carvalho Chehab 		vpif_clr_bit(VPIF_CH2_CTRL, VPIF_CH2_CLIP_ACTIVE_EN);
525d24a170bSMauro Carvalho Chehab 	}
526d24a170bSMauro Carvalho Chehab }
527d24a170bSMauro Carvalho Chehab 
528d24a170bSMauro Carvalho Chehab /* function to enable clipping (for both active and blanking regions) on ch 3 */
channel3_clipping_enable(int enable)529d24a170bSMauro Carvalho Chehab static inline void channel3_clipping_enable(int enable)
530d24a170bSMauro Carvalho Chehab {
531d24a170bSMauro Carvalho Chehab 	if (enable) {
532d24a170bSMauro Carvalho Chehab 		vpif_set_bit(VPIF_CH3_CTRL, VPIF_CH3_CLIP_ANC_EN);
533d24a170bSMauro Carvalho Chehab 		vpif_set_bit(VPIF_CH3_CTRL, VPIF_CH3_CLIP_ACTIVE_EN);
534d24a170bSMauro Carvalho Chehab 	} else {
535d24a170bSMauro Carvalho Chehab 		vpif_clr_bit(VPIF_CH3_CTRL, VPIF_CH3_CLIP_ANC_EN);
536d24a170bSMauro Carvalho Chehab 		vpif_clr_bit(VPIF_CH3_CTRL, VPIF_CH3_CLIP_ACTIVE_EN);
537d24a170bSMauro Carvalho Chehab 	}
538d24a170bSMauro Carvalho Chehab }
539d24a170bSMauro Carvalho Chehab 
540d24a170bSMauro Carvalho Chehab /* inline function to set buffer addresses in case of Y/C non mux mode */
ch2_set_video_buf_addr_yc_nmux(unsigned long top_strt_luma,unsigned long btm_strt_luma,unsigned long top_strt_chroma,unsigned long btm_strt_chroma)541*6be95480SHans Verkuil static inline void ch2_set_video_buf_addr_yc_nmux(unsigned long top_strt_luma,
542d24a170bSMauro Carvalho Chehab 						  unsigned long btm_strt_luma,
543d24a170bSMauro Carvalho Chehab 						  unsigned long top_strt_chroma,
544d24a170bSMauro Carvalho Chehab 						  unsigned long btm_strt_chroma)
545d24a170bSMauro Carvalho Chehab {
546d24a170bSMauro Carvalho Chehab 	regw(top_strt_luma, VPIF_CH2_TOP_STRT_ADD_LUMA);
547d24a170bSMauro Carvalho Chehab 	regw(btm_strt_luma, VPIF_CH2_BTM_STRT_ADD_LUMA);
548d24a170bSMauro Carvalho Chehab 	regw(top_strt_chroma, VPIF_CH3_TOP_STRT_ADD_CHROMA);
549d24a170bSMauro Carvalho Chehab 	regw(btm_strt_chroma, VPIF_CH3_BTM_STRT_ADD_CHROMA);
550d24a170bSMauro Carvalho Chehab }
551d24a170bSMauro Carvalho Chehab 
552d24a170bSMauro Carvalho Chehab /* inline function to set buffer addresses in VPIF registers for video data */
ch2_set_video_buf_addr(unsigned long top_strt_luma,unsigned long btm_strt_luma,unsigned long top_strt_chroma,unsigned long btm_strt_chroma)553*6be95480SHans Verkuil static inline void ch2_set_video_buf_addr(unsigned long top_strt_luma,
554d24a170bSMauro Carvalho Chehab 					  unsigned long btm_strt_luma,
555d24a170bSMauro Carvalho Chehab 					  unsigned long top_strt_chroma,
556d24a170bSMauro Carvalho Chehab 					  unsigned long btm_strt_chroma)
557d24a170bSMauro Carvalho Chehab {
558d24a170bSMauro Carvalho Chehab 	regw(top_strt_luma, VPIF_CH2_TOP_STRT_ADD_LUMA);
559d24a170bSMauro Carvalho Chehab 	regw(btm_strt_luma, VPIF_CH2_BTM_STRT_ADD_LUMA);
560d24a170bSMauro Carvalho Chehab 	regw(top_strt_chroma, VPIF_CH2_TOP_STRT_ADD_CHROMA);
561d24a170bSMauro Carvalho Chehab 	regw(btm_strt_chroma, VPIF_CH2_BTM_STRT_ADD_CHROMA);
562d24a170bSMauro Carvalho Chehab }
563d24a170bSMauro Carvalho Chehab 
ch3_set_video_buf_addr(unsigned long top_strt_luma,unsigned long btm_strt_luma,unsigned long top_strt_chroma,unsigned long btm_strt_chroma)564*6be95480SHans Verkuil static inline void ch3_set_video_buf_addr(unsigned long top_strt_luma,
565d24a170bSMauro Carvalho Chehab 					  unsigned long btm_strt_luma,
566d24a170bSMauro Carvalho Chehab 					  unsigned long top_strt_chroma,
567d24a170bSMauro Carvalho Chehab 					  unsigned long btm_strt_chroma)
568d24a170bSMauro Carvalho Chehab {
569d24a170bSMauro Carvalho Chehab 	regw(top_strt_luma, VPIF_CH3_TOP_STRT_ADD_LUMA);
570d24a170bSMauro Carvalho Chehab 	regw(btm_strt_luma, VPIF_CH3_BTM_STRT_ADD_LUMA);
571d24a170bSMauro Carvalho Chehab 	regw(top_strt_chroma, VPIF_CH3_TOP_STRT_ADD_CHROMA);
572d24a170bSMauro Carvalho Chehab 	regw(btm_strt_chroma, VPIF_CH3_BTM_STRT_ADD_CHROMA);
573d24a170bSMauro Carvalho Chehab }
574d24a170bSMauro Carvalho Chehab 
575d24a170bSMauro Carvalho Chehab /* inline function to set buffer addresses in VPIF registers for vbi data */
ch2_set_vbi_addr(unsigned long top_strt_luma,unsigned long btm_strt_luma,unsigned long top_strt_chroma,unsigned long btm_strt_chroma)576d24a170bSMauro Carvalho Chehab static inline void ch2_set_vbi_addr(unsigned long top_strt_luma,
577d24a170bSMauro Carvalho Chehab 				    unsigned long btm_strt_luma,
578d24a170bSMauro Carvalho Chehab 				    unsigned long top_strt_chroma,
579d24a170bSMauro Carvalho Chehab 				    unsigned long btm_strt_chroma)
580d24a170bSMauro Carvalho Chehab {
581d24a170bSMauro Carvalho Chehab 	regw(top_strt_luma, VPIF_CH2_TOP_STRT_ADD_VANC);
582d24a170bSMauro Carvalho Chehab 	regw(btm_strt_luma, VPIF_CH2_BTM_STRT_ADD_VANC);
583d24a170bSMauro Carvalho Chehab }
584d24a170bSMauro Carvalho Chehab 
ch3_set_vbi_addr(unsigned long top_strt_luma,unsigned long btm_strt_luma,unsigned long top_strt_chroma,unsigned long btm_strt_chroma)585d24a170bSMauro Carvalho Chehab static inline void ch3_set_vbi_addr(unsigned long top_strt_luma,
586d24a170bSMauro Carvalho Chehab 				    unsigned long btm_strt_luma,
587d24a170bSMauro Carvalho Chehab 				    unsigned long top_strt_chroma,
588d24a170bSMauro Carvalho Chehab 				    unsigned long btm_strt_chroma)
589d24a170bSMauro Carvalho Chehab {
590d24a170bSMauro Carvalho Chehab 	regw(top_strt_luma, VPIF_CH3_TOP_STRT_ADD_VANC);
591d24a170bSMauro Carvalho Chehab 	regw(btm_strt_luma, VPIF_CH3_BTM_STRT_ADD_VANC);
592d24a170bSMauro Carvalho Chehab }
593d24a170bSMauro Carvalho Chehab 
vpif_intr_status(int channel)594d24a170bSMauro Carvalho Chehab static inline int vpif_intr_status(int channel)
595d24a170bSMauro Carvalho Chehab {
596d24a170bSMauro Carvalho Chehab 	int status = 0;
597d24a170bSMauro Carvalho Chehab 	int mask;
598d24a170bSMauro Carvalho Chehab 
599d24a170bSMauro Carvalho Chehab 	if (channel < 0 || channel > 3)
600d24a170bSMauro Carvalho Chehab 		return 0;
601d24a170bSMauro Carvalho Chehab 
602d24a170bSMauro Carvalho Chehab 	mask = 1 << channel;
603d24a170bSMauro Carvalho Chehab 	status = regr(VPIF_STATUS) & mask;
604d24a170bSMauro Carvalho Chehab 	regw(status, VPIF_STATUS_CLR);
605d24a170bSMauro Carvalho Chehab 
606d24a170bSMauro Carvalho Chehab 	return status;
607d24a170bSMauro Carvalho Chehab }
608d24a170bSMauro Carvalho Chehab 
609d24a170bSMauro Carvalho Chehab #define VPIF_MAX_NAME	(30)
610d24a170bSMauro Carvalho Chehab 
611d24a170bSMauro Carvalho Chehab /* This structure will store size parameters as per the mode selected by user */
612d24a170bSMauro Carvalho Chehab struct vpif_channel_config_params {
613d24a170bSMauro Carvalho Chehab 	char name[VPIF_MAX_NAME];	/* Name of the mode */
614d24a170bSMauro Carvalho Chehab 	u16 width;			/* Indicates width of the image */
615d24a170bSMauro Carvalho Chehab 	u16 height;			/* Indicates height of the image */
616d24a170bSMauro Carvalho Chehab 	u8 frm_fmt;			/* Interlaced (0) or progressive (1) */
617d24a170bSMauro Carvalho Chehab 	u8 ycmux_mode;			/* This mode requires one (0) or two (1)
618d24a170bSMauro Carvalho Chehab 					   channels */
619d24a170bSMauro Carvalho Chehab 	u16 eav2sav;			/* length of eav 2 sav */
620d24a170bSMauro Carvalho Chehab 	u16 sav2eav;			/* length of sav 2 eav */
621d24a170bSMauro Carvalho Chehab 	u16 l1, l3, l5, l7, l9, l11;	/* Other parameter configurations */
622d24a170bSMauro Carvalho Chehab 	u16 vsize;			/* Vertical size of the image */
623d24a170bSMauro Carvalho Chehab 	u8 capture_format;		/* Indicates whether capture format
624d24a170bSMauro Carvalho Chehab 					 * is in BT or in CCD/CMOS */
625d24a170bSMauro Carvalho Chehab 	u8  vbi_supported;		/* Indicates whether this mode
626d24a170bSMauro Carvalho Chehab 					 * supports capturing vbi or not */
627d24a170bSMauro Carvalho Chehab 	u8 hd_sd;			/* HDTV (1) or SDTV (0) format */
628d24a170bSMauro Carvalho Chehab 	v4l2_std_id stdid;		/* SDTV format */
629d24a170bSMauro Carvalho Chehab 	struct v4l2_dv_timings dv_timings;	/* HDTV format */
630d24a170bSMauro Carvalho Chehab };
631d24a170bSMauro Carvalho Chehab 
632d24a170bSMauro Carvalho Chehab extern const unsigned int vpif_ch_params_count;
633d24a170bSMauro Carvalho Chehab extern const struct vpif_channel_config_params vpif_ch_params[];
634d24a170bSMauro Carvalho Chehab 
635d24a170bSMauro Carvalho Chehab struct vpif_video_params;
636d24a170bSMauro Carvalho Chehab struct vpif_params;
637d24a170bSMauro Carvalho Chehab struct vpif_vbi_params;
638d24a170bSMauro Carvalho Chehab 
639d24a170bSMauro Carvalho Chehab int vpif_set_video_params(struct vpif_params *vpifparams, u8 channel_id);
640d24a170bSMauro Carvalho Chehab void vpif_set_vbi_display_params(struct vpif_vbi_params *vbiparams,
641d24a170bSMauro Carvalho Chehab 							u8 channel_id);
642d24a170bSMauro Carvalho Chehab int vpif_channel_getfid(u8 channel_id);
643d24a170bSMauro Carvalho Chehab 
644d24a170bSMauro Carvalho Chehab enum data_size {
645d24a170bSMauro Carvalho Chehab 	_8BITS = 0,
646d24a170bSMauro Carvalho Chehab 	_10BITS,
647d24a170bSMauro Carvalho Chehab 	_12BITS,
648d24a170bSMauro Carvalho Chehab };
649d24a170bSMauro Carvalho Chehab 
650d24a170bSMauro Carvalho Chehab /* Structure for vpif parameters for raw vbi data */
651d24a170bSMauro Carvalho Chehab struct vpif_vbi_params {
652d24a170bSMauro Carvalho Chehab 	__u32 hstart0;  /* Horizontal start of raw vbi data for first field */
653d24a170bSMauro Carvalho Chehab 	__u32 vstart0;  /* Vertical start of raw vbi data for first field */
654d24a170bSMauro Carvalho Chehab 	__u32 hsize0;   /* Horizontal size of raw vbi data for first field */
655d24a170bSMauro Carvalho Chehab 	__u32 vsize0;   /* Vertical size of raw vbi data for first field */
656d24a170bSMauro Carvalho Chehab 	__u32 hstart1;  /* Horizontal start of raw vbi data for second field */
657d24a170bSMauro Carvalho Chehab 	__u32 vstart1;  /* Vertical start of raw vbi data for second field */
658d24a170bSMauro Carvalho Chehab 	__u32 hsize1;   /* Horizontal size of raw vbi data for second field */
659d24a170bSMauro Carvalho Chehab 	__u32 vsize1;   /* Vertical size of raw vbi data for second field */
660d24a170bSMauro Carvalho Chehab };
661d24a170bSMauro Carvalho Chehab 
662d24a170bSMauro Carvalho Chehab /* structure for vpif parameters */
663d24a170bSMauro Carvalho Chehab struct vpif_video_params {
664d24a170bSMauro Carvalho Chehab 	__u8 storage_mode;	/* Indicates field or frame mode */
665d24a170bSMauro Carvalho Chehab 	unsigned long hpitch;
666d24a170bSMauro Carvalho Chehab 	v4l2_std_id stdid;
667d24a170bSMauro Carvalho Chehab };
668d24a170bSMauro Carvalho Chehab 
669d24a170bSMauro Carvalho Chehab struct vpif_params {
670d24a170bSMauro Carvalho Chehab 	struct vpif_interface iface;
671d24a170bSMauro Carvalho Chehab 	struct vpif_video_params video_params;
672d24a170bSMauro Carvalho Chehab 	struct vpif_channel_config_params std_info;
673d24a170bSMauro Carvalho Chehab 	union param {
674d24a170bSMauro Carvalho Chehab 		struct vpif_vbi_params	vbi_params;
675d24a170bSMauro Carvalho Chehab 		enum data_size data_sz;
676d24a170bSMauro Carvalho Chehab 	} params;
677d24a170bSMauro Carvalho Chehab };
678d24a170bSMauro Carvalho Chehab 
679d24a170bSMauro Carvalho Chehab #endif				/* End of #ifndef VPIF_H */
680