Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2005-2006 Micronas USA Inc. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License (Version 2) as |
| 6 | * published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 12 | */ |
| 13 | |
| 14 | #include <linux/module.h> |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 15 | #include <linux/delay.h> |
| 16 | #include <linux/sched.h> |
| 17 | #include <linux/spinlock.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 18 | #include <linux/slab.h> |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 19 | #include <linux/fs.h> |
| 20 | #include <linux/unistd.h> |
| 21 | #include <linux/time.h> |
| 22 | #include <linux/vmalloc.h> |
| 23 | #include <linux/pagemap.h> |
Hans Verkuil | bae7432 | 2013-03-09 11:08:41 -0300 | [diff] [blame] | 24 | #include <linux/i2c.h> |
| 25 | #include <linux/mutex.h> |
| 26 | #include <linux/uaccess.h> |
Ross Cohen | df20d69 | 2008-09-29 22:36:24 -0400 | [diff] [blame] | 27 | #include <linux/videodev2.h> |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 28 | #include <media/v4l2-common.h> |
| 29 | #include <media/v4l2-ioctl.h> |
Pete Eberlein | fa3c39b | 2009-11-16 15:16:00 -0300 | [diff] [blame] | 30 | #include <media/v4l2-subdev.h> |
Hans Verkuil | bae7432 | 2013-03-09 11:08:41 -0300 | [diff] [blame] | 31 | #include <media/v4l2-event.h> |
Hans Verkuil | ffcc1c0 | 2013-03-11 06:52:27 -0300 | [diff] [blame] | 32 | #include <media/videobuf2-vmalloc.h> |
Mauro Carvalho Chehab | b5dcee2 | 2015-11-10 12:01:44 -0200 | [diff] [blame] | 33 | #include <media/i2c/saa7115.h> |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 34 | |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 35 | #include "go7007-priv.h" |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 36 | |
Pete Eberlein | fa3c39b | 2009-11-16 15:16:00 -0300 | [diff] [blame] | 37 | #define call_all(dev, o, f, args...) \ |
| 38 | v4l2_device_call_until_err(dev, 0, o, f, ##args) |
| 39 | |
Hans Verkuil | 35d2d76 | 2013-03-11 05:58:55 -0300 | [diff] [blame] | 40 | static bool valid_pixelformat(u32 pixelformat) |
| 41 | { |
| 42 | switch (pixelformat) { |
| 43 | case V4L2_PIX_FMT_MJPEG: |
| 44 | case V4L2_PIX_FMT_MPEG1: |
| 45 | case V4L2_PIX_FMT_MPEG2: |
| 46 | case V4L2_PIX_FMT_MPEG4: |
| 47 | return true; |
| 48 | default: |
| 49 | return false; |
| 50 | } |
| 51 | } |
| 52 | |
Hans Verkuil | ffcc1c0 | 2013-03-11 06:52:27 -0300 | [diff] [blame] | 53 | static u32 get_frame_type_flag(struct go7007_buffer *vb, int format) |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 54 | { |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 55 | u8 *ptr = vb2_plane_vaddr(&vb->vb.vb2_buf, 0); |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 56 | |
| 57 | switch (format) { |
Hans Verkuil | 35d2d76 | 2013-03-11 05:58:55 -0300 | [diff] [blame] | 58 | case V4L2_PIX_FMT_MJPEG: |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 59 | return V4L2_BUF_FLAG_KEYFRAME; |
Hans Verkuil | 35d2d76 | 2013-03-11 05:58:55 -0300 | [diff] [blame] | 60 | case V4L2_PIX_FMT_MPEG4: |
Hans Verkuil | ffcc1c0 | 2013-03-11 06:52:27 -0300 | [diff] [blame] | 61 | switch ((ptr[vb->frame_offset + 4] >> 6) & 0x3) { |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 62 | case 0: |
| 63 | return V4L2_BUF_FLAG_KEYFRAME; |
| 64 | case 1: |
| 65 | return V4L2_BUF_FLAG_PFRAME; |
| 66 | case 2: |
| 67 | return V4L2_BUF_FLAG_BFRAME; |
| 68 | default: |
| 69 | return 0; |
| 70 | } |
Hans Verkuil | 35d2d76 | 2013-03-11 05:58:55 -0300 | [diff] [blame] | 71 | case V4L2_PIX_FMT_MPEG1: |
| 72 | case V4L2_PIX_FMT_MPEG2: |
Hans Verkuil | ffcc1c0 | 2013-03-11 06:52:27 -0300 | [diff] [blame] | 73 | switch ((ptr[vb->frame_offset + 5] >> 3) & 0x7) { |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 74 | case 1: |
| 75 | return V4L2_BUF_FLAG_KEYFRAME; |
| 76 | case 2: |
| 77 | return V4L2_BUF_FLAG_PFRAME; |
| 78 | case 3: |
| 79 | return V4L2_BUF_FLAG_BFRAME; |
| 80 | default: |
| 81 | return 0; |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | return 0; |
| 86 | } |
| 87 | |
Hans Verkuil | 50deb74 | 2013-03-11 05:50:21 -0300 | [diff] [blame] | 88 | static void get_resolution(struct go7007 *go, int *width, int *height) |
| 89 | { |
| 90 | switch (go->standard) { |
| 91 | case GO7007_STD_NTSC: |
| 92 | *width = 720; |
| 93 | *height = 480; |
| 94 | break; |
| 95 | case GO7007_STD_PAL: |
| 96 | *width = 720; |
| 97 | *height = 576; |
| 98 | break; |
| 99 | case GO7007_STD_OTHER: |
| 100 | default: |
| 101 | *width = go->board_info->sensor_width; |
| 102 | *height = go->board_info->sensor_height; |
| 103 | break; |
| 104 | } |
| 105 | } |
| 106 | |
Hans Verkuil | 35d2d76 | 2013-03-11 05:58:55 -0300 | [diff] [blame] | 107 | static void set_formatting(struct go7007 *go) |
| 108 | { |
| 109 | if (go->format == V4L2_PIX_FMT_MJPEG) { |
| 110 | go->pali = 0; |
| 111 | go->aspect_ratio = GO7007_RATIO_1_1; |
| 112 | go->gop_size = 0; |
| 113 | go->ipb = 0; |
| 114 | go->closed_gop = 0; |
| 115 | go->repeat_seqhead = 0; |
| 116 | go->seq_header_enable = 0; |
| 117 | go->gop_header_enable = 0; |
| 118 | go->dvd_mode = 0; |
| 119 | return; |
| 120 | } |
| 121 | |
| 122 | switch (go->format) { |
| 123 | case V4L2_PIX_FMT_MPEG1: |
| 124 | go->pali = 0; |
| 125 | break; |
| 126 | default: |
| 127 | case V4L2_PIX_FMT_MPEG2: |
| 128 | go->pali = 0x48; |
| 129 | break; |
| 130 | case V4L2_PIX_FMT_MPEG4: |
| 131 | /* For future reference: this is the list of MPEG4 |
| 132 | * profiles that are available, although they are |
| 133 | * untested: |
| 134 | * |
| 135 | * Profile pali |
| 136 | * -------------- ---- |
| 137 | * PROFILE_S_L0 0x08 |
| 138 | * PROFILE_S_L1 0x01 |
| 139 | * PROFILE_S_L2 0x02 |
| 140 | * PROFILE_S_L3 0x03 |
| 141 | * PROFILE_ARTS_L1 0x91 |
| 142 | * PROFILE_ARTS_L2 0x92 |
| 143 | * PROFILE_ARTS_L3 0x93 |
| 144 | * PROFILE_ARTS_L4 0x94 |
| 145 | * PROFILE_AS_L0 0xf0 |
| 146 | * PROFILE_AS_L1 0xf1 |
| 147 | * PROFILE_AS_L2 0xf2 |
| 148 | * PROFILE_AS_L3 0xf3 |
| 149 | * PROFILE_AS_L4 0xf4 |
| 150 | * PROFILE_AS_L5 0xf5 |
| 151 | */ |
| 152 | go->pali = 0xf5; |
| 153 | break; |
| 154 | } |
| 155 | go->gop_size = v4l2_ctrl_g_ctrl(go->mpeg_video_gop_size); |
| 156 | go->closed_gop = v4l2_ctrl_g_ctrl(go->mpeg_video_gop_closure); |
Volokh Konstantin | 7e4bfb9 | 2013-03-17 07:16:37 -0300 | [diff] [blame] | 157 | go->ipb = v4l2_ctrl_g_ctrl(go->mpeg_video_b_frames) != 0; |
Hans Verkuil | 35d2d76 | 2013-03-11 05:58:55 -0300 | [diff] [blame] | 158 | go->bitrate = v4l2_ctrl_g_ctrl(go->mpeg_video_bitrate); |
Hans Verkuil | 778ca51 | 2013-03-17 10:47:02 -0300 | [diff] [blame] | 159 | go->repeat_seqhead = v4l2_ctrl_g_ctrl(go->mpeg_video_rep_seqheader); |
Hans Verkuil | 35d2d76 | 2013-03-11 05:58:55 -0300 | [diff] [blame] | 160 | go->gop_header_enable = 1; |
| 161 | go->dvd_mode = 0; |
| 162 | if (go->format == V4L2_PIX_FMT_MPEG2) |
| 163 | go->dvd_mode = |
| 164 | go->bitrate == 9800000 && |
| 165 | go->gop_size == 15 && |
Volokh Konstantin | 7e4bfb9 | 2013-03-17 07:16:37 -0300 | [diff] [blame] | 166 | go->ipb == 0 && |
Hans Verkuil | 778ca51 | 2013-03-17 10:47:02 -0300 | [diff] [blame] | 167 | go->repeat_seqhead == 1 && |
Hans Verkuil | 35d2d76 | 2013-03-11 05:58:55 -0300 | [diff] [blame] | 168 | go->closed_gop; |
Hans Verkuil | 35d2d76 | 2013-03-11 05:58:55 -0300 | [diff] [blame] | 169 | |
| 170 | switch (v4l2_ctrl_g_ctrl(go->mpeg_video_aspect_ratio)) { |
| 171 | default: |
| 172 | case V4L2_MPEG_VIDEO_ASPECT_1x1: |
| 173 | go->aspect_ratio = GO7007_RATIO_1_1; |
| 174 | break; |
| 175 | case V4L2_MPEG_VIDEO_ASPECT_4x3: |
| 176 | go->aspect_ratio = GO7007_RATIO_4_3; |
| 177 | break; |
| 178 | case V4L2_MPEG_VIDEO_ASPECT_16x9: |
| 179 | go->aspect_ratio = GO7007_RATIO_16_9; |
| 180 | break; |
| 181 | } |
| 182 | } |
| 183 | |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 184 | static int set_capture_size(struct go7007 *go, struct v4l2_format *fmt, int try) |
| 185 | { |
| 186 | int sensor_height = 0, sensor_width = 0; |
Hans Verkuil | 0ee58f8 | 2014-06-10 07:39:04 -0300 | [diff] [blame] | 187 | int width, height; |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 188 | |
Hans Verkuil | 35d2d76 | 2013-03-11 05:58:55 -0300 | [diff] [blame] | 189 | if (fmt != NULL && !valid_pixelformat(fmt->fmt.pix.pixelformat)) |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 190 | return -EINVAL; |
| 191 | |
Hans Verkuil | 50deb74 | 2013-03-11 05:50:21 -0300 | [diff] [blame] | 192 | get_resolution(go, &sensor_width, &sensor_height); |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 193 | |
| 194 | if (fmt == NULL) { |
| 195 | width = sensor_width; |
| 196 | height = sensor_height; |
| 197 | } else if (go->board_info->sensor_flags & GO7007_SENSOR_SCALING) { |
| 198 | if (fmt->fmt.pix.width > sensor_width) |
| 199 | width = sensor_width; |
| 200 | else if (fmt->fmt.pix.width < 144) |
| 201 | width = 144; |
| 202 | else |
| 203 | width = fmt->fmt.pix.width & ~0x0f; |
| 204 | |
| 205 | if (fmt->fmt.pix.height > sensor_height) |
| 206 | height = sensor_height; |
| 207 | else if (fmt->fmt.pix.height < 96) |
| 208 | height = 96; |
| 209 | else |
| 210 | height = fmt->fmt.pix.height & ~0x0f; |
| 211 | } else { |
Hans Verkuil | 50deb74 | 2013-03-11 05:50:21 -0300 | [diff] [blame] | 212 | width = fmt->fmt.pix.width; |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 213 | |
Hans Verkuil | 50deb74 | 2013-03-11 05:50:21 -0300 | [diff] [blame] | 214 | if (width <= sensor_width / 4) { |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 215 | width = sensor_width / 4; |
| 216 | height = sensor_height / 4; |
Hans Verkuil | 50deb74 | 2013-03-11 05:50:21 -0300 | [diff] [blame] | 217 | } else if (width <= sensor_width / 2) { |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 218 | width = sensor_width / 2; |
| 219 | height = sensor_height / 2; |
| 220 | } else { |
| 221 | width = sensor_width; |
| 222 | height = sensor_height; |
| 223 | } |
| 224 | width &= ~0xf; |
| 225 | height &= ~0xf; |
| 226 | } |
| 227 | |
| 228 | if (fmt != NULL) { |
| 229 | u32 pixelformat = fmt->fmt.pix.pixelformat; |
| 230 | |
| 231 | memset(fmt, 0, sizeof(*fmt)); |
| 232 | fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 233 | fmt->fmt.pix.width = width; |
| 234 | fmt->fmt.pix.height = height; |
| 235 | fmt->fmt.pix.pixelformat = pixelformat; |
| 236 | fmt->fmt.pix.field = V4L2_FIELD_NONE; |
| 237 | fmt->fmt.pix.bytesperline = 0; |
| 238 | fmt->fmt.pix.sizeimage = GO7007_BUF_SIZE; |
Hans Verkuil | 50deb74 | 2013-03-11 05:50:21 -0300 | [diff] [blame] | 239 | fmt->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | if (try) |
| 243 | return 0; |
| 244 | |
Hans Verkuil | 35d2d76 | 2013-03-11 05:58:55 -0300 | [diff] [blame] | 245 | if (fmt) |
| 246 | go->format = fmt->fmt.pix.pixelformat; |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 247 | go->width = width; |
| 248 | go->height = height; |
| 249 | go->encoder_h_offset = go->board_info->sensor_h_offset; |
| 250 | go->encoder_v_offset = go->board_info->sensor_v_offset; |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 251 | |
| 252 | if (go->board_info->sensor_flags & GO7007_SENSOR_SCALING) { |
Hans Verkuil | ebf984b | 2015-04-09 04:05:59 -0300 | [diff] [blame] | 253 | struct v4l2_subdev_format format = { |
| 254 | .which = V4L2_SUBDEV_FORMAT_ACTIVE, |
| 255 | }; |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 256 | |
Hans Verkuil | ebf984b | 2015-04-09 04:05:59 -0300 | [diff] [blame] | 257 | format.format.code = MEDIA_BUS_FMT_FIXED; |
| 258 | format.format.width = fmt ? fmt->fmt.pix.width : width; |
| 259 | format.format.height = height; |
Hans Verkuil | 50deb74 | 2013-03-11 05:50:21 -0300 | [diff] [blame] | 260 | go->encoder_h_halve = 0; |
| 261 | go->encoder_v_halve = 0; |
| 262 | go->encoder_subsample = 0; |
Hans Verkuil | ebf984b | 2015-04-09 04:05:59 -0300 | [diff] [blame] | 263 | call_all(&go->v4l2_dev, pad, set_fmt, NULL, &format); |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 264 | } else { |
| 265 | if (width <= sensor_width / 4) { |
| 266 | go->encoder_h_halve = 1; |
| 267 | go->encoder_v_halve = 1; |
| 268 | go->encoder_subsample = 1; |
| 269 | } else if (width <= sensor_width / 2) { |
| 270 | go->encoder_h_halve = 1; |
| 271 | go->encoder_v_halve = 1; |
| 272 | go->encoder_subsample = 0; |
| 273 | } else { |
| 274 | go->encoder_h_halve = 0; |
| 275 | go->encoder_v_halve = 0; |
| 276 | go->encoder_subsample = 0; |
| 277 | } |
| 278 | } |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 279 | return 0; |
| 280 | } |
| 281 | |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 282 | static int vidioc_querycap(struct file *file, void *priv, |
| 283 | struct v4l2_capability *cap) |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 284 | { |
Hans Verkuil | 899eb84 | 2013-03-11 06:18:20 -0300 | [diff] [blame] | 285 | struct go7007 *go = video_drvdata(file); |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 286 | |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 287 | strlcpy(cap->driver, "go7007", sizeof(cap->driver)); |
| 288 | strlcpy(cap->card, go->name, sizeof(cap->card)); |
Hans Verkuil | 4d217b8 | 2013-03-09 09:38:03 -0300 | [diff] [blame] | 289 | strlcpy(cap->bus_info, go->bus_info, sizeof(cap->bus_info)); |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 290 | |
Hans Verkuil | ffcc1c0 | 2013-03-11 06:52:27 -0300 | [diff] [blame] | 291 | cap->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_READWRITE | |
| 292 | V4L2_CAP_STREAMING; |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 293 | |
Hans Verkuil | 5e41054 | 2013-03-09 13:19:08 -0300 | [diff] [blame] | 294 | if (go->board_info->num_aud_inputs) |
| 295 | cap->device_caps |= V4L2_CAP_AUDIO; |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 296 | if (go->board_info->flags & GO7007_BOARD_HAS_TUNER) |
Hans Verkuil | 4d217b8 | 2013-03-09 09:38:03 -0300 | [diff] [blame] | 297 | cap->device_caps |= V4L2_CAP_TUNER; |
| 298 | cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS; |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 299 | return 0; |
| 300 | } |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 301 | |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 302 | static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv, |
| 303 | struct v4l2_fmtdesc *fmt) |
| 304 | { |
| 305 | char *desc = NULL; |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 306 | |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 307 | switch (fmt->index) { |
| 308 | case 0: |
| 309 | fmt->pixelformat = V4L2_PIX_FMT_MJPEG; |
Hans Verkuil | 35d2d76 | 2013-03-11 05:58:55 -0300 | [diff] [blame] | 310 | desc = "Motion JPEG"; |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 311 | break; |
| 312 | case 1: |
Hans Verkuil | 35d2d76 | 2013-03-11 05:58:55 -0300 | [diff] [blame] | 313 | fmt->pixelformat = V4L2_PIX_FMT_MPEG1; |
| 314 | desc = "MPEG-1 ES"; |
| 315 | break; |
| 316 | case 2: |
| 317 | fmt->pixelformat = V4L2_PIX_FMT_MPEG2; |
| 318 | desc = "MPEG-2 ES"; |
| 319 | break; |
| 320 | case 3: |
| 321 | fmt->pixelformat = V4L2_PIX_FMT_MPEG4; |
| 322 | desc = "MPEG-4 ES"; |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 323 | break; |
| 324 | default: |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 325 | return -EINVAL; |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 326 | } |
| 327 | fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 328 | fmt->flags = V4L2_FMT_FLAG_COMPRESSED; |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 329 | |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 330 | strncpy(fmt->description, desc, sizeof(fmt->description)); |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 331 | |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 332 | return 0; |
| 333 | } |
| 334 | |
| 335 | static int vidioc_g_fmt_vid_cap(struct file *file, void *priv, |
| 336 | struct v4l2_format *fmt) |
| 337 | { |
Hans Verkuil | 899eb84 | 2013-03-11 06:18:20 -0300 | [diff] [blame] | 338 | struct go7007 *go = video_drvdata(file); |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 339 | |
| 340 | fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 341 | fmt->fmt.pix.width = go->width; |
| 342 | fmt->fmt.pix.height = go->height; |
Hans Verkuil | 35d2d76 | 2013-03-11 05:58:55 -0300 | [diff] [blame] | 343 | fmt->fmt.pix.pixelformat = go->format; |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 344 | fmt->fmt.pix.field = V4L2_FIELD_NONE; |
| 345 | fmt->fmt.pix.bytesperline = 0; |
| 346 | fmt->fmt.pix.sizeimage = GO7007_BUF_SIZE; |
| 347 | fmt->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; |
| 348 | |
| 349 | return 0; |
| 350 | } |
| 351 | |
| 352 | static int vidioc_try_fmt_vid_cap(struct file *file, void *priv, |
| 353 | struct v4l2_format *fmt) |
| 354 | { |
Hans Verkuil | 899eb84 | 2013-03-11 06:18:20 -0300 | [diff] [blame] | 355 | struct go7007 *go = video_drvdata(file); |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 356 | |
| 357 | return set_capture_size(go, fmt, 1); |
| 358 | } |
| 359 | |
| 360 | static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, |
| 361 | struct v4l2_format *fmt) |
| 362 | { |
Hans Verkuil | 899eb84 | 2013-03-11 06:18:20 -0300 | [diff] [blame] | 363 | struct go7007 *go = video_drvdata(file); |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 364 | |
Hans Verkuil | ffcc1c0 | 2013-03-11 06:52:27 -0300 | [diff] [blame] | 365 | if (vb2_is_busy(&go->vidq)) |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 366 | return -EBUSY; |
| 367 | |
| 368 | return set_capture_size(go, fmt, 0); |
| 369 | } |
| 370 | |
Aybuke Ozdemir | 5935cae | 2014-03-15 19:10:16 +0200 | [diff] [blame] | 371 | static int go7007_queue_setup(struct vb2_queue *q, |
Hans Verkuil | ffcc1c0 | 2013-03-11 06:52:27 -0300 | [diff] [blame] | 372 | unsigned int *num_buffers, unsigned int *num_planes, |
Hans Verkuil | 36c0f8b | 2016-04-15 09:15:05 -0300 | [diff] [blame] | 373 | unsigned int sizes[], struct device *alloc_devs[]) |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 374 | { |
Hans Verkuil | ffcc1c0 | 2013-03-11 06:52:27 -0300 | [diff] [blame] | 375 | sizes[0] = GO7007_BUF_SIZE; |
| 376 | *num_planes = 1; |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 377 | |
Hans Verkuil | ffcc1c0 | 2013-03-11 06:52:27 -0300 | [diff] [blame] | 378 | if (*num_buffers < 2) |
| 379 | *num_buffers = 2; |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 380 | |
Hans Verkuil | ffcc1c0 | 2013-03-11 06:52:27 -0300 | [diff] [blame] | 381 | return 0; |
| 382 | } |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 383 | |
Hans Verkuil | ffcc1c0 | 2013-03-11 06:52:27 -0300 | [diff] [blame] | 384 | static void go7007_buf_queue(struct vb2_buffer *vb) |
| 385 | { |
| 386 | struct vb2_queue *vq = vb->vb2_queue; |
| 387 | struct go7007 *go = vb2_get_drv_priv(vq); |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 388 | struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); |
Hans Verkuil | ffcc1c0 | 2013-03-11 06:52:27 -0300 | [diff] [blame] | 389 | struct go7007_buffer *go7007_vb = |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 390 | container_of(vbuf, struct go7007_buffer, vb); |
Hans Verkuil | ffcc1c0 | 2013-03-11 06:52:27 -0300 | [diff] [blame] | 391 | unsigned long flags; |
| 392 | |
| 393 | spin_lock_irqsave(&go->spinlock, flags); |
| 394 | list_add_tail(&go7007_vb->list, &go->vidq_active); |
| 395 | spin_unlock_irqrestore(&go->spinlock, flags); |
| 396 | } |
| 397 | |
| 398 | static int go7007_buf_prepare(struct vb2_buffer *vb) |
| 399 | { |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 400 | struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); |
Hans Verkuil | ffcc1c0 | 2013-03-11 06:52:27 -0300 | [diff] [blame] | 401 | struct go7007_buffer *go7007_vb = |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 402 | container_of(vbuf, struct go7007_buffer, vb); |
Hans Verkuil | ffcc1c0 | 2013-03-11 06:52:27 -0300 | [diff] [blame] | 403 | |
| 404 | go7007_vb->modet_active = 0; |
| 405 | go7007_vb->frame_offset = 0; |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 406 | vb->planes[0].bytesused = 0; |
Hans Verkuil | ffcc1c0 | 2013-03-11 06:52:27 -0300 | [diff] [blame] | 407 | return 0; |
| 408 | } |
| 409 | |
Hans Verkuil | 0647064 | 2014-03-04 07:27:13 -0300 | [diff] [blame] | 410 | static void go7007_buf_finish(struct vb2_buffer *vb) |
Hans Verkuil | ffcc1c0 | 2013-03-11 06:52:27 -0300 | [diff] [blame] | 411 | { |
| 412 | struct vb2_queue *vq = vb->vb2_queue; |
| 413 | struct go7007 *go = vb2_get_drv_priv(vq); |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 414 | struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); |
Hans Verkuil | ffcc1c0 | 2013-03-11 06:52:27 -0300 | [diff] [blame] | 415 | struct go7007_buffer *go7007_vb = |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 416 | container_of(vbuf, struct go7007_buffer, vb); |
Hans Verkuil | ffcc1c0 | 2013-03-11 06:52:27 -0300 | [diff] [blame] | 417 | u32 frame_type_flag = get_frame_type_flag(go7007_vb, go->format); |
Hans Verkuil | ffcc1c0 | 2013-03-11 06:52:27 -0300 | [diff] [blame] | 418 | |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 419 | vbuf->flags &= ~(V4L2_BUF_FLAG_KEYFRAME | V4L2_BUF_FLAG_BFRAME | |
Hans Verkuil | ffcc1c0 | 2013-03-11 06:52:27 -0300 | [diff] [blame] | 420 | V4L2_BUF_FLAG_PFRAME); |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 421 | vbuf->flags |= frame_type_flag; |
| 422 | vbuf->field = V4L2_FIELD_NONE; |
Hans Verkuil | ffcc1c0 | 2013-03-11 06:52:27 -0300 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | static int go7007_start_streaming(struct vb2_queue *q, unsigned int count) |
| 426 | { |
| 427 | struct go7007 *go = vb2_get_drv_priv(q); |
| 428 | int ret; |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 429 | |
Hans Verkuil | 35d2d76 | 2013-03-11 05:58:55 -0300 | [diff] [blame] | 430 | set_formatting(go); |
Mauro Carvalho Chehab | fd9a40d | 2009-09-15 11:07:59 -0300 | [diff] [blame] | 431 | mutex_lock(&go->hw_lock); |
Hans Verkuil | ffcc1c0 | 2013-03-11 06:52:27 -0300 | [diff] [blame] | 432 | go->next_seq = 0; |
| 433 | go->active_buf = NULL; |
Hans Verkuil | 0ee58f8 | 2014-06-10 07:39:04 -0300 | [diff] [blame] | 434 | go->modet_event_status = 0; |
Hans Verkuil | ffcc1c0 | 2013-03-11 06:52:27 -0300 | [diff] [blame] | 435 | q->streaming = 1; |
| 436 | if (go7007_start_encoder(go) < 0) |
| 437 | ret = -EIO; |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 438 | else |
Hans Verkuil | ffcc1c0 | 2013-03-11 06:52:27 -0300 | [diff] [blame] | 439 | ret = 0; |
Mauro Carvalho Chehab | fd9a40d | 2009-09-15 11:07:59 -0300 | [diff] [blame] | 440 | mutex_unlock(&go->hw_lock); |
Hans Verkuil | ffcc1c0 | 2013-03-11 06:52:27 -0300 | [diff] [blame] | 441 | if (ret) { |
| 442 | q->streaming = 0; |
| 443 | return ret; |
| 444 | } |
Volokh Konstantin | 0a147c3 | 2013-01-16 09:00:51 -0300 | [diff] [blame] | 445 | call_all(&go->v4l2_dev, video, s_stream, 1); |
Hans Verkuil | 35d2d76 | 2013-03-11 05:58:55 -0300 | [diff] [blame] | 446 | v4l2_ctrl_grab(go->mpeg_video_gop_size, true); |
| 447 | v4l2_ctrl_grab(go->mpeg_video_gop_closure, true); |
| 448 | v4l2_ctrl_grab(go->mpeg_video_bitrate, true); |
| 449 | v4l2_ctrl_grab(go->mpeg_video_aspect_ratio, true); |
Hans Verkuil | 1f1aed2 | 2013-03-17 10:15:03 -0300 | [diff] [blame] | 450 | /* Turn on Capture LED */ |
| 451 | if (go->board_id == GO7007_BOARDID_ADS_USBAV_709) |
| 452 | go7007_write_addr(go, 0x3c82, 0x0005); |
Hans Verkuil | ffcc1c0 | 2013-03-11 06:52:27 -0300 | [diff] [blame] | 453 | return ret; |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 454 | } |
Pete Eberlein | d73f822 | 2008-10-30 12:56:33 -0700 | [diff] [blame] | 455 | |
Hans Verkuil | e37559b | 2014-04-17 02:47:21 -0300 | [diff] [blame] | 456 | static void go7007_stop_streaming(struct vb2_queue *q) |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 457 | { |
Hans Verkuil | ffcc1c0 | 2013-03-11 06:52:27 -0300 | [diff] [blame] | 458 | struct go7007 *go = vb2_get_drv_priv(q); |
| 459 | unsigned long flags; |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 460 | |
Hans Verkuil | ffcc1c0 | 2013-03-11 06:52:27 -0300 | [diff] [blame] | 461 | q->streaming = 0; |
| 462 | go7007_stream_stop(go); |
| 463 | mutex_lock(&go->hw_lock); |
| 464 | go7007_reset_encoder(go); |
| 465 | mutex_unlock(&go->hw_lock); |
Volokh Konstantin | 0a147c3 | 2013-01-16 09:00:51 -0300 | [diff] [blame] | 466 | call_all(&go->v4l2_dev, video, s_stream, 0); |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 467 | |
Hans Verkuil | ffcc1c0 | 2013-03-11 06:52:27 -0300 | [diff] [blame] | 468 | spin_lock_irqsave(&go->spinlock, flags); |
| 469 | INIT_LIST_HEAD(&go->vidq_active); |
| 470 | spin_unlock_irqrestore(&go->spinlock, flags); |
| 471 | v4l2_ctrl_grab(go->mpeg_video_gop_size, false); |
| 472 | v4l2_ctrl_grab(go->mpeg_video_gop_closure, false); |
| 473 | v4l2_ctrl_grab(go->mpeg_video_bitrate, false); |
| 474 | v4l2_ctrl_grab(go->mpeg_video_aspect_ratio, false); |
Hans Verkuil | 1f1aed2 | 2013-03-17 10:15:03 -0300 | [diff] [blame] | 475 | /* Turn on Capture LED */ |
| 476 | if (go->board_id == GO7007_BOARDID_ADS_USBAV_709) |
| 477 | go7007_write_addr(go, 0x3c82, 0x000d); |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 478 | } |
| 479 | |
Julia Lawall | 1bc1771 | 2016-09-08 20:59:01 -0300 | [diff] [blame] | 480 | static const struct vb2_ops go7007_video_qops = { |
Hans Verkuil | ffcc1c0 | 2013-03-11 06:52:27 -0300 | [diff] [blame] | 481 | .queue_setup = go7007_queue_setup, |
| 482 | .buf_queue = go7007_buf_queue, |
| 483 | .buf_prepare = go7007_buf_prepare, |
| 484 | .buf_finish = go7007_buf_finish, |
| 485 | .start_streaming = go7007_start_streaming, |
| 486 | .stop_streaming = go7007_stop_streaming, |
| 487 | .wait_prepare = vb2_ops_wait_prepare, |
| 488 | .wait_finish = vb2_ops_wait_finish, |
| 489 | }; |
| 490 | |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 491 | static int vidioc_g_parm(struct file *filp, void *priv, |
| 492 | struct v4l2_streamparm *parm) |
| 493 | { |
Hans Verkuil | 899eb84 | 2013-03-11 06:18:20 -0300 | [diff] [blame] | 494 | struct go7007 *go = video_drvdata(filp); |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 495 | struct v4l2_fract timeperframe = { |
| 496 | .numerator = 1001 * go->fps_scale, |
| 497 | .denominator = go->sensor_framerate, |
| 498 | }; |
| 499 | |
| 500 | if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 501 | return -EINVAL; |
| 502 | |
Hans Verkuil | 50deb74 | 2013-03-11 05:50:21 -0300 | [diff] [blame] | 503 | parm->parm.capture.readbuffers = 2; |
| 504 | parm->parm.capture.capability = V4L2_CAP_TIMEPERFRAME; |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 505 | parm->parm.capture.timeperframe = timeperframe; |
| 506 | |
| 507 | return 0; |
| 508 | } |
| 509 | |
| 510 | static int vidioc_s_parm(struct file *filp, void *priv, |
| 511 | struct v4l2_streamparm *parm) |
| 512 | { |
Hans Verkuil | 899eb84 | 2013-03-11 06:18:20 -0300 | [diff] [blame] | 513 | struct go7007 *go = video_drvdata(filp); |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 514 | unsigned int n, d; |
| 515 | |
| 516 | if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 517 | return -EINVAL; |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 518 | |
| 519 | n = go->sensor_framerate * |
| 520 | parm->parm.capture.timeperframe.numerator; |
| 521 | d = 1001 * parm->parm.capture.timeperframe.denominator; |
| 522 | if (n != 0 && d != 0 && n > d) |
| 523 | go->fps_scale = (n + d/2) / d; |
| 524 | else |
| 525 | go->fps_scale = 1; |
| 526 | |
Hans Verkuil | 50deb74 | 2013-03-11 05:50:21 -0300 | [diff] [blame] | 527 | return vidioc_g_parm(filp, priv, parm); |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 528 | } |
| 529 | |
Justin P. Mattock | b47acf2 | 2012-03-05 11:49:26 -0300 | [diff] [blame] | 530 | /* VIDIOC_ENUMSTD on go7007 were used for enumerating the supported fps and |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 531 | its resolution, when the device is not connected to TV. |
Justin P. Mattock | b47acf2 | 2012-03-05 11:49:26 -0300 | [diff] [blame] | 532 | This is were an API abuse, probably used by the lack of specific IOCTL's to |
| 533 | enumerate it, by the time the driver was written. |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 534 | |
| 535 | However, since kernel 2.6.19, two new ioctls (VIDIOC_ENUM_FRAMEINTERVALS |
| 536 | and VIDIOC_ENUM_FRAMESIZES) were added for this purpose. |
| 537 | |
Justin P. Mattock | b47acf2 | 2012-03-05 11:49:26 -0300 | [diff] [blame] | 538 | The two functions below implement the newer ioctls |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 539 | */ |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 540 | static int vidioc_enum_framesizes(struct file *filp, void *priv, |
| 541 | struct v4l2_frmsizeenum *fsize) |
| 542 | { |
Hans Verkuil | 899eb84 | 2013-03-11 06:18:20 -0300 | [diff] [blame] | 543 | struct go7007 *go = video_drvdata(filp); |
Hans Verkuil | 50deb74 | 2013-03-11 05:50:21 -0300 | [diff] [blame] | 544 | int width, height; |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 545 | |
Hans Verkuil | 50deb74 | 2013-03-11 05:50:21 -0300 | [diff] [blame] | 546 | if (fsize->index > 2) |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 547 | return -EINVAL; |
| 548 | |
Hans Verkuil | 35d2d76 | 2013-03-11 05:58:55 -0300 | [diff] [blame] | 549 | if (!valid_pixelformat(fsize->pixel_format)) |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 550 | return -EINVAL; |
| 551 | |
Hans Verkuil | 50deb74 | 2013-03-11 05:50:21 -0300 | [diff] [blame] | 552 | get_resolution(go, &width, &height); |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 553 | fsize->type = V4L2_FRMSIZE_TYPE_DISCRETE; |
Hans Verkuil | 50deb74 | 2013-03-11 05:50:21 -0300 | [diff] [blame] | 554 | fsize->discrete.width = (width >> fsize->index) & ~0xf; |
| 555 | fsize->discrete.height = (height >> fsize->index) & ~0xf; |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 556 | return 0; |
| 557 | } |
| 558 | |
| 559 | static int vidioc_enum_frameintervals(struct file *filp, void *priv, |
| 560 | struct v4l2_frmivalenum *fival) |
| 561 | { |
Hans Verkuil | 899eb84 | 2013-03-11 06:18:20 -0300 | [diff] [blame] | 562 | struct go7007 *go = video_drvdata(filp); |
Hans Verkuil | 50deb74 | 2013-03-11 05:50:21 -0300 | [diff] [blame] | 563 | int width, height; |
| 564 | int i; |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 565 | |
Hans Verkuil | 50deb74 | 2013-03-11 05:50:21 -0300 | [diff] [blame] | 566 | if (fival->index > 4) |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 567 | return -EINVAL; |
| 568 | |
Hans Verkuil | 35d2d76 | 2013-03-11 05:58:55 -0300 | [diff] [blame] | 569 | if (!valid_pixelformat(fival->pixel_format)) |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 570 | return -EINVAL; |
| 571 | |
Hans Verkuil | 50deb74 | 2013-03-11 05:50:21 -0300 | [diff] [blame] | 572 | if (!(go->board_info->sensor_flags & GO7007_SENSOR_SCALING)) { |
| 573 | get_resolution(go, &width, &height); |
| 574 | for (i = 0; i <= 2; i++) |
| 575 | if (fival->width == ((width >> i) & ~0xf) && |
| 576 | fival->height == ((height >> i) & ~0xf)) |
| 577 | break; |
| 578 | if (i > 2) |
| 579 | return -EINVAL; |
| 580 | } |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 581 | fival->type = V4L2_FRMIVAL_TYPE_DISCRETE; |
Hans Verkuil | 50deb74 | 2013-03-11 05:50:21 -0300 | [diff] [blame] | 582 | fival->discrete.numerator = 1001 * (fival->index + 1); |
| 583 | fival->discrete.denominator = go->sensor_framerate; |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 584 | return 0; |
| 585 | } |
| 586 | |
Pete Eberlein | bb87165 | 2009-09-18 21:59:29 -0300 | [diff] [blame] | 587 | static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id *std) |
| 588 | { |
Hans Verkuil | 899eb84 | 2013-03-11 06:18:20 -0300 | [diff] [blame] | 589 | struct go7007 *go = video_drvdata(file); |
Pete Eberlein | bb87165 | 2009-09-18 21:59:29 -0300 | [diff] [blame] | 590 | |
Hans Verkuil | 50deb74 | 2013-03-11 05:50:21 -0300 | [diff] [blame] | 591 | *std = go->std; |
| 592 | return 0; |
| 593 | } |
| 594 | |
| 595 | static int go7007_s_std(struct go7007 *go) |
| 596 | { |
Hans Verkuil | 3e4c847 | 2013-03-11 18:58:21 -0300 | [diff] [blame] | 597 | if (go->std & V4L2_STD_625_50) { |
Hans Verkuil | 50deb74 | 2013-03-11 05:50:21 -0300 | [diff] [blame] | 598 | go->standard = GO7007_STD_PAL; |
| 599 | go->sensor_framerate = 25025; |
Hans Verkuil | 3e4c847 | 2013-03-11 18:58:21 -0300 | [diff] [blame] | 600 | } else { |
| 601 | go->standard = GO7007_STD_NTSC; |
| 602 | go->sensor_framerate = 30000; |
Pete Eberlein | bb87165 | 2009-09-18 21:59:29 -0300 | [diff] [blame] | 603 | } |
| 604 | |
Laurent Pinchart | 8774bed | 2014-04-28 16:53:01 -0300 | [diff] [blame] | 605 | call_all(&go->v4l2_dev, video, s_std, go->std); |
Hans Verkuil | 50deb74 | 2013-03-11 05:50:21 -0300 | [diff] [blame] | 606 | set_capture_size(go, NULL, 0); |
Pete Eberlein | bb87165 | 2009-09-18 21:59:29 -0300 | [diff] [blame] | 607 | return 0; |
| 608 | } |
| 609 | |
Hans Verkuil | 314527a | 2013-03-15 06:10:40 -0300 | [diff] [blame] | 610 | static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id std) |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 611 | { |
Hans Verkuil | 50deb74 | 2013-03-11 05:50:21 -0300 | [diff] [blame] | 612 | struct go7007 *go = video_drvdata(file); |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 613 | |
Hans Verkuil | ffcc1c0 | 2013-03-11 06:52:27 -0300 | [diff] [blame] | 614 | if (vb2_is_busy(&go->vidq)) |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 615 | return -EBUSY; |
| 616 | |
Hans Verkuil | 50deb74 | 2013-03-11 05:50:21 -0300 | [diff] [blame] | 617 | go->std = std; |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 618 | |
Hans Verkuil | 50deb74 | 2013-03-11 05:50:21 -0300 | [diff] [blame] | 619 | return go7007_s_std(go); |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 620 | } |
| 621 | |
Pete Eberlein | bb87165 | 2009-09-18 21:59:29 -0300 | [diff] [blame] | 622 | static int vidioc_querystd(struct file *file, void *priv, v4l2_std_id *std) |
| 623 | { |
Hans Verkuil | 899eb84 | 2013-03-11 06:18:20 -0300 | [diff] [blame] | 624 | struct go7007 *go = video_drvdata(file); |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 625 | |
Hans Verkuil | 50deb74 | 2013-03-11 05:50:21 -0300 | [diff] [blame] | 626 | return call_all(&go->v4l2_dev, video, querystd, std); |
Pete Eberlein | bb87165 | 2009-09-18 21:59:29 -0300 | [diff] [blame] | 627 | } |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 628 | |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 629 | static int vidioc_enum_input(struct file *file, void *priv, |
| 630 | struct v4l2_input *inp) |
| 631 | { |
Hans Verkuil | 899eb84 | 2013-03-11 06:18:20 -0300 | [diff] [blame] | 632 | struct go7007 *go = video_drvdata(file); |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 633 | |
| 634 | if (inp->index >= go->board_info->num_inputs) |
| 635 | return -EINVAL; |
| 636 | |
| 637 | strncpy(inp->name, go->board_info->inputs[inp->index].name, |
| 638 | sizeof(inp->name)); |
| 639 | |
Hans Verkuil | 3acd16a | 2013-03-09 09:25:47 -0300 | [diff] [blame] | 640 | /* If this board has a tuner, it will be the first input */ |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 641 | if ((go->board_info->flags & GO7007_BOARD_HAS_TUNER) && |
Hans Verkuil | 3acd16a | 2013-03-09 09:25:47 -0300 | [diff] [blame] | 642 | inp->index == 0) |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 643 | inp->type = V4L2_INPUT_TYPE_TUNER; |
| 644 | else |
| 645 | inp->type = V4L2_INPUT_TYPE_CAMERA; |
| 646 | |
Hans Verkuil | 5e41054 | 2013-03-09 13:19:08 -0300 | [diff] [blame] | 647 | if (go->board_info->num_aud_inputs) |
| 648 | inp->audioset = (1 << go->board_info->num_aud_inputs) - 1; |
| 649 | else |
| 650 | inp->audioset = 0; |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 651 | inp->tuner = 0; |
| 652 | if (go->board_info->sensor_flags & GO7007_SENSOR_TV) |
Hans Verkuil | 50deb74 | 2013-03-11 05:50:21 -0300 | [diff] [blame] | 653 | inp->std = video_devdata(file)->tvnorms; |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 654 | else |
| 655 | inp->std = 0; |
| 656 | |
| 657 | return 0; |
| 658 | } |
| 659 | |
| 660 | |
| 661 | static int vidioc_g_input(struct file *file, void *priv, unsigned int *input) |
| 662 | { |
Hans Verkuil | 899eb84 | 2013-03-11 06:18:20 -0300 | [diff] [blame] | 663 | struct go7007 *go = video_drvdata(file); |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 664 | |
| 665 | *input = go->input; |
| 666 | |
| 667 | return 0; |
| 668 | } |
| 669 | |
Hans Verkuil | 5e41054 | 2013-03-09 13:19:08 -0300 | [diff] [blame] | 670 | static int vidioc_enumaudio(struct file *file, void *fh, struct v4l2_audio *a) |
| 671 | { |
| 672 | struct go7007 *go = video_drvdata(file); |
| 673 | |
| 674 | if (a->index >= go->board_info->num_aud_inputs) |
| 675 | return -EINVAL; |
Aybuke Ozdemir | 5935cae | 2014-03-15 19:10:16 +0200 | [diff] [blame] | 676 | strlcpy(a->name, go->board_info->aud_inputs[a->index].name, |
| 677 | sizeof(a->name)); |
Hans Verkuil | 5e41054 | 2013-03-09 13:19:08 -0300 | [diff] [blame] | 678 | a->capability = V4L2_AUDCAP_STEREO; |
| 679 | return 0; |
| 680 | } |
| 681 | |
| 682 | static int vidioc_g_audio(struct file *file, void *fh, struct v4l2_audio *a) |
| 683 | { |
| 684 | struct go7007 *go = video_drvdata(file); |
| 685 | |
| 686 | a->index = go->aud_input; |
Aybuke Ozdemir | 5935cae | 2014-03-15 19:10:16 +0200 | [diff] [blame] | 687 | strlcpy(a->name, go->board_info->aud_inputs[go->aud_input].name, |
| 688 | sizeof(a->name)); |
Hans Verkuil | 5e41054 | 2013-03-09 13:19:08 -0300 | [diff] [blame] | 689 | a->capability = V4L2_AUDCAP_STEREO; |
| 690 | return 0; |
| 691 | } |
| 692 | |
Aybuke Ozdemir | 5935cae | 2014-03-15 19:10:16 +0200 | [diff] [blame] | 693 | static int vidioc_s_audio(struct file *file, void *fh, |
| 694 | const struct v4l2_audio *a) |
Hans Verkuil | 5e41054 | 2013-03-09 13:19:08 -0300 | [diff] [blame] | 695 | { |
| 696 | struct go7007 *go = video_drvdata(file); |
| 697 | |
| 698 | if (a->index >= go->board_info->num_aud_inputs) |
| 699 | return -EINVAL; |
| 700 | go->aud_input = a->index; |
| 701 | v4l2_subdev_call(go->sd_audio, audio, s_routing, |
Aybuke Ozdemir | 5935cae | 2014-03-15 19:10:16 +0200 | [diff] [blame] | 702 | go->board_info->aud_inputs[go->aud_input].audio_input, 0, 0); |
Hans Verkuil | 5e41054 | 2013-03-09 13:19:08 -0300 | [diff] [blame] | 703 | return 0; |
| 704 | } |
| 705 | |
Hans Verkuil | 50deb74 | 2013-03-11 05:50:21 -0300 | [diff] [blame] | 706 | static void go7007_s_input(struct go7007 *go) |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 707 | { |
Hans Verkuil | 50deb74 | 2013-03-11 05:50:21 -0300 | [diff] [blame] | 708 | unsigned int input = go->input; |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 709 | |
Hans Verkuil | 3acd16a | 2013-03-09 09:25:47 -0300 | [diff] [blame] | 710 | v4l2_subdev_call(go->sd_video, video, s_routing, |
| 711 | go->board_info->inputs[input].video_input, 0, |
| 712 | go->board_info->video_config); |
| 713 | if (go->board_info->num_aud_inputs) { |
| 714 | int aud_input = go->board_info->inputs[input].audio_index; |
| 715 | |
| 716 | v4l2_subdev_call(go->sd_audio, audio, s_routing, |
| 717 | go->board_info->aud_inputs[aud_input].audio_input, 0, 0); |
| 718 | go->aud_input = aud_input; |
| 719 | } |
Hans Verkuil | 50deb74 | 2013-03-11 05:50:21 -0300 | [diff] [blame] | 720 | } |
| 721 | |
| 722 | static int vidioc_s_input(struct file *file, void *priv, unsigned int input) |
| 723 | { |
| 724 | struct go7007 *go = video_drvdata(file); |
| 725 | |
| 726 | if (input >= go->board_info->num_inputs) |
| 727 | return -EINVAL; |
Hans Verkuil | ffcc1c0 | 2013-03-11 06:52:27 -0300 | [diff] [blame] | 728 | if (vb2_is_busy(&go->vidq)) |
Hans Verkuil | 50deb74 | 2013-03-11 05:50:21 -0300 | [diff] [blame] | 729 | return -EBUSY; |
| 730 | |
| 731 | go->input = input; |
| 732 | go7007_s_input(go); |
| 733 | |
Hans Verkuil | 3acd16a | 2013-03-09 09:25:47 -0300 | [diff] [blame] | 734 | return 0; |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 735 | } |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 736 | |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 737 | static int vidioc_g_tuner(struct file *file, void *priv, |
| 738 | struct v4l2_tuner *t) |
| 739 | { |
Hans Verkuil | 899eb84 | 2013-03-11 06:18:20 -0300 | [diff] [blame] | 740 | struct go7007 *go = video_drvdata(file); |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 741 | |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 742 | if (t->index != 0) |
| 743 | return -EINVAL; |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 744 | |
Hans Verkuil | e4d2a61 | 2013-03-09 13:14:32 -0300 | [diff] [blame] | 745 | strlcpy(t->name, "Tuner", sizeof(t->name)); |
Pete Eberlein | fa3c39b | 2009-11-16 15:16:00 -0300 | [diff] [blame] | 746 | return call_all(&go->v4l2_dev, tuner, g_tuner, t); |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 747 | } |
| 748 | |
| 749 | static int vidioc_s_tuner(struct file *file, void *priv, |
Hans Verkuil | 2f73c7c | 2013-03-15 06:10:06 -0300 | [diff] [blame] | 750 | const struct v4l2_tuner *t) |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 751 | { |
Hans Verkuil | 899eb84 | 2013-03-11 06:18:20 -0300 | [diff] [blame] | 752 | struct go7007 *go = video_drvdata(file); |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 753 | |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 754 | if (t->index != 0) |
| 755 | return -EINVAL; |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 756 | |
Pete Eberlein | fa3c39b | 2009-11-16 15:16:00 -0300 | [diff] [blame] | 757 | return call_all(&go->v4l2_dev, tuner, s_tuner, t); |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 758 | } |
| 759 | |
| 760 | static int vidioc_g_frequency(struct file *file, void *priv, |
| 761 | struct v4l2_frequency *f) |
| 762 | { |
Hans Verkuil | 899eb84 | 2013-03-11 06:18:20 -0300 | [diff] [blame] | 763 | struct go7007 *go = video_drvdata(file); |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 764 | |
Hans Verkuil | 50deb74 | 2013-03-11 05:50:21 -0300 | [diff] [blame] | 765 | if (f->tuner) |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 766 | return -EINVAL; |
Pete Eberlein | fa3c39b | 2009-11-16 15:16:00 -0300 | [diff] [blame] | 767 | |
| 768 | return call_all(&go->v4l2_dev, tuner, g_frequency, f); |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 769 | } |
| 770 | |
| 771 | static int vidioc_s_frequency(struct file *file, void *priv, |
Hans Verkuil | b530a44 | 2013-03-19 04:09:26 -0300 | [diff] [blame] | 772 | const struct v4l2_frequency *f) |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 773 | { |
Hans Verkuil | 899eb84 | 2013-03-11 06:18:20 -0300 | [diff] [blame] | 774 | struct go7007 *go = video_drvdata(file); |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 775 | |
Hans Verkuil | 50deb74 | 2013-03-11 05:50:21 -0300 | [diff] [blame] | 776 | if (f->tuner) |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 777 | return -EINVAL; |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 778 | |
Pete Eberlein | fa3c39b | 2009-11-16 15:16:00 -0300 | [diff] [blame] | 779 | return call_all(&go->v4l2_dev, tuner, s_frequency, f); |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 780 | } |
| 781 | |
Hans Verkuil | 59d7b91 | 2013-03-09 11:25:09 -0300 | [diff] [blame] | 782 | static int vidioc_log_status(struct file *file, void *priv) |
| 783 | { |
Hans Verkuil | 899eb84 | 2013-03-11 06:18:20 -0300 | [diff] [blame] | 784 | struct go7007 *go = video_drvdata(file); |
Hans Verkuil | 59d7b91 | 2013-03-09 11:25:09 -0300 | [diff] [blame] | 785 | |
| 786 | v4l2_ctrl_log_status(file, priv); |
| 787 | return call_all(&go->v4l2_dev, core, log_status); |
| 788 | } |
| 789 | |
Hans Verkuil | 0ee58f8 | 2014-06-10 07:39:04 -0300 | [diff] [blame] | 790 | static int vidioc_subscribe_event(struct v4l2_fh *fh, |
| 791 | const struct v4l2_event_subscription *sub) |
| 792 | { |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 793 | |
Hans Verkuil | 0ee58f8 | 2014-06-10 07:39:04 -0300 | [diff] [blame] | 794 | switch (sub->type) { |
Hans Verkuil | 0ee58f8 | 2014-06-10 07:39:04 -0300 | [diff] [blame] | 795 | case V4L2_EVENT_MOTION_DET: |
| 796 | /* Allow for up to 30 events (1 second for NTSC) to be |
| 797 | * stored. */ |
| 798 | return v4l2_event_subscribe(fh, sub, 30, NULL); |
Gustavo Padovan | c3d173a | 2017-02-15 15:55:33 -0200 | [diff] [blame] | 799 | default: |
| 800 | return v4l2_ctrl_subscribe_event(fh, sub); |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 801 | } |
Hans Verkuil | 0ee58f8 | 2014-06-10 07:39:04 -0300 | [diff] [blame] | 802 | } |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 803 | |
Hans Verkuil | 0ee58f8 | 2014-06-10 07:39:04 -0300 | [diff] [blame] | 804 | |
| 805 | static int go7007_s_ctrl(struct v4l2_ctrl *ctrl) |
| 806 | { |
| 807 | struct go7007 *go = |
| 808 | container_of(ctrl->handler, struct go7007, hdl); |
| 809 | unsigned y; |
| 810 | u8 *mt; |
| 811 | |
| 812 | switch (ctrl->id) { |
| 813 | case V4L2_CID_PIXEL_THRESHOLD0: |
| 814 | go->modet[0].pixel_threshold = ctrl->val; |
| 815 | break; |
| 816 | case V4L2_CID_MOTION_THRESHOLD0: |
| 817 | go->modet[0].motion_threshold = ctrl->val; |
| 818 | break; |
| 819 | case V4L2_CID_MB_THRESHOLD0: |
| 820 | go->modet[0].mb_threshold = ctrl->val; |
| 821 | break; |
| 822 | case V4L2_CID_PIXEL_THRESHOLD1: |
| 823 | go->modet[1].pixel_threshold = ctrl->val; |
| 824 | break; |
| 825 | case V4L2_CID_MOTION_THRESHOLD1: |
| 826 | go->modet[1].motion_threshold = ctrl->val; |
| 827 | break; |
| 828 | case V4L2_CID_MB_THRESHOLD1: |
| 829 | go->modet[1].mb_threshold = ctrl->val; |
| 830 | break; |
| 831 | case V4L2_CID_PIXEL_THRESHOLD2: |
| 832 | go->modet[2].pixel_threshold = ctrl->val; |
| 833 | break; |
| 834 | case V4L2_CID_MOTION_THRESHOLD2: |
| 835 | go->modet[2].motion_threshold = ctrl->val; |
| 836 | break; |
| 837 | case V4L2_CID_MB_THRESHOLD2: |
| 838 | go->modet[2].mb_threshold = ctrl->val; |
| 839 | break; |
| 840 | case V4L2_CID_PIXEL_THRESHOLD3: |
| 841 | go->modet[3].pixel_threshold = ctrl->val; |
| 842 | break; |
| 843 | case V4L2_CID_MOTION_THRESHOLD3: |
| 844 | go->modet[3].motion_threshold = ctrl->val; |
| 845 | break; |
| 846 | case V4L2_CID_MB_THRESHOLD3: |
| 847 | go->modet[3].mb_threshold = ctrl->val; |
| 848 | break; |
| 849 | case V4L2_CID_DETECT_MD_REGION_GRID: |
| 850 | mt = go->modet_map; |
| 851 | for (y = 0; y < go->height / 16; y++, mt += go->width / 16) |
| 852 | memcpy(mt, ctrl->p_new.p_u8 + y * (720 / 16), go->width / 16); |
| 853 | break; |
| 854 | default: |
| 855 | return -EINVAL; |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 856 | } |
Hans Verkuil | 0ee58f8 | 2014-06-10 07:39:04 -0300 | [diff] [blame] | 857 | return 0; |
| 858 | } |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 859 | |
Greg Kroah-Hartman | 60572c0 | 2009-01-05 10:21:08 -0800 | [diff] [blame] | 860 | static struct v4l2_file_operations go7007_fops = { |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 861 | .owner = THIS_MODULE, |
Hans Verkuil | 899eb84 | 2013-03-11 06:18:20 -0300 | [diff] [blame] | 862 | .open = v4l2_fh_open, |
Hans Verkuil | ffcc1c0 | 2013-03-11 06:52:27 -0300 | [diff] [blame] | 863 | .release = vb2_fop_release, |
| 864 | .unlocked_ioctl = video_ioctl2, |
| 865 | .read = vb2_fop_read, |
| 866 | .mmap = vb2_fop_mmap, |
| 867 | .poll = vb2_fop_poll, |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 868 | }; |
| 869 | |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 870 | static const struct v4l2_ioctl_ops video_ioctl_ops = { |
| 871 | .vidioc_querycap = vidioc_querycap, |
| 872 | .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap, |
| 873 | .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap, |
| 874 | .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap, |
| 875 | .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap, |
Hans Verkuil | ffcc1c0 | 2013-03-11 06:52:27 -0300 | [diff] [blame] | 876 | .vidioc_reqbufs = vb2_ioctl_reqbufs, |
| 877 | .vidioc_querybuf = vb2_ioctl_querybuf, |
| 878 | .vidioc_qbuf = vb2_ioctl_qbuf, |
| 879 | .vidioc_dqbuf = vb2_ioctl_dqbuf, |
Pete Eberlein | bb87165 | 2009-09-18 21:59:29 -0300 | [diff] [blame] | 880 | .vidioc_g_std = vidioc_g_std, |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 881 | .vidioc_s_std = vidioc_s_std, |
Pete Eberlein | bb87165 | 2009-09-18 21:59:29 -0300 | [diff] [blame] | 882 | .vidioc_querystd = vidioc_querystd, |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 883 | .vidioc_enum_input = vidioc_enum_input, |
| 884 | .vidioc_g_input = vidioc_g_input, |
| 885 | .vidioc_s_input = vidioc_s_input, |
Hans Verkuil | 5e41054 | 2013-03-09 13:19:08 -0300 | [diff] [blame] | 886 | .vidioc_enumaudio = vidioc_enumaudio, |
| 887 | .vidioc_g_audio = vidioc_g_audio, |
| 888 | .vidioc_s_audio = vidioc_s_audio, |
Hans Verkuil | ffcc1c0 | 2013-03-11 06:52:27 -0300 | [diff] [blame] | 889 | .vidioc_streamon = vb2_ioctl_streamon, |
| 890 | .vidioc_streamoff = vb2_ioctl_streamoff, |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 891 | .vidioc_g_tuner = vidioc_g_tuner, |
| 892 | .vidioc_s_tuner = vidioc_s_tuner, |
| 893 | .vidioc_g_frequency = vidioc_g_frequency, |
| 894 | .vidioc_s_frequency = vidioc_s_frequency, |
| 895 | .vidioc_g_parm = vidioc_g_parm, |
| 896 | .vidioc_s_parm = vidioc_s_parm, |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 897 | .vidioc_enum_framesizes = vidioc_enum_framesizes, |
| 898 | .vidioc_enum_frameintervals = vidioc_enum_frameintervals, |
Hans Verkuil | 59d7b91 | 2013-03-09 11:25:09 -0300 | [diff] [blame] | 899 | .vidioc_log_status = vidioc_log_status, |
Hans Verkuil | 0ee58f8 | 2014-06-10 07:39:04 -0300 | [diff] [blame] | 900 | .vidioc_subscribe_event = vidioc_subscribe_event, |
Hans Verkuil | bae7432 | 2013-03-09 11:08:41 -0300 | [diff] [blame] | 901 | .vidioc_unsubscribe_event = v4l2_event_unsubscribe, |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 902 | }; |
| 903 | |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 904 | static struct video_device go7007_template = { |
| 905 | .name = "go7007", |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 906 | .fops = &go7007_fops, |
Hans Verkuil | 6bb0e65 | 2013-03-11 06:34:22 -0300 | [diff] [blame] | 907 | .release = video_device_release_empty, |
Mauro Carvalho Chehab | 65f9f61 | 2008-11-11 22:54:30 -0200 | [diff] [blame] | 908 | .ioctl_ops = &video_ioctl_ops, |
| 909 | .tvnorms = V4L2_STD_ALL, |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 910 | }; |
| 911 | |
Hans Verkuil | 0ee58f8 | 2014-06-10 07:39:04 -0300 | [diff] [blame] | 912 | static const struct v4l2_ctrl_ops go7007_ctrl_ops = { |
| 913 | .s_ctrl = go7007_s_ctrl, |
| 914 | }; |
| 915 | |
| 916 | static const struct v4l2_ctrl_config go7007_pixel_threshold0_ctrl = { |
| 917 | .ops = &go7007_ctrl_ops, |
| 918 | .id = V4L2_CID_PIXEL_THRESHOLD0, |
| 919 | .name = "Pixel Threshold Region 0", |
| 920 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 921 | .def = 20, |
| 922 | .max = 32767, |
| 923 | .step = 1, |
| 924 | }; |
| 925 | |
| 926 | static const struct v4l2_ctrl_config go7007_motion_threshold0_ctrl = { |
| 927 | .ops = &go7007_ctrl_ops, |
| 928 | .id = V4L2_CID_MOTION_THRESHOLD0, |
| 929 | .name = "Motion Threshold Region 0", |
| 930 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 931 | .def = 80, |
| 932 | .max = 32767, |
| 933 | .step = 1, |
| 934 | }; |
| 935 | |
| 936 | static const struct v4l2_ctrl_config go7007_mb_threshold0_ctrl = { |
| 937 | .ops = &go7007_ctrl_ops, |
| 938 | .id = V4L2_CID_MB_THRESHOLD0, |
| 939 | .name = "MB Threshold Region 0", |
| 940 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 941 | .def = 200, |
| 942 | .max = 32767, |
| 943 | .step = 1, |
| 944 | }; |
| 945 | |
| 946 | static const struct v4l2_ctrl_config go7007_pixel_threshold1_ctrl = { |
| 947 | .ops = &go7007_ctrl_ops, |
| 948 | .id = V4L2_CID_PIXEL_THRESHOLD1, |
| 949 | .name = "Pixel Threshold Region 1", |
| 950 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 951 | .def = 20, |
| 952 | .max = 32767, |
| 953 | .step = 1, |
| 954 | }; |
| 955 | |
| 956 | static const struct v4l2_ctrl_config go7007_motion_threshold1_ctrl = { |
| 957 | .ops = &go7007_ctrl_ops, |
| 958 | .id = V4L2_CID_MOTION_THRESHOLD1, |
| 959 | .name = "Motion Threshold Region 1", |
| 960 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 961 | .def = 80, |
| 962 | .max = 32767, |
| 963 | .step = 1, |
| 964 | }; |
| 965 | |
| 966 | static const struct v4l2_ctrl_config go7007_mb_threshold1_ctrl = { |
| 967 | .ops = &go7007_ctrl_ops, |
| 968 | .id = V4L2_CID_MB_THRESHOLD1, |
| 969 | .name = "MB Threshold Region 1", |
| 970 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 971 | .def = 200, |
| 972 | .max = 32767, |
| 973 | .step = 1, |
| 974 | }; |
| 975 | |
| 976 | static const struct v4l2_ctrl_config go7007_pixel_threshold2_ctrl = { |
| 977 | .ops = &go7007_ctrl_ops, |
| 978 | .id = V4L2_CID_PIXEL_THRESHOLD2, |
| 979 | .name = "Pixel Threshold Region 2", |
| 980 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 981 | .def = 20, |
| 982 | .max = 32767, |
| 983 | .step = 1, |
| 984 | }; |
| 985 | |
| 986 | static const struct v4l2_ctrl_config go7007_motion_threshold2_ctrl = { |
| 987 | .ops = &go7007_ctrl_ops, |
| 988 | .id = V4L2_CID_MOTION_THRESHOLD2, |
| 989 | .name = "Motion Threshold Region 2", |
| 990 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 991 | .def = 80, |
| 992 | .max = 32767, |
| 993 | .step = 1, |
| 994 | }; |
| 995 | |
| 996 | static const struct v4l2_ctrl_config go7007_mb_threshold2_ctrl = { |
| 997 | .ops = &go7007_ctrl_ops, |
| 998 | .id = V4L2_CID_MB_THRESHOLD2, |
| 999 | .name = "MB Threshold Region 2", |
| 1000 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 1001 | .def = 200, |
| 1002 | .max = 32767, |
| 1003 | .step = 1, |
| 1004 | }; |
| 1005 | |
| 1006 | static const struct v4l2_ctrl_config go7007_pixel_threshold3_ctrl = { |
| 1007 | .ops = &go7007_ctrl_ops, |
| 1008 | .id = V4L2_CID_PIXEL_THRESHOLD3, |
| 1009 | .name = "Pixel Threshold Region 3", |
| 1010 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 1011 | .def = 20, |
| 1012 | .max = 32767, |
| 1013 | .step = 1, |
| 1014 | }; |
| 1015 | |
| 1016 | static const struct v4l2_ctrl_config go7007_motion_threshold3_ctrl = { |
| 1017 | .ops = &go7007_ctrl_ops, |
| 1018 | .id = V4L2_CID_MOTION_THRESHOLD3, |
| 1019 | .name = "Motion Threshold Region 3", |
| 1020 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 1021 | .def = 80, |
| 1022 | .max = 32767, |
| 1023 | .step = 1, |
| 1024 | }; |
| 1025 | |
| 1026 | static const struct v4l2_ctrl_config go7007_mb_threshold3_ctrl = { |
| 1027 | .ops = &go7007_ctrl_ops, |
| 1028 | .id = V4L2_CID_MB_THRESHOLD3, |
| 1029 | .name = "MB Threshold Region 3", |
| 1030 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 1031 | .def = 200, |
| 1032 | .max = 32767, |
| 1033 | .step = 1, |
| 1034 | }; |
| 1035 | |
| 1036 | static const struct v4l2_ctrl_config go7007_mb_regions_ctrl = { |
| 1037 | .ops = &go7007_ctrl_ops, |
| 1038 | .id = V4L2_CID_DETECT_MD_REGION_GRID, |
| 1039 | .dims = { 576 / 16, 720 / 16 }, |
| 1040 | .max = 3, |
| 1041 | .step = 1, |
| 1042 | }; |
| 1043 | |
Hans Verkuil | 9b8451d | 2013-03-11 05:19:59 -0300 | [diff] [blame] | 1044 | int go7007_v4l2_ctrl_init(struct go7007 *go) |
| 1045 | { |
| 1046 | struct v4l2_ctrl_handler *hdl = &go->hdl; |
| 1047 | struct v4l2_ctrl *ctrl; |
| 1048 | |
Hans Verkuil | 0ee58f8 | 2014-06-10 07:39:04 -0300 | [diff] [blame] | 1049 | v4l2_ctrl_handler_init(hdl, 22); |
Hans Verkuil | 35d2d76 | 2013-03-11 05:58:55 -0300 | [diff] [blame] | 1050 | go->mpeg_video_gop_size = v4l2_ctrl_new_std(hdl, NULL, |
Hans Verkuil | 9b8451d | 2013-03-11 05:19:59 -0300 | [diff] [blame] | 1051 | V4L2_CID_MPEG_VIDEO_GOP_SIZE, 0, 34, 1, 15); |
Hans Verkuil | 35d2d76 | 2013-03-11 05:58:55 -0300 | [diff] [blame] | 1052 | go->mpeg_video_gop_closure = v4l2_ctrl_new_std(hdl, NULL, |
| 1053 | V4L2_CID_MPEG_VIDEO_GOP_CLOSURE, 0, 1, 1, 1); |
| 1054 | go->mpeg_video_bitrate = v4l2_ctrl_new_std(hdl, NULL, |
Hans Verkuil | 9b8451d | 2013-03-11 05:19:59 -0300 | [diff] [blame] | 1055 | V4L2_CID_MPEG_VIDEO_BITRATE, |
Hans Verkuil | 35d2d76 | 2013-03-11 05:58:55 -0300 | [diff] [blame] | 1056 | 64000, 10000000, 1, 9800000); |
Volokh Konstantin | 7e4bfb9 | 2013-03-17 07:16:37 -0300 | [diff] [blame] | 1057 | go->mpeg_video_b_frames = v4l2_ctrl_new_std(hdl, NULL, |
| 1058 | V4L2_CID_MPEG_VIDEO_B_FRAMES, 0, 2, 2, 0); |
Hans Verkuil | 778ca51 | 2013-03-17 10:47:02 -0300 | [diff] [blame] | 1059 | go->mpeg_video_rep_seqheader = v4l2_ctrl_new_std(hdl, NULL, |
| 1060 | V4L2_CID_MPEG_VIDEO_REPEAT_SEQ_HEADER, 0, 1, 1, 1); |
Volokh Konstantin | 7e4bfb9 | 2013-03-17 07:16:37 -0300 | [diff] [blame] | 1061 | |
Hans Verkuil | 35d2d76 | 2013-03-11 05:58:55 -0300 | [diff] [blame] | 1062 | go->mpeg_video_aspect_ratio = v4l2_ctrl_new_std_menu(hdl, NULL, |
| 1063 | V4L2_CID_MPEG_VIDEO_ASPECT, |
| 1064 | V4L2_MPEG_VIDEO_ASPECT_16x9, 0, |
| 1065 | V4L2_MPEG_VIDEO_ASPECT_1x1); |
| 1066 | ctrl = v4l2_ctrl_new_std(hdl, NULL, |
Hans Verkuil | 9b8451d | 2013-03-11 05:19:59 -0300 | [diff] [blame] | 1067 | V4L2_CID_JPEG_ACTIVE_MARKER, 0, |
Aybuke Ozdemir | 5935cae | 2014-03-15 19:10:16 +0200 | [diff] [blame] | 1068 | V4L2_JPEG_ACTIVE_MARKER_DQT | |
| 1069 | V4L2_JPEG_ACTIVE_MARKER_DHT, 0, |
| 1070 | V4L2_JPEG_ACTIVE_MARKER_DQT | |
| 1071 | V4L2_JPEG_ACTIVE_MARKER_DHT); |
Hans Verkuil | 9b8451d | 2013-03-11 05:19:59 -0300 | [diff] [blame] | 1072 | if (ctrl) |
| 1073 | ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY; |
Hans Verkuil | 0ee58f8 | 2014-06-10 07:39:04 -0300 | [diff] [blame] | 1074 | v4l2_ctrl_new_custom(hdl, &go7007_pixel_threshold0_ctrl, NULL); |
| 1075 | v4l2_ctrl_new_custom(hdl, &go7007_motion_threshold0_ctrl, NULL); |
| 1076 | v4l2_ctrl_new_custom(hdl, &go7007_mb_threshold0_ctrl, NULL); |
| 1077 | v4l2_ctrl_new_custom(hdl, &go7007_pixel_threshold1_ctrl, NULL); |
| 1078 | v4l2_ctrl_new_custom(hdl, &go7007_motion_threshold1_ctrl, NULL); |
| 1079 | v4l2_ctrl_new_custom(hdl, &go7007_mb_threshold1_ctrl, NULL); |
| 1080 | v4l2_ctrl_new_custom(hdl, &go7007_pixel_threshold2_ctrl, NULL); |
| 1081 | v4l2_ctrl_new_custom(hdl, &go7007_motion_threshold2_ctrl, NULL); |
| 1082 | v4l2_ctrl_new_custom(hdl, &go7007_mb_threshold2_ctrl, NULL); |
| 1083 | v4l2_ctrl_new_custom(hdl, &go7007_pixel_threshold3_ctrl, NULL); |
| 1084 | v4l2_ctrl_new_custom(hdl, &go7007_motion_threshold3_ctrl, NULL); |
| 1085 | v4l2_ctrl_new_custom(hdl, &go7007_mb_threshold3_ctrl, NULL); |
| 1086 | v4l2_ctrl_new_custom(hdl, &go7007_mb_regions_ctrl, NULL); |
| 1087 | go->modet_mode = v4l2_ctrl_new_std_menu(hdl, NULL, |
| 1088 | V4L2_CID_DETECT_MD_MODE, |
| 1089 | V4L2_DETECT_MD_MODE_REGION_GRID, |
| 1090 | 1 << V4L2_DETECT_MD_MODE_THRESHOLD_GRID, |
| 1091 | V4L2_DETECT_MD_MODE_DISABLED); |
Hans Verkuil | 9b8451d | 2013-03-11 05:19:59 -0300 | [diff] [blame] | 1092 | if (hdl->error) { |
| 1093 | int rv = hdl->error; |
| 1094 | |
| 1095 | v4l2_err(&go->v4l2_dev, "Could not register controls\n"); |
| 1096 | return rv; |
| 1097 | } |
| 1098 | go->v4l2_dev.ctrl_handler = hdl; |
| 1099 | return 0; |
| 1100 | } |
| 1101 | |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 1102 | int go7007_v4l2_init(struct go7007 *go) |
| 1103 | { |
Hans Verkuil | 6bb0e65 | 2013-03-11 06:34:22 -0300 | [diff] [blame] | 1104 | struct video_device *vdev = &go->vdev; |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 1105 | int rv; |
| 1106 | |
Hans Verkuil | ffcc1c0 | 2013-03-11 06:52:27 -0300 | [diff] [blame] | 1107 | mutex_init(&go->serialize_lock); |
| 1108 | mutex_init(&go->queue_lock); |
| 1109 | |
| 1110 | INIT_LIST_HEAD(&go->vidq_active); |
| 1111 | go->vidq.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 1112 | go->vidq.io_modes = VB2_MMAP | VB2_USERPTR | VB2_READ; |
| 1113 | go->vidq.ops = &go7007_video_qops; |
| 1114 | go->vidq.mem_ops = &vb2_vmalloc_memops; |
| 1115 | go->vidq.drv_priv = go; |
| 1116 | go->vidq.buf_struct_size = sizeof(struct go7007_buffer); |
Sakari Ailus | ade4868 | 2014-02-25 19:12:19 -0300 | [diff] [blame] | 1117 | go->vidq.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; |
Hans Verkuil | ffcc1c0 | 2013-03-11 06:52:27 -0300 | [diff] [blame] | 1118 | go->vidq.lock = &go->queue_lock; |
| 1119 | rv = vb2_queue_init(&go->vidq); |
| 1120 | if (rv) |
| 1121 | return rv; |
Hans Verkuil | 6bb0e65 | 2013-03-11 06:34:22 -0300 | [diff] [blame] | 1122 | *vdev = go7007_template; |
| 1123 | vdev->lock = &go->serialize_lock; |
| 1124 | vdev->queue = &go->vidq; |
Hans Verkuil | 6bb0e65 | 2013-03-11 06:34:22 -0300 | [diff] [blame] | 1125 | video_set_drvdata(vdev, go); |
| 1126 | vdev->v4l2_dev = &go->v4l2_dev; |
Hans Verkuil | 9665555 | 2016-04-03 17:44:16 -0300 | [diff] [blame] | 1127 | if (!v4l2_device_has_op(&go->v4l2_dev, 0, video, querystd)) |
Hans Verkuil | 6bb0e65 | 2013-03-11 06:34:22 -0300 | [diff] [blame] | 1128 | v4l2_disable_ioctl(vdev, VIDIOC_QUERYSTD); |
Hans Verkuil | 50deb74 | 2013-03-11 05:50:21 -0300 | [diff] [blame] | 1129 | if (!(go->board_info->flags & GO7007_BOARD_HAS_TUNER)) { |
Hans Verkuil | 6bb0e65 | 2013-03-11 06:34:22 -0300 | [diff] [blame] | 1130 | v4l2_disable_ioctl(vdev, VIDIOC_S_FREQUENCY); |
| 1131 | v4l2_disable_ioctl(vdev, VIDIOC_G_FREQUENCY); |
| 1132 | v4l2_disable_ioctl(vdev, VIDIOC_S_TUNER); |
| 1133 | v4l2_disable_ioctl(vdev, VIDIOC_G_TUNER); |
Hans Verkuil | 50deb74 | 2013-03-11 05:50:21 -0300 | [diff] [blame] | 1134 | } else { |
| 1135 | struct v4l2_frequency f = { |
| 1136 | .type = V4L2_TUNER_ANALOG_TV, |
| 1137 | .frequency = 980, |
| 1138 | }; |
| 1139 | |
| 1140 | call_all(&go->v4l2_dev, tuner, s_frequency, &f); |
| 1141 | } |
| 1142 | if (!(go->board_info->sensor_flags & GO7007_SENSOR_TV)) { |
Hans Verkuil | 6bb0e65 | 2013-03-11 06:34:22 -0300 | [diff] [blame] | 1143 | v4l2_disable_ioctl(vdev, VIDIOC_G_STD); |
| 1144 | v4l2_disable_ioctl(vdev, VIDIOC_S_STD); |
| 1145 | vdev->tvnorms = 0; |
Hans Verkuil | 50deb74 | 2013-03-11 05:50:21 -0300 | [diff] [blame] | 1146 | } |
| 1147 | if (go->board_info->sensor_flags & GO7007_SENSOR_SCALING) |
Hans Verkuil | 6bb0e65 | 2013-03-11 06:34:22 -0300 | [diff] [blame] | 1148 | v4l2_disable_ioctl(vdev, VIDIOC_ENUM_FRAMESIZES); |
Hans Verkuil | 50deb74 | 2013-03-11 05:50:21 -0300 | [diff] [blame] | 1149 | if (go->board_info->num_aud_inputs == 0) { |
Hans Verkuil | 6bb0e65 | 2013-03-11 06:34:22 -0300 | [diff] [blame] | 1150 | v4l2_disable_ioctl(vdev, VIDIOC_G_AUDIO); |
| 1151 | v4l2_disable_ioctl(vdev, VIDIOC_S_AUDIO); |
| 1152 | v4l2_disable_ioctl(vdev, VIDIOC_ENUMAUDIO); |
Hans Verkuil | 50deb74 | 2013-03-11 05:50:21 -0300 | [diff] [blame] | 1153 | } |
Hans Verkuil | b95dd82 | 2013-03-11 06:12:10 -0300 | [diff] [blame] | 1154 | /* Setup correct crystal frequency on this board */ |
| 1155 | if (go->board_info->sensor_flags & GO7007_SENSOR_SAA7115) |
| 1156 | v4l2_subdev_call(go->sd_video, video, s_crystal_freq, |
| 1157 | SAA7115_FREQ_24_576_MHZ, |
| 1158 | SAA7115_FREQ_FL_APLL | SAA7115_FREQ_FL_UCGC | |
| 1159 | SAA7115_FREQ_FL_DOUBLE_ASCLK); |
Hans Verkuil | 50deb74 | 2013-03-11 05:50:21 -0300 | [diff] [blame] | 1160 | go7007_s_input(go); |
| 1161 | if (go->board_info->sensor_flags & GO7007_SENSOR_TV) |
| 1162 | go7007_s_std(go); |
Hans Verkuil | 6bb0e65 | 2013-03-11 06:34:22 -0300 | [diff] [blame] | 1163 | rv = video_register_device(vdev, VFL_TYPE_GRABBER, -1); |
| 1164 | if (rv < 0) |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 1165 | return rv; |
YAMANE Toshiaki | 34047ba | 2012-11-06 08:34:20 -0300 | [diff] [blame] | 1166 | dev_info(go->dev, "registered device %s [v4l2]\n", |
Hans Verkuil | 6bb0e65 | 2013-03-11 06:34:22 -0300 | [diff] [blame] | 1167 | video_device_node_name(vdev)); |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 1168 | |
| 1169 | return 0; |
| 1170 | } |
| 1171 | |
| 1172 | void go7007_v4l2_remove(struct go7007 *go) |
| 1173 | { |
Hans Verkuil | 9b8451d | 2013-03-11 05:19:59 -0300 | [diff] [blame] | 1174 | v4l2_ctrl_handler_free(&go->hdl); |
Greg Kroah-Hartman | 866b869 | 2008-02-15 16:53:09 -0800 | [diff] [blame] | 1175 | } |