Lines Matching +full:standard +full:- +full:vt
1 // SPDX-License-Identifier: GPL-2.0-only
10 #include "pvrusb2-context.h"
11 #include "pvrusb2-hdw.h"
13 #include "pvrusb2-debug.h"
14 #include "pvrusb2-v4l2.h"
15 #include "pvrusb2-ioread.h"
18 #include <media/v4l2-dev.h>
19 #include <media/v4l2-device.h>
20 #include <media/v4l2-fh.h>
21 #include <media/v4l2-common.h>
22 #include <media/v4l2-ioctl.h>
35 enum pvr2_v4l_type minor_type; /* pvr2-understood minor device type */
54 /* streams - Note that these must be separately, individually,
56 * manage their deletion - separately, individually... */
61 static int video_nr[PVR_NUM] = {[0 ... PVR_NUM-1] = -1};
64 static int radio_nr[PVR_NUM] = {[0 ... PVR_NUM-1] = -1};
67 static int vbi_nr[PVR_NUM] = {[0 ... PVR_NUM-1] = -1};
111 struct pvr2_v4l2_fh *fh = file->private_data;
112 struct pvr2_hdw *hdw = fh->channel.mc_head->hdw;
114 strscpy(cap->driver, "pvrusb2", sizeof(cap->driver));
115 strscpy(cap->bus_info, pvr2_hdw_get_bus_info(hdw),
116 sizeof(cap->bus_info));
117 strscpy(cap->card, pvr2_hdw_get_desc(hdw), sizeof(cap->card));
118 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_TUNER |
126 struct pvr2_v4l2_fh *fh = file->private_data;
127 struct pvr2_hdw *hdw = fh->channel.mc_head->hdw;
139 struct pvr2_v4l2_fh *fh = file->private_data;
140 struct pvr2_hdw *hdw = fh->channel.mc_head->hdw;
151 struct pvr2_v4l2_fh *fh = file->private_data;
152 struct pvr2_hdw *hdw = fh->channel.mc_head->hdw;
164 struct pvr2_v4l2_fh *fh = file->private_data;
165 struct pvr2_hdw *hdw = fh->channel.mc_head->hdw;
174 tmp.index = vi->index;
175 if (vi->index >= fh->input_cnt)
176 return -EINVAL;
177 val = fh->input_map[vi->index];
189 return -EINVAL;
194 tmp.name, sizeof(tmp.name) - 1, &cnt);
202 sense in cases where a device might be multi-standard.
204 standard, but it can change over time. For now just
212 struct pvr2_v4l2_fh *fh = file->private_data;
213 struct pvr2_hdw *hdw = fh->channel.mc_head->hdw;
223 for (idx = 0; idx < fh->input_cnt; idx++) {
224 if (fh->input_map[idx] == val) {
234 struct pvr2_v4l2_fh *fh = file->private_data;
235 struct pvr2_hdw *hdw = fh->channel.mc_head->hdw;
238 if (inp >= fh->input_cnt)
239 return -EINVAL;
242 fh->input_map[inp]);
259 up with a more standard way to say "we have inputs but we
264 if (vin->index > 0)
265 return -EINVAL;
266 strscpy(vin->name, "PVRUSB2 Audio", sizeof(vin->name));
267 vin->capability = V4L2_AUDCAP_STEREO;
274 vin->index = 0;
275 strscpy(vin->name, "PVRUSB2 Audio", sizeof(vin->name));
276 vin->capability = V4L2_AUDCAP_STEREO;
282 if (vout->index)
283 return -EINVAL;
287 static int pvr2_g_tuner(struct file *file, void *priv, struct v4l2_tuner *vt)
289 struct pvr2_v4l2_fh *fh = file->private_data;
290 struct pvr2_hdw *hdw = fh->channel.mc_head->hdw;
292 if (vt->index != 0)
293 return -EINVAL; /* Only answer for the 1st tuner */
296 return pvr2_hdw_get_tuner_status(hdw, vt);
299 static int pvr2_s_tuner(struct file *file, void *priv, const struct v4l2_tuner *vt)
301 struct pvr2_v4l2_fh *fh = file->private_data;
302 struct pvr2_hdw *hdw = fh->channel.mc_head->hdw;
305 if (vt->index != 0)
306 return -EINVAL;
310 vt->audmode);
317 struct pvr2_v4l2_fh *fh = file->private_data;
318 struct pvr2_hdw *hdw = fh->channel.mc_head->hdw;
320 struct v4l2_tuner vt;
325 ret = pvr2_hdw_get_tuner_status(hdw, &vt);
332 if (vf->type == V4L2_TUNER_RADIO) {
339 fv = vf->frequency;
340 if (vt.capability & V4L2_TUNER_CAP_LOW)
352 struct pvr2_v4l2_fh *fh = file->private_data;
353 struct pvr2_hdw *hdw = fh->channel.mc_head->hdw;
356 struct v4l2_tuner vt;
359 ret = pvr2_hdw_get_tuner_status(hdw, &vt);
371 vf->type = V4L2_TUNER_RADIO;
373 vf->type = V4L2_TUNER_ANALOG_TV;
374 if (vt.capability & V4L2_TUNER_CAP_LOW)
378 vf->frequency = val;
385 if (fd->index)
386 return -EINVAL;
388 fd->pixelformat = V4L2_PIX_FMT_MPEG;
394 struct pvr2_v4l2_fh *fh = file->private_data;
395 struct pvr2_hdw *hdw = fh->channel.mc_head->hdw;
403 vf->fmt.pix.width = val;
408 vf->fmt.pix.height = val;
414 struct pvr2_v4l2_fh *fh = file->private_data;
415 struct pvr2_hdw *hdw = fh->channel.mc_head->hdw;
418 int h = vf->fmt.pix.height;
419 int w = vf->fmt.pix.width;
427 if (w == -1)
436 if (h == -1)
445 vf->fmt.pix.width = w;
446 vf->fmt.pix.height = h;
452 struct pvr2_v4l2_fh *fh = file->private_data;
453 struct pvr2_hdw *hdw = fh->channel.mc_head->hdw;
461 pvr2_ctrl_set_value(hcp, vf->fmt.pix.width);
462 pvr2_ctrl_set_value(vcp, vf->fmt.pix.height);
469 struct pvr2_v4l2_fh *fh = file->private_data;
470 struct pvr2_hdw *hdw = fh->channel.mc_head->hdw;
471 struct pvr2_v4l2_dev *pdi = fh->pdi;
474 if (!fh->pdi->stream) {
478 return -EPERM;
480 ret = pvr2_hdw_set_stream_type(hdw, pdi->config);
488 struct pvr2_v4l2_fh *fh = file->private_data;
489 struct pvr2_hdw *hdw = fh->channel.mc_head->hdw;
491 if (!fh->pdi->stream) {
495 return -EPERM;
503 struct pvr2_v4l2_fh *fh = file->private_data;
504 struct pvr2_hdw *hdw = fh->channel.mc_head->hdw;
508 if (vc->id & V4L2_CTRL_FLAG_NEXT_CTRL) {
510 hdw, (vc->id & ~V4L2_CTRL_FLAG_NEXT_CTRL));
512 vc->id = pvr2_ctrl_get_v4lid(cptr);
514 cptr = pvr2_hdw_get_ctrl_v4l(hdw, vc->id);
519 vc->id);
520 return -EINVAL;
525 vc->id, pvr2_ctrl_get_name(cptr),
527 strscpy(vc->name, pvr2_ctrl_get_desc(cptr), sizeof(vc->name));
528 vc->flags = pvr2_ctrl_get_v4lflags(cptr);
530 vc->default_value = val;
531 vc->nr_of_dims = 0;
532 vc->elems = 1;
533 vc->elem_size = 4;
536 vc->type = V4L2_CTRL_TYPE_MENU;
537 vc->minimum = 0;
538 vc->maximum = pvr2_ctrl_get_cnt(cptr) - 1;
539 vc->step = 1;
542 vc->type = V4L2_CTRL_TYPE_BOOLEAN;
543 vc->minimum = 0;
544 vc->maximum = 1;
545 vc->step = 1;
548 vc->type = V4L2_CTRL_TYPE_INTEGER;
549 vc->minimum = pvr2_ctrl_get_min(cptr);
550 vc->maximum = pvr2_ctrl_get_max(cptr);
551 vc->step = 1;
556 vc->id, pvr2_ctrl_get_name(cptr));
557 return -EINVAL;
564 struct pvr2_v4l2_fh *fh = file->private_data;
565 struct pvr2_hdw *hdw = fh->channel.mc_head->hdw;
569 ret = pvr2_ctrl_get_valname(pvr2_hdw_get_ctrl_v4l(hdw, vm->id),
570 vm->index,
571 vm->name, sizeof(vm->name) - 1,
573 vm->name[cnt] = 0;
580 struct pvr2_v4l2_fh *fh = file->private_data;
581 struct pvr2_hdw *hdw = fh->channel.mc_head->hdw;
589 for (idx = 0; idx < ctls->count; idx++) {
590 ctrl = ctls->controls + idx;
591 cptr = pvr2_hdw_get_ctrl_v4l(hdw, ctrl->id);
593 if (ctls->which == V4L2_CTRL_WHICH_DEF_VAL)
598 ret = -EINVAL;
601 ctls->error_idx = idx;
606 ctrl->value64 = 0;
607 ctrl->value = val;
615 struct pvr2_v4l2_fh *fh = file->private_data;
616 struct pvr2_hdw *hdw = fh->channel.mc_head->hdw;
622 for (idx = 0; idx < ctls->count; idx++) {
623 ctrl = ctls->controls + idx;
625 pvr2_hdw_get_ctrl_v4l(hdw, ctrl->id),
626 ctrl->value);
628 ctls->error_idx = idx;
640 struct pvr2_v4l2_fh *fh = file->private_data;
641 struct pvr2_hdw *hdw = fh->channel.mc_head->hdw;
648 for (idx = 0; idx < ctls->count; idx++) {
649 ctrl = ctls->controls + idx;
650 pctl = pvr2_hdw_get_ctrl_v4l(hdw, ctrl->id);
652 ctls->error_idx = idx;
653 return -EINVAL;
662 struct pvr2_v4l2_fh *fh = file->private_data;
663 struct pvr2_hdw *hdw = fh->channel.mc_head->hdw;
668 return -EINVAL;
678 struct pvr2_v4l2_fh *fh = file->private_data;
679 struct pvr2_hdw *hdw = fh->channel.mc_head->hdw;
684 if (sel->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
685 return -EINVAL;
689 switch (sel->target) {
694 return -EINVAL;
695 sel->r.left = val;
699 return -EINVAL;
700 sel->r.top = val;
704 return -EINVAL;
705 sel->r.width = val;
709 return -EINVAL;
710 sel->r.height = val;
714 sel->r = cap.defrect;
718 sel->r = cap.bounds;
721 return -EINVAL;
729 struct pvr2_v4l2_fh *fh = file->private_data;
730 struct pvr2_hdw *hdw = fh->channel.mc_head->hdw;
733 if (sel->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
734 sel->target != V4L2_SEL_TGT_CROP)
735 return -EINVAL;
738 sel->r.left);
743 sel->r.top);
748 sel->r.width);
753 sel->r.height);
761 struct pvr2_v4l2_fh *fh = file->private_data;
762 struct pvr2_hdw *hdw = fh->channel.mc_head->hdw;
802 struct pvr2_hdw *hdw = dip->v4lp->channel.mc_head->hdw;
803 enum pvr2_config cfg = dip->config;
810 mcnt = scnprintf(msg, sizeof(msg) - 1,
812 video_device_node_name(&dip->devbase),
816 pvr2_hdw_v4l_store_minor_number(hdw,dip->minor_type,-1);
819 dip->v4lp = NULL;
820 dip->stream = NULL;
824 video_unregister_device(&dip->devbase);
834 if (!dip->devbase.v4l2_dev->dev) return;
835 dip->devbase.v4l2_dev->dev = NULL;
836 device_move(&dip->devbase.dev, NULL, DPM_ORDER_NONE);
842 if (vp->dev_video) {
843 pvr2_v4l2_dev_destroy(vp->dev_video);
844 vp->dev_video = NULL;
846 if (vp->dev_radio) {
847 pvr2_v4l2_dev_destroy(vp->dev_radio);
848 vp->dev_radio = NULL;
852 pvr2_channel_done(&vp->channel);
869 if (!vp->channel.mc_head->disconnect_flag) return;
870 pvr2_v4l2_dev_disassociate_parent(vp->dev_video);
871 pvr2_v4l2_dev_disassociate_parent(vp->dev_radio);
872 if (!list_empty(&vp->dev_video->devbase.fh_list) ||
873 (vp->dev_radio &&
874 !list_empty(&vp->dev_radio->devbase.fh_list))) {
876 "pvr2_v4l2 internal_check exit-empty id=%p", vp);
885 struct pvr2_v4l2_fh *fhp = file->private_data;
886 struct pvr2_v4l2 *vp = fhp->pdi->v4lp;
887 struct pvr2_hdw *hdw = fhp->channel.mc_head->hdw;
891 if (fhp->rhp) {
894 sp = pvr2_ioread_get_stream(fhp->rhp);
896 pvr2_ioread_destroy(fhp->rhp);
897 fhp->rhp = NULL;
900 v4l2_fh_del(&fhp->fh);
901 v4l2_fh_exit(&fhp->fh);
902 file->private_data = NULL;
904 pvr2_channel_done(&fhp->channel);
907 if (fhp->input_map) {
908 kfree(fhp->input_map);
909 fhp->input_map = NULL;
912 if (vp->channel.mc_head->disconnect_flag &&
913 list_empty(&vp->dev_video->devbase.fh_list) &&
914 (!vp->dev_radio ||
915 list_empty(&vp->dev_radio->devbase.fh_list))) {
934 vp = dip->v4lp;
935 hdw = vp->channel.hdw;
942 return -EIO;
947 return -ENOMEM;
950 v4l2_fh_init(&fhp->fh, &dip->devbase);
951 init_waitqueue_head(&fhp->wait_data);
952 fhp->pdi = dip;
955 pvr2_channel_init(&fhp->channel,vp->channel.mc_head);
957 if (dip->v4l_type == VFL_TYPE_RADIO) {
969 ret = pvr2_channel_limit_inputs(&fhp->channel,input_mask);
971 pvr2_channel_done(&fhp->channel);
975 v4l2_fh_exit(&fhp->fh);
985 fhp->input_cnt = input_cnt;
986 fhp->input_map = kzalloc(input_cnt,GFP_KERNEL);
987 if (!fhp->input_map) {
988 pvr2_channel_done(&fhp->channel);
992 v4l2_fh_exit(&fhp->fh);
994 return -ENOMEM;
999 fhp->input_map[input_cnt++] = idx;
1002 fhp->file = file;
1003 file->private_data = fhp;
1005 fhp->fw_mode_flag = pvr2_hdw_cpufw_get_enabled(hdw);
1006 v4l2_fh_add(&fhp->fh);
1016 wake_up(&fhp->wait_data);
1024 if (fh->rhp) return 0;
1026 if (!fh->pdi->stream) {
1029 return -EPERM;
1034 if ((ret = pvr2_channel_claim_stream(&fh->channel,
1035 fh->pdi->stream)) != 0) {
1040 fh->rhp = pvr2_channel_create_mpeg_stream(fh->pdi->stream);
1041 if (!fh->rhp) {
1042 pvr2_channel_claim_stream(&fh->channel,NULL);
1043 return -ENOMEM;
1046 hdw = fh->channel.mc_head->hdw;
1047 sp = fh->pdi->stream->stream;
1049 pvr2_hdw_set_stream_type(hdw,fh->pdi->config);
1051 return pvr2_ioread_set_enabled(fh->rhp,!0);
1058 struct pvr2_v4l2_fh *fh = file->private_data;
1061 if (fh->fw_mode_flag) {
1062 struct pvr2_hdw *hdw = fh->channel.mc_head->hdw;
1069 if (!tbuf) return -ENOMEM;
1081 tcnt = -EFAULT;
1087 count -= c2;
1094 if (!fh->rhp) {
1102 ret = pvr2_ioread_read(fh->rhp,buff,count);
1104 if (ret != -EAGAIN) break;
1105 if (file->f_flags & O_NONBLOCK) break;
1108 fh->wait_data,
1109 pvr2_ioread_avail(fh->rhp) >= 0);
1120 struct pvr2_v4l2_fh *fh = file->private_data;
1123 if (fh->fw_mode_flag) {
1128 if (!fh->rhp) {
1133 poll_wait(file,&fh->wait_data,wait);
1135 if (pvr2_ioread_avail(fh->rhp) >= 0) {
1168 dip->v4lp = vp;
1170 hdw = vp->channel.mc_head->hdw;
1171 dip->v4l_type = v4l_type;
1174 dip->stream = &vp->channel.mc_head->video_stream;
1175 dip->config = pvr2_config_mpeg;
1176 dip->minor_type = pvr2_v4l_type_video;
1181 dip->config = pvr2_config_vbi;
1182 dip->minor_type = pvr2_v4l_type_vbi;
1187 dip->stream = &vp->channel.mc_head->video_stream;
1188 dip->config = pvr2_config_mpeg;
1189 dip->minor_type = pvr2_v4l_type_radio;
1199 dip->devbase = vdev_template;
1200 dip->devbase.release = pvr2_video_device_release;
1201 dip->devbase.ioctl_ops = &pvr2_ioctl_ops;
1202 dip->devbase.device_caps = caps;
1208 dip->devbase.tvnorms = (v4l2_std_id)val;
1211 mindevnum = -1;
1216 pvr2_hdw_set_v4l2_dev(hdw, &dip->devbase);
1217 if ((video_register_device(&dip->devbase,
1218 dip->v4l_type, mindevnum) < 0) &&
1219 (video_register_device(&dip->devbase,
1220 dip->v4l_type, -1) < 0)) {
1226 video_device_node_name(&dip->devbase),
1227 pvr2_config_get_name(dip->config));
1230 dip->minor_type,dip->devbase.minor);
1240 pvr2_channel_init(&vp->channel,mnp);
1243 vp->channel.check_func = pvr2_v4l2_internal_check;
1246 vp->dev_video = kzalloc(sizeof(*vp->dev_video),GFP_KERNEL);
1247 if (!vp->dev_video) goto fail;
1248 pvr2_v4l2_dev_init(vp->dev_video,vp,VFL_TYPE_VIDEO);
1249 if (pvr2_hdw_get_input_available(vp->channel.mc_head->hdw) &
1251 vp->dev_radio = kzalloc(sizeof(*vp->dev_radio),GFP_KERNEL);
1252 if (!vp->dev_radio) goto fail;
1253 pvr2_v4l2_dev_init(vp->dev_radio,vp,VFL_TYPE_RADIO);