go7007-v4l2.c 30.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 * Copyright (C) 2005-2006 Micronas USA Inc.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License (Version 2) as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

#include <linux/module.h>
#include <linux/delay.h>
#include <linux/sched.h>
#include <linux/spinlock.h>
18
#include <linux/slab.h>
19 20 21 22 23
#include <linux/fs.h>
#include <linux/unistd.h>
#include <linux/time.h>
#include <linux/vmalloc.h>
#include <linux/pagemap.h>
24 25 26
#include <linux/i2c.h>
#include <linux/mutex.h>
#include <linux/uaccess.h>
R
Ross Cohen 已提交
27
#include <linux/videodev2.h>
28 29
#include <media/v4l2-common.h>
#include <media/v4l2-ioctl.h>
30
#include <media/v4l2-subdev.h>
31
#include <media/v4l2-event.h>
32
#include <media/videobuf2-vmalloc.h>
33
#include <media/saa7115.h>
34 35 36

#include "go7007-priv.h"

37 38 39
#define call_all(dev, o, f, args...) \
	v4l2_device_call_until_err(dev, 0, o, f, ##args)

40 41 42 43 44 45 46 47 48 49 50 51 52
static bool valid_pixelformat(u32 pixelformat)
{
	switch (pixelformat) {
	case V4L2_PIX_FMT_MJPEG:
	case V4L2_PIX_FMT_MPEG1:
	case V4L2_PIX_FMT_MPEG2:
	case V4L2_PIX_FMT_MPEG4:
		return true;
	default:
		return false;
	}
}

53
static u32 get_frame_type_flag(struct go7007_buffer *vb, int format)
54
{
55
	u8 *ptr = vb2_plane_vaddr(&vb->vb, 0);
56 57

	switch (format) {
58
	case V4L2_PIX_FMT_MJPEG:
59
		return V4L2_BUF_FLAG_KEYFRAME;
60
	case V4L2_PIX_FMT_MPEG4:
61
		switch ((ptr[vb->frame_offset + 4] >> 6) & 0x3) {
62 63 64 65 66 67 68 69 70
		case 0:
			return V4L2_BUF_FLAG_KEYFRAME;
		case 1:
			return V4L2_BUF_FLAG_PFRAME;
		case 2:
			return V4L2_BUF_FLAG_BFRAME;
		default:
			return 0;
		}
71 72
	case V4L2_PIX_FMT_MPEG1:
	case V4L2_PIX_FMT_MPEG2:
73
		switch ((ptr[vb->frame_offset + 5] >> 3) & 0x7) {
74 75 76 77 78 79 80 81 82 83 84 85 86 87
		case 1:
			return V4L2_BUF_FLAG_KEYFRAME;
		case 2:
			return V4L2_BUF_FLAG_PFRAME;
		case 3:
			return V4L2_BUF_FLAG_BFRAME;
		default:
			return 0;
		}
	}

	return 0;
}

88
static void get_resolution(struct go7007 *go, int *width, int *height)
89 90 91
{
	switch (go->standard) {
	case GO7007_STD_NTSC:
92 93
		*width = 720;
		*height = 480;
94 95
		break;
	case GO7007_STD_PAL:
96 97
		*width = 720;
		*height = 576;
98 99
		break;
	case GO7007_STD_OTHER:
100 101 102
	default:
		*width = go->board_info->sensor_width;
		*height = go->board_info->sensor_height;
103 104
		break;
	}
105 106
}

107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
static void set_formatting(struct go7007 *go)
{
	if (go->format == V4L2_PIX_FMT_MJPEG) {
		go->pali = 0;
		go->aspect_ratio = GO7007_RATIO_1_1;
		go->gop_size = 0;
		go->ipb = 0;
		go->closed_gop = 0;
		go->repeat_seqhead = 0;
		go->seq_header_enable = 0;
		go->gop_header_enable = 0;
		go->dvd_mode = 0;
		return;
	}

	switch (go->format) {
	case V4L2_PIX_FMT_MPEG1:
		go->pali = 0;
		break;
	default:
	case V4L2_PIX_FMT_MPEG2:
		go->pali = 0x48;
		break;
	case V4L2_PIX_FMT_MPEG4:
		/* For future reference: this is the list of MPEG4
		 * profiles that are available, although they are
		 * untested:
		 *
		 * Profile		pali
		 * --------------	----
		 * PROFILE_S_L0		0x08
		 * PROFILE_S_L1		0x01
		 * PROFILE_S_L2		0x02
		 * PROFILE_S_L3		0x03
		 * PROFILE_ARTS_L1	0x91
		 * PROFILE_ARTS_L2	0x92
		 * PROFILE_ARTS_L3	0x93
		 * PROFILE_ARTS_L4	0x94
		 * PROFILE_AS_L0	0xf0
		 * PROFILE_AS_L1	0xf1
		 * PROFILE_AS_L2	0xf2
		 * PROFILE_AS_L3	0xf3
		 * PROFILE_AS_L4	0xf4
		 * PROFILE_AS_L5	0xf5
		 */
		go->pali = 0xf5;
		break;
	}
	go->gop_size = v4l2_ctrl_g_ctrl(go->mpeg_video_gop_size);
	go->closed_gop = v4l2_ctrl_g_ctrl(go->mpeg_video_gop_closure);
157
	go->ipb = v4l2_ctrl_g_ctrl(go->mpeg_video_b_frames) != 0;
158
	go->bitrate = v4l2_ctrl_g_ctrl(go->mpeg_video_bitrate);
159
	go->repeat_seqhead = v4l2_ctrl_g_ctrl(go->mpeg_video_rep_seqheader);
160 161 162 163 164 165
	go->gop_header_enable = 1;
	go->dvd_mode = 0;
	if (go->format == V4L2_PIX_FMT_MPEG2)
		go->dvd_mode =
			go->bitrate == 9800000 &&
			go->gop_size == 15 &&
166
			go->ipb == 0 &&
167
			go->repeat_seqhead == 1 &&
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
			go->closed_gop;

	switch (v4l2_ctrl_g_ctrl(go->mpeg_video_aspect_ratio)) {
	default:
	case V4L2_MPEG_VIDEO_ASPECT_1x1:
		go->aspect_ratio = GO7007_RATIO_1_1;
		break;
	case V4L2_MPEG_VIDEO_ASPECT_4x3:
		go->aspect_ratio = GO7007_RATIO_4_3;
		break;
	case V4L2_MPEG_VIDEO_ASPECT_16x9:
		go->aspect_ratio = GO7007_RATIO_16_9;
		break;
	}
}

184 185 186
static int set_capture_size(struct go7007 *go, struct v4l2_format *fmt, int try)
{
	int sensor_height = 0, sensor_width = 0;
187
	int width, height;
188

189
	if (fmt != NULL && !valid_pixelformat(fmt->fmt.pix.pixelformat))
190 191 192
		return -EINVAL;

	get_resolution(go, &sensor_width, &sensor_height);
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211

	if (fmt == NULL) {
		width = sensor_width;
		height = sensor_height;
	} else if (go->board_info->sensor_flags & GO7007_SENSOR_SCALING) {
		if (fmt->fmt.pix.width > sensor_width)
			width = sensor_width;
		else if (fmt->fmt.pix.width < 144)
			width = 144;
		else
			width = fmt->fmt.pix.width & ~0x0f;

		if (fmt->fmt.pix.height > sensor_height)
			height = sensor_height;
		else if (fmt->fmt.pix.height < 96)
			height = 96;
		else
			height = fmt->fmt.pix.height & ~0x0f;
	} else {
212
		width = fmt->fmt.pix.width;
213

214
		if (width <= sensor_width / 4) {
215 216
			width = sensor_width / 4;
			height = sensor_height / 4;
217
		} else if (width <= sensor_width / 2) {
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
			width = sensor_width / 2;
			height = sensor_height / 2;
		} else {
			width = sensor_width;
			height = sensor_height;
		}
		width &= ~0xf;
		height &= ~0xf;
	}

	if (fmt != NULL) {
		u32 pixelformat = fmt->fmt.pix.pixelformat;

		memset(fmt, 0, sizeof(*fmt));
		fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
		fmt->fmt.pix.width = width;
		fmt->fmt.pix.height = height;
		fmt->fmt.pix.pixelformat = pixelformat;
		fmt->fmt.pix.field = V4L2_FIELD_NONE;
		fmt->fmt.pix.bytesperline = 0;
		fmt->fmt.pix.sizeimage = GO7007_BUF_SIZE;
239
		fmt->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
240 241 242 243 244
	}

	if (try)
		return 0;

245 246
	if (fmt)
		go->format = fmt->fmt.pix.pixelformat;
247 248 249 250 251 252
	go->width = width;
	go->height = height;
	go->encoder_h_offset = go->board_info->sensor_h_offset;
	go->encoder_v_offset = go->board_info->sensor_v_offset;

	if (go->board_info->sensor_flags & GO7007_SENSOR_SCALING) {
253
		struct v4l2_mbus_framefmt mbus_fmt;
254

255
		mbus_fmt.code = V4L2_MBUS_FMT_FIXED;
256 257 258 259 260
		mbus_fmt.width = fmt ? fmt->fmt.pix.width : width;
		mbus_fmt.height = height;
		go->encoder_h_halve = 0;
		go->encoder_v_halve = 0;
		go->encoder_subsample = 0;
261
		call_all(&go->v4l2_dev, video, s_mbus_fmt, &mbus_fmt);
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
	} else {
		if (width <= sensor_width / 4) {
			go->encoder_h_halve = 1;
			go->encoder_v_halve = 1;
			go->encoder_subsample = 1;
		} else if (width <= sensor_width / 2) {
			go->encoder_h_halve = 1;
			go->encoder_v_halve = 1;
			go->encoder_subsample = 0;
		} else {
			go->encoder_h_halve = 0;
			go->encoder_v_halve = 0;
			go->encoder_subsample = 0;
		}
	}
	return 0;
}

280 281
static int vidioc_querycap(struct file *file, void  *priv,
					struct v4l2_capability *cap)
282
{
283
	struct go7007 *go = video_drvdata(file);
284

285 286
	strlcpy(cap->driver, "go7007", sizeof(cap->driver));
	strlcpy(cap->card, go->name, sizeof(cap->card));
287
	strlcpy(cap->bus_info, go->bus_info, sizeof(cap->bus_info));
288

289 290
	cap->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_READWRITE |
				V4L2_CAP_STREAMING;
291

292 293
	if (go->board_info->num_aud_inputs)
		cap->device_caps |= V4L2_CAP_AUDIO;
294
	if (go->board_info->flags & GO7007_BOARD_HAS_TUNER)
295 296
		cap->device_caps |= V4L2_CAP_TUNER;
	cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
297 298
	return 0;
}
299

300 301 302 303
static int vidioc_enum_fmt_vid_cap(struct file *file, void  *priv,
					struct v4l2_fmtdesc *fmt)
{
	char *desc = NULL;
P
Pete Eberlein 已提交
304

305 306 307
	switch (fmt->index) {
	case 0:
		fmt->pixelformat = V4L2_PIX_FMT_MJPEG;
308
		desc = "Motion JPEG";
309 310
		break;
	case 1:
311 312 313 314 315 316 317 318 319 320
		fmt->pixelformat = V4L2_PIX_FMT_MPEG1;
		desc = "MPEG-1 ES";
		break;
	case 2:
		fmt->pixelformat = V4L2_PIX_FMT_MPEG2;
		desc = "MPEG-2 ES";
		break;
	case 3:
		fmt->pixelformat = V4L2_PIX_FMT_MPEG4;
		desc = "MPEG-4 ES";
321 322
		break;
	default:
323
		return -EINVAL;
324 325 326
	}
	fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
	fmt->flags = V4L2_FMT_FLAG_COMPRESSED;
327

328
	strncpy(fmt->description, desc, sizeof(fmt->description));
329

330 331 332 333 334 335
	return 0;
}

static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
					struct v4l2_format *fmt)
{
336
	struct go7007 *go = video_drvdata(file);
337 338 339 340

	fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
	fmt->fmt.pix.width = go->width;
	fmt->fmt.pix.height = go->height;
341
	fmt->fmt.pix.pixelformat = go->format;
342 343 344 345 346 347 348 349 350 351 352
	fmt->fmt.pix.field = V4L2_FIELD_NONE;
	fmt->fmt.pix.bytesperline = 0;
	fmt->fmt.pix.sizeimage = GO7007_BUF_SIZE;
	fmt->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;

	return 0;
}

static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
			struct v4l2_format *fmt)
{
353
	struct go7007 *go = video_drvdata(file);
354 355 356 357 358 359 360

	return set_capture_size(go, fmt, 1);
}

static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
			struct v4l2_format *fmt)
{
361
	struct go7007 *go = video_drvdata(file);
362

363
	if (vb2_is_busy(&go->vidq))
364 365 366 367 368
		return -EBUSY;

	return set_capture_size(go, fmt, 0);
}

369 370
static int go7007_queue_setup(struct vb2_queue *q,
		const struct v4l2_format *fmt,
371 372
		unsigned int *num_buffers, unsigned int *num_planes,
		unsigned int sizes[], void *alloc_ctxs[])
373
{
374 375
	sizes[0] = GO7007_BUF_SIZE;
	*num_planes = 1;
376

377 378
	if (*num_buffers < 2)
		*num_buffers = 2;
379 380 381 382

	return 0;
}

383
static void go7007_buf_queue(struct vb2_buffer *vb)
384
{
385 386 387 388
	struct vb2_queue *vq = vb->vb2_queue;
	struct go7007 *go = vb2_get_drv_priv(vq);
	struct go7007_buffer *go7007_vb =
		container_of(vb, struct go7007_buffer, vb);
389 390 391
	unsigned long flags;

	spin_lock_irqsave(&go->spinlock, flags);
392
	list_add_tail(&go7007_vb->list, &go->vidq_active);
393
	spin_unlock_irqrestore(&go->spinlock, flags);
394
}
395

396 397 398 399
static int go7007_buf_prepare(struct vb2_buffer *vb)
{
	struct go7007_buffer *go7007_vb =
		container_of(vb, struct go7007_buffer, vb);
400

401 402 403 404
	go7007_vb->modet_active = 0;
	go7007_vb->frame_offset = 0;
	vb->v4l2_planes[0].bytesused = 0;
	return 0;
405 406
}

407
static void go7007_buf_finish(struct vb2_buffer *vb)
408
{
409 410 411 412 413 414 415 416 417 418
	struct vb2_queue *vq = vb->vb2_queue;
	struct go7007 *go = vb2_get_drv_priv(vq);
	struct go7007_buffer *go7007_vb =
		container_of(vb, struct go7007_buffer, vb);
	u32 frame_type_flag = get_frame_type_flag(go7007_vb, go->format);
	struct v4l2_buffer *buf = &vb->v4l2_buf;

	buf->flags &= ~(V4L2_BUF_FLAG_KEYFRAME | V4L2_BUF_FLAG_BFRAME |
			V4L2_BUF_FLAG_PFRAME);
	buf->flags |= frame_type_flag;
419 420 421
	buf->field = V4L2_FIELD_NONE;
}

422
static int go7007_start_streaming(struct vb2_queue *q, unsigned int count)
423
{
424 425
	struct go7007 *go = vb2_get_drv_priv(q);
	int ret;
426

427
	set_formatting(go);
428
	mutex_lock(&go->hw_lock);
429 430
	go->next_seq = 0;
	go->active_buf = NULL;
431
	go->modet_event_status = 0;
432 433 434 435 436
	q->streaming = 1;
	if (go7007_start_encoder(go) < 0)
		ret = -EIO;
	else
		ret = 0;
437
	mutex_unlock(&go->hw_lock);
438 439 440 441
	if (ret) {
		q->streaming = 0;
		return ret;
	}
442
	call_all(&go->v4l2_dev, video, s_stream, 1);
443 444 445 446
	v4l2_ctrl_grab(go->mpeg_video_gop_size, true);
	v4l2_ctrl_grab(go->mpeg_video_gop_closure, true);
	v4l2_ctrl_grab(go->mpeg_video_bitrate, true);
	v4l2_ctrl_grab(go->mpeg_video_aspect_ratio, true);
447 448 449
	/* Turn on Capture LED */
	if (go->board_id == GO7007_BOARDID_ADS_USBAV_709)
		go7007_write_addr(go, 0x3c82, 0x0005);
450
	return ret;
451 452
}

453
static void go7007_stop_streaming(struct vb2_queue *q)
454
{
455 456
	struct go7007 *go = vb2_get_drv_priv(q);
	unsigned long flags;
457

458 459 460 461 462
	q->streaming = 0;
	go7007_stream_stop(go);
	mutex_lock(&go->hw_lock);
	go7007_reset_encoder(go);
	mutex_unlock(&go->hw_lock);
463
	call_all(&go->v4l2_dev, video, s_stream, 0);
464

465 466 467 468 469 470 471
	spin_lock_irqsave(&go->spinlock, flags);
	INIT_LIST_HEAD(&go->vidq_active);
	spin_unlock_irqrestore(&go->spinlock, flags);
	v4l2_ctrl_grab(go->mpeg_video_gop_size, false);
	v4l2_ctrl_grab(go->mpeg_video_gop_closure, false);
	v4l2_ctrl_grab(go->mpeg_video_bitrate, false);
	v4l2_ctrl_grab(go->mpeg_video_aspect_ratio, false);
472 473 474
	/* Turn on Capture LED */
	if (go->board_id == GO7007_BOARDID_ADS_USBAV_709)
		go7007_write_addr(go, 0x3c82, 0x000d);
475 476
}

477 478 479 480 481 482 483 484 485 486 487
static struct vb2_ops go7007_video_qops = {
	.queue_setup    = go7007_queue_setup,
	.buf_queue      = go7007_buf_queue,
	.buf_prepare    = go7007_buf_prepare,
	.buf_finish     = go7007_buf_finish,
	.start_streaming = go7007_start_streaming,
	.stop_streaming = go7007_stop_streaming,
	.wait_prepare   = vb2_ops_wait_prepare,
	.wait_finish    = vb2_ops_wait_finish,
};

488 489 490
static int vidioc_g_parm(struct file *filp, void *priv,
		struct v4l2_streamparm *parm)
{
491
	struct go7007 *go = video_drvdata(filp);
492 493 494 495 496 497 498 499
	struct v4l2_fract timeperframe = {
		.numerator = 1001 *  go->fps_scale,
		.denominator = go->sensor_framerate,
	};

	if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
		return -EINVAL;

500 501
	parm->parm.capture.readbuffers = 2;
	parm->parm.capture.capability = V4L2_CAP_TIMEPERFRAME;
502 503 504 505 506 507 508 509
	parm->parm.capture.timeperframe = timeperframe;

	return 0;
}

static int vidioc_s_parm(struct file *filp, void *priv,
		struct v4l2_streamparm *parm)
{
510
	struct go7007 *go = video_drvdata(filp);
511 512 513 514 515 516 517 518 519 520 521 522 523
	unsigned int n, d;

	if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
		return -EINVAL;

	n = go->sensor_framerate *
		parm->parm.capture.timeperframe.numerator;
	d = 1001 * parm->parm.capture.timeperframe.denominator;
	if (n != 0 && d != 0 && n > d)
		go->fps_scale = (n + d/2) / d;
	else
		go->fps_scale = 1;

524
	return vidioc_g_parm(filp, priv, parm);
525 526
}

527
/* VIDIOC_ENUMSTD on go7007 were used for enumerating the supported fps and
528
   its resolution, when the device is not connected to TV.
529 530
   This is were an API abuse, probably used by the lack of specific IOCTL's to
   enumerate it, by the time the driver was written.
531 532 533 534

   However, since kernel 2.6.19, two new ioctls (VIDIOC_ENUM_FRAMEINTERVALS
   and VIDIOC_ENUM_FRAMESIZES) were added for this purpose.

535
   The two functions below implement the newer ioctls
536 537 538 539
*/
static int vidioc_enum_framesizes(struct file *filp, void *priv,
				  struct v4l2_frmsizeenum *fsize)
{
540
	struct go7007 *go = video_drvdata(filp);
541
	int width, height;
542

543
	if (fsize->index > 2)
544 545
		return -EINVAL;

546
	if (!valid_pixelformat(fsize->pixel_format))
547 548
		return -EINVAL;

549
	get_resolution(go, &width, &height);
550
	fsize->type = V4L2_FRMSIZE_TYPE_DISCRETE;
551 552
	fsize->discrete.width = (width >> fsize->index) & ~0xf;
	fsize->discrete.height = (height >> fsize->index) & ~0xf;
553 554 555 556 557 558
	return 0;
}

static int vidioc_enum_frameintervals(struct file *filp, void *priv,
				      struct v4l2_frmivalenum *fival)
{
559
	struct go7007 *go = video_drvdata(filp);
560 561
	int width, height;
	int i;
562

563
	if (fival->index > 4)
564 565
		return -EINVAL;

566
	if (!valid_pixelformat(fival->pixel_format))
567 568
		return -EINVAL;

569 570 571 572 573 574 575 576 577
	if (!(go->board_info->sensor_flags & GO7007_SENSOR_SCALING)) {
		get_resolution(go, &width, &height);
		for (i = 0; i <= 2; i++)
			if (fival->width == ((width >> i) & ~0xf) &&
			    fival->height == ((height >> i) & ~0xf))
				break;
		if (i > 2)
			return -EINVAL;
	}
578
	fival->type = V4L2_FRMIVAL_TYPE_DISCRETE;
579 580
	fival->discrete.numerator = 1001 * (fival->index + 1);
	fival->discrete.denominator = go->sensor_framerate;
581 582 583
	return 0;
}

584 585
static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id *std)
{
586
	struct go7007 *go = video_drvdata(file);
587

588 589 590 591 592 593
	*std = go->std;
	return 0;
}

static int go7007_s_std(struct go7007 *go)
{
594
	if (go->std & V4L2_STD_625_50) {
595 596
		go->standard = GO7007_STD_PAL;
		go->sensor_framerate = 25025;
597 598 599
	} else {
		go->standard = GO7007_STD_NTSC;
		go->sensor_framerate = 30000;
600 601
	}

602
	call_all(&go->v4l2_dev, video, s_std, go->std);
603
	set_capture_size(go, NULL, 0);
604 605 606
	return 0;
}

607
static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id std)
608
{
609
	struct go7007 *go = video_drvdata(file);
610

611
	if (vb2_is_busy(&go->vidq))
612 613
		return -EBUSY;

614
	go->std = std;
615

616
	return go7007_s_std(go);
617
}
P
Pete Eberlein 已提交
618

619 620
static int vidioc_querystd(struct file *file, void *priv, v4l2_std_id *std)
{
621
	struct go7007 *go = video_drvdata(file);
622

623
	return call_all(&go->v4l2_dev, video, querystd, std);
624
}
625

626 627 628
static int vidioc_enum_input(struct file *file, void *priv,
				struct v4l2_input *inp)
{
629
	struct go7007 *go = video_drvdata(file);
630

631 632
	if (inp->index >= go->board_info->num_inputs)
		return -EINVAL;
633

634 635
	strncpy(inp->name, go->board_info->inputs[inp->index].name,
			sizeof(inp->name));
636

637
	/* If this board has a tuner, it will be the first input */
638
	if ((go->board_info->flags & GO7007_BOARD_HAS_TUNER) &&
639
			inp->index == 0)
640 641 642
		inp->type = V4L2_INPUT_TYPE_TUNER;
	else
		inp->type = V4L2_INPUT_TYPE_CAMERA;
643

644 645 646 647
	if (go->board_info->num_aud_inputs)
		inp->audioset = (1 << go->board_info->num_aud_inputs) - 1;
	else
		inp->audioset = 0;
648 649
	inp->tuner = 0;
	if (go->board_info->sensor_flags & GO7007_SENSOR_TV)
650
		inp->std = video_devdata(file)->tvnorms;
651 652
	else
		inp->std = 0;
653

654 655
	return 0;
}
656 657


658 659
static int vidioc_g_input(struct file *file, void *priv, unsigned int *input)
{
660
	struct go7007 *go = video_drvdata(file);
661

662
	*input = go->input;
663

664 665 666
	return 0;
}

667 668 669 670 671 672
static int vidioc_enumaudio(struct file *file, void *fh, struct v4l2_audio *a)
{
	struct go7007 *go = video_drvdata(file);

	if (a->index >= go->board_info->num_aud_inputs)
		return -EINVAL;
673 674
	strlcpy(a->name, go->board_info->aud_inputs[a->index].name,
		sizeof(a->name));
675 676 677 678 679 680 681 682 683
	a->capability = V4L2_AUDCAP_STEREO;
	return 0;
}

static int vidioc_g_audio(struct file *file, void *fh, struct v4l2_audio *a)
{
	struct go7007 *go = video_drvdata(file);

	a->index = go->aud_input;
684 685
	strlcpy(a->name, go->board_info->aud_inputs[go->aud_input].name,
		sizeof(a->name));
686 687 688 689
	a->capability = V4L2_AUDCAP_STEREO;
	return 0;
}

690 691
static int vidioc_s_audio(struct file *file, void *fh,
	const struct v4l2_audio *a)
692 693 694 695 696 697 698
{
	struct go7007 *go = video_drvdata(file);

	if (a->index >= go->board_info->num_aud_inputs)
		return -EINVAL;
	go->aud_input = a->index;
	v4l2_subdev_call(go->sd_audio, audio, s_routing,
699
		go->board_info->aud_inputs[go->aud_input].audio_input, 0, 0);
700 701 702
	return 0;
}

703
static void go7007_s_input(struct go7007 *go)
704
{
705
	unsigned int input = go->input;
706

707 708 709 710 711 712 713 714 715 716
	v4l2_subdev_call(go->sd_video, video, s_routing,
			go->board_info->inputs[input].video_input, 0,
			go->board_info->video_config);
	if (go->board_info->num_aud_inputs) {
		int aud_input = go->board_info->inputs[input].audio_index;

		v4l2_subdev_call(go->sd_audio, audio, s_routing,
			go->board_info->aud_inputs[aud_input].audio_input, 0, 0);
		go->aud_input = aud_input;
	}
717 718 719 720 721 722 723 724
}

static int vidioc_s_input(struct file *file, void *priv, unsigned int input)
{
	struct go7007 *go = video_drvdata(file);

	if (input >= go->board_info->num_inputs)
		return -EINVAL;
725
	if (vb2_is_busy(&go->vidq))
726 727 728 729 730
		return -EBUSY;

	go->input = input;
	go7007_s_input(go);

731
	return 0;
732 733 734 735 736
}

static int vidioc_g_tuner(struct file *file, void *priv,
				struct v4l2_tuner *t)
{
737
	struct go7007 *go = video_drvdata(file);
738 739 740 741

	if (t->index != 0)
		return -EINVAL;

742
	strlcpy(t->name, "Tuner", sizeof(t->name));
743
	return call_all(&go->v4l2_dev, tuner, g_tuner, t);
744 745 746
}

static int vidioc_s_tuner(struct file *file, void *priv,
747
				const struct v4l2_tuner *t)
748
{
749
	struct go7007 *go = video_drvdata(file);
750 751 752 753

	if (t->index != 0)
		return -EINVAL;

754
	return call_all(&go->v4l2_dev, tuner, s_tuner, t);
755 756 757 758 759
}

static int vidioc_g_frequency(struct file *file, void *priv,
				struct v4l2_frequency *f)
{
760
	struct go7007 *go = video_drvdata(file);
761

762
	if (f->tuner)
763
		return -EINVAL;
764 765

	return call_all(&go->v4l2_dev, tuner, g_frequency, f);
766 767 768
}

static int vidioc_s_frequency(struct file *file, void *priv,
769
				const struct v4l2_frequency *f)
770
{
771
	struct go7007 *go = video_drvdata(file);
772

773
	if (f->tuner)
774 775
		return -EINVAL;

776
	return call_all(&go->v4l2_dev, tuner, s_frequency, f);
777 778
}

779 780
static int vidioc_log_status(struct file *file, void *priv)
{
781
	struct go7007 *go = video_drvdata(file);
782 783 784 785 786

	v4l2_ctrl_log_status(file, priv);
	return call_all(&go->v4l2_dev, core, log_status);
}

787 788 789
static int vidioc_subscribe_event(struct v4l2_fh *fh,
				const struct v4l2_event_subscription *sub)
{
790

791 792 793 794 795 796 797
	switch (sub->type) {
	case V4L2_EVENT_CTRL:
		return v4l2_ctrl_subscribe_event(fh, sub);
	case V4L2_EVENT_MOTION_DET:
		/* Allow for up to 30 events (1 second for NTSC) to be
		 * stored. */
		return v4l2_event_subscribe(fh, sub, 30, NULL);
798
	}
799 800
	return -EINVAL;
}
801

802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853

static int go7007_s_ctrl(struct v4l2_ctrl *ctrl)
{
	struct go7007 *go =
		container_of(ctrl->handler, struct go7007, hdl);
	unsigned y;
	u8 *mt;

	switch (ctrl->id) {
	case V4L2_CID_PIXEL_THRESHOLD0:
		go->modet[0].pixel_threshold = ctrl->val;
		break;
	case V4L2_CID_MOTION_THRESHOLD0:
		go->modet[0].motion_threshold = ctrl->val;
		break;
	case V4L2_CID_MB_THRESHOLD0:
		go->modet[0].mb_threshold = ctrl->val;
		break;
	case V4L2_CID_PIXEL_THRESHOLD1:
		go->modet[1].pixel_threshold = ctrl->val;
		break;
	case V4L2_CID_MOTION_THRESHOLD1:
		go->modet[1].motion_threshold = ctrl->val;
		break;
	case V4L2_CID_MB_THRESHOLD1:
		go->modet[1].mb_threshold = ctrl->val;
		break;
	case V4L2_CID_PIXEL_THRESHOLD2:
		go->modet[2].pixel_threshold = ctrl->val;
		break;
	case V4L2_CID_MOTION_THRESHOLD2:
		go->modet[2].motion_threshold = ctrl->val;
		break;
	case V4L2_CID_MB_THRESHOLD2:
		go->modet[2].mb_threshold = ctrl->val;
		break;
	case V4L2_CID_PIXEL_THRESHOLD3:
		go->modet[3].pixel_threshold = ctrl->val;
		break;
	case V4L2_CID_MOTION_THRESHOLD3:
		go->modet[3].motion_threshold = ctrl->val;
		break;
	case V4L2_CID_MB_THRESHOLD3:
		go->modet[3].mb_threshold = ctrl->val;
		break;
	case V4L2_CID_DETECT_MD_REGION_GRID:
		mt = go->modet_map;
		for (y = 0; y < go->height / 16; y++, mt += go->width / 16)
			memcpy(mt, ctrl->p_new.p_u8 + y * (720 / 16), go->width / 16);
		break;
	default:
		return -EINVAL;
854
	}
855 856
	return 0;
}
857

858
static struct v4l2_file_operations go7007_fops = {
859
	.owner		= THIS_MODULE,
860
	.open		= v4l2_fh_open,
861 862 863 864 865
	.release	= vb2_fop_release,
	.unlocked_ioctl	= video_ioctl2,
	.read		= vb2_fop_read,
	.mmap		= vb2_fop_mmap,
	.poll		= vb2_fop_poll,
866 867
};

868 869 870 871 872 873
static const struct v4l2_ioctl_ops video_ioctl_ops = {
	.vidioc_querycap          = vidioc_querycap,
	.vidioc_enum_fmt_vid_cap  = vidioc_enum_fmt_vid_cap,
	.vidioc_g_fmt_vid_cap     = vidioc_g_fmt_vid_cap,
	.vidioc_try_fmt_vid_cap   = vidioc_try_fmt_vid_cap,
	.vidioc_s_fmt_vid_cap     = vidioc_s_fmt_vid_cap,
874 875 876 877
	.vidioc_reqbufs           = vb2_ioctl_reqbufs,
	.vidioc_querybuf          = vb2_ioctl_querybuf,
	.vidioc_qbuf              = vb2_ioctl_qbuf,
	.vidioc_dqbuf             = vb2_ioctl_dqbuf,
878
	.vidioc_g_std             = vidioc_g_std,
879
	.vidioc_s_std             = vidioc_s_std,
880
	.vidioc_querystd          = vidioc_querystd,
881 882 883
	.vidioc_enum_input        = vidioc_enum_input,
	.vidioc_g_input           = vidioc_g_input,
	.vidioc_s_input           = vidioc_s_input,
884 885 886
	.vidioc_enumaudio         = vidioc_enumaudio,
	.vidioc_g_audio           = vidioc_g_audio,
	.vidioc_s_audio           = vidioc_s_audio,
887 888
	.vidioc_streamon          = vb2_ioctl_streamon,
	.vidioc_streamoff         = vb2_ioctl_streamoff,
889 890 891 892 893 894 895 896
	.vidioc_g_tuner           = vidioc_g_tuner,
	.vidioc_s_tuner           = vidioc_s_tuner,
	.vidioc_g_frequency       = vidioc_g_frequency,
	.vidioc_s_frequency       = vidioc_s_frequency,
	.vidioc_g_parm            = vidioc_g_parm,
	.vidioc_s_parm            = vidioc_s_parm,
	.vidioc_enum_framesizes   = vidioc_enum_framesizes,
	.vidioc_enum_frameintervals = vidioc_enum_frameintervals,
897
	.vidioc_log_status        = vidioc_log_status,
898
	.vidioc_subscribe_event   = vidioc_subscribe_event,
899
	.vidioc_unsubscribe_event = v4l2_event_unsubscribe,
900 901
};

902 903 904
static struct video_device go7007_template = {
	.name		= "go7007",
	.fops		= &go7007_fops,
905
	.release	= video_device_release_empty,
906 907
	.ioctl_ops	= &video_ioctl_ops,
	.tvnorms	= V4L2_STD_ALL,
908 909
};

910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041
static const struct v4l2_ctrl_ops go7007_ctrl_ops = {
	.s_ctrl = go7007_s_ctrl,
};

static const struct v4l2_ctrl_config go7007_pixel_threshold0_ctrl = {
	.ops = &go7007_ctrl_ops,
	.id = V4L2_CID_PIXEL_THRESHOLD0,
	.name = "Pixel Threshold Region 0",
	.type = V4L2_CTRL_TYPE_INTEGER,
	.def = 20,
	.max = 32767,
	.step = 1,
};

static const struct v4l2_ctrl_config go7007_motion_threshold0_ctrl = {
	.ops = &go7007_ctrl_ops,
	.id = V4L2_CID_MOTION_THRESHOLD0,
	.name = "Motion Threshold Region 0",
	.type = V4L2_CTRL_TYPE_INTEGER,
	.def = 80,
	.max = 32767,
	.step = 1,
};

static const struct v4l2_ctrl_config go7007_mb_threshold0_ctrl = {
	.ops = &go7007_ctrl_ops,
	.id = V4L2_CID_MB_THRESHOLD0,
	.name = "MB Threshold Region 0",
	.type = V4L2_CTRL_TYPE_INTEGER,
	.def = 200,
	.max = 32767,
	.step = 1,
};

static const struct v4l2_ctrl_config go7007_pixel_threshold1_ctrl = {
	.ops = &go7007_ctrl_ops,
	.id = V4L2_CID_PIXEL_THRESHOLD1,
	.name = "Pixel Threshold Region 1",
	.type = V4L2_CTRL_TYPE_INTEGER,
	.def = 20,
	.max = 32767,
	.step = 1,
};

static const struct v4l2_ctrl_config go7007_motion_threshold1_ctrl = {
	.ops = &go7007_ctrl_ops,
	.id = V4L2_CID_MOTION_THRESHOLD1,
	.name = "Motion Threshold Region 1",
	.type = V4L2_CTRL_TYPE_INTEGER,
	.def = 80,
	.max = 32767,
	.step = 1,
};

static const struct v4l2_ctrl_config go7007_mb_threshold1_ctrl = {
	.ops = &go7007_ctrl_ops,
	.id = V4L2_CID_MB_THRESHOLD1,
	.name = "MB Threshold Region 1",
	.type = V4L2_CTRL_TYPE_INTEGER,
	.def = 200,
	.max = 32767,
	.step = 1,
};

static const struct v4l2_ctrl_config go7007_pixel_threshold2_ctrl = {
	.ops = &go7007_ctrl_ops,
	.id = V4L2_CID_PIXEL_THRESHOLD2,
	.name = "Pixel Threshold Region 2",
	.type = V4L2_CTRL_TYPE_INTEGER,
	.def = 20,
	.max = 32767,
	.step = 1,
};

static const struct v4l2_ctrl_config go7007_motion_threshold2_ctrl = {
	.ops = &go7007_ctrl_ops,
	.id = V4L2_CID_MOTION_THRESHOLD2,
	.name = "Motion Threshold Region 2",
	.type = V4L2_CTRL_TYPE_INTEGER,
	.def = 80,
	.max = 32767,
	.step = 1,
};

static const struct v4l2_ctrl_config go7007_mb_threshold2_ctrl = {
	.ops = &go7007_ctrl_ops,
	.id = V4L2_CID_MB_THRESHOLD2,
	.name = "MB Threshold Region 2",
	.type = V4L2_CTRL_TYPE_INTEGER,
	.def = 200,
	.max = 32767,
	.step = 1,
};

static const struct v4l2_ctrl_config go7007_pixel_threshold3_ctrl = {
	.ops = &go7007_ctrl_ops,
	.id = V4L2_CID_PIXEL_THRESHOLD3,
	.name = "Pixel Threshold Region 3",
	.type = V4L2_CTRL_TYPE_INTEGER,
	.def = 20,
	.max = 32767,
	.step = 1,
};

static const struct v4l2_ctrl_config go7007_motion_threshold3_ctrl = {
	.ops = &go7007_ctrl_ops,
	.id = V4L2_CID_MOTION_THRESHOLD3,
	.name = "Motion Threshold Region 3",
	.type = V4L2_CTRL_TYPE_INTEGER,
	.def = 80,
	.max = 32767,
	.step = 1,
};

static const struct v4l2_ctrl_config go7007_mb_threshold3_ctrl = {
	.ops = &go7007_ctrl_ops,
	.id = V4L2_CID_MB_THRESHOLD3,
	.name = "MB Threshold Region 3",
	.type = V4L2_CTRL_TYPE_INTEGER,
	.def = 200,
	.max = 32767,
	.step = 1,
};

static const struct v4l2_ctrl_config go7007_mb_regions_ctrl = {
	.ops = &go7007_ctrl_ops,
	.id = V4L2_CID_DETECT_MD_REGION_GRID,
	.dims = { 576 / 16, 720 / 16 },
	.max = 3,
	.step = 1,
};

1042 1043 1044 1045 1046
int go7007_v4l2_ctrl_init(struct go7007 *go)
{
	struct v4l2_ctrl_handler *hdl = &go->hdl;
	struct v4l2_ctrl *ctrl;

1047
	v4l2_ctrl_handler_init(hdl, 22);
1048
	go->mpeg_video_gop_size = v4l2_ctrl_new_std(hdl, NULL,
1049
			V4L2_CID_MPEG_VIDEO_GOP_SIZE, 0, 34, 1, 15);
1050 1051 1052
	go->mpeg_video_gop_closure = v4l2_ctrl_new_std(hdl, NULL,
			V4L2_CID_MPEG_VIDEO_GOP_CLOSURE, 0, 1, 1, 1);
	go->mpeg_video_bitrate = v4l2_ctrl_new_std(hdl, NULL,
1053
			V4L2_CID_MPEG_VIDEO_BITRATE,
1054
			64000, 10000000, 1, 9800000);
1055 1056
	go->mpeg_video_b_frames = v4l2_ctrl_new_std(hdl, NULL,
			V4L2_CID_MPEG_VIDEO_B_FRAMES, 0, 2, 2, 0);
1057 1058
	go->mpeg_video_rep_seqheader = v4l2_ctrl_new_std(hdl, NULL,
			V4L2_CID_MPEG_VIDEO_REPEAT_SEQ_HEADER, 0, 1, 1, 1);
1059

1060 1061 1062 1063 1064
	go->mpeg_video_aspect_ratio = v4l2_ctrl_new_std_menu(hdl, NULL,
			V4L2_CID_MPEG_VIDEO_ASPECT,
			V4L2_MPEG_VIDEO_ASPECT_16x9, 0,
			V4L2_MPEG_VIDEO_ASPECT_1x1);
	ctrl = v4l2_ctrl_new_std(hdl, NULL,
1065
			V4L2_CID_JPEG_ACTIVE_MARKER, 0,
1066 1067 1068 1069
			V4L2_JPEG_ACTIVE_MARKER_DQT |
			V4L2_JPEG_ACTIVE_MARKER_DHT, 0,
			V4L2_JPEG_ACTIVE_MARKER_DQT |
			V4L2_JPEG_ACTIVE_MARKER_DHT);
1070 1071
	if (ctrl)
		ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY;
1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089
	v4l2_ctrl_new_custom(hdl, &go7007_pixel_threshold0_ctrl, NULL);
	v4l2_ctrl_new_custom(hdl, &go7007_motion_threshold0_ctrl, NULL);
	v4l2_ctrl_new_custom(hdl, &go7007_mb_threshold0_ctrl, NULL);
	v4l2_ctrl_new_custom(hdl, &go7007_pixel_threshold1_ctrl, NULL);
	v4l2_ctrl_new_custom(hdl, &go7007_motion_threshold1_ctrl, NULL);
	v4l2_ctrl_new_custom(hdl, &go7007_mb_threshold1_ctrl, NULL);
	v4l2_ctrl_new_custom(hdl, &go7007_pixel_threshold2_ctrl, NULL);
	v4l2_ctrl_new_custom(hdl, &go7007_motion_threshold2_ctrl, NULL);
	v4l2_ctrl_new_custom(hdl, &go7007_mb_threshold2_ctrl, NULL);
	v4l2_ctrl_new_custom(hdl, &go7007_pixel_threshold3_ctrl, NULL);
	v4l2_ctrl_new_custom(hdl, &go7007_motion_threshold3_ctrl, NULL);
	v4l2_ctrl_new_custom(hdl, &go7007_mb_threshold3_ctrl, NULL);
	v4l2_ctrl_new_custom(hdl, &go7007_mb_regions_ctrl, NULL);
	go->modet_mode = v4l2_ctrl_new_std_menu(hdl, NULL,
			V4L2_CID_DETECT_MD_MODE,
			V4L2_DETECT_MD_MODE_REGION_GRID,
			1 << V4L2_DETECT_MD_MODE_THRESHOLD_GRID,
			V4L2_DETECT_MD_MODE_DISABLED);
1090 1091 1092 1093 1094 1095 1096 1097 1098 1099
	if (hdl->error) {
		int rv = hdl->error;

		v4l2_err(&go->v4l2_dev, "Could not register controls\n");
		return rv;
	}
	go->v4l2_dev.ctrl_handler = hdl;
	return 0;
}

1100 1101
int go7007_v4l2_init(struct go7007 *go)
{
1102
	struct video_device *vdev = &go->vdev;
1103 1104
	int rv;

1105 1106 1107 1108 1109 1110 1111 1112 1113 1114
	mutex_init(&go->serialize_lock);
	mutex_init(&go->queue_lock);

	INIT_LIST_HEAD(&go->vidq_active);
	go->vidq.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
	go->vidq.io_modes = VB2_MMAP | VB2_USERPTR | VB2_READ;
	go->vidq.ops = &go7007_video_qops;
	go->vidq.mem_ops = &vb2_vmalloc_memops;
	go->vidq.drv_priv = go;
	go->vidq.buf_struct_size = sizeof(struct go7007_buffer);
1115
	go->vidq.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
1116 1117 1118 1119
	go->vidq.lock = &go->queue_lock;
	rv = vb2_queue_init(&go->vidq);
	if (rv)
		return rv;
1120 1121 1122 1123 1124
	*vdev = go7007_template;
	vdev->lock = &go->serialize_lock;
	vdev->queue = &go->vidq;
	video_set_drvdata(vdev, go);
	vdev->v4l2_dev = &go->v4l2_dev;
1125
	if (!v4l2_device_has_op(&go->v4l2_dev, video, querystd))
1126
		v4l2_disable_ioctl(vdev, VIDIOC_QUERYSTD);
1127
	if (!(go->board_info->flags & GO7007_BOARD_HAS_TUNER)) {
1128 1129 1130 1131
		v4l2_disable_ioctl(vdev, VIDIOC_S_FREQUENCY);
		v4l2_disable_ioctl(vdev, VIDIOC_G_FREQUENCY);
		v4l2_disable_ioctl(vdev, VIDIOC_S_TUNER);
		v4l2_disable_ioctl(vdev, VIDIOC_G_TUNER);
1132 1133 1134 1135 1136 1137 1138 1139 1140
	} else {
		struct v4l2_frequency f = {
			.type = V4L2_TUNER_ANALOG_TV,
			.frequency = 980,
		};

		call_all(&go->v4l2_dev, tuner, s_frequency, &f);
	}
	if (!(go->board_info->sensor_flags & GO7007_SENSOR_TV)) {
1141 1142 1143
		v4l2_disable_ioctl(vdev, VIDIOC_G_STD);
		v4l2_disable_ioctl(vdev, VIDIOC_S_STD);
		vdev->tvnorms = 0;
1144
	}
1145
	if (go->board_info->sensor_flags & GO7007_SENSOR_SCALING)
1146
		v4l2_disable_ioctl(vdev, VIDIOC_ENUM_FRAMESIZES);
1147
	if (go->board_info->num_aud_inputs == 0) {
1148 1149 1150
		v4l2_disable_ioctl(vdev, VIDIOC_G_AUDIO);
		v4l2_disable_ioctl(vdev, VIDIOC_S_AUDIO);
		v4l2_disable_ioctl(vdev, VIDIOC_ENUMAUDIO);
1151
	}
1152 1153 1154 1155 1156 1157
	/* Setup correct crystal frequency on this board */
	if (go->board_info->sensor_flags & GO7007_SENSOR_SAA7115)
		v4l2_subdev_call(go->sd_video, video, s_crystal_freq,
				SAA7115_FREQ_24_576_MHZ,
				SAA7115_FREQ_FL_APLL | SAA7115_FREQ_FL_UCGC |
				SAA7115_FREQ_FL_DOUBLE_ASCLK);
1158 1159 1160
	go7007_s_input(go);
	if (go->board_info->sensor_flags & GO7007_SENSOR_TV)
		go7007_s_std(go);
1161 1162
	rv = video_register_device(vdev, VFL_TYPE_GRABBER, -1);
	if (rv < 0)
1163
		return rv;
1164
	dev_info(go->dev, "registered device %s [v4l2]\n",
1165
		 video_device_node_name(vdev));
1166 1167 1168 1169 1170 1171

	return 0;
}

void go7007_v4l2_remove(struct go7007 *go)
{
1172
	v4l2_ctrl_handler_free(&go->hdl);
1173
}