vpif.h 21 KB

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