vpif.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  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. /* enabled interrupt on both the fields on vpid_ch0_ctrl register */
  185. #define channel0_intr_assert() (regw((regr(VPIF_CH0_CTRL)|\
  186. (VPIF_INT_BOTH << VPIF_CH0_INT_CTRL_SHIFT)), VPIF_CH0_CTRL))
  187. /* enabled interrupt on both the fields on vpid_ch1_ctrl register */
  188. #define channel1_intr_assert() (regw((regr(VPIF_CH1_CTRL)|\
  189. (VPIF_INT_BOTH << VPIF_CH1_INT_CTRL_SHIFT)), VPIF_CH1_CTRL))
  190. /* enabled interrupt on both the fields on vpid_ch0_ctrl register */
  191. #define channel2_intr_assert() (regw((regr(VPIF_CH2_CTRL)|\
  192. (VPIF_INT_BOTH << VPIF_CH2_INT_CTRL_SHIFT)), VPIF_CH2_CTRL))
  193. /* enabled interrupt on both the fields on vpid_ch1_ctrl register */
  194. #define channel3_intr_assert() (regw((regr(VPIF_CH3_CTRL)|\
  195. (VPIF_INT_BOTH << VPIF_CH3_INT_CTRL_SHIFT)), VPIF_CH3_CTRL))
  196. #define VPIF_CH_FID_MASK (0x20)
  197. #define VPIF_CH_FID_SHIFT (5)
  198. #define VPIF_NTSC_VBI_START_FIELD0 (1)
  199. #define VPIF_NTSC_VBI_START_FIELD1 (263)
  200. #define VPIF_PAL_VBI_START_FIELD0 (624)
  201. #define VPIF_PAL_VBI_START_FIELD1 (311)
  202. #define VPIF_NTSC_HBI_START_FIELD0 (1)
  203. #define VPIF_NTSC_HBI_START_FIELD1 (263)
  204. #define VPIF_PAL_HBI_START_FIELD0 (624)
  205. #define VPIF_PAL_HBI_START_FIELD1 (311)
  206. #define VPIF_NTSC_VBI_COUNT_FIELD0 (20)
  207. #define VPIF_NTSC_VBI_COUNT_FIELD1 (19)
  208. #define VPIF_PAL_VBI_COUNT_FIELD0 (24)
  209. #define VPIF_PAL_VBI_COUNT_FIELD1 (25)
  210. #define VPIF_NTSC_HBI_COUNT_FIELD0 (263)
  211. #define VPIF_NTSC_HBI_COUNT_FIELD1 (262)
  212. #define VPIF_PAL_HBI_COUNT_FIELD0 (312)
  213. #define VPIF_PAL_HBI_COUNT_FIELD1 (313)
  214. #define VPIF_NTSC_VBI_SAMPLES_PER_LINE (720)
  215. #define VPIF_PAL_VBI_SAMPLES_PER_LINE (720)
  216. #define VPIF_NTSC_HBI_SAMPLES_PER_LINE (268)
  217. #define VPIF_PAL_HBI_SAMPLES_PER_LINE (280)
  218. #define VPIF_CH_VANC_EN (0x20)
  219. #define VPIF_DMA_REQ_SIZE (0x080)
  220. #define VPIF_EMULATION_DISABLE (0x01)
  221. extern u8 irq_vpif_capture_channel[VPIF_NUM_CHANNELS];
  222. /* inline function to enable/disable channel0 */
  223. static inline void enable_channel0(int enable)
  224. {
  225. if (enable)
  226. regw((regr(VPIF_CH0_CTRL) | (VPIF_CH0_EN)), VPIF_CH0_CTRL);
  227. else
  228. regw((regr(VPIF_CH0_CTRL) & (~VPIF_CH0_EN)), VPIF_CH0_CTRL);
  229. }
  230. /* inline function to enable/disable channel1 */
  231. static inline void enable_channel1(int enable)
  232. {
  233. if (enable)
  234. regw((regr(VPIF_CH1_CTRL) | (VPIF_CH1_EN)), VPIF_CH1_CTRL);
  235. else
  236. regw((regr(VPIF_CH1_CTRL) & (~VPIF_CH1_EN)), VPIF_CH1_CTRL);
  237. }
  238. /* inline function to enable interrupt for channel0 */
  239. static inline void channel0_intr_enable(int enable)
  240. {
  241. unsigned long flags;
  242. spin_lock_irqsave(&vpif_lock, flags);
  243. if (enable) {
  244. regw((regr(VPIF_INTEN) | 0x10), VPIF_INTEN);
  245. regw((regr(VPIF_INTEN_SET) | 0x10), VPIF_INTEN_SET);
  246. regw((regr(VPIF_INTEN) | VPIF_INTEN_FRAME_CH0), VPIF_INTEN);
  247. regw((regr(VPIF_INTEN_SET) | VPIF_INTEN_FRAME_CH0),
  248. VPIF_INTEN_SET);
  249. } else {
  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. }
  254. spin_unlock_irqrestore(&vpif_lock, flags);
  255. }
  256. /* inline function to enable interrupt for channel1 */
  257. static inline void channel1_intr_enable(int enable)
  258. {
  259. unsigned long flags;
  260. spin_lock_irqsave(&vpif_lock, flags);
  261. if (enable) {
  262. regw((regr(VPIF_INTEN) | 0x10), VPIF_INTEN);
  263. regw((regr(VPIF_INTEN_SET) | 0x10), VPIF_INTEN_SET);
  264. regw((regr(VPIF_INTEN) | VPIF_INTEN_FRAME_CH1), VPIF_INTEN);
  265. regw((regr(VPIF_INTEN_SET) | VPIF_INTEN_FRAME_CH1),
  266. VPIF_INTEN_SET);
  267. } else {
  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. }
  272. spin_unlock_irqrestore(&vpif_lock, flags);
  273. }
  274. /* inline function to set buffer addresses in case of Y/C non mux mode */
  275. static inline void ch0_set_videobuf_addr_yc_nmux(unsigned long top_strt_luma,
  276. unsigned long btm_strt_luma,
  277. unsigned long top_strt_chroma,
  278. unsigned long btm_strt_chroma)
  279. {
  280. regw(top_strt_luma, VPIF_CH0_TOP_STRT_ADD_LUMA);
  281. regw(btm_strt_luma, VPIF_CH0_BTM_STRT_ADD_LUMA);
  282. regw(top_strt_chroma, VPIF_CH1_TOP_STRT_ADD_CHROMA);
  283. regw(btm_strt_chroma, VPIF_CH1_BTM_STRT_ADD_CHROMA);
  284. }
  285. /* inline function to set buffer addresses in VPIF registers for video data */
  286. static inline void ch0_set_videobuf_addr(unsigned long top_strt_luma,
  287. unsigned long btm_strt_luma,
  288. unsigned long top_strt_chroma,
  289. unsigned long btm_strt_chroma)
  290. {
  291. regw(top_strt_luma, VPIF_CH0_TOP_STRT_ADD_LUMA);
  292. regw(btm_strt_luma, VPIF_CH0_BTM_STRT_ADD_LUMA);
  293. regw(top_strt_chroma, VPIF_CH0_TOP_STRT_ADD_CHROMA);
  294. regw(btm_strt_chroma, VPIF_CH0_BTM_STRT_ADD_CHROMA);
  295. }
  296. static inline void ch1_set_videobuf_addr(unsigned long top_strt_luma,
  297. unsigned long btm_strt_luma,
  298. unsigned long top_strt_chroma,
  299. unsigned long btm_strt_chroma)
  300. {
  301. regw(top_strt_luma, VPIF_CH1_TOP_STRT_ADD_LUMA);
  302. regw(btm_strt_luma, VPIF_CH1_BTM_STRT_ADD_LUMA);
  303. regw(top_strt_chroma, VPIF_CH1_TOP_STRT_ADD_CHROMA);
  304. regw(btm_strt_chroma, VPIF_CH1_BTM_STRT_ADD_CHROMA);
  305. }
  306. static inline void ch0_set_vbi_addr(unsigned long top_vbi,
  307. unsigned long btm_vbi, unsigned long a, unsigned long b)
  308. {
  309. regw(top_vbi, VPIF_CH0_TOP_STRT_ADD_VANC);
  310. regw(btm_vbi, VPIF_CH0_BTM_STRT_ADD_VANC);
  311. }
  312. static inline void ch0_set_hbi_addr(unsigned long top_vbi,
  313. unsigned long btm_vbi, unsigned long a, unsigned long b)
  314. {
  315. regw(top_vbi, VPIF_CH0_TOP_STRT_ADD_HANC);
  316. regw(btm_vbi, VPIF_CH0_BTM_STRT_ADD_HANC);
  317. }
  318. static inline void ch1_set_vbi_addr(unsigned long top_vbi,
  319. unsigned long btm_vbi, unsigned long a, unsigned long b)
  320. {
  321. regw(top_vbi, VPIF_CH1_TOP_STRT_ADD_VANC);
  322. regw(btm_vbi, VPIF_CH1_BTM_STRT_ADD_VANC);
  323. }
  324. static inline void ch1_set_hbi_addr(unsigned long top_vbi,
  325. unsigned long btm_vbi, unsigned long a, unsigned long b)
  326. {
  327. regw(top_vbi, VPIF_CH1_TOP_STRT_ADD_HANC);
  328. regw(btm_vbi, VPIF_CH1_BTM_STRT_ADD_HANC);
  329. }
  330. /* Inline function to enable raw vbi in the given channel */
  331. static inline void disable_raw_feature(u8 channel_id, u8 index)
  332. {
  333. u32 ctrl_reg;
  334. if (0 == channel_id)
  335. ctrl_reg = VPIF_CH0_CTRL;
  336. else
  337. ctrl_reg = VPIF_CH1_CTRL;
  338. if (1 == index)
  339. vpif_clr_bit(ctrl_reg, VPIF_CH_VANC_EN_BIT);
  340. else
  341. vpif_clr_bit(ctrl_reg, VPIF_CH_HANC_EN_BIT);
  342. }
  343. static inline void enable_raw_feature(u8 channel_id, u8 index)
  344. {
  345. u32 ctrl_reg;
  346. if (0 == channel_id)
  347. ctrl_reg = VPIF_CH0_CTRL;
  348. else
  349. ctrl_reg = VPIF_CH1_CTRL;
  350. if (1 == index)
  351. vpif_set_bit(ctrl_reg, VPIF_CH_VANC_EN_BIT);
  352. else
  353. vpif_set_bit(ctrl_reg, VPIF_CH_HANC_EN_BIT);
  354. }
  355. /* inline function to enable/disable channel2 */
  356. static inline void enable_channel2(int enable)
  357. {
  358. if (enable) {
  359. regw((regr(VPIF_CH2_CTRL) | (VPIF_CH2_CLK_EN)), VPIF_CH2_CTRL);
  360. regw((regr(VPIF_CH2_CTRL) | (VPIF_CH2_EN)), VPIF_CH2_CTRL);
  361. } else {
  362. regw((regr(VPIF_CH2_CTRL) & (~VPIF_CH2_CLK_EN)), VPIF_CH2_CTRL);
  363. regw((regr(VPIF_CH2_CTRL) & (~VPIF_CH2_EN)), VPIF_CH2_CTRL);
  364. }
  365. }
  366. /* inline function to enable/disable channel3 */
  367. static inline void enable_channel3(int enable)
  368. {
  369. if (enable) {
  370. regw((regr(VPIF_CH3_CTRL) | (VPIF_CH3_CLK_EN)), VPIF_CH3_CTRL);
  371. regw((regr(VPIF_CH3_CTRL) | (VPIF_CH3_EN)), VPIF_CH3_CTRL);
  372. } else {
  373. regw((regr(VPIF_CH3_CTRL) & (~VPIF_CH3_CLK_EN)), VPIF_CH3_CTRL);
  374. regw((regr(VPIF_CH3_CTRL) & (~VPIF_CH3_EN)), VPIF_CH3_CTRL);
  375. }
  376. }
  377. /* inline function to enable interrupt for channel2 */
  378. static inline void channel2_intr_enable(int enable)
  379. {
  380. unsigned long flags;
  381. spin_lock_irqsave(&vpif_lock, flags);
  382. if (enable) {
  383. regw((regr(VPIF_INTEN) | 0x10), VPIF_INTEN);
  384. regw((regr(VPIF_INTEN_SET) | 0x10), VPIF_INTEN_SET);
  385. regw((regr(VPIF_INTEN) | VPIF_INTEN_FRAME_CH2), VPIF_INTEN);
  386. regw((regr(VPIF_INTEN_SET) | VPIF_INTEN_FRAME_CH2),
  387. VPIF_INTEN_SET);
  388. } else {
  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. }
  393. spin_unlock_irqrestore(&vpif_lock, flags);
  394. }
  395. /* inline function to enable interrupt for channel3 */
  396. static inline void channel3_intr_enable(int enable)
  397. {
  398. unsigned long flags;
  399. spin_lock_irqsave(&vpif_lock, flags);
  400. if (enable) {
  401. regw((regr(VPIF_INTEN) | 0x10), VPIF_INTEN);
  402. regw((regr(VPIF_INTEN_SET) | 0x10), VPIF_INTEN_SET);
  403. regw((regr(VPIF_INTEN) | VPIF_INTEN_FRAME_CH3), VPIF_INTEN);
  404. regw((regr(VPIF_INTEN_SET) | VPIF_INTEN_FRAME_CH3),
  405. VPIF_INTEN_SET);
  406. } else {
  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. }
  411. spin_unlock_irqrestore(&vpif_lock, flags);
  412. }
  413. /* inline function to enable raw vbi data for channel2 */
  414. static inline void channel2_raw_enable(int enable, u8 index)
  415. {
  416. u32 mask;
  417. if (1 == index)
  418. mask = VPIF_CH_VANC_EN_BIT;
  419. else
  420. mask = VPIF_CH_HANC_EN_BIT;
  421. if (enable)
  422. vpif_set_bit(VPIF_CH2_CTRL, mask);
  423. else
  424. vpif_clr_bit(VPIF_CH2_CTRL, mask);
  425. }
  426. /* inline function to enable raw vbi data for channel3*/
  427. static inline void channel3_raw_enable(int enable, u8 index)
  428. {
  429. u32 mask;
  430. if (1 == index)
  431. mask = VPIF_CH_VANC_EN_BIT;
  432. else
  433. mask = VPIF_CH_HANC_EN_BIT;
  434. if (enable)
  435. vpif_set_bit(VPIF_CH3_CTRL, mask);
  436. else
  437. vpif_clr_bit(VPIF_CH3_CTRL, mask);
  438. }
  439. /* inline function to set buffer addresses in case of Y/C non mux mode */
  440. static inline void ch2_set_videobuf_addr_yc_nmux(unsigned long top_strt_luma,
  441. unsigned long btm_strt_luma,
  442. unsigned long top_strt_chroma,
  443. unsigned long btm_strt_chroma)
  444. {
  445. regw(top_strt_luma, VPIF_CH2_TOP_STRT_ADD_LUMA);
  446. regw(btm_strt_luma, VPIF_CH2_BTM_STRT_ADD_LUMA);
  447. regw(top_strt_chroma, VPIF_CH3_TOP_STRT_ADD_CHROMA);
  448. regw(btm_strt_chroma, VPIF_CH3_BTM_STRT_ADD_CHROMA);
  449. }
  450. /* inline function to set buffer addresses in VPIF registers for video data */
  451. static inline void ch2_set_videobuf_addr(unsigned long top_strt_luma,
  452. unsigned long btm_strt_luma,
  453. unsigned long top_strt_chroma,
  454. unsigned long btm_strt_chroma)
  455. {
  456. regw(top_strt_luma, VPIF_CH2_TOP_STRT_ADD_LUMA);
  457. regw(btm_strt_luma, VPIF_CH2_BTM_STRT_ADD_LUMA);
  458. regw(top_strt_chroma, VPIF_CH2_TOP_STRT_ADD_CHROMA);
  459. regw(btm_strt_chroma, VPIF_CH2_BTM_STRT_ADD_CHROMA);
  460. }
  461. static inline void ch3_set_videobuf_addr(unsigned long top_strt_luma,
  462. unsigned long btm_strt_luma,
  463. unsigned long top_strt_chroma,
  464. unsigned long btm_strt_chroma)
  465. {
  466. regw(top_strt_luma, VPIF_CH3_TOP_STRT_ADD_LUMA);
  467. regw(btm_strt_luma, VPIF_CH3_BTM_STRT_ADD_LUMA);
  468. regw(top_strt_chroma, VPIF_CH3_TOP_STRT_ADD_CHROMA);
  469. regw(btm_strt_chroma, VPIF_CH3_BTM_STRT_ADD_CHROMA);
  470. }
  471. /* inline function to set buffer addresses in VPIF registers for vbi data */
  472. static inline void ch2_set_vbi_addr(unsigned long top_strt_luma,
  473. unsigned long btm_strt_luma,
  474. unsigned long top_strt_chroma,
  475. unsigned long btm_strt_chroma)
  476. {
  477. regw(top_strt_luma, VPIF_CH2_TOP_STRT_ADD_VANC);
  478. regw(btm_strt_luma, VPIF_CH2_BTM_STRT_ADD_VANC);
  479. }
  480. static inline void ch3_set_vbi_addr(unsigned long top_strt_luma,
  481. unsigned long btm_strt_luma,
  482. unsigned long top_strt_chroma,
  483. unsigned long btm_strt_chroma)
  484. {
  485. regw(top_strt_luma, VPIF_CH3_TOP_STRT_ADD_VANC);
  486. regw(btm_strt_luma, VPIF_CH3_BTM_STRT_ADD_VANC);
  487. }
  488. #define VPIF_MAX_NAME (30)
  489. /* This structure will store size parameters as per the mode selected by user */
  490. struct vpif_channel_config_params {
  491. char name[VPIF_MAX_NAME]; /* Name of the mode */
  492. u16 width; /* Indicates width of the image */
  493. u16 height; /* Indicates height of the image */
  494. u8 frm_fmt; /* Interlaced (0) or progressive (1) */
  495. u8 ycmux_mode; /* This mode requires one (0) or two (1)
  496. channels */
  497. u16 eav2sav; /* length of eav 2 sav */
  498. u16 sav2eav; /* length of sav 2 eav */
  499. u16 l1, l3, l5, l7, l9, l11; /* Other parameter configurations */
  500. u16 vsize; /* Vertical size of the image */
  501. u8 capture_format; /* Indicates whether capture format
  502. * is in BT or in CCD/CMOS */
  503. u8 vbi_supported; /* Indicates whether this mode
  504. * supports capturing vbi or not */
  505. u8 hd_sd; /* HDTV (1) or SDTV (0) format */
  506. v4l2_std_id stdid; /* SDTV format */
  507. u32 dv_preset; /* HDTV format */
  508. };
  509. extern const unsigned int vpif_ch_params_count;
  510. extern const struct vpif_channel_config_params ch_params[];
  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 */