ivtv-video.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. saa7127 interface functions
  3. Copyright (C) 2004-2007 Hans Verkuil <hverkuil@xs4all.nl>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  15. */
  16. #include "ivtv-driver.h"
  17. #include "ivtv-video.h"
  18. #include "ivtv-i2c.h"
  19. #include "ivtv-gpio.h"
  20. #include "ivtv-cards.h"
  21. #include <media/upd64031a.h>
  22. #include <media/upd64083.h>
  23. void ivtv_set_vps(struct ivtv *itv, int enabled, u8 vps1, u8 vps2, u8 vps3,
  24. u8 vps4, u8 vps5)
  25. {
  26. struct v4l2_sliced_vbi_data data;
  27. if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT))
  28. return;
  29. data.id = V4L2_SLICED_VPS;
  30. data.field = 0;
  31. data.line = enabled ? 16 : 0;
  32. data.data[4] = vps1;
  33. data.data[10] = vps2;
  34. data.data[11] = vps3;
  35. data.data[12] = vps4;
  36. data.data[13] = vps5;
  37. ivtv_saa7127(itv, VIDIOC_INT_S_VBI_DATA, &data);
  38. }
  39. void ivtv_set_cc(struct ivtv *itv, int mode, u8 cc1, u8 cc2, u8 cc3, u8 cc4)
  40. {
  41. struct v4l2_sliced_vbi_data data;
  42. if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT))
  43. return;
  44. data.id = V4L2_SLICED_CAPTION_525;
  45. data.field = 0;
  46. data.line = (mode & 1) ? 21 : 0;
  47. data.data[0] = cc1;
  48. data.data[1] = cc2;
  49. ivtv_saa7127(itv, VIDIOC_INT_S_VBI_DATA, &data);
  50. data.field = 1;
  51. data.line = (mode & 2) ? 21 : 0;
  52. data.data[0] = cc3;
  53. data.data[1] = cc4;
  54. ivtv_saa7127(itv, VIDIOC_INT_S_VBI_DATA, &data);
  55. }
  56. void ivtv_set_wss(struct ivtv *itv, int enabled, int mode)
  57. {
  58. struct v4l2_sliced_vbi_data data;
  59. if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT))
  60. return;
  61. /* When using a 50 Hz system, always turn on the
  62. wide screen signal with 4x3 ratio as the default.
  63. Turning this signal on and off can confuse certain
  64. TVs. As far as I can tell there is no reason not to
  65. transmit this signal. */
  66. if ((itv->std & V4L2_STD_625_50) && !enabled) {
  67. enabled = 1;
  68. mode = 0x08; /* 4x3 full format */
  69. }
  70. data.id = V4L2_SLICED_WSS_625;
  71. data.field = 0;
  72. data.line = enabled ? 23 : 0;
  73. data.data[0] = mode & 0xff;
  74. data.data[1] = (mode >> 8) & 0xff;
  75. ivtv_saa7127(itv, VIDIOC_INT_S_VBI_DATA, &data);
  76. }
  77. void ivtv_encoder_enable(struct ivtv *itv, int enabled)
  78. {
  79. if (itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT) {
  80. ivtv_saa7127(itv, enabled ? VIDIOC_STREAMON : VIDIOC_STREAMOFF,
  81. &enabled);
  82. }
  83. }
  84. void ivtv_video_set_io(struct ivtv *itv)
  85. {
  86. struct v4l2_routing route;
  87. int inp = itv->active_input;
  88. u32 type;
  89. route.input = itv->card->video_inputs[inp].video_input;
  90. route.output = 0;
  91. itv->video_dec_func(itv, VIDIOC_INT_S_VIDEO_ROUTING, &route);
  92. type = itv->card->video_inputs[inp].video_type;
  93. if (type == IVTV_CARD_INPUT_VID_TUNER) {
  94. route.input = 0; /* Tuner */
  95. } else if (type < IVTV_CARD_INPUT_COMPOSITE1) {
  96. route.input = 2; /* S-Video */
  97. } else {
  98. route.input = 1; /* Composite */
  99. }
  100. if (itv->card->hw_video & IVTV_HW_GPIO)
  101. ivtv_gpio(itv, VIDIOC_INT_S_VIDEO_ROUTING, &route);
  102. if (itv->card->hw_video & IVTV_HW_UPD64031A) {
  103. if (type == IVTV_CARD_INPUT_VID_TUNER ||
  104. type >= IVTV_CARD_INPUT_COMPOSITE1) {
  105. /* Composite: GR on, connect to 3DYCS */
  106. route.input = UPD64031A_GR_ON | UPD64031A_3DYCS_COMPOSITE;
  107. } else {
  108. /* S-Video: GR bypassed, turn it off */
  109. route.input = UPD64031A_GR_OFF | UPD64031A_3DYCS_DISABLE;
  110. }
  111. route.input |= itv->card->gr_config;
  112. ivtv_upd64031a(itv, VIDIOC_INT_S_VIDEO_ROUTING, &route);
  113. }
  114. if (itv->card->hw_video & IVTV_HW_UPD6408X) {
  115. route.input = UPD64083_YCS_MODE;
  116. if (type > IVTV_CARD_INPUT_VID_TUNER &&
  117. type < IVTV_CARD_INPUT_COMPOSITE1) {
  118. /* S-Video uses YCNR mode and internal Y-ADC, the upd64031a
  119. is not used. */
  120. route.input |= UPD64083_YCNR_MODE;
  121. }
  122. else if (itv->card->hw_video & IVTV_HW_UPD64031A) {
  123. /* Use upd64031a output for tuner and composite(CX23416GYC only) inputs */
  124. if ((type == IVTV_CARD_INPUT_VID_TUNER)||
  125. (itv->card->type == IVTV_CARD_CX23416GYC)) {
  126. route.input |= UPD64083_EXT_Y_ADC;
  127. }
  128. }
  129. ivtv_upd64083(itv, VIDIOC_INT_S_VIDEO_ROUTING, &route);
  130. }
  131. }