cx18-controls.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * cx18 ioctl control functions
  4. *
  5. * Derived from ivtv-controls.c
  6. *
  7. * Copyright (C) 2007 Hans Verkuil <[email protected]>
  8. */
  9. #include <linux/kernel.h>
  10. #include <linux/slab.h>
  11. #include "cx18-driver.h"
  12. #include "cx18-cards.h"
  13. #include "cx18-ioctl.h"
  14. #include "cx18-audio.h"
  15. #include "cx18-mailbox.h"
  16. #include "cx18-controls.h"
  17. static int cx18_s_stream_vbi_fmt(struct cx2341x_handler *cxhdl, u32 fmt)
  18. {
  19. struct cx18 *cx = container_of(cxhdl, struct cx18, cxhdl);
  20. int type = cxhdl->stream_type->val;
  21. if (atomic_read(&cx->ana_capturing) > 0)
  22. return -EBUSY;
  23. if (fmt != V4L2_MPEG_STREAM_VBI_FMT_IVTV ||
  24. !(type == V4L2_MPEG_STREAM_TYPE_MPEG2_PS ||
  25. type == V4L2_MPEG_STREAM_TYPE_MPEG2_DVD ||
  26. type == V4L2_MPEG_STREAM_TYPE_MPEG2_SVCD)) {
  27. /* Only IVTV fmt VBI insertion & only MPEG-2 PS type streams */
  28. cx->vbi.insert_mpeg = V4L2_MPEG_STREAM_VBI_FMT_NONE;
  29. CX18_DEBUG_INFO("disabled insertion of sliced VBI data into the MPEG stream\n");
  30. return 0;
  31. }
  32. /* Allocate sliced VBI buffers if needed. */
  33. if (cx->vbi.sliced_mpeg_data[0] == NULL) {
  34. int i;
  35. for (i = 0; i < CX18_VBI_FRAMES; i++) {
  36. cx->vbi.sliced_mpeg_data[i] =
  37. kmalloc(CX18_SLICED_MPEG_DATA_BUFSZ, GFP_KERNEL);
  38. if (cx->vbi.sliced_mpeg_data[i] == NULL) {
  39. while (--i >= 0) {
  40. kfree(cx->vbi.sliced_mpeg_data[i]);
  41. cx->vbi.sliced_mpeg_data[i] = NULL;
  42. }
  43. cx->vbi.insert_mpeg =
  44. V4L2_MPEG_STREAM_VBI_FMT_NONE;
  45. CX18_WARN("Unable to allocate buffers for sliced VBI data insertion\n");
  46. return -ENOMEM;
  47. }
  48. }
  49. }
  50. cx->vbi.insert_mpeg = fmt;
  51. CX18_DEBUG_INFO("enabled insertion of sliced VBI data into the MPEG PS,when sliced VBI is enabled\n");
  52. /*
  53. * If our current settings have no lines set for capture, store a valid,
  54. * default set of service lines to capture, in our current settings.
  55. */
  56. if (cx18_get_service_set(cx->vbi.sliced_in) == 0) {
  57. if (cx->is_60hz)
  58. cx->vbi.sliced_in->service_set =
  59. V4L2_SLICED_CAPTION_525;
  60. else
  61. cx->vbi.sliced_in->service_set = V4L2_SLICED_WSS_625;
  62. cx18_expand_service_set(cx->vbi.sliced_in, cx->is_50hz);
  63. }
  64. return 0;
  65. }
  66. static int cx18_s_video_encoding(struct cx2341x_handler *cxhdl, u32 val)
  67. {
  68. struct cx18 *cx = container_of(cxhdl, struct cx18, cxhdl);
  69. int is_mpeg1 = val == V4L2_MPEG_VIDEO_ENCODING_MPEG_1;
  70. struct v4l2_subdev_format format = {
  71. .which = V4L2_SUBDEV_FORMAT_ACTIVE,
  72. };
  73. struct v4l2_mbus_framefmt *fmt = &format.format;
  74. /* fix videodecoder resolution */
  75. fmt->width = cxhdl->width / (is_mpeg1 ? 2 : 1);
  76. fmt->height = cxhdl->height;
  77. fmt->code = MEDIA_BUS_FMT_FIXED;
  78. v4l2_subdev_call(cx->sd_av, pad, set_fmt, NULL, &format);
  79. return 0;
  80. }
  81. static int cx18_s_audio_sampling_freq(struct cx2341x_handler *cxhdl, u32 idx)
  82. {
  83. static const u32 freqs[3] = { 44100, 48000, 32000 };
  84. struct cx18 *cx = container_of(cxhdl, struct cx18, cxhdl);
  85. /* The audio clock of the digitizer must match the codec sample
  86. rate otherwise you get some very strange effects. */
  87. if (idx < ARRAY_SIZE(freqs))
  88. cx18_call_all(cx, audio, s_clock_freq, freqs[idx]);
  89. return 0;
  90. }
  91. static int cx18_s_audio_mode(struct cx2341x_handler *cxhdl, u32 val)
  92. {
  93. struct cx18 *cx = container_of(cxhdl, struct cx18, cxhdl);
  94. cx->dualwatch_stereo_mode = val;
  95. return 0;
  96. }
  97. const struct cx2341x_handler_ops cx18_cxhdl_ops = {
  98. .s_audio_mode = cx18_s_audio_mode,
  99. .s_audio_sampling_freq = cx18_s_audio_sampling_freq,
  100. .s_video_encoding = cx18_s_video_encoding,
  101. .s_stream_vbi_fmt = cx18_s_stream_vbi_fmt,
  102. };