cx18-controls.c 3.9 KB

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