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