blob: da66e5f8d91d1c40d60042d14bdd3c8f4cb21b36 [file] [log] [blame]
Steven Tothe47f30b2008-01-10 04:25:59 -03001/*
2 * Driver for the Conexant CX23885 PCIe bridge
3 *
Steven Toth6d897612008-09-03 17:12:12 -03004 * Copyright (c) 2007 Steven Toth <stoth@linuxtv.org>
Steven Tothe47f30b2008-01-10 04:25:59 -03005 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 *
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22#include <linux/init.h>
23#include <linux/list.h>
24#include <linux/module.h>
25#include <linux/moduleparam.h>
26#include <linux/kmod.h>
27#include <linux/kernel.h>
28#include <linux/slab.h>
Alexey Dobriyan405f5572009-07-11 22:08:37 +040029#include <linux/smp_lock.h>
Steven Tothe47f30b2008-01-10 04:25:59 -030030#include <linux/interrupt.h>
31#include <linux/delay.h>
32#include <linux/kthread.h>
33#include <asm/div64.h>
34
35#include "cx23885.h"
36#include <media/v4l2-common.h>
Hans Verkuil35ea11f2008-07-20 08:12:02 -030037#include <media/v4l2-ioctl.h>
Andy Walls74618242009-09-26 22:50:44 -030038#include "cx23885-ioctl.h"
Kusanagi Kouichi0b32d652010-01-22 04:55:28 -030039#include "tuner-xc2028.h"
Steven Tothe47f30b2008-01-10 04:25:59 -030040
Steven Tothe47f30b2008-01-10 04:25:59 -030041MODULE_DESCRIPTION("v4l2 driver module for cx23885 based TV cards");
Steven Toth6d897612008-09-03 17:12:12 -030042MODULE_AUTHOR("Steven Toth <stoth@linuxtv.org>");
Steven Tothe47f30b2008-01-10 04:25:59 -030043MODULE_LICENSE("GPL");
44
45/* ------------------------------------------------------------------ */
46
47static unsigned int video_nr[] = {[0 ... (CX23885_MAXBOARDS - 1)] = UNSET };
48static unsigned int vbi_nr[] = {[0 ... (CX23885_MAXBOARDS - 1)] = UNSET };
49static unsigned int radio_nr[] = {[0 ... (CX23885_MAXBOARDS - 1)] = UNSET };
50
51module_param_array(video_nr, int, NULL, 0444);
52module_param_array(vbi_nr, int, NULL, 0444);
53module_param_array(radio_nr, int, NULL, 0444);
54
55MODULE_PARM_DESC(video_nr, "video device numbers");
56MODULE_PARM_DESC(vbi_nr, "vbi device numbers");
57MODULE_PARM_DESC(radio_nr, "radio device numbers");
58
Steven Toth4513fc692008-01-12 11:36:36 -030059static unsigned int video_debug;
Steven Tothe47f30b2008-01-10 04:25:59 -030060module_param(video_debug, int, 0644);
61MODULE_PARM_DESC(video_debug, "enable debug messages [video]");
62
Steven Toth4513fc692008-01-12 11:36:36 -030063static unsigned int irq_debug;
Steven Tothe47f30b2008-01-10 04:25:59 -030064module_param(irq_debug, int, 0644);
65MODULE_PARM_DESC(irq_debug, "enable debug messages [IRQ handler]");
66
67static unsigned int vid_limit = 16;
68module_param(vid_limit, int, 0644);
69MODULE_PARM_DESC(vid_limit, "capture memory limit in megabytes");
70
71#define dprintk(level, fmt, arg...)\
Steven Toth4513fc692008-01-12 11:36:36 -030072 do { if (video_debug >= level)\
73 printk(KERN_DEBUG "%s/0: " fmt, dev->name, ## arg);\
74 } while (0)
Steven Tothe47f30b2008-01-10 04:25:59 -030075
76/* ------------------------------------------------------------------- */
77/* static data */
78
79#define FORMAT_FLAGS_PACKED 0x01
80
81static struct cx23885_fmt formats[] = {
82 {
83 .name = "8 bpp, gray",
84 .fourcc = V4L2_PIX_FMT_GREY,
85 .depth = 8,
86 .flags = FORMAT_FLAGS_PACKED,
87 }, {
88 .name = "15 bpp RGB, le",
89 .fourcc = V4L2_PIX_FMT_RGB555,
90 .depth = 16,
91 .flags = FORMAT_FLAGS_PACKED,
92 }, {
93 .name = "15 bpp RGB, be",
94 .fourcc = V4L2_PIX_FMT_RGB555X,
95 .depth = 16,
96 .flags = FORMAT_FLAGS_PACKED,
97 }, {
98 .name = "16 bpp RGB, le",
99 .fourcc = V4L2_PIX_FMT_RGB565,
100 .depth = 16,
101 .flags = FORMAT_FLAGS_PACKED,
102 }, {
103 .name = "16 bpp RGB, be",
104 .fourcc = V4L2_PIX_FMT_RGB565X,
105 .depth = 16,
106 .flags = FORMAT_FLAGS_PACKED,
107 }, {
108 .name = "24 bpp RGB, le",
109 .fourcc = V4L2_PIX_FMT_BGR24,
110 .depth = 24,
111 .flags = FORMAT_FLAGS_PACKED,
112 }, {
113 .name = "32 bpp RGB, le",
114 .fourcc = V4L2_PIX_FMT_BGR32,
115 .depth = 32,
116 .flags = FORMAT_FLAGS_PACKED,
117 }, {
118 .name = "32 bpp RGB, be",
119 .fourcc = V4L2_PIX_FMT_RGB32,
120 .depth = 32,
121 .flags = FORMAT_FLAGS_PACKED,
122 }, {
123 .name = "4:2:2, packed, YUYV",
124 .fourcc = V4L2_PIX_FMT_YUYV,
125 .depth = 16,
126 .flags = FORMAT_FLAGS_PACKED,
127 }, {
128 .name = "4:2:2, packed, UYVY",
129 .fourcc = V4L2_PIX_FMT_UYVY,
130 .depth = 16,
131 .flags = FORMAT_FLAGS_PACKED,
132 },
133};
134
135static struct cx23885_fmt *format_by_fourcc(unsigned int fourcc)
136{
137 unsigned int i;
138
139 for (i = 0; i < ARRAY_SIZE(formats); i++)
140 if (formats[i].fourcc == fourcc)
141 return formats+i;
142
Harvey Harrison22b4e642008-04-08 23:20:00 -0300143 printk(KERN_ERR "%s(0x%08x) NOT FOUND\n", __func__, fourcc);
Steven Tothe47f30b2008-01-10 04:25:59 -0300144 return NULL;
145}
146
147/* ------------------------------------------------------------------- */
148
149static const struct v4l2_queryctrl no_ctl = {
150 .name = "42",
151 .flags = V4L2_CTRL_FLAG_DISABLED,
152};
153
154static struct cx23885_ctrl cx23885_ctls[] = {
155 /* --- video --- */
156 {
157 .v = {
158 .id = V4L2_CID_BRIGHTNESS,
159 .name = "Brightness",
160 .minimum = 0x00,
161 .maximum = 0xff,
162 .step = 1,
163 .default_value = 0x7f,
164 .type = V4L2_CTRL_TYPE_INTEGER,
165 },
166 .off = 128,
167 .reg = LUMA_CTRL,
168 .mask = 0x00ff,
169 .shift = 0,
170 }, {
171 .v = {
172 .id = V4L2_CID_CONTRAST,
173 .name = "Contrast",
174 .minimum = 0,
175 .maximum = 0xff,
176 .step = 1,
177 .default_value = 0x3f,
178 .type = V4L2_CTRL_TYPE_INTEGER,
179 },
180 .off = 0,
181 .reg = LUMA_CTRL,
182 .mask = 0xff00,
183 .shift = 8,
184 }, {
185 .v = {
186 .id = V4L2_CID_HUE,
187 .name = "Hue",
188 .minimum = 0,
189 .maximum = 0xff,
190 .step = 1,
191 .default_value = 0x7f,
192 .type = V4L2_CTRL_TYPE_INTEGER,
193 },
194 .off = 128,
195 .reg = CHROMA_CTRL,
196 .mask = 0xff0000,
197 .shift = 16,
198 }, {
199 /* strictly, this only describes only U saturation.
200 * V saturation is handled specially through code.
201 */
202 .v = {
203 .id = V4L2_CID_SATURATION,
204 .name = "Saturation",
205 .minimum = 0,
206 .maximum = 0xff,
207 .step = 1,
208 .default_value = 0x7f,
209 .type = V4L2_CTRL_TYPE_INTEGER,
210 },
211 .off = 0,
212 .reg = CHROMA_CTRL,
213 .mask = 0x00ff,
214 .shift = 0,
215 }, {
216 /* --- audio --- */
217 .v = {
218 .id = V4L2_CID_AUDIO_MUTE,
219 .name = "Mute",
220 .minimum = 0,
221 .maximum = 1,
222 .default_value = 1,
223 .type = V4L2_CTRL_TYPE_BOOLEAN,
224 },
225 .reg = PATH1_CTL1,
226 .mask = (0x1f << 24),
227 .shift = 24,
228 }, {
229 .v = {
230 .id = V4L2_CID_AUDIO_VOLUME,
231 .name = "Volume",
232 .minimum = 0,
233 .maximum = 0x3f,
234 .step = 1,
235 .default_value = 0x3f,
236 .type = V4L2_CTRL_TYPE_INTEGER,
237 },
238 .reg = PATH1_VOL_CTL,
239 .mask = 0xff,
240 .shift = 0,
241 }
242};
243static const int CX23885_CTLS = ARRAY_SIZE(cx23885_ctls);
244
Hans Verkuil2ba58892009-02-13 10:57:48 -0300245/* Must be sorted from low to high control ID! */
Hans Verkuild45b9b82008-09-04 03:33:43 -0300246static const u32 cx23885_user_ctrls[] = {
Steven Tothe47f30b2008-01-10 04:25:59 -0300247 V4L2_CID_USER_CLASS,
248 V4L2_CID_BRIGHTNESS,
249 V4L2_CID_CONTRAST,
250 V4L2_CID_SATURATION,
251 V4L2_CID_HUE,
252 V4L2_CID_AUDIO_VOLUME,
253 V4L2_CID_AUDIO_MUTE,
254 0
255};
Steven Tothe47f30b2008-01-10 04:25:59 -0300256
257static const u32 *ctrl_classes[] = {
258 cx23885_user_ctrls,
259 NULL
260};
261
Hans Verkuild45b9b82008-09-04 03:33:43 -0300262static void cx23885_video_wakeup(struct cx23885_dev *dev,
Steven Tothe47f30b2008-01-10 04:25:59 -0300263 struct cx23885_dmaqueue *q, u32 count)
264{
265 struct cx23885_buffer *buf;
266 int bc;
267
268 for (bc = 0;; bc++) {
269 if (list_empty(&q->active))
270 break;
271 buf = list_entry(q->active.next,
272 struct cx23885_buffer, vb.queue);
Steven Totha19602f22008-01-10 11:43:18 -0300273
Steven Tothe47f30b2008-01-10 04:25:59 -0300274 /* count comes from the hw and is is 16bit wide --
275 * this trick handles wrap-arounds correctly for
276 * up to 32767 buffers in flight... */
277 if ((s16) (count - buf->count) < 0)
278 break;
Steven Totha19602f22008-01-10 11:43:18 -0300279
Steven Tothe47f30b2008-01-10 04:25:59 -0300280 do_gettimeofday(&buf->vb.ts);
281 dprintk(2, "[%p/%d] wakeup reg=%d buf=%d\n", buf, buf->vb.i,
282 count, buf->count);
283 buf->vb.state = VIDEOBUF_DONE;
284 list_del(&buf->vb.queue);
285 wake_up(&buf->vb.done);
286 }
Steven Toth9c8ced52008-10-16 20:18:44 -0300287 if (list_empty(&q->active))
Steven Tothe47f30b2008-01-10 04:25:59 -0300288 del_timer(&q->timeout);
Steven Toth9c8ced52008-10-16 20:18:44 -0300289 else
Steven Tothe47f30b2008-01-10 04:25:59 -0300290 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
Steven Tothe47f30b2008-01-10 04:25:59 -0300291 if (bc != 1)
Steven Toth21a78092008-01-10 04:38:59 -0300292 printk(KERN_ERR "%s: %d buffers handled (should be 1)\n",
Harvey Harrison22b4e642008-04-08 23:20:00 -0300293 __func__, bc);
Steven Tothe47f30b2008-01-10 04:25:59 -0300294}
295
Hans Verkuild45b9b82008-09-04 03:33:43 -0300296static int cx23885_set_tvnorm(struct cx23885_dev *dev, v4l2_std_id norm)
Steven Tothe47f30b2008-01-10 04:25:59 -0300297{
298 dprintk(1, "%s(norm = 0x%08x) name: [%s]\n",
Harvey Harrison22b4e642008-04-08 23:20:00 -0300299 __func__,
Steven Tothe47f30b2008-01-10 04:25:59 -0300300 (unsigned int)norm,
301 v4l2_norm_to_name(norm));
302
303 dev->tvnorm = norm;
304
Hans Verkuilf41737e2009-04-01 03:52:39 -0300305 call_all(dev, core, s_std, norm);
Steven Tothe47f30b2008-01-10 04:25:59 -0300306
307 return 0;
308}
309
Hans Verkuild45b9b82008-09-04 03:33:43 -0300310static struct video_device *cx23885_vdev_init(struct cx23885_dev *dev,
Steven Tothe47f30b2008-01-10 04:25:59 -0300311 struct pci_dev *pci,
312 struct video_device *template,
313 char *type)
314{
315 struct video_device *vfd;
Harvey Harrison22b4e642008-04-08 23:20:00 -0300316 dprintk(1, "%s()\n", __func__);
Steven Tothe47f30b2008-01-10 04:25:59 -0300317
318 vfd = video_device_alloc();
319 if (NULL == vfd)
320 return NULL;
321 *vfd = *template;
Hans Verkuilc0714f62009-03-13 08:02:43 -0300322 vfd->v4l2_dev = &dev->v4l2_dev;
Steven Tothe47f30b2008-01-10 04:25:59 -0300323 vfd->release = video_device_release;
324 snprintf(vfd->name, sizeof(vfd->name), "%s %s (%s)",
325 dev->name, type, cx23885_boards[dev->board].name);
Laurent Pinchart63b0d5a2009-12-10 11:44:04 -0200326 video_set_drvdata(vfd, dev);
Steven Tothe47f30b2008-01-10 04:25:59 -0300327 return vfd;
328}
329
Hans Verkuild45b9b82008-09-04 03:33:43 -0300330static int cx23885_ctrl_query(struct v4l2_queryctrl *qctrl)
Steven Tothe47f30b2008-01-10 04:25:59 -0300331{
332 int i;
333
334 if (qctrl->id < V4L2_CID_BASE ||
335 qctrl->id >= V4L2_CID_LASTP1)
336 return -EINVAL;
337 for (i = 0; i < CX23885_CTLS; i++)
338 if (cx23885_ctls[i].v.id == qctrl->id)
339 break;
340 if (i == CX23885_CTLS) {
341 *qctrl = no_ctl;
342 return 0;
343 }
344 *qctrl = cx23885_ctls[i].v;
345 return 0;
346}
Steven Tothe47f30b2008-01-10 04:25:59 -0300347
348/* ------------------------------------------------------------------- */
349/* resource management */
350
351static int res_get(struct cx23885_dev *dev, struct cx23885_fh *fh,
352 unsigned int bit)
353{
Harvey Harrison22b4e642008-04-08 23:20:00 -0300354 dprintk(1, "%s()\n", __func__);
Steven Tothe47f30b2008-01-10 04:25:59 -0300355 if (fh->resources & bit)
356 /* have it already allocated */
357 return 1;
358
359 /* is it free? */
360 mutex_lock(&dev->lock);
361 if (dev->resources & bit) {
362 /* no, someone else uses it */
363 mutex_unlock(&dev->lock);
364 return 0;
365 }
366 /* it's free, grab it */
367 fh->resources |= bit;
368 dev->resources |= bit;
369 dprintk(1, "res: get %d\n", bit);
370 mutex_unlock(&dev->lock);
371 return 1;
372}
373
374static int res_check(struct cx23885_fh *fh, unsigned int bit)
375{
Steven Toth9c8ced52008-10-16 20:18:44 -0300376 return fh->resources & bit;
Steven Tothe47f30b2008-01-10 04:25:59 -0300377}
378
379static int res_locked(struct cx23885_dev *dev, unsigned int bit)
380{
Steven Toth9c8ced52008-10-16 20:18:44 -0300381 return dev->resources & bit;
Steven Tothe47f30b2008-01-10 04:25:59 -0300382}
383
384static void res_free(struct cx23885_dev *dev, struct cx23885_fh *fh,
385 unsigned int bits)
386{
387 BUG_ON((fh->resources & bits) != bits);
Harvey Harrison22b4e642008-04-08 23:20:00 -0300388 dprintk(1, "%s()\n", __func__);
Steven Tothe47f30b2008-01-10 04:25:59 -0300389
390 mutex_lock(&dev->lock);
391 fh->resources &= ~bits;
392 dev->resources &= ~bits;
393 dprintk(1, "res: put %d\n", bits);
394 mutex_unlock(&dev->lock);
395}
396
Hans Verkuild45b9b82008-09-04 03:33:43 -0300397static int cx23885_video_mux(struct cx23885_dev *dev, unsigned int input)
Steven Tothe47f30b2008-01-10 04:25:59 -0300398{
Steven Tothe47f30b2008-01-10 04:25:59 -0300399 dprintk(1, "%s() video_mux: %d [vmux=%d, gpio=0x%x,0x%x,0x%x,0x%x]\n",
Harvey Harrison22b4e642008-04-08 23:20:00 -0300400 __func__,
Steven Tothe47f30b2008-01-10 04:25:59 -0300401 input, INPUT(input)->vmux,
402 INPUT(input)->gpio0, INPUT(input)->gpio1,
403 INPUT(input)->gpio2, INPUT(input)->gpio3);
404 dev->input = input;
405
David T.L. Wong6f0d8c02009-10-21 13:15:30 -0300406 if (dev->board == CX23885_BOARD_MYGICA_X8506 ||
407 dev->board == CX23885_BOARD_MAGICPRO_PROHDTVE2) {
408 /* Select Analog TV */
409 if (INPUT(input)->type == CX23885_VMUX_TELEVISION)
410 cx23885_gpio_clear(dev, GPIO_0);
411 }
412
Steven Tothe47f30b2008-01-10 04:25:59 -0300413 /* Tell the internal A/V decoder */
Hans Verkuil5325b422009-04-02 11:26:22 -0300414 v4l2_subdev_call(dev->sd_cx25840, video, s_routing,
415 INPUT(input)->vmux, 0, 0);
Steven Tothe47f30b2008-01-10 04:25:59 -0300416
417 return 0;
418}
Steven Tothe47f30b2008-01-10 04:25:59 -0300419
420/* ------------------------------------------------------------------ */
Hans Verkuild45b9b82008-09-04 03:33:43 -0300421static int cx23885_set_scale(struct cx23885_dev *dev, unsigned int width,
Steven Tothe47f30b2008-01-10 04:25:59 -0300422 unsigned int height, enum v4l2_field field)
423{
Harvey Harrison22b4e642008-04-08 23:20:00 -0300424 dprintk(1, "%s()\n", __func__);
Steven Tothe47f30b2008-01-10 04:25:59 -0300425 return 0;
426}
427
428static int cx23885_start_video_dma(struct cx23885_dev *dev,
429 struct cx23885_dmaqueue *q,
430 struct cx23885_buffer *buf)
431{
Harvey Harrison22b4e642008-04-08 23:20:00 -0300432 dprintk(1, "%s()\n", __func__);
Steven Tothe47f30b2008-01-10 04:25:59 -0300433
434 /* setup fifo + format */
435 cx23885_sram_channel_setup(dev, &dev->sram_channels[SRAM_CH01],
436 buf->bpl, buf->risc.dma);
437 cx23885_set_scale(dev, buf->vb.width, buf->vb.height, buf->vb.field);
438
439 /* reset counter */
440 cx_write(VID_A_GPCNT_CTL, 3);
441 q->count = 1;
442
443 /* enable irq */
Andy Wallsdbe83a32010-07-19 01:19:43 -0300444 cx23885_irq_add_enable(dev, 0x01);
Steven Tothe47f30b2008-01-10 04:25:59 -0300445 cx_set(VID_A_INT_MSK, 0x000011);
446
447 /* start dma */
448 cx_set(DEV_CNTRL2, (1<<5));
449 cx_set(VID_A_DMA_CTL, 0x11); /* FIFO and RISC enable */
450
451 return 0;
452}
453
Steven Tothe47f30b2008-01-10 04:25:59 -0300454
455static int cx23885_restart_video_queue(struct cx23885_dev *dev,
456 struct cx23885_dmaqueue *q)
457{
458 struct cx23885_buffer *buf, *prev;
459 struct list_head *item;
Harvey Harrison22b4e642008-04-08 23:20:00 -0300460 dprintk(1, "%s()\n", __func__);
Steven Tothe47f30b2008-01-10 04:25:59 -0300461
462 if (!list_empty(&q->active)) {
463 buf = list_entry(q->active.next, struct cx23885_buffer,
464 vb.queue);
465 dprintk(2, "restart_queue [%p/%d]: restart dma\n",
466 buf, buf->vb.i);
467 cx23885_start_video_dma(dev, q, buf);
468 list_for_each(item, &q->active) {
469 buf = list_entry(item, struct cx23885_buffer,
470 vb.queue);
471 buf->count = q->count++;
472 }
473 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
474 return 0;
475 }
476
477 prev = NULL;
478 for (;;) {
479 if (list_empty(&q->queued))
480 return 0;
481 buf = list_entry(q->queued.next, struct cx23885_buffer,
482 vb.queue);
483 if (NULL == prev) {
484 list_move_tail(&buf->vb.queue, &q->active);
485 cx23885_start_video_dma(dev, q, buf);
486 buf->vb.state = VIDEOBUF_ACTIVE;
487 buf->count = q->count++;
488 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
489 dprintk(2, "[%p/%d] restart_queue - first active\n",
490 buf, buf->vb.i);
491
492 } else if (prev->vb.width == buf->vb.width &&
493 prev->vb.height == buf->vb.height &&
494 prev->fmt == buf->fmt) {
495 list_move_tail(&buf->vb.queue, &q->active);
496 buf->vb.state = VIDEOBUF_ACTIVE;
497 buf->count = q->count++;
498 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
499 prev->risc.jmp[2] = cpu_to_le32(0); /* Bits 63 - 32 */
500 dprintk(2, "[%p/%d] restart_queue - move to active\n",
501 buf, buf->vb.i);
502 } else {
503 return 0;
504 }
505 prev = buf;
506 }
507}
508
509static int buffer_setup(struct videobuf_queue *q, unsigned int *count,
510 unsigned int *size)
511{
512 struct cx23885_fh *fh = q->priv_data;
513
514 *size = fh->fmt->depth*fh->width*fh->height >> 3;
515 if (0 == *count)
516 *count = 32;
Andreas Bombedab7e312010-03-21 16:02:45 -0300517 if (*size * *count > vid_limit * 1024 * 1024)
518 *count = (vid_limit * 1024 * 1024) / *size;
Steven Tothe47f30b2008-01-10 04:25:59 -0300519 return 0;
520}
521
522static int buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
523 enum v4l2_field field)
524{
525 struct cx23885_fh *fh = q->priv_data;
526 struct cx23885_dev *dev = fh->dev;
527 struct cx23885_buffer *buf =
528 container_of(vb, struct cx23885_buffer, vb);
529 int rc, init_buffer = 0;
530 u32 line0_offset, line1_offset;
531 struct videobuf_dmabuf *dma = videobuf_to_dma(&buf->vb);
532
533 BUG_ON(NULL == fh->fmt);
534 if (fh->width < 48 || fh->width > norm_maxw(dev->tvnorm) ||
535 fh->height < 32 || fh->height > norm_maxh(dev->tvnorm))
536 return -EINVAL;
537 buf->vb.size = (fh->width * fh->height * fh->fmt->depth) >> 3;
538 if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size)
539 return -EINVAL;
540
541 if (buf->fmt != fh->fmt ||
542 buf->vb.width != fh->width ||
543 buf->vb.height != fh->height ||
544 buf->vb.field != field) {
545 buf->fmt = fh->fmt;
546 buf->vb.width = fh->width;
547 buf->vb.height = fh->height;
548 buf->vb.field = field;
549 init_buffer = 1;
550 }
551
552 if (VIDEOBUF_NEEDS_INIT == buf->vb.state) {
553 init_buffer = 1;
554 rc = videobuf_iolock(q, &buf->vb, NULL);
555 if (0 != rc)
556 goto fail;
557 }
558
559 if (init_buffer) {
560 buf->bpl = buf->vb.width * buf->fmt->depth >> 3;
561 switch (buf->vb.field) {
562 case V4L2_FIELD_TOP:
563 cx23885_risc_buffer(dev->pci, &buf->risc,
564 dma->sglist, 0, UNSET,
565 buf->bpl, 0, buf->vb.height);
566 break;
567 case V4L2_FIELD_BOTTOM:
568 cx23885_risc_buffer(dev->pci, &buf->risc,
569 dma->sglist, UNSET, 0,
570 buf->bpl, 0, buf->vb.height);
571 break;
572 case V4L2_FIELD_INTERLACED:
573 if (dev->tvnorm & V4L2_STD_NTSC) {
574 /* cx25840 transmits NTSC bottom field first */
575 dprintk(1, "%s() Creating NTSC risc\n",
Harvey Harrison22b4e642008-04-08 23:20:00 -0300576 __func__);
Steven Tothe47f30b2008-01-10 04:25:59 -0300577 line0_offset = buf->bpl;
578 line1_offset = 0;
579 } else {
580 /* All other formats are top field first */
581 dprintk(1, "%s() Creating PAL/SECAM risc\n",
Harvey Harrison22b4e642008-04-08 23:20:00 -0300582 __func__);
Steven Tothe47f30b2008-01-10 04:25:59 -0300583 line0_offset = 0;
584 line1_offset = buf->bpl;
585 }
586 cx23885_risc_buffer(dev->pci, &buf->risc,
587 dma->sglist, line0_offset,
588 line1_offset,
589 buf->bpl, buf->bpl,
590 buf->vb.height >> 1);
591 break;
592 case V4L2_FIELD_SEQ_TB:
593 cx23885_risc_buffer(dev->pci, &buf->risc,
594 dma->sglist,
595 0, buf->bpl * (buf->vb.height >> 1),
596 buf->bpl, 0,
597 buf->vb.height >> 1);
598 break;
599 case V4L2_FIELD_SEQ_BT:
600 cx23885_risc_buffer(dev->pci, &buf->risc,
601 dma->sglist,
602 buf->bpl * (buf->vb.height >> 1), 0,
603 buf->bpl, 0,
604 buf->vb.height >> 1);
605 break;
606 default:
607 BUG();
608 }
609 }
610 dprintk(2, "[%p/%d] buffer_prep - %dx%d %dbpp \"%s\" - dma=0x%08lx\n",
611 buf, buf->vb.i,
612 fh->width, fh->height, fh->fmt->depth, fh->fmt->name,
613 (unsigned long)buf->risc.dma);
614
615 buf->vb.state = VIDEOBUF_PREPARED;
616 return 0;
617
618 fail:
619 cx23885_free_buffer(q, buf);
620 return rc;
621}
622
623static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
624{
625 struct cx23885_buffer *buf = container_of(vb,
626 struct cx23885_buffer, vb);
627 struct cx23885_buffer *prev;
628 struct cx23885_fh *fh = vq->priv_data;
629 struct cx23885_dev *dev = fh->dev;
630 struct cx23885_dmaqueue *q = &dev->vidq;
631
632 /* add jump to stopper */
633 buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC);
634 buf->risc.jmp[1] = cpu_to_le32(q->stopper.dma);
635 buf->risc.jmp[2] = cpu_to_le32(0); /* bits 63-32 */
636
637 if (!list_empty(&q->queued)) {
638 list_add_tail(&buf->vb.queue, &q->queued);
639 buf->vb.state = VIDEOBUF_QUEUED;
640 dprintk(2, "[%p/%d] buffer_queue - append to queued\n",
641 buf, buf->vb.i);
642
643 } else if (list_empty(&q->active)) {
644 list_add_tail(&buf->vb.queue, &q->active);
645 cx23885_start_video_dma(dev, q, buf);
646 buf->vb.state = VIDEOBUF_ACTIVE;
647 buf->count = q->count++;
648 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
649 dprintk(2, "[%p/%d] buffer_queue - first active\n",
650 buf, buf->vb.i);
651
652 } else {
653 prev = list_entry(q->active.prev, struct cx23885_buffer,
654 vb.queue);
655 if (prev->vb.width == buf->vb.width &&
656 prev->vb.height == buf->vb.height &&
657 prev->fmt == buf->fmt) {
658 list_add_tail(&buf->vb.queue, &q->active);
659 buf->vb.state = VIDEOBUF_ACTIVE;
660 buf->count = q->count++;
661 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
662 /* 64 bit bits 63-32 */
663 prev->risc.jmp[2] = cpu_to_le32(0);
664 dprintk(2, "[%p/%d] buffer_queue - append to active\n",
665 buf, buf->vb.i);
666
667 } else {
668 list_add_tail(&buf->vb.queue, &q->queued);
669 buf->vb.state = VIDEOBUF_QUEUED;
670 dprintk(2, "[%p/%d] buffer_queue - first queued\n",
671 buf, buf->vb.i);
672 }
673 }
674}
675
676static void buffer_release(struct videobuf_queue *q,
677 struct videobuf_buffer *vb)
678{
679 struct cx23885_buffer *buf = container_of(vb,
680 struct cx23885_buffer, vb);
681
682 cx23885_free_buffer(q, buf);
683}
684
685static struct videobuf_queue_ops cx23885_video_qops = {
686 .buf_setup = buffer_setup,
687 .buf_prepare = buffer_prepare,
688 .buf_queue = buffer_queue,
689 .buf_release = buffer_release,
690};
691
692static struct videobuf_queue *get_queue(struct cx23885_fh *fh)
693{
694 switch (fh->type) {
695 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
696 return &fh->vidq;
697 case V4L2_BUF_TYPE_VBI_CAPTURE:
698 return &fh->vbiq;
699 default:
700 BUG();
701 return NULL;
702 }
703}
704
705static int get_resource(struct cx23885_fh *fh)
706{
707 switch (fh->type) {
708 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
709 return RESOURCE_VIDEO;
710 case V4L2_BUF_TYPE_VBI_CAPTURE:
711 return RESOURCE_VBI;
712 default:
713 BUG();
714 return 0;
715 }
716}
717
Hans Verkuilbec43662008-12-30 06:58:20 -0300718static int video_open(struct file *file)
Steven Tothe47f30b2008-01-10 04:25:59 -0300719{
Laurent Pinchart63b0d5a2009-12-10 11:44:04 -0200720 struct video_device *vdev = video_devdata(file);
721 struct cx23885_dev *dev = video_drvdata(file);
Steven Tothe47f30b2008-01-10 04:25:59 -0300722 struct cx23885_fh *fh;
Steven Tothe47f30b2008-01-10 04:25:59 -0300723 enum v4l2_buf_type type = 0;
724 int radio = 0;
725
Laurent Pinchart63b0d5a2009-12-10 11:44:04 -0200726 switch (vdev->vfl_type) {
727 case VFL_TYPE_GRABBER:
728 type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
729 break;
730 case VFL_TYPE_VBI:
731 type = V4L2_BUF_TYPE_VBI_CAPTURE;
732 break;
733 case VFL_TYPE_RADIO:
734 radio = 1;
735 break;
Hans Verkuild56dc612008-07-30 08:43:36 -0300736 }
Steven Tothe47f30b2008-01-10 04:25:59 -0300737
Laurent Pinchart50462eb2009-12-10 11:47:13 -0200738 dprintk(1, "open dev=%s radio=%d type=%s\n",
739 video_device_node_name(vdev), radio, v4l2_type_names[type]);
Steven Tothe47f30b2008-01-10 04:25:59 -0300740
741 /* allocate + initialize per filehandle data */
742 fh = kzalloc(sizeof(*fh), GFP_KERNEL);
Laurent Pinchart63b0d5a2009-12-10 11:44:04 -0200743 if (NULL == fh)
Steven Tothe47f30b2008-01-10 04:25:59 -0300744 return -ENOMEM;
Laurent Pinchart63b0d5a2009-12-10 11:44:04 -0200745
746 lock_kernel();
747
Steven Tothe47f30b2008-01-10 04:25:59 -0300748 file->private_data = fh;
749 fh->dev = dev;
750 fh->radio = radio;
751 fh->type = type;
752 fh->width = 320;
753 fh->height = 240;
754 fh->fmt = format_by_fourcc(V4L2_PIX_FMT_BGR24);
755
Guennadi Liakhovetski07051352008-04-22 14:42:13 -0300756 videobuf_queue_sg_init(&fh->vidq, &cx23885_video_qops,
757 &dev->pci->dev, &dev->slock,
Steven Tothe47f30b2008-01-10 04:25:59 -0300758 V4L2_BUF_TYPE_VIDEO_CAPTURE,
759 V4L2_FIELD_INTERLACED,
760 sizeof(struct cx23885_buffer),
761 fh);
762
763 dprintk(1, "post videobuf_queue_init()\n");
764
Hans Verkuild56dc612008-07-30 08:43:36 -0300765 unlock_kernel();
Steven Tothe47f30b2008-01-10 04:25:59 -0300766
767 return 0;
768}
769
770static ssize_t video_read(struct file *file, char __user *data,
771 size_t count, loff_t *ppos)
772{
773 struct cx23885_fh *fh = file->private_data;
774
775 switch (fh->type) {
776 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
777 if (res_locked(fh->dev, RESOURCE_VIDEO))
778 return -EBUSY;
779 return videobuf_read_one(&fh->vidq, data, count, ppos,
780 file->f_flags & O_NONBLOCK);
781 case V4L2_BUF_TYPE_VBI_CAPTURE:
782 if (!res_get(fh->dev, fh, RESOURCE_VBI))
783 return -EBUSY;
784 return videobuf_read_stream(&fh->vbiq, data, count, ppos, 1,
785 file->f_flags & O_NONBLOCK);
786 default:
787 BUG();
788 return 0;
789 }
790}
791
792static unsigned int video_poll(struct file *file,
793 struct poll_table_struct *wait)
794{
795 struct cx23885_fh *fh = file->private_data;
796 struct cx23885_buffer *buf;
Figo.zhang9fd64182009-06-16 13:31:29 -0300797 unsigned int rc = POLLERR;
Steven Tothe47f30b2008-01-10 04:25:59 -0300798
799 if (V4L2_BUF_TYPE_VBI_CAPTURE == fh->type) {
800 if (!res_get(fh->dev, fh, RESOURCE_VBI))
801 return POLLERR;
802 return videobuf_poll_stream(file, &fh->vbiq, wait);
803 }
804
Figo.zhang9fd64182009-06-16 13:31:29 -0300805 mutex_lock(&fh->vidq.vb_lock);
Steven Tothe47f30b2008-01-10 04:25:59 -0300806 if (res_check(fh, RESOURCE_VIDEO)) {
807 /* streaming capture */
808 if (list_empty(&fh->vidq.stream))
Figo.zhang9fd64182009-06-16 13:31:29 -0300809 goto done;
Steven Tothe47f30b2008-01-10 04:25:59 -0300810 buf = list_entry(fh->vidq.stream.next,
811 struct cx23885_buffer, vb.stream);
812 } else {
813 /* read() capture */
814 buf = (struct cx23885_buffer *)fh->vidq.read_buf;
815 if (NULL == buf)
Figo.zhang9fd64182009-06-16 13:31:29 -0300816 goto done;
Steven Tothe47f30b2008-01-10 04:25:59 -0300817 }
818 poll_wait(file, &buf->vb.done, wait);
819 if (buf->vb.state == VIDEOBUF_DONE ||
820 buf->vb.state == VIDEOBUF_ERROR)
Figo.zhang9fd64182009-06-16 13:31:29 -0300821 rc = POLLIN|POLLRDNORM;
822 else
823 rc = 0;
824done:
825 mutex_unlock(&fh->vidq.vb_lock);
826 return rc;
Steven Tothe47f30b2008-01-10 04:25:59 -0300827}
828
Hans Verkuilbec43662008-12-30 06:58:20 -0300829static int video_release(struct file *file)
Steven Tothe47f30b2008-01-10 04:25:59 -0300830{
831 struct cx23885_fh *fh = file->private_data;
832 struct cx23885_dev *dev = fh->dev;
833
834 /* turn off overlay */
835 if (res_check(fh, RESOURCE_OVERLAY)) {
836 /* FIXME */
837 res_free(dev, fh, RESOURCE_OVERLAY);
838 }
839
840 /* stop video capture */
841 if (res_check(fh, RESOURCE_VIDEO)) {
842 videobuf_queue_cancel(&fh->vidq);
843 res_free(dev, fh, RESOURCE_VIDEO);
844 }
845 if (fh->vidq.read_buf) {
846 buffer_release(&fh->vidq, fh->vidq.read_buf);
847 kfree(fh->vidq.read_buf);
848 }
849
850 /* stop vbi capture */
851 if (res_check(fh, RESOURCE_VBI)) {
852 if (fh->vbiq.streaming)
853 videobuf_streamoff(&fh->vbiq);
854 if (fh->vbiq.reading)
855 videobuf_read_stop(&fh->vbiq);
856 res_free(dev, fh, RESOURCE_VBI);
857 }
858
859 videobuf_mmap_free(&fh->vidq);
860 file->private_data = NULL;
861 kfree(fh);
862
Steven Totha19602f22008-01-10 11:43:18 -0300863 /* We are not putting the tuner to sleep here on exit, because
864 * we want to use the mpeg encoder in another session to capture
865 * tuner video. Closing this will result in no video to the encoder.
866 */
Steven Tothe47f30b2008-01-10 04:25:59 -0300867
868 return 0;
869}
870
871static int video_mmap(struct file *file, struct vm_area_struct *vma)
872{
873 struct cx23885_fh *fh = file->private_data;
874
875 return videobuf_mmap_mapper(get_queue(fh), vma);
876}
877
878/* ------------------------------------------------------------------ */
879/* VIDEO CTRL IOCTLS */
880
Steven Toth9c8ced52008-10-16 20:18:44 -0300881static int cx23885_get_control(struct cx23885_dev *dev,
882 struct v4l2_control *ctl)
Steven Tothe47f30b2008-01-10 04:25:59 -0300883{
Harvey Harrison22b4e642008-04-08 23:20:00 -0300884 dprintk(1, "%s() calling cx25840(VIDIOC_G_CTRL)\n", __func__);
Hans Verkuil0d5a19f2009-03-29 06:53:29 -0300885 call_all(dev, core, g_ctrl, ctl);
Steven Tothe47f30b2008-01-10 04:25:59 -0300886 return 0;
887}
Steven Tothe47f30b2008-01-10 04:25:59 -0300888
Steven Toth9c8ced52008-10-16 20:18:44 -0300889static int cx23885_set_control(struct cx23885_dev *dev,
890 struct v4l2_control *ctl)
Steven Tothe47f30b2008-01-10 04:25:59 -0300891{
892 dprintk(1, "%s() calling cx25840(VIDIOC_S_CTRL)"
Harvey Harrison22b4e642008-04-08 23:20:00 -0300893 " (disabled - no action)\n", __func__);
Steven Tothe47f30b2008-01-10 04:25:59 -0300894 return 0;
895}
Steven Tothe47f30b2008-01-10 04:25:59 -0300896
897static void init_controls(struct cx23885_dev *dev)
898{
899 struct v4l2_control ctrl;
900 int i;
901
902 for (i = 0; i < CX23885_CTLS; i++) {
903 ctrl.id = cx23885_ctls[i].v.id;
904 ctrl.value = cx23885_ctls[i].v.default_value;
905
906 cx23885_set_control(dev, &ctrl);
907 }
908}
909
910/* ------------------------------------------------------------------ */
911/* VIDEO IOCTLS */
912
Hans Verkuil78b526a2008-05-28 12:16:41 -0300913static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
Steven Tothe47f30b2008-01-10 04:25:59 -0300914 struct v4l2_format *f)
915{
916 struct cx23885_fh *fh = priv;
917
918 f->fmt.pix.width = fh->width;
919 f->fmt.pix.height = fh->height;
920 f->fmt.pix.field = fh->vidq.field;
921 f->fmt.pix.pixelformat = fh->fmt->fourcc;
922 f->fmt.pix.bytesperline =
923 (f->fmt.pix.width * fh->fmt->depth) >> 3;
924 f->fmt.pix.sizeimage =
925 f->fmt.pix.height * f->fmt.pix.bytesperline;
926
927 return 0;
928}
929
Hans Verkuil78b526a2008-05-28 12:16:41 -0300930static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
Steven Tothe47f30b2008-01-10 04:25:59 -0300931 struct v4l2_format *f)
932{
933 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
934 struct cx23885_fmt *fmt;
935 enum v4l2_field field;
936 unsigned int maxw, maxh;
937
938 fmt = format_by_fourcc(f->fmt.pix.pixelformat);
939 if (NULL == fmt)
940 return -EINVAL;
941
942 field = f->fmt.pix.field;
943 maxw = norm_maxw(dev->tvnorm);
944 maxh = norm_maxh(dev->tvnorm);
945
946 if (V4L2_FIELD_ANY == field) {
947 field = (f->fmt.pix.height > maxh/2)
948 ? V4L2_FIELD_INTERLACED
949 : V4L2_FIELD_BOTTOM;
950 }
951
952 switch (field) {
953 case V4L2_FIELD_TOP:
954 case V4L2_FIELD_BOTTOM:
955 maxh = maxh / 2;
956 break;
957 case V4L2_FIELD_INTERLACED:
958 break;
959 default:
960 return -EINVAL;
961 }
962
963 f->fmt.pix.field = field;
Trent Piepho2449afc2009-05-30 21:45:46 -0300964 v4l_bound_align_image(&f->fmt.pix.width, 48, maxw, 2,
965 &f->fmt.pix.height, 32, maxh, 0, 0);
Steven Tothe47f30b2008-01-10 04:25:59 -0300966 f->fmt.pix.bytesperline =
967 (f->fmt.pix.width * fmt->depth) >> 3;
968 f->fmt.pix.sizeimage =
969 f->fmt.pix.height * f->fmt.pix.bytesperline;
970
971 return 0;
972}
973
Hans Verkuil78b526a2008-05-28 12:16:41 -0300974static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
Steven Tothe47f30b2008-01-10 04:25:59 -0300975 struct v4l2_format *f)
976{
977 struct cx23885_fh *fh = priv;
978 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
Hans Verkuilcc991132010-05-09 10:09:28 -0300979 struct v4l2_mbus_framefmt mbus_fmt;
Steven Tothe47f30b2008-01-10 04:25:59 -0300980 int err;
981
Harvey Harrison22b4e642008-04-08 23:20:00 -0300982 dprintk(2, "%s()\n", __func__);
Hans Verkuil78b526a2008-05-28 12:16:41 -0300983 err = vidioc_try_fmt_vid_cap(file, priv, f);
Steven Tothe47f30b2008-01-10 04:25:59 -0300984
985 if (0 != err)
986 return err;
987 fh->fmt = format_by_fourcc(f->fmt.pix.pixelformat);
988 fh->width = f->fmt.pix.width;
989 fh->height = f->fmt.pix.height;
990 fh->vidq.field = f->fmt.pix.field;
Harvey Harrison22b4e642008-04-08 23:20:00 -0300991 dprintk(2, "%s() width=%d height=%d field=%d\n", __func__,
Steven Tothe47f30b2008-01-10 04:25:59 -0300992 fh->width, fh->height, fh->vidq.field);
Hans Verkuilcc991132010-05-09 10:09:28 -0300993 v4l2_fill_mbus_format(&mbus_fmt, &f->fmt.pix, V4L2_MBUS_FMT_FIXED);
994 call_all(dev, video, s_mbus_fmt, &mbus_fmt);
995 v4l2_fill_pix_format(&f->fmt.pix, &mbus_fmt);
Steven Tothe47f30b2008-01-10 04:25:59 -0300996 return 0;
997}
998
999static int vidioc_querycap(struct file *file, void *priv,
1000 struct v4l2_capability *cap)
1001{
1002 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
1003
1004 strcpy(cap->driver, "cx23885");
1005 strlcpy(cap->card, cx23885_boards[dev->board].name,
1006 sizeof(cap->card));
1007 sprintf(cap->bus_info, "PCIe:%s", pci_name(dev->pci));
1008 cap->version = CX23885_VERSION_CODE;
1009 cap->capabilities =
1010 V4L2_CAP_VIDEO_CAPTURE |
1011 V4L2_CAP_READWRITE |
1012 V4L2_CAP_STREAMING |
1013 V4L2_CAP_VBI_CAPTURE;
1014 if (UNSET != dev->tuner_type)
1015 cap->capabilities |= V4L2_CAP_TUNER;
1016 return 0;
1017}
1018
Hans Verkuil78b526a2008-05-28 12:16:41 -03001019static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
Steven Tothe47f30b2008-01-10 04:25:59 -03001020 struct v4l2_fmtdesc *f)
1021{
1022 if (unlikely(f->index >= ARRAY_SIZE(formats)))
1023 return -EINVAL;
1024
1025 strlcpy(f->description, formats[f->index].name,
1026 sizeof(f->description));
1027 f->pixelformat = formats[f->index].fourcc;
1028
1029 return 0;
1030}
1031
1032#ifdef CONFIG_VIDEO_V4L1_COMPAT
1033static int vidiocgmbuf(struct file *file, void *priv,
1034 struct video_mbuf *mbuf)
1035{
1036 struct cx23885_fh *fh = priv;
1037 struct videobuf_queue *q;
1038 struct v4l2_requestbuffers req;
1039 unsigned int i;
1040 int err;
1041
1042 q = get_queue(fh);
1043 memset(&req, 0, sizeof(req));
1044 req.type = q->type;
1045 req.count = 8;
1046 req.memory = V4L2_MEMORY_MMAP;
1047 err = videobuf_reqbufs(q, &req);
1048 if (err < 0)
1049 return err;
1050
1051 mbuf->frames = req.count;
1052 mbuf->size = 0;
1053 for (i = 0; i < mbuf->frames; i++) {
1054 mbuf->offsets[i] = q->bufs[i]->boff;
1055 mbuf->size += q->bufs[i]->bsize;
1056 }
1057 return 0;
1058}
1059#endif
1060
1061static int vidioc_reqbufs(struct file *file, void *priv,
1062 struct v4l2_requestbuffers *p)
1063{
1064 struct cx23885_fh *fh = priv;
Steven Toth9c8ced52008-10-16 20:18:44 -03001065 return videobuf_reqbufs(get_queue(fh), p);
Steven Tothe47f30b2008-01-10 04:25:59 -03001066}
1067
1068static int vidioc_querybuf(struct file *file, void *priv,
1069 struct v4l2_buffer *p)
1070{
1071 struct cx23885_fh *fh = priv;
Steven Toth9c8ced52008-10-16 20:18:44 -03001072 return videobuf_querybuf(get_queue(fh), p);
Steven Tothe47f30b2008-01-10 04:25:59 -03001073}
1074
1075static int vidioc_qbuf(struct file *file, void *priv,
1076 struct v4l2_buffer *p)
1077{
1078 struct cx23885_fh *fh = priv;
Steven Toth9c8ced52008-10-16 20:18:44 -03001079 return videobuf_qbuf(get_queue(fh), p);
Steven Tothe47f30b2008-01-10 04:25:59 -03001080}
1081
1082static int vidioc_dqbuf(struct file *file, void *priv,
1083 struct v4l2_buffer *p)
1084{
1085 struct cx23885_fh *fh = priv;
Steven Toth9c8ced52008-10-16 20:18:44 -03001086 return videobuf_dqbuf(get_queue(fh), p,
1087 file->f_flags & O_NONBLOCK);
Steven Tothe47f30b2008-01-10 04:25:59 -03001088}
1089
1090static int vidioc_streamon(struct file *file, void *priv,
1091 enum v4l2_buf_type i)
1092{
1093 struct cx23885_fh *fh = priv;
1094 struct cx23885_dev *dev = fh->dev;
Harvey Harrison22b4e642008-04-08 23:20:00 -03001095 dprintk(1, "%s()\n", __func__);
Steven Tothe47f30b2008-01-10 04:25:59 -03001096
1097 if (unlikely(fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE))
1098 return -EINVAL;
1099 if (unlikely(i != fh->type))
1100 return -EINVAL;
1101
1102 if (unlikely(!res_get(dev, fh, get_resource(fh))))
1103 return -EBUSY;
1104 return videobuf_streamon(get_queue(fh));
1105}
1106
1107static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
1108{
1109 struct cx23885_fh *fh = priv;
1110 struct cx23885_dev *dev = fh->dev;
1111 int err, res;
Harvey Harrison22b4e642008-04-08 23:20:00 -03001112 dprintk(1, "%s()\n", __func__);
Steven Tothe47f30b2008-01-10 04:25:59 -03001113
1114 if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1115 return -EINVAL;
1116 if (i != fh->type)
1117 return -EINVAL;
1118
1119 res = get_resource(fh);
1120 err = videobuf_streamoff(get_queue(fh));
1121 if (err < 0)
1122 return err;
1123 res_free(dev, fh, res);
1124 return 0;
1125}
1126
1127static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *tvnorms)
1128{
1129 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
Harvey Harrison22b4e642008-04-08 23:20:00 -03001130 dprintk(1, "%s()\n", __func__);
Steven Tothe47f30b2008-01-10 04:25:59 -03001131
1132 mutex_lock(&dev->lock);
1133 cx23885_set_tvnorm(dev, *tvnorms);
1134 mutex_unlock(&dev->lock);
1135
1136 return 0;
1137}
1138
Hans Verkuild45b9b82008-09-04 03:33:43 -03001139static int cx23885_enum_input(struct cx23885_dev *dev, struct v4l2_input *i)
Steven Tothe47f30b2008-01-10 04:25:59 -03001140{
1141 static const char *iname[] = {
1142 [CX23885_VMUX_COMPOSITE1] = "Composite1",
1143 [CX23885_VMUX_COMPOSITE2] = "Composite2",
1144 [CX23885_VMUX_COMPOSITE3] = "Composite3",
1145 [CX23885_VMUX_COMPOSITE4] = "Composite4",
1146 [CX23885_VMUX_SVIDEO] = "S-Video",
David T.L. Wongdac65fa2009-10-21 11:07:24 -03001147 [CX23885_VMUX_COMPONENT] = "Component",
Steven Tothe47f30b2008-01-10 04:25:59 -03001148 [CX23885_VMUX_TELEVISION] = "Television",
1149 [CX23885_VMUX_CABLE] = "Cable TV",
1150 [CX23885_VMUX_DVB] = "DVB",
1151 [CX23885_VMUX_DEBUG] = "for debug only",
1152 };
1153 unsigned int n;
Harvey Harrison22b4e642008-04-08 23:20:00 -03001154 dprintk(1, "%s()\n", __func__);
Steven Tothe47f30b2008-01-10 04:25:59 -03001155
1156 n = i->index;
1157 if (n >= 4)
1158 return -EINVAL;
1159
1160 if (0 == INPUT(n)->type)
1161 return -EINVAL;
1162
1163 memset(i, 0, sizeof(*i));
1164 i->index = n;
1165 i->type = V4L2_INPUT_TYPE_CAMERA;
1166 strcpy(i->name, iname[INPUT(n)->type]);
1167 if ((CX23885_VMUX_TELEVISION == INPUT(n)->type) ||
1168 (CX23885_VMUX_CABLE == INPUT(n)->type))
1169 i->type = V4L2_INPUT_TYPE_TUNER;
1170 i->std = CX23885_NORMS;
1171 return 0;
1172}
Steven Tothe47f30b2008-01-10 04:25:59 -03001173
1174static int vidioc_enum_input(struct file *file, void *priv,
1175 struct v4l2_input *i)
1176{
1177 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
Harvey Harrison22b4e642008-04-08 23:20:00 -03001178 dprintk(1, "%s()\n", __func__);
Steven Tothe47f30b2008-01-10 04:25:59 -03001179 return cx23885_enum_input(dev, i);
1180}
1181
1182static int vidioc_g_input(struct file *file, void *priv, unsigned int *i)
1183{
1184 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
1185
1186 *i = dev->input;
Harvey Harrison22b4e642008-04-08 23:20:00 -03001187 dprintk(1, "%s() returns %d\n", __func__, *i);
Steven Tothe47f30b2008-01-10 04:25:59 -03001188 return 0;
1189}
1190
1191static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
1192{
1193 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
1194
Harvey Harrison22b4e642008-04-08 23:20:00 -03001195 dprintk(1, "%s(%d)\n", __func__, i);
Steven Tothe47f30b2008-01-10 04:25:59 -03001196
1197 if (i >= 4) {
Harvey Harrison22b4e642008-04-08 23:20:00 -03001198 dprintk(1, "%s() -EINVAL\n", __func__);
Steven Tothe47f30b2008-01-10 04:25:59 -03001199 return -EINVAL;
1200 }
1201
1202 mutex_lock(&dev->lock);
1203 cx23885_video_mux(dev, i);
1204 mutex_unlock(&dev->lock);
1205 return 0;
1206}
1207
Andy Wallse9e5cf42010-07-18 18:18:06 -03001208static int vidioc_log_status(struct file *file, void *priv)
1209{
1210 struct cx23885_fh *fh = priv;
1211 struct cx23885_dev *dev = fh->dev;
1212
1213 printk(KERN_INFO
1214 "%s/0: ============ START LOG STATUS ============\n",
1215 dev->name);
1216 call_all(dev, core, log_status);
1217 printk(KERN_INFO
1218 "%s/0: ============= END LOG STATUS =============\n",
1219 dev->name);
1220 return 0;
1221}
1222
Steven Tothe47f30b2008-01-10 04:25:59 -03001223static int vidioc_queryctrl(struct file *file, void *priv,
1224 struct v4l2_queryctrl *qctrl)
1225{
1226 qctrl->id = v4l2_ctrl_next(ctrl_classes, qctrl->id);
1227 if (unlikely(qctrl->id == 0))
1228 return -EINVAL;
1229 return cx23885_ctrl_query(qctrl);
1230}
1231
1232static int vidioc_g_ctrl(struct file *file, void *priv,
1233 struct v4l2_control *ctl)
1234{
1235 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
1236
1237 return cx23885_get_control(dev, ctl);
1238}
1239
1240static int vidioc_s_ctrl(struct file *file, void *priv,
1241 struct v4l2_control *ctl)
1242{
1243 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
1244
1245 return cx23885_set_control(dev, ctl);
1246}
1247
1248static int vidioc_g_tuner(struct file *file, void *priv,
1249 struct v4l2_tuner *t)
1250{
1251 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
1252
1253 if (unlikely(UNSET == dev->tuner_type))
1254 return -EINVAL;
1255 if (0 != t->index)
1256 return -EINVAL;
1257
1258 strcpy(t->name, "Television");
1259 t->type = V4L2_TUNER_ANALOG_TV;
1260 t->capability = V4L2_TUNER_CAP_NORM;
1261 t->rangehigh = 0xffffffffUL;
1262 t->signal = 0xffff ; /* LOCKED */
1263 return 0;
1264}
1265
1266static int vidioc_s_tuner(struct file *file, void *priv,
1267 struct v4l2_tuner *t)
1268{
1269 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
1270
1271 if (UNSET == dev->tuner_type)
1272 return -EINVAL;
1273 if (0 != t->index)
1274 return -EINVAL;
1275 return 0;
1276}
1277
1278static int vidioc_g_frequency(struct file *file, void *priv,
1279 struct v4l2_frequency *f)
1280{
1281 struct cx23885_fh *fh = priv;
1282 struct cx23885_dev *dev = fh->dev;
1283
1284 if (unlikely(UNSET == dev->tuner_type))
1285 return -EINVAL;
1286
1287 /* f->type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; */
1288 f->type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
1289 f->frequency = dev->freq;
1290
Hans Verkuil0d5a19f2009-03-29 06:53:29 -03001291 call_all(dev, tuner, g_frequency, f);
Steven Tothe47f30b2008-01-10 04:25:59 -03001292
1293 return 0;
1294}
1295
Hans Verkuild45b9b82008-09-04 03:33:43 -03001296static int cx23885_set_freq(struct cx23885_dev *dev, struct v4l2_frequency *f)
Steven Tothe47f30b2008-01-10 04:25:59 -03001297{
1298 if (unlikely(UNSET == dev->tuner_type))
1299 return -EINVAL;
1300 if (unlikely(f->tuner != 0))
1301 return -EINVAL;
1302
1303 mutex_lock(&dev->lock);
1304 dev->freq = f->frequency;
1305
Hans Verkuil0d5a19f2009-03-29 06:53:29 -03001306 call_all(dev, tuner, s_frequency, f);
Steven Tothe47f30b2008-01-10 04:25:59 -03001307
1308 /* When changing channels it is required to reset TVAUDIO */
1309 msleep(10);
1310
1311 mutex_unlock(&dev->lock);
1312
1313 return 0;
1314}
Steven Tothe47f30b2008-01-10 04:25:59 -03001315
1316static int vidioc_s_frequency(struct file *file, void *priv,
1317 struct v4l2_frequency *f)
1318{
1319 struct cx23885_fh *fh = priv;
1320 struct cx23885_dev *dev = fh->dev;
1321
1322 if (unlikely(0 == fh->radio && f->type != V4L2_TUNER_ANALOG_TV))
1323 return -EINVAL;
1324 if (unlikely(1 == fh->radio && f->type != V4L2_TUNER_RADIO))
1325 return -EINVAL;
1326
1327 return
1328 cx23885_set_freq(dev, f);
1329}
1330
Steven Tothe47f30b2008-01-10 04:25:59 -03001331/* ----------------------------------------------------------- */
Steven Tothe47f30b2008-01-10 04:25:59 -03001332
1333static void cx23885_vid_timeout(unsigned long data)
1334{
1335 struct cx23885_dev *dev = (struct cx23885_dev *)data;
1336 struct cx23885_dmaqueue *q = &dev->vidq;
1337 struct cx23885_buffer *buf;
1338 unsigned long flags;
1339
1340 cx23885_sram_channel_dump(dev, &dev->sram_channels[SRAM_CH01]);
1341
1342 cx_clear(VID_A_DMA_CTL, 0x11);
1343
1344 spin_lock_irqsave(&dev->slock, flags);
1345 while (!list_empty(&q->active)) {
1346 buf = list_entry(q->active.next,
1347 struct cx23885_buffer, vb.queue);
1348 list_del(&buf->vb.queue);
1349 buf->vb.state = VIDEOBUF_ERROR;
1350 wake_up(&buf->vb.done);
1351 printk(KERN_ERR "%s/0: [%p/%d] timeout - dma=0x%08lx\n",
1352 dev->name, buf, buf->vb.i,
1353 (unsigned long)buf->risc.dma);
1354 }
1355 cx23885_restart_video_queue(dev, q);
1356 spin_unlock_irqrestore(&dev->slock, flags);
1357}
1358
1359int cx23885_video_irq(struct cx23885_dev *dev, u32 status)
1360{
1361 u32 mask, count;
1362 int handled = 0;
1363
1364 mask = cx_read(VID_A_INT_MSK);
1365 if (0 == (status & mask))
1366 return handled;
1367 cx_write(VID_A_INT_STAT, status);
1368
Harvey Harrison22b4e642008-04-08 23:20:00 -03001369 dprintk(2, "%s() status = 0x%08x\n", __func__, status);
Steven Tothe47f30b2008-01-10 04:25:59 -03001370 /* risc op code error */
1371 if (status & (1 << 16)) {
1372 printk(KERN_WARNING "%s/0: video risc op code error\n",
1373 dev->name);
1374 cx_clear(VID_A_DMA_CTL, 0x11);
1375 cx23885_sram_channel_dump(dev, &dev->sram_channels[SRAM_CH01]);
1376 }
1377
1378 /* risc1 y */
1379 if (status & 0x01) {
1380 spin_lock(&dev->slock);
1381 count = cx_read(VID_A_GPCNT);
1382 cx23885_video_wakeup(dev, &dev->vidq, count);
1383 spin_unlock(&dev->slock);
1384 handled++;
1385 }
1386 /* risc2 y */
1387 if (status & 0x10) {
1388 dprintk(2, "stopper video\n");
1389 spin_lock(&dev->slock);
1390 cx23885_restart_video_queue(dev, &dev->vidq);
1391 spin_unlock(&dev->slock);
1392 handled++;
1393 }
1394
1395 return handled;
1396}
1397
Steven Tothe47f30b2008-01-10 04:25:59 -03001398/* ----------------------------------------------------------- */
1399/* exported stuff */
1400
Hans Verkuilbec43662008-12-30 06:58:20 -03001401static const struct v4l2_file_operations video_fops = {
Steven Tothe47f30b2008-01-10 04:25:59 -03001402 .owner = THIS_MODULE,
1403 .open = video_open,
1404 .release = video_release,
1405 .read = video_read,
1406 .poll = video_poll,
1407 .mmap = video_mmap,
1408 .ioctl = video_ioctl2,
Steven Tothe47f30b2008-01-10 04:25:59 -03001409};
1410
Hans Verkuila3998102008-07-21 02:57:38 -03001411static const struct v4l2_ioctl_ops video_ioctl_ops = {
Steven Tothe47f30b2008-01-10 04:25:59 -03001412 .vidioc_querycap = vidioc_querycap,
Hans Verkuil78b526a2008-05-28 12:16:41 -03001413 .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
1414 .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
1415 .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
1416 .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
1417 .vidioc_g_fmt_vbi_cap = cx23885_vbi_fmt,
1418 .vidioc_try_fmt_vbi_cap = cx23885_vbi_fmt,
1419 .vidioc_s_fmt_vbi_cap = cx23885_vbi_fmt,
Steven Tothe47f30b2008-01-10 04:25:59 -03001420 .vidioc_reqbufs = vidioc_reqbufs,
1421 .vidioc_querybuf = vidioc_querybuf,
1422 .vidioc_qbuf = vidioc_qbuf,
1423 .vidioc_dqbuf = vidioc_dqbuf,
1424 .vidioc_s_std = vidioc_s_std,
1425 .vidioc_enum_input = vidioc_enum_input,
1426 .vidioc_g_input = vidioc_g_input,
1427 .vidioc_s_input = vidioc_s_input,
Andy Wallse9e5cf42010-07-18 18:18:06 -03001428 .vidioc_log_status = vidioc_log_status,
Steven Tothe47f30b2008-01-10 04:25:59 -03001429 .vidioc_queryctrl = vidioc_queryctrl,
1430 .vidioc_g_ctrl = vidioc_g_ctrl,
1431 .vidioc_s_ctrl = vidioc_s_ctrl,
1432 .vidioc_streamon = vidioc_streamon,
1433 .vidioc_streamoff = vidioc_streamoff,
1434#ifdef CONFIG_VIDEO_V4L1_COMPAT
1435 .vidiocgmbuf = vidiocgmbuf,
1436#endif
1437 .vidioc_g_tuner = vidioc_g_tuner,
1438 .vidioc_s_tuner = vidioc_s_tuner,
1439 .vidioc_g_frequency = vidioc_g_frequency,
1440 .vidioc_s_frequency = vidioc_s_frequency,
Andy Walls74618242009-09-26 22:50:44 -03001441 .vidioc_g_chip_ident = cx23885_g_chip_ident,
Steven Tothe47f30b2008-01-10 04:25:59 -03001442#ifdef CONFIG_VIDEO_ADV_DEBUG
Andy Walls74618242009-09-26 22:50:44 -03001443 .vidioc_g_register = cx23885_g_register,
1444 .vidioc_s_register = cx23885_s_register,
Steven Tothe47f30b2008-01-10 04:25:59 -03001445#endif
Hans Verkuila3998102008-07-21 02:57:38 -03001446};
1447
1448static struct video_device cx23885_vbi_template;
1449static struct video_device cx23885_video_template = {
1450 .name = "cx23885-video",
Hans Verkuila3998102008-07-21 02:57:38 -03001451 .fops = &video_fops,
Hans Verkuila3998102008-07-21 02:57:38 -03001452 .ioctl_ops = &video_ioctl_ops,
Steven Tothe47f30b2008-01-10 04:25:59 -03001453 .tvnorms = CX23885_NORMS,
1454 .current_norm = V4L2_STD_NTSC_M,
1455};
1456
Hans Verkuilbec43662008-12-30 06:58:20 -03001457static const struct v4l2_file_operations radio_fops = {
Steven Tothe47f30b2008-01-10 04:25:59 -03001458 .owner = THIS_MODULE,
1459 .open = video_open,
1460 .release = video_release,
1461 .ioctl = video_ioctl2,
Steven Tothe47f30b2008-01-10 04:25:59 -03001462};
1463
1464
1465void cx23885_video_unregister(struct cx23885_dev *dev)
1466{
Harvey Harrison22b4e642008-04-08 23:20:00 -03001467 dprintk(1, "%s()\n", __func__);
Andy Wallsdbe83a32010-07-19 01:19:43 -03001468 cx23885_irq_remove(dev, 0x01);
Steven Tothe47f30b2008-01-10 04:25:59 -03001469
1470 if (dev->video_dev) {
Laurent Pinchartf0813b42009-11-27 13:57:30 -03001471 if (video_is_registered(dev->video_dev))
Steven Tothe47f30b2008-01-10 04:25:59 -03001472 video_unregister_device(dev->video_dev);
1473 else
1474 video_device_release(dev->video_dev);
1475 dev->video_dev = NULL;
1476
1477 btcx_riscmem_free(dev->pci, &dev->vidq.stopper);
1478 }
1479}
1480
1481int cx23885_video_register(struct cx23885_dev *dev)
1482{
1483 int err;
1484
Harvey Harrison22b4e642008-04-08 23:20:00 -03001485 dprintk(1, "%s()\n", __func__);
Steven Tothe47f30b2008-01-10 04:25:59 -03001486 spin_lock_init(&dev->slock);
1487
1488 /* Initialize VBI template */
1489 memcpy(&cx23885_vbi_template, &cx23885_video_template,
1490 sizeof(cx23885_vbi_template));
1491 strcpy(cx23885_vbi_template.name, "cx23885-vbi");
Steven Tothe47f30b2008-01-10 04:25:59 -03001492
1493 dev->tvnorm = cx23885_video_template.current_norm;
1494
1495 /* init video dma queues */
1496 INIT_LIST_HEAD(&dev->vidq.active);
1497 INIT_LIST_HEAD(&dev->vidq.queued);
1498 dev->vidq.timeout.function = cx23885_vid_timeout;
1499 dev->vidq.timeout.data = (unsigned long)dev;
1500 init_timer(&dev->vidq.timeout);
1501 cx23885_risc_stopper(dev->pci, &dev->vidq.stopper,
1502 VID_A_DMA_CTL, 0x11, 0x00);
1503
Steven Totha19602f22008-01-10 11:43:18 -03001504 /* Don't enable VBI yet */
Andy Wallsdbe83a32010-07-19 01:19:43 -03001505
1506 cx23885_irq_add_enable(dev, 0x01);
Steven Tothe47f30b2008-01-10 04:25:59 -03001507
Hans Verkuil0d5a19f2009-03-29 06:53:29 -03001508 if (TUNER_ABSENT != dev->tuner_type) {
1509 struct v4l2_subdev *sd = NULL;
1510
1511 if (dev->tuner_addr)
Hans Verkuile6574f22009-04-01 03:57:53 -03001512 sd = v4l2_i2c_new_subdev(&dev->v4l2_dev,
1513 &dev->i2c_bus[1].i2c_adap,
Hans Verkuil53dacb12009-08-10 02:49:08 -03001514 "tuner", "tuner", dev->tuner_addr, NULL);
Hans Verkuil0d5a19f2009-03-29 06:53:29 -03001515 else
Hans Verkuil53dacb12009-08-10 02:49:08 -03001516 sd = v4l2_i2c_new_subdev(&dev->v4l2_dev,
Hans Verkuile6574f22009-04-01 03:57:53 -03001517 &dev->i2c_bus[1].i2c_adap,
Hans Verkuil53dacb12009-08-10 02:49:08 -03001518 "tuner", "tuner", 0, v4l2_i2c_tuner_addrs(ADDRS_TV));
Hans Verkuil0d5a19f2009-03-29 06:53:29 -03001519 if (sd) {
1520 struct tuner_setup tun_setup;
1521
David T.L. Wongfd705e72009-10-21 11:08:30 -03001522 memset(&tun_setup, 0, sizeof(tun_setup));
Hans Verkuil0d5a19f2009-03-29 06:53:29 -03001523 tun_setup.mode_mask = T_ANALOG_TV;
1524 tun_setup.type = dev->tuner_type;
1525 tun_setup.addr = v4l2_i2c_subdev_addr(sd);
David T.L. Wong6f0d8c02009-10-21 13:15:30 -03001526 tun_setup.tuner_callback = cx23885_tuner_callback;
Hans Verkuil0d5a19f2009-03-29 06:53:29 -03001527
1528 v4l2_subdev_call(sd, tuner, s_type_addr, &tun_setup);
Kusanagi Kouichi0b32d652010-01-22 04:55:28 -03001529
1530 if (dev->board == CX23885_BOARD_LEADTEK_WINFAST_PXTV1200) {
1531 struct xc2028_ctrl ctrl = {
1532 .fname = XC2028_DEFAULT_FIRMWARE,
1533 .max_len = 64
1534 };
1535 struct v4l2_priv_tun_config cfg = {
1536 .tuner = dev->tuner_type,
1537 .priv = &ctrl
1538 };
1539 v4l2_subdev_call(sd, tuner, s_config, &cfg);
1540 }
Hans Verkuil0d5a19f2009-03-29 06:53:29 -03001541 }
1542 }
1543
Steven Tothe47f30b2008-01-10 04:25:59 -03001544
1545 /* register v4l devices */
1546 dev->video_dev = cx23885_vdev_init(dev, dev->pci,
1547 &cx23885_video_template, "video");
1548 err = video_register_device(dev->video_dev, VFL_TYPE_GRABBER,
1549 video_nr[dev->nr]);
1550 if (err < 0) {
1551 printk(KERN_INFO "%s: can't register video device\n",
1552 dev->name);
1553 goto fail_unreg;
1554 }
Laurent Pinchart38c7c032009-11-27 13:57:15 -03001555 printk(KERN_INFO "%s/0: registered device %s [v4l2]\n",
1556 dev->name, video_device_node_name(dev->video_dev));
Steven Tothe47f30b2008-01-10 04:25:59 -03001557 /* initial device configuration */
1558 mutex_lock(&dev->lock);
1559 cx23885_set_tvnorm(dev, dev->tvnorm);
1560 init_controls(dev);
1561 cx23885_video_mux(dev, 0);
1562 mutex_unlock(&dev->lock);
1563
Steven Tothe47f30b2008-01-10 04:25:59 -03001564 return 0;
1565
1566fail_unreg:
1567 cx23885_video_unregister(dev);
1568 return err;
1569}
1570