ivtv-controls.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /*
  2. ioctl control functions
  3. Copyright (C) 2003-2004 Kevin Thayer <nufan_wfk at yahoo.com>
  4. Copyright (C) 2005-2007 Hans Verkuil <hverkuil@xs4all.nl>
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. */
  17. #include "ivtv-driver.h"
  18. #include "ivtv-ioctl.h"
  19. #include "ivtv-controls.h"
  20. #include "ivtv-mailbox.h"
  21. static int ivtv_s_stream_vbi_fmt(struct cx2341x_handler *cxhdl, u32 fmt)
  22. {
  23. struct ivtv *itv = container_of(cxhdl, struct ivtv, cxhdl);
  24. /* First try to allocate sliced VBI buffers if needed. */
  25. if (fmt && itv->vbi.sliced_mpeg_data[0] == NULL) {
  26. int i;
  27. for (i = 0; i < IVTV_VBI_FRAMES; i++) {
  28. /* Yuck, hardcoded. Needs to be a define */
  29. itv->vbi.sliced_mpeg_data[i] = kmalloc(2049, GFP_KERNEL);
  30. if (itv->vbi.sliced_mpeg_data[i] == NULL) {
  31. while (--i >= 0) {
  32. kfree(itv->vbi.sliced_mpeg_data[i]);
  33. itv->vbi.sliced_mpeg_data[i] = NULL;
  34. }
  35. return -ENOMEM;
  36. }
  37. }
  38. }
  39. itv->vbi.insert_mpeg = fmt;
  40. if (itv->vbi.insert_mpeg == 0) {
  41. return 0;
  42. }
  43. /* Need sliced data for mpeg insertion */
  44. if (ivtv_get_service_set(itv->vbi.sliced_in) == 0) {
  45. if (itv->is_60hz)
  46. itv->vbi.sliced_in->service_set = V4L2_SLICED_CAPTION_525;
  47. else
  48. itv->vbi.sliced_in->service_set = V4L2_SLICED_WSS_625;
  49. ivtv_expand_service_set(itv->vbi.sliced_in, itv->is_50hz);
  50. }
  51. return 0;
  52. }
  53. static int ivtv_s_video_encoding(struct cx2341x_handler *cxhdl, u32 val)
  54. {
  55. struct ivtv *itv = container_of(cxhdl, struct ivtv, cxhdl);
  56. int is_mpeg1 = val == V4L2_MPEG_VIDEO_ENCODING_MPEG_1;
  57. struct v4l2_mbus_framefmt fmt;
  58. /* fix videodecoder resolution */
  59. fmt.width = cxhdl->width / (is_mpeg1 ? 2 : 1);
  60. fmt.height = cxhdl->height;
  61. fmt.code = V4L2_MBUS_FMT_FIXED;
  62. v4l2_subdev_call(itv->sd_video, video, s_mbus_fmt, &fmt);
  63. return 0;
  64. }
  65. static int ivtv_s_audio_sampling_freq(struct cx2341x_handler *cxhdl, u32 idx)
  66. {
  67. static const u32 freqs[3] = { 44100, 48000, 32000 };
  68. struct ivtv *itv = container_of(cxhdl, struct ivtv, cxhdl);
  69. /* The audio clock of the digitizer must match the codec sample
  70. rate otherwise you get some very strange effects. */
  71. if (idx < ARRAY_SIZE(freqs))
  72. ivtv_call_all(itv, audio, s_clock_freq, freqs[idx]);
  73. return 0;
  74. }
  75. static int ivtv_s_audio_mode(struct cx2341x_handler *cxhdl, u32 val)
  76. {
  77. struct ivtv *itv = container_of(cxhdl, struct ivtv, cxhdl);
  78. itv->dualwatch_stereo_mode = val;
  79. return 0;
  80. }
  81. struct cx2341x_handler_ops ivtv_cxhdl_ops = {
  82. .s_audio_mode = ivtv_s_audio_mode,
  83. .s_audio_sampling_freq = ivtv_s_audio_sampling_freq,
  84. .s_video_encoding = ivtv_s_video_encoding,
  85. .s_stream_vbi_fmt = ivtv_s_stream_vbi_fmt,
  86. };
  87. int ivtv_g_pts_frame(struct ivtv *itv, s64 *pts, s64 *frame)
  88. {
  89. u32 data[CX2341X_MBOX_MAX_DATA];
  90. if (test_bit(IVTV_F_I_VALID_DEC_TIMINGS, &itv->i_flags)) {
  91. *pts = (s64)((u64)itv->last_dec_timing[2] << 32) |
  92. (u64)itv->last_dec_timing[1];
  93. *frame = itv->last_dec_timing[0];
  94. return 0;
  95. }
  96. *pts = 0;
  97. *frame = 0;
  98. if (atomic_read(&itv->decoding)) {
  99. if (ivtv_api(itv, CX2341X_DEC_GET_TIMING_INFO, 5, data)) {
  100. IVTV_DEBUG_WARN("GET_TIMING: couldn't read clock\n");
  101. return -EIO;
  102. }
  103. memcpy(itv->last_dec_timing, data, sizeof(itv->last_dec_timing));
  104. set_bit(IVTV_F_I_VALID_DEC_TIMINGS, &itv->i_flags);
  105. *pts = (s64)((u64) data[2] << 32) | (u64) data[1];
  106. *frame = data[0];
  107. /*timing->scr = (u64) (((u64) data[4] << 32) | (u64) (data[3]));*/
  108. }
  109. return 0;
  110. }
  111. static int ivtv_g_volatile_ctrl(struct v4l2_ctrl *ctrl)
  112. {
  113. struct ivtv *itv = container_of(ctrl->handler, struct ivtv, cxhdl.hdl);
  114. switch (ctrl->id) {
  115. /* V4L2_CID_MPEG_VIDEO_DEC_PTS and V4L2_CID_MPEG_VIDEO_DEC_FRAME
  116. control cluster */
  117. case V4L2_CID_MPEG_VIDEO_DEC_PTS:
  118. return ivtv_g_pts_frame(itv, &itv->ctrl_pts->val64,
  119. &itv->ctrl_frame->val64);
  120. }
  121. return 0;
  122. }
  123. static int ivtv_s_ctrl(struct v4l2_ctrl *ctrl)
  124. {
  125. struct ivtv *itv = container_of(ctrl->handler, struct ivtv, cxhdl.hdl);
  126. switch (ctrl->id) {
  127. /* V4L2_CID_MPEG_AUDIO_DEC_PLAYBACK and MULTILINGUAL_PLAYBACK
  128. control cluster */
  129. case V4L2_CID_MPEG_AUDIO_DEC_PLAYBACK:
  130. itv->audio_stereo_mode = itv->ctrl_audio_playback->val - 1;
  131. itv->audio_bilingual_mode = itv->ctrl_audio_multilingual_playback->val - 1;
  132. ivtv_vapi(itv, CX2341X_DEC_SET_AUDIO_MODE, 2, itv->audio_bilingual_mode, itv->audio_stereo_mode);
  133. break;
  134. }
  135. return 0;
  136. }
  137. const struct v4l2_ctrl_ops ivtv_hdl_out_ops = {
  138. .s_ctrl = ivtv_s_ctrl,
  139. .g_volatile_ctrl = ivtv_g_volatile_ctrl,
  140. };