vpif.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  1. /*
  2. * vpif - DM646x Video Port Interface driver
  3. * VPIF is a receiver and transmitter for video data. It has two channels(0, 1)
  4. * that receiveing video byte stream and two channels(2, 3) for video output.
  5. * The hardware supports SDTV, HDTV formats, raw data capture.
  6. * Currently, the driver supports NTSC and PAL standards.
  7. *
  8. * Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License as
  12. * published by the Free Software Foundation version 2.
  13. *
  14. * This program is distributed .as is. WITHOUT ANY WARRANTY of any
  15. * kind, whether express or implied; without even the implied warranty
  16. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. */
  19. #include <linux/init.h>
  20. #include <linux/module.h>
  21. #include <linux/platform_device.h>
  22. #include <linux/spinlock.h>
  23. #include <linux/kernel.h>
  24. #include <linux/io.h>
  25. #include <mach/hardware.h>
  26. #include "vpif.h"
  27. MODULE_DESCRIPTION("TI DaVinci Video Port Interface driver");
  28. MODULE_LICENSE("GPL");
  29. #define VPIF_CH0_MAX_MODES (22)
  30. #define VPIF_CH1_MAX_MODES (02)
  31. #define VPIF_CH2_MAX_MODES (15)
  32. #define VPIF_CH3_MAX_MODES (02)
  33. static resource_size_t res_len;
  34. static struct resource *res;
  35. spinlock_t vpif_lock;
  36. void __iomem *vpif_base;
  37. /**
  38. * ch_params: video standard configuration parameters for vpif
  39. * The table must include all presets from supported subdevices.
  40. */
  41. const struct vpif_channel_config_params ch_params[] = {
  42. /* HDTV formats */
  43. {
  44. .name = "480p59_94",
  45. .width = 720,
  46. .height = 480,
  47. .frm_fmt = 1,
  48. .ycmux_mode = 0,
  49. .eav2sav = 138-8,
  50. .sav2eav = 720,
  51. .l1 = 1,
  52. .l3 = 43,
  53. .l5 = 523,
  54. .vsize = 525,
  55. .capture_format = 0,
  56. .vbi_supported = 0,
  57. .hd_sd = 1,
  58. .dv_preset = V4L2_DV_480P59_94,
  59. },
  60. {
  61. .name = "576p50",
  62. .width = 720,
  63. .height = 576,
  64. .frm_fmt = 1,
  65. .ycmux_mode = 0,
  66. .eav2sav = 144-8,
  67. .sav2eav = 720,
  68. .l1 = 1,
  69. .l3 = 45,
  70. .l5 = 621,
  71. .vsize = 625,
  72. .capture_format = 0,
  73. .vbi_supported = 0,
  74. .hd_sd = 1,
  75. .dv_preset = V4L2_DV_576P50,
  76. },
  77. {
  78. .name = "720p50",
  79. .width = 1280,
  80. .height = 720,
  81. .frm_fmt = 1,
  82. .ycmux_mode = 0,
  83. .eav2sav = 700-8,
  84. .sav2eav = 1280,
  85. .l1 = 1,
  86. .l3 = 26,
  87. .l5 = 746,
  88. .vsize = 750,
  89. .capture_format = 0,
  90. .vbi_supported = 0,
  91. .hd_sd = 1,
  92. .dv_preset = V4L2_DV_720P50,
  93. },
  94. {
  95. .name = "720p60",
  96. .width = 1280,
  97. .height = 720,
  98. .frm_fmt = 1,
  99. .ycmux_mode = 0,
  100. .eav2sav = 370 - 8,
  101. .sav2eav = 1280,
  102. .l1 = 1,
  103. .l3 = 26,
  104. .l5 = 746,
  105. .vsize = 750,
  106. .capture_format = 0,
  107. .vbi_supported = 0,
  108. .hd_sd = 1,
  109. .dv_preset = V4L2_DV_720P60,
  110. },
  111. {
  112. .name = "1080I50",
  113. .width = 1920,
  114. .height = 1080,
  115. .frm_fmt = 0,
  116. .ycmux_mode = 0,
  117. .eav2sav = 720 - 8,
  118. .sav2eav = 1920,
  119. .l1 = 1,
  120. .l3 = 21,
  121. .l5 = 561,
  122. .l7 = 563,
  123. .l9 = 584,
  124. .l11 = 1124,
  125. .vsize = 1125,
  126. .capture_format = 0,
  127. .vbi_supported = 0,
  128. .hd_sd = 1,
  129. .dv_preset = V4L2_DV_1080I50,
  130. },
  131. {
  132. .name = "1080I60",
  133. .width = 1920,
  134. .height = 1080,
  135. .frm_fmt = 0,
  136. .ycmux_mode = 0,
  137. .eav2sav = 280 - 8,
  138. .sav2eav = 1920,
  139. .l1 = 1,
  140. .l3 = 21,
  141. .l5 = 561,
  142. .l7 = 563,
  143. .l9 = 584,
  144. .l11 = 1124,
  145. .vsize = 1125,
  146. .capture_format = 0,
  147. .vbi_supported = 0,
  148. .hd_sd = 1,
  149. .dv_preset = V4L2_DV_1080I60,
  150. },
  151. {
  152. .name = "1080p60",
  153. .width = 1920,
  154. .height = 1080,
  155. .frm_fmt = 1,
  156. .ycmux_mode = 0,
  157. .eav2sav = 280 - 8,
  158. .sav2eav = 1920,
  159. .l1 = 1,
  160. .l3 = 42,
  161. .l5 = 1122,
  162. .vsize = 1125,
  163. .capture_format = 0,
  164. .vbi_supported = 0,
  165. .hd_sd = 1,
  166. .dv_preset = V4L2_DV_1080P60,
  167. },
  168. /* SDTV formats */
  169. {
  170. .name = "NTSC_M",
  171. .width = 720,
  172. .height = 480,
  173. .frm_fmt = 0,
  174. .ycmux_mode = 1,
  175. .eav2sav = 268,
  176. .sav2eav = 1440,
  177. .l1 = 1,
  178. .l3 = 23,
  179. .l5 = 263,
  180. .l7 = 266,
  181. .l9 = 286,
  182. .l11 = 525,
  183. .vsize = 525,
  184. .capture_format = 0,
  185. .vbi_supported = 1,
  186. .hd_sd = 0,
  187. .stdid = V4L2_STD_525_60,
  188. },
  189. {
  190. .name = "PAL_BDGHIK",
  191. .width = 720,
  192. .height = 576,
  193. .frm_fmt = 0,
  194. .ycmux_mode = 1,
  195. .eav2sav = 280,
  196. .sav2eav = 1440,
  197. .l1 = 1,
  198. .l3 = 23,
  199. .l5 = 311,
  200. .l7 = 313,
  201. .l9 = 336,
  202. .l11 = 624,
  203. .vsize = 625,
  204. .capture_format = 0,
  205. .vbi_supported = 1,
  206. .hd_sd = 0,
  207. .stdid = V4L2_STD_625_50,
  208. },
  209. };
  210. const unsigned int vpif_ch_params_count = ARRAY_SIZE(ch_params);
  211. static inline void vpif_wr_bit(u32 reg, u32 bit, u32 val)
  212. {
  213. if (val)
  214. vpif_set_bit(reg, bit);
  215. else
  216. vpif_clr_bit(reg, bit);
  217. }
  218. /* This structure is used to keep track of VPIF size register's offsets */
  219. struct vpif_registers {
  220. u32 h_cfg, v_cfg_00, v_cfg_01, v_cfg_02, v_cfg, ch_ctrl;
  221. u32 line_offset, vanc0_strt, vanc0_size, vanc1_strt;
  222. u32 vanc1_size, width_mask, len_mask;
  223. u8 max_modes;
  224. };
  225. static const struct vpif_registers vpifregs[VPIF_NUM_CHANNELS] = {
  226. /* Channel0 */
  227. {
  228. VPIF_CH0_H_CFG, VPIF_CH0_V_CFG_00, VPIF_CH0_V_CFG_01,
  229. VPIF_CH0_V_CFG_02, VPIF_CH0_V_CFG_03, VPIF_CH0_CTRL,
  230. VPIF_CH0_IMG_ADD_OFST, 0, 0, 0, 0, 0x1FFF, 0xFFF,
  231. VPIF_CH0_MAX_MODES,
  232. },
  233. /* Channel1 */
  234. {
  235. VPIF_CH1_H_CFG, VPIF_CH1_V_CFG_00, VPIF_CH1_V_CFG_01,
  236. VPIF_CH1_V_CFG_02, VPIF_CH1_V_CFG_03, VPIF_CH1_CTRL,
  237. VPIF_CH1_IMG_ADD_OFST, 0, 0, 0, 0, 0x1FFF, 0xFFF,
  238. VPIF_CH1_MAX_MODES,
  239. },
  240. /* Channel2 */
  241. {
  242. VPIF_CH2_H_CFG, VPIF_CH2_V_CFG_00, VPIF_CH2_V_CFG_01,
  243. VPIF_CH2_V_CFG_02, VPIF_CH2_V_CFG_03, VPIF_CH2_CTRL,
  244. VPIF_CH2_IMG_ADD_OFST, VPIF_CH2_VANC0_STRT, VPIF_CH2_VANC0_SIZE,
  245. VPIF_CH2_VANC1_STRT, VPIF_CH2_VANC1_SIZE, 0x7FF, 0x7FF,
  246. VPIF_CH2_MAX_MODES
  247. },
  248. /* Channel3 */
  249. {
  250. VPIF_CH3_H_CFG, VPIF_CH3_V_CFG_00, VPIF_CH3_V_CFG_01,
  251. VPIF_CH3_V_CFG_02, VPIF_CH3_V_CFG_03, VPIF_CH3_CTRL,
  252. VPIF_CH3_IMG_ADD_OFST, VPIF_CH3_VANC0_STRT, VPIF_CH3_VANC0_SIZE,
  253. VPIF_CH3_VANC1_STRT, VPIF_CH3_VANC1_SIZE, 0x7FF, 0x7FF,
  254. VPIF_CH3_MAX_MODES
  255. },
  256. };
  257. /* vpif_set_mode_info:
  258. * This function is used to set horizontal and vertical config parameters
  259. * As per the standard in the channel, configure the values of L1, L3,
  260. * L5, L7 L9, L11 in VPIF Register , also write width and height
  261. */
  262. static void vpif_set_mode_info(const struct vpif_channel_config_params *config,
  263. u8 channel_id, u8 config_channel_id)
  264. {
  265. u32 value;
  266. value = (config->eav2sav & vpifregs[config_channel_id].width_mask);
  267. value <<= VPIF_CH_LEN_SHIFT;
  268. value |= (config->sav2eav & vpifregs[config_channel_id].width_mask);
  269. regw(value, vpifregs[channel_id].h_cfg);
  270. value = (config->l1 & vpifregs[config_channel_id].len_mask);
  271. value <<= VPIF_CH_LEN_SHIFT;
  272. value |= (config->l3 & vpifregs[config_channel_id].len_mask);
  273. regw(value, vpifregs[channel_id].v_cfg_00);
  274. value = (config->l5 & vpifregs[config_channel_id].len_mask);
  275. value <<= VPIF_CH_LEN_SHIFT;
  276. value |= (config->l7 & vpifregs[config_channel_id].len_mask);
  277. regw(value, vpifregs[channel_id].v_cfg_01);
  278. value = (config->l9 & vpifregs[config_channel_id].len_mask);
  279. value <<= VPIF_CH_LEN_SHIFT;
  280. value |= (config->l11 & vpifregs[config_channel_id].len_mask);
  281. regw(value, vpifregs[channel_id].v_cfg_02);
  282. value = (config->vsize & vpifregs[config_channel_id].len_mask);
  283. regw(value, vpifregs[channel_id].v_cfg);
  284. }
  285. /* config_vpif_params
  286. * Function to set the parameters of a channel
  287. * Mainly modifies the channel ciontrol register
  288. * It sets frame format, yc mux mode
  289. */
  290. static void config_vpif_params(struct vpif_params *vpifparams,
  291. u8 channel_id, u8 found)
  292. {
  293. const struct vpif_channel_config_params *config = &vpifparams->std_info;
  294. u32 value, ch_nip, reg;
  295. u8 start, end;
  296. int i;
  297. start = channel_id;
  298. end = channel_id + found;
  299. for (i = start; i < end; i++) {
  300. reg = vpifregs[i].ch_ctrl;
  301. if (channel_id < 2)
  302. ch_nip = VPIF_CAPTURE_CH_NIP;
  303. else
  304. ch_nip = VPIF_DISPLAY_CH_NIP;
  305. vpif_wr_bit(reg, ch_nip, config->frm_fmt);
  306. vpif_wr_bit(reg, VPIF_CH_YC_MUX_BIT, config->ycmux_mode);
  307. vpif_wr_bit(reg, VPIF_CH_INPUT_FIELD_FRAME_BIT,
  308. vpifparams->video_params.storage_mode);
  309. /* Set raster scanning SDR Format */
  310. vpif_clr_bit(reg, VPIF_CH_SDR_FMT_BIT);
  311. vpif_wr_bit(reg, VPIF_CH_DATA_MODE_BIT, config->capture_format);
  312. if (channel_id > 1) /* Set the Pixel enable bit */
  313. vpif_set_bit(reg, VPIF_DISPLAY_PIX_EN_BIT);
  314. else if (config->capture_format) {
  315. /* Set the polarity of various pins */
  316. vpif_wr_bit(reg, VPIF_CH_FID_POLARITY_BIT,
  317. vpifparams->iface.fid_pol);
  318. vpif_wr_bit(reg, VPIF_CH_V_VALID_POLARITY_BIT,
  319. vpifparams->iface.vd_pol);
  320. vpif_wr_bit(reg, VPIF_CH_H_VALID_POLARITY_BIT,
  321. vpifparams->iface.hd_pol);
  322. value = regr(reg);
  323. /* Set data width */
  324. value &= ((~(unsigned int)(0x3)) <<
  325. VPIF_CH_DATA_WIDTH_BIT);
  326. value |= ((vpifparams->params.data_sz) <<
  327. VPIF_CH_DATA_WIDTH_BIT);
  328. regw(value, reg);
  329. }
  330. /* Write the pitch in the driver */
  331. regw((vpifparams->video_params.hpitch),
  332. vpifregs[i].line_offset);
  333. }
  334. }
  335. /* vpif_set_video_params
  336. * This function is used to set video parameters in VPIF register
  337. */
  338. int vpif_set_video_params(struct vpif_params *vpifparams, u8 channel_id)
  339. {
  340. const struct vpif_channel_config_params *config = &vpifparams->std_info;
  341. int found = 1;
  342. vpif_set_mode_info(config, channel_id, channel_id);
  343. if (!config->ycmux_mode) {
  344. /* YC are on separate channels (HDTV formats) */
  345. vpif_set_mode_info(config, channel_id + 1, channel_id);
  346. found = 2;
  347. }
  348. config_vpif_params(vpifparams, channel_id, found);
  349. regw(0x80, VPIF_REQ_SIZE);
  350. regw(0x01, VPIF_EMULATION_CTRL);
  351. return found;
  352. }
  353. EXPORT_SYMBOL(vpif_set_video_params);
  354. void vpif_set_vbi_display_params(struct vpif_vbi_params *vbiparams,
  355. u8 channel_id)
  356. {
  357. u32 value;
  358. value = 0x3F8 & (vbiparams->hstart0);
  359. value |= 0x3FFFFFF & ((vbiparams->vstart0) << 16);
  360. regw(value, vpifregs[channel_id].vanc0_strt);
  361. value = 0x3F8 & (vbiparams->hstart1);
  362. value |= 0x3FFFFFF & ((vbiparams->vstart1) << 16);
  363. regw(value, vpifregs[channel_id].vanc1_strt);
  364. value = 0x3F8 & (vbiparams->hsize0);
  365. value |= 0x3FFFFFF & ((vbiparams->vsize0) << 16);
  366. regw(value, vpifregs[channel_id].vanc0_size);
  367. value = 0x3F8 & (vbiparams->hsize1);
  368. value |= 0x3FFFFFF & ((vbiparams->vsize1) << 16);
  369. regw(value, vpifregs[channel_id].vanc1_size);
  370. }
  371. EXPORT_SYMBOL(vpif_set_vbi_display_params);
  372. int vpif_channel_getfid(u8 channel_id)
  373. {
  374. return (regr(vpifregs[channel_id].ch_ctrl) & VPIF_CH_FID_MASK)
  375. >> VPIF_CH_FID_SHIFT;
  376. }
  377. EXPORT_SYMBOL(vpif_channel_getfid);
  378. static int __init vpif_probe(struct platform_device *pdev)
  379. {
  380. int status = 0;
  381. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  382. if (!res)
  383. return -ENOENT;
  384. res_len = resource_size(res);
  385. res = request_mem_region(res->start, res_len, res->name);
  386. if (!res)
  387. return -EBUSY;
  388. vpif_base = ioremap(res->start, res_len);
  389. if (!vpif_base) {
  390. status = -EBUSY;
  391. goto fail;
  392. }
  393. spin_lock_init(&vpif_lock);
  394. dev_info(&pdev->dev, "vpif probe success\n");
  395. return 0;
  396. fail:
  397. release_mem_region(res->start, res_len);
  398. return status;
  399. }
  400. static int __devexit vpif_remove(struct platform_device *pdev)
  401. {
  402. iounmap(vpif_base);
  403. release_mem_region(res->start, res_len);
  404. return 0;
  405. }
  406. static struct platform_driver vpif_driver = {
  407. .driver = {
  408. .name = "vpif",
  409. .owner = THIS_MODULE,
  410. },
  411. .remove = __devexit_p(vpif_remove),
  412. .probe = vpif_probe,
  413. };
  414. static void vpif_exit(void)
  415. {
  416. platform_driver_unregister(&vpif_driver);
  417. }
  418. static int __init vpif_init(void)
  419. {
  420. return platform_driver_register(&vpif_driver);
  421. }
  422. subsys_initcall(vpif_init);
  423. module_exit(vpif_exit);