ivtv-controls.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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_subdev_format format = {
  58. .which = V4L2_SUBDEV_FORMAT_ACTIVE,
  59. };
  60. /* fix videodecoder resolution */
  61. format.format.width = cxhdl->width / (is_mpeg1 ? 2 : 1);
  62. format.format.height = cxhdl->height;
  63. format.format.code = MEDIA_BUS_FMT_FIXED;
  64. v4l2_subdev_call(itv->sd_video, pad, set_fmt, NULL, &format);
  65. return 0;
  66. }
  67. static int ivtv_s_audio_sampling_freq(struct cx2341x_handler *cxhdl, u32 idx)
  68. {
  69. static const u32 freqs[3] = { 44100, 48000, 32000 };
  70. struct ivtv *itv = container_of(cxhdl, struct ivtv, cxhdl);
  71. /* The audio clock of the digitizer must match the codec sample
  72. rate otherwise you get some very strange effects. */
  73. if (idx < ARRAY_SIZE(freqs))
  74. ivtv_call_all(itv, audio, s_clock_freq, freqs[idx]);
  75. return 0;
  76. }
  77. static int ivtv_s_audio_mode(struct cx2341x_handler *cxhdl, u32 val)
  78. {
  79. struct ivtv *itv = container_of(cxhdl, struct ivtv, cxhdl);
  80. itv->dualwatch_stereo_mode = val;
  81. return 0;
  82. }
  83. const struct cx2341x_handler_ops ivtv_cxhdl_ops = {
  84. .s_audio_mode = ivtv_s_audio_mode,
  85. .s_audio_sampling_freq = ivtv_s_audio_sampling_freq,
  86. .s_video_encoding = ivtv_s_video_encoding,
  87. .s_stream_vbi_fmt = ivtv_s_stream_vbi_fmt,
  88. };
  89. int ivtv_g_pts_frame(struct ivtv *itv, s64 *pts, s64 *frame)
  90. {
  91. u32 data[CX2341X_MBOX_MAX_DATA];
  92. if (test_bit(IVTV_F_I_VALID_DEC_TIMINGS, &itv->i_flags)) {
  93. *pts = (s64)((u64)itv->last_dec_timing[2] << 32) |
  94. (u64)itv->last_dec_timing[1];
  95. *frame = itv->last_dec_timing[0];
  96. return 0;
  97. }
  98. *pts = 0;
  99. *frame = 0;
  100. if (atomic_read(&itv->decoding)) {
  101. if (ivtv_api(itv, CX2341X_DEC_GET_TIMING_INFO, 5, data)) {
  102. IVTV_DEBUG_WARN("GET_TIMING: couldn't read clock\n");
  103. return -EIO;
  104. }
  105. memcpy(itv->last_dec_timing, data, sizeof(itv->last_dec_timing));
  106. set_bit(IVTV_F_I_VALID_DEC_TIMINGS, &itv->i_flags);
  107. *pts = (s64)((u64) data[2] << 32) | (u64) data[1];
  108. *frame = data[0];
  109. /*timing->scr = (u64) (((u64) data[4] << 32) | (u64) (data[3]));*/
  110. }
  111. return 0;
  112. }
  113. static int ivtv_g_volatile_ctrl(struct v4l2_ctrl *ctrl)
  114. {
  115. struct ivtv *itv = container_of(ctrl->handler, struct ivtv, cxhdl.hdl);
  116. switch (ctrl->id) {
  117. /* V4L2_CID_MPEG_VIDEO_DEC_PTS and V4L2_CID_MPEG_VIDEO_DEC_FRAME
  118. control cluster */
  119. case V4L2_CID_MPEG_VIDEO_DEC_PTS:
  120. return ivtv_g_pts_frame(itv, itv->ctrl_pts->p_new.p_s64,
  121. itv->ctrl_frame->p_new.p_s64);
  122. }
  123. return 0;
  124. }
  125. static int ivtv_s_ctrl(struct v4l2_ctrl *ctrl)
  126. {
  127. struct ivtv *itv = container_of(ctrl->handler, struct ivtv, cxhdl.hdl);
  128. switch (ctrl->id) {
  129. /* V4L2_CID_MPEG_AUDIO_DEC_PLAYBACK and MULTILINGUAL_PLAYBACK
  130. control cluster */
  131. case V4L2_CID_MPEG_AUDIO_DEC_PLAYBACK:
  132. itv->audio_stereo_mode = itv->ctrl_audio_playback->val - 1;
  133. itv->audio_bilingual_mode = itv->ctrl_audio_multilingual_playback->val - 1;
  134. ivtv_vapi(itv, CX2341X_DEC_SET_AUDIO_MODE, 2, itv->audio_bilingual_mode, itv->audio_stereo_mode);
  135. break;
  136. }
  137. return 0;
  138. }
  139. const struct v4l2_ctrl_ops ivtv_hdl_out_ops = {
  140. .s_ctrl = ivtv_s_ctrl,
  141. .g_volatile_ctrl = ivtv_g_volatile_ctrl,
  142. };