vpif.h 20 KB

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