Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003     ioctl control functions
0004     Copyright (C) 2003-2004  Kevin Thayer <nufan_wfk at yahoo.com>
0005     Copyright (C) 2005-2007  Hans Verkuil <hverkuil@xs4all.nl>
0006 
0007  */
0008 
0009 #include "ivtv-driver.h"
0010 #include "ivtv-ioctl.h"
0011 #include "ivtv-controls.h"
0012 #include "ivtv-mailbox.h"
0013 
0014 static int ivtv_s_stream_vbi_fmt(struct cx2341x_handler *cxhdl, u32 fmt)
0015 {
0016     struct ivtv *itv = container_of(cxhdl, struct ivtv, cxhdl);
0017 
0018     /* First try to allocate sliced VBI buffers if needed. */
0019     if (fmt && itv->vbi.sliced_mpeg_data[0] == NULL) {
0020         int i;
0021 
0022         for (i = 0; i < IVTV_VBI_FRAMES; i++) {
0023             /* Yuck, hardcoded. Needs to be a define */
0024             itv->vbi.sliced_mpeg_data[i] = kmalloc(2049, GFP_KERNEL);
0025             if (itv->vbi.sliced_mpeg_data[i] == NULL) {
0026                 while (--i >= 0) {
0027                     kfree(itv->vbi.sliced_mpeg_data[i]);
0028                     itv->vbi.sliced_mpeg_data[i] = NULL;
0029                 }
0030                 return -ENOMEM;
0031             }
0032         }
0033     }
0034 
0035     itv->vbi.insert_mpeg = fmt;
0036 
0037     if (itv->vbi.insert_mpeg == 0) {
0038         return 0;
0039     }
0040     /* Need sliced data for mpeg insertion */
0041     if (ivtv_get_service_set(itv->vbi.sliced_in) == 0) {
0042         if (itv->is_60hz)
0043             itv->vbi.sliced_in->service_set = V4L2_SLICED_CAPTION_525;
0044         else
0045             itv->vbi.sliced_in->service_set = V4L2_SLICED_WSS_625;
0046         ivtv_expand_service_set(itv->vbi.sliced_in, itv->is_50hz);
0047     }
0048     return 0;
0049 }
0050 
0051 static int ivtv_s_video_encoding(struct cx2341x_handler *cxhdl, u32 val)
0052 {
0053     struct ivtv *itv = container_of(cxhdl, struct ivtv, cxhdl);
0054     int is_mpeg1 = val == V4L2_MPEG_VIDEO_ENCODING_MPEG_1;
0055     struct v4l2_subdev_format format = {
0056         .which = V4L2_SUBDEV_FORMAT_ACTIVE,
0057     };
0058 
0059     /* fix videodecoder resolution */
0060     format.format.width = cxhdl->width / (is_mpeg1 ? 2 : 1);
0061     format.format.height = cxhdl->height;
0062     format.format.code = MEDIA_BUS_FMT_FIXED;
0063     v4l2_subdev_call(itv->sd_video, pad, set_fmt, NULL, &format);
0064     return 0;
0065 }
0066 
0067 static int ivtv_s_audio_sampling_freq(struct cx2341x_handler *cxhdl, u32 idx)
0068 {
0069     static const u32 freqs[3] = { 44100, 48000, 32000 };
0070     struct ivtv *itv = container_of(cxhdl, struct ivtv, cxhdl);
0071 
0072     /* The audio clock of the digitizer must match the codec sample
0073        rate otherwise you get some very strange effects. */
0074     if (idx < ARRAY_SIZE(freqs))
0075         ivtv_call_all(itv, audio, s_clock_freq, freqs[idx]);
0076     return 0;
0077 }
0078 
0079 static int ivtv_s_audio_mode(struct cx2341x_handler *cxhdl, u32 val)
0080 {
0081     struct ivtv *itv = container_of(cxhdl, struct ivtv, cxhdl);
0082 
0083     itv->dualwatch_stereo_mode = val;
0084     return 0;
0085 }
0086 
0087 const struct cx2341x_handler_ops ivtv_cxhdl_ops = {
0088     .s_audio_mode = ivtv_s_audio_mode,
0089     .s_audio_sampling_freq = ivtv_s_audio_sampling_freq,
0090     .s_video_encoding = ivtv_s_video_encoding,
0091     .s_stream_vbi_fmt = ivtv_s_stream_vbi_fmt,
0092 };
0093 
0094 int ivtv_g_pts_frame(struct ivtv *itv, s64 *pts, s64 *frame)
0095 {
0096     u32 data[CX2341X_MBOX_MAX_DATA];
0097 
0098     if (test_bit(IVTV_F_I_VALID_DEC_TIMINGS, &itv->i_flags)) {
0099         *pts = (s64)((u64)itv->last_dec_timing[2] << 32) |
0100             (u64)itv->last_dec_timing[1];
0101         *frame = itv->last_dec_timing[0];
0102         return 0;
0103     }
0104     *pts = 0;
0105     *frame = 0;
0106     if (atomic_read(&itv->decoding)) {
0107         if (ivtv_api(itv, CX2341X_DEC_GET_TIMING_INFO, 5, data)) {
0108             IVTV_DEBUG_WARN("GET_TIMING: couldn't read clock\n");
0109             return -EIO;
0110         }
0111         memcpy(itv->last_dec_timing, data, sizeof(itv->last_dec_timing));
0112         set_bit(IVTV_F_I_VALID_DEC_TIMINGS, &itv->i_flags);
0113         *pts = (s64)((u64) data[2] << 32) | (u64) data[1];
0114         *frame = data[0];
0115         /*timing->scr = (u64) (((u64) data[4] << 32) | (u64) (data[3]));*/
0116     }
0117     return 0;
0118 }
0119 
0120 static int ivtv_g_volatile_ctrl(struct v4l2_ctrl *ctrl)
0121 {
0122     struct ivtv *itv = container_of(ctrl->handler, struct ivtv, cxhdl.hdl);
0123 
0124     switch (ctrl->id) {
0125     /* V4L2_CID_MPEG_VIDEO_DEC_PTS and V4L2_CID_MPEG_VIDEO_DEC_FRAME
0126        control cluster */
0127     case V4L2_CID_MPEG_VIDEO_DEC_PTS:
0128         return ivtv_g_pts_frame(itv, itv->ctrl_pts->p_new.p_s64,
0129                          itv->ctrl_frame->p_new.p_s64);
0130     }
0131     return 0;
0132 }
0133 
0134 static int ivtv_s_ctrl(struct v4l2_ctrl *ctrl)
0135 {
0136     struct ivtv *itv = container_of(ctrl->handler, struct ivtv, cxhdl.hdl);
0137 
0138     switch (ctrl->id) {
0139     /* V4L2_CID_MPEG_AUDIO_DEC_PLAYBACK and MULTILINGUAL_PLAYBACK
0140        control cluster */
0141     case V4L2_CID_MPEG_AUDIO_DEC_PLAYBACK:
0142         itv->audio_stereo_mode = itv->ctrl_audio_playback->val - 1;
0143         itv->audio_bilingual_mode = itv->ctrl_audio_multilingual_playback->val - 1;
0144         ivtv_vapi(itv, CX2341X_DEC_SET_AUDIO_MODE, 2, itv->audio_bilingual_mode, itv->audio_stereo_mode);
0145         break;
0146     }
0147     return 0;
0148 }
0149 
0150 const struct v4l2_ctrl_ops ivtv_hdl_out_ops = {
0151     .s_ctrl = ivtv_s_ctrl,
0152     .g_volatile_ctrl = ivtv_g_volatile_ctrl,
0153 };