1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18#include <linux/kernel.h>
19#include <linux/slab.h>
20
21#include "cx18-driver.h"
22#include "cx18-cards.h"
23#include "cx18-ioctl.h"
24#include "cx18-audio.h"
25#include "cx18-mailbox.h"
26#include "cx18-controls.h"
27
28static int cx18_s_stream_vbi_fmt(struct cx2341x_handler *cxhdl, u32 fmt)
29{
30 struct cx18 *cx = container_of(cxhdl, struct cx18, cxhdl);
31 int type = cxhdl->stream_type->val;
32
33 if (atomic_read(&cx->ana_capturing) > 0)
34 return -EBUSY;
35
36 if (fmt != V4L2_MPEG_STREAM_VBI_FMT_IVTV ||
37 !(type == V4L2_MPEG_STREAM_TYPE_MPEG2_PS ||
38 type == V4L2_MPEG_STREAM_TYPE_MPEG2_DVD ||
39 type == V4L2_MPEG_STREAM_TYPE_MPEG2_SVCD)) {
40
41 cx->vbi.insert_mpeg = V4L2_MPEG_STREAM_VBI_FMT_NONE;
42 CX18_DEBUG_INFO("disabled insertion of sliced VBI data into the MPEG stream\n");
43 return 0;
44 }
45
46
47 if (cx->vbi.sliced_mpeg_data[0] == NULL) {
48 int i;
49
50 for (i = 0; i < CX18_VBI_FRAMES; i++) {
51 cx->vbi.sliced_mpeg_data[i] =
52 kmalloc(CX18_SLICED_MPEG_DATA_BUFSZ, GFP_KERNEL);
53 if (cx->vbi.sliced_mpeg_data[i] == NULL) {
54 while (--i >= 0) {
55 kfree(cx->vbi.sliced_mpeg_data[i]);
56 cx->vbi.sliced_mpeg_data[i] = NULL;
57 }
58 cx->vbi.insert_mpeg =
59 V4L2_MPEG_STREAM_VBI_FMT_NONE;
60 CX18_WARN("Unable to allocate buffers for sliced VBI data insertion\n");
61 return -ENOMEM;
62 }
63 }
64 }
65
66 cx->vbi.insert_mpeg = fmt;
67 CX18_DEBUG_INFO("enabled insertion of sliced VBI data into the MPEG PS,when sliced VBI is enabled\n");
68
69
70
71
72
73 if (cx18_get_service_set(cx->vbi.sliced_in) == 0) {
74 if (cx->is_60hz)
75 cx->vbi.sliced_in->service_set =
76 V4L2_SLICED_CAPTION_525;
77 else
78 cx->vbi.sliced_in->service_set = V4L2_SLICED_WSS_625;
79 cx18_expand_service_set(cx->vbi.sliced_in, cx->is_50hz);
80 }
81 return 0;
82}
83
84static int cx18_s_video_encoding(struct cx2341x_handler *cxhdl, u32 val)
85{
86 struct cx18 *cx = container_of(cxhdl, struct cx18, cxhdl);
87 int is_mpeg1 = val == V4L2_MPEG_VIDEO_ENCODING_MPEG_1;
88 struct v4l2_subdev_format format = {
89 .which = V4L2_SUBDEV_FORMAT_ACTIVE,
90 };
91 struct v4l2_mbus_framefmt *fmt = &format.format;
92
93
94 fmt->width = cxhdl->width / (is_mpeg1 ? 2 : 1);
95 fmt->height = cxhdl->height;
96 fmt->code = MEDIA_BUS_FMT_FIXED;
97 v4l2_subdev_call(cx->sd_av, pad, set_fmt, NULL, &format);
98 return 0;
99}
100
101static int cx18_s_audio_sampling_freq(struct cx2341x_handler *cxhdl, u32 idx)
102{
103 static const u32 freqs[3] = { 44100, 48000, 32000 };
104 struct cx18 *cx = container_of(cxhdl, struct cx18, cxhdl);
105
106
107
108 if (idx < ARRAY_SIZE(freqs))
109 cx18_call_all(cx, audio, s_clock_freq, freqs[idx]);
110 return 0;
111}
112
113static int cx18_s_audio_mode(struct cx2341x_handler *cxhdl, u32 val)
114{
115 struct cx18 *cx = container_of(cxhdl, struct cx18, cxhdl);
116
117 cx->dualwatch_stereo_mode = val;
118 return 0;
119}
120
121const struct cx2341x_handler_ops cx18_cxhdl_ops = {
122 .s_audio_mode = cx18_s_audio_mode,
123 .s_audio_sampling_freq = cx18_s_audio_sampling_freq,
124 .s_video_encoding = cx18_s_video_encoding,
125 .s_stream_vbi_fmt = cx18_s_stream_vbi_fmt,
126};
127