vpif.h 20 KB

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