blob: 2225d4b94140cb8f9079e751966ef4a3386b31d2 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 *
3 * device driver for Conexant 2388x based TV cards
4 * video4linux video interface
5 *
6 * (c) 2003-04 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23#include <linux/init.h>
24#include <linux/list.h>
25#include <linux/module.h>
26#include <linux/moduleparam.h>
27#include <linux/kmod.h>
28#include <linux/kernel.h>
29#include <linux/slab.h>
30#include <linux/interrupt.h>
31#include <linux/delay.h>
32#include <linux/kthread.h>
33#include <asm/div64.h>
34
35#include "cx88.h"
Michael Krufky5e453dc2006-01-09 15:32:31 -020036#include <media/v4l2-common.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
Mauro Carvalho Chehabcd41e282006-04-09 15:43:41 -030038#ifdef CONFIG_VIDEO_V4L1_COMPAT
Mauro Carvalho Chehab79436632005-11-08 21:37:49 -080039/* Include V4L1 specific functions. Should be removed soon */
40#include <linux/videodev.h>
Mauro Carvalho Chehabcd41e282006-04-09 15:43:41 -030041#endif
Mauro Carvalho Chehab79436632005-11-08 21:37:49 -080042
Linus Torvalds1da177e2005-04-16 15:20:36 -070043MODULE_DESCRIPTION("v4l2 driver module for cx2388x based TV cards");
44MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
45MODULE_LICENSE("GPL");
46
47/* ------------------------------------------------------------------ */
48
49static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
50static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
51static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
52
53module_param_array(video_nr, int, NULL, 0444);
54module_param_array(vbi_nr, int, NULL, 0444);
55module_param_array(radio_nr, int, NULL, 0444);
56
57MODULE_PARM_DESC(video_nr,"video device numbers");
58MODULE_PARM_DESC(vbi_nr,"vbi device numbers");
59MODULE_PARM_DESC(radio_nr,"radio device numbers");
60
61static unsigned int video_debug = 0;
62module_param(video_debug,int,0644);
63MODULE_PARM_DESC(video_debug,"enable debug messages [video]");
64
65static unsigned int irq_debug = 0;
66module_param(irq_debug,int,0644);
67MODULE_PARM_DESC(irq_debug,"enable debug messages [IRQ handler]");
68
69static unsigned int vid_limit = 16;
70module_param(vid_limit,int,0644);
71MODULE_PARM_DESC(vid_limit,"capture memory limit in megabytes");
72
73#define dprintk(level,fmt, arg...) if (video_debug >= level) \
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -070074 printk(KERN_DEBUG "%s/0: " fmt, core->name , ## arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
76/* ------------------------------------------------------------------ */
77
78static LIST_HEAD(cx8800_devlist);
79
80/* ------------------------------------------------------------------- */
81/* static data */
82
83static struct cx88_tvnorm tvnorms[] = {
84 {
85 .name = "NTSC-M",
86 .id = V4L2_STD_NTSC_M,
87 .cxiformat = VideoFormatNTSC,
88 .cxoformat = 0x181f0008,
89 },{
90 .name = "NTSC-JP",
91 .id = V4L2_STD_NTSC_M_JP,
92 .cxiformat = VideoFormatNTSCJapan,
93 .cxoformat = 0x181f0008,
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 },{
95 .name = "PAL-BG",
96 .id = V4L2_STD_PAL_BG,
97 .cxiformat = VideoFormatPAL,
98 .cxoformat = 0x181f0008,
99 },{
100 .name = "PAL-DK",
101 .id = V4L2_STD_PAL_DK,
102 .cxiformat = VideoFormatPAL,
103 .cxoformat = 0x181f0008,
104 },{
105 .name = "PAL-I",
106 .id = V4L2_STD_PAL_I,
107 .cxiformat = VideoFormatPAL,
108 .cxoformat = 0x181f0008,
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -0800109 },{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 .name = "PAL-M",
111 .id = V4L2_STD_PAL_M,
112 .cxiformat = VideoFormatPALM,
113 .cxoformat = 0x1c1f0008,
114 },{
115 .name = "PAL-N",
116 .id = V4L2_STD_PAL_N,
117 .cxiformat = VideoFormatPALN,
118 .cxoformat = 0x1c1f0008,
119 },{
120 .name = "PAL-Nc",
121 .id = V4L2_STD_PAL_Nc,
122 .cxiformat = VideoFormatPALNC,
123 .cxoformat = 0x1c1f0008,
124 },{
125 .name = "PAL-60",
126 .id = V4L2_STD_PAL_60,
127 .cxiformat = VideoFormatPAL60,
128 .cxoformat = 0x181f0008,
129 },{
130 .name = "SECAM-L",
131 .id = V4L2_STD_SECAM_L,
132 .cxiformat = VideoFormatSECAM,
133 .cxoformat = 0x181f0008,
134 },{
135 .name = "SECAM-DK",
136 .id = V4L2_STD_SECAM_DK,
137 .cxiformat = VideoFormatSECAM,
138 .cxoformat = 0x181f0008,
139 }
140};
141
142static struct cx8800_fmt formats[] = {
143 {
144 .name = "8 bpp, gray",
145 .fourcc = V4L2_PIX_FMT_GREY,
146 .cxformat = ColorFormatY8,
147 .depth = 8,
148 .flags = FORMAT_FLAGS_PACKED,
149 },{
150 .name = "15 bpp RGB, le",
151 .fourcc = V4L2_PIX_FMT_RGB555,
152 .cxformat = ColorFormatRGB15,
153 .depth = 16,
154 .flags = FORMAT_FLAGS_PACKED,
155 },{
156 .name = "15 bpp RGB, be",
157 .fourcc = V4L2_PIX_FMT_RGB555X,
158 .cxformat = ColorFormatRGB15 | ColorFormatBSWAP,
159 .depth = 16,
160 .flags = FORMAT_FLAGS_PACKED,
161 },{
162 .name = "16 bpp RGB, le",
163 .fourcc = V4L2_PIX_FMT_RGB565,
164 .cxformat = ColorFormatRGB16,
165 .depth = 16,
166 .flags = FORMAT_FLAGS_PACKED,
167 },{
168 .name = "16 bpp RGB, be",
169 .fourcc = V4L2_PIX_FMT_RGB565X,
170 .cxformat = ColorFormatRGB16 | ColorFormatBSWAP,
171 .depth = 16,
172 .flags = FORMAT_FLAGS_PACKED,
173 },{
174 .name = "24 bpp RGB, le",
175 .fourcc = V4L2_PIX_FMT_BGR24,
176 .cxformat = ColorFormatRGB24,
177 .depth = 24,
178 .flags = FORMAT_FLAGS_PACKED,
179 },{
180 .name = "32 bpp RGB, le",
181 .fourcc = V4L2_PIX_FMT_BGR32,
182 .cxformat = ColorFormatRGB32,
183 .depth = 32,
184 .flags = FORMAT_FLAGS_PACKED,
185 },{
186 .name = "32 bpp RGB, be",
187 .fourcc = V4L2_PIX_FMT_RGB32,
188 .cxformat = ColorFormatRGB32 | ColorFormatBSWAP | ColorFormatWSWAP,
189 .depth = 32,
190 .flags = FORMAT_FLAGS_PACKED,
191 },{
192 .name = "4:2:2, packed, YUYV",
193 .fourcc = V4L2_PIX_FMT_YUYV,
194 .cxformat = ColorFormatYUY2,
195 .depth = 16,
196 .flags = FORMAT_FLAGS_PACKED,
197 },{
198 .name = "4:2:2, packed, UYVY",
199 .fourcc = V4L2_PIX_FMT_UYVY,
200 .cxformat = ColorFormatYUY2 | ColorFormatBSWAP,
201 .depth = 16,
202 .flags = FORMAT_FLAGS_PACKED,
203 },
204};
205
206static struct cx8800_fmt* format_by_fourcc(unsigned int fourcc)
207{
208 unsigned int i;
209
210 for (i = 0; i < ARRAY_SIZE(formats); i++)
211 if (formats[i].fourcc == fourcc)
212 return formats+i;
213 return NULL;
214}
215
216/* ------------------------------------------------------------------- */
217
218static const struct v4l2_queryctrl no_ctl = {
219 .name = "42",
220 .flags = V4L2_CTRL_FLAG_DISABLED,
221};
222
223static struct cx88_ctrl cx8800_ctls[] = {
224 /* --- video --- */
225 {
226 .v = {
227 .id = V4L2_CID_BRIGHTNESS,
228 .name = "Brightness",
229 .minimum = 0x00,
230 .maximum = 0xff,
231 .step = 1,
Marcin Rudowski9f9c9072006-03-12 00:03:47 -0300232 .default_value = 0x7f,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 .type = V4L2_CTRL_TYPE_INTEGER,
234 },
235 .off = 128,
236 .reg = MO_CONTR_BRIGHT,
237 .mask = 0x00ff,
238 .shift = 0,
239 },{
240 .v = {
241 .id = V4L2_CID_CONTRAST,
242 .name = "Contrast",
243 .minimum = 0,
244 .maximum = 0xff,
245 .step = 1,
Mauro Carvalho Chehab70f00042006-01-09 15:25:26 -0200246 .default_value = 0x3f,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 .type = V4L2_CTRL_TYPE_INTEGER,
248 },
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -0700249 .off = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 .reg = MO_CONTR_BRIGHT,
251 .mask = 0xff00,
252 .shift = 8,
253 },{
254 .v = {
255 .id = V4L2_CID_HUE,
256 .name = "Hue",
257 .minimum = 0,
258 .maximum = 0xff,
259 .step = 1,
Marcin Rudowski9f9c9072006-03-12 00:03:47 -0300260 .default_value = 0x7f,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 .type = V4L2_CTRL_TYPE_INTEGER,
262 },
Michael Krufky9ac4c1582005-07-07 17:58:38 -0700263 .off = 128,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 .reg = MO_HUE,
265 .mask = 0x00ff,
266 .shift = 0,
267 },{
268 /* strictly, this only describes only U saturation.
269 * V saturation is handled specially through code.
270 */
271 .v = {
272 .id = V4L2_CID_SATURATION,
273 .name = "Saturation",
274 .minimum = 0,
275 .maximum = 0xff,
276 .step = 1,
Mauro Carvalho Chehab70f00042006-01-09 15:25:26 -0200277 .default_value = 0x7f,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 .type = V4L2_CTRL_TYPE_INTEGER,
279 },
280 .off = 0,
281 .reg = MO_UV_SATURATION,
282 .mask = 0x00ff,
283 .shift = 0,
284 },{
285 /* --- audio --- */
286 .v = {
287 .id = V4L2_CID_AUDIO_MUTE,
288 .name = "Mute",
289 .minimum = 0,
290 .maximum = 1,
Mauro Carvalho Chehab70f00042006-01-09 15:25:26 -0200291 .default_value = 1,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 .type = V4L2_CTRL_TYPE_BOOLEAN,
293 },
294 .reg = AUD_VOL_CTL,
295 .sreg = SHADOW_AUD_VOL_CTL,
296 .mask = (1 << 6),
297 .shift = 6,
298 },{
299 .v = {
300 .id = V4L2_CID_AUDIO_VOLUME,
301 .name = "Volume",
302 .minimum = 0,
303 .maximum = 0x3f,
304 .step = 1,
Marcin Rudowski9f9c9072006-03-12 00:03:47 -0300305 .default_value = 0x3f,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 .type = V4L2_CTRL_TYPE_INTEGER,
307 },
308 .reg = AUD_VOL_CTL,
309 .sreg = SHADOW_AUD_VOL_CTL,
310 .mask = 0x3f,
311 .shift = 0,
312 },{
313 .v = {
314 .id = V4L2_CID_AUDIO_BALANCE,
315 .name = "Balance",
316 .minimum = 0,
317 .maximum = 0x7f,
318 .step = 1,
319 .default_value = 0x40,
320 .type = V4L2_CTRL_TYPE_INTEGER,
321 },
322 .reg = AUD_BAL_CTL,
323 .sreg = SHADOW_AUD_BAL_CTL,
324 .mask = 0x7f,
325 .shift = 0,
326 }
327};
Adrian Bunk408b6642005-05-01 08:59:29 -0700328static const int CX8800_CTLS = ARRAY_SIZE(cx8800_ctls);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329
Michael Krufky38a27132006-06-26 23:42:39 -0300330const u32 cx88_user_ctrls[] = {
331 V4L2_CID_USER_CLASS,
332 V4L2_CID_BRIGHTNESS,
333 V4L2_CID_CONTRAST,
334 V4L2_CID_SATURATION,
335 V4L2_CID_HUE,
336 V4L2_CID_AUDIO_VOLUME,
337 V4L2_CID_AUDIO_BALANCE,
338 V4L2_CID_AUDIO_MUTE,
339 0
340};
341EXPORT_SYMBOL(cx88_user_ctrls);
342
343static const u32 *ctrl_classes[] = {
344 cx88_user_ctrls,
345 NULL
346};
347
348int cx8800_ctrl_query(struct v4l2_queryctrl *qctrl)
349{
350 int i;
351
352 if (qctrl->id < V4L2_CID_BASE ||
353 qctrl->id >= V4L2_CID_LASTP1)
354 return -EINVAL;
355 for (i = 0; i < CX8800_CTLS; i++)
356 if (cx8800_ctls[i].v.id == qctrl->id)
357 break;
358 if (i == CX8800_CTLS) {
359 *qctrl = no_ctl;
360 return 0;
361 }
362 *qctrl = cx8800_ctls[i].v;
363 return 0;
364}
365EXPORT_SYMBOL(cx8800_ctrl_query);
366
367static int cx88_queryctrl(struct v4l2_queryctrl *qctrl)
368{
369 qctrl->id = v4l2_ctrl_next(ctrl_classes, qctrl->id);
370 if (qctrl->id == 0)
371 return -EINVAL;
372 return cx8800_ctrl_query(qctrl);
373}
374
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375/* ------------------------------------------------------------------- */
376/* resource management */
377
378static int res_get(struct cx8800_dev *dev, struct cx8800_fh *fh, unsigned int bit)
379{
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700380 struct cx88_core *core = dev->core;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 if (fh->resources & bit)
382 /* have it already allocated */
383 return 1;
384
385 /* is it free? */
Ingo Molnar3593cab2006-02-07 06:49:14 -0200386 mutex_lock(&core->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 if (dev->resources & bit) {
388 /* no, someone else uses it */
Ingo Molnar3593cab2006-02-07 06:49:14 -0200389 mutex_unlock(&core->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 return 0;
391 }
392 /* it's free, grab it */
393 fh->resources |= bit;
394 dev->resources |= bit;
395 dprintk(1,"res: get %d\n",bit);
Ingo Molnar3593cab2006-02-07 06:49:14 -0200396 mutex_unlock(&core->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 return 1;
398}
399
400static
401int res_check(struct cx8800_fh *fh, unsigned int bit)
402{
403 return (fh->resources & bit);
404}
405
406static
407int res_locked(struct cx8800_dev *dev, unsigned int bit)
408{
409 return (dev->resources & bit);
410}
411
412static
413void res_free(struct cx8800_dev *dev, struct cx8800_fh *fh, unsigned int bits)
414{
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700415 struct cx88_core *core = dev->core;
Eric Sesterhennae246012006-03-13 13:17:11 -0300416 BUG_ON((fh->resources & bits) != bits);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417
Ingo Molnar3593cab2006-02-07 06:49:14 -0200418 mutex_lock(&core->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 fh->resources &= ~bits;
420 dev->resources &= ~bits;
421 dprintk(1,"res: put %d\n",bits);
Ingo Molnar3593cab2006-02-07 06:49:14 -0200422 mutex_unlock(&core->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423}
424
425/* ------------------------------------------------------------------ */
426
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700427/* static int video_mux(struct cx8800_dev *dev, unsigned int input) */
428static int video_mux(struct cx88_core *core, unsigned int input)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429{
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700430 /* struct cx88_core *core = dev->core; */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431
432 dprintk(1,"video_mux: %d [vmux=%d,gpio=0x%x,0x%x,0x%x,0x%x]\n",
433 input, INPUT(input)->vmux,
434 INPUT(input)->gpio0,INPUT(input)->gpio1,
435 INPUT(input)->gpio2,INPUT(input)->gpio3);
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700436 core->input = input;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 cx_andor(MO_INPUT_FORMAT, 0x03 << 14, INPUT(input)->vmux << 14);
438 cx_write(MO_GP3_IO, INPUT(input)->gpio3);
439 cx_write(MO_GP0_IO, INPUT(input)->gpio0);
440 cx_write(MO_GP1_IO, INPUT(input)->gpio1);
441 cx_write(MO_GP2_IO, INPUT(input)->gpio2);
442
443 switch (INPUT(input)->type) {
444 case CX88_VMUX_SVIDEO:
445 cx_set(MO_AFECFG_IO, 0x00000001);
446 cx_set(MO_INPUT_FORMAT, 0x00010010);
447 cx_set(MO_FILTER_EVEN, 0x00002020);
448 cx_set(MO_FILTER_ODD, 0x00002020);
449 break;
450 default:
451 cx_clear(MO_AFECFG_IO, 0x00000001);
452 cx_clear(MO_INPUT_FORMAT, 0x00010010);
453 cx_clear(MO_FILTER_EVEN, 0x00002020);
454 cx_clear(MO_FILTER_ODD, 0x00002020);
455 break;
456 }
457 return 0;
458}
459
460/* ------------------------------------------------------------------ */
461
462static int start_video_dma(struct cx8800_dev *dev,
463 struct cx88_dmaqueue *q,
464 struct cx88_buffer *buf)
465{
466 struct cx88_core *core = dev->core;
467
468 /* setup fifo + format */
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700469 cx88_sram_channel_setup(core, &cx88_sram_channels[SRAM_CH21],
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 buf->bpl, buf->risc.dma);
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700471 cx88_set_scale(core, buf->vb.width, buf->vb.height, buf->vb.field);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 cx_write(MO_COLOR_CTRL, buf->fmt->cxformat | ColorFormatGamma);
473
474 /* reset counter */
475 cx_write(MO_VIDY_GPCNTRL,GP_COUNT_CONTROL_RESET);
476 q->count = 1;
477
478 /* enable irqs */
479 cx_set(MO_PCI_INTMSK, core->pci_irqmask | 0x01);
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700480
481 /* Enables corresponding bits at PCI_INT_STAT:
482 bits 0 to 4: video, audio, transport stream, VIP, Host
483 bit 7: timer
484 bits 8 and 9: DMA complete for: SRC, DST
485 bits 10 and 11: BERR signal asserted for RISC: RD, WR
486 bits 12 to 15: BERR signal asserted for: BRDG, SRC, DST, IPB
487 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 cx_set(MO_VID_INTMSK, 0x0f0011);
489
490 /* enable capture */
491 cx_set(VID_CAPTURE_CONTROL,0x06);
492
493 /* start dma */
494 cx_set(MO_DEV_CNTRL2, (1<<5));
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700495 cx_set(MO_VID_DMACNTRL, 0x11); /* Planar Y and packed FIFO and RISC enable */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496
497 return 0;
498}
499
500static int stop_video_dma(struct cx8800_dev *dev)
501{
502 struct cx88_core *core = dev->core;
503
504 /* stop dma */
505 cx_clear(MO_VID_DMACNTRL, 0x11);
506
507 /* disable capture */
508 cx_clear(VID_CAPTURE_CONTROL,0x06);
509
510 /* disable irqs */
511 cx_clear(MO_PCI_INTMSK, 0x000001);
512 cx_clear(MO_VID_INTMSK, 0x0f0011);
513 return 0;
514}
515
516static int restart_video_queue(struct cx8800_dev *dev,
517 struct cx88_dmaqueue *q)
518{
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700519 struct cx88_core *core = dev->core;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 struct cx88_buffer *buf, *prev;
521 struct list_head *item;
522
523 if (!list_empty(&q->active)) {
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -0800524 buf = list_entry(q->active.next, struct cx88_buffer, vb.queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 dprintk(2,"restart_queue [%p/%d]: restart dma\n",
526 buf, buf->vb.i);
527 start_video_dma(dev, q, buf);
528 list_for_each(item,&q->active) {
529 buf = list_entry(item, struct cx88_buffer, vb.queue);
530 buf->count = q->count++;
531 }
532 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
533 return 0;
534 }
535
536 prev = NULL;
537 for (;;) {
538 if (list_empty(&q->queued))
539 return 0;
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -0800540 buf = list_entry(q->queued.next, struct cx88_buffer, vb.queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 if (NULL == prev) {
Akinobu Mita179e0912006-06-26 00:24:41 -0700542 list_move_tail(&buf->vb.queue, &q->active);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 start_video_dma(dev, q, buf);
544 buf->vb.state = STATE_ACTIVE;
545 buf->count = q->count++;
546 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
547 dprintk(2,"[%p/%d] restart_queue - first active\n",
548 buf,buf->vb.i);
549
550 } else if (prev->vb.width == buf->vb.width &&
551 prev->vb.height == buf->vb.height &&
552 prev->fmt == buf->fmt) {
Akinobu Mita179e0912006-06-26 00:24:41 -0700553 list_move_tail(&buf->vb.queue, &q->active);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 buf->vb.state = STATE_ACTIVE;
555 buf->count = q->count++;
556 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
557 dprintk(2,"[%p/%d] restart_queue - move to active\n",
558 buf,buf->vb.i);
559 } else {
560 return 0;
561 }
562 prev = buf;
563 }
564}
565
566/* ------------------------------------------------------------------ */
567
568static int
569buffer_setup(struct videobuf_queue *q, unsigned int *count, unsigned int *size)
570{
571 struct cx8800_fh *fh = q->priv_data;
572
573 *size = fh->fmt->depth*fh->width*fh->height >> 3;
574 if (0 == *count)
575 *count = 32;
576 while (*size * *count > vid_limit * 1024 * 1024)
577 (*count)--;
578 return 0;
579}
580
581static int
582buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
583 enum v4l2_field field)
584{
585 struct cx8800_fh *fh = q->priv_data;
586 struct cx8800_dev *dev = fh->dev;
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700587 struct cx88_core *core = dev->core;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 struct cx88_buffer *buf = container_of(vb,struct cx88_buffer,vb);
589 int rc, init_buffer = 0;
590
591 BUG_ON(NULL == fh->fmt);
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700592 if (fh->width < 48 || fh->width > norm_maxw(core->tvnorm) ||
593 fh->height < 32 || fh->height > norm_maxh(core->tvnorm))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 return -EINVAL;
595 buf->vb.size = (fh->width * fh->height * fh->fmt->depth) >> 3;
596 if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size)
597 return -EINVAL;
598
599 if (buf->fmt != fh->fmt ||
600 buf->vb.width != fh->width ||
601 buf->vb.height != fh->height ||
602 buf->vb.field != field) {
603 buf->fmt = fh->fmt;
604 buf->vb.width = fh->width;
605 buf->vb.height = fh->height;
606 buf->vb.field = field;
607 init_buffer = 1;
608 }
609
610 if (STATE_NEEDS_INIT == buf->vb.state) {
611 init_buffer = 1;
Mauro Carvalho Chehabc7b0ac02006-03-10 12:29:15 -0300612 if (0 != (rc = videobuf_iolock(q,&buf->vb,NULL)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 goto fail;
614 }
615
616 if (init_buffer) {
617 buf->bpl = buf->vb.width * buf->fmt->depth >> 3;
618 switch (buf->vb.field) {
619 case V4L2_FIELD_TOP:
620 cx88_risc_buffer(dev->pci, &buf->risc,
621 buf->vb.dma.sglist, 0, UNSET,
622 buf->bpl, 0, buf->vb.height);
623 break;
624 case V4L2_FIELD_BOTTOM:
625 cx88_risc_buffer(dev->pci, &buf->risc,
626 buf->vb.dma.sglist, UNSET, 0,
627 buf->bpl, 0, buf->vb.height);
628 break;
629 case V4L2_FIELD_INTERLACED:
630 cx88_risc_buffer(dev->pci, &buf->risc,
631 buf->vb.dma.sglist, 0, buf->bpl,
632 buf->bpl, buf->bpl,
633 buf->vb.height >> 1);
634 break;
635 case V4L2_FIELD_SEQ_TB:
636 cx88_risc_buffer(dev->pci, &buf->risc,
637 buf->vb.dma.sglist,
638 0, buf->bpl * (buf->vb.height >> 1),
639 buf->bpl, 0,
640 buf->vb.height >> 1);
641 break;
642 case V4L2_FIELD_SEQ_BT:
643 cx88_risc_buffer(dev->pci, &buf->risc,
644 buf->vb.dma.sglist,
645 buf->bpl * (buf->vb.height >> 1), 0,
646 buf->bpl, 0,
647 buf->vb.height >> 1);
648 break;
649 default:
650 BUG();
651 }
652 }
653 dprintk(2,"[%p/%d] buffer_prepare - %dx%d %dbpp \"%s\" - dma=0x%08lx\n",
654 buf, buf->vb.i,
655 fh->width, fh->height, fh->fmt->depth, fh->fmt->name,
656 (unsigned long)buf->risc.dma);
657
658 buf->vb.state = STATE_PREPARED;
659 return 0;
660
661 fail:
Mauro Carvalho Chehabc7b0ac02006-03-10 12:29:15 -0300662 cx88_free_buffer(q,buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 return rc;
664}
665
666static void
667buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
668{
669 struct cx88_buffer *buf = container_of(vb,struct cx88_buffer,vb);
670 struct cx88_buffer *prev;
671 struct cx8800_fh *fh = vq->priv_data;
672 struct cx8800_dev *dev = fh->dev;
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700673 struct cx88_core *core = dev->core;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 struct cx88_dmaqueue *q = &dev->vidq;
675
676 /* add jump to stopper */
677 buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC);
678 buf->risc.jmp[1] = cpu_to_le32(q->stopper.dma);
679
680 if (!list_empty(&q->queued)) {
681 list_add_tail(&buf->vb.queue,&q->queued);
682 buf->vb.state = STATE_QUEUED;
683 dprintk(2,"[%p/%d] buffer_queue - append to queued\n",
684 buf, buf->vb.i);
685
686 } else if (list_empty(&q->active)) {
687 list_add_tail(&buf->vb.queue,&q->active);
688 start_video_dma(dev, q, buf);
689 buf->vb.state = STATE_ACTIVE;
690 buf->count = q->count++;
691 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
692 dprintk(2,"[%p/%d] buffer_queue - first active\n",
693 buf, buf->vb.i);
694
695 } else {
696 prev = list_entry(q->active.prev, struct cx88_buffer, vb.queue);
697 if (prev->vb.width == buf->vb.width &&
698 prev->vb.height == buf->vb.height &&
699 prev->fmt == buf->fmt) {
700 list_add_tail(&buf->vb.queue,&q->active);
701 buf->vb.state = STATE_ACTIVE;
702 buf->count = q->count++;
703 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
704 dprintk(2,"[%p/%d] buffer_queue - append to active\n",
705 buf, buf->vb.i);
706
707 } else {
708 list_add_tail(&buf->vb.queue,&q->queued);
709 buf->vb.state = STATE_QUEUED;
710 dprintk(2,"[%p/%d] buffer_queue - first queued\n",
711 buf, buf->vb.i);
712 }
713 }
714}
715
716static void buffer_release(struct videobuf_queue *q, struct videobuf_buffer *vb)
717{
718 struct cx88_buffer *buf = container_of(vb,struct cx88_buffer,vb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719
Mauro Carvalho Chehabc7b0ac02006-03-10 12:29:15 -0300720 cx88_free_buffer(q,buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721}
722
Adrian Bunk408b6642005-05-01 08:59:29 -0700723static struct videobuf_queue_ops cx8800_video_qops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724 .buf_setup = buffer_setup,
725 .buf_prepare = buffer_prepare,
726 .buf_queue = buffer_queue,
727 .buf_release = buffer_release,
728};
729
730/* ------------------------------------------------------------------ */
731
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732
733/* ------------------------------------------------------------------ */
734
735static struct videobuf_queue* get_queue(struct cx8800_fh *fh)
736{
737 switch (fh->type) {
738 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
739 return &fh->vidq;
740 case V4L2_BUF_TYPE_VBI_CAPTURE:
741 return &fh->vbiq;
742 default:
743 BUG();
744 return NULL;
745 }
746}
747
748static int get_ressource(struct cx8800_fh *fh)
749{
750 switch (fh->type) {
751 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
752 return RESOURCE_VIDEO;
753 case V4L2_BUF_TYPE_VBI_CAPTURE:
754 return RESOURCE_VBI;
755 default:
756 BUG();
757 return 0;
758 }
759}
760
761static int video_open(struct inode *inode, struct file *file)
762{
763 int minor = iminor(inode);
764 struct cx8800_dev *h,*dev = NULL;
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700765 struct cx88_core *core;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766 struct cx8800_fh *fh;
767 struct list_head *list;
768 enum v4l2_buf_type type = 0;
769 int radio = 0;
770
771 list_for_each(list,&cx8800_devlist) {
772 h = list_entry(list, struct cx8800_dev, devlist);
773 if (h->video_dev->minor == minor) {
774 dev = h;
775 type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
776 }
777 if (h->vbi_dev->minor == minor) {
778 dev = h;
779 type = V4L2_BUF_TYPE_VBI_CAPTURE;
780 }
781 if (h->radio_dev &&
782 h->radio_dev->minor == minor) {
783 radio = 1;
784 dev = h;
785 }
786 }
787 if (NULL == dev)
788 return -ENODEV;
789
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700790 core = dev->core;
791
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 dprintk(1,"open minor=%d radio=%d type=%s\n",
793 minor,radio,v4l2_type_names[type]);
794
795 /* allocate + initialize per filehandle data */
Panagiotis Issaris74081872006-01-11 19:40:56 -0200796 fh = kzalloc(sizeof(*fh),GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797 if (NULL == fh)
798 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 file->private_data = fh;
800 fh->dev = dev;
801 fh->radio = radio;
802 fh->type = type;
803 fh->width = 320;
804 fh->height = 240;
805 fh->fmt = format_by_fourcc(V4L2_PIX_FMT_BGR24);
806
807 videobuf_queue_init(&fh->vidq, &cx8800_video_qops,
808 dev->pci, &dev->slock,
809 V4L2_BUF_TYPE_VIDEO_CAPTURE,
810 V4L2_FIELD_INTERLACED,
811 sizeof(struct cx88_buffer),
812 fh);
813 videobuf_queue_init(&fh->vbiq, &cx8800_vbi_qops,
814 dev->pci, &dev->slock,
815 V4L2_BUF_TYPE_VBI_CAPTURE,
816 V4L2_FIELD_SEQ_TB,
817 sizeof(struct cx88_buffer),
818 fh);
819
820 if (fh->radio) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 int board = core->board;
822 dprintk(1,"video_open: setting radio device\n");
Mauro Carvalho Chehabfd3113e2005-07-31 22:34:43 -0700823 cx_write(MO_GP3_IO, cx88_boards[board].radio.gpio3);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 cx_write(MO_GP0_IO, cx88_boards[board].radio.gpio0);
825 cx_write(MO_GP1_IO, cx88_boards[board].radio.gpio1);
826 cx_write(MO_GP2_IO, cx88_boards[board].radio.gpio2);
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700827 core->tvaudio = WW_FM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 cx88_set_tvaudio(core);
829 cx88_set_stereo(core,V4L2_TUNER_MODE_STEREO,1);
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700830 cx88_call_i2c_clients(core,AUDC_SET_RADIO,NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831 }
832
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -0800833 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834}
835
836static ssize_t
Peter Hagervallf9e7a022005-11-08 21:36:29 -0800837video_read(struct file *file, char __user *data, size_t count, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838{
839 struct cx8800_fh *fh = file->private_data;
840
841 switch (fh->type) {
842 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
843 if (res_locked(fh->dev,RESOURCE_VIDEO))
844 return -EBUSY;
845 return videobuf_read_one(&fh->vidq, data, count, ppos,
846 file->f_flags & O_NONBLOCK);
847 case V4L2_BUF_TYPE_VBI_CAPTURE:
848 if (!res_get(fh->dev,fh,RESOURCE_VBI))
849 return -EBUSY;
850 return videobuf_read_stream(&fh->vbiq, data, count, ppos, 1,
851 file->f_flags & O_NONBLOCK);
852 default:
853 BUG();
854 return 0;
855 }
856}
857
858static unsigned int
859video_poll(struct file *file, struct poll_table_struct *wait)
860{
861 struct cx8800_fh *fh = file->private_data;
862 struct cx88_buffer *buf;
863
864 if (V4L2_BUF_TYPE_VBI_CAPTURE == fh->type) {
865 if (!res_get(fh->dev,fh,RESOURCE_VBI))
866 return POLLERR;
867 return videobuf_poll_stream(file, &fh->vbiq, wait);
868 }
869
870 if (res_check(fh,RESOURCE_VIDEO)) {
871 /* streaming capture */
872 if (list_empty(&fh->vidq.stream))
873 return POLLERR;
874 buf = list_entry(fh->vidq.stream.next,struct cx88_buffer,vb.stream);
875 } else {
876 /* read() capture */
877 buf = (struct cx88_buffer*)fh->vidq.read_buf;
878 if (NULL == buf)
879 return POLLERR;
880 }
881 poll_wait(file, &buf->vb.done, wait);
882 if (buf->vb.state == STATE_DONE ||
883 buf->vb.state == STATE_ERROR)
884 return POLLIN|POLLRDNORM;
885 return 0;
886}
887
888static int video_release(struct inode *inode, struct file *file)
889{
890 struct cx8800_fh *fh = file->private_data;
891 struct cx8800_dev *dev = fh->dev;
892
893 /* turn off overlay */
894 if (res_check(fh, RESOURCE_OVERLAY)) {
895 /* FIXME */
896 res_free(dev,fh,RESOURCE_OVERLAY);
897 }
898
899 /* stop video capture */
900 if (res_check(fh, RESOURCE_VIDEO)) {
901 videobuf_queue_cancel(&fh->vidq);
902 res_free(dev,fh,RESOURCE_VIDEO);
903 }
904 if (fh->vidq.read_buf) {
905 buffer_release(&fh->vidq,fh->vidq.read_buf);
906 kfree(fh->vidq.read_buf);
907 }
908
909 /* stop vbi capture */
910 if (res_check(fh, RESOURCE_VBI)) {
911 if (fh->vbiq.streaming)
912 videobuf_streamoff(&fh->vbiq);
913 if (fh->vbiq.reading)
914 videobuf_read_stop(&fh->vbiq);
915 res_free(dev,fh,RESOURCE_VBI);
916 }
917
918 videobuf_mmap_free(&fh->vidq);
919 videobuf_mmap_free(&fh->vbiq);
920 file->private_data = NULL;
921 kfree(fh);
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700922
923 cx88_call_i2c_clients (dev->core, TUNER_SET_STANDBY, NULL);
924
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925 return 0;
926}
927
928static int
929video_mmap(struct file *file, struct vm_area_struct * vma)
930{
931 struct cx8800_fh *fh = file->private_data;
932
933 return videobuf_mmap_mapper(get_queue(fh), vma);
934}
935
936/* ------------------------------------------------------------------ */
937
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700938/* static int get_control(struct cx8800_dev *dev, struct v4l2_control *ctl) */
939static int get_control(struct cx88_core *core, struct v4l2_control *ctl)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940{
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700941 /* struct cx88_core *core = dev->core; */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942 struct cx88_ctrl *c = NULL;
943 u32 value;
944 int i;
945
946 for (i = 0; i < CX8800_CTLS; i++)
947 if (cx8800_ctls[i].v.id == ctl->id)
948 c = &cx8800_ctls[i];
949 if (NULL == c)
950 return -EINVAL;
951
952 value = c->sreg ? cx_sread(c->sreg) : cx_read(c->reg);
953 switch (ctl->id) {
954 case V4L2_CID_AUDIO_BALANCE:
Marcin Rudowski9f9c9072006-03-12 00:03:47 -0300955 ctl->value = ((value & 0x7f) < 0x40) ? ((value & 0x7f) + 0x40)
956 : (0x7f - (value & 0x7f));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957 break;
958 case V4L2_CID_AUDIO_VOLUME:
959 ctl->value = 0x3f - (value & 0x3f);
960 break;
961 default:
962 ctl->value = ((value + (c->off << c->shift)) & c->mask) >> c->shift;
963 break;
964 }
Ian Pickworth6457af52006-02-27 00:09:45 -0300965 dprintk(1,"get_control id=0x%X(%s) ctrl=0x%02x, reg=0x%02x val=0x%02x (mask 0x%02x)%s\n",
966 ctl->id, c->v.name, ctl->value, c->reg,
967 value,c->mask, c->sreg ? " [shadowed]" : "");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968 return 0;
969}
970
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700971/* static int set_control(struct cx8800_dev *dev, struct v4l2_control *ctl) */
972static int set_control(struct cx88_core *core, struct v4l2_control *ctl)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973{
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700974 /* struct cx88_core *core = dev->core; */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 struct cx88_ctrl *c = NULL;
Mauro Carvalho Chehab70f00042006-01-09 15:25:26 -0200976 u32 value,mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977 int i;
Mauro Carvalho Chehab70f00042006-01-09 15:25:26 -0200978 for (i = 0; i < CX8800_CTLS; i++) {
979 if (cx8800_ctls[i].v.id == ctl->id) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980 c = &cx8800_ctls[i];
Mauro Carvalho Chehab70f00042006-01-09 15:25:26 -0200981 }
982 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983 if (NULL == c)
984 return -EINVAL;
985
986 if (ctl->value < c->v.minimum)
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700987 ctl->value = c->v.minimum;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988 if (ctl->value > c->v.maximum)
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700989 ctl->value = c->v.maximum;
Mauro Carvalho Chehab70f00042006-01-09 15:25:26 -0200990 mask=c->mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991 switch (ctl->id) {
992 case V4L2_CID_AUDIO_BALANCE:
Marcin Rudowski9f9c9072006-03-12 00:03:47 -0300993 value = (ctl->value < 0x40) ? (0x7f - ctl->value) : (ctl->value - 0x40);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994 break;
995 case V4L2_CID_AUDIO_VOLUME:
996 value = 0x3f - (ctl->value & 0x3f);
997 break;
998 case V4L2_CID_SATURATION:
999 /* special v_sat handling */
Mauro Carvalho Chehab70f00042006-01-09 15:25:26 -02001000
1001 value = ((ctl->value - c->off) << c->shift) & c->mask;
1002
1003 if (core->tvnorm->id & V4L2_STD_SECAM) {
1004 /* For SECAM, both U and V sat should be equal */
1005 value=value<<8|value;
1006 } else {
1007 /* Keeps U Saturation proportional to V Sat */
1008 value=(value*0x5a)/0x7f<<8|value;
1009 }
1010 mask=0xffff;
1011 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012 default:
1013 value = ((ctl->value - c->off) << c->shift) & c->mask;
1014 break;
1015 }
Ian Pickworth6457af52006-02-27 00:09:45 -03001016 dprintk(1,"set_control id=0x%X(%s) ctrl=0x%02x, reg=0x%02x val=0x%02x (mask 0x%02x)%s\n",
1017 ctl->id, c->v.name, ctl->value, c->reg, value,
1018 mask, c->sreg ? " [shadowed]" : "");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019 if (c->sreg) {
Mauro Carvalho Chehab70f00042006-01-09 15:25:26 -02001020 cx_sandor(c->sreg, c->reg, mask, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021 } else {
Mauro Carvalho Chehab70f00042006-01-09 15:25:26 -02001022 cx_andor(c->reg, mask, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 }
1024 return 0;
1025}
1026
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001027static void init_controls(struct cx88_core *core)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028{
Mauro Carvalho Chehab70f00042006-01-09 15:25:26 -02001029 struct v4l2_control ctrl;
1030 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031
Mauro Carvalho Chehab70f00042006-01-09 15:25:26 -02001032 for (i = 0; i < CX8800_CTLS; i++) {
1033 ctrl.id=cx8800_ctls[i].v.id;
Marcin Rudowski9f9c9072006-03-12 00:03:47 -03001034 ctrl.value=cx8800_ctls[i].v.default_value;
Mauro Carvalho Chehab70f00042006-01-09 15:25:26 -02001035 set_control(core, &ctrl);
1036 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037}
1038
1039/* ------------------------------------------------------------------ */
1040
1041static int cx8800_g_fmt(struct cx8800_dev *dev, struct cx8800_fh *fh,
1042 struct v4l2_format *f)
1043{
1044 switch (f->type) {
1045 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
1046 memset(&f->fmt.pix,0,sizeof(f->fmt.pix));
1047 f->fmt.pix.width = fh->width;
1048 f->fmt.pix.height = fh->height;
1049 f->fmt.pix.field = fh->vidq.field;
1050 f->fmt.pix.pixelformat = fh->fmt->fourcc;
1051 f->fmt.pix.bytesperline =
1052 (f->fmt.pix.width * fh->fmt->depth) >> 3;
1053 f->fmt.pix.sizeimage =
1054 f->fmt.pix.height * f->fmt.pix.bytesperline;
1055 return 0;
1056 case V4L2_BUF_TYPE_VBI_CAPTURE:
1057 cx8800_vbi_fmt(dev, f);
1058 return 0;
1059 default:
1060 return -EINVAL;
1061 }
1062}
1063
1064static int cx8800_try_fmt(struct cx8800_dev *dev, struct cx8800_fh *fh,
1065 struct v4l2_format *f)
1066{
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001067 struct cx88_core *core = dev->core;
1068
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069 switch (f->type) {
1070 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
1071 {
1072 struct cx8800_fmt *fmt;
1073 enum v4l2_field field;
1074 unsigned int maxw, maxh;
1075
1076 fmt = format_by_fourcc(f->fmt.pix.pixelformat);
1077 if (NULL == fmt)
1078 return -EINVAL;
1079
1080 field = f->fmt.pix.field;
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001081 maxw = norm_maxw(core->tvnorm);
1082 maxh = norm_maxh(core->tvnorm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083
1084 if (V4L2_FIELD_ANY == field) {
1085 field = (f->fmt.pix.height > maxh/2)
1086 ? V4L2_FIELD_INTERLACED
1087 : V4L2_FIELD_BOTTOM;
1088 }
1089
1090 switch (field) {
1091 case V4L2_FIELD_TOP:
1092 case V4L2_FIELD_BOTTOM:
1093 maxh = maxh / 2;
1094 break;
1095 case V4L2_FIELD_INTERLACED:
1096 break;
1097 default:
1098 return -EINVAL;
1099 }
1100
1101 f->fmt.pix.field = field;
1102 if (f->fmt.pix.height < 32)
1103 f->fmt.pix.height = 32;
1104 if (f->fmt.pix.height > maxh)
1105 f->fmt.pix.height = maxh;
1106 if (f->fmt.pix.width < 48)
1107 f->fmt.pix.width = 48;
1108 if (f->fmt.pix.width > maxw)
1109 f->fmt.pix.width = maxw;
1110 f->fmt.pix.width &= ~0x03;
1111 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 case V4L2_BUF_TYPE_VBI_CAPTURE:
1119 cx8800_vbi_fmt(dev, f);
1120 return 0;
1121 default:
1122 return -EINVAL;
1123 }
1124}
1125
1126static int cx8800_s_fmt(struct cx8800_dev *dev, struct cx8800_fh *fh,
1127 struct v4l2_format *f)
1128{
1129 int err;
1130
1131 switch (f->type) {
1132 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
1133 err = cx8800_try_fmt(dev,fh,f);
1134 if (0 != err)
1135 return err;
1136
1137 fh->fmt = format_by_fourcc(f->fmt.pix.pixelformat);
1138 fh->width = f->fmt.pix.width;
1139 fh->height = f->fmt.pix.height;
1140 fh->vidq.field = f->fmt.pix.field;
1141 return 0;
1142 case V4L2_BUF_TYPE_VBI_CAPTURE:
1143 cx8800_vbi_fmt(dev, f);
1144 return 0;
1145 default:
1146 return -EINVAL;
1147 }
1148}
1149
1150/*
1151 * This function is _not_ called directly, but from
1152 * video_generic_ioctl (and maybe others). userspace
1153 * copying is done already, arg is a kernel pointer.
1154 */
1155static int video_do_ioctl(struct inode *inode, struct file *file,
1156 unsigned int cmd, void *arg)
1157{
1158 struct cx8800_fh *fh = file->private_data;
1159 struct cx8800_dev *dev = fh->dev;
1160 struct cx88_core *core = dev->core;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161 int err;
1162
1163 if (video_debug > 1)
Michael Krufky5e453dc2006-01-09 15:32:31 -02001164 v4l_print_ioctl(core->name,cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165 switch (cmd) {
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001166
1167 /* --- capabilities ------------------------------------------ */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168 case VIDIOC_QUERYCAP:
1169 {
1170 struct v4l2_capability *cap = arg;
1171
1172 memset(cap,0,sizeof(*cap));
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001173 strcpy(cap->driver, "cx8800");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174 strlcpy(cap->card, cx88_boards[core->board].name,
1175 sizeof(cap->card));
1176 sprintf(cap->bus_info,"PCI:%s",pci_name(dev->pci));
1177 cap->version = CX88_VERSION_CODE;
1178 cap->capabilities =
1179 V4L2_CAP_VIDEO_CAPTURE |
1180 V4L2_CAP_READWRITE |
1181 V4L2_CAP_STREAMING |
1182 V4L2_CAP_VBI_CAPTURE |
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001183 V4L2_CAP_VIDEO_OVERLAY |
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184 0;
1185 if (UNSET != core->tuner_type)
1186 cap->capabilities |= V4L2_CAP_TUNER;
1187 return 0;
1188 }
1189
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190 /* --- capture ioctls ---------------------------------------- */
1191 case VIDIOC_ENUM_FMT:
1192 {
1193 struct v4l2_fmtdesc *f = arg;
1194 enum v4l2_buf_type type;
1195 unsigned int index;
1196
1197 index = f->index;
1198 type = f->type;
1199 switch (type) {
1200 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
1201 if (index >= ARRAY_SIZE(formats))
1202 return -EINVAL;
1203 memset(f,0,sizeof(*f));
1204 f->index = index;
1205 f->type = type;
1206 strlcpy(f->description,formats[index].name,sizeof(f->description));
1207 f->pixelformat = formats[index].fourcc;
1208 break;
1209 default:
1210 return -EINVAL;
1211 }
1212 return 0;
1213 }
1214 case VIDIOC_G_FMT:
1215 {
1216 struct v4l2_format *f = arg;
1217 return cx8800_g_fmt(dev,fh,f);
1218 }
1219 case VIDIOC_S_FMT:
1220 {
1221 struct v4l2_format *f = arg;
1222 return cx8800_s_fmt(dev,fh,f);
1223 }
1224 case VIDIOC_TRY_FMT:
1225 {
1226 struct v4l2_format *f = arg;
1227 return cx8800_try_fmt(dev,fh,f);
1228 }
Mauro Carvalho Chehab79436632005-11-08 21:37:49 -08001229#ifdef HAVE_V4L1
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001230 /* --- streaming capture ------------------------------------- */
1231 case VIDIOCGMBUF:
1232 {
1233 struct video_mbuf *mbuf = arg;
1234 struct videobuf_queue *q;
1235 struct v4l2_requestbuffers req;
1236 unsigned int i;
1237
1238 q = get_queue(fh);
1239 memset(&req,0,sizeof(req));
1240 req.type = q->type;
1241 req.count = 8;
1242 req.memory = V4L2_MEMORY_MMAP;
1243 err = videobuf_reqbufs(q,&req);
1244 if (err < 0)
1245 return err;
1246 memset(mbuf,0,sizeof(*mbuf));
1247 mbuf->frames = req.count;
1248 mbuf->size = 0;
1249 for (i = 0; i < mbuf->frames; i++) {
1250 mbuf->offsets[i] = q->bufs[i]->boff;
1251 mbuf->size += q->bufs[i]->bsize;
1252 }
1253 return 0;
1254 }
Mauro Carvalho Chehab79436632005-11-08 21:37:49 -08001255#endif
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001256 case VIDIOC_REQBUFS:
1257 return videobuf_reqbufs(get_queue(fh), arg);
1258
1259 case VIDIOC_QUERYBUF:
1260 return videobuf_querybuf(get_queue(fh), arg);
1261
1262 case VIDIOC_QBUF:
1263 return videobuf_qbuf(get_queue(fh), arg);
1264
1265 case VIDIOC_DQBUF:
1266 return videobuf_dqbuf(get_queue(fh), arg,
1267 file->f_flags & O_NONBLOCK);
1268
1269 case VIDIOC_STREAMON:
1270 {
1271 int res = get_ressource(fh);
1272
1273 if (!res_get(dev,fh,res))
1274 return -EBUSY;
1275 return videobuf_streamon(get_queue(fh));
1276 }
1277 case VIDIOC_STREAMOFF:
1278 {
1279 int res = get_ressource(fh);
1280
1281 err = videobuf_streamoff(get_queue(fh));
1282 if (err < 0)
1283 return err;
1284 res_free(dev,fh,res);
1285 return 0;
1286 }
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001287 default:
1288 return cx88_do_ioctl( inode, file, fh->radio, core, cmd, arg, video_do_ioctl );
1289 }
1290 return 0;
1291}
1292
1293int cx88_do_ioctl(struct inode *inode, struct file *file, int radio,
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -08001294 struct cx88_core *core, unsigned int cmd, void *arg, v4l2_kioctl driver_ioctl)
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001295{
1296 int err;
1297
Mauro Carvalho Chehabc7b0ac02006-03-10 12:29:15 -03001298 if (video_debug) {
1299 if (video_debug > 1) {
1300 if (_IOC_DIR(cmd) & _IOC_WRITE)
1301 v4l_printk_ioctl_arg("cx88(w)",cmd, arg);
1302 else if (!_IOC_DIR(cmd) & _IOC_READ) {
1303 v4l_print_ioctl("cx88", cmd);
1304 }
1305 } else
1306 v4l_print_ioctl(core->name,cmd);
1307
1308 }
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001309
1310 switch (cmd) {
1311 /* ---------- tv norms ---------- */
1312 case VIDIOC_ENUMSTD:
1313 {
1314 struct v4l2_standard *e = arg;
1315 unsigned int i;
1316
1317 i = e->index;
1318 if (i >= ARRAY_SIZE(tvnorms))
1319 return -EINVAL;
1320 err = v4l2_video_std_construct(e, tvnorms[e->index].id,
1321 tvnorms[e->index].name);
1322 e->index = i;
1323 if (err < 0)
1324 return err;
1325 return 0;
1326 }
1327 case VIDIOC_G_STD:
1328 {
1329 v4l2_std_id *id = arg;
1330
1331 *id = core->tvnorm->id;
1332 return 0;
1333 }
1334 case VIDIOC_S_STD:
1335 {
1336 v4l2_std_id *id = arg;
1337 unsigned int i;
1338
1339 for(i = 0; i < ARRAY_SIZE(tvnorms); i++)
1340 if (*id & tvnorms[i].id)
1341 break;
1342 if (i == ARRAY_SIZE(tvnorms))
1343 return -EINVAL;
1344
Ingo Molnar3593cab2006-02-07 06:49:14 -02001345 mutex_lock(&core->lock);
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001346 cx88_set_tvnorm(core,&tvnorms[i]);
Ingo Molnar3593cab2006-02-07 06:49:14 -02001347 mutex_unlock(&core->lock);
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001348 return 0;
1349 }
1350
1351 /* ------ input switching ---------- */
1352 case VIDIOC_ENUMINPUT:
1353 {
1354 static const char *iname[] = {
1355 [ CX88_VMUX_COMPOSITE1 ] = "Composite1",
1356 [ CX88_VMUX_COMPOSITE2 ] = "Composite2",
1357 [ CX88_VMUX_COMPOSITE3 ] = "Composite3",
1358 [ CX88_VMUX_COMPOSITE4 ] = "Composite4",
1359 [ CX88_VMUX_SVIDEO ] = "S-Video",
1360 [ CX88_VMUX_TELEVISION ] = "Television",
1361 [ CX88_VMUX_CABLE ] = "Cable TV",
1362 [ CX88_VMUX_DVB ] = "DVB",
1363 [ CX88_VMUX_DEBUG ] = "for debug only",
1364 };
1365 struct v4l2_input *i = arg;
1366 unsigned int n;
1367
1368 n = i->index;
1369 if (n >= 4)
1370 return -EINVAL;
1371 if (0 == INPUT(n)->type)
1372 return -EINVAL;
1373 memset(i,0,sizeof(*i));
1374 i->index = n;
1375 i->type = V4L2_INPUT_TYPE_CAMERA;
1376 strcpy(i->name,iname[INPUT(n)->type]);
1377 if ((CX88_VMUX_TELEVISION == INPUT(n)->type) ||
1378 (CX88_VMUX_CABLE == INPUT(n)->type))
1379 i->type = V4L2_INPUT_TYPE_TUNER;
1380 for (n = 0; n < ARRAY_SIZE(tvnorms); n++)
1381 i->std |= tvnorms[n].id;
1382 return 0;
1383 }
1384 case VIDIOC_G_INPUT:
1385 {
1386 unsigned int *i = arg;
1387
1388 *i = core->input;
1389 return 0;
1390 }
1391 case VIDIOC_S_INPUT:
1392 {
1393 unsigned int *i = arg;
1394
1395 if (*i >= 4)
1396 return -EINVAL;
Ingo Molnar3593cab2006-02-07 06:49:14 -02001397 mutex_lock(&core->lock);
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001398 cx88_newstation(core);
1399 video_mux(core,*i);
Ingo Molnar3593cab2006-02-07 06:49:14 -02001400 mutex_unlock(&core->lock);
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001401 return 0;
1402 }
1403
1404
1405
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406 /* --- controls ---------------------------------------------- */
1407 case VIDIOC_QUERYCTRL:
1408 {
1409 struct v4l2_queryctrl *c = arg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410
Michael Krufky38a27132006-06-26 23:42:39 -03001411 return cx88_queryctrl(c);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412 }
1413 case VIDIOC_G_CTRL:
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001414 return get_control(core,arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415 case VIDIOC_S_CTRL:
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001416 return set_control(core,arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417
1418 /* --- tuner ioctls ------------------------------------------ */
1419 case VIDIOC_G_TUNER:
1420 {
1421 struct v4l2_tuner *t = arg;
1422 u32 reg;
1423
1424 if (UNSET == core->tuner_type)
1425 return -EINVAL;
1426 if (0 != t->index)
1427 return -EINVAL;
1428
1429 memset(t,0,sizeof(*t));
1430 strcpy(t->name, "Television");
1431 t->type = V4L2_TUNER_ANALOG_TV;
1432 t->capability = V4L2_TUNER_CAP_NORM;
1433 t->rangehigh = 0xffffffffUL;
1434
1435 cx88_get_stereo(core ,t);
1436 reg = cx_read(MO_DEVICE_STATUS);
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -08001437 t->signal = (reg & (1<<5)) ? 0xffff : 0x0000;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438 return 0;
1439 }
1440 case VIDIOC_S_TUNER:
1441 {
1442 struct v4l2_tuner *t = arg;
1443
1444 if (UNSET == core->tuner_type)
1445 return -EINVAL;
1446 if (0 != t->index)
1447 return -EINVAL;
1448 cx88_set_stereo(core, t->audmode, 1);
1449 return 0;
1450 }
1451 case VIDIOC_G_FREQUENCY:
1452 {
1453 struct v4l2_frequency *f = arg;
1454
Mauro Carvalho Chehaba82decf2005-07-07 17:58:36 -07001455 memset(f,0,sizeof(*f));
1456
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457 if (UNSET == core->tuner_type)
1458 return -EINVAL;
Mauro Carvalho Chehaba82decf2005-07-07 17:58:36 -07001459
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001460 /* f->type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; */
1461 f->type = radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
1462 f->frequency = core->freq;
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -07001463
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001464 cx88_call_i2c_clients(core,VIDIOC_G_FREQUENCY,f);
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -07001465
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466 return 0;
1467 }
1468 case VIDIOC_S_FREQUENCY:
1469 {
1470 struct v4l2_frequency *f = arg;
1471
1472 if (UNSET == core->tuner_type)
1473 return -EINVAL;
1474 if (f->tuner != 0)
1475 return -EINVAL;
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001476 if (0 == radio && f->type != V4L2_TUNER_ANALOG_TV)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477 return -EINVAL;
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001478 if (1 == radio && f->type != V4L2_TUNER_RADIO)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479 return -EINVAL;
Ingo Molnar3593cab2006-02-07 06:49:14 -02001480 mutex_lock(&core->lock);
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001481 core->freq = f->frequency;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482 cx88_newstation(core);
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001483 cx88_call_i2c_clients(core,VIDIOC_S_FREQUENCY,f);
Mauro Carvalho Chehabc5287ba2005-07-15 03:56:28 -07001484
1485 /* When changing channels it is required to reset TVAUDIO */
1486 msleep (10);
1487 cx88_set_tvaudio(core);
1488
Ingo Molnar3593cab2006-02-07 06:49:14 -02001489 mutex_unlock(&core->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490 return 0;
1491 }
1492
1493 default:
1494 return v4l_compat_translate_ioctl(inode,file,cmd,arg,
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001495 driver_ioctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496 }
1497 return 0;
1498}
1499
1500static int video_ioctl(struct inode *inode, struct file *file,
1501 unsigned int cmd, unsigned long arg)
1502{
Mauro Carvalho Chehabc7b0ac02006-03-10 12:29:15 -03001503 int retval;
1504
1505 retval=video_usercopy(inode, file, cmd, arg, video_do_ioctl);
1506
1507 if (video_debug > 1) {
1508 if (retval < 0) {
1509 v4l_print_ioctl("cx88(err)", cmd);
1510 printk(KERN_DEBUG "cx88(err): errcode=%d\n",retval);
1511 } else if (_IOC_DIR(cmd) & _IOC_READ)
1512 v4l_printk_ioctl_arg("cx88(r)",cmd, (void *)arg);
1513 }
1514
1515 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516}
1517
1518/* ----------------------------------------------------------- */
1519
1520static int radio_do_ioctl(struct inode *inode, struct file *file,
1521 unsigned int cmd, void *arg)
1522{
1523 struct cx8800_fh *fh = file->private_data;
1524 struct cx8800_dev *dev = fh->dev;
1525 struct cx88_core *core = dev->core;
1526
1527 if (video_debug > 1)
Michael Krufky5e453dc2006-01-09 15:32:31 -02001528 v4l_print_ioctl(core->name,cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529
1530 switch (cmd) {
1531 case VIDIOC_QUERYCAP:
1532 {
1533 struct v4l2_capability *cap = arg;
1534
1535 memset(cap,0,sizeof(*cap));
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -08001536 strcpy(cap->driver, "cx8800");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537 strlcpy(cap->card, cx88_boards[core->board].name,
1538 sizeof(cap->card));
1539 sprintf(cap->bus_info,"PCI:%s", pci_name(dev->pci));
1540 cap->version = CX88_VERSION_CODE;
Mauro Carvalho Chehaba82decf2005-07-07 17:58:36 -07001541 cap->capabilities = V4L2_CAP_TUNER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542 return 0;
1543 }
1544 case VIDIOC_G_TUNER:
1545 {
1546 struct v4l2_tuner *t = arg;
1547
1548 if (t->index > 0)
1549 return -EINVAL;
1550
1551 memset(t,0,sizeof(*t));
1552 strcpy(t->name, "Radio");
Elad Lahav48c42592005-11-08 21:37:59 -08001553 t->type = V4L2_TUNER_RADIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001555 cx88_call_i2c_clients(core,VIDIOC_G_TUNER,t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556 return 0;
1557 }
1558 case VIDIOC_ENUMINPUT:
1559 {
1560 struct v4l2_input *i = arg;
1561
1562 if (i->index != 0)
1563 return -EINVAL;
1564 strcpy(i->name,"Radio");
1565 i->type = V4L2_INPUT_TYPE_TUNER;
1566 return 0;
1567 }
1568 case VIDIOC_G_INPUT:
1569 {
1570 int *i = arg;
1571 *i = 0;
1572 return 0;
1573 }
1574 case VIDIOC_G_AUDIO:
1575 {
1576 struct v4l2_audio *a = arg;
1577
1578 memset(a,0,sizeof(*a));
1579 strcpy(a->name,"Radio");
1580 return 0;
1581 }
1582 case VIDIOC_G_STD:
1583 {
1584 v4l2_std_id *id = arg;
1585 *id = 0;
1586 return 0;
1587 }
Mauro Carvalho Chehab79436632005-11-08 21:37:49 -08001588#ifdef HAVE_V4L1
Mauro Carvalho Chehaba82decf2005-07-07 17:58:36 -07001589 case VIDIOCSTUNER:
1590 {
1591 struct video_tuner *v = arg;
1592
1593 if (v->tuner) /* Only tuner 0 */
1594 return -EINVAL;
1595
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001596 cx88_call_i2c_clients(core,VIDIOCSTUNER,v);
1597 return 0;
Mauro Carvalho Chehaba82decf2005-07-07 17:58:36 -07001598 }
Mauro Carvalho Chehab79436632005-11-08 21:37:49 -08001599#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001600 case VIDIOC_S_TUNER:
Mauro Carvalho Chehaba82decf2005-07-07 17:58:36 -07001601 {
1602 struct v4l2_tuner *t = arg;
1603
1604 if (0 != t->index)
1605 return -EINVAL;
1606
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001607 cx88_call_i2c_clients(core,VIDIOC_S_TUNER,t);
Mauro Carvalho Chehaba82decf2005-07-07 17:58:36 -07001608
1609 return 0;
1610 }
1611
1612 case VIDIOC_S_AUDIO:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613 case VIDIOC_S_INPUT:
1614 case VIDIOC_S_STD:
1615 return 0;
1616
1617 case VIDIOC_QUERYCTRL:
1618 {
1619 struct v4l2_queryctrl *c = arg;
1620 int i;
1621
1622 if (c->id < V4L2_CID_BASE ||
1623 c->id >= V4L2_CID_LASTP1)
1624 return -EINVAL;
1625 if (c->id == V4L2_CID_AUDIO_MUTE) {
1626 for (i = 0; i < CX8800_CTLS; i++)
1627 if (cx8800_ctls[i].v.id == c->id)
1628 break;
1629 *c = cx8800_ctls[i].v;
1630 } else
1631 *c = no_ctl;
1632 return 0;
1633 }
1634
1635
1636 case VIDIOC_G_CTRL:
1637 case VIDIOC_S_CTRL:
1638 case VIDIOC_G_FREQUENCY:
1639 case VIDIOC_S_FREQUENCY:
1640 return video_do_ioctl(inode,file,cmd,arg);
1641
1642 default:
1643 return v4l_compat_translate_ioctl(inode,file,cmd,arg,
1644 radio_do_ioctl);
1645 }
1646 return 0;
1647};
1648
1649static int radio_ioctl(struct inode *inode, struct file *file,
1650 unsigned int cmd, unsigned long arg)
1651{
1652 return video_usercopy(inode, file, cmd, arg, radio_do_ioctl);
1653};
1654
1655/* ----------------------------------------------------------- */
1656
1657static void cx8800_vid_timeout(unsigned long data)
1658{
1659 struct cx8800_dev *dev = (struct cx8800_dev*)data;
1660 struct cx88_core *core = dev->core;
1661 struct cx88_dmaqueue *q = &dev->vidq;
1662 struct cx88_buffer *buf;
1663 unsigned long flags;
1664
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001665 cx88_sram_channel_dump(core, &cx88_sram_channels[SRAM_CH21]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666
1667 cx_clear(MO_VID_DMACNTRL, 0x11);
1668 cx_clear(VID_CAPTURE_CONTROL, 0x06);
1669
1670 spin_lock_irqsave(&dev->slock,flags);
1671 while (!list_empty(&q->active)) {
1672 buf = list_entry(q->active.next, struct cx88_buffer, vb.queue);
1673 list_del(&buf->vb.queue);
1674 buf->vb.state = STATE_ERROR;
1675 wake_up(&buf->vb.done);
1676 printk("%s/0: [%p/%d] timeout - dma=0x%08lx\n", core->name,
1677 buf, buf->vb.i, (unsigned long)buf->risc.dma);
1678 }
1679 restart_video_queue(dev,q);
1680 spin_unlock_irqrestore(&dev->slock,flags);
1681}
1682
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -07001683static char *cx88_vid_irqs[32] = {
1684 "y_risci1", "u_risci1", "v_risci1", "vbi_risc1",
1685 "y_risci2", "u_risci2", "v_risci2", "vbi_risc2",
1686 "y_oflow", "u_oflow", "v_oflow", "vbi_oflow",
1687 "y_sync", "u_sync", "v_sync", "vbi_sync",
1688 "opc_err", "par_err", "rip_err", "pci_abort",
1689};
1690
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691static void cx8800_vid_irq(struct cx8800_dev *dev)
1692{
1693 struct cx88_core *core = dev->core;
1694 u32 status, mask, count;
1695
1696 status = cx_read(MO_VID_INTSTAT);
1697 mask = cx_read(MO_VID_INTMSK);
1698 if (0 == (status & mask))
1699 return;
1700 cx_write(MO_VID_INTSTAT, status);
1701 if (irq_debug || (status & mask & ~0xff))
1702 cx88_print_irqbits(core->name, "irq vid",
1703 cx88_vid_irqs, status, mask);
1704
1705 /* risc op code error */
1706 if (status & (1 << 16)) {
1707 printk(KERN_WARNING "%s/0: video risc op code error\n",core->name);
1708 cx_clear(MO_VID_DMACNTRL, 0x11);
1709 cx_clear(VID_CAPTURE_CONTROL, 0x06);
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001710 cx88_sram_channel_dump(core, &cx88_sram_channels[SRAM_CH21]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711 }
1712
1713 /* risc1 y */
1714 if (status & 0x01) {
1715 spin_lock(&dev->slock);
1716 count = cx_read(MO_VIDY_GPCNT);
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001717 cx88_wakeup(core, &dev->vidq, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718 spin_unlock(&dev->slock);
1719 }
1720
1721 /* risc1 vbi */
1722 if (status & 0x08) {
1723 spin_lock(&dev->slock);
1724 count = cx_read(MO_VBI_GPCNT);
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001725 cx88_wakeup(core, &dev->vbiq, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001726 spin_unlock(&dev->slock);
1727 }
1728
1729 /* risc2 y */
1730 if (status & 0x10) {
1731 dprintk(2,"stopper video\n");
1732 spin_lock(&dev->slock);
1733 restart_video_queue(dev,&dev->vidq);
1734 spin_unlock(&dev->slock);
1735 }
1736
1737 /* risc2 vbi */
1738 if (status & 0x80) {
1739 dprintk(2,"stopper vbi\n");
1740 spin_lock(&dev->slock);
1741 cx8800_restart_vbi_queue(dev,&dev->vbiq);
1742 spin_unlock(&dev->slock);
1743 }
1744}
1745
1746static irqreturn_t cx8800_irq(int irq, void *dev_id, struct pt_regs *regs)
1747{
1748 struct cx8800_dev *dev = dev_id;
1749 struct cx88_core *core = dev->core;
1750 u32 status;
1751 int loop, handled = 0;
1752
1753 for (loop = 0; loop < 10; loop++) {
1754 status = cx_read(MO_PCI_INTSTAT) & (core->pci_irqmask | 0x01);
1755 if (0 == status)
1756 goto out;
1757 cx_write(MO_PCI_INTSTAT, status);
1758 handled = 1;
1759
1760 if (status & core->pci_irqmask)
1761 cx88_core_irq(core,status);
1762 if (status & 0x01)
1763 cx8800_vid_irq(dev);
1764 };
1765 if (10 == loop) {
1766 printk(KERN_WARNING "%s/0: irq loop -- clearing mask\n",
1767 core->name);
1768 cx_write(MO_PCI_INTMSK,0);
1769 }
1770
1771 out:
1772 return IRQ_RETVAL(handled);
1773}
1774
1775/* ----------------------------------------------------------- */
1776/* exported stuff */
1777
1778static struct file_operations video_fops =
1779{
1780 .owner = THIS_MODULE,
1781 .open = video_open,
1782 .release = video_release,
1783 .read = video_read,
1784 .poll = video_poll,
1785 .mmap = video_mmap,
1786 .ioctl = video_ioctl,
Arnd Bergmann0d0fbf82006-01-09 15:24:57 -02001787 .compat_ioctl = v4l_compat_ioctl32,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001788 .llseek = no_llseek,
1789};
1790
Adrian Bunk408b6642005-05-01 08:59:29 -07001791static struct video_device cx8800_video_template =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792{
1793 .name = "cx8800-video",
1794 .type = VID_TYPE_CAPTURE|VID_TYPE_TUNER|VID_TYPE_SCALES,
1795 .hardware = 0,
1796 .fops = &video_fops,
1797 .minor = -1,
1798};
1799
Adrian Bunk408b6642005-05-01 08:59:29 -07001800static struct video_device cx8800_vbi_template =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801{
1802 .name = "cx8800-vbi",
1803 .type = VID_TYPE_TELETEXT|VID_TYPE_TUNER,
1804 .hardware = 0,
1805 .fops = &video_fops,
1806 .minor = -1,
1807};
1808
1809static struct file_operations radio_fops =
1810{
1811 .owner = THIS_MODULE,
1812 .open = video_open,
1813 .release = video_release,
1814 .ioctl = radio_ioctl,
Arnd Bergmann0d0fbf82006-01-09 15:24:57 -02001815 .compat_ioctl = v4l_compat_ioctl32,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001816 .llseek = no_llseek,
1817};
1818
Adrian Bunk408b6642005-05-01 08:59:29 -07001819static struct video_device cx8800_radio_template =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001820{
1821 .name = "cx8800-radio",
1822 .type = VID_TYPE_TUNER,
1823 .hardware = 0,
1824 .fops = &radio_fops,
1825 .minor = -1,
1826};
1827
1828/* ----------------------------------------------------------- */
1829
1830static void cx8800_unregister_video(struct cx8800_dev *dev)
1831{
1832 if (dev->radio_dev) {
1833 if (-1 != dev->radio_dev->minor)
1834 video_unregister_device(dev->radio_dev);
1835 else
1836 video_device_release(dev->radio_dev);
1837 dev->radio_dev = NULL;
1838 }
1839 if (dev->vbi_dev) {
1840 if (-1 != dev->vbi_dev->minor)
1841 video_unregister_device(dev->vbi_dev);
1842 else
1843 video_device_release(dev->vbi_dev);
1844 dev->vbi_dev = NULL;
1845 }
1846 if (dev->video_dev) {
1847 if (-1 != dev->video_dev->minor)
1848 video_unregister_device(dev->video_dev);
1849 else
1850 video_device_release(dev->video_dev);
1851 dev->video_dev = NULL;
1852 }
1853}
1854
1855static int __devinit cx8800_initdev(struct pci_dev *pci_dev,
1856 const struct pci_device_id *pci_id)
1857{
1858 struct cx8800_dev *dev;
1859 struct cx88_core *core;
1860 int err;
1861
Panagiotis Issaris74081872006-01-11 19:40:56 -02001862 dev = kzalloc(sizeof(*dev),GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001863 if (NULL == dev)
1864 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001865
1866 /* pci init */
1867 dev->pci = pci_dev;
1868 if (pci_enable_device(pci_dev)) {
1869 err = -EIO;
1870 goto fail_free;
1871 }
1872 core = cx88_core_get(dev->pci);
1873 if (NULL == core) {
1874 err = -EINVAL;
1875 goto fail_free;
1876 }
1877 dev->core = core;
1878
1879 /* print pci info */
1880 pci_read_config_byte(pci_dev, PCI_CLASS_REVISION, &dev->pci_rev);
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -08001881 pci_read_config_byte(pci_dev, PCI_LATENCY_TIMER, &dev->pci_lat);
1882 printk(KERN_INFO "%s/0: found at %s, rev: %d, irq: %d, "
Greg Kroah-Hartman228aef62006-06-12 15:16:52 -07001883 "latency: %d, mmio: 0x%llx\n", core->name,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001884 pci_name(pci_dev), dev->pci_rev, pci_dev->irq,
Greg Kroah-Hartman228aef62006-06-12 15:16:52 -07001885 dev->pci_lat,(unsigned long long)pci_resource_start(pci_dev,0));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886
1887 pci_set_master(pci_dev);
1888 if (!pci_dma_supported(pci_dev,0xffffffff)) {
1889 printk("%s/0: Oops: no 32bit PCI DMA ???\n",core->name);
1890 err = -EIO;
1891 goto fail_core;
1892 }
1893
1894 /* initialize driver struct */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001895 spin_lock_init(&dev->slock);
1896 core->tvnorm = tvnorms;
1897
1898 /* init video dma queues */
1899 INIT_LIST_HEAD(&dev->vidq.active);
1900 INIT_LIST_HEAD(&dev->vidq.queued);
1901 dev->vidq.timeout.function = cx8800_vid_timeout;
1902 dev->vidq.timeout.data = (unsigned long)dev;
1903 init_timer(&dev->vidq.timeout);
1904 cx88_risc_stopper(dev->pci,&dev->vidq.stopper,
1905 MO_VID_DMACNTRL,0x11,0x00);
1906
1907 /* init vbi dma queues */
1908 INIT_LIST_HEAD(&dev->vbiq.active);
1909 INIT_LIST_HEAD(&dev->vbiq.queued);
1910 dev->vbiq.timeout.function = cx8800_vbi_timeout;
1911 dev->vbiq.timeout.data = (unsigned long)dev;
1912 init_timer(&dev->vbiq.timeout);
1913 cx88_risc_stopper(dev->pci,&dev->vbiq.stopper,
1914 MO_VID_DMACNTRL,0x88,0x00);
1915
1916 /* get irq */
1917 err = request_irq(pci_dev->irq, cx8800_irq,
Thomas Gleixner8076fe32006-07-01 19:29:37 -07001918 IRQF_SHARED | IRQF_DISABLED, core->name, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001919 if (err < 0) {
1920 printk(KERN_ERR "%s: can't get IRQ %d\n",
1921 core->name,pci_dev->irq);
1922 goto fail_core;
1923 }
1924 cx_set(MO_PCI_INTMSK, core->pci_irqmask);
1925
1926 /* load and configure helper modules */
1927 if (TUNER_ABSENT != core->tuner_type)
1928 request_module("tuner");
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001929
Linus Torvalds1da177e2005-04-16 15:20:36 -07001930 /* register v4l devices */
1931 dev->video_dev = cx88_vdev_init(core,dev->pci,
1932 &cx8800_video_template,"video");
1933 err = video_register_device(dev->video_dev,VFL_TYPE_GRABBER,
1934 video_nr[core->nr]);
1935 if (err < 0) {
1936 printk(KERN_INFO "%s: can't register video device\n",
1937 core->name);
1938 goto fail_unreg;
1939 }
1940 printk(KERN_INFO "%s/0: registered device video%d [v4l2]\n",
1941 core->name,dev->video_dev->minor & 0x1f);
1942
1943 dev->vbi_dev = cx88_vdev_init(core,dev->pci,&cx8800_vbi_template,"vbi");
1944 err = video_register_device(dev->vbi_dev,VFL_TYPE_VBI,
1945 vbi_nr[core->nr]);
1946 if (err < 0) {
1947 printk(KERN_INFO "%s/0: can't register vbi device\n",
1948 core->name);
1949 goto fail_unreg;
1950 }
1951 printk(KERN_INFO "%s/0: registered device vbi%d\n",
1952 core->name,dev->vbi_dev->minor & 0x1f);
1953
1954 if (core->has_radio) {
1955 dev->radio_dev = cx88_vdev_init(core,dev->pci,
1956 &cx8800_radio_template,"radio");
1957 err = video_register_device(dev->radio_dev,VFL_TYPE_RADIO,
1958 radio_nr[core->nr]);
1959 if (err < 0) {
1960 printk(KERN_INFO "%s/0: can't register radio device\n",
1961 core->name);
1962 goto fail_unreg;
1963 }
1964 printk(KERN_INFO "%s/0: registered device radio%d\n",
1965 core->name,dev->radio_dev->minor & 0x1f);
1966 }
1967
1968 /* everything worked */
1969 list_add_tail(&dev->devlist,&cx8800_devlist);
1970 pci_set_drvdata(pci_dev,dev);
1971
1972 /* initial device configuration */
Ingo Molnar3593cab2006-02-07 06:49:14 -02001973 mutex_lock(&core->lock);
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001974 cx88_set_tvnorm(core,tvnorms);
Mauro Carvalho Chehab70f00042006-01-09 15:25:26 -02001975 init_controls(core);
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001976 video_mux(core,0);
Ingo Molnar3593cab2006-02-07 06:49:14 -02001977 mutex_unlock(&core->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001978
1979 /* start tvaudio thread */
1980 if (core->tuner_type != TUNER_ABSENT)
1981 core->kthread = kthread_run(cx88_audio_thread, core, "cx88 tvaudio");
1982 return 0;
1983
1984fail_unreg:
1985 cx8800_unregister_video(dev);
1986 free_irq(pci_dev->irq, dev);
1987fail_core:
1988 cx88_core_put(core,dev->pci);
1989fail_free:
1990 kfree(dev);
1991 return err;
1992}
1993
1994static void __devexit cx8800_finidev(struct pci_dev *pci_dev)
1995{
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -08001996 struct cx8800_dev *dev = pci_get_drvdata(pci_dev);
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001997 struct cx88_core *core = dev->core;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001998
1999 /* stop thread */
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07002000 if (core->kthread) {
2001 kthread_stop(core->kthread);
2002 core->kthread = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002003 }
2004
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07002005 cx88_shutdown(core); /* FIXME */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002006 pci_disable_device(pci_dev);
2007
2008 /* unregister stuff */
2009
2010 free_irq(pci_dev->irq, dev);
2011 cx8800_unregister_video(dev);
2012 pci_set_drvdata(pci_dev, NULL);
2013
2014 /* free memory */
2015 btcx_riscmem_free(dev->pci,&dev->vidq.stopper);
2016 list_del(&dev->devlist);
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07002017 cx88_core_put(core,dev->pci);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002018 kfree(dev);
2019}
2020
2021static int cx8800_suspend(struct pci_dev *pci_dev, pm_message_t state)
2022{
Mauro Carvalho Chehabb45009b2005-06-23 22:05:03 -07002023 struct cx8800_dev *dev = pci_get_drvdata(pci_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002024 struct cx88_core *core = dev->core;
2025
2026 /* stop video+vbi capture */
2027 spin_lock(&dev->slock);
2028 if (!list_empty(&dev->vidq.active)) {
2029 printk("%s: suspend video\n", core->name);
2030 stop_video_dma(dev);
2031 del_timer(&dev->vidq.timeout);
2032 }
2033 if (!list_empty(&dev->vbiq.active)) {
2034 printk("%s: suspend vbi\n", core->name);
2035 cx8800_stop_vbi_dma(dev);
2036 del_timer(&dev->vbiq.timeout);
2037 }
2038 spin_unlock(&dev->slock);
2039
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040 /* FIXME -- shutdown device */
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07002041 cx88_shutdown(core);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002042
2043 pci_save_state(pci_dev);
2044 if (0 != pci_set_power_state(pci_dev, pci_choose_state(pci_dev, state))) {
2045 pci_disable_device(pci_dev);
2046 dev->state.disabled = 1;
2047 }
2048 return 0;
2049}
2050
2051static int cx8800_resume(struct pci_dev *pci_dev)
2052{
Mauro Carvalho Chehabb45009b2005-06-23 22:05:03 -07002053 struct cx8800_dev *dev = pci_get_drvdata(pci_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054 struct cx88_core *core = dev->core;
Mauro Carvalho Chehab08adb9e2005-09-09 13:03:55 -07002055 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002056
2057 if (dev->state.disabled) {
Mauro Carvalho Chehab08adb9e2005-09-09 13:03:55 -07002058 err=pci_enable_device(pci_dev);
2059 if (err) {
2060 printk(KERN_ERR "%s: can't enable device\n",
2061 core->name);
2062 return err;
2063 }
2064
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065 dev->state.disabled = 0;
2066 }
Mauro Carvalho Chehab08adb9e2005-09-09 13:03:55 -07002067 err= pci_set_power_state(pci_dev, PCI_D0);
2068 if (err) {
2069 printk(KERN_ERR "%s: can't enable device\n",
2070 core->name);
2071
2072 pci_disable_device(pci_dev);
2073 dev->state.disabled = 1;
2074
2075 return err;
2076 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002077 pci_restore_state(pci_dev);
2078
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079 /* FIXME: re-initialize hardware */
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07002080 cx88_reset(core);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081
2082 /* restart video+vbi capture */
2083 spin_lock(&dev->slock);
2084 if (!list_empty(&dev->vidq.active)) {
2085 printk("%s: resume video\n", core->name);
2086 restart_video_queue(dev,&dev->vidq);
2087 }
2088 if (!list_empty(&dev->vbiq.active)) {
2089 printk("%s: resume vbi\n", core->name);
2090 cx8800_restart_vbi_queue(dev,&dev->vbiq);
2091 }
2092 spin_unlock(&dev->slock);
2093
2094 return 0;
2095}
2096
2097/* ----------------------------------------------------------- */
2098
Adrian Bunk408b6642005-05-01 08:59:29 -07002099static struct pci_device_id cx8800_pci_tbl[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100 {
2101 .vendor = 0x14f1,
2102 .device = 0x8800,
Mauro Carvalho Chehabb45009b2005-06-23 22:05:03 -07002103 .subvendor = PCI_ANY_ID,
2104 .subdevice = PCI_ANY_ID,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105 },{
2106 /* --- end of list --- */
2107 }
2108};
2109MODULE_DEVICE_TABLE(pci, cx8800_pci_tbl);
2110
2111static struct pci_driver cx8800_pci_driver = {
Mauro Carvalho Chehabb45009b2005-06-23 22:05:03 -07002112 .name = "cx8800",
2113 .id_table = cx8800_pci_tbl,
2114 .probe = cx8800_initdev,
2115 .remove = __devexit_p(cx8800_finidev),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002116
2117 .suspend = cx8800_suspend,
2118 .resume = cx8800_resume,
2119};
2120
2121static int cx8800_init(void)
2122{
2123 printk(KERN_INFO "cx2388x v4l2 driver version %d.%d.%d loaded\n",
2124 (CX88_VERSION_CODE >> 16) & 0xff,
2125 (CX88_VERSION_CODE >> 8) & 0xff,
2126 CX88_VERSION_CODE & 0xff);
2127#ifdef SNAPSHOT
2128 printk(KERN_INFO "cx2388x: snapshot date %04d-%02d-%02d\n",
2129 SNAPSHOT/10000, (SNAPSHOT/100)%100, SNAPSHOT%100);
2130#endif
2131 return pci_register_driver(&cx8800_pci_driver);
2132}
2133
2134static void cx8800_fini(void)
2135{
2136 pci_unregister_driver(&cx8800_pci_driver);
2137}
2138
2139module_init(cx8800_init);
2140module_exit(cx8800_fini);
2141
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07002142EXPORT_SYMBOL(cx88_do_ioctl);
2143
Linus Torvalds1da177e2005-04-16 15:20:36 -07002144/* ----------------------------------------------------------- */
2145/*
2146 * Local variables:
2147 * c-basic-offset: 8
2148 * End:
Mauro Carvalho Chehabb45009b2005-06-23 22:05:03 -07002149 * kate: eol "unix"; indent-width 3; remove-trailing-space on; replace-trailing-space-save on; tab-width 8; replace-tabs off; space-indent off; mixed-indent off
Linus Torvalds1da177e2005-04-16 15:20:36 -07002150 */