blob: 4fba913edb1ba8a0803c0c2842bc6aa8b0ad9bae [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 *
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03008 * (c) 2005-2006 Mauro Carvalho Chehab <mchehab@infradead.org>
9 * - Multituner support
10 * - video_ioctl2 conversion
11 * - PAL/M fixes
12 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 */
27
28#include <linux/init.h>
29#include <linux/list.h>
30#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <linux/kmod.h>
32#include <linux/kernel.h>
33#include <linux/slab.h>
Alexey Dobriyan405f5572009-07-11 22:08:37 +040034#include <linux/smp_lock.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include <linux/interrupt.h>
Andrew Mortonc24228d2007-05-06 14:51:55 -070036#include <linux/dma-mapping.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#include <linux/delay.h>
38#include <linux/kthread.h>
39#include <asm/div64.h>
40
41#include "cx88.h"
Michael Krufky5e453dc2006-01-09 15:32:31 -020042#include <media/v4l2-common.h>
Hans Verkuil35ea11f2008-07-20 08:12:02 -030043#include <media/v4l2-ioctl.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
45MODULE_DESCRIPTION("v4l2 driver module for cx2388x based TV cards");
46MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
47MODULE_LICENSE("GPL");
48
49/* ------------------------------------------------------------------ */
50
51static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
52static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
53static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
54
55module_param_array(video_nr, int, NULL, 0444);
56module_param_array(vbi_nr, int, NULL, 0444);
57module_param_array(radio_nr, int, NULL, 0444);
58
59MODULE_PARM_DESC(video_nr,"video device numbers");
60MODULE_PARM_DESC(vbi_nr,"vbi device numbers");
61MODULE_PARM_DESC(radio_nr,"radio device numbers");
62
Douglas Schilling Landgrafff699e62008-04-22 14:41:48 -030063static unsigned int video_debug;
Linus Torvalds1da177e2005-04-16 15:20:36 -070064module_param(video_debug,int,0644);
65MODULE_PARM_DESC(video_debug,"enable debug messages [video]");
66
Douglas Schilling Landgrafff699e62008-04-22 14:41:48 -030067static unsigned int irq_debug;
Linus Torvalds1da177e2005-04-16 15:20:36 -070068module_param(irq_debug,int,0644);
69MODULE_PARM_DESC(irq_debug,"enable debug messages [IRQ handler]");
70
71static unsigned int vid_limit = 16;
72module_param(vid_limit,int,0644);
73MODULE_PARM_DESC(vid_limit,"capture memory limit in megabytes");
74
75#define dprintk(level,fmt, arg...) if (video_debug >= level) \
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -070076 printk(KERN_DEBUG "%s/0: " fmt, core->name , ## arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
Linus Torvalds1da177e2005-04-16 15:20:36 -070078/* ------------------------------------------------------------------- */
79/* static data */
80
Linus Torvalds1da177e2005-04-16 15:20:36 -070081static struct cx8800_fmt formats[] = {
82 {
83 .name = "8 bpp, gray",
84 .fourcc = V4L2_PIX_FMT_GREY,
85 .cxformat = ColorFormatY8,
86 .depth = 8,
87 .flags = FORMAT_FLAGS_PACKED,
88 },{
89 .name = "15 bpp RGB, le",
90 .fourcc = V4L2_PIX_FMT_RGB555,
91 .cxformat = ColorFormatRGB15,
92 .depth = 16,
93 .flags = FORMAT_FLAGS_PACKED,
94 },{
95 .name = "15 bpp RGB, be",
96 .fourcc = V4L2_PIX_FMT_RGB555X,
97 .cxformat = ColorFormatRGB15 | ColorFormatBSWAP,
98 .depth = 16,
99 .flags = FORMAT_FLAGS_PACKED,
100 },{
101 .name = "16 bpp RGB, le",
102 .fourcc = V4L2_PIX_FMT_RGB565,
103 .cxformat = ColorFormatRGB16,
104 .depth = 16,
105 .flags = FORMAT_FLAGS_PACKED,
106 },{
107 .name = "16 bpp RGB, be",
108 .fourcc = V4L2_PIX_FMT_RGB565X,
109 .cxformat = ColorFormatRGB16 | ColorFormatBSWAP,
110 .depth = 16,
111 .flags = FORMAT_FLAGS_PACKED,
112 },{
113 .name = "24 bpp RGB, le",
114 .fourcc = V4L2_PIX_FMT_BGR24,
115 .cxformat = ColorFormatRGB24,
116 .depth = 24,
117 .flags = FORMAT_FLAGS_PACKED,
118 },{
119 .name = "32 bpp RGB, le",
120 .fourcc = V4L2_PIX_FMT_BGR32,
121 .cxformat = ColorFormatRGB32,
122 .depth = 32,
123 .flags = FORMAT_FLAGS_PACKED,
124 },{
125 .name = "32 bpp RGB, be",
126 .fourcc = V4L2_PIX_FMT_RGB32,
127 .cxformat = ColorFormatRGB32 | ColorFormatBSWAP | ColorFormatWSWAP,
128 .depth = 32,
129 .flags = FORMAT_FLAGS_PACKED,
130 },{
131 .name = "4:2:2, packed, YUYV",
132 .fourcc = V4L2_PIX_FMT_YUYV,
133 .cxformat = ColorFormatYUY2,
134 .depth = 16,
135 .flags = FORMAT_FLAGS_PACKED,
136 },{
137 .name = "4:2:2, packed, UYVY",
138 .fourcc = V4L2_PIX_FMT_UYVY,
139 .cxformat = ColorFormatYUY2 | ColorFormatBSWAP,
140 .depth = 16,
141 .flags = FORMAT_FLAGS_PACKED,
142 },
143};
144
145static struct cx8800_fmt* format_by_fourcc(unsigned int fourcc)
146{
147 unsigned int i;
148
149 for (i = 0; i < ARRAY_SIZE(formats); i++)
150 if (formats[i].fourcc == fourcc)
151 return formats+i;
152 return NULL;
153}
154
155/* ------------------------------------------------------------------- */
156
157static const struct v4l2_queryctrl no_ctl = {
158 .name = "42",
159 .flags = V4L2_CTRL_FLAG_DISABLED,
160};
161
162static struct cx88_ctrl cx8800_ctls[] = {
163 /* --- video --- */
164 {
165 .v = {
166 .id = V4L2_CID_BRIGHTNESS,
167 .name = "Brightness",
168 .minimum = 0x00,
169 .maximum = 0xff,
170 .step = 1,
Marcin Rudowski9f9c9072006-03-12 00:03:47 -0300171 .default_value = 0x7f,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 .type = V4L2_CTRL_TYPE_INTEGER,
173 },
174 .off = 128,
175 .reg = MO_CONTR_BRIGHT,
176 .mask = 0x00ff,
177 .shift = 0,
178 },{
179 .v = {
180 .id = V4L2_CID_CONTRAST,
181 .name = "Contrast",
182 .minimum = 0,
183 .maximum = 0xff,
184 .step = 1,
Mauro Carvalho Chehab70f00042006-01-09 15:25:26 -0200185 .default_value = 0x3f,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 .type = V4L2_CTRL_TYPE_INTEGER,
187 },
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -0700188 .off = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 .reg = MO_CONTR_BRIGHT,
190 .mask = 0xff00,
191 .shift = 8,
192 },{
193 .v = {
194 .id = V4L2_CID_HUE,
195 .name = "Hue",
196 .minimum = 0,
197 .maximum = 0xff,
198 .step = 1,
Marcin Rudowski9f9c9072006-03-12 00:03:47 -0300199 .default_value = 0x7f,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 .type = V4L2_CTRL_TYPE_INTEGER,
201 },
Michael Krufky9ac4c1582005-07-07 17:58:38 -0700202 .off = 128,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 .reg = MO_HUE,
204 .mask = 0x00ff,
205 .shift = 0,
206 },{
207 /* strictly, this only describes only U saturation.
208 * V saturation is handled specially through code.
209 */
210 .v = {
211 .id = V4L2_CID_SATURATION,
212 .name = "Saturation",
213 .minimum = 0,
214 .maximum = 0xff,
215 .step = 1,
Mauro Carvalho Chehab70f00042006-01-09 15:25:26 -0200216 .default_value = 0x7f,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 .type = V4L2_CTRL_TYPE_INTEGER,
218 },
219 .off = 0,
220 .reg = MO_UV_SATURATION,
221 .mask = 0x00ff,
222 .shift = 0,
223 },{
Frej Drejhammar6d042032008-03-23 22:43:21 -0300224 .v = {
225 .id = V4L2_CID_CHROMA_AGC,
226 .name = "Chroma AGC",
227 .minimum = 0,
228 .maximum = 1,
Frej Drejhammar87a17382008-03-23 22:43:22 -0300229 .default_value = 0x1,
Frej Drejhammar6d042032008-03-23 22:43:21 -0300230 .type = V4L2_CTRL_TYPE_BOOLEAN,
231 },
232 .reg = MO_INPUT_FORMAT,
233 .mask = 1 << 10,
234 .shift = 10,
235 }, {
Frej Drejhammar1b879c42008-03-23 22:43:24 -0300236 .v = {
237 .id = V4L2_CID_COLOR_KILLER,
238 .name = "Color killer",
239 .minimum = 0,
240 .maximum = 1,
Frej Drejhammar0b5afdd2008-03-23 22:43:25 -0300241 .default_value = 0x1,
Frej Drejhammar1b879c42008-03-23 22:43:24 -0300242 .type = V4L2_CTRL_TYPE_BOOLEAN,
243 },
244 .reg = MO_INPUT_FORMAT,
245 .mask = 1 << 9,
246 .shift = 9,
247 }, {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 /* --- audio --- */
249 .v = {
250 .id = V4L2_CID_AUDIO_MUTE,
251 .name = "Mute",
252 .minimum = 0,
253 .maximum = 1,
Mauro Carvalho Chehab70f00042006-01-09 15:25:26 -0200254 .default_value = 1,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 .type = V4L2_CTRL_TYPE_BOOLEAN,
256 },
257 .reg = AUD_VOL_CTL,
258 .sreg = SHADOW_AUD_VOL_CTL,
259 .mask = (1 << 6),
260 .shift = 6,
261 },{
262 .v = {
263 .id = V4L2_CID_AUDIO_VOLUME,
264 .name = "Volume",
265 .minimum = 0,
266 .maximum = 0x3f,
267 .step = 1,
Marcin Rudowski9f9c9072006-03-12 00:03:47 -0300268 .default_value = 0x3f,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 .type = V4L2_CTRL_TYPE_INTEGER,
270 },
271 .reg = AUD_VOL_CTL,
272 .sreg = SHADOW_AUD_VOL_CTL,
273 .mask = 0x3f,
274 .shift = 0,
275 },{
276 .v = {
277 .id = V4L2_CID_AUDIO_BALANCE,
278 .name = "Balance",
279 .minimum = 0,
280 .maximum = 0x7f,
281 .step = 1,
282 .default_value = 0x40,
283 .type = V4L2_CTRL_TYPE_INTEGER,
284 },
285 .reg = AUD_BAL_CTL,
286 .sreg = SHADOW_AUD_BAL_CTL,
287 .mask = 0x7f,
288 .shift = 0,
289 }
290};
Adrian Bunk408b6642005-05-01 08:59:29 -0700291static const int CX8800_CTLS = ARRAY_SIZE(cx8800_ctls);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292
Hans Verkuil2ba58892009-02-13 10:57:48 -0300293/* Must be sorted from low to high control ID! */
Michael Krufky38a27132006-06-26 23:42:39 -0300294const u32 cx88_user_ctrls[] = {
295 V4L2_CID_USER_CLASS,
296 V4L2_CID_BRIGHTNESS,
297 V4L2_CID_CONTRAST,
298 V4L2_CID_SATURATION,
299 V4L2_CID_HUE,
300 V4L2_CID_AUDIO_VOLUME,
301 V4L2_CID_AUDIO_BALANCE,
302 V4L2_CID_AUDIO_MUTE,
Frej Drejhammar6d042032008-03-23 22:43:21 -0300303 V4L2_CID_CHROMA_AGC,
Frej Drejhammar1b879c42008-03-23 22:43:24 -0300304 V4L2_CID_COLOR_KILLER,
Michael Krufky38a27132006-06-26 23:42:39 -0300305 0
306};
307EXPORT_SYMBOL(cx88_user_ctrls);
308
309static const u32 *ctrl_classes[] = {
310 cx88_user_ctrls,
311 NULL
312};
313
Frej Drejhammar6d042032008-03-23 22:43:21 -0300314int cx8800_ctrl_query(struct cx88_core *core, struct v4l2_queryctrl *qctrl)
Michael Krufky38a27132006-06-26 23:42:39 -0300315{
316 int i;
317
318 if (qctrl->id < V4L2_CID_BASE ||
319 qctrl->id >= V4L2_CID_LASTP1)
320 return -EINVAL;
321 for (i = 0; i < CX8800_CTLS; i++)
322 if (cx8800_ctls[i].v.id == qctrl->id)
323 break;
324 if (i == CX8800_CTLS) {
325 *qctrl = no_ctl;
326 return 0;
327 }
328 *qctrl = cx8800_ctls[i].v;
Frej Drejhammar6d042032008-03-23 22:43:21 -0300329 /* Report chroma AGC as inactive when SECAM is selected */
330 if (cx8800_ctls[i].v.id == V4L2_CID_CHROMA_AGC &&
331 core->tvnorm & V4L2_STD_SECAM)
332 qctrl->flags |= V4L2_CTRL_FLAG_INACTIVE;
333
Michael Krufky38a27132006-06-26 23:42:39 -0300334 return 0;
335}
336EXPORT_SYMBOL(cx8800_ctrl_query);
337
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338/* ------------------------------------------------------------------- */
339/* resource management */
340
341static int res_get(struct cx8800_dev *dev, struct cx8800_fh *fh, unsigned int bit)
342{
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700343 struct cx88_core *core = dev->core;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 if (fh->resources & bit)
345 /* have it already allocated */
346 return 1;
347
348 /* is it free? */
Ingo Molnar3593cab2006-02-07 06:49:14 -0200349 mutex_lock(&core->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 if (dev->resources & bit) {
351 /* no, someone else uses it */
Ingo Molnar3593cab2006-02-07 06:49:14 -0200352 mutex_unlock(&core->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 return 0;
354 }
355 /* it's free, grab it */
356 fh->resources |= bit;
357 dev->resources |= bit;
358 dprintk(1,"res: get %d\n",bit);
Ingo Molnar3593cab2006-02-07 06:49:14 -0200359 mutex_unlock(&core->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 return 1;
361}
362
363static
364int res_check(struct cx8800_fh *fh, unsigned int bit)
365{
366 return (fh->resources & bit);
367}
368
369static
370int res_locked(struct cx8800_dev *dev, unsigned int bit)
371{
372 return (dev->resources & bit);
373}
374
375static
376void res_free(struct cx8800_dev *dev, struct cx8800_fh *fh, unsigned int bits)
377{
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700378 struct cx88_core *core = dev->core;
Eric Sesterhennae246012006-03-13 13:17:11 -0300379 BUG_ON((fh->resources & bits) != bits);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380
Ingo Molnar3593cab2006-02-07 06:49:14 -0200381 mutex_lock(&core->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 fh->resources &= ~bits;
383 dev->resources &= ~bits;
384 dprintk(1,"res: put %d\n",bits);
Ingo Molnar3593cab2006-02-07 06:49:14 -0200385 mutex_unlock(&core->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386}
387
388/* ------------------------------------------------------------------ */
389
Mauro Carvalho Chehabe90311a2007-01-20 13:58:29 -0300390int cx88_video_mux(struct cx88_core *core, unsigned int input)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391{
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700392 /* struct cx88_core *core = dev->core; */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393
394 dprintk(1,"video_mux: %d [vmux=%d,gpio=0x%x,0x%x,0x%x,0x%x]\n",
Trent Piepho6a59d642007-08-15 14:41:57 -0300395 input, INPUT(input).vmux,
396 INPUT(input).gpio0,INPUT(input).gpio1,
397 INPUT(input).gpio2,INPUT(input).gpio3);
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700398 core->input = input;
Trent Piepho6a59d642007-08-15 14:41:57 -0300399 cx_andor(MO_INPUT_FORMAT, 0x03 << 14, INPUT(input).vmux << 14);
400 cx_write(MO_GP3_IO, INPUT(input).gpio3);
401 cx_write(MO_GP0_IO, INPUT(input).gpio0);
402 cx_write(MO_GP1_IO, INPUT(input).gpio1);
403 cx_write(MO_GP2_IO, INPUT(input).gpio2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404
Trent Piepho6a59d642007-08-15 14:41:57 -0300405 switch (INPUT(input).type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 case CX88_VMUX_SVIDEO:
407 cx_set(MO_AFECFG_IO, 0x00000001);
408 cx_set(MO_INPUT_FORMAT, 0x00010010);
409 cx_set(MO_FILTER_EVEN, 0x00002020);
410 cx_set(MO_FILTER_ODD, 0x00002020);
411 break;
412 default:
413 cx_clear(MO_AFECFG_IO, 0x00000001);
414 cx_clear(MO_INPUT_FORMAT, 0x00010010);
415 cx_clear(MO_FILTER_EVEN, 0x00002020);
416 cx_clear(MO_FILTER_ODD, 0x00002020);
417 break;
418 }
Michael Krufkyf24546a2006-10-16 16:51:11 -0300419
Ricardo Cerqueira66e6fbd2007-10-16 20:52:08 -0300420 /* if there are audioroutes defined, we have an external
421 ADC to deal with audio */
Ricardo Cerqueira66e6fbd2007-10-16 20:52:08 -0300422 if (INPUT(input).audioroute) {
Ricardo Cerqueira66e6fbd2007-10-16 20:52:08 -0300423 /* The wm8775 module has the "2" route hardwired into
424 the initialization. Some boards may use different
425 routes for different inputs. HVR-1300 surely does */
426 if (core->board.audio_chip &&
Hans Verkuil38f9d302008-07-23 05:09:15 -0300427 core->board.audio_chip == V4L2_IDENT_WM8775) {
Hans Verkuil5325b422009-04-02 11:26:22 -0300428 call_all(core, audio, s_routing,
istvan_v@mailbox.hu6e1f4df2010-03-27 09:31:32 -0300429 INPUT(input).audioroute, 0, 0);
Ricardo Cerqueira66e6fbd2007-10-16 20:52:08 -0300430 }
Darron Broad430189d2008-10-15 14:18:42 -0300431 /* cx2388's C-ADC is connected to the tuner only.
432 When used with S-Video, that ADC is busy dealing with
433 chroma, so an external must be used for baseband audio */
istvan_v@mailbox.hu6e1f4df2010-03-27 09:31:32 -0300434 if (INPUT(input).type != CX88_VMUX_TELEVISION &&
435 INPUT(input).type != CX88_VMUX_CABLE) {
Darron Broad430189d2008-10-15 14:18:42 -0300436 /* "I2S ADC mode" */
437 core->tvaudio = WW_I2SADC;
438 cx88_set_tvaudio(core);
439 } else {
440 /* Normal mode */
441 cx_write(AUD_I2SCNTL, 0x0);
442 cx_clear(AUD_CTL, EN_I2SIN_ENABLE);
443 }
Michael Krufkyf24546a2006-10-16 16:51:11 -0300444 }
Ricardo Cerqueira66e6fbd2007-10-16 20:52:08 -0300445
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 return 0;
447}
Mauro Carvalho Chehabe90311a2007-01-20 13:58:29 -0300448EXPORT_SYMBOL(cx88_video_mux);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449
450/* ------------------------------------------------------------------ */
451
452static int start_video_dma(struct cx8800_dev *dev,
453 struct cx88_dmaqueue *q,
454 struct cx88_buffer *buf)
455{
456 struct cx88_core *core = dev->core;
457
458 /* setup fifo + format */
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700459 cx88_sram_channel_setup(core, &cx88_sram_channels[SRAM_CH21],
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 buf->bpl, buf->risc.dma);
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700461 cx88_set_scale(core, buf->vb.width, buf->vb.height, buf->vb.field);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 cx_write(MO_COLOR_CTRL, buf->fmt->cxformat | ColorFormatGamma);
463
464 /* reset counter */
465 cx_write(MO_VIDY_GPCNTRL,GP_COUNT_CONTROL_RESET);
466 q->count = 1;
467
468 /* enable irqs */
Trent Piepho8ddac9e2007-08-18 06:57:55 -0300469 cx_set(MO_PCI_INTMSK, core->pci_irqmask | PCI_INT_VIDINT);
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700470
471 /* Enables corresponding bits at PCI_INT_STAT:
472 bits 0 to 4: video, audio, transport stream, VIP, Host
473 bit 7: timer
474 bits 8 and 9: DMA complete for: SRC, DST
475 bits 10 and 11: BERR signal asserted for RISC: RD, WR
476 bits 12 to 15: BERR signal asserted for: BRDG, SRC, DST, IPB
477 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 cx_set(MO_VID_INTMSK, 0x0f0011);
479
480 /* enable capture */
481 cx_set(VID_CAPTURE_CONTROL,0x06);
482
483 /* start dma */
484 cx_set(MO_DEV_CNTRL2, (1<<5));
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700485 cx_set(MO_VID_DMACNTRL, 0x11); /* Planar Y and packed FIFO and RISC enable */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486
487 return 0;
488}
489
Alexey Dobriyan17bc98a2006-08-12 22:01:27 -0300490#ifdef CONFIG_PM
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491static int stop_video_dma(struct cx8800_dev *dev)
492{
493 struct cx88_core *core = dev->core;
494
495 /* stop dma */
496 cx_clear(MO_VID_DMACNTRL, 0x11);
497
498 /* disable capture */
499 cx_clear(VID_CAPTURE_CONTROL,0x06);
500
501 /* disable irqs */
Trent Piepho8ddac9e2007-08-18 06:57:55 -0300502 cx_clear(MO_PCI_INTMSK, PCI_INT_VIDINT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 cx_clear(MO_VID_INTMSK, 0x0f0011);
504 return 0;
505}
Alexey Dobriyan17bc98a2006-08-12 22:01:27 -0300506#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507
508static int restart_video_queue(struct cx8800_dev *dev,
509 struct cx88_dmaqueue *q)
510{
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700511 struct cx88_core *core = dev->core;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 struct cx88_buffer *buf, *prev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513
514 if (!list_empty(&q->active)) {
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -0800515 buf = list_entry(q->active.next, struct cx88_buffer, vb.queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 dprintk(2,"restart_queue [%p/%d]: restart dma\n",
517 buf, buf->vb.i);
518 start_video_dma(dev, q, buf);
Trent Piepho8bb629e22007-10-10 05:37:40 -0300519 list_for_each_entry(buf, &q->active, vb.queue)
520 buf->count = q->count++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
522 return 0;
523 }
524
525 prev = NULL;
526 for (;;) {
527 if (list_empty(&q->queued))
528 return 0;
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -0800529 buf = list_entry(q->queued.next, struct cx88_buffer, vb.queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 if (NULL == prev) {
Akinobu Mita179e0912006-06-26 00:24:41 -0700531 list_move_tail(&buf->vb.queue, &q->active);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 start_video_dma(dev, q, buf);
Brandon Philips0fc06862007-11-06 20:02:36 -0300533 buf->vb.state = VIDEOBUF_ACTIVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 buf->count = q->count++;
535 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
536 dprintk(2,"[%p/%d] restart_queue - first active\n",
537 buf,buf->vb.i);
538
539 } else if (prev->vb.width == buf->vb.width &&
540 prev->vb.height == buf->vb.height &&
541 prev->fmt == buf->fmt) {
Akinobu Mita179e0912006-06-26 00:24:41 -0700542 list_move_tail(&buf->vb.queue, &q->active);
Brandon Philips0fc06862007-11-06 20:02:36 -0300543 buf->vb.state = VIDEOBUF_ACTIVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 buf->count = q->count++;
545 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
546 dprintk(2,"[%p/%d] restart_queue - move to active\n",
547 buf,buf->vb.i);
548 } else {
549 return 0;
550 }
551 prev = buf;
552 }
553}
554
555/* ------------------------------------------------------------------ */
556
557static int
558buffer_setup(struct videobuf_queue *q, unsigned int *count, unsigned int *size)
559{
560 struct cx8800_fh *fh = q->priv_data;
561
562 *size = fh->fmt->depth*fh->width*fh->height >> 3;
563 if (0 == *count)
564 *count = 32;
Andreas Bombedab7e312010-03-21 16:02:45 -0300565 if (*size * *count > vid_limit * 1024 * 1024)
566 *count = (vid_limit * 1024 * 1024) / *size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 return 0;
568}
569
570static int
571buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
572 enum v4l2_field field)
573{
574 struct cx8800_fh *fh = q->priv_data;
575 struct cx8800_dev *dev = fh->dev;
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700576 struct cx88_core *core = dev->core;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 struct cx88_buffer *buf = container_of(vb,struct cx88_buffer,vb);
Mauro Carvalho Chehabc1accaa2007-08-23 16:37:49 -0300578 struct videobuf_dmabuf *dma=videobuf_to_dma(&buf->vb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 int rc, init_buffer = 0;
580
581 BUG_ON(NULL == fh->fmt);
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700582 if (fh->width < 48 || fh->width > norm_maxw(core->tvnorm) ||
583 fh->height < 32 || fh->height > norm_maxh(core->tvnorm))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 return -EINVAL;
585 buf->vb.size = (fh->width * fh->height * fh->fmt->depth) >> 3;
586 if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size)
587 return -EINVAL;
588
589 if (buf->fmt != fh->fmt ||
590 buf->vb.width != fh->width ||
591 buf->vb.height != fh->height ||
592 buf->vb.field != field) {
593 buf->fmt = fh->fmt;
594 buf->vb.width = fh->width;
595 buf->vb.height = fh->height;
596 buf->vb.field = field;
597 init_buffer = 1;
598 }
599
Brandon Philips0fc06862007-11-06 20:02:36 -0300600 if (VIDEOBUF_NEEDS_INIT == buf->vb.state) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 init_buffer = 1;
Mauro Carvalho Chehabc7b0ac02006-03-10 12:29:15 -0300602 if (0 != (rc = videobuf_iolock(q,&buf->vb,NULL)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 goto fail;
604 }
605
606 if (init_buffer) {
607 buf->bpl = buf->vb.width * buf->fmt->depth >> 3;
608 switch (buf->vb.field) {
609 case V4L2_FIELD_TOP:
610 cx88_risc_buffer(dev->pci, &buf->risc,
Mauro Carvalho Chehabc1accaa2007-08-23 16:37:49 -0300611 dma->sglist, 0, UNSET,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 buf->bpl, 0, buf->vb.height);
613 break;
614 case V4L2_FIELD_BOTTOM:
615 cx88_risc_buffer(dev->pci, &buf->risc,
Mauro Carvalho Chehabc1accaa2007-08-23 16:37:49 -0300616 dma->sglist, UNSET, 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 buf->bpl, 0, buf->vb.height);
618 break;
619 case V4L2_FIELD_INTERLACED:
620 cx88_risc_buffer(dev->pci, &buf->risc,
Mauro Carvalho Chehabc1accaa2007-08-23 16:37:49 -0300621 dma->sglist, 0, buf->bpl,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 buf->bpl, buf->bpl,
623 buf->vb.height >> 1);
624 break;
625 case V4L2_FIELD_SEQ_TB:
626 cx88_risc_buffer(dev->pci, &buf->risc,
Mauro Carvalho Chehabc1accaa2007-08-23 16:37:49 -0300627 dma->sglist,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 0, buf->bpl * (buf->vb.height >> 1),
629 buf->bpl, 0,
630 buf->vb.height >> 1);
631 break;
632 case V4L2_FIELD_SEQ_BT:
633 cx88_risc_buffer(dev->pci, &buf->risc,
Mauro Carvalho Chehabc1accaa2007-08-23 16:37:49 -0300634 dma->sglist,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 buf->bpl * (buf->vb.height >> 1), 0,
636 buf->bpl, 0,
637 buf->vb.height >> 1);
638 break;
639 default:
640 BUG();
641 }
642 }
643 dprintk(2,"[%p/%d] buffer_prepare - %dx%d %dbpp \"%s\" - dma=0x%08lx\n",
644 buf, buf->vb.i,
645 fh->width, fh->height, fh->fmt->depth, fh->fmt->name,
646 (unsigned long)buf->risc.dma);
647
Brandon Philips0fc06862007-11-06 20:02:36 -0300648 buf->vb.state = VIDEOBUF_PREPARED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 return 0;
650
651 fail:
Mauro Carvalho Chehabc7b0ac02006-03-10 12:29:15 -0300652 cx88_free_buffer(q,buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 return rc;
654}
655
656static void
657buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
658{
659 struct cx88_buffer *buf = container_of(vb,struct cx88_buffer,vb);
660 struct cx88_buffer *prev;
661 struct cx8800_fh *fh = vq->priv_data;
662 struct cx8800_dev *dev = fh->dev;
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700663 struct cx88_core *core = dev->core;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 struct cx88_dmaqueue *q = &dev->vidq;
665
666 /* add jump to stopper */
667 buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC);
668 buf->risc.jmp[1] = cpu_to_le32(q->stopper.dma);
669
670 if (!list_empty(&q->queued)) {
671 list_add_tail(&buf->vb.queue,&q->queued);
Brandon Philips0fc06862007-11-06 20:02:36 -0300672 buf->vb.state = VIDEOBUF_QUEUED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 dprintk(2,"[%p/%d] buffer_queue - append to queued\n",
674 buf, buf->vb.i);
675
676 } else if (list_empty(&q->active)) {
677 list_add_tail(&buf->vb.queue,&q->active);
678 start_video_dma(dev, q, buf);
Brandon Philips0fc06862007-11-06 20:02:36 -0300679 buf->vb.state = VIDEOBUF_ACTIVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 buf->count = q->count++;
681 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
682 dprintk(2,"[%p/%d] buffer_queue - first active\n",
683 buf, buf->vb.i);
684
685 } else {
686 prev = list_entry(q->active.prev, struct cx88_buffer, vb.queue);
687 if (prev->vb.width == buf->vb.width &&
688 prev->vb.height == buf->vb.height &&
689 prev->fmt == buf->fmt) {
690 list_add_tail(&buf->vb.queue,&q->active);
Brandon Philips0fc06862007-11-06 20:02:36 -0300691 buf->vb.state = VIDEOBUF_ACTIVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 buf->count = q->count++;
693 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
694 dprintk(2,"[%p/%d] buffer_queue - append to active\n",
695 buf, buf->vb.i);
696
697 } else {
698 list_add_tail(&buf->vb.queue,&q->queued);
Brandon Philips0fc06862007-11-06 20:02:36 -0300699 buf->vb.state = VIDEOBUF_QUEUED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 dprintk(2,"[%p/%d] buffer_queue - first queued\n",
701 buf, buf->vb.i);
702 }
703 }
704}
705
706static void buffer_release(struct videobuf_queue *q, struct videobuf_buffer *vb)
707{
708 struct cx88_buffer *buf = container_of(vb,struct cx88_buffer,vb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709
Mauro Carvalho Chehabc7b0ac02006-03-10 12:29:15 -0300710 cx88_free_buffer(q,buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711}
712
Adrian Bunk408b6642005-05-01 08:59:29 -0700713static struct videobuf_queue_ops cx8800_video_qops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 .buf_setup = buffer_setup,
715 .buf_prepare = buffer_prepare,
716 .buf_queue = buffer_queue,
717 .buf_release = buffer_release,
718};
719
720/* ------------------------------------------------------------------ */
721
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722
723/* ------------------------------------------------------------------ */
724
725static struct videobuf_queue* get_queue(struct cx8800_fh *fh)
726{
727 switch (fh->type) {
728 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
729 return &fh->vidq;
730 case V4L2_BUF_TYPE_VBI_CAPTURE:
731 return &fh->vbiq;
732 default:
733 BUG();
734 return NULL;
735 }
736}
737
738static int get_ressource(struct cx8800_fh *fh)
739{
740 switch (fh->type) {
741 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
742 return RESOURCE_VIDEO;
743 case V4L2_BUF_TYPE_VBI_CAPTURE:
744 return RESOURCE_VBI;
745 default:
746 BUG();
747 return 0;
748 }
749}
750
Hans Verkuilbec43662008-12-30 06:58:20 -0300751static int video_open(struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752{
Laurent Pinchart63b0d5a2009-12-10 11:44:04 -0200753 struct video_device *vdev = video_devdata(file);
754 struct cx8800_dev *dev = video_drvdata(file);
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700755 struct cx88_core *core;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 struct cx8800_fh *fh;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 enum v4l2_buf_type type = 0;
758 int radio = 0;
759
Laurent Pinchart63b0d5a2009-12-10 11:44:04 -0200760 switch (vdev->vfl_type) {
761 case VFL_TYPE_GRABBER:
762 type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
763 break;
764 case VFL_TYPE_VBI:
765 type = V4L2_BUF_TYPE_VBI_CAPTURE;
766 break;
767 case VFL_TYPE_RADIO:
768 radio = 1;
769 break;
770 }
771
Hans Verkuild56dc612008-07-30 08:43:36 -0300772 lock_kernel();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700774 core = dev->core;
775
Laurent Pinchart50462eb2009-12-10 11:47:13 -0200776 dprintk(1, "open dev=%s radio=%d type=%s\n",
777 video_device_node_name(vdev), radio, v4l2_type_names[type]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778
779 /* allocate + initialize per filehandle data */
Panagiotis Issaris74081872006-01-11 19:40:56 -0200780 fh = kzalloc(sizeof(*fh),GFP_KERNEL);
Hans Verkuild56dc612008-07-30 08:43:36 -0300781 if (NULL == fh) {
782 unlock_kernel();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783 return -ENOMEM;
Hans Verkuild56dc612008-07-30 08:43:36 -0300784 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 file->private_data = fh;
786 fh->dev = dev;
787 fh->radio = radio;
788 fh->type = type;
789 fh->width = 320;
790 fh->height = 240;
791 fh->fmt = format_by_fourcc(V4L2_PIX_FMT_BGR24);
792
Guennadi Liakhovetski07051352008-04-22 14:42:13 -0300793 videobuf_queue_sg_init(&fh->vidq, &cx8800_video_qops,
794 &dev->pci->dev, &dev->slock,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795 V4L2_BUF_TYPE_VIDEO_CAPTURE,
796 V4L2_FIELD_INTERLACED,
797 sizeof(struct cx88_buffer),
798 fh);
Guennadi Liakhovetski07051352008-04-22 14:42:13 -0300799 videobuf_queue_sg_init(&fh->vbiq, &cx8800_vbi_qops,
800 &dev->pci->dev, &dev->slock,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801 V4L2_BUF_TYPE_VBI_CAPTURE,
802 V4L2_FIELD_SEQ_TB,
803 sizeof(struct cx88_buffer),
804 fh);
805
806 if (fh->radio) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807 dprintk(1,"video_open: setting radio device\n");
Trent Piepho6a59d642007-08-15 14:41:57 -0300808 cx_write(MO_GP3_IO, core->board.radio.gpio3);
809 cx_write(MO_GP0_IO, core->board.radio.gpio0);
810 cx_write(MO_GP1_IO, core->board.radio.gpio1);
811 cx_write(MO_GP2_IO, core->board.radio.gpio2);
Darron Broad430189d2008-10-15 14:18:42 -0300812 if (core->board.radio.audioroute) {
813 if(core->board.audio_chip &&
814 core->board.audio_chip == V4L2_IDENT_WM8775) {
Hans Verkuil5325b422009-04-02 11:26:22 -0300815 call_all(core, audio, s_routing,
816 core->board.radio.audioroute, 0, 0);
Darron Broad430189d2008-10-15 14:18:42 -0300817 }
818 /* "I2S ADC mode" */
819 core->tvaudio = WW_I2SADC;
820 cx88_set_tvaudio(core);
821 } else {
822 /* FM Mode */
823 core->tvaudio = WW_FM;
824 cx88_set_tvaudio(core);
825 cx88_set_stereo(core,V4L2_TUNER_MODE_STEREO,1);
826 }
Hans Verkuilb8341e12009-03-29 08:26:01 -0300827 call_all(core, tuner, s_radio);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 }
Hans Verkuild56dc612008-07-30 08:43:36 -0300829 unlock_kernel();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830
Darron Broad3e010842008-09-25 16:51:11 -0300831 atomic_inc(&core->users);
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;
Figo.zhang9fd64182009-06-16 13:31:29 -0300863 unsigned int rc = POLLERR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864
865 if (V4L2_BUF_TYPE_VBI_CAPTURE == fh->type) {
866 if (!res_get(fh->dev,fh,RESOURCE_VBI))
867 return POLLERR;
868 return videobuf_poll_stream(file, &fh->vbiq, wait);
869 }
870
Figo.zhang9fd64182009-06-16 13:31:29 -0300871 mutex_lock(&fh->vidq.vb_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 if (res_check(fh,RESOURCE_VIDEO)) {
873 /* streaming capture */
874 if (list_empty(&fh->vidq.stream))
Figo.zhang9fd64182009-06-16 13:31:29 -0300875 goto done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876 buf = list_entry(fh->vidq.stream.next,struct cx88_buffer,vb.stream);
877 } else {
878 /* read() capture */
879 buf = (struct cx88_buffer*)fh->vidq.read_buf;
880 if (NULL == buf)
Figo.zhang9fd64182009-06-16 13:31:29 -0300881 goto done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 }
883 poll_wait(file, &buf->vb.done, wait);
Brandon Philips0fc06862007-11-06 20:02:36 -0300884 if (buf->vb.state == VIDEOBUF_DONE ||
885 buf->vb.state == VIDEOBUF_ERROR)
Figo.zhang9fd64182009-06-16 13:31:29 -0300886 rc = POLLIN|POLLRDNORM;
887 else
888 rc = 0;
889done:
890 mutex_unlock(&fh->vidq.vb_lock);
891 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892}
893
Hans Verkuilbec43662008-12-30 06:58:20 -0300894static int video_release(struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895{
896 struct cx8800_fh *fh = file->private_data;
897 struct cx8800_dev *dev = fh->dev;
898
899 /* turn off overlay */
900 if (res_check(fh, RESOURCE_OVERLAY)) {
901 /* FIXME */
902 res_free(dev,fh,RESOURCE_OVERLAY);
903 }
904
905 /* stop video capture */
906 if (res_check(fh, RESOURCE_VIDEO)) {
907 videobuf_queue_cancel(&fh->vidq);
908 res_free(dev,fh,RESOURCE_VIDEO);
909 }
910 if (fh->vidq.read_buf) {
911 buffer_release(&fh->vidq,fh->vidq.read_buf);
912 kfree(fh->vidq.read_buf);
913 }
914
915 /* stop vbi capture */
916 if (res_check(fh, RESOURCE_VBI)) {
Brandon Philips053fcb62007-11-13 20:11:26 -0300917 videobuf_stop(&fh->vbiq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918 res_free(dev,fh,RESOURCE_VBI);
919 }
920
921 videobuf_mmap_free(&fh->vidq);
922 videobuf_mmap_free(&fh->vbiq);
923 file->private_data = NULL;
924 kfree(fh);
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700925
Devin Heitmueller06f837c2009-04-28 14:35:27 -0300926 mutex_lock(&dev->core->lock);
Darron Broad3e010842008-09-25 16:51:11 -0300927 if(atomic_dec_and_test(&dev->core->users))
Laurent Pinchart622b8282009-10-05 10:48:17 -0300928 call_all(dev->core, core, s_power, 0);
Devin Heitmueller06f837c2009-04-28 14:35:27 -0300929 mutex_unlock(&dev->core->lock);
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700930
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931 return 0;
932}
933
934static int
935video_mmap(struct file *file, struct vm_area_struct * vma)
936{
937 struct cx8800_fh *fh = file->private_data;
938
939 return videobuf_mmap_mapper(get_queue(fh), vma);
940}
941
942/* ------------------------------------------------------------------ */
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -0300943/* VIDEO CTRL IOCTLS */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944
Mauro Carvalho Chehab54da49f2007-01-20 13:58:26 -0300945int cx88_get_control (struct cx88_core *core, struct v4l2_control *ctl)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946{
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -0300947 struct cx88_ctrl *c = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948 u32 value;
949 int i;
950
951 for (i = 0; i < CX8800_CTLS; i++)
952 if (cx8800_ctls[i].v.id == ctl->id)
953 c = &cx8800_ctls[i];
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -0300954 if (unlikely(NULL == c))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955 return -EINVAL;
956
957 value = c->sreg ? cx_sread(c->sreg) : cx_read(c->reg);
958 switch (ctl->id) {
959 case V4L2_CID_AUDIO_BALANCE:
Marcin Rudowski9f9c9072006-03-12 00:03:47 -0300960 ctl->value = ((value & 0x7f) < 0x40) ? ((value & 0x7f) + 0x40)
961 : (0x7f - (value & 0x7f));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962 break;
963 case V4L2_CID_AUDIO_VOLUME:
964 ctl->value = 0x3f - (value & 0x3f);
965 break;
966 default:
967 ctl->value = ((value + (c->off << c->shift)) & c->mask) >> c->shift;
968 break;
969 }
Ian Pickworth6457af52006-02-27 00:09:45 -0300970 dprintk(1,"get_control id=0x%X(%s) ctrl=0x%02x, reg=0x%02x val=0x%02x (mask 0x%02x)%s\n",
971 ctl->id, c->v.name, ctl->value, c->reg,
972 value,c->mask, c->sreg ? " [shadowed]" : "");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973 return 0;
974}
Mauro Carvalho Chehab54da49f2007-01-20 13:58:26 -0300975EXPORT_SYMBOL(cx88_get_control);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976
Mauro Carvalho Chehab54da49f2007-01-20 13:58:26 -0300977int cx88_set_control(struct cx88_core *core, struct v4l2_control *ctl)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979 struct cx88_ctrl *c = NULL;
Mauro Carvalho Chehab70f00042006-01-09 15:25:26 -0200980 u32 value,mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981 int i;
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -0300982
Mauro Carvalho Chehab70f00042006-01-09 15:25:26 -0200983 for (i = 0; i < CX8800_CTLS; i++) {
984 if (cx8800_ctls[i].v.id == ctl->id) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985 c = &cx8800_ctls[i];
Mauro Carvalho Chehab70f00042006-01-09 15:25:26 -0200986 }
987 }
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -0300988 if (unlikely(NULL == c))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989 return -EINVAL;
990
991 if (ctl->value < c->v.minimum)
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700992 ctl->value = c->v.minimum;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993 if (ctl->value > c->v.maximum)
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700994 ctl->value = c->v.maximum;
Mauro Carvalho Chehab70f00042006-01-09 15:25:26 -0200995 mask=c->mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996 switch (ctl->id) {
997 case V4L2_CID_AUDIO_BALANCE:
Marcin Rudowski9f9c9072006-03-12 00:03:47 -0300998 value = (ctl->value < 0x40) ? (0x7f - ctl->value) : (ctl->value - 0x40);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999 break;
1000 case V4L2_CID_AUDIO_VOLUME:
1001 value = 0x3f - (ctl->value & 0x3f);
1002 break;
1003 case V4L2_CID_SATURATION:
1004 /* special v_sat handling */
Mauro Carvalho Chehab70f00042006-01-09 15:25:26 -02001005
1006 value = ((ctl->value - c->off) << c->shift) & c->mask;
1007
Mauro Carvalho Chehab63ab1bd2007-01-20 13:58:33 -03001008 if (core->tvnorm & V4L2_STD_SECAM) {
Mauro Carvalho Chehab70f00042006-01-09 15:25:26 -02001009 /* For SECAM, both U and V sat should be equal */
1010 value=value<<8|value;
1011 } else {
1012 /* Keeps U Saturation proportional to V Sat */
1013 value=(value*0x5a)/0x7f<<8|value;
1014 }
1015 mask=0xffff;
1016 break;
Frej Drejhammar6d042032008-03-23 22:43:21 -03001017 case V4L2_CID_CHROMA_AGC:
1018 /* Do not allow chroma AGC to be enabled for SECAM */
1019 value = ((ctl->value - c->off) << c->shift) & c->mask;
1020 if (core->tvnorm & V4L2_STD_SECAM && value)
1021 return -EINVAL;
1022 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 default:
1024 value = ((ctl->value - c->off) << c->shift) & c->mask;
1025 break;
1026 }
Ian Pickworth6457af52006-02-27 00:09:45 -03001027 dprintk(1,"set_control id=0x%X(%s) ctrl=0x%02x, reg=0x%02x val=0x%02x (mask 0x%02x)%s\n",
1028 ctl->id, c->v.name, ctl->value, c->reg, value,
1029 mask, c->sreg ? " [shadowed]" : "");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 if (c->sreg) {
Mauro Carvalho Chehab70f00042006-01-09 15:25:26 -02001031 cx_sandor(c->sreg, c->reg, mask, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032 } else {
Mauro Carvalho Chehab70f00042006-01-09 15:25:26 -02001033 cx_andor(c->reg, mask, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034 }
1035 return 0;
1036}
Mauro Carvalho Chehab54da49f2007-01-20 13:58:26 -03001037EXPORT_SYMBOL(cx88_set_control);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001039static void init_controls(struct cx88_core *core)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040{
Mauro Carvalho Chehab70f00042006-01-09 15:25:26 -02001041 struct v4l2_control ctrl;
1042 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043
Mauro Carvalho Chehab70f00042006-01-09 15:25:26 -02001044 for (i = 0; i < CX8800_CTLS; i++) {
1045 ctrl.id=cx8800_ctls[i].v.id;
Marcin Rudowski9f9c9072006-03-12 00:03:47 -03001046 ctrl.value=cx8800_ctls[i].v.default_value;
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001047
Mauro Carvalho Chehab54da49f2007-01-20 13:58:26 -03001048 cx88_set_control(core, &ctrl);
Mauro Carvalho Chehab70f00042006-01-09 15:25:26 -02001049 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050}
1051
1052/* ------------------------------------------------------------------ */
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001053/* VIDEO IOCTLS */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054
Hans Verkuil78b526a2008-05-28 12:16:41 -03001055static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001056 struct v4l2_format *f)
1057{
1058 struct cx8800_fh *fh = priv;
1059
1060 f->fmt.pix.width = fh->width;
1061 f->fmt.pix.height = fh->height;
1062 f->fmt.pix.field = fh->vidq.field;
1063 f->fmt.pix.pixelformat = fh->fmt->fourcc;
1064 f->fmt.pix.bytesperline =
1065 (f->fmt.pix.width * fh->fmt->depth) >> 3;
1066 f->fmt.pix.sizeimage =
1067 f->fmt.pix.height * f->fmt.pix.bytesperline;
1068 return 0;
1069}
1070
Hans Verkuil78b526a2008-05-28 12:16:41 -03001071static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072 struct v4l2_format *f)
1073{
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001074 struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core;
1075 struct cx8800_fmt *fmt;
1076 enum v4l2_field field;
1077 unsigned int maxw, maxh;
1078
1079 fmt = format_by_fourcc(f->fmt.pix.pixelformat);
1080 if (NULL == fmt)
1081 return -EINVAL;
1082
1083 field = f->fmt.pix.field;
1084 maxw = norm_maxw(core->tvnorm);
1085 maxh = norm_maxh(core->tvnorm);
1086
1087 if (V4L2_FIELD_ANY == field) {
1088 field = (f->fmt.pix.height > maxh/2)
1089 ? V4L2_FIELD_INTERLACED
1090 : V4L2_FIELD_BOTTOM;
1091 }
1092
1093 switch (field) {
1094 case V4L2_FIELD_TOP:
1095 case V4L2_FIELD_BOTTOM:
1096 maxh = maxh / 2;
1097 break;
1098 case V4L2_FIELD_INTERLACED:
1099 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100 default:
1101 return -EINVAL;
1102 }
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001103
1104 f->fmt.pix.field = field;
Trent Piepho4b899452009-05-30 21:45:46 -03001105 v4l_bound_align_image(&f->fmt.pix.width, 48, maxw, 2,
1106 &f->fmt.pix.height, 32, maxh, 0, 0);
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001107 f->fmt.pix.bytesperline =
1108 (f->fmt.pix.width * fmt->depth) >> 3;
1109 f->fmt.pix.sizeimage =
1110 f->fmt.pix.height * f->fmt.pix.bytesperline;
1111
1112 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113}
1114
Hans Verkuil78b526a2008-05-28 12:16:41 -03001115static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001116 struct v4l2_format *f)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117{
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001118 struct cx8800_fh *fh = priv;
Hans Verkuil78b526a2008-05-28 12:16:41 -03001119 int err = vidioc_try_fmt_vid_cap (file,priv,f);
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001120
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001121 if (0 != err)
1122 return err;
1123 fh->fmt = format_by_fourcc(f->fmt.pix.pixelformat);
1124 fh->width = f->fmt.pix.width;
1125 fh->height = f->fmt.pix.height;
1126 fh->vidq.field = f->fmt.pix.field;
1127 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128}
1129
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001130static int vidioc_querycap (struct file *file, void *priv,
1131 struct v4l2_capability *cap)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132{
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001133 struct cx8800_dev *dev = ((struct cx8800_fh *)priv)->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134 struct cx88_core *core = dev->core;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001136 strcpy(cap->driver, "cx8800");
Trent Piepho6a59d642007-08-15 14:41:57 -03001137 strlcpy(cap->card, core->board.name, sizeof(cap->card));
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001138 sprintf(cap->bus_info,"PCI:%s",pci_name(dev->pci));
1139 cap->version = CX88_VERSION_CODE;
1140 cap->capabilities =
1141 V4L2_CAP_VIDEO_CAPTURE |
1142 V4L2_CAP_READWRITE |
1143 V4L2_CAP_STREAMING |
1144 V4L2_CAP_VBI_CAPTURE;
Trent Piepho6a59d642007-08-15 14:41:57 -03001145 if (UNSET != core->board.tuner_type)
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001146 cap->capabilities |= V4L2_CAP_TUNER;
1147 return 0;
1148}
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001149
Hans Verkuil78b526a2008-05-28 12:16:41 -03001150static int vidioc_enum_fmt_vid_cap (struct file *file, void *priv,
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001151 struct v4l2_fmtdesc *f)
1152{
1153 if (unlikely(f->index >= ARRAY_SIZE(formats)))
1154 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001156 strlcpy(f->description,formats[f->index].name,sizeof(f->description));
1157 f->pixelformat = formats[f->index].fourcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001159 return 0;
1160}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161
Mauro Carvalho Chehab0dfa9ab2006-08-08 09:10:10 -03001162#ifdef CONFIG_VIDEO_V4L1_COMPAT
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001163static int vidiocgmbuf (struct file *file, void *priv, struct video_mbuf *mbuf)
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001164{
Mauro Carvalho Chehabc1accaa2007-08-23 16:37:49 -03001165 struct cx8800_fh *fh = priv;
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001166
Mauro Carvalho Chehabc1accaa2007-08-23 16:37:49 -03001167 return videobuf_cgmbuf (get_queue(fh), mbuf, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168}
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001169#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001171static int vidioc_reqbufs (struct file *file, void *priv, struct v4l2_requestbuffers *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172{
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001173 struct cx8800_fh *fh = priv;
1174 return (videobuf_reqbufs(get_queue(fh), p));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175}
1176
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001177static int vidioc_querybuf (struct file *file, void *priv, struct v4l2_buffer *p)
1178{
1179 struct cx8800_fh *fh = priv;
1180 return (videobuf_querybuf(get_queue(fh), p));
1181}
1182
1183static int vidioc_qbuf (struct file *file, void *priv, struct v4l2_buffer *p)
1184{
1185 struct cx8800_fh *fh = priv;
1186 return (videobuf_qbuf(get_queue(fh), p));
1187}
1188
1189static int vidioc_dqbuf (struct file *file, void *priv, struct v4l2_buffer *p)
1190{
1191 struct cx8800_fh *fh = priv;
1192 return (videobuf_dqbuf(get_queue(fh), p,
1193 file->f_flags & O_NONBLOCK));
1194}
1195
1196static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
1197{
1198 struct cx8800_fh *fh = priv;
1199 struct cx8800_dev *dev = fh->dev;
1200
Rafael Dinizb058e3f2008-10-24 23:07:57 -03001201 /* We should remember that this driver also supports teletext, */
1202 /* so we have to test if the v4l2_buf_type is VBI capture data. */
1203 if (unlikely((fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) &&
1204 (fh->type != V4L2_BUF_TYPE_VBI_CAPTURE)))
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001205 return -EINVAL;
Rafael Dinizb058e3f2008-10-24 23:07:57 -03001206
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001207 if (unlikely(i != fh->type))
1208 return -EINVAL;
1209
1210 if (unlikely(!res_get(dev,fh,get_ressource(fh))))
1211 return -EBUSY;
1212 return videobuf_streamon(get_queue(fh));
1213}
1214
1215static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
1216{
1217 struct cx8800_fh *fh = priv;
1218 struct cx8800_dev *dev = fh->dev;
1219 int err, res;
1220
Rafael Dinizb058e3f2008-10-24 23:07:57 -03001221 if ((fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) &&
1222 (fh->type != V4L2_BUF_TYPE_VBI_CAPTURE))
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001223 return -EINVAL;
Rafael Dinizb058e3f2008-10-24 23:07:57 -03001224
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001225 if (i != fh->type)
1226 return -EINVAL;
1227
1228 res = get_ressource(fh);
1229 err = videobuf_streamoff(get_queue(fh));
1230 if (err < 0)
1231 return err;
1232 res_free(dev,fh,res);
1233 return 0;
1234}
1235
Mauro Carvalho Chehab63ab1bd2007-01-20 13:58:33 -03001236static int vidioc_s_std (struct file *file, void *priv, v4l2_std_id *tvnorms)
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001237{
1238 struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core;
1239
1240 mutex_lock(&core->lock);
Mauro Carvalho Chehab63ab1bd2007-01-20 13:58:33 -03001241 cx88_set_tvnorm(core,*tvnorms);
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001242 mutex_unlock(&core->lock);
Mauro Carvalho Chehab63ab1bd2007-01-20 13:58:33 -03001243
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001244 return 0;
1245}
1246
1247/* only one input in this sample driver */
Mauro Carvalho Chehab54da49f2007-01-20 13:58:26 -03001248int cx88_enum_input (struct cx88_core *core,struct v4l2_input *i)
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001249{
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001250 static const char *iname[] = {
1251 [ CX88_VMUX_COMPOSITE1 ] = "Composite1",
1252 [ CX88_VMUX_COMPOSITE2 ] = "Composite2",
1253 [ CX88_VMUX_COMPOSITE3 ] = "Composite3",
1254 [ CX88_VMUX_COMPOSITE4 ] = "Composite4",
1255 [ CX88_VMUX_SVIDEO ] = "S-Video",
1256 [ CX88_VMUX_TELEVISION ] = "Television",
1257 [ CX88_VMUX_CABLE ] = "Cable TV",
1258 [ CX88_VMUX_DVB ] = "DVB",
1259 [ CX88_VMUX_DEBUG ] = "for debug only",
1260 };
Trent Piephof3334bc2009-03-04 01:21:03 -03001261 unsigned int n = i->index;
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001262
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001263 if (n >= 4)
1264 return -EINVAL;
Trent Piepho6a59d642007-08-15 14:41:57 -03001265 if (0 == INPUT(n).type)
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001266 return -EINVAL;
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001267 i->type = V4L2_INPUT_TYPE_CAMERA;
Trent Piepho6a59d642007-08-15 14:41:57 -03001268 strcpy(i->name,iname[INPUT(n).type]);
1269 if ((CX88_VMUX_TELEVISION == INPUT(n).type) ||
Julia Lawall473d8022010-08-05 17:22:44 -03001270 (CX88_VMUX_CABLE == INPUT(n).type)) {
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001271 i->type = V4L2_INPUT_TYPE_TUNER;
Mauro Carvalho Chehab63ab1bd2007-01-20 13:58:33 -03001272 i->std = CX88_NORMS;
Julia Lawall473d8022010-08-05 17:22:44 -03001273 }
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001274 return 0;
1275}
Mauro Carvalho Chehab54da49f2007-01-20 13:58:26 -03001276EXPORT_SYMBOL(cx88_enum_input);
1277
1278static int vidioc_enum_input (struct file *file, void *priv,
1279 struct v4l2_input *i)
1280{
1281 struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core;
1282 return cx88_enum_input (core,i);
1283}
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001284
1285static int vidioc_g_input (struct file *file, void *priv, unsigned int *i)
1286{
1287 struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core;
1288
1289 *i = core->input;
1290 return 0;
1291}
1292
1293static int vidioc_s_input (struct file *file, void *priv, unsigned int i)
1294{
1295 struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core;
1296
1297 if (i >= 4)
1298 return -EINVAL;
1299
1300 mutex_lock(&core->lock);
1301 cx88_newstation(core);
Mauro Carvalho Chehabe90311a2007-01-20 13:58:29 -03001302 cx88_video_mux(core,i);
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001303 mutex_unlock(&core->lock);
1304 return 0;
1305}
1306
1307
1308
1309static int vidioc_queryctrl (struct file *file, void *priv,
1310 struct v4l2_queryctrl *qctrl)
1311{
Frej Drejhammar6d042032008-03-23 22:43:21 -03001312 struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core;
1313
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001314 qctrl->id = v4l2_ctrl_next(ctrl_classes, qctrl->id);
1315 if (unlikely(qctrl->id == 0))
1316 return -EINVAL;
Frej Drejhammar6d042032008-03-23 22:43:21 -03001317 return cx8800_ctrl_query(core, qctrl);
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001318}
1319
Mauro Carvalho Chehab54da49f2007-01-20 13:58:26 -03001320static int vidioc_g_ctrl (struct file *file, void *priv,
1321 struct v4l2_control *ctl)
1322{
1323 struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core;
1324 return
1325 cx88_get_control(core,ctl);
1326}
1327
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001328static int vidioc_s_ctrl (struct file *file, void *priv,
1329 struct v4l2_control *ctl)
1330{
1331 struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core;
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001332 return
Mauro Carvalho Chehab54da49f2007-01-20 13:58:26 -03001333 cx88_set_control(core,ctl);
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001334}
1335
1336static int vidioc_g_tuner (struct file *file, void *priv,
1337 struct v4l2_tuner *t)
1338{
1339 struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core;
1340 u32 reg;
1341
Trent Piepho6a59d642007-08-15 14:41:57 -03001342 if (unlikely(UNSET == core->board.tuner_type))
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001343 return -EINVAL;
Mauro Carvalho Chehab243d8c02007-01-20 13:58:36 -03001344 if (0 != t->index)
1345 return -EINVAL;
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001346
1347 strcpy(t->name, "Television");
1348 t->type = V4L2_TUNER_ANALOG_TV;
1349 t->capability = V4L2_TUNER_CAP_NORM;
1350 t->rangehigh = 0xffffffffUL;
1351
1352 cx88_get_stereo(core ,t);
1353 reg = cx_read(MO_DEVICE_STATUS);
1354 t->signal = (reg & (1<<5)) ? 0xffff : 0x0000;
1355 return 0;
1356}
1357
1358static int vidioc_s_tuner (struct file *file, void *priv,
1359 struct v4l2_tuner *t)
1360{
1361 struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core;
1362
Trent Piepho6a59d642007-08-15 14:41:57 -03001363 if (UNSET == core->board.tuner_type)
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001364 return -EINVAL;
1365 if (0 != t->index)
1366 return -EINVAL;
1367
1368 cx88_set_stereo(core, t->audmode, 1);
1369 return 0;
1370}
1371
1372static int vidioc_g_frequency (struct file *file, void *priv,
1373 struct v4l2_frequency *f)
1374{
1375 struct cx8800_fh *fh = priv;
1376 struct cx88_core *core = fh->dev->core;
1377
Trent Piepho6a59d642007-08-15 14:41:57 -03001378 if (unlikely(UNSET == core->board.tuner_type))
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001379 return -EINVAL;
1380
1381 /* f->type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; */
1382 f->type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
1383 f->frequency = core->freq;
1384
Hans Verkuilb8341e12009-03-29 08:26:01 -03001385 call_all(core, tuner, g_frequency, f);
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001386
1387 return 0;
1388}
1389
Mauro Carvalho Chehab54da49f2007-01-20 13:58:26 -03001390int cx88_set_freq (struct cx88_core *core,
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001391 struct v4l2_frequency *f)
1392{
Trent Piepho6a59d642007-08-15 14:41:57 -03001393 if (unlikely(UNSET == core->board.tuner_type))
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001394 return -EINVAL;
1395 if (unlikely(f->tuner != 0))
1396 return -EINVAL;
Mauro Carvalho Chehab54da49f2007-01-20 13:58:26 -03001397
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001398 mutex_lock(&core->lock);
1399 core->freq = f->frequency;
1400 cx88_newstation(core);
Hans Verkuilb8341e12009-03-29 08:26:01 -03001401 call_all(core, tuner, s_frequency, f);
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001402
1403 /* When changing channels it is required to reset TVAUDIO */
1404 msleep (10);
1405 cx88_set_tvaudio(core);
1406
1407 mutex_unlock(&core->lock);
Mauro Carvalho Chehab54da49f2007-01-20 13:58:26 -03001408
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001409 return 0;
1410}
Mauro Carvalho Chehab54da49f2007-01-20 13:58:26 -03001411EXPORT_SYMBOL(cx88_set_freq);
1412
1413static int vidioc_s_frequency (struct file *file, void *priv,
1414 struct v4l2_frequency *f)
1415{
1416 struct cx8800_fh *fh = priv;
1417 struct cx88_core *core = fh->dev->core;
1418
1419 if (unlikely(0 == fh->radio && f->type != V4L2_TUNER_ANALOG_TV))
1420 return -EINVAL;
1421 if (unlikely(1 == fh->radio && f->type != V4L2_TUNER_RADIO))
1422 return -EINVAL;
1423
1424 return
1425 cx88_set_freq (core,f);
1426}
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001427
Trent Piephodbbff482007-01-22 23:31:53 -03001428#ifdef CONFIG_VIDEO_ADV_DEBUG
1429static int vidioc_g_register (struct file *file, void *fh,
Hans Verkuilaecde8b2008-12-30 07:14:19 -03001430 struct v4l2_dbg_register *reg)
Trent Piephodbbff482007-01-22 23:31:53 -03001431{
1432 struct cx88_core *core = ((struct cx8800_fh*)fh)->dev->core;
1433
Hans Verkuilaecde8b2008-12-30 07:14:19 -03001434 if (!v4l2_chip_match_host(&reg->match))
Trent Piephodbbff482007-01-22 23:31:53 -03001435 return -EINVAL;
1436 /* cx2388x has a 24-bit register space */
Hans Verkuilaecde8b2008-12-30 07:14:19 -03001437 reg->val = cx_read(reg->reg & 0xffffff);
1438 reg->size = 4;
Trent Piephodbbff482007-01-22 23:31:53 -03001439 return 0;
1440}
1441
1442static int vidioc_s_register (struct file *file, void *fh,
Hans Verkuilaecde8b2008-12-30 07:14:19 -03001443 struct v4l2_dbg_register *reg)
Trent Piephodbbff482007-01-22 23:31:53 -03001444{
1445 struct cx88_core *core = ((struct cx8800_fh*)fh)->dev->core;
1446
Hans Verkuilaecde8b2008-12-30 07:14:19 -03001447 if (!v4l2_chip_match_host(&reg->match))
Trent Piephodbbff482007-01-22 23:31:53 -03001448 return -EINVAL;
Hans Verkuilaecde8b2008-12-30 07:14:19 -03001449 cx_write(reg->reg & 0xffffff, reg->val);
Trent Piephodbbff482007-01-22 23:31:53 -03001450 return 0;
1451}
1452#endif
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001453
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454/* ----------------------------------------------------------- */
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001455/* RADIO ESPECIFIC IOCTLS */
1456/* ----------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001458static int radio_querycap (struct file *file, void *priv,
1459 struct v4l2_capability *cap)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460{
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001461 struct cx8800_dev *dev = ((struct cx8800_fh *)priv)->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462 struct cx88_core *core = dev->core;
1463
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001464 strcpy(cap->driver, "cx8800");
Trent Piepho6a59d642007-08-15 14:41:57 -03001465 strlcpy(cap->card, core->board.name, sizeof(cap->card));
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001466 sprintf(cap->bus_info,"PCI:%s", pci_name(dev->pci));
1467 cap->version = CX88_VERSION_CODE;
1468 cap->capabilities = V4L2_CAP_TUNER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469 return 0;
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001470}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001472static int radio_g_tuner (struct file *file, void *priv,
1473 struct v4l2_tuner *t)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474{
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001475 struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core;
1476
1477 if (unlikely(t->index > 0))
1478 return -EINVAL;
1479
1480 strcpy(t->name, "Radio");
1481 t->type = V4L2_TUNER_RADIO;
1482
Hans Verkuilb8341e12009-03-29 08:26:01 -03001483 call_all(core, tuner, g_tuner, t);
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001484 return 0;
1485}
1486
1487static int radio_enum_input (struct file *file, void *priv,
1488 struct v4l2_input *i)
1489{
1490 if (i->index != 0)
1491 return -EINVAL;
1492 strcpy(i->name,"Radio");
1493 i->type = V4L2_INPUT_TYPE_TUNER;
1494
1495 return 0;
1496}
1497
1498static int radio_g_audio (struct file *file, void *priv, struct v4l2_audio *a)
1499{
1500 if (unlikely(a->index))
1501 return -EINVAL;
1502
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001503 strcpy(a->name,"Radio");
1504 return 0;
1505}
1506
1507/* FIXME: Should add a standard for radio */
1508
1509static int radio_s_tuner (struct file *file, void *priv,
1510 struct v4l2_tuner *t)
1511{
1512 struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core;
1513
1514 if (0 != t->index)
1515 return -EINVAL;
1516
Hans Verkuilb8341e12009-03-29 08:26:01 -03001517 call_all(core, tuner, s_tuner, t);
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001518
1519 return 0;
1520}
1521
1522static int radio_s_audio (struct file *file, void *fh,
1523 struct v4l2_audio *a)
1524{
1525 return 0;
1526}
1527
1528static int radio_s_input (struct file *file, void *fh, unsigned int i)
1529{
1530 return 0;
1531}
1532
1533static int radio_queryctrl (struct file *file, void *priv,
1534 struct v4l2_queryctrl *c)
1535{
1536 int i;
1537
1538 if (c->id < V4L2_CID_BASE ||
1539 c->id >= V4L2_CID_LASTP1)
1540 return -EINVAL;
1541 if (c->id == V4L2_CID_AUDIO_MUTE) {
Dan Carpentera41b2ea2010-04-02 08:31:50 -03001542 for (i = 0; i < CX8800_CTLS; i++) {
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001543 if (cx8800_ctls[i].v.id == c->id)
1544 break;
Dan Carpentera41b2ea2010-04-02 08:31:50 -03001545 }
1546 if (i == CX8800_CTLS)
1547 return -EINVAL;
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001548 *c = cx8800_ctls[i].v;
1549 } else
1550 *c = no_ctl;
1551 return 0;
1552}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553
1554/* ----------------------------------------------------------- */
1555
1556static void cx8800_vid_timeout(unsigned long data)
1557{
1558 struct cx8800_dev *dev = (struct cx8800_dev*)data;
1559 struct cx88_core *core = dev->core;
1560 struct cx88_dmaqueue *q = &dev->vidq;
1561 struct cx88_buffer *buf;
1562 unsigned long flags;
1563
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001564 cx88_sram_channel_dump(core, &cx88_sram_channels[SRAM_CH21]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565
1566 cx_clear(MO_VID_DMACNTRL, 0x11);
1567 cx_clear(VID_CAPTURE_CONTROL, 0x06);
1568
1569 spin_lock_irqsave(&dev->slock,flags);
1570 while (!list_empty(&q->active)) {
1571 buf = list_entry(q->active.next, struct cx88_buffer, vb.queue);
1572 list_del(&buf->vb.queue);
Brandon Philips0fc06862007-11-06 20:02:36 -03001573 buf->vb.state = VIDEOBUF_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574 wake_up(&buf->vb.done);
1575 printk("%s/0: [%p/%d] timeout - dma=0x%08lx\n", core->name,
1576 buf, buf->vb.i, (unsigned long)buf->risc.dma);
1577 }
1578 restart_video_queue(dev,q);
1579 spin_unlock_irqrestore(&dev->slock,flags);
1580}
1581
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -07001582static char *cx88_vid_irqs[32] = {
1583 "y_risci1", "u_risci1", "v_risci1", "vbi_risc1",
1584 "y_risci2", "u_risci2", "v_risci2", "vbi_risc2",
1585 "y_oflow", "u_oflow", "v_oflow", "vbi_oflow",
1586 "y_sync", "u_sync", "v_sync", "vbi_sync",
1587 "opc_err", "par_err", "rip_err", "pci_abort",
1588};
1589
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590static void cx8800_vid_irq(struct cx8800_dev *dev)
1591{
1592 struct cx88_core *core = dev->core;
1593 u32 status, mask, count;
1594
1595 status = cx_read(MO_VID_INTSTAT);
1596 mask = cx_read(MO_VID_INTMSK);
1597 if (0 == (status & mask))
1598 return;
1599 cx_write(MO_VID_INTSTAT, status);
1600 if (irq_debug || (status & mask & ~0xff))
1601 cx88_print_irqbits(core->name, "irq vid",
Mauro Carvalho Chehab66623a02007-03-29 08:47:04 -03001602 cx88_vid_irqs, ARRAY_SIZE(cx88_vid_irqs),
1603 status, mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604
1605 /* risc op code error */
1606 if (status & (1 << 16)) {
1607 printk(KERN_WARNING "%s/0: video risc op code error\n",core->name);
1608 cx_clear(MO_VID_DMACNTRL, 0x11);
1609 cx_clear(VID_CAPTURE_CONTROL, 0x06);
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001610 cx88_sram_channel_dump(core, &cx88_sram_channels[SRAM_CH21]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611 }
1612
1613 /* risc1 y */
1614 if (status & 0x01) {
1615 spin_lock(&dev->slock);
1616 count = cx_read(MO_VIDY_GPCNT);
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001617 cx88_wakeup(core, &dev->vidq, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618 spin_unlock(&dev->slock);
1619 }
1620
1621 /* risc1 vbi */
1622 if (status & 0x08) {
1623 spin_lock(&dev->slock);
1624 count = cx_read(MO_VBI_GPCNT);
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001625 cx88_wakeup(core, &dev->vbiq, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626 spin_unlock(&dev->slock);
1627 }
1628
1629 /* risc2 y */
1630 if (status & 0x10) {
1631 dprintk(2,"stopper video\n");
1632 spin_lock(&dev->slock);
1633 restart_video_queue(dev,&dev->vidq);
1634 spin_unlock(&dev->slock);
1635 }
1636
1637 /* risc2 vbi */
1638 if (status & 0x80) {
1639 dprintk(2,"stopper vbi\n");
1640 spin_lock(&dev->slock);
1641 cx8800_restart_vbi_queue(dev,&dev->vbiq);
1642 spin_unlock(&dev->slock);
1643 }
1644}
1645
David Howells7d12e782006-10-05 14:55:46 +01001646static irqreturn_t cx8800_irq(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001647{
1648 struct cx8800_dev *dev = dev_id;
1649 struct cx88_core *core = dev->core;
1650 u32 status;
1651 int loop, handled = 0;
1652
1653 for (loop = 0; loop < 10; loop++) {
Trent Piepho8ddac9e2007-08-18 06:57:55 -03001654 status = cx_read(MO_PCI_INTSTAT) &
1655 (core->pci_irqmask | PCI_INT_VIDINT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656 if (0 == status)
1657 goto out;
1658 cx_write(MO_PCI_INTSTAT, status);
1659 handled = 1;
1660
1661 if (status & core->pci_irqmask)
1662 cx88_core_irq(core,status);
Trent Piepho8ddac9e2007-08-18 06:57:55 -03001663 if (status & PCI_INT_VIDINT)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664 cx8800_vid_irq(dev);
1665 };
1666 if (10 == loop) {
1667 printk(KERN_WARNING "%s/0: irq loop -- clearing mask\n",
1668 core->name);
1669 cx_write(MO_PCI_INTMSK,0);
1670 }
1671
1672 out:
1673 return IRQ_RETVAL(handled);
1674}
1675
1676/* ----------------------------------------------------------- */
1677/* exported stuff */
1678
Hans Verkuilbec43662008-12-30 06:58:20 -03001679static const struct v4l2_file_operations video_fops =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001680{
1681 .owner = THIS_MODULE,
1682 .open = video_open,
1683 .release = video_release,
1684 .read = video_read,
1685 .poll = video_poll,
1686 .mmap = video_mmap,
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001687 .ioctl = video_ioctl2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688};
1689
Hans Verkuila3998102008-07-21 02:57:38 -03001690static const struct v4l2_ioctl_ops video_ioctl_ops = {
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001691 .vidioc_querycap = vidioc_querycap,
Hans Verkuil78b526a2008-05-28 12:16:41 -03001692 .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
1693 .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
1694 .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
1695 .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
1696 .vidioc_g_fmt_vbi_cap = cx8800_vbi_fmt,
1697 .vidioc_try_fmt_vbi_cap = cx8800_vbi_fmt,
1698 .vidioc_s_fmt_vbi_cap = cx8800_vbi_fmt,
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001699 .vidioc_reqbufs = vidioc_reqbufs,
1700 .vidioc_querybuf = vidioc_querybuf,
1701 .vidioc_qbuf = vidioc_qbuf,
1702 .vidioc_dqbuf = vidioc_dqbuf,
1703 .vidioc_s_std = vidioc_s_std,
1704 .vidioc_enum_input = vidioc_enum_input,
1705 .vidioc_g_input = vidioc_g_input,
1706 .vidioc_s_input = vidioc_s_input,
1707 .vidioc_queryctrl = vidioc_queryctrl,
1708 .vidioc_g_ctrl = vidioc_g_ctrl,
1709 .vidioc_s_ctrl = vidioc_s_ctrl,
1710 .vidioc_streamon = vidioc_streamon,
1711 .vidioc_streamoff = vidioc_streamoff,
1712#ifdef CONFIG_VIDEO_V4L1_COMPAT
1713 .vidiocgmbuf = vidiocgmbuf,
1714#endif
1715 .vidioc_g_tuner = vidioc_g_tuner,
1716 .vidioc_s_tuner = vidioc_s_tuner,
1717 .vidioc_g_frequency = vidioc_g_frequency,
1718 .vidioc_s_frequency = vidioc_s_frequency,
Trent Piephodbbff482007-01-22 23:31:53 -03001719#ifdef CONFIG_VIDEO_ADV_DEBUG
1720 .vidioc_g_register = vidioc_g_register,
1721 .vidioc_s_register = vidioc_s_register,
1722#endif
Hans Verkuila3998102008-07-21 02:57:38 -03001723};
1724
1725static struct video_device cx8800_vbi_template;
1726
1727static struct video_device cx8800_video_template = {
1728 .name = "cx8800-video",
Hans Verkuila3998102008-07-21 02:57:38 -03001729 .fops = &video_fops,
Hans Verkuila3998102008-07-21 02:57:38 -03001730 .ioctl_ops = &video_ioctl_ops,
Mauro Carvalho Chehab63ab1bd2007-01-20 13:58:33 -03001731 .tvnorms = CX88_NORMS,
Trent Piephodbbff482007-01-22 23:31:53 -03001732 .current_norm = V4L2_STD_NTSC_M,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733};
1734
Hans Verkuilbec43662008-12-30 06:58:20 -03001735static const struct v4l2_file_operations radio_fops =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736{
1737 .owner = THIS_MODULE,
1738 .open = video_open,
1739 .release = video_release,
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001740 .ioctl = video_ioctl2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741};
1742
Hans Verkuila3998102008-07-21 02:57:38 -03001743static const struct v4l2_ioctl_ops radio_ioctl_ops = {
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001744 .vidioc_querycap = radio_querycap,
1745 .vidioc_g_tuner = radio_g_tuner,
1746 .vidioc_enum_input = radio_enum_input,
1747 .vidioc_g_audio = radio_g_audio,
1748 .vidioc_s_tuner = radio_s_tuner,
1749 .vidioc_s_audio = radio_s_audio,
1750 .vidioc_s_input = radio_s_input,
1751 .vidioc_queryctrl = radio_queryctrl,
1752 .vidioc_g_ctrl = vidioc_g_ctrl,
1753 .vidioc_s_ctrl = vidioc_s_ctrl,
1754 .vidioc_g_frequency = vidioc_g_frequency,
1755 .vidioc_s_frequency = vidioc_s_frequency,
Trent Piephoa75d2042007-08-01 00:13:28 -03001756#ifdef CONFIG_VIDEO_ADV_DEBUG
1757 .vidioc_g_register = vidioc_g_register,
1758 .vidioc_s_register = vidioc_s_register,
1759#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001760};
1761
Hans Verkuila3998102008-07-21 02:57:38 -03001762static struct video_device cx8800_radio_template = {
1763 .name = "cx8800-radio",
Hans Verkuila3998102008-07-21 02:57:38 -03001764 .fops = &radio_fops,
Hans Verkuila3998102008-07-21 02:57:38 -03001765 .ioctl_ops = &radio_ioctl_ops,
1766};
1767
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768/* ----------------------------------------------------------- */
1769
1770static void cx8800_unregister_video(struct cx8800_dev *dev)
1771{
1772 if (dev->radio_dev) {
Laurent Pinchartf0813b42009-11-27 13:57:30 -03001773 if (video_is_registered(dev->radio_dev))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774 video_unregister_device(dev->radio_dev);
1775 else
1776 video_device_release(dev->radio_dev);
1777 dev->radio_dev = NULL;
1778 }
1779 if (dev->vbi_dev) {
Laurent Pinchartf0813b42009-11-27 13:57:30 -03001780 if (video_is_registered(dev->vbi_dev))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781 video_unregister_device(dev->vbi_dev);
1782 else
1783 video_device_release(dev->vbi_dev);
1784 dev->vbi_dev = NULL;
1785 }
1786 if (dev->video_dev) {
Laurent Pinchartf0813b42009-11-27 13:57:30 -03001787 if (video_is_registered(dev->video_dev))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001788 video_unregister_device(dev->video_dev);
1789 else
1790 video_device_release(dev->video_dev);
1791 dev->video_dev = NULL;
1792 }
1793}
1794
1795static int __devinit cx8800_initdev(struct pci_dev *pci_dev,
1796 const struct pci_device_id *pci_id)
1797{
1798 struct cx8800_dev *dev;
1799 struct cx88_core *core;
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001800
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801 int err;
1802
Panagiotis Issaris74081872006-01-11 19:40:56 -02001803 dev = kzalloc(sizeof(*dev),GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804 if (NULL == dev)
1805 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806
1807 /* pci init */
1808 dev->pci = pci_dev;
1809 if (pci_enable_device(pci_dev)) {
1810 err = -EIO;
1811 goto fail_free;
1812 }
1813 core = cx88_core_get(dev->pci);
1814 if (NULL == core) {
1815 err = -EINVAL;
1816 goto fail_free;
1817 }
1818 dev->core = core;
1819
1820 /* print pci info */
1821 pci_read_config_byte(pci_dev, PCI_CLASS_REVISION, &dev->pci_rev);
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -08001822 pci_read_config_byte(pci_dev, PCI_LATENCY_TIMER, &dev->pci_lat);
1823 printk(KERN_INFO "%s/0: found at %s, rev: %d, irq: %d, "
Greg Kroah-Hartman228aef62006-06-12 15:16:52 -07001824 "latency: %d, mmio: 0x%llx\n", core->name,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825 pci_name(pci_dev), dev->pci_rev, pci_dev->irq,
Greg Kroah-Hartman228aef62006-06-12 15:16:52 -07001826 dev->pci_lat,(unsigned long long)pci_resource_start(pci_dev,0));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827
1828 pci_set_master(pci_dev);
Yang Hongyang284901a2009-04-06 19:01:15 -07001829 if (!pci_dma_supported(pci_dev,DMA_BIT_MASK(32))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001830 printk("%s/0: Oops: no 32bit PCI DMA ???\n",core->name);
1831 err = -EIO;
1832 goto fail_core;
1833 }
1834
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001835 /* Initialize VBI template */
1836 memcpy( &cx8800_vbi_template, &cx8800_video_template,
1837 sizeof(cx8800_vbi_template) );
1838 strcpy(cx8800_vbi_template.name,"cx8800-vbi");
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001839
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840 /* initialize driver struct */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001841 spin_lock_init(&dev->slock);
Mauro Carvalho Chehab63ab1bd2007-01-20 13:58:33 -03001842 core->tvnorm = cx8800_video_template.current_norm;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843
1844 /* init video dma queues */
1845 INIT_LIST_HEAD(&dev->vidq.active);
1846 INIT_LIST_HEAD(&dev->vidq.queued);
1847 dev->vidq.timeout.function = cx8800_vid_timeout;
1848 dev->vidq.timeout.data = (unsigned long)dev;
1849 init_timer(&dev->vidq.timeout);
1850 cx88_risc_stopper(dev->pci,&dev->vidq.stopper,
1851 MO_VID_DMACNTRL,0x11,0x00);
1852
1853 /* init vbi dma queues */
1854 INIT_LIST_HEAD(&dev->vbiq.active);
1855 INIT_LIST_HEAD(&dev->vbiq.queued);
1856 dev->vbiq.timeout.function = cx8800_vbi_timeout;
1857 dev->vbiq.timeout.data = (unsigned long)dev;
1858 init_timer(&dev->vbiq.timeout);
1859 cx88_risc_stopper(dev->pci,&dev->vbiq.stopper,
1860 MO_VID_DMACNTRL,0x88,0x00);
1861
1862 /* get irq */
1863 err = request_irq(pci_dev->irq, cx8800_irq,
Thomas Gleixner8076fe32006-07-01 19:29:37 -07001864 IRQF_SHARED | IRQF_DISABLED, core->name, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001865 if (err < 0) {
Trent Piepho5772f812007-08-15 14:41:59 -03001866 printk(KERN_ERR "%s/0: can't get IRQ %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001867 core->name,pci_dev->irq);
1868 goto fail_core;
1869 }
1870 cx_set(MO_PCI_INTMSK, core->pci_irqmask);
1871
1872 /* load and configure helper modules */
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001873
Hans Verkuil38f9d302008-07-23 05:09:15 -03001874 if (core->board.audio_chip == V4L2_IDENT_WM8775)
Hans Verkuile6574f22009-04-01 03:57:53 -03001875 v4l2_i2c_new_subdev(&core->v4l2_dev, &core->i2c_adap,
Hans Verkuil53dacb12009-08-10 02:49:08 -03001876 "wm8775", "wm8775", 0x36 >> 1, NULL);
Hans Verkuilb8341e12009-03-29 08:26:01 -03001877
1878 if (core->board.audio_chip == V4L2_IDENT_TVAUDIO) {
1879 /* This probes for a tda9874 as is used on some
1880 Pixelview Ultra boards. */
Hans Verkuil53dacb12009-08-10 02:49:08 -03001881 v4l2_i2c_new_subdev(&core->v4l2_dev,
Hans Verkuil1792f682009-03-30 11:47:55 -03001882 &core->i2c_adap,
Hans Verkuil53dacb12009-08-10 02:49:08 -03001883 "tvaudio", "tvaudio", 0, I2C_ADDRS(0xb0 >> 1));
Hans Verkuilb8341e12009-03-29 08:26:01 -03001884 }
Steven Toth30579062006-09-25 12:43:42 -03001885
Michael Krufky6fcecce2007-08-24 01:32:31 -03001886 switch (core->boardnr) {
1887 case CX88_BOARD_DVICO_FUSIONHDTV_5_GOLD:
Hans Verkuilb8341e12009-03-29 08:26:01 -03001888 case CX88_BOARD_DVICO_FUSIONHDTV_7_GOLD: {
1889 static struct i2c_board_info rtc_info = {
1890 I2C_BOARD_INFO("isl1208", 0x6f)
1891 };
1892
Michael Krufky6fcecce2007-08-24 01:32:31 -03001893 request_module("rtc-isl1208");
Hans Verkuilb8341e12009-03-29 08:26:01 -03001894 core->i2c_rtc = i2c_new_device(&core->i2c_adap, &rtc_info);
1895 }
Michael Krufky8efd2e22008-04-22 14:45:14 -03001896 /* break intentionally omitted */
1897 case CX88_BOARD_DVICO_FUSIONHDTV_5_PCI_NANO:
1898 request_module("ir-kbd-i2c");
Michael Krufky6fcecce2007-08-24 01:32:31 -03001899 }
1900
Linus Torvalds1da177e2005-04-16 15:20:36 -07001901 /* register v4l devices */
1902 dev->video_dev = cx88_vdev_init(core,dev->pci,
1903 &cx8800_video_template,"video");
Laurent Pinchart63b0d5a2009-12-10 11:44:04 -02001904 video_set_drvdata(dev->video_dev, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001905 err = video_register_device(dev->video_dev,VFL_TYPE_GRABBER,
1906 video_nr[core->nr]);
1907 if (err < 0) {
Trent Piepho5772f812007-08-15 14:41:59 -03001908 printk(KERN_ERR "%s/0: can't register video device\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909 core->name);
1910 goto fail_unreg;
1911 }
Laurent Pinchart38c7c032009-11-27 13:57:15 -03001912 printk(KERN_INFO "%s/0: registered device %s [v4l2]\n",
1913 core->name, video_device_node_name(dev->video_dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001914
1915 dev->vbi_dev = cx88_vdev_init(core,dev->pci,&cx8800_vbi_template,"vbi");
Laurent Pinchart63b0d5a2009-12-10 11:44:04 -02001916 video_set_drvdata(dev->vbi_dev, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001917 err = video_register_device(dev->vbi_dev,VFL_TYPE_VBI,
1918 vbi_nr[core->nr]);
1919 if (err < 0) {
Trent Piepho5772f812007-08-15 14:41:59 -03001920 printk(KERN_ERR "%s/0: can't register vbi device\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001921 core->name);
1922 goto fail_unreg;
1923 }
Laurent Pinchart38c7c032009-11-27 13:57:15 -03001924 printk(KERN_INFO "%s/0: registered device %s\n",
1925 core->name, video_device_node_name(dev->vbi_dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001926
Trent Piepho6a59d642007-08-15 14:41:57 -03001927 if (core->board.radio.type == CX88_RADIO) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001928 dev->radio_dev = cx88_vdev_init(core,dev->pci,
1929 &cx8800_radio_template,"radio");
Laurent Pinchart63b0d5a2009-12-10 11:44:04 -02001930 video_set_drvdata(dev->radio_dev, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001931 err = video_register_device(dev->radio_dev,VFL_TYPE_RADIO,
1932 radio_nr[core->nr]);
1933 if (err < 0) {
Trent Piepho5772f812007-08-15 14:41:59 -03001934 printk(KERN_ERR "%s/0: can't register radio device\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001935 core->name);
1936 goto fail_unreg;
1937 }
Laurent Pinchart38c7c032009-11-27 13:57:15 -03001938 printk(KERN_INFO "%s/0: registered device %s\n",
1939 core->name, video_device_node_name(dev->radio_dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001940 }
1941
1942 /* everything worked */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943 pci_set_drvdata(pci_dev,dev);
1944
1945 /* initial device configuration */
Ingo Molnar3593cab2006-02-07 06:49:14 -02001946 mutex_lock(&core->lock);
Mauro Carvalho Chehab63ab1bd2007-01-20 13:58:33 -03001947 cx88_set_tvnorm(core,core->tvnorm);
Mauro Carvalho Chehab70f00042006-01-09 15:25:26 -02001948 init_controls(core);
Mauro Carvalho Chehabe90311a2007-01-20 13:58:29 -03001949 cx88_video_mux(core,0);
Ingo Molnar3593cab2006-02-07 06:49:14 -02001950 mutex_unlock(&core->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951
1952 /* start tvaudio thread */
Trent Piepho6a59d642007-08-15 14:41:57 -03001953 if (core->board.tuner_type != TUNER_ABSENT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001954 core->kthread = kthread_run(cx88_audio_thread, core, "cx88 tvaudio");
Cyrill Gorcunov32b78de2007-07-19 11:44:11 -03001955 if (IS_ERR(core->kthread)) {
1956 err = PTR_ERR(core->kthread);
Trent Piepho5772f812007-08-15 14:41:59 -03001957 printk(KERN_ERR "%s/0: failed to create cx88 audio thread, err=%d\n",
1958 core->name, err);
Cyrill Gorcunov32b78de2007-07-19 11:44:11 -03001959 }
1960 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001961 return 0;
1962
1963fail_unreg:
1964 cx8800_unregister_video(dev);
1965 free_irq(pci_dev->irq, dev);
1966fail_core:
1967 cx88_core_put(core,dev->pci);
1968fail_free:
1969 kfree(dev);
1970 return err;
1971}
1972
1973static void __devexit cx8800_finidev(struct pci_dev *pci_dev)
1974{
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -08001975 struct cx8800_dev *dev = pci_get_drvdata(pci_dev);
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001976 struct cx88_core *core = dev->core;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001977
1978 /* stop thread */
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001979 if (core->kthread) {
1980 kthread_stop(core->kthread);
1981 core->kthread = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001982 }
1983
Marton Balintb12203d2008-03-26 02:07:35 -03001984 if (core->ir)
Mauro Carvalho Chehab92f4fc12010-03-31 16:07:49 -03001985 cx88_ir_stop(core);
Marton Balintb12203d2008-03-26 02:07:35 -03001986
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001987 cx88_shutdown(core); /* FIXME */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001988 pci_disable_device(pci_dev);
1989
1990 /* unregister stuff */
1991
1992 free_irq(pci_dev->irq, dev);
1993 cx8800_unregister_video(dev);
1994 pci_set_drvdata(pci_dev, NULL);
1995
1996 /* free memory */
1997 btcx_riscmem_free(dev->pci,&dev->vidq.stopper);
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001998 cx88_core_put(core,dev->pci);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001999 kfree(dev);
2000}
2001
Alexey Dobriyan17bc98a2006-08-12 22:01:27 -03002002#ifdef CONFIG_PM
Linus Torvalds1da177e2005-04-16 15:20:36 -07002003static int cx8800_suspend(struct pci_dev *pci_dev, pm_message_t state)
2004{
Mauro Carvalho Chehabb45009b2005-06-23 22:05:03 -07002005 struct cx8800_dev *dev = pci_get_drvdata(pci_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002006 struct cx88_core *core = dev->core;
2007
2008 /* stop video+vbi capture */
2009 spin_lock(&dev->slock);
2010 if (!list_empty(&dev->vidq.active)) {
Trent Piepho5772f812007-08-15 14:41:59 -03002011 printk("%s/0: suspend video\n", core->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002012 stop_video_dma(dev);
2013 del_timer(&dev->vidq.timeout);
2014 }
2015 if (!list_empty(&dev->vbiq.active)) {
Trent Piepho5772f812007-08-15 14:41:59 -03002016 printk("%s/0: suspend vbi\n", core->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002017 cx8800_stop_vbi_dma(dev);
2018 del_timer(&dev->vbiq.timeout);
2019 }
2020 spin_unlock(&dev->slock);
2021
Mauro Carvalho Chehab13595a52007-10-01 08:51:39 -03002022 if (core->ir)
Mauro Carvalho Chehab92f4fc12010-03-31 16:07:49 -03002023 cx88_ir_stop(core);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002024 /* FIXME -- shutdown device */
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07002025 cx88_shutdown(core);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002026
2027 pci_save_state(pci_dev);
2028 if (0 != pci_set_power_state(pci_dev, pci_choose_state(pci_dev, state))) {
2029 pci_disable_device(pci_dev);
2030 dev->state.disabled = 1;
2031 }
2032 return 0;
2033}
2034
2035static int cx8800_resume(struct pci_dev *pci_dev)
2036{
Mauro Carvalho Chehabb45009b2005-06-23 22:05:03 -07002037 struct cx8800_dev *dev = pci_get_drvdata(pci_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002038 struct cx88_core *core = dev->core;
Mauro Carvalho Chehab08adb9e2005-09-09 13:03:55 -07002039 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040
2041 if (dev->state.disabled) {
Mauro Carvalho Chehab08adb9e2005-09-09 13:03:55 -07002042 err=pci_enable_device(pci_dev);
2043 if (err) {
Trent Piepho5772f812007-08-15 14:41:59 -03002044 printk(KERN_ERR "%s/0: can't enable device\n",
2045 core->name);
Mauro Carvalho Chehab08adb9e2005-09-09 13:03:55 -07002046 return err;
2047 }
2048
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049 dev->state.disabled = 0;
2050 }
Mauro Carvalho Chehab08adb9e2005-09-09 13:03:55 -07002051 err= pci_set_power_state(pci_dev, PCI_D0);
2052 if (err) {
Trent Piepho5772f812007-08-15 14:41:59 -03002053 printk(KERN_ERR "%s/0: can't set power state\n", core->name);
Mauro Carvalho Chehab08adb9e2005-09-09 13:03:55 -07002054 pci_disable_device(pci_dev);
2055 dev->state.disabled = 1;
2056
2057 return err;
2058 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002059 pci_restore_state(pci_dev);
2060
Linus Torvalds1da177e2005-04-16 15:20:36 -07002061 /* FIXME: re-initialize hardware */
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07002062 cx88_reset(core);
Mauro Carvalho Chehab13595a52007-10-01 08:51:39 -03002063 if (core->ir)
Mauro Carvalho Chehab92f4fc12010-03-31 16:07:49 -03002064 cx88_ir_start(core);
Mauro Carvalho Chehab13595a52007-10-01 08:51:39 -03002065
2066 cx_set(MO_PCI_INTMSK, core->pci_irqmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067
2068 /* restart video+vbi capture */
2069 spin_lock(&dev->slock);
2070 if (!list_empty(&dev->vidq.active)) {
Trent Piepho5772f812007-08-15 14:41:59 -03002071 printk("%s/0: resume video\n", core->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002072 restart_video_queue(dev,&dev->vidq);
2073 }
2074 if (!list_empty(&dev->vbiq.active)) {
Trent Piepho5772f812007-08-15 14:41:59 -03002075 printk("%s/0: resume vbi\n", core->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002076 cx8800_restart_vbi_queue(dev,&dev->vbiq);
2077 }
2078 spin_unlock(&dev->slock);
2079
2080 return 0;
2081}
Alexey Dobriyan17bc98a2006-08-12 22:01:27 -03002082#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002083
2084/* ----------------------------------------------------------- */
2085
Adrian Bunk408b6642005-05-01 08:59:29 -07002086static struct pci_device_id cx8800_pci_tbl[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087 {
2088 .vendor = 0x14f1,
2089 .device = 0x8800,
Mauro Carvalho Chehabb45009b2005-06-23 22:05:03 -07002090 .subvendor = PCI_ANY_ID,
2091 .subdevice = PCI_ANY_ID,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092 },{
2093 /* --- end of list --- */
2094 }
2095};
2096MODULE_DEVICE_TABLE(pci, cx8800_pci_tbl);
2097
2098static struct pci_driver cx8800_pci_driver = {
Mauro Carvalho Chehabb45009b2005-06-23 22:05:03 -07002099 .name = "cx8800",
2100 .id_table = cx8800_pci_tbl,
2101 .probe = cx8800_initdev,
2102 .remove = __devexit_p(cx8800_finidev),
Alexey Dobriyan17bc98a2006-08-12 22:01:27 -03002103#ifdef CONFIG_PM
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104 .suspend = cx8800_suspend,
2105 .resume = cx8800_resume,
Alexey Dobriyan17bc98a2006-08-12 22:01:27 -03002106#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107};
2108
Peter Huewe31d0f842009-07-17 01:00:01 +02002109static int __init cx8800_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002110{
Trent Piepho5772f812007-08-15 14:41:59 -03002111 printk(KERN_INFO "cx88/0: cx2388x v4l2 driver version %d.%d.%d loaded\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002112 (CX88_VERSION_CODE >> 16) & 0xff,
2113 (CX88_VERSION_CODE >> 8) & 0xff,
2114 CX88_VERSION_CODE & 0xff);
2115#ifdef SNAPSHOT
2116 printk(KERN_INFO "cx2388x: snapshot date %04d-%02d-%02d\n",
2117 SNAPSHOT/10000, (SNAPSHOT/100)%100, SNAPSHOT%100);
2118#endif
2119 return pci_register_driver(&cx8800_pci_driver);
2120}
2121
Peter Huewe31d0f842009-07-17 01:00:01 +02002122static void __exit cx8800_fini(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002123{
2124 pci_unregister_driver(&cx8800_pci_driver);
2125}
2126
2127module_init(cx8800_init);
2128module_exit(cx8800_fini);
2129
2130/* ----------------------------------------------------------- */
2131/*
2132 * Local variables:
2133 * c-basic-offset: 8
2134 * End:
Mauro Carvalho Chehabb45009b2005-06-23 22:05:03 -07002135 * 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 -07002136 */