Path: blob/master/drivers/media/video/cx18/cx18-controls.c
17697 views
/*1* cx18 ioctl control functions2*3* Derived from ivtv-controls.c4*5* Copyright (C) 2007 Hans Verkuil <[email protected]>6*7* This program is free software; you can redistribute it and/or modify8* it under the terms of the GNU General Public License as published by9* the Free Software Foundation; either version 2 of the License, or10* (at your option) any later version.11*12* This program is distributed in the hope that it will be useful,13* but WITHOUT ANY WARRANTY; without even the implied warranty of14* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the15* GNU General Public License for more details.16*17* You should have received a copy of the GNU General Public License18* along with this program; if not, write to the Free Software19* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA20* 02111-1307 USA21*/22#include <linux/kernel.h>23#include <linux/slab.h>2425#include "cx18-driver.h"26#include "cx18-cards.h"27#include "cx18-ioctl.h"28#include "cx18-audio.h"29#include "cx18-mailbox.h"30#include "cx18-controls.h"3132static int cx18_s_stream_vbi_fmt(struct cx2341x_handler *cxhdl, u32 fmt)33{34struct cx18 *cx = container_of(cxhdl, struct cx18, cxhdl);35int type = cxhdl->stream_type->val;3637if (atomic_read(&cx->ana_capturing) > 0)38return -EBUSY;3940if (fmt != V4L2_MPEG_STREAM_VBI_FMT_IVTV ||41!(type == V4L2_MPEG_STREAM_TYPE_MPEG2_PS ||42type == V4L2_MPEG_STREAM_TYPE_MPEG2_DVD ||43type == V4L2_MPEG_STREAM_TYPE_MPEG2_SVCD)) {44/* Only IVTV fmt VBI insertion & only MPEG-2 PS type streams */45cx->vbi.insert_mpeg = V4L2_MPEG_STREAM_VBI_FMT_NONE;46CX18_DEBUG_INFO("disabled insertion of sliced VBI data into "47"the MPEG stream\n");48return 0;49}5051/* Allocate sliced VBI buffers if needed. */52if (cx->vbi.sliced_mpeg_data[0] == NULL) {53int i;5455for (i = 0; i < CX18_VBI_FRAMES; i++) {56cx->vbi.sliced_mpeg_data[i] =57kmalloc(CX18_SLICED_MPEG_DATA_BUFSZ, GFP_KERNEL);58if (cx->vbi.sliced_mpeg_data[i] == NULL) {59while (--i >= 0) {60kfree(cx->vbi.sliced_mpeg_data[i]);61cx->vbi.sliced_mpeg_data[i] = NULL;62}63cx->vbi.insert_mpeg =64V4L2_MPEG_STREAM_VBI_FMT_NONE;65CX18_WARN("Unable to allocate buffers for "66"sliced VBI data insertion\n");67return -ENOMEM;68}69}70}7172cx->vbi.insert_mpeg = fmt;73CX18_DEBUG_INFO("enabled insertion of sliced VBI data into the MPEG PS,"74"when sliced VBI is enabled\n");7576/*77* If our current settings have no lines set for capture, store a valid,78* default set of service lines to capture, in our current settings.79*/80if (cx18_get_service_set(cx->vbi.sliced_in) == 0) {81if (cx->is_60hz)82cx->vbi.sliced_in->service_set =83V4L2_SLICED_CAPTION_525;84else85cx->vbi.sliced_in->service_set = V4L2_SLICED_WSS_625;86cx18_expand_service_set(cx->vbi.sliced_in, cx->is_50hz);87}88return 0;89}9091static int cx18_s_video_encoding(struct cx2341x_handler *cxhdl, u32 val)92{93struct cx18 *cx = container_of(cxhdl, struct cx18, cxhdl);94int is_mpeg1 = val == V4L2_MPEG_VIDEO_ENCODING_MPEG_1;95struct v4l2_mbus_framefmt fmt;9697/* fix videodecoder resolution */98fmt.width = cxhdl->width / (is_mpeg1 ? 2 : 1);99fmt.height = cxhdl->height;100fmt.code = V4L2_MBUS_FMT_FIXED;101v4l2_subdev_call(cx->sd_av, video, s_mbus_fmt, &fmt);102return 0;103}104105static int cx18_s_audio_sampling_freq(struct cx2341x_handler *cxhdl, u32 idx)106{107static const u32 freqs[3] = { 44100, 48000, 32000 };108struct cx18 *cx = container_of(cxhdl, struct cx18, cxhdl);109110/* The audio clock of the digitizer must match the codec sample111rate otherwise you get some very strange effects. */112if (idx < ARRAY_SIZE(freqs))113cx18_call_all(cx, audio, s_clock_freq, freqs[idx]);114return 0;115}116117static int cx18_s_audio_mode(struct cx2341x_handler *cxhdl, u32 val)118{119struct cx18 *cx = container_of(cxhdl, struct cx18, cxhdl);120121cx->dualwatch_stereo_mode = val;122return 0;123}124125struct cx2341x_handler_ops cx18_cxhdl_ops = {126.s_audio_mode = cx18_s_audio_mode,127.s_audio_sampling_freq = cx18_s_audio_sampling_freq,128.s_video_encoding = cx18_s_video_encoding,129.s_stream_vbi_fmt = cx18_s_stream_vbi_fmt,130};131132133