blob: 5991bc8dc158bdb70dd5de2236ba05d68f1427d4 [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>
29#include <linux/interrupt.h>
30#include <linux/delay.h>
31#include <linux/kthread.h>
32#include <asm/div64.h>
33
34#include "cx23885.h"
35#include <media/v4l2-common.h>
Hans Verkuil35ea11f2008-07-20 08:12:02 -030036#include <media/v4l2-ioctl.h>
Andy Walls74618242009-09-26 22:50:44 -030037#include "cx23885-ioctl.h"
Kusanagi Kouichi0b32d652010-01-22 04:55:28 -030038#include "tuner-xc2028.h"
Steven Tothe47f30b2008-01-10 04:25:59 -030039
Mijhail Moreyra97ce5672011-10-10 11:09:53 -030040#include <media/cx25840.h>
41
Steven Tothe47f30b2008-01-10 04:25:59 -030042MODULE_DESCRIPTION("v4l2 driver module for cx23885 based TV cards");
Steven Toth6d897612008-09-03 17:12:12 -030043MODULE_AUTHOR("Steven Toth <stoth@linuxtv.org>");
Steven Tothe47f30b2008-01-10 04:25:59 -030044MODULE_LICENSE("GPL");
45
46/* ------------------------------------------------------------------ */
47
48static unsigned int video_nr[] = {[0 ... (CX23885_MAXBOARDS - 1)] = UNSET };
49static unsigned int vbi_nr[] = {[0 ... (CX23885_MAXBOARDS - 1)] = UNSET };
50static unsigned int radio_nr[] = {[0 ... (CX23885_MAXBOARDS - 1)] = UNSET };
51
52module_param_array(video_nr, int, NULL, 0444);
53module_param_array(vbi_nr, int, NULL, 0444);
54module_param_array(radio_nr, int, NULL, 0444);
55
56MODULE_PARM_DESC(video_nr, "video device numbers");
57MODULE_PARM_DESC(vbi_nr, "vbi device numbers");
58MODULE_PARM_DESC(radio_nr, "radio device numbers");
59
Steven Toth4513fc692008-01-12 11:36:36 -030060static unsigned int video_debug;
Steven Tothe47f30b2008-01-10 04:25:59 -030061module_param(video_debug, int, 0644);
62MODULE_PARM_DESC(video_debug, "enable debug messages [video]");
63
Steven Toth4513fc692008-01-12 11:36:36 -030064static unsigned int irq_debug;
Steven Tothe47f30b2008-01-10 04:25:59 -030065module_param(irq_debug, int, 0644);
66MODULE_PARM_DESC(irq_debug, "enable debug messages [IRQ handler]");
67
68static unsigned int vid_limit = 16;
69module_param(vid_limit, int, 0644);
70MODULE_PARM_DESC(vid_limit, "capture memory limit in megabytes");
71
72#define dprintk(level, fmt, arg...)\
Steven Toth4513fc692008-01-12 11:36:36 -030073 do { if (video_debug >= level)\
Steven Toth79776c82011-10-10 11:09:54 -030074 printk(KERN_DEBUG "%s: " fmt, dev->name, ## arg);\
Steven Toth4513fc692008-01-12 11:36:36 -030075 } while (0)
Steven Tothe47f30b2008-01-10 04:25:59 -030076
77/* ------------------------------------------------------------------- */
78/* static data */
79
80#define FORMAT_FLAGS_PACKED 0x01
Steven Tothaf76e9f2011-10-10 11:09:54 -030081#if 0
Steven Tothe47f30b2008-01-10 04:25:59 -030082static struct cx23885_fmt formats[] = {
83 {
84 .name = "8 bpp, gray",
85 .fourcc = V4L2_PIX_FMT_GREY,
86 .depth = 8,
87 .flags = FORMAT_FLAGS_PACKED,
88 }, {
89 .name = "15 bpp RGB, le",
90 .fourcc = V4L2_PIX_FMT_RGB555,
91 .depth = 16,
92 .flags = FORMAT_FLAGS_PACKED,
93 }, {
94 .name = "15 bpp RGB, be",
95 .fourcc = V4L2_PIX_FMT_RGB555X,
96 .depth = 16,
97 .flags = FORMAT_FLAGS_PACKED,
98 }, {
99 .name = "16 bpp RGB, le",
100 .fourcc = V4L2_PIX_FMT_RGB565,
101 .depth = 16,
102 .flags = FORMAT_FLAGS_PACKED,
103 }, {
104 .name = "16 bpp RGB, be",
105 .fourcc = V4L2_PIX_FMT_RGB565X,
106 .depth = 16,
107 .flags = FORMAT_FLAGS_PACKED,
108 }, {
109 .name = "24 bpp RGB, le",
110 .fourcc = V4L2_PIX_FMT_BGR24,
111 .depth = 24,
112 .flags = FORMAT_FLAGS_PACKED,
113 }, {
114 .name = "32 bpp RGB, le",
115 .fourcc = V4L2_PIX_FMT_BGR32,
116 .depth = 32,
117 .flags = FORMAT_FLAGS_PACKED,
118 }, {
119 .name = "32 bpp RGB, be",
120 .fourcc = V4L2_PIX_FMT_RGB32,
121 .depth = 32,
122 .flags = FORMAT_FLAGS_PACKED,
123 }, {
124 .name = "4:2:2, packed, YUYV",
125 .fourcc = V4L2_PIX_FMT_YUYV,
126 .depth = 16,
127 .flags = FORMAT_FLAGS_PACKED,
128 }, {
129 .name = "4:2:2, packed, UYVY",
130 .fourcc = V4L2_PIX_FMT_UYVY,
131 .depth = 16,
132 .flags = FORMAT_FLAGS_PACKED,
133 },
134};
Steven Tothaf76e9f2011-10-10 11:09:54 -0300135#else
136static struct cx23885_fmt formats[] = {
137 {
138#if 0
139 .name = "4:2:2, packed, UYVY",
140 .fourcc = V4L2_PIX_FMT_UYVY,
141 .depth = 16,
142 .flags = FORMAT_FLAGS_PACKED,
143 }, {
144#endif
145 .name = "4:2:2, packed, YUYV",
146 .fourcc = V4L2_PIX_FMT_YUYV,
147 .depth = 16,
148 .flags = FORMAT_FLAGS_PACKED,
149 }
150};
151#endif
Steven Tothe47f30b2008-01-10 04:25:59 -0300152
153static struct cx23885_fmt *format_by_fourcc(unsigned int fourcc)
154{
155 unsigned int i;
156
157 for (i = 0; i < ARRAY_SIZE(formats); i++)
158 if (formats[i].fourcc == fourcc)
159 return formats+i;
160
Steven Tothaf76e9f2011-10-10 11:09:54 -0300161 printk(KERN_ERR "%s(%c%c%c%c) NOT FOUND\n", __func__,
162 (fourcc & 0xff),
163 ((fourcc >> 8) & 0xff),
164 ((fourcc >> 16) & 0xff),
165 ((fourcc >> 24) & 0xff)
166 );
Steven Tothe47f30b2008-01-10 04:25:59 -0300167 return NULL;
168}
169
170/* ------------------------------------------------------------------- */
171
172static const struct v4l2_queryctrl no_ctl = {
173 .name = "42",
174 .flags = V4L2_CTRL_FLAG_DISABLED,
175};
176
177static struct cx23885_ctrl cx23885_ctls[] = {
178 /* --- video --- */
179 {
180 .v = {
181 .id = V4L2_CID_BRIGHTNESS,
182 .name = "Brightness",
183 .minimum = 0x00,
184 .maximum = 0xff,
185 .step = 1,
186 .default_value = 0x7f,
187 .type = V4L2_CTRL_TYPE_INTEGER,
188 },
189 .off = 128,
190 .reg = LUMA_CTRL,
191 .mask = 0x00ff,
192 .shift = 0,
193 }, {
194 .v = {
195 .id = V4L2_CID_CONTRAST,
196 .name = "Contrast",
197 .minimum = 0,
Mijhail Moreyrab12ab3f2011-10-10 11:09:53 -0300198 .maximum = 0x7f,
Steven Tothe47f30b2008-01-10 04:25:59 -0300199 .step = 1,
200 .default_value = 0x3f,
201 .type = V4L2_CTRL_TYPE_INTEGER,
202 },
203 .off = 0,
204 .reg = LUMA_CTRL,
205 .mask = 0xff00,
206 .shift = 8,
207 }, {
208 .v = {
209 .id = V4L2_CID_HUE,
210 .name = "Hue",
Mijhail Moreyrab12ab3f2011-10-10 11:09:53 -0300211 .minimum = -127,
212 .maximum = 128,
Steven Tothe47f30b2008-01-10 04:25:59 -0300213 .step = 1,
Mijhail Moreyrab12ab3f2011-10-10 11:09:53 -0300214 .default_value = 0x0,
Steven Tothe47f30b2008-01-10 04:25:59 -0300215 .type = V4L2_CTRL_TYPE_INTEGER,
216 },
217 .off = 128,
218 .reg = CHROMA_CTRL,
219 .mask = 0xff0000,
220 .shift = 16,
221 }, {
222 /* strictly, this only describes only U saturation.
223 * V saturation is handled specially through code.
224 */
225 .v = {
226 .id = V4L2_CID_SATURATION,
227 .name = "Saturation",
228 .minimum = 0,
Mijhail Moreyrab12ab3f2011-10-10 11:09:53 -0300229 .maximum = 0x7f,
Steven Tothe47f30b2008-01-10 04:25:59 -0300230 .step = 1,
Mijhail Moreyrab12ab3f2011-10-10 11:09:53 -0300231 .default_value = 0x3f,
Steven Tothe47f30b2008-01-10 04:25:59 -0300232 .type = V4L2_CTRL_TYPE_INTEGER,
233 },
234 .off = 0,
235 .reg = CHROMA_CTRL,
236 .mask = 0x00ff,
237 .shift = 0,
238 }, {
239 /* --- audio --- */
240 .v = {
241 .id = V4L2_CID_AUDIO_MUTE,
242 .name = "Mute",
243 .minimum = 0,
244 .maximum = 1,
245 .default_value = 1,
246 .type = V4L2_CTRL_TYPE_BOOLEAN,
247 },
248 .reg = PATH1_CTL1,
249 .mask = (0x1f << 24),
250 .shift = 24,
251 }, {
252 .v = {
253 .id = V4L2_CID_AUDIO_VOLUME,
254 .name = "Volume",
255 .minimum = 0,
Steven Toth4c3764d2012-01-04 10:47:57 -0300256 .maximum = 65535,
257 .step = 65535 / 100,
258 .default_value = 65535,
Steven Tothe47f30b2008-01-10 04:25:59 -0300259 .type = V4L2_CTRL_TYPE_INTEGER,
260 },
261 .reg = PATH1_VOL_CTL,
262 .mask = 0xff,
263 .shift = 0,
264 }
265};
266static const int CX23885_CTLS = ARRAY_SIZE(cx23885_ctls);
267
Hans Verkuil2ba58892009-02-13 10:57:48 -0300268/* Must be sorted from low to high control ID! */
Hans Verkuild45b9b82008-09-04 03:33:43 -0300269static const u32 cx23885_user_ctrls[] = {
Steven Tothe47f30b2008-01-10 04:25:59 -0300270 V4L2_CID_USER_CLASS,
271 V4L2_CID_BRIGHTNESS,
272 V4L2_CID_CONTRAST,
273 V4L2_CID_SATURATION,
274 V4L2_CID_HUE,
275 V4L2_CID_AUDIO_VOLUME,
276 V4L2_CID_AUDIO_MUTE,
277 0
278};
Steven Tothe47f30b2008-01-10 04:25:59 -0300279
280static const u32 *ctrl_classes[] = {
281 cx23885_user_ctrls,
282 NULL
283};
284
Steven Toth79776c82011-10-10 11:09:54 -0300285void cx23885_video_wakeup(struct cx23885_dev *dev,
286 struct cx23885_dmaqueue *q, u32 count)
Steven Tothe47f30b2008-01-10 04:25:59 -0300287{
288 struct cx23885_buffer *buf;
289 int bc;
290
291 for (bc = 0;; bc++) {
292 if (list_empty(&q->active))
293 break;
294 buf = list_entry(q->active.next,
295 struct cx23885_buffer, vb.queue);
Steven Totha19602f22008-01-10 11:43:18 -0300296
Steven Tothe47f30b2008-01-10 04:25:59 -0300297 /* count comes from the hw and is is 16bit wide --
298 * this trick handles wrap-arounds correctly for
299 * up to 32767 buffers in flight... */
300 if ((s16) (count - buf->count) < 0)
301 break;
Steven Totha19602f22008-01-10 11:43:18 -0300302
Sakari Ailus8e6057b2012-09-15 15:14:42 -0300303 v4l2_get_timestamp(&buf->vb.ts);
Steven Tothe47f30b2008-01-10 04:25:59 -0300304 dprintk(2, "[%p/%d] wakeup reg=%d buf=%d\n", buf, buf->vb.i,
305 count, buf->count);
306 buf->vb.state = VIDEOBUF_DONE;
307 list_del(&buf->vb.queue);
308 wake_up(&buf->vb.done);
309 }
Steven Toth9c8ced52008-10-16 20:18:44 -0300310 if (list_empty(&q->active))
Steven Tothe47f30b2008-01-10 04:25:59 -0300311 del_timer(&q->timeout);
Steven Toth9c8ced52008-10-16 20:18:44 -0300312 else
Steven Tothe47f30b2008-01-10 04:25:59 -0300313 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
Steven Tothe47f30b2008-01-10 04:25:59 -0300314 if (bc != 1)
Steven Toth21a78092008-01-10 04:38:59 -0300315 printk(KERN_ERR "%s: %d buffers handled (should be 1)\n",
Harvey Harrison22b4e642008-04-08 23:20:00 -0300316 __func__, bc);
Steven Tothe47f30b2008-01-10 04:25:59 -0300317}
318
Steven Toth35045132012-01-04 21:08:35 -0300319int cx23885_set_tvnorm(struct cx23885_dev *dev, v4l2_std_id norm)
Steven Tothe47f30b2008-01-10 04:25:59 -0300320{
321 dprintk(1, "%s(norm = 0x%08x) name: [%s]\n",
Harvey Harrison22b4e642008-04-08 23:20:00 -0300322 __func__,
Steven Tothe47f30b2008-01-10 04:25:59 -0300323 (unsigned int)norm,
324 v4l2_norm_to_name(norm));
325
326 dev->tvnorm = norm;
327
Hans Verkuilf41737e2009-04-01 03:52:39 -0300328 call_all(dev, core, s_std, norm);
Steven Tothe47f30b2008-01-10 04:25:59 -0300329
330 return 0;
331}
332
Hans Verkuild45b9b82008-09-04 03:33:43 -0300333static struct video_device *cx23885_vdev_init(struct cx23885_dev *dev,
Steven Tothe47f30b2008-01-10 04:25:59 -0300334 struct pci_dev *pci,
335 struct video_device *template,
336 char *type)
337{
338 struct video_device *vfd;
Harvey Harrison22b4e642008-04-08 23:20:00 -0300339 dprintk(1, "%s()\n", __func__);
Steven Tothe47f30b2008-01-10 04:25:59 -0300340
341 vfd = video_device_alloc();
342 if (NULL == vfd)
343 return NULL;
344 *vfd = *template;
Hans Verkuilc0714f62009-03-13 08:02:43 -0300345 vfd->v4l2_dev = &dev->v4l2_dev;
Steven Tothe47f30b2008-01-10 04:25:59 -0300346 vfd->release = video_device_release;
Steven Toth9def5ed2012-01-04 21:13:26 -0300347 snprintf(vfd->name, sizeof(vfd->name), "%s (%s)",
348 cx23885_boards[dev->board].name, type);
Laurent Pinchart63b0d5a2009-12-10 11:44:04 -0200349 video_set_drvdata(vfd, dev);
Steven Tothe47f30b2008-01-10 04:25:59 -0300350 return vfd;
351}
352
Hans Verkuild45b9b82008-09-04 03:33:43 -0300353static int cx23885_ctrl_query(struct v4l2_queryctrl *qctrl)
Steven Tothe47f30b2008-01-10 04:25:59 -0300354{
355 int i;
356
357 if (qctrl->id < V4L2_CID_BASE ||
358 qctrl->id >= V4L2_CID_LASTP1)
359 return -EINVAL;
360 for (i = 0; i < CX23885_CTLS; i++)
361 if (cx23885_ctls[i].v.id == qctrl->id)
362 break;
363 if (i == CX23885_CTLS) {
364 *qctrl = no_ctl;
365 return 0;
366 }
367 *qctrl = cx23885_ctls[i].v;
368 return 0;
369}
Steven Tothe47f30b2008-01-10 04:25:59 -0300370
371/* ------------------------------------------------------------------- */
372/* resource management */
373
374static int res_get(struct cx23885_dev *dev, struct cx23885_fh *fh,
375 unsigned int bit)
376{
Harvey Harrison22b4e642008-04-08 23:20:00 -0300377 dprintk(1, "%s()\n", __func__);
Steven Tothe47f30b2008-01-10 04:25:59 -0300378 if (fh->resources & bit)
379 /* have it already allocated */
380 return 1;
381
382 /* is it free? */
383 mutex_lock(&dev->lock);
384 if (dev->resources & bit) {
385 /* no, someone else uses it */
386 mutex_unlock(&dev->lock);
387 return 0;
388 }
389 /* it's free, grab it */
390 fh->resources |= bit;
391 dev->resources |= bit;
392 dprintk(1, "res: get %d\n", bit);
393 mutex_unlock(&dev->lock);
394 return 1;
395}
396
397static int res_check(struct cx23885_fh *fh, unsigned int bit)
398{
Steven Toth9c8ced52008-10-16 20:18:44 -0300399 return fh->resources & bit;
Steven Tothe47f30b2008-01-10 04:25:59 -0300400}
401
402static int res_locked(struct cx23885_dev *dev, unsigned int bit)
403{
Steven Toth9c8ced52008-10-16 20:18:44 -0300404 return dev->resources & bit;
Steven Tothe47f30b2008-01-10 04:25:59 -0300405}
406
407static void res_free(struct cx23885_dev *dev, struct cx23885_fh *fh,
408 unsigned int bits)
409{
410 BUG_ON((fh->resources & bits) != bits);
Harvey Harrison22b4e642008-04-08 23:20:00 -0300411 dprintk(1, "%s()\n", __func__);
Steven Tothe47f30b2008-01-10 04:25:59 -0300412
413 mutex_lock(&dev->lock);
414 fh->resources &= ~bits;
415 dev->resources &= ~bits;
416 dprintk(1, "res: put %d\n", bits);
417 mutex_unlock(&dev->lock);
418}
419
Steven Toth33cdeb32011-10-10 11:09:55 -0300420static int cx23885_flatiron_write(struct cx23885_dev *dev, u8 reg, u8 data)
421{
422 /* 8 bit registers, 8 bit values */
423 u8 buf[] = { reg, data };
424
425 struct i2c_msg msg = { .addr = 0x98 >> 1,
426 .flags = 0, .buf = buf, .len = 2 };
427
428 return i2c_transfer(&dev->i2c_bus[2].i2c_adap, &msg, 1);
429}
430
431static u8 cx23885_flatiron_read(struct cx23885_dev *dev, u8 reg)
432{
433 /* 8 bit registers, 8 bit values */
434 int ret;
435 u8 b0[] = { reg };
436 u8 b1[] = { 0 };
437
438 struct i2c_msg msg[] = {
439 { .addr = 0x98 >> 1, .flags = 0, .buf = b0, .len = 1 },
440 { .addr = 0x98 >> 1, .flags = I2C_M_RD, .buf = b1, .len = 1 }
441 };
442
443 ret = i2c_transfer(&dev->i2c_bus[2].i2c_adap, &msg[0], 2);
444 if (ret != 2)
445 printk(KERN_ERR "%s() error\n", __func__);
446
447 return b1[0];
448}
449
450static void cx23885_flatiron_dump(struct cx23885_dev *dev)
451{
452 int i;
453 dprintk(1, "Flatiron dump\n");
454 for (i = 0; i < 0x24; i++) {
455 dprintk(1, "FI[%02x] = %02x\n", i,
456 cx23885_flatiron_read(dev, i));
457 }
458}
459
460static int cx23885_flatiron_mux(struct cx23885_dev *dev, int input)
461{
462 u8 val;
463 dprintk(1, "%s(input = %d)\n", __func__, input);
464
465 if (input == 1)
466 val = cx23885_flatiron_read(dev, CH_PWR_CTRL1) & ~FLD_CH_SEL;
467 else if (input == 2)
468 val = cx23885_flatiron_read(dev, CH_PWR_CTRL1) | FLD_CH_SEL;
469 else
470 return -EINVAL;
471
472 val |= 0x20; /* Enable clock to delta-sigma and dec filter */
473
474 cx23885_flatiron_write(dev, CH_PWR_CTRL1, val);
475
476 /* Wake up */
477 cx23885_flatiron_write(dev, CH_PWR_CTRL2, 0);
478
479 if (video_debug)
480 cx23885_flatiron_dump(dev);
481
482 return 0;
483}
484
Hans Verkuild45b9b82008-09-04 03:33:43 -0300485static int cx23885_video_mux(struct cx23885_dev *dev, unsigned int input)
Steven Tothe47f30b2008-01-10 04:25:59 -0300486{
Steven Tothe47f30b2008-01-10 04:25:59 -0300487 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 -0300488 __func__,
Steven Tothe47f30b2008-01-10 04:25:59 -0300489 input, INPUT(input)->vmux,
490 INPUT(input)->gpio0, INPUT(input)->gpio1,
491 INPUT(input)->gpio2, INPUT(input)->gpio3);
492 dev->input = input;
493
David T.L. Wong6f0d8c02009-10-21 13:15:30 -0300494 if (dev->board == CX23885_BOARD_MYGICA_X8506 ||
Alfredo Jesús Delaiti87988752011-11-09 15:13:00 -0300495 dev->board == CX23885_BOARD_MAGICPRO_PROHDTVE2 ||
496 dev->board == CX23885_BOARD_MYGICA_X8507) {
David T.L. Wong6f0d8c02009-10-21 13:15:30 -0300497 /* Select Analog TV */
498 if (INPUT(input)->type == CX23885_VMUX_TELEVISION)
499 cx23885_gpio_clear(dev, GPIO_0);
500 }
501
Steven Tothe47f30b2008-01-10 04:25:59 -0300502 /* Tell the internal A/V decoder */
Hans Verkuil5325b422009-04-02 11:26:22 -0300503 v4l2_subdev_call(dev->sd_cx25840, video, s_routing,
504 INPUT(input)->vmux, 0, 0);
Steven Tothe47f30b2008-01-10 04:25:59 -0300505
Steven Toth2cb9ccd2011-10-10 11:09:55 -0300506 if ((dev->board == CX23885_BOARD_HAUPPAUGE_HVR1800) ||
Steven Toth35045132012-01-04 21:08:35 -0300507 (dev->board == CX23885_BOARD_MPX885) ||
Devin Heitmuellerd214ddc2012-07-01 16:15:13 -0300508 (dev->board == CX23885_BOARD_HAUPPAUGE_HVR1250) ||
Devin Heitmueller0ac60ac2012-07-01 16:15:14 -0300509 (dev->board == CX23885_BOARD_HAUPPAUGE_HVR1255) ||
510 (dev->board == CX23885_BOARD_HAUPPAUGE_HVR1255_22111) ||
Alfredo Jesús Delaiti082c0572012-09-21 10:33:51 -0300511 (dev->board == CX23885_BOARD_HAUPPAUGE_HVR1850) ||
Oleh Kravchenkoe8d42372012-12-08 18:20:59 -0300512 (dev->board == CX23885_BOARD_MYGICA_X8507) ||
513 (dev->board == CX23885_BOARD_AVERMEDIA_HC81R)) {
Steven Toth33cdeb32011-10-10 11:09:55 -0300514 /* Configure audio routing */
515 v4l2_subdev_call(dev->sd_cx25840, audio, s_routing,
516 INPUT(input)->amux, 0, 0);
517
518 if (INPUT(input)->amux == CX25840_AUDIO7)
519 cx23885_flatiron_mux(dev, 1);
520 else if (INPUT(input)->amux == CX25840_AUDIO6)
521 cx23885_flatiron_mux(dev, 2);
522 }
523
Steven Tothe47f30b2008-01-10 04:25:59 -0300524 return 0;
525}
Steven Tothe47f30b2008-01-10 04:25:59 -0300526
Steven Tothfc1a8892011-10-10 11:09:56 -0300527static int cx23885_audio_mux(struct cx23885_dev *dev, unsigned int input)
528{
529 dprintk(1, "%s(input=%d)\n", __func__, input);
530
Steven Tothfa1e0fd2011-10-10 11:09:56 -0300531 /* The baseband video core of the cx23885 has two audio inputs.
532 * LR1 and LR2. In almost every single case so far only HVR1xxx
533 * cards we've only ever supported LR1. Time to support LR2,
534 * which is available via the optional white breakout header on
535 * the board.
536 * We'll use a could of existing enums in the card struct to allow
537 * devs to specify which baseband input they need, or just default
538 * to what we've always used.
539 */
540 if (INPUT(input)->amux == CX25840_AUDIO7)
541 cx23885_flatiron_mux(dev, 1);
542 else if (INPUT(input)->amux == CX25840_AUDIO6)
543 cx23885_flatiron_mux(dev, 2);
544 else {
545 /* Not specifically defined, assume the default. */
546 cx23885_flatiron_mux(dev, 1);
Steven Tothfc1a8892011-10-10 11:09:56 -0300547 }
548
549 return 0;
550}
551
Steven Tothe47f30b2008-01-10 04:25:59 -0300552/* ------------------------------------------------------------------ */
Steven Tothe47f30b2008-01-10 04:25:59 -0300553static int cx23885_start_video_dma(struct cx23885_dev *dev,
554 struct cx23885_dmaqueue *q,
555 struct cx23885_buffer *buf)
556{
Harvey Harrison22b4e642008-04-08 23:20:00 -0300557 dprintk(1, "%s()\n", __func__);
Steven Tothe47f30b2008-01-10 04:25:59 -0300558
Steven Totha461e0a2011-10-10 11:09:56 -0300559 /* Stop the dma/fifo before we tamper with it's risc programs */
560 cx_clear(VID_A_DMA_CTL, 0x11);
561
Steven Tothe47f30b2008-01-10 04:25:59 -0300562 /* setup fifo + format */
563 cx23885_sram_channel_setup(dev, &dev->sram_channels[SRAM_CH01],
564 buf->bpl, buf->risc.dma);
Steven Tothe47f30b2008-01-10 04:25:59 -0300565
566 /* reset counter */
567 cx_write(VID_A_GPCNT_CTL, 3);
568 q->count = 1;
569
570 /* enable irq */
Andy Wallsdbe83a32010-07-19 01:19:43 -0300571 cx23885_irq_add_enable(dev, 0x01);
Steven Tothe47f30b2008-01-10 04:25:59 -0300572 cx_set(VID_A_INT_MSK, 0x000011);
573
574 /* start dma */
575 cx_set(DEV_CNTRL2, (1<<5));
576 cx_set(VID_A_DMA_CTL, 0x11); /* FIFO and RISC enable */
577
578 return 0;
579}
580
Steven Tothe47f30b2008-01-10 04:25:59 -0300581
582static int cx23885_restart_video_queue(struct cx23885_dev *dev,
583 struct cx23885_dmaqueue *q)
584{
585 struct cx23885_buffer *buf, *prev;
586 struct list_head *item;
Harvey Harrison22b4e642008-04-08 23:20:00 -0300587 dprintk(1, "%s()\n", __func__);
Steven Tothe47f30b2008-01-10 04:25:59 -0300588
589 if (!list_empty(&q->active)) {
590 buf = list_entry(q->active.next, struct cx23885_buffer,
591 vb.queue);
592 dprintk(2, "restart_queue [%p/%d]: restart dma\n",
593 buf, buf->vb.i);
594 cx23885_start_video_dma(dev, q, buf);
595 list_for_each(item, &q->active) {
596 buf = list_entry(item, struct cx23885_buffer,
597 vb.queue);
598 buf->count = q->count++;
599 }
600 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
601 return 0;
602 }
603
604 prev = NULL;
605 for (;;) {
606 if (list_empty(&q->queued))
607 return 0;
608 buf = list_entry(q->queued.next, struct cx23885_buffer,
609 vb.queue);
610 if (NULL == prev) {
611 list_move_tail(&buf->vb.queue, &q->active);
612 cx23885_start_video_dma(dev, q, buf);
613 buf->vb.state = VIDEOBUF_ACTIVE;
614 buf->count = q->count++;
615 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
616 dprintk(2, "[%p/%d] restart_queue - first active\n",
617 buf, buf->vb.i);
618
619 } else if (prev->vb.width == buf->vb.width &&
620 prev->vb.height == buf->vb.height &&
621 prev->fmt == buf->fmt) {
622 list_move_tail(&buf->vb.queue, &q->active);
623 buf->vb.state = VIDEOBUF_ACTIVE;
624 buf->count = q->count++;
625 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
626 prev->risc.jmp[2] = cpu_to_le32(0); /* Bits 63 - 32 */
627 dprintk(2, "[%p/%d] restart_queue - move to active\n",
628 buf, buf->vb.i);
629 } else {
630 return 0;
631 }
632 prev = buf;
633 }
634}
635
636static int buffer_setup(struct videobuf_queue *q, unsigned int *count,
637 unsigned int *size)
638{
639 struct cx23885_fh *fh = q->priv_data;
640
641 *size = fh->fmt->depth*fh->width*fh->height >> 3;
642 if (0 == *count)
643 *count = 32;
Andreas Bombedab7e312010-03-21 16:02:45 -0300644 if (*size * *count > vid_limit * 1024 * 1024)
645 *count = (vid_limit * 1024 * 1024) / *size;
Steven Tothe47f30b2008-01-10 04:25:59 -0300646 return 0;
647}
648
649static int buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
650 enum v4l2_field field)
651{
652 struct cx23885_fh *fh = q->priv_data;
653 struct cx23885_dev *dev = fh->dev;
654 struct cx23885_buffer *buf =
655 container_of(vb, struct cx23885_buffer, vb);
656 int rc, init_buffer = 0;
657 u32 line0_offset, line1_offset;
658 struct videobuf_dmabuf *dma = videobuf_to_dma(&buf->vb);
Steven Toth35045132012-01-04 21:08:35 -0300659 int field_tff;
Steven Tothe47f30b2008-01-10 04:25:59 -0300660
661 BUG_ON(NULL == fh->fmt);
662 if (fh->width < 48 || fh->width > norm_maxw(dev->tvnorm) ||
663 fh->height < 32 || fh->height > norm_maxh(dev->tvnorm))
664 return -EINVAL;
665 buf->vb.size = (fh->width * fh->height * fh->fmt->depth) >> 3;
666 if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size)
667 return -EINVAL;
668
669 if (buf->fmt != fh->fmt ||
670 buf->vb.width != fh->width ||
671 buf->vb.height != fh->height ||
672 buf->vb.field != field) {
673 buf->fmt = fh->fmt;
674 buf->vb.width = fh->width;
675 buf->vb.height = fh->height;
676 buf->vb.field = field;
677 init_buffer = 1;
678 }
679
680 if (VIDEOBUF_NEEDS_INIT == buf->vb.state) {
681 init_buffer = 1;
682 rc = videobuf_iolock(q, &buf->vb, NULL);
683 if (0 != rc)
684 goto fail;
685 }
686
687 if (init_buffer) {
688 buf->bpl = buf->vb.width * buf->fmt->depth >> 3;
689 switch (buf->vb.field) {
690 case V4L2_FIELD_TOP:
691 cx23885_risc_buffer(dev->pci, &buf->risc,
692 dma->sglist, 0, UNSET,
693 buf->bpl, 0, buf->vb.height);
694 break;
695 case V4L2_FIELD_BOTTOM:
696 cx23885_risc_buffer(dev->pci, &buf->risc,
697 dma->sglist, UNSET, 0,
698 buf->bpl, 0, buf->vb.height);
699 break;
700 case V4L2_FIELD_INTERLACED:
Steven Toth35045132012-01-04 21:08:35 -0300701 if (dev->tvnorm & V4L2_STD_NTSC)
702 /* NTSC or */
703 field_tff = 1;
704 else
705 field_tff = 0;
706
707 if (cx23885_boards[dev->board].force_bff)
708 /* PAL / SECAM OR 888 in NTSC MODE */
709 field_tff = 0;
710
711 if (field_tff) {
Steven Tothe47f30b2008-01-10 04:25:59 -0300712 /* cx25840 transmits NTSC bottom field first */
Steven Toth35045132012-01-04 21:08:35 -0300713 dprintk(1, "%s() Creating TFF/NTSC risc\n",
Harvey Harrison22b4e642008-04-08 23:20:00 -0300714 __func__);
Steven Tothe47f30b2008-01-10 04:25:59 -0300715 line0_offset = buf->bpl;
716 line1_offset = 0;
717 } else {
718 /* All other formats are top field first */
Steven Toth35045132012-01-04 21:08:35 -0300719 dprintk(1, "%s() Creating BFF/PAL/SECAM risc\n",
Harvey Harrison22b4e642008-04-08 23:20:00 -0300720 __func__);
Steven Tothe47f30b2008-01-10 04:25:59 -0300721 line0_offset = 0;
722 line1_offset = buf->bpl;
723 }
724 cx23885_risc_buffer(dev->pci, &buf->risc,
725 dma->sglist, line0_offset,
726 line1_offset,
727 buf->bpl, buf->bpl,
728 buf->vb.height >> 1);
729 break;
730 case V4L2_FIELD_SEQ_TB:
731 cx23885_risc_buffer(dev->pci, &buf->risc,
732 dma->sglist,
733 0, buf->bpl * (buf->vb.height >> 1),
734 buf->bpl, 0,
735 buf->vb.height >> 1);
736 break;
737 case V4L2_FIELD_SEQ_BT:
738 cx23885_risc_buffer(dev->pci, &buf->risc,
739 dma->sglist,
740 buf->bpl * (buf->vb.height >> 1), 0,
741 buf->bpl, 0,
742 buf->vb.height >> 1);
743 break;
744 default:
745 BUG();
746 }
747 }
748 dprintk(2, "[%p/%d] buffer_prep - %dx%d %dbpp \"%s\" - dma=0x%08lx\n",
749 buf, buf->vb.i,
750 fh->width, fh->height, fh->fmt->depth, fh->fmt->name,
751 (unsigned long)buf->risc.dma);
752
753 buf->vb.state = VIDEOBUF_PREPARED;
754 return 0;
755
756 fail:
757 cx23885_free_buffer(q, buf);
758 return rc;
759}
760
761static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
762{
763 struct cx23885_buffer *buf = container_of(vb,
764 struct cx23885_buffer, vb);
765 struct cx23885_buffer *prev;
766 struct cx23885_fh *fh = vq->priv_data;
767 struct cx23885_dev *dev = fh->dev;
768 struct cx23885_dmaqueue *q = &dev->vidq;
769
770 /* add jump to stopper */
771 buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC);
772 buf->risc.jmp[1] = cpu_to_le32(q->stopper.dma);
773 buf->risc.jmp[2] = cpu_to_le32(0); /* bits 63-32 */
774
775 if (!list_empty(&q->queued)) {
776 list_add_tail(&buf->vb.queue, &q->queued);
777 buf->vb.state = VIDEOBUF_QUEUED;
778 dprintk(2, "[%p/%d] buffer_queue - append to queued\n",
779 buf, buf->vb.i);
780
781 } else if (list_empty(&q->active)) {
782 list_add_tail(&buf->vb.queue, &q->active);
783 cx23885_start_video_dma(dev, q, buf);
784 buf->vb.state = VIDEOBUF_ACTIVE;
785 buf->count = q->count++;
786 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
787 dprintk(2, "[%p/%d] buffer_queue - first active\n",
788 buf, buf->vb.i);
789
790 } else {
791 prev = list_entry(q->active.prev, struct cx23885_buffer,
792 vb.queue);
793 if (prev->vb.width == buf->vb.width &&
794 prev->vb.height == buf->vb.height &&
795 prev->fmt == buf->fmt) {
796 list_add_tail(&buf->vb.queue, &q->active);
797 buf->vb.state = VIDEOBUF_ACTIVE;
798 buf->count = q->count++;
799 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
800 /* 64 bit bits 63-32 */
801 prev->risc.jmp[2] = cpu_to_le32(0);
802 dprintk(2, "[%p/%d] buffer_queue - append to active\n",
803 buf, buf->vb.i);
804
805 } else {
806 list_add_tail(&buf->vb.queue, &q->queued);
807 buf->vb.state = VIDEOBUF_QUEUED;
808 dprintk(2, "[%p/%d] buffer_queue - first queued\n",
809 buf, buf->vb.i);
810 }
811 }
812}
813
814static void buffer_release(struct videobuf_queue *q,
815 struct videobuf_buffer *vb)
816{
817 struct cx23885_buffer *buf = container_of(vb,
818 struct cx23885_buffer, vb);
819
820 cx23885_free_buffer(q, buf);
821}
822
823static struct videobuf_queue_ops cx23885_video_qops = {
824 .buf_setup = buffer_setup,
825 .buf_prepare = buffer_prepare,
826 .buf_queue = buffer_queue,
827 .buf_release = buffer_release,
828};
829
830static struct videobuf_queue *get_queue(struct cx23885_fh *fh)
831{
832 switch (fh->type) {
833 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
834 return &fh->vidq;
835 case V4L2_BUF_TYPE_VBI_CAPTURE:
836 return &fh->vbiq;
837 default:
838 BUG();
839 return NULL;
840 }
841}
842
843static int get_resource(struct cx23885_fh *fh)
844{
845 switch (fh->type) {
846 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
847 return RESOURCE_VIDEO;
848 case V4L2_BUF_TYPE_VBI_CAPTURE:
849 return RESOURCE_VBI;
850 default:
851 BUG();
852 return 0;
853 }
854}
855
Hans Verkuilbec43662008-12-30 06:58:20 -0300856static int video_open(struct file *file)
Steven Tothe47f30b2008-01-10 04:25:59 -0300857{
Laurent Pinchart63b0d5a2009-12-10 11:44:04 -0200858 struct video_device *vdev = video_devdata(file);
859 struct cx23885_dev *dev = video_drvdata(file);
Steven Tothe47f30b2008-01-10 04:25:59 -0300860 struct cx23885_fh *fh;
Steven Tothe47f30b2008-01-10 04:25:59 -0300861 enum v4l2_buf_type type = 0;
862 int radio = 0;
863
Laurent Pinchart63b0d5a2009-12-10 11:44:04 -0200864 switch (vdev->vfl_type) {
865 case VFL_TYPE_GRABBER:
866 type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
867 break;
868 case VFL_TYPE_VBI:
869 type = V4L2_BUF_TYPE_VBI_CAPTURE;
870 break;
871 case VFL_TYPE_RADIO:
872 radio = 1;
873 break;
Hans Verkuild56dc612008-07-30 08:43:36 -0300874 }
Steven Tothe47f30b2008-01-10 04:25:59 -0300875
Laurent Pinchart50462eb2009-12-10 11:47:13 -0200876 dprintk(1, "open dev=%s radio=%d type=%s\n",
877 video_device_node_name(vdev), radio, v4l2_type_names[type]);
Steven Tothe47f30b2008-01-10 04:25:59 -0300878
879 /* allocate + initialize per filehandle data */
880 fh = kzalloc(sizeof(*fh), GFP_KERNEL);
Laurent Pinchart63b0d5a2009-12-10 11:44:04 -0200881 if (NULL == fh)
Steven Tothe47f30b2008-01-10 04:25:59 -0300882 return -ENOMEM;
Laurent Pinchart63b0d5a2009-12-10 11:44:04 -0200883
Steven Tothe47f30b2008-01-10 04:25:59 -0300884 file->private_data = fh;
885 fh->dev = dev;
886 fh->radio = radio;
887 fh->type = type;
888 fh->width = 320;
889 fh->height = 240;
Steven Tothaf76e9f2011-10-10 11:09:54 -0300890 fh->fmt = format_by_fourcc(V4L2_PIX_FMT_YUYV);
Steven Tothe47f30b2008-01-10 04:25:59 -0300891
Guennadi Liakhovetski07051352008-04-22 14:42:13 -0300892 videobuf_queue_sg_init(&fh->vidq, &cx23885_video_qops,
893 &dev->pci->dev, &dev->slock,
Steven Tothe47f30b2008-01-10 04:25:59 -0300894 V4L2_BUF_TYPE_VIDEO_CAPTURE,
895 V4L2_FIELD_INTERLACED,
896 sizeof(struct cx23885_buffer),
Hans Verkuil08bff032010-09-20 17:39:46 -0300897 fh, NULL);
Steven Tothe47f30b2008-01-10 04:25:59 -0300898
Steven Toth79776c82011-10-10 11:09:54 -0300899 videobuf_queue_sg_init(&fh->vbiq, &cx23885_vbi_qops,
900 &dev->pci->dev, &dev->slock,
901 V4L2_BUF_TYPE_VBI_CAPTURE,
902 V4L2_FIELD_SEQ_TB,
903 sizeof(struct cx23885_buffer),
904 fh, NULL);
905
906
Steven Tothe47f30b2008-01-10 04:25:59 -0300907 dprintk(1, "post videobuf_queue_init()\n");
908
Steven Tothe47f30b2008-01-10 04:25:59 -0300909 return 0;
910}
911
912static ssize_t video_read(struct file *file, char __user *data,
913 size_t count, loff_t *ppos)
914{
915 struct cx23885_fh *fh = file->private_data;
916
917 switch (fh->type) {
918 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
919 if (res_locked(fh->dev, RESOURCE_VIDEO))
920 return -EBUSY;
921 return videobuf_read_one(&fh->vidq, data, count, ppos,
922 file->f_flags & O_NONBLOCK);
923 case V4L2_BUF_TYPE_VBI_CAPTURE:
924 if (!res_get(fh->dev, fh, RESOURCE_VBI))
925 return -EBUSY;
926 return videobuf_read_stream(&fh->vbiq, data, count, ppos, 1,
927 file->f_flags & O_NONBLOCK);
928 default:
929 BUG();
930 return 0;
931 }
932}
933
934static unsigned int video_poll(struct file *file,
935 struct poll_table_struct *wait)
936{
937 struct cx23885_fh *fh = file->private_data;
938 struct cx23885_buffer *buf;
Figo.zhang9fd64182009-06-16 13:31:29 -0300939 unsigned int rc = POLLERR;
Steven Tothe47f30b2008-01-10 04:25:59 -0300940
941 if (V4L2_BUF_TYPE_VBI_CAPTURE == fh->type) {
942 if (!res_get(fh->dev, fh, RESOURCE_VBI))
943 return POLLERR;
944 return videobuf_poll_stream(file, &fh->vbiq, wait);
945 }
946
Figo.zhang9fd64182009-06-16 13:31:29 -0300947 mutex_lock(&fh->vidq.vb_lock);
Steven Tothe47f30b2008-01-10 04:25:59 -0300948 if (res_check(fh, RESOURCE_VIDEO)) {
949 /* streaming capture */
950 if (list_empty(&fh->vidq.stream))
Figo.zhang9fd64182009-06-16 13:31:29 -0300951 goto done;
Steven Tothe47f30b2008-01-10 04:25:59 -0300952 buf = list_entry(fh->vidq.stream.next,
953 struct cx23885_buffer, vb.stream);
954 } else {
955 /* read() capture */
956 buf = (struct cx23885_buffer *)fh->vidq.read_buf;
957 if (NULL == buf)
Figo.zhang9fd64182009-06-16 13:31:29 -0300958 goto done;
Steven Tothe47f30b2008-01-10 04:25:59 -0300959 }
960 poll_wait(file, &buf->vb.done, wait);
961 if (buf->vb.state == VIDEOBUF_DONE ||
962 buf->vb.state == VIDEOBUF_ERROR)
Figo.zhang9fd64182009-06-16 13:31:29 -0300963 rc = POLLIN|POLLRDNORM;
964 else
965 rc = 0;
966done:
967 mutex_unlock(&fh->vidq.vb_lock);
968 return rc;
Steven Tothe47f30b2008-01-10 04:25:59 -0300969}
970
Hans Verkuilbec43662008-12-30 06:58:20 -0300971static int video_release(struct file *file)
Steven Tothe47f30b2008-01-10 04:25:59 -0300972{
973 struct cx23885_fh *fh = file->private_data;
974 struct cx23885_dev *dev = fh->dev;
975
976 /* turn off overlay */
977 if (res_check(fh, RESOURCE_OVERLAY)) {
978 /* FIXME */
979 res_free(dev, fh, RESOURCE_OVERLAY);
980 }
981
982 /* stop video capture */
983 if (res_check(fh, RESOURCE_VIDEO)) {
984 videobuf_queue_cancel(&fh->vidq);
985 res_free(dev, fh, RESOURCE_VIDEO);
986 }
987 if (fh->vidq.read_buf) {
988 buffer_release(&fh->vidq, fh->vidq.read_buf);
989 kfree(fh->vidq.read_buf);
990 }
991
992 /* stop vbi capture */
993 if (res_check(fh, RESOURCE_VBI)) {
994 if (fh->vbiq.streaming)
995 videobuf_streamoff(&fh->vbiq);
996 if (fh->vbiq.reading)
997 videobuf_read_stop(&fh->vbiq);
998 res_free(dev, fh, RESOURCE_VBI);
999 }
1000
1001 videobuf_mmap_free(&fh->vidq);
Steven Toth35045132012-01-04 21:08:35 -03001002 videobuf_mmap_free(&fh->vbiq);
1003
Steven Tothe47f30b2008-01-10 04:25:59 -03001004 file->private_data = NULL;
1005 kfree(fh);
1006
Steven Totha19602f22008-01-10 11:43:18 -03001007 /* We are not putting the tuner to sleep here on exit, because
1008 * we want to use the mpeg encoder in another session to capture
1009 * tuner video. Closing this will result in no video to the encoder.
1010 */
Steven Tothe47f30b2008-01-10 04:25:59 -03001011
1012 return 0;
1013}
1014
1015static int video_mmap(struct file *file, struct vm_area_struct *vma)
1016{
1017 struct cx23885_fh *fh = file->private_data;
1018
1019 return videobuf_mmap_mapper(get_queue(fh), vma);
1020}
1021
1022/* ------------------------------------------------------------------ */
1023/* VIDEO CTRL IOCTLS */
1024
Steven Toth35045132012-01-04 21:08:35 -03001025int cx23885_get_control(struct cx23885_dev *dev,
Steven Toth9c8ced52008-10-16 20:18:44 -03001026 struct v4l2_control *ctl)
Steven Tothe47f30b2008-01-10 04:25:59 -03001027{
Harvey Harrison22b4e642008-04-08 23:20:00 -03001028 dprintk(1, "%s() calling cx25840(VIDIOC_G_CTRL)\n", __func__);
Hans Verkuil0d5a19f2009-03-29 06:53:29 -03001029 call_all(dev, core, g_ctrl, ctl);
Steven Tothe47f30b2008-01-10 04:25:59 -03001030 return 0;
1031}
Steven Tothe47f30b2008-01-10 04:25:59 -03001032
Steven Toth35045132012-01-04 21:08:35 -03001033int cx23885_set_control(struct cx23885_dev *dev,
Steven Toth9c8ced52008-10-16 20:18:44 -03001034 struct v4l2_control *ctl)
Steven Tothe47f30b2008-01-10 04:25:59 -03001035{
Mijhail Moreyra97ce5672011-10-10 11:09:53 -03001036 dprintk(1, "%s() calling cx25840(VIDIOC_S_CTRL)\n", __func__);
1037 call_all(dev, core, s_ctrl, ctl);
1038
Steven Tothe47f30b2008-01-10 04:25:59 -03001039 return 0;
1040}
Steven Tothe47f30b2008-01-10 04:25:59 -03001041
1042static void init_controls(struct cx23885_dev *dev)
1043{
1044 struct v4l2_control ctrl;
1045 int i;
1046
1047 for (i = 0; i < CX23885_CTLS; i++) {
1048 ctrl.id = cx23885_ctls[i].v.id;
1049 ctrl.value = cx23885_ctls[i].v.default_value;
1050
1051 cx23885_set_control(dev, &ctrl);
1052 }
1053}
1054
1055/* ------------------------------------------------------------------ */
1056/* VIDEO IOCTLS */
1057
Hans Verkuil78b526a2008-05-28 12:16:41 -03001058static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
Steven Tothe47f30b2008-01-10 04:25:59 -03001059 struct v4l2_format *f)
1060{
1061 struct cx23885_fh *fh = priv;
1062
1063 f->fmt.pix.width = fh->width;
1064 f->fmt.pix.height = fh->height;
1065 f->fmt.pix.field = fh->vidq.field;
1066 f->fmt.pix.pixelformat = fh->fmt->fourcc;
1067 f->fmt.pix.bytesperline =
1068 (f->fmt.pix.width * fh->fmt->depth) >> 3;
1069 f->fmt.pix.sizeimage =
1070 f->fmt.pix.height * f->fmt.pix.bytesperline;
1071
1072 return 0;
1073}
1074
Hans Verkuil78b526a2008-05-28 12:16:41 -03001075static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
Steven Tothe47f30b2008-01-10 04:25:59 -03001076 struct v4l2_format *f)
1077{
1078 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
1079 struct cx23885_fmt *fmt;
1080 enum v4l2_field field;
1081 unsigned int maxw, maxh;
1082
1083 fmt = format_by_fourcc(f->fmt.pix.pixelformat);
1084 if (NULL == fmt)
1085 return -EINVAL;
1086
1087 field = f->fmt.pix.field;
1088 maxw = norm_maxw(dev->tvnorm);
1089 maxh = norm_maxh(dev->tvnorm);
1090
1091 if (V4L2_FIELD_ANY == field) {
1092 field = (f->fmt.pix.height > maxh/2)
1093 ? V4L2_FIELD_INTERLACED
1094 : V4L2_FIELD_BOTTOM;
1095 }
1096
1097 switch (field) {
1098 case V4L2_FIELD_TOP:
1099 case V4L2_FIELD_BOTTOM:
1100 maxh = maxh / 2;
1101 break;
1102 case V4L2_FIELD_INTERLACED:
1103 break;
1104 default:
1105 return -EINVAL;
1106 }
1107
1108 f->fmt.pix.field = field;
Trent Piepho2449afc2009-05-30 21:45:46 -03001109 v4l_bound_align_image(&f->fmt.pix.width, 48, maxw, 2,
1110 &f->fmt.pix.height, 32, maxh, 0, 0);
Steven Tothe47f30b2008-01-10 04:25:59 -03001111 f->fmt.pix.bytesperline =
1112 (f->fmt.pix.width * fmt->depth) >> 3;
1113 f->fmt.pix.sizeimage =
1114 f->fmt.pix.height * f->fmt.pix.bytesperline;
1115
1116 return 0;
1117}
1118
Hans Verkuil78b526a2008-05-28 12:16:41 -03001119static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
Steven Tothe47f30b2008-01-10 04:25:59 -03001120 struct v4l2_format *f)
1121{
1122 struct cx23885_fh *fh = priv;
1123 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
Hans Verkuilcc991132010-05-09 10:09:28 -03001124 struct v4l2_mbus_framefmt mbus_fmt;
Steven Tothe47f30b2008-01-10 04:25:59 -03001125 int err;
1126
Harvey Harrison22b4e642008-04-08 23:20:00 -03001127 dprintk(2, "%s()\n", __func__);
Hans Verkuil78b526a2008-05-28 12:16:41 -03001128 err = vidioc_try_fmt_vid_cap(file, priv, f);
Steven Tothe47f30b2008-01-10 04:25:59 -03001129
1130 if (0 != err)
1131 return err;
1132 fh->fmt = format_by_fourcc(f->fmt.pix.pixelformat);
1133 fh->width = f->fmt.pix.width;
1134 fh->height = f->fmt.pix.height;
1135 fh->vidq.field = f->fmt.pix.field;
Harvey Harrison22b4e642008-04-08 23:20:00 -03001136 dprintk(2, "%s() width=%d height=%d field=%d\n", __func__,
Steven Tothe47f30b2008-01-10 04:25:59 -03001137 fh->width, fh->height, fh->vidq.field);
Hans Verkuilcc991132010-05-09 10:09:28 -03001138 v4l2_fill_mbus_format(&mbus_fmt, &f->fmt.pix, V4L2_MBUS_FMT_FIXED);
1139 call_all(dev, video, s_mbus_fmt, &mbus_fmt);
1140 v4l2_fill_pix_format(&f->fmt.pix, &mbus_fmt);
Steven Tothe47f30b2008-01-10 04:25:59 -03001141 return 0;
1142}
1143
1144static int vidioc_querycap(struct file *file, void *priv,
1145 struct v4l2_capability *cap)
1146{
1147 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
1148
1149 strcpy(cap->driver, "cx23885");
1150 strlcpy(cap->card, cx23885_boards[dev->board].name,
1151 sizeof(cap->card));
1152 sprintf(cap->bus_info, "PCIe:%s", pci_name(dev->pci));
Steven Tothe47f30b2008-01-10 04:25:59 -03001153 cap->capabilities =
1154 V4L2_CAP_VIDEO_CAPTURE |
1155 V4L2_CAP_READWRITE |
1156 V4L2_CAP_STREAMING |
1157 V4L2_CAP_VBI_CAPTURE;
1158 if (UNSET != dev->tuner_type)
1159 cap->capabilities |= V4L2_CAP_TUNER;
1160 return 0;
1161}
1162
Hans Verkuil78b526a2008-05-28 12:16:41 -03001163static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
Steven Tothe47f30b2008-01-10 04:25:59 -03001164 struct v4l2_fmtdesc *f)
1165{
1166 if (unlikely(f->index >= ARRAY_SIZE(formats)))
1167 return -EINVAL;
1168
1169 strlcpy(f->description, formats[f->index].name,
1170 sizeof(f->description));
1171 f->pixelformat = formats[f->index].fourcc;
1172
1173 return 0;
1174}
1175
Steven Tothe47f30b2008-01-10 04:25:59 -03001176static int vidioc_reqbufs(struct file *file, void *priv,
1177 struct v4l2_requestbuffers *p)
1178{
1179 struct cx23885_fh *fh = priv;
Steven Toth9c8ced52008-10-16 20:18:44 -03001180 return videobuf_reqbufs(get_queue(fh), p);
Steven Tothe47f30b2008-01-10 04:25:59 -03001181}
1182
1183static int vidioc_querybuf(struct file *file, void *priv,
1184 struct v4l2_buffer *p)
1185{
1186 struct cx23885_fh *fh = priv;
Steven Toth9c8ced52008-10-16 20:18:44 -03001187 return videobuf_querybuf(get_queue(fh), p);
Steven Tothe47f30b2008-01-10 04:25:59 -03001188}
1189
1190static int vidioc_qbuf(struct file *file, void *priv,
1191 struct v4l2_buffer *p)
1192{
1193 struct cx23885_fh *fh = priv;
Steven Toth9c8ced52008-10-16 20:18:44 -03001194 return videobuf_qbuf(get_queue(fh), p);
Steven Tothe47f30b2008-01-10 04:25:59 -03001195}
1196
1197static int vidioc_dqbuf(struct file *file, void *priv,
1198 struct v4l2_buffer *p)
1199{
1200 struct cx23885_fh *fh = priv;
Steven Toth9c8ced52008-10-16 20:18:44 -03001201 return videobuf_dqbuf(get_queue(fh), p,
1202 file->f_flags & O_NONBLOCK);
Steven Tothe47f30b2008-01-10 04:25:59 -03001203}
1204
1205static int vidioc_streamon(struct file *file, void *priv,
1206 enum v4l2_buf_type i)
1207{
1208 struct cx23885_fh *fh = priv;
1209 struct cx23885_dev *dev = fh->dev;
Harvey Harrison22b4e642008-04-08 23:20:00 -03001210 dprintk(1, "%s()\n", __func__);
Steven Tothe47f30b2008-01-10 04:25:59 -03001211
Steven Toth5ab27e62011-10-10 11:09:54 -03001212 if ((fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) &&
1213 (fh->type != V4L2_BUF_TYPE_VBI_CAPTURE))
Steven Tothe47f30b2008-01-10 04:25:59 -03001214 return -EINVAL;
1215 if (unlikely(i != fh->type))
1216 return -EINVAL;
1217
1218 if (unlikely(!res_get(dev, fh, get_resource(fh))))
1219 return -EBUSY;
Steven Toth24465b42011-10-10 11:09:54 -03001220
1221 /* Don't start VBI streaming unless vida streaming
1222 * has already started.
1223 */
1224 if ((fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) &&
1225 ((cx_read(VID_A_DMA_CTL) & 0x11) == 0))
1226 return -EINVAL;
1227
Steven Tothe47f30b2008-01-10 04:25:59 -03001228 return videobuf_streamon(get_queue(fh));
1229}
1230
1231static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
1232{
1233 struct cx23885_fh *fh = priv;
1234 struct cx23885_dev *dev = fh->dev;
1235 int err, res;
Harvey Harrison22b4e642008-04-08 23:20:00 -03001236 dprintk(1, "%s()\n", __func__);
Steven Tothe47f30b2008-01-10 04:25:59 -03001237
Steven Toth5ab27e62011-10-10 11:09:54 -03001238 if ((fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) &&
1239 (fh->type != V4L2_BUF_TYPE_VBI_CAPTURE))
Steven Tothe47f30b2008-01-10 04:25:59 -03001240 return -EINVAL;
1241 if (i != fh->type)
1242 return -EINVAL;
1243
1244 res = get_resource(fh);
1245 err = videobuf_streamoff(get_queue(fh));
1246 if (err < 0)
1247 return err;
1248 res_free(dev, fh, res);
1249 return 0;
1250}
1251
Steven Toth35045132012-01-04 21:08:35 -03001252static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id *id)
1253{
1254 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
1255 dprintk(1, "%s()\n", __func__);
1256
1257 call_all(dev, core, g_std, id);
1258
1259 return 0;
1260}
1261
Steven Tothe47f30b2008-01-10 04:25:59 -03001262static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *tvnorms)
1263{
1264 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
Harvey Harrison22b4e642008-04-08 23:20:00 -03001265 dprintk(1, "%s()\n", __func__);
Steven Tothe47f30b2008-01-10 04:25:59 -03001266
1267 mutex_lock(&dev->lock);
1268 cx23885_set_tvnorm(dev, *tvnorms);
1269 mutex_unlock(&dev->lock);
1270
1271 return 0;
1272}
1273
Steven Toth35045132012-01-04 21:08:35 -03001274int cx23885_enum_input(struct cx23885_dev *dev, struct v4l2_input *i)
Steven Tothe47f30b2008-01-10 04:25:59 -03001275{
1276 static const char *iname[] = {
1277 [CX23885_VMUX_COMPOSITE1] = "Composite1",
1278 [CX23885_VMUX_COMPOSITE2] = "Composite2",
1279 [CX23885_VMUX_COMPOSITE3] = "Composite3",
1280 [CX23885_VMUX_COMPOSITE4] = "Composite4",
1281 [CX23885_VMUX_SVIDEO] = "S-Video",
David T.L. Wongdac65fa2009-10-21 11:07:24 -03001282 [CX23885_VMUX_COMPONENT] = "Component",
Steven Tothe47f30b2008-01-10 04:25:59 -03001283 [CX23885_VMUX_TELEVISION] = "Television",
1284 [CX23885_VMUX_CABLE] = "Cable TV",
1285 [CX23885_VMUX_DVB] = "DVB",
1286 [CX23885_VMUX_DEBUG] = "for debug only",
1287 };
1288 unsigned int n;
Harvey Harrison22b4e642008-04-08 23:20:00 -03001289 dprintk(1, "%s()\n", __func__);
Steven Tothe47f30b2008-01-10 04:25:59 -03001290
1291 n = i->index;
Steven Tothe92bcf82011-10-10 11:09:55 -03001292 if (n >= MAX_CX23885_INPUT)
Steven Tothe47f30b2008-01-10 04:25:59 -03001293 return -EINVAL;
1294
1295 if (0 == INPUT(n)->type)
1296 return -EINVAL;
1297
Steven Tothe47f30b2008-01-10 04:25:59 -03001298 i->index = n;
1299 i->type = V4L2_INPUT_TYPE_CAMERA;
1300 strcpy(i->name, iname[INPUT(n)->type]);
1301 if ((CX23885_VMUX_TELEVISION == INPUT(n)->type) ||
Julia Lawall473d8022010-08-05 17:22:44 -03001302 (CX23885_VMUX_CABLE == INPUT(n)->type)) {
Steven Tothe47f30b2008-01-10 04:25:59 -03001303 i->type = V4L2_INPUT_TYPE_TUNER;
1304 i->std = CX23885_NORMS;
Julia Lawall473d8022010-08-05 17:22:44 -03001305 }
Steven Toth6c6f52f2011-10-10 11:09:56 -03001306
1307 /* Two selectable audio inputs for non-tv inputs */
1308 if (INPUT(n)->type != CX23885_VMUX_TELEVISION)
1309 i->audioset = 0x3;
1310
Steven Tothc147f612012-01-06 11:55:32 -03001311 if (dev->input == n) {
1312 /* enum'd input matches our configured input.
1313 * Ask the video decoder to process the call
1314 * and give it an oppertunity to update the
1315 * status field.
1316 */
1317 call_all(dev, video, g_input_status, &i->status);
1318 }
1319
Steven Tothe47f30b2008-01-10 04:25:59 -03001320 return 0;
1321}
Steven Tothe47f30b2008-01-10 04:25:59 -03001322
1323static int vidioc_enum_input(struct file *file, void *priv,
1324 struct v4l2_input *i)
1325{
1326 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
Harvey Harrison22b4e642008-04-08 23:20:00 -03001327 dprintk(1, "%s()\n", __func__);
Steven Tothe47f30b2008-01-10 04:25:59 -03001328 return cx23885_enum_input(dev, i);
1329}
1330
Steven Toth35045132012-01-04 21:08:35 -03001331int cx23885_get_input(struct file *file, void *priv, unsigned int *i)
Steven Tothe47f30b2008-01-10 04:25:59 -03001332{
1333 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
1334
1335 *i = dev->input;
Harvey Harrison22b4e642008-04-08 23:20:00 -03001336 dprintk(1, "%s() returns %d\n", __func__, *i);
Steven Tothe47f30b2008-01-10 04:25:59 -03001337 return 0;
1338}
1339
Steven Toth35045132012-01-04 21:08:35 -03001340static int vidioc_g_input(struct file *file, void *priv, unsigned int *i)
1341{
1342 return cx23885_get_input(file, priv, i);
1343}
1344
1345int cx23885_set_input(struct file *file, void *priv, unsigned int i)
Steven Tothe47f30b2008-01-10 04:25:59 -03001346{
1347 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
1348
Harvey Harrison22b4e642008-04-08 23:20:00 -03001349 dprintk(1, "%s(%d)\n", __func__, i);
Steven Tothe47f30b2008-01-10 04:25:59 -03001350
Steven Tothe92bcf82011-10-10 11:09:55 -03001351 if (i >= MAX_CX23885_INPUT) {
Harvey Harrison22b4e642008-04-08 23:20:00 -03001352 dprintk(1, "%s() -EINVAL\n", __func__);
Steven Tothe47f30b2008-01-10 04:25:59 -03001353 return -EINVAL;
1354 }
1355
Steven Tothe92bcf82011-10-10 11:09:55 -03001356 if (INPUT(i)->type == 0)
1357 return -EINVAL;
1358
Steven Tothe47f30b2008-01-10 04:25:59 -03001359 mutex_lock(&dev->lock);
1360 cx23885_video_mux(dev, i);
Steven Tothfa1e0fd2011-10-10 11:09:56 -03001361
1362 /* By default establish the default audio input for the card also */
1363 /* Caller is free to use VIDIOC_S_AUDIO to override afterwards */
1364 cx23885_audio_mux(dev, i);
Steven Tothe47f30b2008-01-10 04:25:59 -03001365 mutex_unlock(&dev->lock);
1366 return 0;
1367}
1368
Steven Toth35045132012-01-04 21:08:35 -03001369static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
1370{
1371 return cx23885_set_input(file, priv, i);
1372}
1373
Andy Wallse9e5cf42010-07-18 18:18:06 -03001374static int vidioc_log_status(struct file *file, void *priv)
1375{
1376 struct cx23885_fh *fh = priv;
1377 struct cx23885_dev *dev = fh->dev;
1378
1379 printk(KERN_INFO
1380 "%s/0: ============ START LOG STATUS ============\n",
Steven Toth35045132012-01-04 21:08:35 -03001381 dev->name);
Andy Wallse9e5cf42010-07-18 18:18:06 -03001382 call_all(dev, core, log_status);
1383 printk(KERN_INFO
1384 "%s/0: ============= END LOG STATUS =============\n",
Steven Toth35045132012-01-04 21:08:35 -03001385 dev->name);
Andy Wallse9e5cf42010-07-18 18:18:06 -03001386 return 0;
1387}
1388
Steven Tothfc1a8892011-10-10 11:09:56 -03001389static int cx23885_query_audinput(struct file *file, void *priv,
1390 struct v4l2_audio *i)
1391{
1392 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
1393 static const char *iname[] = {
1394 [0] = "Baseband L/R 1",
1395 [1] = "Baseband L/R 2",
1396 };
1397 unsigned int n;
1398 dprintk(1, "%s()\n", __func__);
1399
1400 n = i->index;
1401 if (n >= 2)
1402 return -EINVAL;
1403
1404 memset(i, 0, sizeof(*i));
1405 i->index = n;
1406 strcpy(i->name, iname[n]);
1407 i->capability = V4L2_AUDCAP_STEREO;
1408 i->mode = V4L2_AUDMODE_AVL;
1409 return 0;
1410
1411}
1412
1413static int vidioc_enum_audinput(struct file *file, void *priv,
1414 struct v4l2_audio *i)
1415{
1416 return cx23885_query_audinput(file, priv, i);
1417}
1418
1419static int vidioc_g_audinput(struct file *file, void *priv,
1420 struct v4l2_audio *i)
1421{
1422 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
1423
1424 i->index = dev->audinput;
1425 dprintk(1, "%s(input=%d)\n", __func__, i->index);
1426
1427 return cx23885_query_audinput(file, priv, i);
1428}
1429
1430static int vidioc_s_audinput(struct file *file, void *priv,
Hans Verkuil0e8025b2012-09-04 11:59:31 -03001431 const struct v4l2_audio *i)
Steven Tothfc1a8892011-10-10 11:09:56 -03001432{
1433 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
Steven Tothfc1a8892011-10-10 11:09:56 -03001434 if (i->index >= 2)
1435 return -EINVAL;
1436
1437 dprintk(1, "%s(%d)\n", __func__, i->index);
1438
Steven Tothfc1a8892011-10-10 11:09:56 -03001439 dev->audinput = i->index;
Steven Tothfa1e0fd2011-10-10 11:09:56 -03001440
1441 /* Skip the audio defaults from the cards struct, caller wants
1442 * directly touch the audio mux hardware. */
1443 cx23885_flatiron_mux(dev, dev->audinput + 1);
Steven Tothfc1a8892011-10-10 11:09:56 -03001444 return 0;
1445}
1446
Steven Tothe47f30b2008-01-10 04:25:59 -03001447static int vidioc_queryctrl(struct file *file, void *priv,
1448 struct v4l2_queryctrl *qctrl)
1449{
1450 qctrl->id = v4l2_ctrl_next(ctrl_classes, qctrl->id);
1451 if (unlikely(qctrl->id == 0))
1452 return -EINVAL;
1453 return cx23885_ctrl_query(qctrl);
1454}
1455
1456static int vidioc_g_ctrl(struct file *file, void *priv,
1457 struct v4l2_control *ctl)
1458{
1459 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
1460
1461 return cx23885_get_control(dev, ctl);
1462}
1463
1464static int vidioc_s_ctrl(struct file *file, void *priv,
1465 struct v4l2_control *ctl)
1466{
1467 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
1468
1469 return cx23885_set_control(dev, ctl);
1470}
1471
1472static int vidioc_g_tuner(struct file *file, void *priv,
1473 struct v4l2_tuner *t)
1474{
1475 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
1476
1477 if (unlikely(UNSET == dev->tuner_type))
1478 return -EINVAL;
1479 if (0 != t->index)
1480 return -EINVAL;
1481
1482 strcpy(t->name, "Television");
Mijhail Moreyra97ce5672011-10-10 11:09:53 -03001483
Steven Toth80f1e082011-10-10 11:09:53 -03001484 call_all(dev, tuner, g_tuner, t);
Steven Tothe47f30b2008-01-10 04:25:59 -03001485 return 0;
1486}
1487
1488static int vidioc_s_tuner(struct file *file, void *priv,
1489 struct v4l2_tuner *t)
1490{
1491 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
1492
1493 if (UNSET == dev->tuner_type)
1494 return -EINVAL;
1495 if (0 != t->index)
1496 return -EINVAL;
Mijhail Moreyra97ce5672011-10-10 11:09:53 -03001497 /* Update the A/V core */
Steven Toth80f1e082011-10-10 11:09:53 -03001498 call_all(dev, tuner, s_tuner, t);
Mijhail Moreyra97ce5672011-10-10 11:09:53 -03001499
Steven Tothe47f30b2008-01-10 04:25:59 -03001500 return 0;
1501}
1502
1503static int vidioc_g_frequency(struct file *file, void *priv,
1504 struct v4l2_frequency *f)
1505{
1506 struct cx23885_fh *fh = priv;
1507 struct cx23885_dev *dev = fh->dev;
1508
1509 if (unlikely(UNSET == dev->tuner_type))
1510 return -EINVAL;
1511
1512 /* f->type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; */
1513 f->type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
1514 f->frequency = dev->freq;
1515
Hans Verkuil0d5a19f2009-03-29 06:53:29 -03001516 call_all(dev, tuner, g_frequency, f);
Steven Tothe47f30b2008-01-10 04:25:59 -03001517
1518 return 0;
1519}
1520
Hans Verkuild45b9b82008-09-04 03:33:43 -03001521static int cx23885_set_freq(struct cx23885_dev *dev, struct v4l2_frequency *f)
Steven Tothe47f30b2008-01-10 04:25:59 -03001522{
Steven Toth35045132012-01-04 21:08:35 -03001523 struct v4l2_control ctrl;
1524
Steven Tothe47f30b2008-01-10 04:25:59 -03001525 if (unlikely(UNSET == dev->tuner_type))
1526 return -EINVAL;
1527 if (unlikely(f->tuner != 0))
1528 return -EINVAL;
1529
1530 mutex_lock(&dev->lock);
1531 dev->freq = f->frequency;
1532
Steven Toth35045132012-01-04 21:08:35 -03001533 /* I need to mute audio here */
1534 ctrl.id = V4L2_CID_AUDIO_MUTE;
1535 ctrl.value = 1;
1536 cx23885_set_control(dev, &ctrl);
1537
Hans Verkuil0d5a19f2009-03-29 06:53:29 -03001538 call_all(dev, tuner, s_frequency, f);
Steven Tothe47f30b2008-01-10 04:25:59 -03001539
1540 /* When changing channels it is required to reset TVAUDIO */
Steven Toth35045132012-01-04 21:08:35 -03001541 msleep(100);
1542
1543 /* I need to unmute audio here */
1544 ctrl.value = 0;
1545 cx23885_set_control(dev, &ctrl);
Steven Tothe47f30b2008-01-10 04:25:59 -03001546
1547 mutex_unlock(&dev->lock);
1548
1549 return 0;
1550}
Steven Tothe47f30b2008-01-10 04:25:59 -03001551
Steven Toth35045132012-01-04 21:08:35 -03001552static int cx23885_set_freq_via_ops(struct cx23885_dev *dev,
1553 struct v4l2_frequency *f)
1554{
1555 struct v4l2_control ctrl;
1556 struct videobuf_dvb_frontend *vfe;
1557 struct dvb_frontend *fe;
Steven Toth35045132012-01-04 21:08:35 -03001558
1559 struct analog_parameters params = {
1560 .mode = V4L2_TUNER_ANALOG_TV,
1561 .audmode = V4L2_TUNER_MODE_STEREO,
1562 .std = dev->tvnorm,
1563 .frequency = f->frequency
1564 };
1565
1566 mutex_lock(&dev->lock);
1567 dev->freq = f->frequency;
1568
1569 /* I need to mute audio here */
1570 ctrl.id = V4L2_CID_AUDIO_MUTE;
1571 ctrl.value = 1;
1572 cx23885_set_control(dev, &ctrl);
1573
1574 /* If HVR1850 */
1575 dprintk(1, "%s() frequency=%d tuner=%d std=0x%llx\n", __func__,
1576 params.frequency, f->tuner, params.std);
1577
1578 vfe = videobuf_dvb_get_frontend(&dev->ts2.frontends, 1);
Dan Carpenter0cb64f02012-01-10 05:04:39 -03001579 if (!vfe) {
1580 mutex_unlock(&dev->lock);
1581 return -EINVAL;
1582 }
Steven Toth35045132012-01-04 21:08:35 -03001583
1584 fe = vfe->dvb.frontend;
1585
Devin Heitmueller0ac60ac2012-07-01 16:15:14 -03001586 if ((dev->board == CX23885_BOARD_HAUPPAUGE_HVR1850) ||
1587 (dev->board == CX23885_BOARD_HAUPPAUGE_HVR1255) ||
1588 (dev->board == CX23885_BOARD_HAUPPAUGE_HVR1255_22111))
Steven Toth35045132012-01-04 21:08:35 -03001589 fe = &dev->ts1.analog_fe;
1590
1591 if (fe && fe->ops.tuner_ops.set_analog_params) {
1592 call_all(dev, core, s_std, dev->tvnorm);
1593 fe->ops.tuner_ops.set_analog_params(fe, &params);
1594 }
1595 else
1596 printk(KERN_ERR "%s() No analog tuner, aborting\n", __func__);
1597
1598 /* When changing channels it is required to reset TVAUDIO */
1599 msleep(100);
1600
1601 /* I need to unmute audio here */
1602 ctrl.value = 0;
1603 cx23885_set_control(dev, &ctrl);
1604
1605 mutex_unlock(&dev->lock);
1606
1607 return 0;
1608}
1609
1610int cx23885_set_frequency(struct file *file, void *priv,
1611 struct v4l2_frequency *f)
Steven Tothe47f30b2008-01-10 04:25:59 -03001612{
1613 struct cx23885_fh *fh = priv;
1614 struct cx23885_dev *dev = fh->dev;
Steven Toth35045132012-01-04 21:08:35 -03001615 int ret;
Steven Tothe47f30b2008-01-10 04:25:59 -03001616
Steven Toth35045132012-01-04 21:08:35 -03001617 switch (dev->board) {
Devin Heitmueller0ac60ac2012-07-01 16:15:14 -03001618 case CX23885_BOARD_HAUPPAUGE_HVR1255:
1619 case CX23885_BOARD_HAUPPAUGE_HVR1255_22111:
Steven Toth35045132012-01-04 21:08:35 -03001620 case CX23885_BOARD_HAUPPAUGE_HVR1850:
1621 ret = cx23885_set_freq_via_ops(dev, f);
1622 break;
1623 default:
1624 ret = cx23885_set_freq(dev, f);
1625 }
Steven Tothe47f30b2008-01-10 04:25:59 -03001626
Steven Toth35045132012-01-04 21:08:35 -03001627 return ret;
1628}
1629
1630static int vidioc_s_frequency(struct file *file, void *priv,
1631 struct v4l2_frequency *f)
1632{
1633 return cx23885_set_frequency(file, priv, f);
Steven Tothe47f30b2008-01-10 04:25:59 -03001634}
1635
Steven Tothe47f30b2008-01-10 04:25:59 -03001636/* ----------------------------------------------------------- */
Steven Tothe47f30b2008-01-10 04:25:59 -03001637
1638static void cx23885_vid_timeout(unsigned long data)
1639{
1640 struct cx23885_dev *dev = (struct cx23885_dev *)data;
1641 struct cx23885_dmaqueue *q = &dev->vidq;
1642 struct cx23885_buffer *buf;
1643 unsigned long flags;
1644
Steven Tothe47f30b2008-01-10 04:25:59 -03001645 spin_lock_irqsave(&dev->slock, flags);
1646 while (!list_empty(&q->active)) {
1647 buf = list_entry(q->active.next,
1648 struct cx23885_buffer, vb.queue);
1649 list_del(&buf->vb.queue);
1650 buf->vb.state = VIDEOBUF_ERROR;
1651 wake_up(&buf->vb.done);
Steven Toth79776c82011-10-10 11:09:54 -03001652 printk(KERN_ERR "%s: [%p/%d] timeout - dma=0x%08lx\n",
Steven Tothe47f30b2008-01-10 04:25:59 -03001653 dev->name, buf, buf->vb.i,
1654 (unsigned long)buf->risc.dma);
1655 }
1656 cx23885_restart_video_queue(dev, q);
1657 spin_unlock_irqrestore(&dev->slock, flags);
1658}
1659
1660int cx23885_video_irq(struct cx23885_dev *dev, u32 status)
1661{
1662 u32 mask, count;
1663 int handled = 0;
1664
1665 mask = cx_read(VID_A_INT_MSK);
1666 if (0 == (status & mask))
1667 return handled;
Steven Toth79776c82011-10-10 11:09:54 -03001668
Steven Tothe47f30b2008-01-10 04:25:59 -03001669 cx_write(VID_A_INT_STAT, status);
1670
Steven Toth19696f02011-10-10 11:09:56 -03001671 /* risc op code error, fifo overflow or line sync detection error */
Steven Toth79776c82011-10-10 11:09:54 -03001672 if ((status & VID_BC_MSK_OPC_ERR) ||
1673 (status & VID_BC_MSK_SYNC) ||
1674 (status & VID_BC_MSK_OF)) {
1675
Steven Toth19696f02011-10-10 11:09:56 -03001676 if (status & VID_BC_MSK_OPC_ERR) {
Steven Toth79776c82011-10-10 11:09:54 -03001677 dprintk(7, " (VID_BC_MSK_OPC_ERR 0x%08x)\n",
1678 VID_BC_MSK_OPC_ERR);
Steven Toth19696f02011-10-10 11:09:56 -03001679 printk(KERN_WARNING "%s: video risc op code error\n",
1680 dev->name);
1681 cx23885_sram_channel_dump(dev,
1682 &dev->sram_channels[SRAM_CH01]);
1683 }
Steven Toth79776c82011-10-10 11:09:54 -03001684
1685 if (status & VID_BC_MSK_SYNC)
Steven Toth19696f02011-10-10 11:09:56 -03001686 dprintk(7, " (VID_BC_MSK_SYNC 0x%08x) "
1687 "video lines miss-match\n",
Steven Toth79776c82011-10-10 11:09:54 -03001688 VID_BC_MSK_SYNC);
1689
1690 if (status & VID_BC_MSK_OF)
Steven Toth19696f02011-10-10 11:09:56 -03001691 dprintk(7, " (VID_BC_MSK_OF 0x%08x) fifo overflow\n",
Steven Toth79776c82011-10-10 11:09:54 -03001692 VID_BC_MSK_OF);
1693
Steven Tothe47f30b2008-01-10 04:25:59 -03001694 }
1695
Steven Toth79776c82011-10-10 11:09:54 -03001696 /* Video */
1697 if (status & VID_BC_MSK_RISCI1) {
Steven Tothe47f30b2008-01-10 04:25:59 -03001698 spin_lock(&dev->slock);
1699 count = cx_read(VID_A_GPCNT);
1700 cx23885_video_wakeup(dev, &dev->vidq, count);
1701 spin_unlock(&dev->slock);
1702 handled++;
1703 }
Steven Toth79776c82011-10-10 11:09:54 -03001704 if (status & VID_BC_MSK_RISCI2) {
Steven Tothe47f30b2008-01-10 04:25:59 -03001705 dprintk(2, "stopper video\n");
1706 spin_lock(&dev->slock);
1707 cx23885_restart_video_queue(dev, &dev->vidq);
1708 spin_unlock(&dev->slock);
1709 handled++;
1710 }
1711
Steven Toth79776c82011-10-10 11:09:54 -03001712 /* Allow the VBI framework to process it's payload */
1713 handled += cx23885_vbi_irq(dev, status);
1714
Steven Tothe47f30b2008-01-10 04:25:59 -03001715 return handled;
1716}
1717
Steven Tothe47f30b2008-01-10 04:25:59 -03001718/* ----------------------------------------------------------- */
1719/* exported stuff */
1720
Hans Verkuilbec43662008-12-30 06:58:20 -03001721static const struct v4l2_file_operations video_fops = {
Steven Tothe47f30b2008-01-10 04:25:59 -03001722 .owner = THIS_MODULE,
1723 .open = video_open,
1724 .release = video_release,
1725 .read = video_read,
1726 .poll = video_poll,
1727 .mmap = video_mmap,
1728 .ioctl = video_ioctl2,
Steven Tothe47f30b2008-01-10 04:25:59 -03001729};
1730
Hans Verkuila3998102008-07-21 02:57:38 -03001731static const struct v4l2_ioctl_ops video_ioctl_ops = {
Steven Tothe47f30b2008-01-10 04:25:59 -03001732 .vidioc_querycap = vidioc_querycap,
Hans Verkuil78b526a2008-05-28 12:16:41 -03001733 .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
1734 .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
1735 .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
1736 .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
1737 .vidioc_g_fmt_vbi_cap = cx23885_vbi_fmt,
1738 .vidioc_try_fmt_vbi_cap = cx23885_vbi_fmt,
1739 .vidioc_s_fmt_vbi_cap = cx23885_vbi_fmt,
Steven Tothe47f30b2008-01-10 04:25:59 -03001740 .vidioc_reqbufs = vidioc_reqbufs,
1741 .vidioc_querybuf = vidioc_querybuf,
1742 .vidioc_qbuf = vidioc_qbuf,
1743 .vidioc_dqbuf = vidioc_dqbuf,
1744 .vidioc_s_std = vidioc_s_std,
Steven Toth35045132012-01-04 21:08:35 -03001745 .vidioc_g_std = vidioc_g_std,
1746 .vidioc_querystd = vidioc_g_std,
Steven Tothe47f30b2008-01-10 04:25:59 -03001747 .vidioc_enum_input = vidioc_enum_input,
1748 .vidioc_g_input = vidioc_g_input,
1749 .vidioc_s_input = vidioc_s_input,
Andy Wallse9e5cf42010-07-18 18:18:06 -03001750 .vidioc_log_status = vidioc_log_status,
Steven Tothe47f30b2008-01-10 04:25:59 -03001751 .vidioc_queryctrl = vidioc_queryctrl,
1752 .vidioc_g_ctrl = vidioc_g_ctrl,
1753 .vidioc_s_ctrl = vidioc_s_ctrl,
1754 .vidioc_streamon = vidioc_streamon,
1755 .vidioc_streamoff = vidioc_streamoff,
Steven Tothe47f30b2008-01-10 04:25:59 -03001756 .vidioc_g_tuner = vidioc_g_tuner,
1757 .vidioc_s_tuner = vidioc_s_tuner,
1758 .vidioc_g_frequency = vidioc_g_frequency,
1759 .vidioc_s_frequency = vidioc_s_frequency,
Andy Walls74618242009-09-26 22:50:44 -03001760 .vidioc_g_chip_ident = cx23885_g_chip_ident,
Steven Tothe47f30b2008-01-10 04:25:59 -03001761#ifdef CONFIG_VIDEO_ADV_DEBUG
Andy Walls74618242009-09-26 22:50:44 -03001762 .vidioc_g_register = cx23885_g_register,
1763 .vidioc_s_register = cx23885_s_register,
Steven Tothe47f30b2008-01-10 04:25:59 -03001764#endif
Steven Tothfc1a8892011-10-10 11:09:56 -03001765 .vidioc_enumaudio = vidioc_enum_audinput,
1766 .vidioc_g_audio = vidioc_g_audinput,
1767 .vidioc_s_audio = vidioc_s_audinput,
Hans Verkuila3998102008-07-21 02:57:38 -03001768};
1769
1770static struct video_device cx23885_vbi_template;
1771static struct video_device cx23885_video_template = {
1772 .name = "cx23885-video",
Hans Verkuila3998102008-07-21 02:57:38 -03001773 .fops = &video_fops,
Hans Verkuila3998102008-07-21 02:57:38 -03001774 .ioctl_ops = &video_ioctl_ops,
Steven Tothe47f30b2008-01-10 04:25:59 -03001775 .tvnorms = CX23885_NORMS,
1776 .current_norm = V4L2_STD_NTSC_M,
1777};
1778
Hans Verkuilbec43662008-12-30 06:58:20 -03001779static const struct v4l2_file_operations radio_fops = {
Steven Tothe47f30b2008-01-10 04:25:59 -03001780 .owner = THIS_MODULE,
1781 .open = video_open,
1782 .release = video_release,
1783 .ioctl = video_ioctl2,
Steven Tothe47f30b2008-01-10 04:25:59 -03001784};
1785
1786
1787void cx23885_video_unregister(struct cx23885_dev *dev)
1788{
Harvey Harrison22b4e642008-04-08 23:20:00 -03001789 dprintk(1, "%s()\n", __func__);
Andy Wallsdbe83a32010-07-19 01:19:43 -03001790 cx23885_irq_remove(dev, 0x01);
Steven Tothe47f30b2008-01-10 04:25:59 -03001791
Steven Toth79776c82011-10-10 11:09:54 -03001792 if (dev->vbi_dev) {
1793 if (video_is_registered(dev->vbi_dev))
1794 video_unregister_device(dev->vbi_dev);
1795 else
1796 video_device_release(dev->vbi_dev);
1797 dev->vbi_dev = NULL;
1798 btcx_riscmem_free(dev->pci, &dev->vbiq.stopper);
1799 }
Steven Tothe47f30b2008-01-10 04:25:59 -03001800 if (dev->video_dev) {
Laurent Pinchartf0813b42009-11-27 13:57:30 -03001801 if (video_is_registered(dev->video_dev))
Steven Tothe47f30b2008-01-10 04:25:59 -03001802 video_unregister_device(dev->video_dev);
1803 else
1804 video_device_release(dev->video_dev);
1805 dev->video_dev = NULL;
1806
1807 btcx_riscmem_free(dev->pci, &dev->vidq.stopper);
1808 }
Mijhail Moreyra97ce5672011-10-10 11:09:53 -03001809
1810 if (dev->audio_dev)
Steven Tothefa762f2011-10-10 11:09:53 -03001811 cx23885_audio_unregister(dev);
Steven Tothe47f30b2008-01-10 04:25:59 -03001812}
1813
1814int cx23885_video_register(struct cx23885_dev *dev)
1815{
1816 int err;
1817
Harvey Harrison22b4e642008-04-08 23:20:00 -03001818 dprintk(1, "%s()\n", __func__);
Steven Tothe47f30b2008-01-10 04:25:59 -03001819 spin_lock_init(&dev->slock);
1820
1821 /* Initialize VBI template */
Ezequiel Garcia3618aca2012-10-23 15:57:20 -03001822 cx23885_vbi_template = cx23885_video_template;
Steven Tothe47f30b2008-01-10 04:25:59 -03001823 strcpy(cx23885_vbi_template.name, "cx23885-vbi");
Steven Tothe47f30b2008-01-10 04:25:59 -03001824
1825 dev->tvnorm = cx23885_video_template.current_norm;
1826
1827 /* init video dma queues */
1828 INIT_LIST_HEAD(&dev->vidq.active);
1829 INIT_LIST_HEAD(&dev->vidq.queued);
1830 dev->vidq.timeout.function = cx23885_vid_timeout;
1831 dev->vidq.timeout.data = (unsigned long)dev;
1832 init_timer(&dev->vidq.timeout);
1833 cx23885_risc_stopper(dev->pci, &dev->vidq.stopper,
1834 VID_A_DMA_CTL, 0x11, 0x00);
1835
Steven Toth79776c82011-10-10 11:09:54 -03001836 /* init vbi dma queues */
1837 INIT_LIST_HEAD(&dev->vbiq.active);
1838 INIT_LIST_HEAD(&dev->vbiq.queued);
1839 dev->vbiq.timeout.function = cx23885_vbi_timeout;
1840 dev->vbiq.timeout.data = (unsigned long)dev;
1841 init_timer(&dev->vbiq.timeout);
1842 cx23885_risc_stopper(dev->pci, &dev->vbiq.stopper,
1843 VID_A_DMA_CTL, 0x22, 0x00);
Andy Wallsdbe83a32010-07-19 01:19:43 -03001844
1845 cx23885_irq_add_enable(dev, 0x01);
Steven Tothe47f30b2008-01-10 04:25:59 -03001846
Igor M. Liplianin557f48d2011-01-25 17:05:00 -03001847 if ((TUNER_ABSENT != dev->tuner_type) &&
1848 ((dev->tuner_bus == 0) || (dev->tuner_bus == 1))) {
Hans Verkuil0d5a19f2009-03-29 06:53:29 -03001849 struct v4l2_subdev *sd = NULL;
1850
1851 if (dev->tuner_addr)
Hans Verkuile6574f22009-04-01 03:57:53 -03001852 sd = v4l2_i2c_new_subdev(&dev->v4l2_dev,
Igor M. Liplianin557f48d2011-01-25 17:05:00 -03001853 &dev->i2c_bus[dev->tuner_bus].i2c_adap,
Laurent Pinchart9a1f8b32010-09-24 10:16:44 -03001854 "tuner", dev->tuner_addr, NULL);
Hans Verkuil0d5a19f2009-03-29 06:53:29 -03001855 else
Hans Verkuil53dacb12009-08-10 02:49:08 -03001856 sd = v4l2_i2c_new_subdev(&dev->v4l2_dev,
Igor M. Liplianin557f48d2011-01-25 17:05:00 -03001857 &dev->i2c_bus[dev->tuner_bus].i2c_adap,
Laurent Pinchart1532a072010-09-24 07:58:29 -03001858 "tuner", 0, v4l2_i2c_tuner_addrs(ADDRS_TV));
Hans Verkuil0d5a19f2009-03-29 06:53:29 -03001859 if (sd) {
1860 struct tuner_setup tun_setup;
1861
David T.L. Wongfd705e72009-10-21 11:08:30 -03001862 memset(&tun_setup, 0, sizeof(tun_setup));
Hans Verkuil0d5a19f2009-03-29 06:53:29 -03001863 tun_setup.mode_mask = T_ANALOG_TV;
1864 tun_setup.type = dev->tuner_type;
1865 tun_setup.addr = v4l2_i2c_subdev_addr(sd);
David T.L. Wong6f0d8c02009-10-21 13:15:30 -03001866 tun_setup.tuner_callback = cx23885_tuner_callback;
Hans Verkuil0d5a19f2009-03-29 06:53:29 -03001867
1868 v4l2_subdev_call(sd, tuner, s_type_addr, &tun_setup);
Kusanagi Kouichi0b32d652010-01-22 04:55:28 -03001869
1870 if (dev->board == CX23885_BOARD_LEADTEK_WINFAST_PXTV1200) {
1871 struct xc2028_ctrl ctrl = {
1872 .fname = XC2028_DEFAULT_FIRMWARE,
1873 .max_len = 64
1874 };
1875 struct v4l2_priv_tun_config cfg = {
1876 .tuner = dev->tuner_type,
1877 .priv = &ctrl
1878 };
1879 v4l2_subdev_call(sd, tuner, s_config, &cfg);
1880 }
Oleh Kravchenkoe8d42372012-12-08 18:20:59 -03001881
1882 if (dev->board == CX23885_BOARD_AVERMEDIA_HC81R) {
1883 struct xc2028_ctrl ctrl = {
1884 .fname = "xc3028L-v36.fw",
1885 .max_len = 64
1886 };
1887 struct v4l2_priv_tun_config cfg = {
1888 .tuner = dev->tuner_type,
1889 .priv = &ctrl
1890 };
1891 v4l2_subdev_call(sd, tuner, s_config, &cfg);
1892 }
Hans Verkuil0d5a19f2009-03-29 06:53:29 -03001893 }
1894 }
1895
Steven Toth79776c82011-10-10 11:09:54 -03001896 /* register Video device */
Steven Tothe47f30b2008-01-10 04:25:59 -03001897 dev->video_dev = cx23885_vdev_init(dev, dev->pci,
1898 &cx23885_video_template, "video");
1899 err = video_register_device(dev->video_dev, VFL_TYPE_GRABBER,
1900 video_nr[dev->nr]);
1901 if (err < 0) {
1902 printk(KERN_INFO "%s: can't register video device\n",
1903 dev->name);
1904 goto fail_unreg;
1905 }
Steven Tothf88fb8e2011-10-10 11:09:54 -03001906 printk(KERN_INFO "%s: registered device %s [v4l2]\n",
Laurent Pinchart38c7c032009-11-27 13:57:15 -03001907 dev->name, video_device_node_name(dev->video_dev));
Mijhail Moreyra97ce5672011-10-10 11:09:53 -03001908
Steven Tothf88fb8e2011-10-10 11:09:54 -03001909 /* register VBI device */
1910 dev->vbi_dev = cx23885_vdev_init(dev, dev->pci,
1911 &cx23885_vbi_template, "vbi");
1912 err = video_register_device(dev->vbi_dev, VFL_TYPE_VBI,
1913 vbi_nr[dev->nr]);
1914 if (err < 0) {
1915 printk(KERN_INFO "%s: can't register vbi device\n",
1916 dev->name);
1917 goto fail_unreg;
1918 }
1919 printk(KERN_INFO "%s: registered device %s\n",
1920 dev->name, video_device_node_name(dev->vbi_dev));
1921
Mijhail Moreyra97ce5672011-10-10 11:09:53 -03001922 /* Register ALSA audio device */
Steven Tothefa762f2011-10-10 11:09:53 -03001923 dev->audio_dev = cx23885_audio_register(dev);
Mijhail Moreyra97ce5672011-10-10 11:09:53 -03001924
Steven Tothe47f30b2008-01-10 04:25:59 -03001925 /* initial device configuration */
1926 mutex_lock(&dev->lock);
1927 cx23885_set_tvnorm(dev, dev->tvnorm);
1928 init_controls(dev);
1929 cx23885_video_mux(dev, 0);
Steven Tothfa1e0fd2011-10-10 11:09:56 -03001930 cx23885_audio_mux(dev, 0);
Steven Tothe47f30b2008-01-10 04:25:59 -03001931 mutex_unlock(&dev->lock);
1932
Steven Tothe47f30b2008-01-10 04:25:59 -03001933 return 0;
1934
1935fail_unreg:
1936 cx23885_video_unregister(dev);
1937 return err;
1938}
1939