Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 1 | /* |
| 2 | * |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2005 Mike Isely <isely@pobox.com> |
| 5 | * Copyright (C) 2004 Aurelien Alleaume <slts@free.fr> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 16 | */ |
| 17 | |
| 18 | #include <linux/kernel.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 19 | #include <linux/slab.h> |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 20 | #include "pvrusb2-context.h" |
| 21 | #include "pvrusb2-hdw.h" |
| 22 | #include "pvrusb2.h" |
| 23 | #include "pvrusb2-debug.h" |
| 24 | #include "pvrusb2-v4l2.h" |
| 25 | #include "pvrusb2-ioread.h" |
| 26 | #include <linux/videodev2.h> |
Paul Gortmaker | 7a707b8 | 2011-07-03 14:03:12 -0400 | [diff] [blame] | 27 | #include <linux/module.h> |
Mike Isely | 43e0602 | 2006-09-23 23:47:50 -0300 | [diff] [blame] | 28 | #include <media/v4l2-dev.h> |
Hans Verkuil | a28fbd0 | 2013-06-10 09:16:25 -0300 | [diff] [blame] | 29 | #include <media/v4l2-device.h> |
Hans Verkuil | cee05cb | 2015-02-03 10:46:55 -0300 | [diff] [blame] | 30 | #include <media/v4l2-fh.h> |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 31 | #include <media/v4l2-common.h> |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 32 | #include <media/v4l2-ioctl.h> |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 33 | |
| 34 | struct pvr2_v4l2_dev; |
| 35 | struct pvr2_v4l2_fh; |
| 36 | struct pvr2_v4l2; |
| 37 | |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 38 | struct pvr2_v4l2_dev { |
Mike Isely | 7591005 | 2006-09-23 22:30:50 -0300 | [diff] [blame] | 39 | struct video_device devbase; /* MUST be first! */ |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 40 | struct pvr2_v4l2 *v4lp; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 41 | struct pvr2_context_stream *stream; |
Mike Isely | 16eb40d | 2006-12-30 18:27:32 -0300 | [diff] [blame] | 42 | /* Information about this device: */ |
| 43 | enum pvr2_config config; /* Expected stream format */ |
| 44 | int v4l_type; /* V4L defined type for this device node */ |
| 45 | enum pvr2_v4l_type minor_type; /* pvr2-understood minor device type */ |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 46 | }; |
| 47 | |
| 48 | struct pvr2_v4l2_fh { |
Hans Verkuil | cee05cb | 2015-02-03 10:46:55 -0300 | [diff] [blame] | 49 | struct v4l2_fh fh; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 50 | struct pvr2_channel channel; |
Joe Perches | 108bdd7 | 2010-04-05 16:05:39 -0300 | [diff] [blame] | 51 | struct pvr2_v4l2_dev *pdi; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 52 | struct pvr2_ioread *rhp; |
| 53 | struct file *file; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 54 | wait_queue_head_t wait_data; |
| 55 | int fw_mode_flag; |
Mike Isely | e57b1c8 | 2008-04-21 03:52:34 -0300 | [diff] [blame] | 56 | /* Map contiguous ordinal value to input id */ |
| 57 | unsigned char *input_map; |
| 58 | unsigned int input_cnt; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 59 | }; |
| 60 | |
| 61 | struct pvr2_v4l2 { |
| 62 | struct pvr2_channel channel; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 63 | |
Mike Isely | 0f0f257b | 2006-12-27 23:19:42 -0300 | [diff] [blame] | 64 | /* streams - Note that these must be separately, individually, |
| 65 | * allocated pointers. This is because the v4l core is going to |
| 66 | * manage their deletion - separately, individually... */ |
| 67 | struct pvr2_v4l2_dev *dev_video; |
| 68 | struct pvr2_v4l2_dev *dev_radio; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 69 | }; |
| 70 | |
| 71 | static int video_nr[PVR_NUM] = {[0 ... PVR_NUM-1] = -1}; |
| 72 | module_param_array(video_nr, int, NULL, 0444); |
Mike Isely | 5e6862c | 2006-12-27 23:17:26 -0300 | [diff] [blame] | 73 | MODULE_PARM_DESC(video_nr, "Offset for device's video dev minor"); |
| 74 | static int radio_nr[PVR_NUM] = {[0 ... PVR_NUM-1] = -1}; |
| 75 | module_param_array(radio_nr, int, NULL, 0444); |
| 76 | MODULE_PARM_DESC(radio_nr, "Offset for device's radio dev minor"); |
| 77 | static int vbi_nr[PVR_NUM] = {[0 ... PVR_NUM-1] = -1}; |
| 78 | module_param_array(vbi_nr, int, NULL, 0444); |
| 79 | MODULE_PARM_DESC(vbi_nr, "Offset for device's vbi dev minor"); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 80 | |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 81 | #define PVR_FORMAT_PIX 0 |
| 82 | #define PVR_FORMAT_VBI 1 |
| 83 | |
Adrian Bunk | 07e337e | 2006-06-30 11:30:20 -0300 | [diff] [blame] | 84 | static struct v4l2_format pvr_format [] = { |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 85 | [PVR_FORMAT_PIX] = { |
| 86 | .type = V4L2_BUF_TYPE_VIDEO_CAPTURE, |
| 87 | .fmt = { |
| 88 | .pix = { |
| 89 | .width = 720, |
Hans Verkuil | c4b72ee | 2017-12-13 18:44:42 -0500 | [diff] [blame] | 90 | .height = 576, |
| 91 | .pixelformat = V4L2_PIX_FMT_MPEG, |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 92 | .field = V4L2_FIELD_INTERLACED, |
Hans Verkuil | c4b72ee | 2017-12-13 18:44:42 -0500 | [diff] [blame] | 93 | /* FIXME : Don't know what to put here... */ |
| 94 | .sizeimage = 32 * 1024, |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 95 | } |
| 96 | } |
| 97 | }, |
| 98 | [PVR_FORMAT_VBI] = { |
| 99 | .type = V4L2_BUF_TYPE_VBI_CAPTURE, |
| 100 | .fmt = { |
| 101 | .vbi = { |
| 102 | .sampling_rate = 27000000, |
| 103 | .offset = 248, |
| 104 | .samples_per_line = 1443, |
| 105 | .sample_format = V4L2_PIX_FMT_GREY, |
| 106 | .start = { 0, 0 }, |
| 107 | .count = { 0, 0 }, |
| 108 | .flags = 0, |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 109 | } |
| 110 | } |
| 111 | } |
| 112 | }; |
| 113 | |
Mike Isely | 16eb40d | 2006-12-30 18:27:32 -0300 | [diff] [blame] | 114 | |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 115 | |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 116 | /* |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 117 | * This is part of Video 4 Linux API. These procedures handle ioctl() calls. |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 118 | */ |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 119 | static int pvr2_querycap(struct file *file, void *priv, struct v4l2_capability *cap) |
| 120 | { |
| 121 | struct pvr2_v4l2_fh *fh = file->private_data; |
| 122 | struct pvr2_hdw *hdw = fh->channel.mc_head->hdw; |
| 123 | |
Mauro Carvalho Chehab | c0decac | 2018-09-10 08:19:14 -0400 | [diff] [blame] | 124 | strscpy(cap->driver, "pvrusb2", sizeof(cap->driver)); |
| 125 | strscpy(cap->bus_info, pvr2_hdw_get_bus_info(hdw), |
| 126 | sizeof(cap->bus_info)); |
| 127 | strscpy(cap->card, pvr2_hdw_get_desc(hdw), sizeof(cap->card)); |
Hans Verkuil | 42639f6 | 2015-01-19 06:23:26 -0300 | [diff] [blame] | 128 | cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_TUNER | |
| 129 | V4L2_CAP_AUDIO | V4L2_CAP_RADIO | |
| 130 | V4L2_CAP_READWRITE | V4L2_CAP_DEVICE_CAPS; |
| 131 | switch (fh->pdi->devbase.vfl_type) { |
| 132 | case VFL_TYPE_GRABBER: |
| 133 | cap->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_AUDIO; |
| 134 | break; |
| 135 | case VFL_TYPE_RADIO: |
| 136 | cap->device_caps = V4L2_CAP_RADIO; |
| 137 | break; |
Mauro Carvalho Chehab | 4839c58 | 2017-09-28 18:39:32 -0400 | [diff] [blame] | 138 | default: |
| 139 | return -EINVAL; |
Hans Verkuil | 42639f6 | 2015-01-19 06:23:26 -0300 | [diff] [blame] | 140 | } |
| 141 | cap->device_caps |= V4L2_CAP_TUNER | V4L2_CAP_READWRITE; |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 142 | return 0; |
| 143 | } |
| 144 | |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 145 | static int pvr2_g_std(struct file *file, void *priv, v4l2_std_id *std) |
| 146 | { |
| 147 | struct pvr2_v4l2_fh *fh = file->private_data; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 148 | struct pvr2_hdw *hdw = fh->channel.mc_head->hdw; |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 149 | int val = 0; |
| 150 | int ret; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 151 | |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 152 | ret = pvr2_ctrl_get_value( |
| 153 | pvr2_hdw_get_ctrl_by_id(hdw, PVR2_CID_STDCUR), &val); |
| 154 | *std = val; |
| 155 | return ret; |
| 156 | } |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 157 | |
Hans Verkuil | 314527a | 2013-03-15 06:10:40 -0300 | [diff] [blame] | 158 | static int pvr2_s_std(struct file *file, void *priv, v4l2_std_id std) |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 159 | { |
| 160 | struct pvr2_v4l2_fh *fh = file->private_data; |
| 161 | struct pvr2_hdw *hdw = fh->channel.mc_head->hdw; |
Hans Verkuil | eba09b5 | 2018-05-24 16:35:01 -0400 | [diff] [blame] | 162 | int ret; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 163 | |
Hans Verkuil | eba09b5 | 2018-05-24 16:35:01 -0400 | [diff] [blame] | 164 | ret = pvr2_ctrl_set_value( |
Hans Verkuil | 314527a | 2013-03-15 06:10:40 -0300 | [diff] [blame] | 165 | pvr2_hdw_get_ctrl_by_id(hdw, PVR2_CID_STDCUR), std); |
Hans Verkuil | eba09b5 | 2018-05-24 16:35:01 -0400 | [diff] [blame] | 166 | pvr2_hdw_commit_ctl(hdw); |
| 167 | return ret; |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 168 | } |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 169 | |
Mike Isely | 0927ee6 | 2012-02-20 02:26:06 -0300 | [diff] [blame] | 170 | static int pvr2_querystd(struct file *file, void *priv, v4l2_std_id *std) |
| 171 | { |
| 172 | struct pvr2_v4l2_fh *fh = file->private_data; |
| 173 | struct pvr2_hdw *hdw = fh->channel.mc_head->hdw; |
Mike Isely | ac04d00 | 2012-02-20 02:28:56 -0300 | [diff] [blame] | 174 | int val = 0; |
| 175 | int ret; |
Mike Isely | 0927ee6 | 2012-02-20 02:26:06 -0300 | [diff] [blame] | 176 | |
Mike Isely | ac04d00 | 2012-02-20 02:28:56 -0300 | [diff] [blame] | 177 | ret = pvr2_ctrl_get_value( |
| 178 | pvr2_hdw_get_ctrl_by_id(hdw, PVR2_CID_STDDETECT), &val); |
| 179 | *std = val; |
| 180 | return ret; |
Mike Isely | 0927ee6 | 2012-02-20 02:26:06 -0300 | [diff] [blame] | 181 | } |
| 182 | |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 183 | static int pvr2_enum_input(struct file *file, void *priv, struct v4l2_input *vi) |
| 184 | { |
| 185 | struct pvr2_v4l2_fh *fh = file->private_data; |
| 186 | struct pvr2_hdw *hdw = fh->channel.mc_head->hdw; |
| 187 | struct pvr2_ctrl *cptr; |
| 188 | struct v4l2_input tmp; |
| 189 | unsigned int cnt; |
| 190 | int val; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 191 | |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 192 | cptr = pvr2_hdw_get_ctrl_by_id(hdw, PVR2_CID_INPUT); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 193 | |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 194 | memset(&tmp, 0, sizeof(tmp)); |
| 195 | tmp.index = vi->index; |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 196 | if (vi->index >= fh->input_cnt) |
| 197 | return -EINVAL; |
| 198 | val = fh->input_map[vi->index]; |
| 199 | switch (val) { |
| 200 | case PVR2_CVAL_INPUT_TV: |
| 201 | case PVR2_CVAL_INPUT_DTV: |
| 202 | case PVR2_CVAL_INPUT_RADIO: |
| 203 | tmp.type = V4L2_INPUT_TYPE_TUNER; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 204 | break; |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 205 | case PVR2_CVAL_INPUT_SVIDEO: |
| 206 | case PVR2_CVAL_INPUT_COMPOSITE: |
| 207 | tmp.type = V4L2_INPUT_TYPE_CAMERA; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 208 | break; |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 209 | default: |
| 210 | return -EINVAL; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 211 | } |
| 212 | |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 213 | cnt = 0; |
| 214 | pvr2_ctrl_get_valname(cptr, val, |
| 215 | tmp.name, sizeof(tmp.name) - 1, &cnt); |
| 216 | tmp.name[cnt] = 0; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 217 | |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 218 | /* Don't bother with audioset, since this driver currently |
| 219 | always switches the audio whenever the video is |
| 220 | switched. */ |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 221 | |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 222 | /* Handling std is a tougher problem. It doesn't make |
| 223 | sense in cases where a device might be multi-standard. |
| 224 | We could just copy out the current value for the |
| 225 | standard, but it can change over time. For now just |
| 226 | leave it zero. */ |
| 227 | *vi = tmp; |
| 228 | return 0; |
| 229 | } |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 230 | |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 231 | static int pvr2_g_input(struct file *file, void *priv, unsigned int *i) |
| 232 | { |
| 233 | struct pvr2_v4l2_fh *fh = file->private_data; |
| 234 | struct pvr2_hdw *hdw = fh->channel.mc_head->hdw; |
| 235 | unsigned int idx; |
| 236 | struct pvr2_ctrl *cptr; |
| 237 | int val; |
| 238 | int ret; |
Mauro Carvalho Chehab | 7383a47 | 2011-10-03 12:22:28 -0300 | [diff] [blame] | 239 | |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 240 | cptr = pvr2_hdw_get_ctrl_by_id(hdw, PVR2_CID_INPUT); |
| 241 | val = 0; |
| 242 | ret = pvr2_ctrl_get_value(cptr, &val); |
| 243 | *i = 0; |
| 244 | for (idx = 0; idx < fh->input_cnt; idx++) { |
| 245 | if (fh->input_map[idx] == val) { |
| 246 | *i = idx; |
Mike Isely | beb0ecd | 2008-04-22 14:45:38 -0300 | [diff] [blame] | 247 | break; |
| 248 | } |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 249 | } |
| 250 | return ret; |
| 251 | } |
| 252 | |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 253 | static int pvr2_s_input(struct file *file, void *priv, unsigned int inp) |
| 254 | { |
| 255 | struct pvr2_v4l2_fh *fh = file->private_data; |
| 256 | struct pvr2_hdw *hdw = fh->channel.mc_head->hdw; |
Hans Verkuil | eba09b5 | 2018-05-24 16:35:01 -0400 | [diff] [blame] | 257 | int ret; |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 258 | |
| 259 | if (inp >= fh->input_cnt) |
| 260 | return -EINVAL; |
Hans Verkuil | eba09b5 | 2018-05-24 16:35:01 -0400 | [diff] [blame] | 261 | ret = pvr2_ctrl_set_value( |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 262 | pvr2_hdw_get_ctrl_by_id(hdw, PVR2_CID_INPUT), |
| 263 | fh->input_map[inp]); |
Hans Verkuil | eba09b5 | 2018-05-24 16:35:01 -0400 | [diff] [blame] | 264 | pvr2_hdw_commit_ctl(hdw); |
| 265 | return ret; |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | static int pvr2_enumaudio(struct file *file, void *priv, struct v4l2_audio *vin) |
| 269 | { |
| 270 | /* pkt: FIXME: We are returning one "fake" input here |
| 271 | which could very well be called "whatever_we_like". |
| 272 | This is for apps that want to see an audio input |
| 273 | just to feel comfortable, as well as to test if |
| 274 | it can do stereo or sth. There is actually no guarantee |
| 275 | that the actual audio input cannot change behind the app's |
| 276 | back, but most applications should not mind that either. |
| 277 | |
| 278 | Hopefully, mplayer people will work with us on this (this |
| 279 | whole mess is to support mplayer pvr://), or Hans will come |
| 280 | up with a more standard way to say "we have inputs but we |
| 281 | don 't want you to change them independent of video" which |
| 282 | will sort this mess. |
| 283 | */ |
| 284 | |
| 285 | if (vin->index > 0) |
| 286 | return -EINVAL; |
Mauro Carvalho Chehab | 85709cb | 2018-09-10 08:19:16 -0400 | [diff] [blame] | 287 | strscpy(vin->name, "PVRUSB2 Audio", sizeof(vin->name)); |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 288 | vin->capability = V4L2_AUDCAP_STEREO; |
| 289 | return 0; |
| 290 | } |
| 291 | |
| 292 | static int pvr2_g_audio(struct file *file, void *priv, struct v4l2_audio *vin) |
| 293 | { |
| 294 | /* pkt: FIXME: see above comment (VIDIOC_ENUMAUDIO) */ |
| 295 | vin->index = 0; |
Mauro Carvalho Chehab | 85709cb | 2018-09-10 08:19:16 -0400 | [diff] [blame] | 296 | strscpy(vin->name, "PVRUSB2 Audio", sizeof(vin->name)); |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 297 | vin->capability = V4L2_AUDCAP_STEREO; |
| 298 | return 0; |
| 299 | } |
| 300 | |
Hans Verkuil | 0e8025b9 | 2012-09-04 11:59:31 -0300 | [diff] [blame] | 301 | static int pvr2_s_audio(struct file *file, void *priv, const struct v4l2_audio *vout) |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 302 | { |
| 303 | if (vout->index) |
| 304 | return -EINVAL; |
| 305 | return 0; |
| 306 | } |
| 307 | |
| 308 | static int pvr2_g_tuner(struct file *file, void *priv, struct v4l2_tuner *vt) |
| 309 | { |
| 310 | struct pvr2_v4l2_fh *fh = file->private_data; |
| 311 | struct pvr2_hdw *hdw = fh->channel.mc_head->hdw; |
| 312 | |
| 313 | if (vt->index != 0) |
| 314 | return -EINVAL; /* Only answer for the 1st tuner */ |
| 315 | |
| 316 | pvr2_hdw_execute_tuner_poll(hdw); |
| 317 | return pvr2_hdw_get_tuner_status(hdw, vt); |
| 318 | } |
| 319 | |
Hans Verkuil | 2f73c7c | 2013-03-15 06:10:06 -0300 | [diff] [blame] | 320 | static int pvr2_s_tuner(struct file *file, void *priv, const struct v4l2_tuner *vt) |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 321 | { |
| 322 | struct pvr2_v4l2_fh *fh = file->private_data; |
| 323 | struct pvr2_hdw *hdw = fh->channel.mc_head->hdw; |
Hans Verkuil | eba09b5 | 2018-05-24 16:35:01 -0400 | [diff] [blame] | 324 | int ret; |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 325 | |
| 326 | if (vt->index != 0) |
| 327 | return -EINVAL; |
| 328 | |
Hans Verkuil | eba09b5 | 2018-05-24 16:35:01 -0400 | [diff] [blame] | 329 | ret = pvr2_ctrl_set_value( |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 330 | pvr2_hdw_get_ctrl_by_id(hdw, PVR2_CID_AUDIOMODE), |
| 331 | vt->audmode); |
Hans Verkuil | eba09b5 | 2018-05-24 16:35:01 -0400 | [diff] [blame] | 332 | pvr2_hdw_commit_ctl(hdw); |
| 333 | return ret; |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 334 | } |
| 335 | |
Hans Verkuil | b530a44 | 2013-03-19 04:09:26 -0300 | [diff] [blame] | 336 | static int pvr2_s_frequency(struct file *file, void *priv, const struct v4l2_frequency *vf) |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 337 | { |
| 338 | struct pvr2_v4l2_fh *fh = file->private_data; |
| 339 | struct pvr2_hdw *hdw = fh->channel.mc_head->hdw; |
| 340 | unsigned long fv; |
| 341 | struct v4l2_tuner vt; |
| 342 | int cur_input; |
| 343 | struct pvr2_ctrl *ctrlp; |
| 344 | int ret; |
| 345 | |
| 346 | ret = pvr2_hdw_get_tuner_status(hdw, &vt); |
| 347 | if (ret != 0) |
| 348 | return ret; |
| 349 | ctrlp = pvr2_hdw_get_ctrl_by_id(hdw, PVR2_CID_INPUT); |
| 350 | ret = pvr2_ctrl_get_value(ctrlp, &cur_input); |
| 351 | if (ret != 0) |
| 352 | return ret; |
| 353 | if (vf->type == V4L2_TUNER_RADIO) { |
| 354 | if (cur_input != PVR2_CVAL_INPUT_RADIO) |
| 355 | pvr2_ctrl_set_value(ctrlp, PVR2_CVAL_INPUT_RADIO); |
| 356 | } else { |
| 357 | if (cur_input == PVR2_CVAL_INPUT_RADIO) |
| 358 | pvr2_ctrl_set_value(ctrlp, PVR2_CVAL_INPUT_TV); |
| 359 | } |
| 360 | fv = vf->frequency; |
| 361 | if (vt.capability & V4L2_TUNER_CAP_LOW) |
| 362 | fv = (fv * 125) / 2; |
| 363 | else |
| 364 | fv = fv * 62500; |
Hans Verkuil | eba09b5 | 2018-05-24 16:35:01 -0400 | [diff] [blame] | 365 | ret = pvr2_ctrl_set_value( |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 366 | pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_FREQUENCY),fv); |
Hans Verkuil | eba09b5 | 2018-05-24 16:35:01 -0400 | [diff] [blame] | 367 | pvr2_hdw_commit_ctl(hdw); |
| 368 | return ret; |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | static int pvr2_g_frequency(struct file *file, void *priv, struct v4l2_frequency *vf) |
| 372 | { |
| 373 | struct pvr2_v4l2_fh *fh = file->private_data; |
| 374 | struct pvr2_hdw *hdw = fh->channel.mc_head->hdw; |
| 375 | int val = 0; |
| 376 | int cur_input; |
| 377 | struct v4l2_tuner vt; |
| 378 | int ret; |
| 379 | |
| 380 | ret = pvr2_hdw_get_tuner_status(hdw, &vt); |
| 381 | if (ret != 0) |
| 382 | return ret; |
| 383 | ret = pvr2_ctrl_get_value( |
| 384 | pvr2_hdw_get_ctrl_by_id(hdw, PVR2_CID_FREQUENCY), |
| 385 | &val); |
| 386 | if (ret != 0) |
| 387 | return ret; |
| 388 | pvr2_ctrl_get_value( |
| 389 | pvr2_hdw_get_ctrl_by_id(hdw, PVR2_CID_INPUT), |
| 390 | &cur_input); |
| 391 | if (cur_input == PVR2_CVAL_INPUT_RADIO) |
| 392 | vf->type = V4L2_TUNER_RADIO; |
| 393 | else |
| 394 | vf->type = V4L2_TUNER_ANALOG_TV; |
| 395 | if (vt.capability & V4L2_TUNER_CAP_LOW) |
| 396 | val = (val * 2) / 125; |
| 397 | else |
| 398 | val /= 62500; |
| 399 | vf->frequency = val; |
| 400 | return 0; |
| 401 | } |
| 402 | |
| 403 | static int pvr2_enum_fmt_vid_cap(struct file *file, void *priv, struct v4l2_fmtdesc *fd) |
| 404 | { |
Hans Verkuil | c4b72ee | 2017-12-13 18:44:42 -0500 | [diff] [blame] | 405 | /* Only one format is supported: MPEG. */ |
| 406 | if (fd->index) |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 407 | return -EINVAL; |
| 408 | |
Hans Verkuil | c4b72ee | 2017-12-13 18:44:42 -0500 | [diff] [blame] | 409 | fd->pixelformat = V4L2_PIX_FMT_MPEG; |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 410 | return 0; |
| 411 | } |
| 412 | |
| 413 | static int pvr2_g_fmt_vid_cap(struct file *file, void *priv, struct v4l2_format *vf) |
| 414 | { |
| 415 | struct pvr2_v4l2_fh *fh = file->private_data; |
| 416 | struct pvr2_hdw *hdw = fh->channel.mc_head->hdw; |
| 417 | int val; |
| 418 | |
| 419 | memcpy(vf, &pvr_format[PVR_FORMAT_PIX], sizeof(struct v4l2_format)); |
| 420 | val = 0; |
| 421 | pvr2_ctrl_get_value( |
| 422 | pvr2_hdw_get_ctrl_by_id(hdw, PVR2_CID_HRES), |
| 423 | &val); |
| 424 | vf->fmt.pix.width = val; |
| 425 | val = 0; |
| 426 | pvr2_ctrl_get_value( |
| 427 | pvr2_hdw_get_ctrl_by_id(hdw, PVR2_CID_VRES), |
| 428 | &val); |
| 429 | vf->fmt.pix.height = val; |
| 430 | return 0; |
| 431 | } |
| 432 | |
| 433 | static int pvr2_try_fmt_vid_cap(struct file *file, void *priv, struct v4l2_format *vf) |
| 434 | { |
| 435 | struct pvr2_v4l2_fh *fh = file->private_data; |
| 436 | struct pvr2_hdw *hdw = fh->channel.mc_head->hdw; |
| 437 | int lmin, lmax, ldef; |
| 438 | struct pvr2_ctrl *hcp, *vcp; |
| 439 | int h = vf->fmt.pix.height; |
| 440 | int w = vf->fmt.pix.width; |
| 441 | |
| 442 | hcp = pvr2_hdw_get_ctrl_by_id(hdw, PVR2_CID_HRES); |
| 443 | vcp = pvr2_hdw_get_ctrl_by_id(hdw, PVR2_CID_VRES); |
| 444 | |
| 445 | lmin = pvr2_ctrl_get_min(hcp); |
| 446 | lmax = pvr2_ctrl_get_max(hcp); |
| 447 | pvr2_ctrl_get_def(hcp, &ldef); |
| 448 | if (w == -1) |
| 449 | w = ldef; |
| 450 | else if (w < lmin) |
| 451 | w = lmin; |
| 452 | else if (w > lmax) |
| 453 | w = lmax; |
| 454 | lmin = pvr2_ctrl_get_min(vcp); |
| 455 | lmax = pvr2_ctrl_get_max(vcp); |
| 456 | pvr2_ctrl_get_def(vcp, &ldef); |
| 457 | if (h == -1) |
| 458 | h = ldef; |
| 459 | else if (h < lmin) |
| 460 | h = lmin; |
| 461 | else if (h > lmax) |
| 462 | h = lmax; |
| 463 | |
| 464 | memcpy(vf, &pvr_format[PVR_FORMAT_PIX], |
| 465 | sizeof(struct v4l2_format)); |
| 466 | vf->fmt.pix.width = w; |
| 467 | vf->fmt.pix.height = h; |
| 468 | return 0; |
| 469 | } |
| 470 | |
| 471 | static int pvr2_s_fmt_vid_cap(struct file *file, void *priv, struct v4l2_format *vf) |
| 472 | { |
| 473 | struct pvr2_v4l2_fh *fh = file->private_data; |
| 474 | struct pvr2_hdw *hdw = fh->channel.mc_head->hdw; |
| 475 | struct pvr2_ctrl *hcp, *vcp; |
| 476 | int ret = pvr2_try_fmt_vid_cap(file, fh, vf); |
| 477 | |
| 478 | if (ret) |
| 479 | return ret; |
| 480 | hcp = pvr2_hdw_get_ctrl_by_id(hdw, PVR2_CID_HRES); |
| 481 | vcp = pvr2_hdw_get_ctrl_by_id(hdw, PVR2_CID_VRES); |
| 482 | pvr2_ctrl_set_value(hcp, vf->fmt.pix.width); |
| 483 | pvr2_ctrl_set_value(vcp, vf->fmt.pix.height); |
Hans Verkuil | eba09b5 | 2018-05-24 16:35:01 -0400 | [diff] [blame] | 484 | pvr2_hdw_commit_ctl(hdw); |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 485 | return 0; |
| 486 | } |
| 487 | |
| 488 | static int pvr2_streamon(struct file *file, void *priv, enum v4l2_buf_type i) |
| 489 | { |
| 490 | struct pvr2_v4l2_fh *fh = file->private_data; |
| 491 | struct pvr2_hdw *hdw = fh->channel.mc_head->hdw; |
| 492 | struct pvr2_v4l2_dev *pdi = fh->pdi; |
| 493 | int ret; |
| 494 | |
| 495 | if (!fh->pdi->stream) { |
| 496 | /* No stream defined for this node. This means |
| 497 | that we're not currently allowed to stream from |
| 498 | this node. */ |
| 499 | return -EPERM; |
| 500 | } |
| 501 | ret = pvr2_hdw_set_stream_type(hdw, pdi->config); |
| 502 | if (ret < 0) |
| 503 | return ret; |
| 504 | return pvr2_hdw_set_streaming(hdw, !0); |
| 505 | } |
| 506 | |
| 507 | static int pvr2_streamoff(struct file *file, void *priv, enum v4l2_buf_type i) |
| 508 | { |
| 509 | struct pvr2_v4l2_fh *fh = file->private_data; |
| 510 | struct pvr2_hdw *hdw = fh->channel.mc_head->hdw; |
| 511 | |
| 512 | if (!fh->pdi->stream) { |
| 513 | /* No stream defined for this node. This means |
| 514 | that we're not currently allowed to stream from |
| 515 | this node. */ |
| 516 | return -EPERM; |
| 517 | } |
| 518 | return pvr2_hdw_set_streaming(hdw, 0); |
| 519 | } |
| 520 | |
| 521 | static int pvr2_queryctrl(struct file *file, void *priv, |
| 522 | struct v4l2_queryctrl *vc) |
| 523 | { |
| 524 | struct pvr2_v4l2_fh *fh = file->private_data; |
| 525 | struct pvr2_hdw *hdw = fh->channel.mc_head->hdw; |
| 526 | struct pvr2_ctrl *cptr; |
| 527 | int val; |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 528 | |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 529 | if (vc->id & V4L2_CTRL_FLAG_NEXT_CTRL) { |
| 530 | cptr = pvr2_hdw_get_ctrl_nextv4l( |
| 531 | hdw, (vc->id & ~V4L2_CTRL_FLAG_NEXT_CTRL)); |
| 532 | if (cptr) |
| 533 | vc->id = pvr2_ctrl_get_v4lid(cptr); |
| 534 | } else { |
| 535 | cptr = pvr2_hdw_get_ctrl_v4l(hdw, vc->id); |
| 536 | } |
| 537 | if (!cptr) { |
| 538 | pvr2_trace(PVR2_TRACE_V4LIOCTL, |
| 539 | "QUERYCTRL id=0x%x not implemented here", |
| 540 | vc->id); |
| 541 | return -EINVAL; |
| 542 | } |
| 543 | |
| 544 | pvr2_trace(PVR2_TRACE_V4LIOCTL, |
| 545 | "QUERYCTRL id=0x%x mapping name=%s (%s)", |
| 546 | vc->id, pvr2_ctrl_get_name(cptr), |
| 547 | pvr2_ctrl_get_desc(cptr)); |
Mauro Carvalho Chehab | c0decac | 2018-09-10 08:19:14 -0400 | [diff] [blame] | 548 | strscpy(vc->name, pvr2_ctrl_get_desc(cptr), sizeof(vc->name)); |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 549 | vc->flags = pvr2_ctrl_get_v4lflags(cptr); |
| 550 | pvr2_ctrl_get_def(cptr, &val); |
| 551 | vc->default_value = val; |
| 552 | switch (pvr2_ctrl_get_type(cptr)) { |
| 553 | case pvr2_ctl_enum: |
| 554 | vc->type = V4L2_CTRL_TYPE_MENU; |
| 555 | vc->minimum = 0; |
| 556 | vc->maximum = pvr2_ctrl_get_cnt(cptr) - 1; |
| 557 | vc->step = 1; |
| 558 | break; |
| 559 | case pvr2_ctl_bool: |
| 560 | vc->type = V4L2_CTRL_TYPE_BOOLEAN; |
| 561 | vc->minimum = 0; |
| 562 | vc->maximum = 1; |
| 563 | vc->step = 1; |
| 564 | break; |
| 565 | case pvr2_ctl_int: |
| 566 | vc->type = V4L2_CTRL_TYPE_INTEGER; |
| 567 | vc->minimum = pvr2_ctrl_get_min(cptr); |
| 568 | vc->maximum = pvr2_ctrl_get_max(cptr); |
| 569 | vc->step = 1; |
| 570 | break; |
| 571 | default: |
| 572 | pvr2_trace(PVR2_TRACE_V4LIOCTL, |
| 573 | "QUERYCTRL id=0x%x name=%s not mappable", |
| 574 | vc->id, pvr2_ctrl_get_name(cptr)); |
| 575 | return -EINVAL; |
| 576 | } |
| 577 | return 0; |
| 578 | } |
| 579 | |
| 580 | static int pvr2_querymenu(struct file *file, void *priv, struct v4l2_querymenu *vm) |
| 581 | { |
| 582 | struct pvr2_v4l2_fh *fh = file->private_data; |
| 583 | struct pvr2_hdw *hdw = fh->channel.mc_head->hdw; |
| 584 | unsigned int cnt = 0; |
| 585 | int ret; |
| 586 | |
| 587 | ret = pvr2_ctrl_get_valname(pvr2_hdw_get_ctrl_v4l(hdw, vm->id), |
| 588 | vm->index, |
| 589 | vm->name, sizeof(vm->name) - 1, |
| 590 | &cnt); |
| 591 | vm->name[cnt] = 0; |
| 592 | return ret; |
| 593 | } |
| 594 | |
| 595 | static int pvr2_g_ctrl(struct file *file, void *priv, struct v4l2_control *vc) |
| 596 | { |
| 597 | struct pvr2_v4l2_fh *fh = file->private_data; |
| 598 | struct pvr2_hdw *hdw = fh->channel.mc_head->hdw; |
| 599 | int val = 0; |
| 600 | int ret; |
| 601 | |
| 602 | ret = pvr2_ctrl_get_value(pvr2_hdw_get_ctrl_v4l(hdw, vc->id), |
| 603 | &val); |
| 604 | vc->value = val; |
| 605 | return ret; |
| 606 | } |
| 607 | |
| 608 | static int pvr2_s_ctrl(struct file *file, void *priv, struct v4l2_control *vc) |
| 609 | { |
| 610 | struct pvr2_v4l2_fh *fh = file->private_data; |
| 611 | struct pvr2_hdw *hdw = fh->channel.mc_head->hdw; |
Hans Verkuil | eba09b5 | 2018-05-24 16:35:01 -0400 | [diff] [blame] | 612 | int ret; |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 613 | |
Hans Verkuil | eba09b5 | 2018-05-24 16:35:01 -0400 | [diff] [blame] | 614 | ret = pvr2_ctrl_set_value(pvr2_hdw_get_ctrl_v4l(hdw, vc->id), |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 615 | vc->value); |
Hans Verkuil | eba09b5 | 2018-05-24 16:35:01 -0400 | [diff] [blame] | 616 | pvr2_hdw_commit_ctl(hdw); |
| 617 | return ret; |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 618 | } |
| 619 | |
| 620 | static int pvr2_g_ext_ctrls(struct file *file, void *priv, |
| 621 | struct v4l2_ext_controls *ctls) |
| 622 | { |
| 623 | struct pvr2_v4l2_fh *fh = file->private_data; |
| 624 | struct pvr2_hdw *hdw = fh->channel.mc_head->hdw; |
| 625 | struct v4l2_ext_control *ctrl; |
Ricardo Ribalda | 082afb7 | 2015-10-29 08:10:31 -0200 | [diff] [blame] | 626 | struct pvr2_ctrl *cptr; |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 627 | unsigned int idx; |
| 628 | int val; |
| 629 | int ret; |
| 630 | |
| 631 | ret = 0; |
| 632 | for (idx = 0; idx < ctls->count; idx++) { |
| 633 | ctrl = ctls->controls + idx; |
Ricardo Ribalda | 082afb7 | 2015-10-29 08:10:31 -0200 | [diff] [blame] | 634 | cptr = pvr2_hdw_get_ctrl_v4l(hdw, ctrl->id); |
| 635 | if (cptr) { |
| 636 | if (ctls->which == V4L2_CTRL_WHICH_DEF_VAL) |
| 637 | pvr2_ctrl_get_def(cptr, &val); |
| 638 | else |
| 639 | ret = pvr2_ctrl_get_value(cptr, &val); |
| 640 | } else |
| 641 | ret = -EINVAL; |
| 642 | |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 643 | if (ret) { |
| 644 | ctls->error_idx = idx; |
| 645 | return ret; |
| 646 | } |
| 647 | /* Ensure that if read as a 64 bit value, the user |
| 648 | will still get a hopefully sane value */ |
| 649 | ctrl->value64 = 0; |
| 650 | ctrl->value = val; |
| 651 | } |
| 652 | return 0; |
| 653 | } |
| 654 | |
| 655 | static int pvr2_s_ext_ctrls(struct file *file, void *priv, |
| 656 | struct v4l2_ext_controls *ctls) |
| 657 | { |
| 658 | struct pvr2_v4l2_fh *fh = file->private_data; |
| 659 | struct pvr2_hdw *hdw = fh->channel.mc_head->hdw; |
| 660 | struct v4l2_ext_control *ctrl; |
| 661 | unsigned int idx; |
| 662 | int ret; |
| 663 | |
Ricardo Ribalda | 082afb7 | 2015-10-29 08:10:31 -0200 | [diff] [blame] | 664 | /* Default value cannot be changed */ |
| 665 | if (ctls->which == V4L2_CTRL_WHICH_DEF_VAL) |
| 666 | return -EINVAL; |
| 667 | |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 668 | ret = 0; |
| 669 | for (idx = 0; idx < ctls->count; idx++) { |
| 670 | ctrl = ctls->controls + idx; |
| 671 | ret = pvr2_ctrl_set_value( |
| 672 | pvr2_hdw_get_ctrl_v4l(hdw, ctrl->id), |
| 673 | ctrl->value); |
| 674 | if (ret) { |
| 675 | ctls->error_idx = idx; |
Hans Verkuil | eba09b5 | 2018-05-24 16:35:01 -0400 | [diff] [blame] | 676 | goto commit; |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 677 | } |
| 678 | } |
Hans Verkuil | eba09b5 | 2018-05-24 16:35:01 -0400 | [diff] [blame] | 679 | commit: |
| 680 | pvr2_hdw_commit_ctl(hdw); |
| 681 | return ret; |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 682 | } |
| 683 | |
| 684 | static int pvr2_try_ext_ctrls(struct file *file, void *priv, |
| 685 | struct v4l2_ext_controls *ctls) |
| 686 | { |
| 687 | struct pvr2_v4l2_fh *fh = file->private_data; |
| 688 | struct pvr2_hdw *hdw = fh->channel.mc_head->hdw; |
| 689 | struct v4l2_ext_control *ctrl; |
| 690 | struct pvr2_ctrl *pctl; |
| 691 | unsigned int idx; |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 692 | |
| 693 | /* For the moment just validate that the requested control |
| 694 | actually exists. */ |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 695 | for (idx = 0; idx < ctls->count; idx++) { |
| 696 | ctrl = ctls->controls + idx; |
| 697 | pctl = pvr2_hdw_get_ctrl_v4l(hdw, ctrl->id); |
| 698 | if (!pctl) { |
| 699 | ctls->error_idx = idx; |
| 700 | return -EINVAL; |
| 701 | } |
| 702 | } |
| 703 | return 0; |
| 704 | } |
| 705 | |
Hans Verkuil | 5200ab6 | 2018-10-04 17:38:15 -0400 | [diff] [blame] | 706 | static int pvr2_g_pixelaspect(struct file *file, void *priv, |
| 707 | int type, struct v4l2_fract *f) |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 708 | { |
| 709 | struct pvr2_v4l2_fh *fh = file->private_data; |
| 710 | struct pvr2_hdw *hdw = fh->channel.mc_head->hdw; |
Hans Verkuil | 5200ab6 | 2018-10-04 17:38:15 -0400 | [diff] [blame] | 711 | struct v4l2_cropcap cap = { .type = type }; |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 712 | int ret; |
| 713 | |
Hans Verkuil | 5200ab6 | 2018-10-04 17:38:15 -0400 | [diff] [blame] | 714 | if (type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 715 | return -EINVAL; |
Hans Verkuil | 5200ab6 | 2018-10-04 17:38:15 -0400 | [diff] [blame] | 716 | ret = pvr2_hdw_get_cropcap(hdw, &cap); |
| 717 | if (!ret) |
| 718 | *f = cap.pixelaspect; |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 719 | return ret; |
| 720 | } |
| 721 | |
Hans Verkuil | 1f981a4 | 2016-07-03 08:14:17 -0300 | [diff] [blame] | 722 | static int pvr2_g_selection(struct file *file, void *priv, |
| 723 | struct v4l2_selection *sel) |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 724 | { |
| 725 | struct pvr2_v4l2_fh *fh = file->private_data; |
| 726 | struct pvr2_hdw *hdw = fh->channel.mc_head->hdw; |
Hans Verkuil | 1f981a4 | 2016-07-03 08:14:17 -0300 | [diff] [blame] | 727 | struct v4l2_cropcap cap; |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 728 | int val = 0; |
| 729 | int ret; |
| 730 | |
Hans Verkuil | 1f981a4 | 2016-07-03 08:14:17 -0300 | [diff] [blame] | 731 | if (sel->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 732 | return -EINVAL; |
Hans Verkuil | 1f981a4 | 2016-07-03 08:14:17 -0300 | [diff] [blame] | 733 | |
| 734 | cap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 735 | |
| 736 | switch (sel->target) { |
| 737 | case V4L2_SEL_TGT_CROP: |
| 738 | ret = pvr2_ctrl_get_value( |
| 739 | pvr2_hdw_get_ctrl_by_id(hdw, PVR2_CID_CROPL), &val); |
| 740 | if (ret != 0) |
| 741 | return -EINVAL; |
| 742 | sel->r.left = val; |
| 743 | ret = pvr2_ctrl_get_value( |
| 744 | pvr2_hdw_get_ctrl_by_id(hdw, PVR2_CID_CROPT), &val); |
| 745 | if (ret != 0) |
| 746 | return -EINVAL; |
| 747 | sel->r.top = val; |
| 748 | ret = pvr2_ctrl_get_value( |
| 749 | pvr2_hdw_get_ctrl_by_id(hdw, PVR2_CID_CROPW), &val); |
| 750 | if (ret != 0) |
| 751 | return -EINVAL; |
| 752 | sel->r.width = val; |
| 753 | ret = pvr2_ctrl_get_value( |
| 754 | pvr2_hdw_get_ctrl_by_id(hdw, PVR2_CID_CROPH), &val); |
| 755 | if (ret != 0) |
| 756 | return -EINVAL; |
| 757 | sel->r.height = val; |
| 758 | break; |
| 759 | case V4L2_SEL_TGT_CROP_DEFAULT: |
| 760 | ret = pvr2_hdw_get_cropcap(hdw, &cap); |
| 761 | sel->r = cap.defrect; |
| 762 | break; |
| 763 | case V4L2_SEL_TGT_CROP_BOUNDS: |
| 764 | ret = pvr2_hdw_get_cropcap(hdw, &cap); |
| 765 | sel->r = cap.bounds; |
| 766 | break; |
| 767 | default: |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 768 | return -EINVAL; |
Hans Verkuil | 1f981a4 | 2016-07-03 08:14:17 -0300 | [diff] [blame] | 769 | } |
| 770 | return ret; |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 771 | } |
| 772 | |
Hans Verkuil | 1f981a4 | 2016-07-03 08:14:17 -0300 | [diff] [blame] | 773 | static int pvr2_s_selection(struct file *file, void *priv, |
| 774 | struct v4l2_selection *sel) |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 775 | { |
| 776 | struct pvr2_v4l2_fh *fh = file->private_data; |
| 777 | struct pvr2_hdw *hdw = fh->channel.mc_head->hdw; |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 778 | int ret; |
| 779 | |
Hans Verkuil | 1f981a4 | 2016-07-03 08:14:17 -0300 | [diff] [blame] | 780 | if (sel->type != V4L2_BUF_TYPE_VIDEO_CAPTURE || |
| 781 | sel->target != V4L2_SEL_TGT_CROP) |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 782 | return -EINVAL; |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 783 | ret = pvr2_ctrl_set_value( |
| 784 | pvr2_hdw_get_ctrl_by_id(hdw, PVR2_CID_CROPL), |
Hans Verkuil | 1f981a4 | 2016-07-03 08:14:17 -0300 | [diff] [blame] | 785 | sel->r.left); |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 786 | if (ret != 0) |
Hans Verkuil | eba09b5 | 2018-05-24 16:35:01 -0400 | [diff] [blame] | 787 | goto commit; |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 788 | ret = pvr2_ctrl_set_value( |
| 789 | pvr2_hdw_get_ctrl_by_id(hdw, PVR2_CID_CROPT), |
Hans Verkuil | 1f981a4 | 2016-07-03 08:14:17 -0300 | [diff] [blame] | 790 | sel->r.top); |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 791 | if (ret != 0) |
Hans Verkuil | eba09b5 | 2018-05-24 16:35:01 -0400 | [diff] [blame] | 792 | goto commit; |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 793 | ret = pvr2_ctrl_set_value( |
| 794 | pvr2_hdw_get_ctrl_by_id(hdw, PVR2_CID_CROPW), |
Hans Verkuil | 1f981a4 | 2016-07-03 08:14:17 -0300 | [diff] [blame] | 795 | sel->r.width); |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 796 | if (ret != 0) |
Hans Verkuil | eba09b5 | 2018-05-24 16:35:01 -0400 | [diff] [blame] | 797 | goto commit; |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 798 | ret = pvr2_ctrl_set_value( |
| 799 | pvr2_hdw_get_ctrl_by_id(hdw, PVR2_CID_CROPH), |
Hans Verkuil | 1f981a4 | 2016-07-03 08:14:17 -0300 | [diff] [blame] | 800 | sel->r.height); |
Hans Verkuil | eba09b5 | 2018-05-24 16:35:01 -0400 | [diff] [blame] | 801 | commit: |
| 802 | pvr2_hdw_commit_ctl(hdw); |
| 803 | return ret; |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 804 | } |
| 805 | |
| 806 | static int pvr2_log_status(struct file *file, void *priv) |
| 807 | { |
| 808 | struct pvr2_v4l2_fh *fh = file->private_data; |
| 809 | struct pvr2_hdw *hdw = fh->channel.mc_head->hdw; |
| 810 | |
| 811 | pvr2_hdw_trigger_module_log(hdw); |
| 812 | return 0; |
| 813 | } |
| 814 | |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 815 | static const struct v4l2_ioctl_ops pvr2_ioctl_ops = { |
| 816 | .vidioc_querycap = pvr2_querycap, |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 817 | .vidioc_s_audio = pvr2_s_audio, |
| 818 | .vidioc_g_audio = pvr2_g_audio, |
| 819 | .vidioc_enumaudio = pvr2_enumaudio, |
| 820 | .vidioc_enum_input = pvr2_enum_input, |
Hans Verkuil | 5200ab6 | 2018-10-04 17:38:15 -0400 | [diff] [blame] | 821 | .vidioc_g_pixelaspect = pvr2_g_pixelaspect, |
Hans Verkuil | 1f981a4 | 2016-07-03 08:14:17 -0300 | [diff] [blame] | 822 | .vidioc_s_selection = pvr2_s_selection, |
| 823 | .vidioc_g_selection = pvr2_g_selection, |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 824 | .vidioc_g_input = pvr2_g_input, |
| 825 | .vidioc_s_input = pvr2_s_input, |
| 826 | .vidioc_g_frequency = pvr2_g_frequency, |
| 827 | .vidioc_s_frequency = pvr2_s_frequency, |
| 828 | .vidioc_s_tuner = pvr2_s_tuner, |
| 829 | .vidioc_g_tuner = pvr2_g_tuner, |
| 830 | .vidioc_g_std = pvr2_g_std, |
| 831 | .vidioc_s_std = pvr2_s_std, |
Mike Isely | 0927ee6 | 2012-02-20 02:26:06 -0300 | [diff] [blame] | 832 | .vidioc_querystd = pvr2_querystd, |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 833 | .vidioc_log_status = pvr2_log_status, |
| 834 | .vidioc_enum_fmt_vid_cap = pvr2_enum_fmt_vid_cap, |
| 835 | .vidioc_g_fmt_vid_cap = pvr2_g_fmt_vid_cap, |
| 836 | .vidioc_s_fmt_vid_cap = pvr2_s_fmt_vid_cap, |
| 837 | .vidioc_try_fmt_vid_cap = pvr2_try_fmt_vid_cap, |
| 838 | .vidioc_streamon = pvr2_streamon, |
| 839 | .vidioc_streamoff = pvr2_streamoff, |
| 840 | .vidioc_queryctrl = pvr2_queryctrl, |
| 841 | .vidioc_querymenu = pvr2_querymenu, |
| 842 | .vidioc_g_ctrl = pvr2_g_ctrl, |
| 843 | .vidioc_s_ctrl = pvr2_s_ctrl, |
| 844 | .vidioc_g_ext_ctrls = pvr2_g_ext_ctrls, |
| 845 | .vidioc_s_ext_ctrls = pvr2_s_ext_ctrls, |
| 846 | .vidioc_try_ext_ctrls = pvr2_try_ext_ctrls, |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 847 | }; |
| 848 | |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 849 | static void pvr2_v4l2_dev_destroy(struct pvr2_v4l2_dev *dip) |
| 850 | { |
Mike Isely | 0f0f257b | 2006-12-27 23:19:42 -0300 | [diff] [blame] | 851 | struct pvr2_hdw *hdw = dip->v4lp->channel.mc_head->hdw; |
Mike Isely | 16eb40d | 2006-12-30 18:27:32 -0300 | [diff] [blame] | 852 | enum pvr2_config cfg = dip->config; |
Mike Isely | d72baad | 2010-05-15 00:15:38 -0300 | [diff] [blame] | 853 | char msg[80]; |
| 854 | unsigned int mcnt; |
| 855 | |
| 856 | /* Construct the unregistration message *before* we actually |
| 857 | perform the unregistration step. By doing it this way we don't |
| 858 | have to worry about potentially touching deleted resources. */ |
| 859 | mcnt = scnprintf(msg, sizeof(msg) - 1, |
| 860 | "pvrusb2: unregistered device %s [%s]", |
| 861 | video_device_node_name(&dip->devbase), |
| 862 | pvr2_config_get_name(cfg)); |
| 863 | msg[mcnt] = 0; |
Mike Isely | 0f0f257b | 2006-12-27 23:19:42 -0300 | [diff] [blame] | 864 | |
Mike Isely | 16eb40d | 2006-12-30 18:27:32 -0300 | [diff] [blame] | 865 | pvr2_hdw_v4l_store_minor_number(hdw,dip->minor_type,-1); |
Mike Isely | 7591005 | 2006-09-23 22:30:50 -0300 | [diff] [blame] | 866 | |
| 867 | /* Paranoia */ |
Randy Dunlap | c2625bf | 2006-10-29 11:12:27 -0300 | [diff] [blame] | 868 | dip->v4lp = NULL; |
| 869 | dip->stream = NULL; |
Mike Isely | 7591005 | 2006-09-23 22:30:50 -0300 | [diff] [blame] | 870 | |
| 871 | /* Actual deallocation happens later when all internal references |
| 872 | are gone. */ |
| 873 | video_unregister_device(&dip->devbase); |
Mike Isely | 0f0f257b | 2006-12-27 23:19:42 -0300 | [diff] [blame] | 874 | |
Dafna Hirschfeld | 8f845c6 | 2018-10-08 08:06:47 -0400 | [diff] [blame] | 875 | pr_info("%s\n", msg); |
Mike Isely | 0f0f257b | 2006-12-27 23:19:42 -0300 | [diff] [blame] | 876 | |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 877 | } |
| 878 | |
| 879 | |
Mike Isely | 4a89baa | 2009-10-12 00:13:28 -0300 | [diff] [blame] | 880 | static void pvr2_v4l2_dev_disassociate_parent(struct pvr2_v4l2_dev *dip) |
| 881 | { |
| 882 | if (!dip) return; |
Hans Verkuil | a28fbd0 | 2013-06-10 09:16:25 -0300 | [diff] [blame] | 883 | if (!dip->devbase.v4l2_dev->dev) return; |
| 884 | dip->devbase.v4l2_dev->dev = NULL; |
Mike Isely | 4a89baa | 2009-10-12 00:13:28 -0300 | [diff] [blame] | 885 | device_move(&dip->devbase.dev, NULL, DPM_ORDER_NONE); |
| 886 | } |
| 887 | |
| 888 | |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 889 | static void pvr2_v4l2_destroy_no_lock(struct pvr2_v4l2 *vp) |
| 890 | { |
Mike Isely | 0f0f257b | 2006-12-27 23:19:42 -0300 | [diff] [blame] | 891 | if (vp->dev_video) { |
| 892 | pvr2_v4l2_dev_destroy(vp->dev_video); |
Al Viro | 89952d1 | 2007-03-14 09:17:59 +0000 | [diff] [blame] | 893 | vp->dev_video = NULL; |
Mike Isely | 0f0f257b | 2006-12-27 23:19:42 -0300 | [diff] [blame] | 894 | } |
| 895 | if (vp->dev_radio) { |
| 896 | pvr2_v4l2_dev_destroy(vp->dev_radio); |
Al Viro | 89952d1 | 2007-03-14 09:17:59 +0000 | [diff] [blame] | 897 | vp->dev_radio = NULL; |
Mike Isely | 0f0f257b | 2006-12-27 23:19:42 -0300 | [diff] [blame] | 898 | } |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 899 | |
| 900 | pvr2_trace(PVR2_TRACE_STRUCT,"Destroying pvr2_v4l2 id=%p",vp); |
| 901 | pvr2_channel_done(&vp->channel); |
| 902 | kfree(vp); |
| 903 | } |
| 904 | |
| 905 | |
Mike Isely | 7591005 | 2006-09-23 22:30:50 -0300 | [diff] [blame] | 906 | static void pvr2_video_device_release(struct video_device *vdev) |
| 907 | { |
| 908 | struct pvr2_v4l2_dev *dev; |
| 909 | dev = container_of(vdev,struct pvr2_v4l2_dev,devbase); |
| 910 | kfree(dev); |
| 911 | } |
| 912 | |
| 913 | |
Adrian Bunk | 07e337e | 2006-06-30 11:30:20 -0300 | [diff] [blame] | 914 | static void pvr2_v4l2_internal_check(struct pvr2_channel *chp) |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 915 | { |
| 916 | struct pvr2_v4l2 *vp; |
| 917 | vp = container_of(chp,struct pvr2_v4l2,channel); |
| 918 | if (!vp->channel.mc_head->disconnect_flag) return; |
Mike Isely | 4a89baa | 2009-10-12 00:13:28 -0300 | [diff] [blame] | 919 | pvr2_v4l2_dev_disassociate_parent(vp->dev_video); |
| 920 | pvr2_v4l2_dev_disassociate_parent(vp->dev_radio); |
Hans Verkuil | cee05cb | 2015-02-03 10:46:55 -0300 | [diff] [blame] | 921 | if (!list_empty(&vp->dev_video->devbase.fh_list) || |
| 922 | !list_empty(&vp->dev_radio->devbase.fh_list)) |
| 923 | return; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 924 | pvr2_v4l2_destroy_no_lock(vp); |
| 925 | } |
| 926 | |
| 927 | |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 928 | static int pvr2_v4l2_release(struct file *file) |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 929 | { |
| 930 | struct pvr2_v4l2_fh *fhp = file->private_data; |
Hans Verkuil | cee05cb | 2015-02-03 10:46:55 -0300 | [diff] [blame] | 931 | struct pvr2_v4l2 *vp = fhp->pdi->v4lp; |
Mike Isely | c74e006 | 2006-12-30 18:31:22 -0300 | [diff] [blame] | 932 | struct pvr2_hdw *hdw = fhp->channel.mc_head->hdw; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 933 | |
| 934 | pvr2_trace(PVR2_TRACE_OPEN_CLOSE,"pvr2_v4l2_release"); |
| 935 | |
| 936 | if (fhp->rhp) { |
| 937 | struct pvr2_stream *sp; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 938 | pvr2_hdw_set_streaming(hdw,0); |
| 939 | sp = pvr2_ioread_get_stream(fhp->rhp); |
Mike Isely | a0fd1cb | 2006-06-30 11:35:28 -0300 | [diff] [blame] | 940 | if (sp) pvr2_stream_set_callback(sp,NULL,NULL); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 941 | pvr2_ioread_destroy(fhp->rhp); |
Mike Isely | a0fd1cb | 2006-06-30 11:35:28 -0300 | [diff] [blame] | 942 | fhp->rhp = NULL; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 943 | } |
Pantelis Koukousoulas | ae2b9e2 | 2006-12-27 23:09:55 -0300 | [diff] [blame] | 944 | |
Hans Verkuil | cee05cb | 2015-02-03 10:46:55 -0300 | [diff] [blame] | 945 | v4l2_fh_del(&fhp->fh); |
| 946 | v4l2_fh_exit(&fhp->fh); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 947 | file->private_data = NULL; |
| 948 | |
Mike Isely | 794b160 | 2008-04-22 14:45:45 -0300 | [diff] [blame] | 949 | pvr2_channel_done(&fhp->channel); |
| 950 | pvr2_trace(PVR2_TRACE_STRUCT, |
| 951 | "Destroying pvr_v4l2_fh id=%p",fhp); |
Mike Isely | e57b1c8 | 2008-04-21 03:52:34 -0300 | [diff] [blame] | 952 | if (fhp->input_map) { |
| 953 | kfree(fhp->input_map); |
| 954 | fhp->input_map = NULL; |
| 955 | } |
Mike Isely | 794b160 | 2008-04-22 14:45:45 -0300 | [diff] [blame] | 956 | kfree(fhp); |
Hans Verkuil | cee05cb | 2015-02-03 10:46:55 -0300 | [diff] [blame] | 957 | if (vp->channel.mc_head->disconnect_flag && |
| 958 | list_empty(&vp->dev_video->devbase.fh_list) && |
| 959 | list_empty(&vp->dev_radio->devbase.fh_list)) { |
Mike Isely | 794b160 | 2008-04-22 14:45:45 -0300 | [diff] [blame] | 960 | pvr2_v4l2_destroy_no_lock(vp); |
| 961 | } |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 962 | return 0; |
| 963 | } |
| 964 | |
| 965 | |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 966 | static int pvr2_v4l2_open(struct file *file) |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 967 | { |
Mike Isely | 7591005 | 2006-09-23 22:30:50 -0300 | [diff] [blame] | 968 | struct pvr2_v4l2_dev *dip; /* Our own context pointer */ |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 969 | struct pvr2_v4l2_fh *fhp; |
| 970 | struct pvr2_v4l2 *vp; |
| 971 | struct pvr2_hdw *hdw; |
Mike Isely | 1cb03b7 | 2008-04-21 03:47:43 -0300 | [diff] [blame] | 972 | unsigned int input_mask = 0; |
Mike Isely | e57b1c8 | 2008-04-21 03:52:34 -0300 | [diff] [blame] | 973 | unsigned int input_cnt,idx; |
Mike Isely | 1cb03b7 | 2008-04-21 03:47:43 -0300 | [diff] [blame] | 974 | int ret = 0; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 975 | |
Mike Isely | 7591005 | 2006-09-23 22:30:50 -0300 | [diff] [blame] | 976 | dip = container_of(video_devdata(file),struct pvr2_v4l2_dev,devbase); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 977 | |
| 978 | vp = dip->v4lp; |
| 979 | hdw = vp->channel.hdw; |
| 980 | |
| 981 | pvr2_trace(PVR2_TRACE_OPEN_CLOSE,"pvr2_v4l2_open"); |
| 982 | |
| 983 | if (!pvr2_hdw_dev_ok(hdw)) { |
| 984 | pvr2_trace(PVR2_TRACE_OPEN_CLOSE, |
| 985 | "pvr2_v4l2_open: hardware not ready"); |
| 986 | return -EIO; |
| 987 | } |
| 988 | |
Mike Isely | 4b85dee | 2007-01-20 00:03:32 -0300 | [diff] [blame] | 989 | fhp = kzalloc(sizeof(*fhp),GFP_KERNEL); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 990 | if (!fhp) { |
| 991 | return -ENOMEM; |
| 992 | } |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 993 | |
Hans Verkuil | cee05cb | 2015-02-03 10:46:55 -0300 | [diff] [blame] | 994 | v4l2_fh_init(&fhp->fh, &dip->devbase); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 995 | init_waitqueue_head(&fhp->wait_data); |
Joe Perches | 108bdd7 | 2010-04-05 16:05:39 -0300 | [diff] [blame] | 996 | fhp->pdi = dip; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 997 | |
Mike Isely | 794b160 | 2008-04-22 14:45:45 -0300 | [diff] [blame] | 998 | pvr2_trace(PVR2_TRACE_STRUCT,"Creating pvr_v4l2_fh id=%p",fhp); |
| 999 | pvr2_channel_init(&fhp->channel,vp->channel.mc_head); |
Pantelis Koukousoulas | ae2b9e2 | 2006-12-27 23:09:55 -0300 | [diff] [blame] | 1000 | |
Mike Isely | 1cb03b7 | 2008-04-21 03:47:43 -0300 | [diff] [blame] | 1001 | if (dip->v4l_type == VFL_TYPE_RADIO) { |
| 1002 | /* Opening device as a radio, legal input selection subset |
| 1003 | is just the radio. */ |
| 1004 | input_mask = (1 << PVR2_CVAL_INPUT_RADIO); |
| 1005 | } else { |
| 1006 | /* Opening the main V4L device, legal input selection |
| 1007 | subset includes all analog inputs. */ |
| 1008 | input_mask = ((1 << PVR2_CVAL_INPUT_RADIO) | |
| 1009 | (1 << PVR2_CVAL_INPUT_TV) | |
| 1010 | (1 << PVR2_CVAL_INPUT_COMPOSITE) | |
| 1011 | (1 << PVR2_CVAL_INPUT_SVIDEO)); |
| 1012 | } |
| 1013 | ret = pvr2_channel_limit_inputs(&fhp->channel,input_mask); |
| 1014 | if (ret) { |
| 1015 | pvr2_channel_done(&fhp->channel); |
| 1016 | pvr2_trace(PVR2_TRACE_STRUCT, |
| 1017 | "Destroying pvr_v4l2_fh id=%p (input mask error)", |
| 1018 | fhp); |
Santosh Kumar Singh | 01faa0d | 2016-12-19 15:20:37 -0200 | [diff] [blame] | 1019 | v4l2_fh_exit(&fhp->fh); |
Mike Isely | 1cb03b7 | 2008-04-21 03:47:43 -0300 | [diff] [blame] | 1020 | kfree(fhp); |
| 1021 | return ret; |
| 1022 | } |
| 1023 | |
Mike Isely | e57b1c8 | 2008-04-21 03:52:34 -0300 | [diff] [blame] | 1024 | input_mask &= pvr2_hdw_get_input_available(hdw); |
| 1025 | input_cnt = 0; |
| 1026 | for (idx = 0; idx < (sizeof(input_mask) << 3); idx++) { |
| 1027 | if (input_mask & (1 << idx)) input_cnt++; |
| 1028 | } |
| 1029 | fhp->input_cnt = input_cnt; |
| 1030 | fhp->input_map = kzalloc(input_cnt,GFP_KERNEL); |
| 1031 | if (!fhp->input_map) { |
| 1032 | pvr2_channel_done(&fhp->channel); |
| 1033 | pvr2_trace(PVR2_TRACE_STRUCT, |
| 1034 | "Destroying pvr_v4l2_fh id=%p (input map failure)", |
| 1035 | fhp); |
Santosh Kumar Singh | 01faa0d | 2016-12-19 15:20:37 -0200 | [diff] [blame] | 1036 | v4l2_fh_exit(&fhp->fh); |
Mike Isely | e57b1c8 | 2008-04-21 03:52:34 -0300 | [diff] [blame] | 1037 | kfree(fhp); |
| 1038 | return -ENOMEM; |
| 1039 | } |
| 1040 | input_cnt = 0; |
| 1041 | for (idx = 0; idx < (sizeof(input_mask) << 3); idx++) { |
| 1042 | if (!(input_mask & (1 << idx))) continue; |
| 1043 | fhp->input_map[input_cnt++] = idx; |
| 1044 | } |
| 1045 | |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 1046 | fhp->file = file; |
| 1047 | file->private_data = fhp; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 1048 | |
| 1049 | fhp->fw_mode_flag = pvr2_hdw_cpufw_get_enabled(hdw); |
Hans Verkuil | cee05cb | 2015-02-03 10:46:55 -0300 | [diff] [blame] | 1050 | v4l2_fh_add(&fhp->fh); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 1051 | |
| 1052 | return 0; |
| 1053 | } |
| 1054 | |
| 1055 | |
| 1056 | static void pvr2_v4l2_notify(struct pvr2_v4l2_fh *fhp) |
| 1057 | { |
| 1058 | wake_up(&fhp->wait_data); |
| 1059 | } |
| 1060 | |
| 1061 | static int pvr2_v4l2_iosetup(struct pvr2_v4l2_fh *fh) |
| 1062 | { |
| 1063 | int ret; |
| 1064 | struct pvr2_stream *sp; |
| 1065 | struct pvr2_hdw *hdw; |
| 1066 | if (fh->rhp) return 0; |
| 1067 | |
Joe Perches | 108bdd7 | 2010-04-05 16:05:39 -0300 | [diff] [blame] | 1068 | if (!fh->pdi->stream) { |
Mike Isely | 16eb40d | 2006-12-30 18:27:32 -0300 | [diff] [blame] | 1069 | /* No stream defined for this node. This means that we're |
| 1070 | not currently allowed to stream from this node. */ |
| 1071 | return -EPERM; |
| 1072 | } |
| 1073 | |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 1074 | /* First read() attempt. Try to claim the stream and start |
| 1075 | it... */ |
| 1076 | if ((ret = pvr2_channel_claim_stream(&fh->channel, |
Joe Perches | 108bdd7 | 2010-04-05 16:05:39 -0300 | [diff] [blame] | 1077 | fh->pdi->stream)) != 0) { |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 1078 | /* Someone else must already have it */ |
| 1079 | return ret; |
| 1080 | } |
| 1081 | |
Joe Perches | 108bdd7 | 2010-04-05 16:05:39 -0300 | [diff] [blame] | 1082 | fh->rhp = pvr2_channel_create_mpeg_stream(fh->pdi->stream); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 1083 | if (!fh->rhp) { |
Mike Isely | a0fd1cb | 2006-06-30 11:35:28 -0300 | [diff] [blame] | 1084 | pvr2_channel_claim_stream(&fh->channel,NULL); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 1085 | return -ENOMEM; |
| 1086 | } |
| 1087 | |
| 1088 | hdw = fh->channel.mc_head->hdw; |
Joe Perches | 108bdd7 | 2010-04-05 16:05:39 -0300 | [diff] [blame] | 1089 | sp = fh->pdi->stream->stream; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 1090 | pvr2_stream_set_callback(sp,(pvr2_stream_callback)pvr2_v4l2_notify,fh); |
Joe Perches | 108bdd7 | 2010-04-05 16:05:39 -0300 | [diff] [blame] | 1091 | pvr2_hdw_set_stream_type(hdw,fh->pdi->config); |
Mike Isely | 681c739 | 2007-11-26 01:48:52 -0300 | [diff] [blame] | 1092 | if ((ret = pvr2_hdw_set_streaming(hdw,!0)) < 0) return ret; |
| 1093 | return pvr2_ioread_set_enabled(fh->rhp,!0); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 1094 | } |
| 1095 | |
| 1096 | |
| 1097 | static ssize_t pvr2_v4l2_read(struct file *file, |
| 1098 | char __user *buff, size_t count, loff_t *ppos) |
| 1099 | { |
| 1100 | struct pvr2_v4l2_fh *fh = file->private_data; |
| 1101 | int ret; |
| 1102 | |
| 1103 | if (fh->fw_mode_flag) { |
| 1104 | struct pvr2_hdw *hdw = fh->channel.mc_head->hdw; |
| 1105 | char *tbuf; |
| 1106 | int c1,c2; |
| 1107 | int tcnt = 0; |
| 1108 | unsigned int offs = *ppos; |
| 1109 | |
| 1110 | tbuf = kmalloc(PAGE_SIZE,GFP_KERNEL); |
| 1111 | if (!tbuf) return -ENOMEM; |
| 1112 | |
| 1113 | while (count) { |
| 1114 | c1 = count; |
| 1115 | if (c1 > PAGE_SIZE) c1 = PAGE_SIZE; |
| 1116 | c2 = pvr2_hdw_cpufw_get(hdw,offs,tbuf,c1); |
| 1117 | if (c2 < 0) { |
| 1118 | tcnt = c2; |
| 1119 | break; |
| 1120 | } |
| 1121 | if (!c2) break; |
| 1122 | if (copy_to_user(buff,tbuf,c2)) { |
| 1123 | tcnt = -EFAULT; |
| 1124 | break; |
| 1125 | } |
| 1126 | offs += c2; |
| 1127 | tcnt += c2; |
| 1128 | buff += c2; |
| 1129 | count -= c2; |
| 1130 | *ppos += c2; |
| 1131 | } |
| 1132 | kfree(tbuf); |
| 1133 | return tcnt; |
| 1134 | } |
| 1135 | |
| 1136 | if (!fh->rhp) { |
| 1137 | ret = pvr2_v4l2_iosetup(fh); |
| 1138 | if (ret) { |
| 1139 | return ret; |
| 1140 | } |
| 1141 | } |
| 1142 | |
| 1143 | for (;;) { |
| 1144 | ret = pvr2_ioread_read(fh->rhp,buff,count); |
| 1145 | if (ret >= 0) break; |
| 1146 | if (ret != -EAGAIN) break; |
| 1147 | if (file->f_flags & O_NONBLOCK) break; |
| 1148 | /* Doing blocking I/O. Wait here. */ |
| 1149 | ret = wait_event_interruptible( |
| 1150 | fh->wait_data, |
| 1151 | pvr2_ioread_avail(fh->rhp) >= 0); |
| 1152 | if (ret < 0) break; |
| 1153 | } |
| 1154 | |
| 1155 | return ret; |
| 1156 | } |
| 1157 | |
| 1158 | |
Al Viro | c23e0cb | 2017-07-03 03:02:56 -0400 | [diff] [blame] | 1159 | static __poll_t pvr2_v4l2_poll(struct file *file, poll_table *wait) |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 1160 | { |
Al Viro | c23e0cb | 2017-07-03 03:02:56 -0400 | [diff] [blame] | 1161 | __poll_t mask = 0; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 1162 | struct pvr2_v4l2_fh *fh = file->private_data; |
| 1163 | int ret; |
| 1164 | |
| 1165 | if (fh->fw_mode_flag) { |
Linus Torvalds | a9a0884 | 2018-02-11 14:34:03 -0800 | [diff] [blame] | 1166 | mask |= EPOLLIN | EPOLLRDNORM; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 1167 | return mask; |
| 1168 | } |
| 1169 | |
| 1170 | if (!fh->rhp) { |
| 1171 | ret = pvr2_v4l2_iosetup(fh); |
Linus Torvalds | a9a0884 | 2018-02-11 14:34:03 -0800 | [diff] [blame] | 1172 | if (ret) return EPOLLERR; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 1173 | } |
| 1174 | |
| 1175 | poll_wait(file,&fh->wait_data,wait); |
| 1176 | |
| 1177 | if (pvr2_ioread_avail(fh->rhp) >= 0) { |
Linus Torvalds | a9a0884 | 2018-02-11 14:34:03 -0800 | [diff] [blame] | 1178 | mask |= EPOLLIN | EPOLLRDNORM; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 1179 | } |
| 1180 | |
| 1181 | return mask; |
| 1182 | } |
| 1183 | |
| 1184 | |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 1185 | static const struct v4l2_file_operations vdev_fops = { |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 1186 | .owner = THIS_MODULE, |
| 1187 | .open = pvr2_v4l2_open, |
| 1188 | .release = pvr2_v4l2_release, |
| 1189 | .read = pvr2_v4l2_read, |
Hans Verkuil | eba09b5 | 2018-05-24 16:35:01 -0400 | [diff] [blame] | 1190 | .unlocked_ioctl = video_ioctl2, |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 1191 | .poll = pvr2_v4l2_poll, |
| 1192 | }; |
| 1193 | |
| 1194 | |
Bhumika Goyal | 8684494 | 2017-08-26 09:11:30 -0400 | [diff] [blame] | 1195 | static const struct video_device vdev_template = { |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 1196 | .fops = &vdev_fops, |
| 1197 | }; |
| 1198 | |
| 1199 | |
| 1200 | static void pvr2_v4l2_dev_init(struct pvr2_v4l2_dev *dip, |
| 1201 | struct pvr2_v4l2 *vp, |
Mike Isely | 16eb40d | 2006-12-30 18:27:32 -0300 | [diff] [blame] | 1202 | int v4l_type) |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 1203 | { |
| 1204 | int mindevnum; |
| 1205 | int unit_number; |
Mike Isely | 598e978 | 2012-02-20 02:35:20 -0300 | [diff] [blame] | 1206 | struct pvr2_hdw *hdw; |
Al Viro | 89952d1 | 2007-03-14 09:17:59 +0000 | [diff] [blame] | 1207 | int *nr_ptr = NULL; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 1208 | dip->v4lp = vp; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 1209 | |
Mike Isely | 598e978 | 2012-02-20 02:35:20 -0300 | [diff] [blame] | 1210 | hdw = vp->channel.mc_head->hdw; |
Mike Isely | 16eb40d | 2006-12-30 18:27:32 -0300 | [diff] [blame] | 1211 | dip->v4l_type = v4l_type; |
| 1212 | switch (v4l_type) { |
| 1213 | case VFL_TYPE_GRABBER: |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 1214 | dip->stream = &vp->channel.mc_head->video_stream; |
Mike Isely | 16eb40d | 2006-12-30 18:27:32 -0300 | [diff] [blame] | 1215 | dip->config = pvr2_config_mpeg; |
| 1216 | dip->minor_type = pvr2_v4l_type_video; |
| 1217 | nr_ptr = video_nr; |
Mike Isely | c74e006 | 2006-12-30 18:31:22 -0300 | [diff] [blame] | 1218 | if (!dip->stream) { |
Mauro Carvalho Chehab | be9ed51 | 2009-01-08 09:13:42 -0300 | [diff] [blame] | 1219 | pr_err(KBUILD_MODNAME |
Mauro Carvalho Chehab | 96292c8 | 2016-10-18 17:44:18 -0200 | [diff] [blame] | 1220 | ": Failed to set up pvrusb2 v4l video dev due to missing stream instance\n"); |
Mike Isely | c74e006 | 2006-12-30 18:31:22 -0300 | [diff] [blame] | 1221 | return; |
| 1222 | } |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 1223 | break; |
Mike Isely | 16eb40d | 2006-12-30 18:27:32 -0300 | [diff] [blame] | 1224 | case VFL_TYPE_VBI: |
| 1225 | dip->config = pvr2_config_vbi; |
| 1226 | dip->minor_type = pvr2_v4l_type_vbi; |
| 1227 | nr_ptr = vbi_nr; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 1228 | break; |
Mike Isely | 16eb40d | 2006-12-30 18:27:32 -0300 | [diff] [blame] | 1229 | case VFL_TYPE_RADIO: |
Mike Isely | af78a48 | 2007-01-20 00:04:31 -0300 | [diff] [blame] | 1230 | dip->stream = &vp->channel.mc_head->video_stream; |
| 1231 | dip->config = pvr2_config_mpeg; |
Mike Isely | 16eb40d | 2006-12-30 18:27:32 -0300 | [diff] [blame] | 1232 | dip->minor_type = pvr2_v4l_type_radio; |
| 1233 | nr_ptr = radio_nr; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 1234 | break; |
| 1235 | default: |
| 1236 | /* Bail out (this should be impossible) */ |
Mauro Carvalho Chehab | 96292c8 | 2016-10-18 17:44:18 -0200 | [diff] [blame] | 1237 | pr_err(KBUILD_MODNAME ": Failed to set up pvrusb2 v4l dev due to unrecognized config\n"); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 1238 | return; |
| 1239 | } |
| 1240 | |
Ezequiel Garcia | 5338c16 | 2012-10-23 15:57:09 -0300 | [diff] [blame] | 1241 | dip->devbase = vdev_template; |
Mike Isely | 7591005 | 2006-09-23 22:30:50 -0300 | [diff] [blame] | 1242 | dip->devbase.release = pvr2_video_device_release; |
Hans Verkuil | c6d26cf | 2012-02-20 02:21:00 -0300 | [diff] [blame] | 1243 | dip->devbase.ioctl_ops = &pvr2_ioctl_ops; |
Mike Isely | d8329f8 | 2012-02-20 02:33:06 -0300 | [diff] [blame] | 1244 | { |
| 1245 | int val; |
| 1246 | pvr2_ctrl_get_value( |
Mike Isely | 598e978 | 2012-02-20 02:35:20 -0300 | [diff] [blame] | 1247 | pvr2_hdw_get_ctrl_by_id(hdw, |
Mike Isely | d8329f8 | 2012-02-20 02:33:06 -0300 | [diff] [blame] | 1248 | PVR2_CID_STDAVAIL), &val); |
| 1249 | dip->devbase.tvnorms = (v4l2_std_id)val; |
| 1250 | } |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 1251 | |
| 1252 | mindevnum = -1; |
Mike Isely | 598e978 | 2012-02-20 02:35:20 -0300 | [diff] [blame] | 1253 | unit_number = pvr2_hdw_get_unit_number(hdw); |
Mike Isely | 16eb40d | 2006-12-30 18:27:32 -0300 | [diff] [blame] | 1254 | if (nr_ptr && (unit_number >= 0) && (unit_number < PVR_NUM)) { |
| 1255 | mindevnum = nr_ptr[unit_number]; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 1256 | } |
Hans Verkuil | a28fbd0 | 2013-06-10 09:16:25 -0300 | [diff] [blame] | 1257 | pvr2_hdw_set_v4l2_dev(hdw, &dip->devbase); |
Mike Isely | 16eb40d | 2006-12-30 18:27:32 -0300 | [diff] [blame] | 1258 | if ((video_register_device(&dip->devbase, |
| 1259 | dip->v4l_type, mindevnum) < 0) && |
| 1260 | (video_register_device(&dip->devbase, |
| 1261 | dip->v4l_type, -1) < 0)) { |
Mauro Carvalho Chehab | be9ed51 | 2009-01-08 09:13:42 -0300 | [diff] [blame] | 1262 | pr_err(KBUILD_MODNAME |
| 1263 | ": Failed to register pvrusb2 v4l device\n"); |
Pantelis Koukousoulas | ae2b9e2 | 2006-12-27 23:09:55 -0300 | [diff] [blame] | 1264 | } |
Mike Isely | 16eb40d | 2006-12-30 18:27:32 -0300 | [diff] [blame] | 1265 | |
Dafna Hirschfeld | 8f845c6 | 2018-10-08 08:06:47 -0400 | [diff] [blame] | 1266 | pr_info("pvrusb2: registered device %s [%s]\n", |
Laurent Pinchart | 38c7c03 | 2009-11-27 13:57:15 -0300 | [diff] [blame] | 1267 | video_device_node_name(&dip->devbase), |
Mike Isely | 16eb40d | 2006-12-30 18:27:32 -0300 | [diff] [blame] | 1268 | pvr2_config_get_name(dip->config)); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 1269 | |
Mike Isely | 598e978 | 2012-02-20 02:35:20 -0300 | [diff] [blame] | 1270 | pvr2_hdw_v4l_store_minor_number(hdw, |
Mike Isely | 16eb40d | 2006-12-30 18:27:32 -0300 | [diff] [blame] | 1271 | dip->minor_type,dip->devbase.minor); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 1272 | } |
| 1273 | |
| 1274 | |
| 1275 | struct pvr2_v4l2 *pvr2_v4l2_create(struct pvr2_context *mnp) |
| 1276 | { |
| 1277 | struct pvr2_v4l2 *vp; |
| 1278 | |
Mike Isely | 4b85dee | 2007-01-20 00:03:32 -0300 | [diff] [blame] | 1279 | vp = kzalloc(sizeof(*vp),GFP_KERNEL); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 1280 | if (!vp) return vp; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 1281 | pvr2_channel_init(&vp->channel,mnp); |
| 1282 | pvr2_trace(PVR2_TRACE_STRUCT,"Creating pvr2_v4l2 id=%p",vp); |
| 1283 | |
| 1284 | vp->channel.check_func = pvr2_v4l2_internal_check; |
| 1285 | |
| 1286 | /* register streams */ |
Mike Isely | beb0ecd | 2008-04-22 14:45:38 -0300 | [diff] [blame] | 1287 | vp->dev_video = kzalloc(sizeof(*vp->dev_video),GFP_KERNEL); |
| 1288 | if (!vp->dev_video) goto fail; |
Mike Isely | 16eb40d | 2006-12-30 18:27:32 -0300 | [diff] [blame] | 1289 | pvr2_v4l2_dev_init(vp->dev_video,vp,VFL_TYPE_GRABBER); |
Mike Isely | e57b1c8 | 2008-04-21 03:52:34 -0300 | [diff] [blame] | 1290 | if (pvr2_hdw_get_input_available(vp->channel.mc_head->hdw) & |
| 1291 | (1 << PVR2_CVAL_INPUT_RADIO)) { |
Mike Isely | beb0ecd | 2008-04-22 14:45:38 -0300 | [diff] [blame] | 1292 | vp->dev_radio = kzalloc(sizeof(*vp->dev_radio),GFP_KERNEL); |
| 1293 | if (!vp->dev_radio) goto fail; |
| 1294 | pvr2_v4l2_dev_init(vp->dev_radio,vp,VFL_TYPE_RADIO); |
| 1295 | } |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 1296 | |
| 1297 | return vp; |
Mike Isely | beb0ecd | 2008-04-22 14:45:38 -0300 | [diff] [blame] | 1298 | fail: |
| 1299 | pvr2_trace(PVR2_TRACE_STRUCT,"Failure creating pvr2_v4l2 id=%p",vp); |
| 1300 | pvr2_v4l2_destroy_no_lock(vp); |
Harvey Harrison | a6a3a17 | 2008-04-28 16:50:03 -0700 | [diff] [blame] | 1301 | return NULL; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 1302 | } |