blob: 0a3849c710f877fe0a0f8e778c5c2d50f1c7578b [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,
429 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 */
434 if (INPUT(input).type != CX88_VMUX_TELEVISION ) {
435 /* "I2S ADC mode" */
436 core->tvaudio = WW_I2SADC;
437 cx88_set_tvaudio(core);
438 } else {
439 /* Normal mode */
440 cx_write(AUD_I2SCNTL, 0x0);
441 cx_clear(AUD_CTL, EN_I2SIN_ENABLE);
442 }
Michael Krufkyf24546a2006-10-16 16:51:11 -0300443 }
Ricardo Cerqueira66e6fbd2007-10-16 20:52:08 -0300444
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 return 0;
446}
Mauro Carvalho Chehabe90311a2007-01-20 13:58:29 -0300447EXPORT_SYMBOL(cx88_video_mux);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448
449/* ------------------------------------------------------------------ */
450
451static int start_video_dma(struct cx8800_dev *dev,
452 struct cx88_dmaqueue *q,
453 struct cx88_buffer *buf)
454{
455 struct cx88_core *core = dev->core;
456
457 /* setup fifo + format */
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700458 cx88_sram_channel_setup(core, &cx88_sram_channels[SRAM_CH21],
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 buf->bpl, buf->risc.dma);
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700460 cx88_set_scale(core, buf->vb.width, buf->vb.height, buf->vb.field);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 cx_write(MO_COLOR_CTRL, buf->fmt->cxformat | ColorFormatGamma);
462
463 /* reset counter */
464 cx_write(MO_VIDY_GPCNTRL,GP_COUNT_CONTROL_RESET);
465 q->count = 1;
466
467 /* enable irqs */
Trent Piepho8ddac9e2007-08-18 06:57:55 -0300468 cx_set(MO_PCI_INTMSK, core->pci_irqmask | PCI_INT_VIDINT);
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700469
470 /* Enables corresponding bits at PCI_INT_STAT:
471 bits 0 to 4: video, audio, transport stream, VIP, Host
472 bit 7: timer
473 bits 8 and 9: DMA complete for: SRC, DST
474 bits 10 and 11: BERR signal asserted for RISC: RD, WR
475 bits 12 to 15: BERR signal asserted for: BRDG, SRC, DST, IPB
476 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 cx_set(MO_VID_INTMSK, 0x0f0011);
478
479 /* enable capture */
480 cx_set(VID_CAPTURE_CONTROL,0x06);
481
482 /* start dma */
483 cx_set(MO_DEV_CNTRL2, (1<<5));
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700484 cx_set(MO_VID_DMACNTRL, 0x11); /* Planar Y and packed FIFO and RISC enable */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485
486 return 0;
487}
488
Alexey Dobriyan17bc98a2006-08-12 22:01:27 -0300489#ifdef CONFIG_PM
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490static int stop_video_dma(struct cx8800_dev *dev)
491{
492 struct cx88_core *core = dev->core;
493
494 /* stop dma */
495 cx_clear(MO_VID_DMACNTRL, 0x11);
496
497 /* disable capture */
498 cx_clear(VID_CAPTURE_CONTROL,0x06);
499
500 /* disable irqs */
Trent Piepho8ddac9e2007-08-18 06:57:55 -0300501 cx_clear(MO_PCI_INTMSK, PCI_INT_VIDINT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 cx_clear(MO_VID_INTMSK, 0x0f0011);
503 return 0;
504}
Alexey Dobriyan17bc98a2006-08-12 22:01:27 -0300505#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506
507static int restart_video_queue(struct cx8800_dev *dev,
508 struct cx88_dmaqueue *q)
509{
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700510 struct cx88_core *core = dev->core;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 struct cx88_buffer *buf, *prev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512
513 if (!list_empty(&q->active)) {
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -0800514 buf = list_entry(q->active.next, struct cx88_buffer, vb.queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 dprintk(2,"restart_queue [%p/%d]: restart dma\n",
516 buf, buf->vb.i);
517 start_video_dma(dev, q, buf);
Trent Piepho8bb629e22007-10-10 05:37:40 -0300518 list_for_each_entry(buf, &q->active, vb.queue)
519 buf->count = q->count++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
521 return 0;
522 }
523
524 prev = NULL;
525 for (;;) {
526 if (list_empty(&q->queued))
527 return 0;
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -0800528 buf = list_entry(q->queued.next, struct cx88_buffer, vb.queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 if (NULL == prev) {
Akinobu Mita179e0912006-06-26 00:24:41 -0700530 list_move_tail(&buf->vb.queue, &q->active);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 start_video_dma(dev, q, buf);
Brandon Philips0fc06862007-11-06 20:02:36 -0300532 buf->vb.state = VIDEOBUF_ACTIVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 buf->count = q->count++;
534 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
535 dprintk(2,"[%p/%d] restart_queue - first active\n",
536 buf,buf->vb.i);
537
538 } else if (prev->vb.width == buf->vb.width &&
539 prev->vb.height == buf->vb.height &&
540 prev->fmt == buf->fmt) {
Akinobu Mita179e0912006-06-26 00:24:41 -0700541 list_move_tail(&buf->vb.queue, &q->active);
Brandon Philips0fc06862007-11-06 20:02:36 -0300542 buf->vb.state = VIDEOBUF_ACTIVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 buf->count = q->count++;
544 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
545 dprintk(2,"[%p/%d] restart_queue - move to active\n",
546 buf,buf->vb.i);
547 } else {
548 return 0;
549 }
550 prev = buf;
551 }
552}
553
554/* ------------------------------------------------------------------ */
555
556static int
557buffer_setup(struct videobuf_queue *q, unsigned int *count, unsigned int *size)
558{
559 struct cx8800_fh *fh = q->priv_data;
560
561 *size = fh->fmt->depth*fh->width*fh->height >> 3;
562 if (0 == *count)
563 *count = 32;
Andreas Bombedab7e312010-03-21 16:02:45 -0300564 if (*size * *count > vid_limit * 1024 * 1024)
565 *count = (vid_limit * 1024 * 1024) / *size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 return 0;
567}
568
569static int
570buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
571 enum v4l2_field field)
572{
573 struct cx8800_fh *fh = q->priv_data;
574 struct cx8800_dev *dev = fh->dev;
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700575 struct cx88_core *core = dev->core;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 struct cx88_buffer *buf = container_of(vb,struct cx88_buffer,vb);
Mauro Carvalho Chehabc1accaa2007-08-23 16:37:49 -0300577 struct videobuf_dmabuf *dma=videobuf_to_dma(&buf->vb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 int rc, init_buffer = 0;
579
580 BUG_ON(NULL == fh->fmt);
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700581 if (fh->width < 48 || fh->width > norm_maxw(core->tvnorm) ||
582 fh->height < 32 || fh->height > norm_maxh(core->tvnorm))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 return -EINVAL;
584 buf->vb.size = (fh->width * fh->height * fh->fmt->depth) >> 3;
585 if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size)
586 return -EINVAL;
587
588 if (buf->fmt != fh->fmt ||
589 buf->vb.width != fh->width ||
590 buf->vb.height != fh->height ||
591 buf->vb.field != field) {
592 buf->fmt = fh->fmt;
593 buf->vb.width = fh->width;
594 buf->vb.height = fh->height;
595 buf->vb.field = field;
596 init_buffer = 1;
597 }
598
Brandon Philips0fc06862007-11-06 20:02:36 -0300599 if (VIDEOBUF_NEEDS_INIT == buf->vb.state) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 init_buffer = 1;
Mauro Carvalho Chehabc7b0ac02006-03-10 12:29:15 -0300601 if (0 != (rc = videobuf_iolock(q,&buf->vb,NULL)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 goto fail;
603 }
604
605 if (init_buffer) {
606 buf->bpl = buf->vb.width * buf->fmt->depth >> 3;
607 switch (buf->vb.field) {
608 case V4L2_FIELD_TOP:
609 cx88_risc_buffer(dev->pci, &buf->risc,
Mauro Carvalho Chehabc1accaa2007-08-23 16:37:49 -0300610 dma->sglist, 0, UNSET,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 buf->bpl, 0, buf->vb.height);
612 break;
613 case V4L2_FIELD_BOTTOM:
614 cx88_risc_buffer(dev->pci, &buf->risc,
Mauro Carvalho Chehabc1accaa2007-08-23 16:37:49 -0300615 dma->sglist, UNSET, 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 buf->bpl, 0, buf->vb.height);
617 break;
618 case V4L2_FIELD_INTERLACED:
619 cx88_risc_buffer(dev->pci, &buf->risc,
Mauro Carvalho Chehabc1accaa2007-08-23 16:37:49 -0300620 dma->sglist, 0, buf->bpl,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 buf->bpl, buf->bpl,
622 buf->vb.height >> 1);
623 break;
624 case V4L2_FIELD_SEQ_TB:
625 cx88_risc_buffer(dev->pci, &buf->risc,
Mauro Carvalho Chehabc1accaa2007-08-23 16:37:49 -0300626 dma->sglist,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 0, buf->bpl * (buf->vb.height >> 1),
628 buf->bpl, 0,
629 buf->vb.height >> 1);
630 break;
631 case V4L2_FIELD_SEQ_BT:
632 cx88_risc_buffer(dev->pci, &buf->risc,
Mauro Carvalho Chehabc1accaa2007-08-23 16:37:49 -0300633 dma->sglist,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 buf->bpl * (buf->vb.height >> 1), 0,
635 buf->bpl, 0,
636 buf->vb.height >> 1);
637 break;
638 default:
639 BUG();
640 }
641 }
642 dprintk(2,"[%p/%d] buffer_prepare - %dx%d %dbpp \"%s\" - dma=0x%08lx\n",
643 buf, buf->vb.i,
644 fh->width, fh->height, fh->fmt->depth, fh->fmt->name,
645 (unsigned long)buf->risc.dma);
646
Brandon Philips0fc06862007-11-06 20:02:36 -0300647 buf->vb.state = VIDEOBUF_PREPARED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 return 0;
649
650 fail:
Mauro Carvalho Chehabc7b0ac02006-03-10 12:29:15 -0300651 cx88_free_buffer(q,buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 return rc;
653}
654
655static void
656buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
657{
658 struct cx88_buffer *buf = container_of(vb,struct cx88_buffer,vb);
659 struct cx88_buffer *prev;
660 struct cx8800_fh *fh = vq->priv_data;
661 struct cx8800_dev *dev = fh->dev;
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700662 struct cx88_core *core = dev->core;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 struct cx88_dmaqueue *q = &dev->vidq;
664
665 /* add jump to stopper */
666 buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC);
667 buf->risc.jmp[1] = cpu_to_le32(q->stopper.dma);
668
669 if (!list_empty(&q->queued)) {
670 list_add_tail(&buf->vb.queue,&q->queued);
Brandon Philips0fc06862007-11-06 20:02:36 -0300671 buf->vb.state = VIDEOBUF_QUEUED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 dprintk(2,"[%p/%d] buffer_queue - append to queued\n",
673 buf, buf->vb.i);
674
675 } else if (list_empty(&q->active)) {
676 list_add_tail(&buf->vb.queue,&q->active);
677 start_video_dma(dev, q, buf);
Brandon Philips0fc06862007-11-06 20:02:36 -0300678 buf->vb.state = VIDEOBUF_ACTIVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 buf->count = q->count++;
680 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
681 dprintk(2,"[%p/%d] buffer_queue - first active\n",
682 buf, buf->vb.i);
683
684 } else {
685 prev = list_entry(q->active.prev, struct cx88_buffer, vb.queue);
686 if (prev->vb.width == buf->vb.width &&
687 prev->vb.height == buf->vb.height &&
688 prev->fmt == buf->fmt) {
689 list_add_tail(&buf->vb.queue,&q->active);
Brandon Philips0fc06862007-11-06 20:02:36 -0300690 buf->vb.state = VIDEOBUF_ACTIVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 buf->count = q->count++;
692 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
693 dprintk(2,"[%p/%d] buffer_queue - append to active\n",
694 buf, buf->vb.i);
695
696 } else {
697 list_add_tail(&buf->vb.queue,&q->queued);
Brandon Philips0fc06862007-11-06 20:02:36 -0300698 buf->vb.state = VIDEOBUF_QUEUED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 dprintk(2,"[%p/%d] buffer_queue - first queued\n",
700 buf, buf->vb.i);
701 }
702 }
703}
704
705static void buffer_release(struct videobuf_queue *q, struct videobuf_buffer *vb)
706{
707 struct cx88_buffer *buf = container_of(vb,struct cx88_buffer,vb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708
Mauro Carvalho Chehabc7b0ac02006-03-10 12:29:15 -0300709 cx88_free_buffer(q,buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710}
711
Adrian Bunk408b6642005-05-01 08:59:29 -0700712static struct videobuf_queue_ops cx8800_video_qops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 .buf_setup = buffer_setup,
714 .buf_prepare = buffer_prepare,
715 .buf_queue = buffer_queue,
716 .buf_release = buffer_release,
717};
718
719/* ------------------------------------------------------------------ */
720
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721
722/* ------------------------------------------------------------------ */
723
724static struct videobuf_queue* get_queue(struct cx8800_fh *fh)
725{
726 switch (fh->type) {
727 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
728 return &fh->vidq;
729 case V4L2_BUF_TYPE_VBI_CAPTURE:
730 return &fh->vbiq;
731 default:
732 BUG();
733 return NULL;
734 }
735}
736
737static int get_ressource(struct cx8800_fh *fh)
738{
739 switch (fh->type) {
740 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
741 return RESOURCE_VIDEO;
742 case V4L2_BUF_TYPE_VBI_CAPTURE:
743 return RESOURCE_VBI;
744 default:
745 BUG();
746 return 0;
747 }
748}
749
Hans Verkuilbec43662008-12-30 06:58:20 -0300750static int video_open(struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751{
Laurent Pinchart63b0d5a2009-12-10 11:44:04 -0200752 struct video_device *vdev = video_devdata(file);
753 struct cx8800_dev *dev = video_drvdata(file);
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700754 struct cx88_core *core;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 struct cx8800_fh *fh;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 enum v4l2_buf_type type = 0;
757 int radio = 0;
758
Laurent Pinchart63b0d5a2009-12-10 11:44:04 -0200759 switch (vdev->vfl_type) {
760 case VFL_TYPE_GRABBER:
761 type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
762 break;
763 case VFL_TYPE_VBI:
764 type = V4L2_BUF_TYPE_VBI_CAPTURE;
765 break;
766 case VFL_TYPE_RADIO:
767 radio = 1;
768 break;
769 }
770
Hans Verkuild56dc612008-07-30 08:43:36 -0300771 lock_kernel();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700773 core = dev->core;
774
Laurent Pinchart50462eb2009-12-10 11:47:13 -0200775 dprintk(1, "open dev=%s radio=%d type=%s\n",
776 video_device_node_name(vdev), radio, v4l2_type_names[type]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777
778 /* allocate + initialize per filehandle data */
Panagiotis Issaris74081872006-01-11 19:40:56 -0200779 fh = kzalloc(sizeof(*fh),GFP_KERNEL);
Hans Verkuild56dc612008-07-30 08:43:36 -0300780 if (NULL == fh) {
781 unlock_kernel();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782 return -ENOMEM;
Hans Verkuild56dc612008-07-30 08:43:36 -0300783 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784 file->private_data = fh;
785 fh->dev = dev;
786 fh->radio = radio;
787 fh->type = type;
788 fh->width = 320;
789 fh->height = 240;
790 fh->fmt = format_by_fourcc(V4L2_PIX_FMT_BGR24);
791
Guennadi Liakhovetski07051352008-04-22 14:42:13 -0300792 videobuf_queue_sg_init(&fh->vidq, &cx8800_video_qops,
793 &dev->pci->dev, &dev->slock,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794 V4L2_BUF_TYPE_VIDEO_CAPTURE,
795 V4L2_FIELD_INTERLACED,
796 sizeof(struct cx88_buffer),
797 fh);
Guennadi Liakhovetski07051352008-04-22 14:42:13 -0300798 videobuf_queue_sg_init(&fh->vbiq, &cx8800_vbi_qops,
799 &dev->pci->dev, &dev->slock,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 V4L2_BUF_TYPE_VBI_CAPTURE,
801 V4L2_FIELD_SEQ_TB,
802 sizeof(struct cx88_buffer),
803 fh);
804
805 if (fh->radio) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806 dprintk(1,"video_open: setting radio device\n");
Trent Piepho6a59d642007-08-15 14:41:57 -0300807 cx_write(MO_GP3_IO, core->board.radio.gpio3);
808 cx_write(MO_GP0_IO, core->board.radio.gpio0);
809 cx_write(MO_GP1_IO, core->board.radio.gpio1);
810 cx_write(MO_GP2_IO, core->board.radio.gpio2);
Darron Broad430189d2008-10-15 14:18:42 -0300811 if (core->board.radio.audioroute) {
812 if(core->board.audio_chip &&
813 core->board.audio_chip == V4L2_IDENT_WM8775) {
Hans Verkuil5325b422009-04-02 11:26:22 -0300814 call_all(core, audio, s_routing,
815 core->board.radio.audioroute, 0, 0);
Darron Broad430189d2008-10-15 14:18:42 -0300816 }
817 /* "I2S ADC mode" */
818 core->tvaudio = WW_I2SADC;
819 cx88_set_tvaudio(core);
820 } else {
821 /* FM Mode */
822 core->tvaudio = WW_FM;
823 cx88_set_tvaudio(core);
824 cx88_set_stereo(core,V4L2_TUNER_MODE_STEREO,1);
825 }
Hans Verkuilb8341e12009-03-29 08:26:01 -0300826 call_all(core, tuner, s_radio);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 }
Hans Verkuild56dc612008-07-30 08:43:36 -0300828 unlock_kernel();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829
Darron Broad3e010842008-09-25 16:51:11 -0300830 atomic_inc(&core->users);
831
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -0800832 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833}
834
835static ssize_t
Peter Hagervallf9e7a022005-11-08 21:36:29 -0800836video_read(struct file *file, char __user *data, size_t count, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837{
838 struct cx8800_fh *fh = file->private_data;
839
840 switch (fh->type) {
841 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
842 if (res_locked(fh->dev,RESOURCE_VIDEO))
843 return -EBUSY;
844 return videobuf_read_one(&fh->vidq, data, count, ppos,
845 file->f_flags & O_NONBLOCK);
846 case V4L2_BUF_TYPE_VBI_CAPTURE:
847 if (!res_get(fh->dev,fh,RESOURCE_VBI))
848 return -EBUSY;
849 return videobuf_read_stream(&fh->vbiq, data, count, ppos, 1,
850 file->f_flags & O_NONBLOCK);
851 default:
852 BUG();
853 return 0;
854 }
855}
856
857static unsigned int
858video_poll(struct file *file, struct poll_table_struct *wait)
859{
860 struct cx8800_fh *fh = file->private_data;
861 struct cx88_buffer *buf;
Figo.zhang9fd64182009-06-16 13:31:29 -0300862 unsigned int rc = POLLERR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863
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
Figo.zhang9fd64182009-06-16 13:31:29 -0300870 mutex_lock(&fh->vidq.vb_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871 if (res_check(fh,RESOURCE_VIDEO)) {
872 /* streaming capture */
873 if (list_empty(&fh->vidq.stream))
Figo.zhang9fd64182009-06-16 13:31:29 -0300874 goto done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875 buf = list_entry(fh->vidq.stream.next,struct cx88_buffer,vb.stream);
876 } else {
877 /* read() capture */
878 buf = (struct cx88_buffer*)fh->vidq.read_buf;
879 if (NULL == buf)
Figo.zhang9fd64182009-06-16 13:31:29 -0300880 goto done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881 }
882 poll_wait(file, &buf->vb.done, wait);
Brandon Philips0fc06862007-11-06 20:02:36 -0300883 if (buf->vb.state == VIDEOBUF_DONE ||
884 buf->vb.state == VIDEOBUF_ERROR)
Figo.zhang9fd64182009-06-16 13:31:29 -0300885 rc = POLLIN|POLLRDNORM;
886 else
887 rc = 0;
888done:
889 mutex_unlock(&fh->vidq.vb_lock);
890 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891}
892
Hans Verkuilbec43662008-12-30 06:58:20 -0300893static int video_release(struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894{
895 struct cx8800_fh *fh = file->private_data;
896 struct cx8800_dev *dev = fh->dev;
897
898 /* turn off overlay */
899 if (res_check(fh, RESOURCE_OVERLAY)) {
900 /* FIXME */
901 res_free(dev,fh,RESOURCE_OVERLAY);
902 }
903
904 /* stop video capture */
905 if (res_check(fh, RESOURCE_VIDEO)) {
906 videobuf_queue_cancel(&fh->vidq);
907 res_free(dev,fh,RESOURCE_VIDEO);
908 }
909 if (fh->vidq.read_buf) {
910 buffer_release(&fh->vidq,fh->vidq.read_buf);
911 kfree(fh->vidq.read_buf);
912 }
913
914 /* stop vbi capture */
915 if (res_check(fh, RESOURCE_VBI)) {
Brandon Philips053fcb62007-11-13 20:11:26 -0300916 videobuf_stop(&fh->vbiq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 res_free(dev,fh,RESOURCE_VBI);
918 }
919
920 videobuf_mmap_free(&fh->vidq);
921 videobuf_mmap_free(&fh->vbiq);
922 file->private_data = NULL;
923 kfree(fh);
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700924
Devin Heitmueller06f837c2009-04-28 14:35:27 -0300925 mutex_lock(&dev->core->lock);
Darron Broad3e010842008-09-25 16:51:11 -0300926 if(atomic_dec_and_test(&dev->core->users))
Laurent Pinchart622b8282009-10-05 10:48:17 -0300927 call_all(dev->core, core, s_power, 0);
Devin Heitmueller06f837c2009-04-28 14:35:27 -0300928 mutex_unlock(&dev->core->lock);
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700929
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930 return 0;
931}
932
933static int
934video_mmap(struct file *file, struct vm_area_struct * vma)
935{
936 struct cx8800_fh *fh = file->private_data;
937
938 return videobuf_mmap_mapper(get_queue(fh), vma);
939}
940
941/* ------------------------------------------------------------------ */
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -0300942/* VIDEO CTRL IOCTLS */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943
Mauro Carvalho Chehab54da49f2007-01-20 13:58:26 -0300944int cx88_get_control (struct cx88_core *core, struct v4l2_control *ctl)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945{
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -0300946 struct cx88_ctrl *c = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947 u32 value;
948 int i;
949
950 for (i = 0; i < CX8800_CTLS; i++)
951 if (cx8800_ctls[i].v.id == ctl->id)
952 c = &cx8800_ctls[i];
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -0300953 if (unlikely(NULL == c))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954 return -EINVAL;
955
956 value = c->sreg ? cx_sread(c->sreg) : cx_read(c->reg);
957 switch (ctl->id) {
958 case V4L2_CID_AUDIO_BALANCE:
Marcin Rudowski9f9c9072006-03-12 00:03:47 -0300959 ctl->value = ((value & 0x7f) < 0x40) ? ((value & 0x7f) + 0x40)
960 : (0x7f - (value & 0x7f));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961 break;
962 case V4L2_CID_AUDIO_VOLUME:
963 ctl->value = 0x3f - (value & 0x3f);
964 break;
965 default:
966 ctl->value = ((value + (c->off << c->shift)) & c->mask) >> c->shift;
967 break;
968 }
Ian Pickworth6457af52006-02-27 00:09:45 -0300969 dprintk(1,"get_control id=0x%X(%s) ctrl=0x%02x, reg=0x%02x val=0x%02x (mask 0x%02x)%s\n",
970 ctl->id, c->v.name, ctl->value, c->reg,
971 value,c->mask, c->sreg ? " [shadowed]" : "");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972 return 0;
973}
Mauro Carvalho Chehab54da49f2007-01-20 13:58:26 -0300974EXPORT_SYMBOL(cx88_get_control);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975
Mauro Carvalho Chehab54da49f2007-01-20 13:58:26 -0300976int cx88_set_control(struct cx88_core *core, struct v4l2_control *ctl)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978 struct cx88_ctrl *c = NULL;
Mauro Carvalho Chehab70f00042006-01-09 15:25:26 -0200979 u32 value,mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980 int i;
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -0300981
Mauro Carvalho Chehab70f00042006-01-09 15:25:26 -0200982 for (i = 0; i < CX8800_CTLS; i++) {
983 if (cx8800_ctls[i].v.id == ctl->id) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984 c = &cx8800_ctls[i];
Mauro Carvalho Chehab70f00042006-01-09 15:25:26 -0200985 }
986 }
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -0300987 if (unlikely(NULL == c))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988 return -EINVAL;
989
990 if (ctl->value < c->v.minimum)
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700991 ctl->value = c->v.minimum;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992 if (ctl->value > c->v.maximum)
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700993 ctl->value = c->v.maximum;
Mauro Carvalho Chehab70f00042006-01-09 15:25:26 -0200994 mask=c->mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995 switch (ctl->id) {
996 case V4L2_CID_AUDIO_BALANCE:
Marcin Rudowski9f9c9072006-03-12 00:03:47 -0300997 value = (ctl->value < 0x40) ? (0x7f - ctl->value) : (ctl->value - 0x40);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998 break;
999 case V4L2_CID_AUDIO_VOLUME:
1000 value = 0x3f - (ctl->value & 0x3f);
1001 break;
1002 case V4L2_CID_SATURATION:
1003 /* special v_sat handling */
Mauro Carvalho Chehab70f00042006-01-09 15:25:26 -02001004
1005 value = ((ctl->value - c->off) << c->shift) & c->mask;
1006
Mauro Carvalho Chehab63ab1bd2007-01-20 13:58:33 -03001007 if (core->tvnorm & V4L2_STD_SECAM) {
Mauro Carvalho Chehab70f00042006-01-09 15:25:26 -02001008 /* For SECAM, both U and V sat should be equal */
1009 value=value<<8|value;
1010 } else {
1011 /* Keeps U Saturation proportional to V Sat */
1012 value=(value*0x5a)/0x7f<<8|value;
1013 }
1014 mask=0xffff;
1015 break;
Frej Drejhammar6d042032008-03-23 22:43:21 -03001016 case V4L2_CID_CHROMA_AGC:
1017 /* Do not allow chroma AGC to be enabled for SECAM */
1018 value = ((ctl->value - c->off) << c->shift) & c->mask;
1019 if (core->tvnorm & V4L2_STD_SECAM && value)
1020 return -EINVAL;
1021 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022 default:
1023 value = ((ctl->value - c->off) << c->shift) & c->mask;
1024 break;
1025 }
Ian Pickworth6457af52006-02-27 00:09:45 -03001026 dprintk(1,"set_control id=0x%X(%s) ctrl=0x%02x, reg=0x%02x val=0x%02x (mask 0x%02x)%s\n",
1027 ctl->id, c->v.name, ctl->value, c->reg, value,
1028 mask, c->sreg ? " [shadowed]" : "");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029 if (c->sreg) {
Mauro Carvalho Chehab70f00042006-01-09 15:25:26 -02001030 cx_sandor(c->sreg, c->reg, mask, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031 } else {
Mauro Carvalho Chehab70f00042006-01-09 15:25:26 -02001032 cx_andor(c->reg, mask, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033 }
1034 return 0;
1035}
Mauro Carvalho Chehab54da49f2007-01-20 13:58:26 -03001036EXPORT_SYMBOL(cx88_set_control);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001038static void init_controls(struct cx88_core *core)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039{
Mauro Carvalho Chehab70f00042006-01-09 15:25:26 -02001040 struct v4l2_control ctrl;
1041 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042
Mauro Carvalho Chehab70f00042006-01-09 15:25:26 -02001043 for (i = 0; i < CX8800_CTLS; i++) {
1044 ctrl.id=cx8800_ctls[i].v.id;
Marcin Rudowski9f9c9072006-03-12 00:03:47 -03001045 ctrl.value=cx8800_ctls[i].v.default_value;
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001046
Mauro Carvalho Chehab54da49f2007-01-20 13:58:26 -03001047 cx88_set_control(core, &ctrl);
Mauro Carvalho Chehab70f00042006-01-09 15:25:26 -02001048 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049}
1050
1051/* ------------------------------------------------------------------ */
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001052/* VIDEO IOCTLS */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053
Hans Verkuil78b526a2008-05-28 12:16:41 -03001054static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001055 struct v4l2_format *f)
1056{
1057 struct cx8800_fh *fh = priv;
1058
1059 f->fmt.pix.width = fh->width;
1060 f->fmt.pix.height = fh->height;
1061 f->fmt.pix.field = fh->vidq.field;
1062 f->fmt.pix.pixelformat = fh->fmt->fourcc;
1063 f->fmt.pix.bytesperline =
1064 (f->fmt.pix.width * fh->fmt->depth) >> 3;
1065 f->fmt.pix.sizeimage =
1066 f->fmt.pix.height * f->fmt.pix.bytesperline;
1067 return 0;
1068}
1069
Hans Verkuil78b526a2008-05-28 12:16:41 -03001070static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071 struct v4l2_format *f)
1072{
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001073 struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core;
1074 struct cx8800_fmt *fmt;
1075 enum v4l2_field field;
1076 unsigned int maxw, maxh;
1077
1078 fmt = format_by_fourcc(f->fmt.pix.pixelformat);
1079 if (NULL == fmt)
1080 return -EINVAL;
1081
1082 field = f->fmt.pix.field;
1083 maxw = norm_maxw(core->tvnorm);
1084 maxh = norm_maxh(core->tvnorm);
1085
1086 if (V4L2_FIELD_ANY == field) {
1087 field = (f->fmt.pix.height > maxh/2)
1088 ? V4L2_FIELD_INTERLACED
1089 : V4L2_FIELD_BOTTOM;
1090 }
1091
1092 switch (field) {
1093 case V4L2_FIELD_TOP:
1094 case V4L2_FIELD_BOTTOM:
1095 maxh = maxh / 2;
1096 break;
1097 case V4L2_FIELD_INTERLACED:
1098 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099 default:
1100 return -EINVAL;
1101 }
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001102
1103 f->fmt.pix.field = field;
Trent Piepho4b899452009-05-30 21:45:46 -03001104 v4l_bound_align_image(&f->fmt.pix.width, 48, maxw, 2,
1105 &f->fmt.pix.height, 32, maxh, 0, 0);
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001106 f->fmt.pix.bytesperline =
1107 (f->fmt.pix.width * fmt->depth) >> 3;
1108 f->fmt.pix.sizeimage =
1109 f->fmt.pix.height * f->fmt.pix.bytesperline;
1110
1111 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112}
1113
Hans Verkuil78b526a2008-05-28 12:16:41 -03001114static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001115 struct v4l2_format *f)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116{
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001117 struct cx8800_fh *fh = priv;
Hans Verkuil78b526a2008-05-28 12:16:41 -03001118 int err = vidioc_try_fmt_vid_cap (file,priv,f);
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001119
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001120 if (0 != err)
1121 return err;
1122 fh->fmt = format_by_fourcc(f->fmt.pix.pixelformat);
1123 fh->width = f->fmt.pix.width;
1124 fh->height = f->fmt.pix.height;
1125 fh->vidq.field = f->fmt.pix.field;
1126 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127}
1128
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001129static int vidioc_querycap (struct file *file, void *priv,
1130 struct v4l2_capability *cap)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131{
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001132 struct cx8800_dev *dev = ((struct cx8800_fh *)priv)->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133 struct cx88_core *core = dev->core;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001135 strcpy(cap->driver, "cx8800");
Trent Piepho6a59d642007-08-15 14:41:57 -03001136 strlcpy(cap->card, core->board.name, sizeof(cap->card));
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001137 sprintf(cap->bus_info,"PCI:%s",pci_name(dev->pci));
1138 cap->version = CX88_VERSION_CODE;
1139 cap->capabilities =
1140 V4L2_CAP_VIDEO_CAPTURE |
1141 V4L2_CAP_READWRITE |
1142 V4L2_CAP_STREAMING |
1143 V4L2_CAP_VBI_CAPTURE;
Trent Piepho6a59d642007-08-15 14:41:57 -03001144 if (UNSET != core->board.tuner_type)
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001145 cap->capabilities |= V4L2_CAP_TUNER;
1146 return 0;
1147}
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001148
Hans Verkuil78b526a2008-05-28 12:16:41 -03001149static int vidioc_enum_fmt_vid_cap (struct file *file, void *priv,
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001150 struct v4l2_fmtdesc *f)
1151{
1152 if (unlikely(f->index >= ARRAY_SIZE(formats)))
1153 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001155 strlcpy(f->description,formats[f->index].name,sizeof(f->description));
1156 f->pixelformat = formats[f->index].fourcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001158 return 0;
1159}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160
Mauro Carvalho Chehab0dfa9ab2006-08-08 09:10:10 -03001161#ifdef CONFIG_VIDEO_V4L1_COMPAT
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001162static int vidiocgmbuf (struct file *file, void *priv, struct video_mbuf *mbuf)
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001163{
Mauro Carvalho Chehabc1accaa2007-08-23 16:37:49 -03001164 struct cx8800_fh *fh = priv;
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001165
Mauro Carvalho Chehabc1accaa2007-08-23 16:37:49 -03001166 return videobuf_cgmbuf (get_queue(fh), mbuf, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167}
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001168#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001170static int vidioc_reqbufs (struct file *file, void *priv, struct v4l2_requestbuffers *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171{
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001172 struct cx8800_fh *fh = priv;
1173 return (videobuf_reqbufs(get_queue(fh), p));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174}
1175
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001176static int vidioc_querybuf (struct file *file, void *priv, struct v4l2_buffer *p)
1177{
1178 struct cx8800_fh *fh = priv;
1179 return (videobuf_querybuf(get_queue(fh), p));
1180}
1181
1182static int vidioc_qbuf (struct file *file, void *priv, struct v4l2_buffer *p)
1183{
1184 struct cx8800_fh *fh = priv;
1185 return (videobuf_qbuf(get_queue(fh), p));
1186}
1187
1188static int vidioc_dqbuf (struct file *file, void *priv, struct v4l2_buffer *p)
1189{
1190 struct cx8800_fh *fh = priv;
1191 return (videobuf_dqbuf(get_queue(fh), p,
1192 file->f_flags & O_NONBLOCK));
1193}
1194
1195static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
1196{
1197 struct cx8800_fh *fh = priv;
1198 struct cx8800_dev *dev = fh->dev;
1199
Rafael Dinizb058e3f2008-10-24 23:07:57 -03001200 /* We should remember that this driver also supports teletext, */
1201 /* so we have to test if the v4l2_buf_type is VBI capture data. */
1202 if (unlikely((fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) &&
1203 (fh->type != V4L2_BUF_TYPE_VBI_CAPTURE)))
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001204 return -EINVAL;
Rafael Dinizb058e3f2008-10-24 23:07:57 -03001205
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001206 if (unlikely(i != fh->type))
1207 return -EINVAL;
1208
1209 if (unlikely(!res_get(dev,fh,get_ressource(fh))))
1210 return -EBUSY;
1211 return videobuf_streamon(get_queue(fh));
1212}
1213
1214static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
1215{
1216 struct cx8800_fh *fh = priv;
1217 struct cx8800_dev *dev = fh->dev;
1218 int err, res;
1219
Rafael Dinizb058e3f2008-10-24 23:07:57 -03001220 if ((fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) &&
1221 (fh->type != V4L2_BUF_TYPE_VBI_CAPTURE))
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001222 return -EINVAL;
Rafael Dinizb058e3f2008-10-24 23:07:57 -03001223
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001224 if (i != fh->type)
1225 return -EINVAL;
1226
1227 res = get_ressource(fh);
1228 err = videobuf_streamoff(get_queue(fh));
1229 if (err < 0)
1230 return err;
1231 res_free(dev,fh,res);
1232 return 0;
1233}
1234
Mauro Carvalho Chehab63ab1bd2007-01-20 13:58:33 -03001235static int vidioc_s_std (struct file *file, void *priv, v4l2_std_id *tvnorms)
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001236{
1237 struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core;
1238
1239 mutex_lock(&core->lock);
Mauro Carvalho Chehab63ab1bd2007-01-20 13:58:33 -03001240 cx88_set_tvnorm(core,*tvnorms);
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001241 mutex_unlock(&core->lock);
Mauro Carvalho Chehab63ab1bd2007-01-20 13:58:33 -03001242
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001243 return 0;
1244}
1245
1246/* only one input in this sample driver */
Mauro Carvalho Chehab54da49f2007-01-20 13:58:26 -03001247int cx88_enum_input (struct cx88_core *core,struct v4l2_input *i)
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001248{
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001249 static const char *iname[] = {
1250 [ CX88_VMUX_COMPOSITE1 ] = "Composite1",
1251 [ CX88_VMUX_COMPOSITE2 ] = "Composite2",
1252 [ CX88_VMUX_COMPOSITE3 ] = "Composite3",
1253 [ CX88_VMUX_COMPOSITE4 ] = "Composite4",
1254 [ CX88_VMUX_SVIDEO ] = "S-Video",
1255 [ CX88_VMUX_TELEVISION ] = "Television",
1256 [ CX88_VMUX_CABLE ] = "Cable TV",
1257 [ CX88_VMUX_DVB ] = "DVB",
1258 [ CX88_VMUX_DEBUG ] = "for debug only",
1259 };
Trent Piephof3334bc2009-03-04 01:21:03 -03001260 unsigned int n = i->index;
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001261
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001262 if (n >= 4)
1263 return -EINVAL;
Trent Piepho6a59d642007-08-15 14:41:57 -03001264 if (0 == INPUT(n).type)
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001265 return -EINVAL;
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001266 i->type = V4L2_INPUT_TYPE_CAMERA;
Trent Piepho6a59d642007-08-15 14:41:57 -03001267 strcpy(i->name,iname[INPUT(n).type]);
1268 if ((CX88_VMUX_TELEVISION == INPUT(n).type) ||
1269 (CX88_VMUX_CABLE == INPUT(n).type))
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001270 i->type = V4L2_INPUT_TYPE_TUNER;
Mauro Carvalho Chehab63ab1bd2007-01-20 13:58:33 -03001271 i->std = CX88_NORMS;
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001272 return 0;
1273}
Mauro Carvalho Chehab54da49f2007-01-20 13:58:26 -03001274EXPORT_SYMBOL(cx88_enum_input);
1275
1276static int vidioc_enum_input (struct file *file, void *priv,
1277 struct v4l2_input *i)
1278{
1279 struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core;
1280 return cx88_enum_input (core,i);
1281}
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001282
1283static int vidioc_g_input (struct file *file, void *priv, unsigned int *i)
1284{
1285 struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core;
1286
1287 *i = core->input;
1288 return 0;
1289}
1290
1291static int vidioc_s_input (struct file *file, void *priv, unsigned int i)
1292{
1293 struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core;
1294
1295 if (i >= 4)
1296 return -EINVAL;
1297
1298 mutex_lock(&core->lock);
1299 cx88_newstation(core);
Mauro Carvalho Chehabe90311a2007-01-20 13:58:29 -03001300 cx88_video_mux(core,i);
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001301 mutex_unlock(&core->lock);
1302 return 0;
1303}
1304
1305
1306
1307static int vidioc_queryctrl (struct file *file, void *priv,
1308 struct v4l2_queryctrl *qctrl)
1309{
Frej Drejhammar6d042032008-03-23 22:43:21 -03001310 struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core;
1311
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001312 qctrl->id = v4l2_ctrl_next(ctrl_classes, qctrl->id);
1313 if (unlikely(qctrl->id == 0))
1314 return -EINVAL;
Frej Drejhammar6d042032008-03-23 22:43:21 -03001315 return cx8800_ctrl_query(core, qctrl);
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001316}
1317
Mauro Carvalho Chehab54da49f2007-01-20 13:58:26 -03001318static int vidioc_g_ctrl (struct file *file, void *priv,
1319 struct v4l2_control *ctl)
1320{
1321 struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core;
1322 return
1323 cx88_get_control(core,ctl);
1324}
1325
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001326static int vidioc_s_ctrl (struct file *file, void *priv,
1327 struct v4l2_control *ctl)
1328{
1329 struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core;
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001330 return
Mauro Carvalho Chehab54da49f2007-01-20 13:58:26 -03001331 cx88_set_control(core,ctl);
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001332}
1333
1334static int vidioc_g_tuner (struct file *file, void *priv,
1335 struct v4l2_tuner *t)
1336{
1337 struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core;
1338 u32 reg;
1339
Trent Piepho6a59d642007-08-15 14:41:57 -03001340 if (unlikely(UNSET == core->board.tuner_type))
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001341 return -EINVAL;
Mauro Carvalho Chehab243d8c02007-01-20 13:58:36 -03001342 if (0 != t->index)
1343 return -EINVAL;
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001344
1345 strcpy(t->name, "Television");
1346 t->type = V4L2_TUNER_ANALOG_TV;
1347 t->capability = V4L2_TUNER_CAP_NORM;
1348 t->rangehigh = 0xffffffffUL;
1349
1350 cx88_get_stereo(core ,t);
1351 reg = cx_read(MO_DEVICE_STATUS);
1352 t->signal = (reg & (1<<5)) ? 0xffff : 0x0000;
1353 return 0;
1354}
1355
1356static int vidioc_s_tuner (struct file *file, void *priv,
1357 struct v4l2_tuner *t)
1358{
1359 struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core;
1360
Trent Piepho6a59d642007-08-15 14:41:57 -03001361 if (UNSET == core->board.tuner_type)
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001362 return -EINVAL;
1363 if (0 != t->index)
1364 return -EINVAL;
1365
1366 cx88_set_stereo(core, t->audmode, 1);
1367 return 0;
1368}
1369
1370static int vidioc_g_frequency (struct file *file, void *priv,
1371 struct v4l2_frequency *f)
1372{
1373 struct cx8800_fh *fh = priv;
1374 struct cx88_core *core = fh->dev->core;
1375
Trent Piepho6a59d642007-08-15 14:41:57 -03001376 if (unlikely(UNSET == core->board.tuner_type))
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001377 return -EINVAL;
1378
1379 /* f->type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; */
1380 f->type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
1381 f->frequency = core->freq;
1382
Hans Verkuilb8341e12009-03-29 08:26:01 -03001383 call_all(core, tuner, g_frequency, f);
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001384
1385 return 0;
1386}
1387
Mauro Carvalho Chehab54da49f2007-01-20 13:58:26 -03001388int cx88_set_freq (struct cx88_core *core,
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001389 struct v4l2_frequency *f)
1390{
Trent Piepho6a59d642007-08-15 14:41:57 -03001391 if (unlikely(UNSET == core->board.tuner_type))
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001392 return -EINVAL;
1393 if (unlikely(f->tuner != 0))
1394 return -EINVAL;
Mauro Carvalho Chehab54da49f2007-01-20 13:58:26 -03001395
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001396 mutex_lock(&core->lock);
1397 core->freq = f->frequency;
1398 cx88_newstation(core);
Hans Verkuilb8341e12009-03-29 08:26:01 -03001399 call_all(core, tuner, s_frequency, f);
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001400
1401 /* When changing channels it is required to reset TVAUDIO */
1402 msleep (10);
1403 cx88_set_tvaudio(core);
1404
1405 mutex_unlock(&core->lock);
Mauro Carvalho Chehab54da49f2007-01-20 13:58:26 -03001406
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001407 return 0;
1408}
Mauro Carvalho Chehab54da49f2007-01-20 13:58:26 -03001409EXPORT_SYMBOL(cx88_set_freq);
1410
1411static int vidioc_s_frequency (struct file *file, void *priv,
1412 struct v4l2_frequency *f)
1413{
1414 struct cx8800_fh *fh = priv;
1415 struct cx88_core *core = fh->dev->core;
1416
1417 if (unlikely(0 == fh->radio && f->type != V4L2_TUNER_ANALOG_TV))
1418 return -EINVAL;
1419 if (unlikely(1 == fh->radio && f->type != V4L2_TUNER_RADIO))
1420 return -EINVAL;
1421
1422 return
1423 cx88_set_freq (core,f);
1424}
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001425
Trent Piephodbbff482007-01-22 23:31:53 -03001426#ifdef CONFIG_VIDEO_ADV_DEBUG
1427static int vidioc_g_register (struct file *file, void *fh,
Hans Verkuilaecde8b52008-12-30 07:14:19 -03001428 struct v4l2_dbg_register *reg)
Trent Piephodbbff482007-01-22 23:31:53 -03001429{
1430 struct cx88_core *core = ((struct cx8800_fh*)fh)->dev->core;
1431
Hans Verkuilaecde8b52008-12-30 07:14:19 -03001432 if (!v4l2_chip_match_host(&reg->match))
Trent Piephodbbff482007-01-22 23:31:53 -03001433 return -EINVAL;
1434 /* cx2388x has a 24-bit register space */
Hans Verkuilaecde8b52008-12-30 07:14:19 -03001435 reg->val = cx_read(reg->reg & 0xffffff);
1436 reg->size = 4;
Trent Piephodbbff482007-01-22 23:31:53 -03001437 return 0;
1438}
1439
1440static int vidioc_s_register (struct file *file, void *fh,
Hans Verkuilaecde8b52008-12-30 07:14:19 -03001441 struct v4l2_dbg_register *reg)
Trent Piephodbbff482007-01-22 23:31:53 -03001442{
1443 struct cx88_core *core = ((struct cx8800_fh*)fh)->dev->core;
1444
Hans Verkuilaecde8b52008-12-30 07:14:19 -03001445 if (!v4l2_chip_match_host(&reg->match))
Trent Piephodbbff482007-01-22 23:31:53 -03001446 return -EINVAL;
Hans Verkuilaecde8b52008-12-30 07:14:19 -03001447 cx_write(reg->reg & 0xffffff, reg->val);
Trent Piephodbbff482007-01-22 23:31:53 -03001448 return 0;
1449}
1450#endif
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001451
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452/* ----------------------------------------------------------- */
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001453/* RADIO ESPECIFIC IOCTLS */
1454/* ----------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001456static int radio_querycap (struct file *file, void *priv,
1457 struct v4l2_capability *cap)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458{
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001459 struct cx8800_dev *dev = ((struct cx8800_fh *)priv)->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460 struct cx88_core *core = dev->core;
1461
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001462 strcpy(cap->driver, "cx8800");
Trent Piepho6a59d642007-08-15 14:41:57 -03001463 strlcpy(cap->card, core->board.name, sizeof(cap->card));
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001464 sprintf(cap->bus_info,"PCI:%s", pci_name(dev->pci));
1465 cap->version = CX88_VERSION_CODE;
1466 cap->capabilities = V4L2_CAP_TUNER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467 return 0;
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001468}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001470static int radio_g_tuner (struct file *file, void *priv,
1471 struct v4l2_tuner *t)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472{
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001473 struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core;
1474
1475 if (unlikely(t->index > 0))
1476 return -EINVAL;
1477
1478 strcpy(t->name, "Radio");
1479 t->type = V4L2_TUNER_RADIO;
1480
Hans Verkuilb8341e12009-03-29 08:26:01 -03001481 call_all(core, tuner, g_tuner, t);
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001482 return 0;
1483}
1484
1485static int radio_enum_input (struct file *file, void *priv,
1486 struct v4l2_input *i)
1487{
1488 if (i->index != 0)
1489 return -EINVAL;
1490 strcpy(i->name,"Radio");
1491 i->type = V4L2_INPUT_TYPE_TUNER;
1492
1493 return 0;
1494}
1495
1496static int radio_g_audio (struct file *file, void *priv, struct v4l2_audio *a)
1497{
1498 if (unlikely(a->index))
1499 return -EINVAL;
1500
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001501 strcpy(a->name,"Radio");
1502 return 0;
1503}
1504
1505/* FIXME: Should add a standard for radio */
1506
1507static int radio_s_tuner (struct file *file, void *priv,
1508 struct v4l2_tuner *t)
1509{
1510 struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core;
1511
1512 if (0 != t->index)
1513 return -EINVAL;
1514
Hans Verkuilb8341e12009-03-29 08:26:01 -03001515 call_all(core, tuner, s_tuner, t);
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001516
1517 return 0;
1518}
1519
1520static int radio_s_audio (struct file *file, void *fh,
1521 struct v4l2_audio *a)
1522{
1523 return 0;
1524}
1525
1526static int radio_s_input (struct file *file, void *fh, unsigned int i)
1527{
1528 return 0;
1529}
1530
1531static int radio_queryctrl (struct file *file, void *priv,
1532 struct v4l2_queryctrl *c)
1533{
1534 int i;
1535
1536 if (c->id < V4L2_CID_BASE ||
1537 c->id >= V4L2_CID_LASTP1)
1538 return -EINVAL;
1539 if (c->id == V4L2_CID_AUDIO_MUTE) {
1540 for (i = 0; i < CX8800_CTLS; i++)
1541 if (cx8800_ctls[i].v.id == c->id)
1542 break;
1543 *c = cx8800_ctls[i].v;
1544 } else
1545 *c = no_ctl;
1546 return 0;
1547}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548
1549/* ----------------------------------------------------------- */
1550
1551static void cx8800_vid_timeout(unsigned long data)
1552{
1553 struct cx8800_dev *dev = (struct cx8800_dev*)data;
1554 struct cx88_core *core = dev->core;
1555 struct cx88_dmaqueue *q = &dev->vidq;
1556 struct cx88_buffer *buf;
1557 unsigned long flags;
1558
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001559 cx88_sram_channel_dump(core, &cx88_sram_channels[SRAM_CH21]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560
1561 cx_clear(MO_VID_DMACNTRL, 0x11);
1562 cx_clear(VID_CAPTURE_CONTROL, 0x06);
1563
1564 spin_lock_irqsave(&dev->slock,flags);
1565 while (!list_empty(&q->active)) {
1566 buf = list_entry(q->active.next, struct cx88_buffer, vb.queue);
1567 list_del(&buf->vb.queue);
Brandon Philips0fc06862007-11-06 20:02:36 -03001568 buf->vb.state = VIDEOBUF_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569 wake_up(&buf->vb.done);
1570 printk("%s/0: [%p/%d] timeout - dma=0x%08lx\n", core->name,
1571 buf, buf->vb.i, (unsigned long)buf->risc.dma);
1572 }
1573 restart_video_queue(dev,q);
1574 spin_unlock_irqrestore(&dev->slock,flags);
1575}
1576
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -07001577static char *cx88_vid_irqs[32] = {
1578 "y_risci1", "u_risci1", "v_risci1", "vbi_risc1",
1579 "y_risci2", "u_risci2", "v_risci2", "vbi_risc2",
1580 "y_oflow", "u_oflow", "v_oflow", "vbi_oflow",
1581 "y_sync", "u_sync", "v_sync", "vbi_sync",
1582 "opc_err", "par_err", "rip_err", "pci_abort",
1583};
1584
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585static void cx8800_vid_irq(struct cx8800_dev *dev)
1586{
1587 struct cx88_core *core = dev->core;
1588 u32 status, mask, count;
1589
1590 status = cx_read(MO_VID_INTSTAT);
1591 mask = cx_read(MO_VID_INTMSK);
1592 if (0 == (status & mask))
1593 return;
1594 cx_write(MO_VID_INTSTAT, status);
1595 if (irq_debug || (status & mask & ~0xff))
1596 cx88_print_irqbits(core->name, "irq vid",
Mauro Carvalho Chehab66623a02007-03-29 08:47:04 -03001597 cx88_vid_irqs, ARRAY_SIZE(cx88_vid_irqs),
1598 status, mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001599
1600 /* risc op code error */
1601 if (status & (1 << 16)) {
1602 printk(KERN_WARNING "%s/0: video risc op code error\n",core->name);
1603 cx_clear(MO_VID_DMACNTRL, 0x11);
1604 cx_clear(VID_CAPTURE_CONTROL, 0x06);
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001605 cx88_sram_channel_dump(core, &cx88_sram_channels[SRAM_CH21]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606 }
1607
1608 /* risc1 y */
1609 if (status & 0x01) {
1610 spin_lock(&dev->slock);
1611 count = cx_read(MO_VIDY_GPCNT);
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001612 cx88_wakeup(core, &dev->vidq, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613 spin_unlock(&dev->slock);
1614 }
1615
1616 /* risc1 vbi */
1617 if (status & 0x08) {
1618 spin_lock(&dev->slock);
1619 count = cx_read(MO_VBI_GPCNT);
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001620 cx88_wakeup(core, &dev->vbiq, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621 spin_unlock(&dev->slock);
1622 }
1623
1624 /* risc2 y */
1625 if (status & 0x10) {
1626 dprintk(2,"stopper video\n");
1627 spin_lock(&dev->slock);
1628 restart_video_queue(dev,&dev->vidq);
1629 spin_unlock(&dev->slock);
1630 }
1631
1632 /* risc2 vbi */
1633 if (status & 0x80) {
1634 dprintk(2,"stopper vbi\n");
1635 spin_lock(&dev->slock);
1636 cx8800_restart_vbi_queue(dev,&dev->vbiq);
1637 spin_unlock(&dev->slock);
1638 }
1639}
1640
David Howells7d12e782006-10-05 14:55:46 +01001641static irqreturn_t cx8800_irq(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001642{
1643 struct cx8800_dev *dev = dev_id;
1644 struct cx88_core *core = dev->core;
1645 u32 status;
1646 int loop, handled = 0;
1647
1648 for (loop = 0; loop < 10; loop++) {
Trent Piepho8ddac9e2007-08-18 06:57:55 -03001649 status = cx_read(MO_PCI_INTSTAT) &
1650 (core->pci_irqmask | PCI_INT_VIDINT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001651 if (0 == status)
1652 goto out;
1653 cx_write(MO_PCI_INTSTAT, status);
1654 handled = 1;
1655
1656 if (status & core->pci_irqmask)
1657 cx88_core_irq(core,status);
Trent Piepho8ddac9e2007-08-18 06:57:55 -03001658 if (status & PCI_INT_VIDINT)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659 cx8800_vid_irq(dev);
1660 };
1661 if (10 == loop) {
1662 printk(KERN_WARNING "%s/0: irq loop -- clearing mask\n",
1663 core->name);
1664 cx_write(MO_PCI_INTMSK,0);
1665 }
1666
1667 out:
1668 return IRQ_RETVAL(handled);
1669}
1670
1671/* ----------------------------------------------------------- */
1672/* exported stuff */
1673
Hans Verkuilbec43662008-12-30 06:58:20 -03001674static const struct v4l2_file_operations video_fops =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001675{
1676 .owner = THIS_MODULE,
1677 .open = video_open,
1678 .release = video_release,
1679 .read = video_read,
1680 .poll = video_poll,
1681 .mmap = video_mmap,
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001682 .ioctl = video_ioctl2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001683};
1684
Hans Verkuila3998102008-07-21 02:57:38 -03001685static const struct v4l2_ioctl_ops video_ioctl_ops = {
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001686 .vidioc_querycap = vidioc_querycap,
Hans Verkuil78b526a2008-05-28 12:16:41 -03001687 .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
1688 .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
1689 .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
1690 .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
1691 .vidioc_g_fmt_vbi_cap = cx8800_vbi_fmt,
1692 .vidioc_try_fmt_vbi_cap = cx8800_vbi_fmt,
1693 .vidioc_s_fmt_vbi_cap = cx8800_vbi_fmt,
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001694 .vidioc_reqbufs = vidioc_reqbufs,
1695 .vidioc_querybuf = vidioc_querybuf,
1696 .vidioc_qbuf = vidioc_qbuf,
1697 .vidioc_dqbuf = vidioc_dqbuf,
1698 .vidioc_s_std = vidioc_s_std,
1699 .vidioc_enum_input = vidioc_enum_input,
1700 .vidioc_g_input = vidioc_g_input,
1701 .vidioc_s_input = vidioc_s_input,
1702 .vidioc_queryctrl = vidioc_queryctrl,
1703 .vidioc_g_ctrl = vidioc_g_ctrl,
1704 .vidioc_s_ctrl = vidioc_s_ctrl,
1705 .vidioc_streamon = vidioc_streamon,
1706 .vidioc_streamoff = vidioc_streamoff,
1707#ifdef CONFIG_VIDEO_V4L1_COMPAT
1708 .vidiocgmbuf = vidiocgmbuf,
1709#endif
1710 .vidioc_g_tuner = vidioc_g_tuner,
1711 .vidioc_s_tuner = vidioc_s_tuner,
1712 .vidioc_g_frequency = vidioc_g_frequency,
1713 .vidioc_s_frequency = vidioc_s_frequency,
Trent Piephodbbff482007-01-22 23:31:53 -03001714#ifdef CONFIG_VIDEO_ADV_DEBUG
1715 .vidioc_g_register = vidioc_g_register,
1716 .vidioc_s_register = vidioc_s_register,
1717#endif
Hans Verkuila3998102008-07-21 02:57:38 -03001718};
1719
1720static struct video_device cx8800_vbi_template;
1721
1722static struct video_device cx8800_video_template = {
1723 .name = "cx8800-video",
Hans Verkuila3998102008-07-21 02:57:38 -03001724 .fops = &video_fops,
Hans Verkuila3998102008-07-21 02:57:38 -03001725 .ioctl_ops = &video_ioctl_ops,
Mauro Carvalho Chehab63ab1bd2007-01-20 13:58:33 -03001726 .tvnorms = CX88_NORMS,
Trent Piephodbbff482007-01-22 23:31:53 -03001727 .current_norm = V4L2_STD_NTSC_M,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728};
1729
Hans Verkuilbec43662008-12-30 06:58:20 -03001730static const struct v4l2_file_operations radio_fops =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731{
1732 .owner = THIS_MODULE,
1733 .open = video_open,
1734 .release = video_release,
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001735 .ioctl = video_ioctl2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736};
1737
Hans Verkuila3998102008-07-21 02:57:38 -03001738static const struct v4l2_ioctl_ops radio_ioctl_ops = {
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001739 .vidioc_querycap = radio_querycap,
1740 .vidioc_g_tuner = radio_g_tuner,
1741 .vidioc_enum_input = radio_enum_input,
1742 .vidioc_g_audio = radio_g_audio,
1743 .vidioc_s_tuner = radio_s_tuner,
1744 .vidioc_s_audio = radio_s_audio,
1745 .vidioc_s_input = radio_s_input,
1746 .vidioc_queryctrl = radio_queryctrl,
1747 .vidioc_g_ctrl = vidioc_g_ctrl,
1748 .vidioc_s_ctrl = vidioc_s_ctrl,
1749 .vidioc_g_frequency = vidioc_g_frequency,
1750 .vidioc_s_frequency = vidioc_s_frequency,
Trent Piephoa75d2042007-08-01 00:13:28 -03001751#ifdef CONFIG_VIDEO_ADV_DEBUG
1752 .vidioc_g_register = vidioc_g_register,
1753 .vidioc_s_register = vidioc_s_register,
1754#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755};
1756
Hans Verkuila3998102008-07-21 02:57:38 -03001757static struct video_device cx8800_radio_template = {
1758 .name = "cx8800-radio",
Hans Verkuila3998102008-07-21 02:57:38 -03001759 .fops = &radio_fops,
Hans Verkuila3998102008-07-21 02:57:38 -03001760 .ioctl_ops = &radio_ioctl_ops,
1761};
1762
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763/* ----------------------------------------------------------- */
1764
1765static void cx8800_unregister_video(struct cx8800_dev *dev)
1766{
1767 if (dev->radio_dev) {
Laurent Pinchartf0813b42009-11-27 13:57:30 -03001768 if (video_is_registered(dev->radio_dev))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769 video_unregister_device(dev->radio_dev);
1770 else
1771 video_device_release(dev->radio_dev);
1772 dev->radio_dev = NULL;
1773 }
1774 if (dev->vbi_dev) {
Laurent Pinchartf0813b42009-11-27 13:57:30 -03001775 if (video_is_registered(dev->vbi_dev))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001776 video_unregister_device(dev->vbi_dev);
1777 else
1778 video_device_release(dev->vbi_dev);
1779 dev->vbi_dev = NULL;
1780 }
1781 if (dev->video_dev) {
Laurent Pinchartf0813b42009-11-27 13:57:30 -03001782 if (video_is_registered(dev->video_dev))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783 video_unregister_device(dev->video_dev);
1784 else
1785 video_device_release(dev->video_dev);
1786 dev->video_dev = NULL;
1787 }
1788}
1789
1790static int __devinit cx8800_initdev(struct pci_dev *pci_dev,
1791 const struct pci_device_id *pci_id)
1792{
1793 struct cx8800_dev *dev;
1794 struct cx88_core *core;
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001795
Linus Torvalds1da177e2005-04-16 15:20:36 -07001796 int err;
1797
Panagiotis Issaris74081872006-01-11 19:40:56 -02001798 dev = kzalloc(sizeof(*dev),GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799 if (NULL == dev)
1800 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801
1802 /* pci init */
1803 dev->pci = pci_dev;
1804 if (pci_enable_device(pci_dev)) {
1805 err = -EIO;
1806 goto fail_free;
1807 }
1808 core = cx88_core_get(dev->pci);
1809 if (NULL == core) {
1810 err = -EINVAL;
1811 goto fail_free;
1812 }
1813 dev->core = core;
1814
1815 /* print pci info */
1816 pci_read_config_byte(pci_dev, PCI_CLASS_REVISION, &dev->pci_rev);
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -08001817 pci_read_config_byte(pci_dev, PCI_LATENCY_TIMER, &dev->pci_lat);
1818 printk(KERN_INFO "%s/0: found at %s, rev: %d, irq: %d, "
Greg Kroah-Hartman228aef62006-06-12 15:16:52 -07001819 "latency: %d, mmio: 0x%llx\n", core->name,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001820 pci_name(pci_dev), dev->pci_rev, pci_dev->irq,
Greg Kroah-Hartman228aef62006-06-12 15:16:52 -07001821 dev->pci_lat,(unsigned long long)pci_resource_start(pci_dev,0));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001822
1823 pci_set_master(pci_dev);
Yang Hongyang284901a2009-04-06 19:01:15 -07001824 if (!pci_dma_supported(pci_dev,DMA_BIT_MASK(32))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825 printk("%s/0: Oops: no 32bit PCI DMA ???\n",core->name);
1826 err = -EIO;
1827 goto fail_core;
1828 }
1829
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001830 /* Initialize VBI template */
1831 memcpy( &cx8800_vbi_template, &cx8800_video_template,
1832 sizeof(cx8800_vbi_template) );
1833 strcpy(cx8800_vbi_template.name,"cx8800-vbi");
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001834
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835 /* initialize driver struct */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836 spin_lock_init(&dev->slock);
Mauro Carvalho Chehab63ab1bd2007-01-20 13:58:33 -03001837 core->tvnorm = cx8800_video_template.current_norm;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001838
1839 /* init video dma queues */
1840 INIT_LIST_HEAD(&dev->vidq.active);
1841 INIT_LIST_HEAD(&dev->vidq.queued);
1842 dev->vidq.timeout.function = cx8800_vid_timeout;
1843 dev->vidq.timeout.data = (unsigned long)dev;
1844 init_timer(&dev->vidq.timeout);
1845 cx88_risc_stopper(dev->pci,&dev->vidq.stopper,
1846 MO_VID_DMACNTRL,0x11,0x00);
1847
1848 /* init vbi dma queues */
1849 INIT_LIST_HEAD(&dev->vbiq.active);
1850 INIT_LIST_HEAD(&dev->vbiq.queued);
1851 dev->vbiq.timeout.function = cx8800_vbi_timeout;
1852 dev->vbiq.timeout.data = (unsigned long)dev;
1853 init_timer(&dev->vbiq.timeout);
1854 cx88_risc_stopper(dev->pci,&dev->vbiq.stopper,
1855 MO_VID_DMACNTRL,0x88,0x00);
1856
1857 /* get irq */
1858 err = request_irq(pci_dev->irq, cx8800_irq,
Thomas Gleixner8076fe32006-07-01 19:29:37 -07001859 IRQF_SHARED | IRQF_DISABLED, core->name, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001860 if (err < 0) {
Trent Piepho5772f812007-08-15 14:41:59 -03001861 printk(KERN_ERR "%s/0: can't get IRQ %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001862 core->name,pci_dev->irq);
1863 goto fail_core;
1864 }
1865 cx_set(MO_PCI_INTMSK, core->pci_irqmask);
1866
1867 /* load and configure helper modules */
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001868
Hans Verkuil38f9d302008-07-23 05:09:15 -03001869 if (core->board.audio_chip == V4L2_IDENT_WM8775)
Hans Verkuile6574f22009-04-01 03:57:53 -03001870 v4l2_i2c_new_subdev(&core->v4l2_dev, &core->i2c_adap,
Hans Verkuil53dacb12009-08-10 02:49:08 -03001871 "wm8775", "wm8775", 0x36 >> 1, NULL);
Hans Verkuilb8341e12009-03-29 08:26:01 -03001872
1873 if (core->board.audio_chip == V4L2_IDENT_TVAUDIO) {
1874 /* This probes for a tda9874 as is used on some
1875 Pixelview Ultra boards. */
Hans Verkuil53dacb12009-08-10 02:49:08 -03001876 v4l2_i2c_new_subdev(&core->v4l2_dev,
Hans Verkuil1792f682009-03-30 11:47:55 -03001877 &core->i2c_adap,
Hans Verkuil53dacb12009-08-10 02:49:08 -03001878 "tvaudio", "tvaudio", 0, I2C_ADDRS(0xb0 >> 1));
Hans Verkuilb8341e12009-03-29 08:26:01 -03001879 }
Steven Toth30579062006-09-25 12:43:42 -03001880
Michael Krufky6fcecce2007-08-24 01:32:31 -03001881 switch (core->boardnr) {
1882 case CX88_BOARD_DVICO_FUSIONHDTV_5_GOLD:
Hans Verkuilb8341e12009-03-29 08:26:01 -03001883 case CX88_BOARD_DVICO_FUSIONHDTV_7_GOLD: {
1884 static struct i2c_board_info rtc_info = {
1885 I2C_BOARD_INFO("isl1208", 0x6f)
1886 };
1887
Michael Krufky6fcecce2007-08-24 01:32:31 -03001888 request_module("rtc-isl1208");
Hans Verkuilb8341e12009-03-29 08:26:01 -03001889 core->i2c_rtc = i2c_new_device(&core->i2c_adap, &rtc_info);
1890 }
Michael Krufky8efd2e22008-04-22 14:45:14 -03001891 /* break intentionally omitted */
1892 case CX88_BOARD_DVICO_FUSIONHDTV_5_PCI_NANO:
1893 request_module("ir-kbd-i2c");
Michael Krufky6fcecce2007-08-24 01:32:31 -03001894 }
1895
Linus Torvalds1da177e2005-04-16 15:20:36 -07001896 /* register v4l devices */
1897 dev->video_dev = cx88_vdev_init(core,dev->pci,
1898 &cx8800_video_template,"video");
Laurent Pinchart63b0d5a2009-12-10 11:44:04 -02001899 video_set_drvdata(dev->video_dev, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001900 err = video_register_device(dev->video_dev,VFL_TYPE_GRABBER,
1901 video_nr[core->nr]);
1902 if (err < 0) {
Trent Piepho5772f812007-08-15 14:41:59 -03001903 printk(KERN_ERR "%s/0: can't register video device\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001904 core->name);
1905 goto fail_unreg;
1906 }
Laurent Pinchart38c7c032009-11-27 13:57:15 -03001907 printk(KERN_INFO "%s/0: registered device %s [v4l2]\n",
1908 core->name, video_device_node_name(dev->video_dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909
1910 dev->vbi_dev = cx88_vdev_init(core,dev->pci,&cx8800_vbi_template,"vbi");
Laurent Pinchart63b0d5a2009-12-10 11:44:04 -02001911 video_set_drvdata(dev->vbi_dev, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912 err = video_register_device(dev->vbi_dev,VFL_TYPE_VBI,
1913 vbi_nr[core->nr]);
1914 if (err < 0) {
Trent Piepho5772f812007-08-15 14:41:59 -03001915 printk(KERN_ERR "%s/0: can't register vbi device\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001916 core->name);
1917 goto fail_unreg;
1918 }
Laurent Pinchart38c7c032009-11-27 13:57:15 -03001919 printk(KERN_INFO "%s/0: registered device %s\n",
1920 core->name, video_device_node_name(dev->vbi_dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001921
Trent Piepho6a59d642007-08-15 14:41:57 -03001922 if (core->board.radio.type == CX88_RADIO) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001923 dev->radio_dev = cx88_vdev_init(core,dev->pci,
1924 &cx8800_radio_template,"radio");
Laurent Pinchart63b0d5a2009-12-10 11:44:04 -02001925 video_set_drvdata(dev->radio_dev, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001926 err = video_register_device(dev->radio_dev,VFL_TYPE_RADIO,
1927 radio_nr[core->nr]);
1928 if (err < 0) {
Trent Piepho5772f812007-08-15 14:41:59 -03001929 printk(KERN_ERR "%s/0: can't register radio device\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001930 core->name);
1931 goto fail_unreg;
1932 }
Laurent Pinchart38c7c032009-11-27 13:57:15 -03001933 printk(KERN_INFO "%s/0: registered device %s\n",
1934 core->name, video_device_node_name(dev->radio_dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001935 }
1936
1937 /* everything worked */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001938 pci_set_drvdata(pci_dev,dev);
1939
1940 /* initial device configuration */
Ingo Molnar3593cab2006-02-07 06:49:14 -02001941 mutex_lock(&core->lock);
Mauro Carvalho Chehab63ab1bd2007-01-20 13:58:33 -03001942 cx88_set_tvnorm(core,core->tvnorm);
Mauro Carvalho Chehab70f00042006-01-09 15:25:26 -02001943 init_controls(core);
Mauro Carvalho Chehabe90311a2007-01-20 13:58:29 -03001944 cx88_video_mux(core,0);
Ingo Molnar3593cab2006-02-07 06:49:14 -02001945 mutex_unlock(&core->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001946
1947 /* start tvaudio thread */
Trent Piepho6a59d642007-08-15 14:41:57 -03001948 if (core->board.tuner_type != TUNER_ABSENT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001949 core->kthread = kthread_run(cx88_audio_thread, core, "cx88 tvaudio");
Cyrill Gorcunov32b78de2007-07-19 11:44:11 -03001950 if (IS_ERR(core->kthread)) {
1951 err = PTR_ERR(core->kthread);
Trent Piepho5772f812007-08-15 14:41:59 -03001952 printk(KERN_ERR "%s/0: failed to create cx88 audio thread, err=%d\n",
1953 core->name, err);
Cyrill Gorcunov32b78de2007-07-19 11:44:11 -03001954 }
1955 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001956 return 0;
1957
1958fail_unreg:
1959 cx8800_unregister_video(dev);
1960 free_irq(pci_dev->irq, dev);
1961fail_core:
1962 cx88_core_put(core,dev->pci);
1963fail_free:
1964 kfree(dev);
1965 return err;
1966}
1967
1968static void __devexit cx8800_finidev(struct pci_dev *pci_dev)
1969{
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -08001970 struct cx8800_dev *dev = pci_get_drvdata(pci_dev);
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001971 struct cx88_core *core = dev->core;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001972
1973 /* stop thread */
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001974 if (core->kthread) {
1975 kthread_stop(core->kthread);
1976 core->kthread = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001977 }
1978
Marton Balintb12203d2008-03-26 02:07:35 -03001979 if (core->ir)
Mauro Carvalho Chehab92f4fc12010-03-31 16:07:49 -03001980 cx88_ir_stop(core);
Marton Balintb12203d2008-03-26 02:07:35 -03001981
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001982 cx88_shutdown(core); /* FIXME */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001983 pci_disable_device(pci_dev);
1984
1985 /* unregister stuff */
1986
1987 free_irq(pci_dev->irq, dev);
1988 cx8800_unregister_video(dev);
1989 pci_set_drvdata(pci_dev, NULL);
1990
1991 /* free memory */
1992 btcx_riscmem_free(dev->pci,&dev->vidq.stopper);
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001993 cx88_core_put(core,dev->pci);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001994 kfree(dev);
1995}
1996
Alexey Dobriyan17bc98a2006-08-12 22:01:27 -03001997#ifdef CONFIG_PM
Linus Torvalds1da177e2005-04-16 15:20:36 -07001998static int cx8800_suspend(struct pci_dev *pci_dev, pm_message_t state)
1999{
Mauro Carvalho Chehabb45009b2005-06-23 22:05:03 -07002000 struct cx8800_dev *dev = pci_get_drvdata(pci_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002001 struct cx88_core *core = dev->core;
2002
2003 /* stop video+vbi capture */
2004 spin_lock(&dev->slock);
2005 if (!list_empty(&dev->vidq.active)) {
Trent Piepho5772f812007-08-15 14:41:59 -03002006 printk("%s/0: suspend video\n", core->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002007 stop_video_dma(dev);
2008 del_timer(&dev->vidq.timeout);
2009 }
2010 if (!list_empty(&dev->vbiq.active)) {
Trent Piepho5772f812007-08-15 14:41:59 -03002011 printk("%s/0: suspend vbi\n", core->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002012 cx8800_stop_vbi_dma(dev);
2013 del_timer(&dev->vbiq.timeout);
2014 }
2015 spin_unlock(&dev->slock);
2016
Mauro Carvalho Chehab13595a52007-10-01 08:51:39 -03002017 if (core->ir)
Mauro Carvalho Chehab92f4fc12010-03-31 16:07:49 -03002018 cx88_ir_stop(core);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002019 /* FIXME -- shutdown device */
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07002020 cx88_shutdown(core);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002021
2022 pci_save_state(pci_dev);
2023 if (0 != pci_set_power_state(pci_dev, pci_choose_state(pci_dev, state))) {
2024 pci_disable_device(pci_dev);
2025 dev->state.disabled = 1;
2026 }
2027 return 0;
2028}
2029
2030static int cx8800_resume(struct pci_dev *pci_dev)
2031{
Mauro Carvalho Chehabb45009b2005-06-23 22:05:03 -07002032 struct cx8800_dev *dev = pci_get_drvdata(pci_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002033 struct cx88_core *core = dev->core;
Mauro Carvalho Chehab08adb9e2005-09-09 13:03:55 -07002034 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002035
2036 if (dev->state.disabled) {
Mauro Carvalho Chehab08adb9e2005-09-09 13:03:55 -07002037 err=pci_enable_device(pci_dev);
2038 if (err) {
Trent Piepho5772f812007-08-15 14:41:59 -03002039 printk(KERN_ERR "%s/0: can't enable device\n",
2040 core->name);
Mauro Carvalho Chehab08adb9e2005-09-09 13:03:55 -07002041 return err;
2042 }
2043
Linus Torvalds1da177e2005-04-16 15:20:36 -07002044 dev->state.disabled = 0;
2045 }
Mauro Carvalho Chehab08adb9e2005-09-09 13:03:55 -07002046 err= pci_set_power_state(pci_dev, PCI_D0);
2047 if (err) {
Trent Piepho5772f812007-08-15 14:41:59 -03002048 printk(KERN_ERR "%s/0: can't set power state\n", core->name);
Mauro Carvalho Chehab08adb9e2005-09-09 13:03:55 -07002049 pci_disable_device(pci_dev);
2050 dev->state.disabled = 1;
2051
2052 return err;
2053 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054 pci_restore_state(pci_dev);
2055
Linus Torvalds1da177e2005-04-16 15:20:36 -07002056 /* FIXME: re-initialize hardware */
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07002057 cx88_reset(core);
Mauro Carvalho Chehab13595a52007-10-01 08:51:39 -03002058 if (core->ir)
Mauro Carvalho Chehab92f4fc12010-03-31 16:07:49 -03002059 cx88_ir_start(core);
Mauro Carvalho Chehab13595a52007-10-01 08:51:39 -03002060
2061 cx_set(MO_PCI_INTMSK, core->pci_irqmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062
2063 /* restart video+vbi capture */
2064 spin_lock(&dev->slock);
2065 if (!list_empty(&dev->vidq.active)) {
Trent Piepho5772f812007-08-15 14:41:59 -03002066 printk("%s/0: resume video\n", core->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067 restart_video_queue(dev,&dev->vidq);
2068 }
2069 if (!list_empty(&dev->vbiq.active)) {
Trent Piepho5772f812007-08-15 14:41:59 -03002070 printk("%s/0: resume vbi\n", core->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002071 cx8800_restart_vbi_queue(dev,&dev->vbiq);
2072 }
2073 spin_unlock(&dev->slock);
2074
2075 return 0;
2076}
Alexey Dobriyan17bc98a2006-08-12 22:01:27 -03002077#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002078
2079/* ----------------------------------------------------------- */
2080
Adrian Bunk408b6642005-05-01 08:59:29 -07002081static struct pci_device_id cx8800_pci_tbl[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002082 {
2083 .vendor = 0x14f1,
2084 .device = 0x8800,
Mauro Carvalho Chehabb45009b2005-06-23 22:05:03 -07002085 .subvendor = PCI_ANY_ID,
2086 .subdevice = PCI_ANY_ID,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087 },{
2088 /* --- end of list --- */
2089 }
2090};
2091MODULE_DEVICE_TABLE(pci, cx8800_pci_tbl);
2092
2093static struct pci_driver cx8800_pci_driver = {
Mauro Carvalho Chehabb45009b2005-06-23 22:05:03 -07002094 .name = "cx8800",
2095 .id_table = cx8800_pci_tbl,
2096 .probe = cx8800_initdev,
2097 .remove = __devexit_p(cx8800_finidev),
Alexey Dobriyan17bc98a2006-08-12 22:01:27 -03002098#ifdef CONFIG_PM
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099 .suspend = cx8800_suspend,
2100 .resume = cx8800_resume,
Alexey Dobriyan17bc98a2006-08-12 22:01:27 -03002101#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002102};
2103
Peter Huewe31d0f842009-07-17 01:00:01 +02002104static int __init cx8800_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105{
Trent Piepho5772f812007-08-15 14:41:59 -03002106 printk(KERN_INFO "cx88/0: cx2388x v4l2 driver version %d.%d.%d loaded\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107 (CX88_VERSION_CODE >> 16) & 0xff,
2108 (CX88_VERSION_CODE >> 8) & 0xff,
2109 CX88_VERSION_CODE & 0xff);
2110#ifdef SNAPSHOT
2111 printk(KERN_INFO "cx2388x: snapshot date %04d-%02d-%02d\n",
2112 SNAPSHOT/10000, (SNAPSHOT/100)%100, SNAPSHOT%100);
2113#endif
2114 return pci_register_driver(&cx8800_pci_driver);
2115}
2116
Peter Huewe31d0f842009-07-17 01:00:01 +02002117static void __exit cx8800_fini(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002118{
2119 pci_unregister_driver(&cx8800_pci_driver);
2120}
2121
2122module_init(cx8800_init);
2123module_exit(cx8800_fini);
2124
2125/* ----------------------------------------------------------- */
2126/*
2127 * Local variables:
2128 * c-basic-offset: 8
2129 * End:
Mauro Carvalho Chehabb45009b2005-06-23 22:05:03 -07002130 * 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 -07002131 */