/* * * $Id: pvrusb2-i2c-cmd-v4l2.c,v 1.1 2006/01/01 08:26:03 mcisely Exp $ * * Copyright (C) 2005 Mike Isely * Copyright (C) 2004 Aurelien Alleaume * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #include "pvrusb2-i2c-cmd-v4l2.h" #include "pvrusb2-hdw-internal.h" #include "pvrusb2-debug.h" #include #include static void set_standard(struct pvr2_hdw *hdw) { int cvstd = hdw->controls[PVR2_CID_VIDEOSTANDARD].value; v4l2_std_id vs; pvr2_trace(PVR2_TRACE_CHIPS, "i2c v4l2 set_standard(%d)",cvstd); switch (cvstd) { default: case PVR2_CVAL_VIDEOSTANDARD_NTSC_M: vs = V4L2_STD_NTSC_M; break; case PVR2_CVAL_VIDEOSTANDARD_SECAM_L: vs = V4L2_STD_SECAM; break; case PVR2_CVAL_VIDEOSTANDARD_PAL_BG: vs = V4L2_STD_PAL_BG; break; case PVR2_CVAL_VIDEOSTANDARD_PAL_I: vs = V4L2_STD_PAL_I; break; case PVR2_CVAL_VIDEOSTANDARD_PAL_DK: vs = V4L2_STD_PAL_DK; break; case PVR2_CVAL_VIDEOSTANDARD_PAL_M: vs = V4L2_STD_PAL_M; break; } pvr2_i2c_core_cmd(hdw,VIDIOC_S_STD,&vs); } static int check_standard(struct pvr2_hdw *hdw) { return hdw->controls[PVR2_CID_VIDEOSTANDARD].dirty != 0; } const struct pvr2_i2c_op pvr2_i2c_op_v4l2_standard = { .check = check_standard, .update = set_standard, .name = "v4l2_standard", }; static void set_bcsh(struct pvr2_hdw *hdw) { struct v4l2_control ctrl; pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 set_bcsh" " b=%d c=%d s=%d h=%d", hdw->controls[PVR2_CID_BRIGHTNESS].value, hdw->controls[PVR2_CID_CONTRAST].value, hdw->controls[PVR2_CID_SATURATION].value, hdw->controls[PVR2_CID_HUE].value); memset(&ctrl,0,sizeof(ctrl)); ctrl.id = V4L2_CID_BRIGHTNESS; ctrl.value = hdw->controls[PVR2_CID_BRIGHTNESS].value; pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl); ctrl.id = V4L2_CID_CONTRAST; ctrl.value = hdw->controls[PVR2_CID_CONTRAST].value; pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl); ctrl.id = V4L2_CID_SATURATION; ctrl.value = hdw->controls[PVR2_CID_SATURATION].value; pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl); ctrl.id = V4L2_CID_HUE; ctrl.value = hdw->controls[PVR2_CID_HUE].value; pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl); } static int check_bcsh(struct pvr2_hdw *hdw) { return (hdw->controls[PVR2_CID_BRIGHTNESS].dirty || hdw->controls[PVR2_CID_CONTRAST].dirty || hdw->controls[PVR2_CID_SATURATION].dirty || hdw->controls[PVR2_CID_HUE].dirty); } const struct pvr2_i2c_op pvr2_i2c_op_v4l2_bcsh = { .check = check_bcsh, .update = set_bcsh, .name = "v4l2_bcsh", }; static void set_volume(struct pvr2_hdw *hdw) { struct v4l2_control ctrl; pvr2_trace(PVR2_TRACE_CHIPS, "i2c v4l2 set_volume" "(vol=%d bal=%d bas=%d treb=%d mute=%d)", hdw->controls[PVR2_CID_VOLUME].value, hdw->controls[PVR2_CID_BALANCE].value, hdw->controls[PVR2_CID_BASS].value, hdw->controls[PVR2_CID_TREBLE].value, hdw->controls[PVR2_CID_MUTE].value); memset(&ctrl,0,sizeof(ctrl)); ctrl.id = V4L2_CID_AUDIO_MUTE; ctrl.value = hdw->controls[PVR2_CID_MUTE].value ? 1 : 0; pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl); ctrl.id = V4L2_CID_AUDIO_VOLUME; ctrl.value = hdw->controls[PVR2_CID_VOLUME].value; pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl); ctrl.id = V4L2_CID_AUDIO_BALANCE; ctrl.value = hdw->controls[PVR2_CID_BALANCE].value; pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl); ctrl.id = V4L2_CID_AUDIO_BASS; ctrl.value = hdw->controls[PVR2_CID_BASS].value; pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl); ctrl.id = V4L2_CID_AUDIO_TREBLE; ctrl.value = hdw->controls[PVR2_CID_TREBLE].value; pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl); } static int check_volume(struct pvr2_hdw *hdw) { return (hdw->controls[PVR2_CID_VOLUME].dirty || hdw->controls[PVR2_CID_BALANCE].dirty || hdw->controls[PVR2_CID_BASS].dirty || hdw->controls[PVR2_CID_TREBLE].dirty || hdw->controls[PVR2_CID_MUTE].dirty); } const struct pvr2_i2c_op pvr2_i2c_op_v4l2_volume = { .check = check_volume, .update = set_volume, .name = "v4l2_volume", }; static void set_frequency(struct pvr2_hdw *hdw) { unsigned long fv; struct v4l2_frequency freq; fv = hdw->controls[PVR2_CID_FREQUENCY].value; pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 set_freq(%lu)",fv); memset(&freq,0,sizeof(freq)); freq.frequency = fv / 62500; freq.tuner = 0; freq.type = V4L2_TUNER_ANALOG_TV; pvr2_i2c_core_cmd(hdw,VIDIOC_S_FREQUENCY,&freq); } static int check_frequency(struct pvr2_hdw *hdw) { return hdw->controls[PVR2_CID_FREQUENCY].dirty != 0; } const struct pvr2_i2c_op pvr2_i2c_op_v4l2_frequency = { .check = check_frequency, .update = set_frequency, .name = "v4l2_freq", }; static void set_size(struct pvr2_hdw *hdw) { struct v4l2_format fmt; memset(&fmt,0,sizeof(fmt)); fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; fmt.fmt.pix.width = hdw->controls[PVR2_CID_HRES].value; fmt.fmt.pix.height = hdw->controls[PVR2_CID_VRES].value; pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 set_size(%dx%d)", fmt.fmt.pix.width,fmt.fmt.pix.height); pvr2_i2c_core_cmd(hdw,VIDIOC_S_FMT,&fmt); } static int check_size(struct pvr2_hdw *hdw) { return (hdw->controls[PVR2_CID_HRES].dirty || hdw->controls[PVR2_CID_VRES].dirty); } const struct pvr2_i2c_op pvr2_i2c_op_v4l2_size = { .check = check_size, .update = set_size, .name = "v4l2_size", }; /* Stuff for Emacs to see, in order to encourage consistent editing style: *** Local Variables: *** *** mode: c *** *** fill-column: 70 *** *** tab-width: 8 *** *** c-basic-offset: 8 *** *** End: *** */