ivtv-controls.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. ioctl control functions
  4. Copyright (C) 2003-2004 Kevin Thayer <nufan_wfk at yahoo.com>
  5. Copyright (C) 2005-2007 Hans Verkuil <[email protected]>
  6. */
  7. #include "ivtv-driver.h"
  8. #include "ivtv-ioctl.h"
  9. #include "ivtv-controls.h"
  10. #include "ivtv-mailbox.h"
  11. static int ivtv_s_stream_vbi_fmt(struct cx2341x_handler *cxhdl, u32 fmt)
  12. {
  13. struct ivtv *itv = container_of(cxhdl, struct ivtv, cxhdl);
  14. /* First try to allocate sliced VBI buffers if needed. */
  15. if (fmt && itv->vbi.sliced_mpeg_data[0] == NULL) {
  16. int i;
  17. for (i = 0; i < IVTV_VBI_FRAMES; i++) {
  18. /* Yuck, hardcoded. Needs to be a define */
  19. itv->vbi.sliced_mpeg_data[i] = kmalloc(2049, GFP_KERNEL);
  20. if (itv->vbi.sliced_mpeg_data[i] == NULL) {
  21. while (--i >= 0) {
  22. kfree(itv->vbi.sliced_mpeg_data[i]);
  23. itv->vbi.sliced_mpeg_data[i] = NULL;
  24. }
  25. return -ENOMEM;
  26. }
  27. }
  28. }
  29. itv->vbi.insert_mpeg = fmt;
  30. if (itv->vbi.insert_mpeg == 0) {
  31. return 0;
  32. }
  33. /* Need sliced data for mpeg insertion */
  34. if (ivtv_get_service_set(itv->vbi.sliced_in) == 0) {
  35. if (itv->is_60hz)
  36. itv->vbi.sliced_in->service_set = V4L2_SLICED_CAPTION_525;
  37. else
  38. itv->vbi.sliced_in->service_set = V4L2_SLICED_WSS_625;
  39. ivtv_expand_service_set(itv->vbi.sliced_in, itv->is_50hz);
  40. }
  41. return 0;
  42. }
  43. static int ivtv_s_video_encoding(struct cx2341x_handler *cxhdl, u32 val)
  44. {
  45. struct ivtv *itv = container_of(cxhdl, struct ivtv, cxhdl);
  46. int is_mpeg1 = val == V4L2_MPEG_VIDEO_ENCODING_MPEG_1;
  47. struct v4l2_subdev_format format = {
  48. .which = V4L2_SUBDEV_FORMAT_ACTIVE,
  49. };
  50. /* fix videodecoder resolution */
  51. format.format.width = cxhdl->width / (is_mpeg1 ? 2 : 1);
  52. format.format.height = cxhdl->height;
  53. format.format.code = MEDIA_BUS_FMT_FIXED;
  54. v4l2_subdev_call(itv->sd_video, pad, set_fmt, NULL, &format);
  55. return 0;
  56. }
  57. static int ivtv_s_audio_sampling_freq(struct cx2341x_handler *cxhdl, u32 idx)
  58. {
  59. static const u32 freqs[3] = { 44100, 48000, 32000 };
  60. struct ivtv *itv = container_of(cxhdl, struct ivtv, cxhdl);
  61. /* The audio clock of the digitizer must match the codec sample
  62. rate otherwise you get some very strange effects. */
  63. if (idx < ARRAY_SIZE(freqs))
  64. ivtv_call_all(itv, audio, s_clock_freq, freqs[idx]);
  65. return 0;
  66. }
  67. static int ivtv_s_audio_mode(struct cx2341x_handler *cxhdl, u32 val)
  68. {
  69. struct ivtv *itv = container_of(cxhdl, struct ivtv, cxhdl);
  70. itv->dualwatch_stereo_mode = val;
  71. return 0;
  72. }
  73. const struct cx2341x_handler_ops ivtv_cxhdl_ops = {
  74. .s_audio_mode = ivtv_s_audio_mode,
  75. .s_audio_sampling_freq = ivtv_s_audio_sampling_freq,
  76. .s_video_encoding = ivtv_s_video_encoding,
  77. .s_stream_vbi_fmt = ivtv_s_stream_vbi_fmt,
  78. };
  79. int ivtv_g_pts_frame(struct ivtv *itv, s64 *pts, s64 *frame)
  80. {
  81. u32 data[CX2341X_MBOX_MAX_DATA];
  82. if (test_bit(IVTV_F_I_VALID_DEC_TIMINGS, &itv->i_flags)) {
  83. *pts = (s64)((u64)itv->last_dec_timing[2] << 32) |
  84. (u64)itv->last_dec_timing[1];
  85. *frame = itv->last_dec_timing[0];
  86. return 0;
  87. }
  88. *pts = 0;
  89. *frame = 0;
  90. if (atomic_read(&itv->decoding)) {
  91. if (ivtv_api(itv, CX2341X_DEC_GET_TIMING_INFO, 5, data)) {
  92. IVTV_DEBUG_WARN("GET_TIMING: couldn't read clock\n");
  93. return -EIO;
  94. }
  95. memcpy(itv->last_dec_timing, data, sizeof(itv->last_dec_timing));
  96. set_bit(IVTV_F_I_VALID_DEC_TIMINGS, &itv->i_flags);
  97. *pts = (s64)((u64) data[2] << 32) | (u64) data[1];
  98. *frame = data[0];
  99. /*timing->scr = (u64) (((u64) data[4] << 32) | (u64) (data[3]));*/
  100. }
  101. return 0;
  102. }
  103. static int ivtv_g_volatile_ctrl(struct v4l2_ctrl *ctrl)
  104. {
  105. struct ivtv *itv = container_of(ctrl->handler, struct ivtv, cxhdl.hdl);
  106. switch (ctrl->id) {
  107. /* V4L2_CID_MPEG_VIDEO_DEC_PTS and V4L2_CID_MPEG_VIDEO_DEC_FRAME
  108. control cluster */
  109. case V4L2_CID_MPEG_VIDEO_DEC_PTS:
  110. return ivtv_g_pts_frame(itv, itv->ctrl_pts->p_new.p_s64,
  111. itv->ctrl_frame->p_new.p_s64);
  112. }
  113. return 0;
  114. }
  115. static int ivtv_s_ctrl(struct v4l2_ctrl *ctrl)
  116. {
  117. struct ivtv *itv = container_of(ctrl->handler, struct ivtv, cxhdl.hdl);
  118. switch (ctrl->id) {
  119. /* V4L2_CID_MPEG_AUDIO_DEC_PLAYBACK and MULTILINGUAL_PLAYBACK
  120. control cluster */
  121. case V4L2_CID_MPEG_AUDIO_DEC_PLAYBACK:
  122. itv->audio_stereo_mode = itv->ctrl_audio_playback->val - 1;
  123. itv->audio_bilingual_mode = itv->ctrl_audio_multilingual_playback->val - 1;
  124. ivtv_vapi(itv, CX2341X_DEC_SET_AUDIO_MODE, 2, itv->audio_bilingual_mode, itv->audio_stereo_mode);
  125. break;
  126. }
  127. return 0;
  128. }
  129. const struct v4l2_ctrl_ops ivtv_hdl_out_ops = {
  130. .s_ctrl = ivtv_s_ctrl,
  131. .g_volatile_ctrl = ivtv_g_volatile_ctrl,
  132. };