blob: 2bb54c3ef5cdcefbc708718aebee684005f80e3d [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
78/* ------------------------------------------------------------------ */
79
80static LIST_HEAD(cx8800_devlist);
81
82/* ------------------------------------------------------------------- */
83/* static data */
84
Linus Torvalds1da177e2005-04-16 15:20:36 -070085static struct cx8800_fmt formats[] = {
86 {
87 .name = "8 bpp, gray",
88 .fourcc = V4L2_PIX_FMT_GREY,
89 .cxformat = ColorFormatY8,
90 .depth = 8,
91 .flags = FORMAT_FLAGS_PACKED,
92 },{
93 .name = "15 bpp RGB, le",
94 .fourcc = V4L2_PIX_FMT_RGB555,
95 .cxformat = ColorFormatRGB15,
96 .depth = 16,
97 .flags = FORMAT_FLAGS_PACKED,
98 },{
99 .name = "15 bpp RGB, be",
100 .fourcc = V4L2_PIX_FMT_RGB555X,
101 .cxformat = ColorFormatRGB15 | ColorFormatBSWAP,
102 .depth = 16,
103 .flags = FORMAT_FLAGS_PACKED,
104 },{
105 .name = "16 bpp RGB, le",
106 .fourcc = V4L2_PIX_FMT_RGB565,
107 .cxformat = ColorFormatRGB16,
108 .depth = 16,
109 .flags = FORMAT_FLAGS_PACKED,
110 },{
111 .name = "16 bpp RGB, be",
112 .fourcc = V4L2_PIX_FMT_RGB565X,
113 .cxformat = ColorFormatRGB16 | ColorFormatBSWAP,
114 .depth = 16,
115 .flags = FORMAT_FLAGS_PACKED,
116 },{
117 .name = "24 bpp RGB, le",
118 .fourcc = V4L2_PIX_FMT_BGR24,
119 .cxformat = ColorFormatRGB24,
120 .depth = 24,
121 .flags = FORMAT_FLAGS_PACKED,
122 },{
123 .name = "32 bpp RGB, le",
124 .fourcc = V4L2_PIX_FMT_BGR32,
125 .cxformat = ColorFormatRGB32,
126 .depth = 32,
127 .flags = FORMAT_FLAGS_PACKED,
128 },{
129 .name = "32 bpp RGB, be",
130 .fourcc = V4L2_PIX_FMT_RGB32,
131 .cxformat = ColorFormatRGB32 | ColorFormatBSWAP | ColorFormatWSWAP,
132 .depth = 32,
133 .flags = FORMAT_FLAGS_PACKED,
134 },{
135 .name = "4:2:2, packed, YUYV",
136 .fourcc = V4L2_PIX_FMT_YUYV,
137 .cxformat = ColorFormatYUY2,
138 .depth = 16,
139 .flags = FORMAT_FLAGS_PACKED,
140 },{
141 .name = "4:2:2, packed, UYVY",
142 .fourcc = V4L2_PIX_FMT_UYVY,
143 .cxformat = ColorFormatYUY2 | ColorFormatBSWAP,
144 .depth = 16,
145 .flags = FORMAT_FLAGS_PACKED,
146 },
147};
148
149static struct cx8800_fmt* format_by_fourcc(unsigned int fourcc)
150{
151 unsigned int i;
152
153 for (i = 0; i < ARRAY_SIZE(formats); i++)
154 if (formats[i].fourcc == fourcc)
155 return formats+i;
156 return NULL;
157}
158
159/* ------------------------------------------------------------------- */
160
161static const struct v4l2_queryctrl no_ctl = {
162 .name = "42",
163 .flags = V4L2_CTRL_FLAG_DISABLED,
164};
165
166static struct cx88_ctrl cx8800_ctls[] = {
167 /* --- video --- */
168 {
169 .v = {
170 .id = V4L2_CID_BRIGHTNESS,
171 .name = "Brightness",
172 .minimum = 0x00,
173 .maximum = 0xff,
174 .step = 1,
Marcin Rudowski9f9c9072006-03-12 00:03:47 -0300175 .default_value = 0x7f,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 .type = V4L2_CTRL_TYPE_INTEGER,
177 },
178 .off = 128,
179 .reg = MO_CONTR_BRIGHT,
180 .mask = 0x00ff,
181 .shift = 0,
182 },{
183 .v = {
184 .id = V4L2_CID_CONTRAST,
185 .name = "Contrast",
186 .minimum = 0,
187 .maximum = 0xff,
188 .step = 1,
Mauro Carvalho Chehab70f00042006-01-09 15:25:26 -0200189 .default_value = 0x3f,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190 .type = V4L2_CTRL_TYPE_INTEGER,
191 },
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -0700192 .off = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 .reg = MO_CONTR_BRIGHT,
194 .mask = 0xff00,
195 .shift = 8,
196 },{
197 .v = {
198 .id = V4L2_CID_HUE,
199 .name = "Hue",
200 .minimum = 0,
201 .maximum = 0xff,
202 .step = 1,
Marcin Rudowski9f9c9072006-03-12 00:03:47 -0300203 .default_value = 0x7f,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 .type = V4L2_CTRL_TYPE_INTEGER,
205 },
Michael Krufky9ac4c152005-07-07 17:58:38 -0700206 .off = 128,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 .reg = MO_HUE,
208 .mask = 0x00ff,
209 .shift = 0,
210 },{
211 /* strictly, this only describes only U saturation.
212 * V saturation is handled specially through code.
213 */
214 .v = {
215 .id = V4L2_CID_SATURATION,
216 .name = "Saturation",
217 .minimum = 0,
218 .maximum = 0xff,
219 .step = 1,
Mauro Carvalho Chehab70f00042006-01-09 15:25:26 -0200220 .default_value = 0x7f,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 .type = V4L2_CTRL_TYPE_INTEGER,
222 },
223 .off = 0,
224 .reg = MO_UV_SATURATION,
225 .mask = 0x00ff,
226 .shift = 0,
227 },{
Frej Drejhammar6d042032008-03-23 22:43:21 -0300228 .v = {
229 .id = V4L2_CID_CHROMA_AGC,
230 .name = "Chroma AGC",
231 .minimum = 0,
232 .maximum = 1,
Frej Drejhammar87a17382008-03-23 22:43:22 -0300233 .default_value = 0x1,
Frej Drejhammar6d042032008-03-23 22:43:21 -0300234 .type = V4L2_CTRL_TYPE_BOOLEAN,
235 },
236 .reg = MO_INPUT_FORMAT,
237 .mask = 1 << 10,
238 .shift = 10,
239 }, {
Frej Drejhammar1b879c42008-03-23 22:43:24 -0300240 .v = {
241 .id = V4L2_CID_COLOR_KILLER,
242 .name = "Color killer",
243 .minimum = 0,
244 .maximum = 1,
Frej Drejhammar0b5afdd2008-03-23 22:43:25 -0300245 .default_value = 0x1,
Frej Drejhammar1b879c42008-03-23 22:43:24 -0300246 .type = V4L2_CTRL_TYPE_BOOLEAN,
247 },
248 .reg = MO_INPUT_FORMAT,
249 .mask = 1 << 9,
250 .shift = 9,
251 }, {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 /* --- audio --- */
253 .v = {
254 .id = V4L2_CID_AUDIO_MUTE,
255 .name = "Mute",
256 .minimum = 0,
257 .maximum = 1,
Mauro Carvalho Chehab70f00042006-01-09 15:25:26 -0200258 .default_value = 1,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 .type = V4L2_CTRL_TYPE_BOOLEAN,
260 },
261 .reg = AUD_VOL_CTL,
262 .sreg = SHADOW_AUD_VOL_CTL,
263 .mask = (1 << 6),
264 .shift = 6,
265 },{
266 .v = {
267 .id = V4L2_CID_AUDIO_VOLUME,
268 .name = "Volume",
269 .minimum = 0,
270 .maximum = 0x3f,
271 .step = 1,
Marcin Rudowski9f9c9072006-03-12 00:03:47 -0300272 .default_value = 0x3f,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 .type = V4L2_CTRL_TYPE_INTEGER,
274 },
275 .reg = AUD_VOL_CTL,
276 .sreg = SHADOW_AUD_VOL_CTL,
277 .mask = 0x3f,
278 .shift = 0,
279 },{
280 .v = {
281 .id = V4L2_CID_AUDIO_BALANCE,
282 .name = "Balance",
283 .minimum = 0,
284 .maximum = 0x7f,
285 .step = 1,
286 .default_value = 0x40,
287 .type = V4L2_CTRL_TYPE_INTEGER,
288 },
289 .reg = AUD_BAL_CTL,
290 .sreg = SHADOW_AUD_BAL_CTL,
291 .mask = 0x7f,
292 .shift = 0,
293 }
294};
Adrian Bunk408b6642005-05-01 08:59:29 -0700295static const int CX8800_CTLS = ARRAY_SIZE(cx8800_ctls);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296
Hans Verkuil2ba58892009-02-13 10:57:48 -0300297/* Must be sorted from low to high control ID! */
Michael Krufky38a27132006-06-26 23:42:39 -0300298const u32 cx88_user_ctrls[] = {
299 V4L2_CID_USER_CLASS,
300 V4L2_CID_BRIGHTNESS,
301 V4L2_CID_CONTRAST,
302 V4L2_CID_SATURATION,
303 V4L2_CID_HUE,
304 V4L2_CID_AUDIO_VOLUME,
305 V4L2_CID_AUDIO_BALANCE,
306 V4L2_CID_AUDIO_MUTE,
Frej Drejhammar6d042032008-03-23 22:43:21 -0300307 V4L2_CID_CHROMA_AGC,
Frej Drejhammar1b879c42008-03-23 22:43:24 -0300308 V4L2_CID_COLOR_KILLER,
Michael Krufky38a27132006-06-26 23:42:39 -0300309 0
310};
311EXPORT_SYMBOL(cx88_user_ctrls);
312
313static const u32 *ctrl_classes[] = {
314 cx88_user_ctrls,
315 NULL
316};
317
Frej Drejhammar6d042032008-03-23 22:43:21 -0300318int cx8800_ctrl_query(struct cx88_core *core, struct v4l2_queryctrl *qctrl)
Michael Krufky38a27132006-06-26 23:42:39 -0300319{
320 int i;
321
322 if (qctrl->id < V4L2_CID_BASE ||
323 qctrl->id >= V4L2_CID_LASTP1)
324 return -EINVAL;
325 for (i = 0; i < CX8800_CTLS; i++)
326 if (cx8800_ctls[i].v.id == qctrl->id)
327 break;
328 if (i == CX8800_CTLS) {
329 *qctrl = no_ctl;
330 return 0;
331 }
332 *qctrl = cx8800_ctls[i].v;
Frej Drejhammar6d042032008-03-23 22:43:21 -0300333 /* Report chroma AGC as inactive when SECAM is selected */
334 if (cx8800_ctls[i].v.id == V4L2_CID_CHROMA_AGC &&
335 core->tvnorm & V4L2_STD_SECAM)
336 qctrl->flags |= V4L2_CTRL_FLAG_INACTIVE;
337
Michael Krufky38a27132006-06-26 23:42:39 -0300338 return 0;
339}
340EXPORT_SYMBOL(cx8800_ctrl_query);
341
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342/* ------------------------------------------------------------------- */
343/* resource management */
344
345static int res_get(struct cx8800_dev *dev, struct cx8800_fh *fh, unsigned int bit)
346{
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700347 struct cx88_core *core = dev->core;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 if (fh->resources & bit)
349 /* have it already allocated */
350 return 1;
351
352 /* is it free? */
Ingo Molnar3593cab2006-02-07 06:49:14 -0200353 mutex_lock(&core->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 if (dev->resources & bit) {
355 /* no, someone else uses it */
Ingo Molnar3593cab2006-02-07 06:49:14 -0200356 mutex_unlock(&core->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 return 0;
358 }
359 /* it's free, grab it */
360 fh->resources |= bit;
361 dev->resources |= bit;
362 dprintk(1,"res: get %d\n",bit);
Ingo Molnar3593cab2006-02-07 06:49:14 -0200363 mutex_unlock(&core->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 return 1;
365}
366
367static
368int res_check(struct cx8800_fh *fh, unsigned int bit)
369{
370 return (fh->resources & bit);
371}
372
373static
374int res_locked(struct cx8800_dev *dev, unsigned int bit)
375{
376 return (dev->resources & bit);
377}
378
379static
380void res_free(struct cx8800_dev *dev, struct cx8800_fh *fh, unsigned int bits)
381{
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700382 struct cx88_core *core = dev->core;
Eric Sesterhennae246012006-03-13 13:17:11 -0300383 BUG_ON((fh->resources & bits) != bits);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384
Ingo Molnar3593cab2006-02-07 06:49:14 -0200385 mutex_lock(&core->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 fh->resources &= ~bits;
387 dev->resources &= ~bits;
388 dprintk(1,"res: put %d\n",bits);
Ingo Molnar3593cab2006-02-07 06:49:14 -0200389 mutex_unlock(&core->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390}
391
392/* ------------------------------------------------------------------ */
393
Mauro Carvalho Chehabe90311a2007-01-20 13:58:29 -0300394int cx88_video_mux(struct cx88_core *core, unsigned int input)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395{
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700396 /* struct cx88_core *core = dev->core; */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397
398 dprintk(1,"video_mux: %d [vmux=%d,gpio=0x%x,0x%x,0x%x,0x%x]\n",
Trent Piepho6a59d642007-08-15 14:41:57 -0300399 input, INPUT(input).vmux,
400 INPUT(input).gpio0,INPUT(input).gpio1,
401 INPUT(input).gpio2,INPUT(input).gpio3);
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700402 core->input = input;
Trent Piepho6a59d642007-08-15 14:41:57 -0300403 cx_andor(MO_INPUT_FORMAT, 0x03 << 14, INPUT(input).vmux << 14);
404 cx_write(MO_GP3_IO, INPUT(input).gpio3);
405 cx_write(MO_GP0_IO, INPUT(input).gpio0);
406 cx_write(MO_GP1_IO, INPUT(input).gpio1);
407 cx_write(MO_GP2_IO, INPUT(input).gpio2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408
Trent Piepho6a59d642007-08-15 14:41:57 -0300409 switch (INPUT(input).type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 case CX88_VMUX_SVIDEO:
411 cx_set(MO_AFECFG_IO, 0x00000001);
412 cx_set(MO_INPUT_FORMAT, 0x00010010);
413 cx_set(MO_FILTER_EVEN, 0x00002020);
414 cx_set(MO_FILTER_ODD, 0x00002020);
415 break;
416 default:
417 cx_clear(MO_AFECFG_IO, 0x00000001);
418 cx_clear(MO_INPUT_FORMAT, 0x00010010);
419 cx_clear(MO_FILTER_EVEN, 0x00002020);
420 cx_clear(MO_FILTER_ODD, 0x00002020);
421 break;
422 }
Michael Krufkyf24546a2006-10-16 16:51:11 -0300423
Ricardo Cerqueira66e6fbd2007-10-16 20:52:08 -0300424 /* if there are audioroutes defined, we have an external
425 ADC to deal with audio */
Ricardo Cerqueira66e6fbd2007-10-16 20:52:08 -0300426 if (INPUT(input).audioroute) {
Ricardo Cerqueira66e6fbd2007-10-16 20:52:08 -0300427 /* The wm8775 module has the "2" route hardwired into
428 the initialization. Some boards may use different
429 routes for different inputs. HVR-1300 surely does */
430 if (core->board.audio_chip &&
Hans Verkuil38f9d302008-07-23 05:09:15 -0300431 core->board.audio_chip == V4L2_IDENT_WM8775) {
Hans Verkuil5325b422009-04-02 11:26:22 -0300432 call_all(core, audio, s_routing,
433 INPUT(input).audioroute, 0, 0);
Ricardo Cerqueira66e6fbd2007-10-16 20:52:08 -0300434 }
Darron Broad430189d2008-10-15 14:18:42 -0300435 /* cx2388's C-ADC is connected to the tuner only.
436 When used with S-Video, that ADC is busy dealing with
437 chroma, so an external must be used for baseband audio */
438 if (INPUT(input).type != CX88_VMUX_TELEVISION ) {
439 /* "I2S ADC mode" */
440 core->tvaudio = WW_I2SADC;
441 cx88_set_tvaudio(core);
442 } else {
443 /* Normal mode */
444 cx_write(AUD_I2SCNTL, 0x0);
445 cx_clear(AUD_CTL, EN_I2SIN_ENABLE);
446 }
Michael Krufkyf24546a2006-10-16 16:51:11 -0300447 }
Ricardo Cerqueira66e6fbd2007-10-16 20:52:08 -0300448
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 return 0;
450}
Mauro Carvalho Chehabe90311a2007-01-20 13:58:29 -0300451EXPORT_SYMBOL(cx88_video_mux);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452
453/* ------------------------------------------------------------------ */
454
455static int start_video_dma(struct cx8800_dev *dev,
456 struct cx88_dmaqueue *q,
457 struct cx88_buffer *buf)
458{
459 struct cx88_core *core = dev->core;
460
461 /* setup fifo + format */
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700462 cx88_sram_channel_setup(core, &cx88_sram_channels[SRAM_CH21],
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 buf->bpl, buf->risc.dma);
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700464 cx88_set_scale(core, buf->vb.width, buf->vb.height, buf->vb.field);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 cx_write(MO_COLOR_CTRL, buf->fmt->cxformat | ColorFormatGamma);
466
467 /* reset counter */
468 cx_write(MO_VIDY_GPCNTRL,GP_COUNT_CONTROL_RESET);
469 q->count = 1;
470
471 /* enable irqs */
Trent Piepho8ddac9e2007-08-18 06:57:55 -0300472 cx_set(MO_PCI_INTMSK, core->pci_irqmask | PCI_INT_VIDINT);
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700473
474 /* Enables corresponding bits at PCI_INT_STAT:
475 bits 0 to 4: video, audio, transport stream, VIP, Host
476 bit 7: timer
477 bits 8 and 9: DMA complete for: SRC, DST
478 bits 10 and 11: BERR signal asserted for RISC: RD, WR
479 bits 12 to 15: BERR signal asserted for: BRDG, SRC, DST, IPB
480 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 cx_set(MO_VID_INTMSK, 0x0f0011);
482
483 /* enable capture */
484 cx_set(VID_CAPTURE_CONTROL,0x06);
485
486 /* start dma */
487 cx_set(MO_DEV_CNTRL2, (1<<5));
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700488 cx_set(MO_VID_DMACNTRL, 0x11); /* Planar Y and packed FIFO and RISC enable */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489
490 return 0;
491}
492
Alexey Dobriyan17bc98a2006-08-12 22:01:27 -0300493#ifdef CONFIG_PM
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494static int stop_video_dma(struct cx8800_dev *dev)
495{
496 struct cx88_core *core = dev->core;
497
498 /* stop dma */
499 cx_clear(MO_VID_DMACNTRL, 0x11);
500
501 /* disable capture */
502 cx_clear(VID_CAPTURE_CONTROL,0x06);
503
504 /* disable irqs */
Trent Piepho8ddac9e2007-08-18 06:57:55 -0300505 cx_clear(MO_PCI_INTMSK, PCI_INT_VIDINT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 cx_clear(MO_VID_INTMSK, 0x0f0011);
507 return 0;
508}
Alexey Dobriyan17bc98a2006-08-12 22:01:27 -0300509#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510
511static int restart_video_queue(struct cx8800_dev *dev,
512 struct cx88_dmaqueue *q)
513{
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700514 struct cx88_core *core = dev->core;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 struct cx88_buffer *buf, *prev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516
517 if (!list_empty(&q->active)) {
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -0800518 buf = list_entry(q->active.next, struct cx88_buffer, vb.queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 dprintk(2,"restart_queue [%p/%d]: restart dma\n",
520 buf, buf->vb.i);
521 start_video_dma(dev, q, buf);
Trent Piepho8bb629e22007-10-10 05:37:40 -0300522 list_for_each_entry(buf, &q->active, vb.queue)
523 buf->count = q->count++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
525 return 0;
526 }
527
528 prev = NULL;
529 for (;;) {
530 if (list_empty(&q->queued))
531 return 0;
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -0800532 buf = list_entry(q->queued.next, struct cx88_buffer, vb.queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 if (NULL == prev) {
Akinobu Mita179e0912006-06-26 00:24:41 -0700534 list_move_tail(&buf->vb.queue, &q->active);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 start_video_dma(dev, q, buf);
Brandon Philips0fc06862007-11-06 20:02:36 -0300536 buf->vb.state = VIDEOBUF_ACTIVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 buf->count = q->count++;
538 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
539 dprintk(2,"[%p/%d] restart_queue - first active\n",
540 buf,buf->vb.i);
541
542 } else if (prev->vb.width == buf->vb.width &&
543 prev->vb.height == buf->vb.height &&
544 prev->fmt == buf->fmt) {
Akinobu Mita179e0912006-06-26 00:24:41 -0700545 list_move_tail(&buf->vb.queue, &q->active);
Brandon Philips0fc06862007-11-06 20:02:36 -0300546 buf->vb.state = VIDEOBUF_ACTIVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 buf->count = q->count++;
548 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
549 dprintk(2,"[%p/%d] restart_queue - move to active\n",
550 buf,buf->vb.i);
551 } else {
552 return 0;
553 }
554 prev = buf;
555 }
556}
557
558/* ------------------------------------------------------------------ */
559
560static int
561buffer_setup(struct videobuf_queue *q, unsigned int *count, unsigned int *size)
562{
563 struct cx8800_fh *fh = q->priv_data;
564
565 *size = fh->fmt->depth*fh->width*fh->height >> 3;
566 if (0 == *count)
567 *count = 32;
568 while (*size * *count > vid_limit * 1024 * 1024)
569 (*count)--;
570 return 0;
571}
572
573static int
574buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
575 enum v4l2_field field)
576{
577 struct cx8800_fh *fh = q->priv_data;
578 struct cx8800_dev *dev = fh->dev;
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700579 struct cx88_core *core = dev->core;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 struct cx88_buffer *buf = container_of(vb,struct cx88_buffer,vb);
Mauro Carvalho Chehabc1accaa2007-08-23 16:37:49 -0300581 struct videobuf_dmabuf *dma=videobuf_to_dma(&buf->vb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 int rc, init_buffer = 0;
583
584 BUG_ON(NULL == fh->fmt);
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700585 if (fh->width < 48 || fh->width > norm_maxw(core->tvnorm) ||
586 fh->height < 32 || fh->height > norm_maxh(core->tvnorm))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 return -EINVAL;
588 buf->vb.size = (fh->width * fh->height * fh->fmt->depth) >> 3;
589 if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size)
590 return -EINVAL;
591
592 if (buf->fmt != fh->fmt ||
593 buf->vb.width != fh->width ||
594 buf->vb.height != fh->height ||
595 buf->vb.field != field) {
596 buf->fmt = fh->fmt;
597 buf->vb.width = fh->width;
598 buf->vb.height = fh->height;
599 buf->vb.field = field;
600 init_buffer = 1;
601 }
602
Brandon Philips0fc06862007-11-06 20:02:36 -0300603 if (VIDEOBUF_NEEDS_INIT == buf->vb.state) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 init_buffer = 1;
Mauro Carvalho Chehabc7b0ac02006-03-10 12:29:15 -0300605 if (0 != (rc = videobuf_iolock(q,&buf->vb,NULL)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 goto fail;
607 }
608
609 if (init_buffer) {
610 buf->bpl = buf->vb.width * buf->fmt->depth >> 3;
611 switch (buf->vb.field) {
612 case V4L2_FIELD_TOP:
613 cx88_risc_buffer(dev->pci, &buf->risc,
Mauro Carvalho Chehabc1accaa2007-08-23 16:37:49 -0300614 dma->sglist, 0, UNSET,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 buf->bpl, 0, buf->vb.height);
616 break;
617 case V4L2_FIELD_BOTTOM:
618 cx88_risc_buffer(dev->pci, &buf->risc,
Mauro Carvalho Chehabc1accaa2007-08-23 16:37:49 -0300619 dma->sglist, UNSET, 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 buf->bpl, 0, buf->vb.height);
621 break;
622 case V4L2_FIELD_INTERLACED:
623 cx88_risc_buffer(dev->pci, &buf->risc,
Mauro Carvalho Chehabc1accaa2007-08-23 16:37:49 -0300624 dma->sglist, 0, buf->bpl,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 buf->bpl, buf->bpl,
626 buf->vb.height >> 1);
627 break;
628 case V4L2_FIELD_SEQ_TB:
629 cx88_risc_buffer(dev->pci, &buf->risc,
Mauro Carvalho Chehabc1accaa2007-08-23 16:37:49 -0300630 dma->sglist,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 0, buf->bpl * (buf->vb.height >> 1),
632 buf->bpl, 0,
633 buf->vb.height >> 1);
634 break;
635 case V4L2_FIELD_SEQ_BT:
636 cx88_risc_buffer(dev->pci, &buf->risc,
Mauro Carvalho Chehabc1accaa2007-08-23 16:37:49 -0300637 dma->sglist,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 buf->bpl * (buf->vb.height >> 1), 0,
639 buf->bpl, 0,
640 buf->vb.height >> 1);
641 break;
642 default:
643 BUG();
644 }
645 }
646 dprintk(2,"[%p/%d] buffer_prepare - %dx%d %dbpp \"%s\" - dma=0x%08lx\n",
647 buf, buf->vb.i,
648 fh->width, fh->height, fh->fmt->depth, fh->fmt->name,
649 (unsigned long)buf->risc.dma);
650
Brandon Philips0fc06862007-11-06 20:02:36 -0300651 buf->vb.state = VIDEOBUF_PREPARED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 return 0;
653
654 fail:
Mauro Carvalho Chehabc7b0ac02006-03-10 12:29:15 -0300655 cx88_free_buffer(q,buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 return rc;
657}
658
659static void
660buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
661{
662 struct cx88_buffer *buf = container_of(vb,struct cx88_buffer,vb);
663 struct cx88_buffer *prev;
664 struct cx8800_fh *fh = vq->priv_data;
665 struct cx8800_dev *dev = fh->dev;
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700666 struct cx88_core *core = dev->core;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 struct cx88_dmaqueue *q = &dev->vidq;
668
669 /* add jump to stopper */
670 buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC);
671 buf->risc.jmp[1] = cpu_to_le32(q->stopper.dma);
672
673 if (!list_empty(&q->queued)) {
674 list_add_tail(&buf->vb.queue,&q->queued);
Brandon Philips0fc06862007-11-06 20:02:36 -0300675 buf->vb.state = VIDEOBUF_QUEUED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 dprintk(2,"[%p/%d] buffer_queue - append to queued\n",
677 buf, buf->vb.i);
678
679 } else if (list_empty(&q->active)) {
680 list_add_tail(&buf->vb.queue,&q->active);
681 start_video_dma(dev, q, buf);
Brandon Philips0fc06862007-11-06 20:02:36 -0300682 buf->vb.state = VIDEOBUF_ACTIVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 buf->count = q->count++;
684 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
685 dprintk(2,"[%p/%d] buffer_queue - first active\n",
686 buf, buf->vb.i);
687
688 } else {
689 prev = list_entry(q->active.prev, struct cx88_buffer, vb.queue);
690 if (prev->vb.width == buf->vb.width &&
691 prev->vb.height == buf->vb.height &&
692 prev->fmt == buf->fmt) {
693 list_add_tail(&buf->vb.queue,&q->active);
Brandon Philips0fc06862007-11-06 20:02:36 -0300694 buf->vb.state = VIDEOBUF_ACTIVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 buf->count = q->count++;
696 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
697 dprintk(2,"[%p/%d] buffer_queue - append to active\n",
698 buf, buf->vb.i);
699
700 } else {
701 list_add_tail(&buf->vb.queue,&q->queued);
Brandon Philips0fc06862007-11-06 20:02:36 -0300702 buf->vb.state = VIDEOBUF_QUEUED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 dprintk(2,"[%p/%d] buffer_queue - first queued\n",
704 buf, buf->vb.i);
705 }
706 }
707}
708
709static void buffer_release(struct videobuf_queue *q, struct videobuf_buffer *vb)
710{
711 struct cx88_buffer *buf = container_of(vb,struct cx88_buffer,vb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712
Mauro Carvalho Chehabc7b0ac02006-03-10 12:29:15 -0300713 cx88_free_buffer(q,buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714}
715
Adrian Bunk408b6642005-05-01 08:59:29 -0700716static struct videobuf_queue_ops cx8800_video_qops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 .buf_setup = buffer_setup,
718 .buf_prepare = buffer_prepare,
719 .buf_queue = buffer_queue,
720 .buf_release = buffer_release,
721};
722
723/* ------------------------------------------------------------------ */
724
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725
726/* ------------------------------------------------------------------ */
727
728static struct videobuf_queue* get_queue(struct cx8800_fh *fh)
729{
730 switch (fh->type) {
731 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
732 return &fh->vidq;
733 case V4L2_BUF_TYPE_VBI_CAPTURE:
734 return &fh->vbiq;
735 default:
736 BUG();
737 return NULL;
738 }
739}
740
741static int get_ressource(struct cx8800_fh *fh)
742{
743 switch (fh->type) {
744 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
745 return RESOURCE_VIDEO;
746 case V4L2_BUF_TYPE_VBI_CAPTURE:
747 return RESOURCE_VBI;
748 default:
749 BUG();
750 return 0;
751 }
752}
753
Hans Verkuilbec43662008-12-30 06:58:20 -0300754static int video_open(struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755{
Hans Verkuilbec43662008-12-30 06:58:20 -0300756 int minor = video_devdata(file)->minor;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 struct cx8800_dev *h,*dev = NULL;
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700758 struct cx88_core *core;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759 struct cx8800_fh *fh;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 enum v4l2_buf_type type = 0;
761 int radio = 0;
762
Hans Verkuild56dc612008-07-30 08:43:36 -0300763 lock_kernel();
Trent Piepho8bb629e22007-10-10 05:37:40 -0300764 list_for_each_entry(h, &cx8800_devlist, devlist) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765 if (h->video_dev->minor == minor) {
766 dev = h;
767 type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
768 }
769 if (h->vbi_dev->minor == minor) {
770 dev = h;
771 type = V4L2_BUF_TYPE_VBI_CAPTURE;
772 }
773 if (h->radio_dev &&
774 h->radio_dev->minor == minor) {
775 radio = 1;
776 dev = h;
777 }
778 }
Hans Verkuild56dc612008-07-30 08:43:36 -0300779 if (NULL == dev) {
780 unlock_kernel();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781 return -ENODEV;
Hans Verkuild56dc612008-07-30 08:43:36 -0300782 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700784 core = dev->core;
785
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 dprintk(1,"open minor=%d radio=%d type=%s\n",
787 minor,radio,v4l2_type_names[type]);
788
789 /* allocate + initialize per filehandle data */
Panagiotis Issaris74081872006-01-11 19:40:56 -0200790 fh = kzalloc(sizeof(*fh),GFP_KERNEL);
Hans Verkuild56dc612008-07-30 08:43:36 -0300791 if (NULL == fh) {
792 unlock_kernel();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793 return -ENOMEM;
Hans Verkuild56dc612008-07-30 08:43:36 -0300794 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795 file->private_data = fh;
796 fh->dev = dev;
797 fh->radio = radio;
798 fh->type = type;
799 fh->width = 320;
800 fh->height = 240;
801 fh->fmt = format_by_fourcc(V4L2_PIX_FMT_BGR24);
802
Guennadi Liakhovetski07051352008-04-22 14:42:13 -0300803 videobuf_queue_sg_init(&fh->vidq, &cx8800_video_qops,
804 &dev->pci->dev, &dev->slock,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805 V4L2_BUF_TYPE_VIDEO_CAPTURE,
806 V4L2_FIELD_INTERLACED,
807 sizeof(struct cx88_buffer),
808 fh);
Guennadi Liakhovetski07051352008-04-22 14:42:13 -0300809 videobuf_queue_sg_init(&fh->vbiq, &cx8800_vbi_qops,
810 &dev->pci->dev, &dev->slock,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811 V4L2_BUF_TYPE_VBI_CAPTURE,
812 V4L2_FIELD_SEQ_TB,
813 sizeof(struct cx88_buffer),
814 fh);
815
816 if (fh->radio) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817 dprintk(1,"video_open: setting radio device\n");
Trent Piepho6a59d642007-08-15 14:41:57 -0300818 cx_write(MO_GP3_IO, core->board.radio.gpio3);
819 cx_write(MO_GP0_IO, core->board.radio.gpio0);
820 cx_write(MO_GP1_IO, core->board.radio.gpio1);
821 cx_write(MO_GP2_IO, core->board.radio.gpio2);
Darron Broad430189d2008-10-15 14:18:42 -0300822 if (core->board.radio.audioroute) {
823 if(core->board.audio_chip &&
824 core->board.audio_chip == V4L2_IDENT_WM8775) {
Hans Verkuil5325b422009-04-02 11:26:22 -0300825 call_all(core, audio, s_routing,
826 core->board.radio.audioroute, 0, 0);
Darron Broad430189d2008-10-15 14:18:42 -0300827 }
828 /* "I2S ADC mode" */
829 core->tvaudio = WW_I2SADC;
830 cx88_set_tvaudio(core);
831 } else {
832 /* FM Mode */
833 core->tvaudio = WW_FM;
834 cx88_set_tvaudio(core);
835 cx88_set_stereo(core,V4L2_TUNER_MODE_STEREO,1);
836 }
Hans Verkuilb8341e12009-03-29 08:26:01 -0300837 call_all(core, tuner, s_radio);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 }
Hans Verkuild56dc612008-07-30 08:43:36 -0300839 unlock_kernel();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840
Darron Broad3e010842008-09-25 16:51:11 -0300841 atomic_inc(&core->users);
842
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -0800843 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844}
845
846static ssize_t
Peter Hagervallf9e7a022005-11-08 21:36:29 -0800847video_read(struct file *file, char __user *data, size_t count, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848{
849 struct cx8800_fh *fh = file->private_data;
850
851 switch (fh->type) {
852 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
853 if (res_locked(fh->dev,RESOURCE_VIDEO))
854 return -EBUSY;
855 return videobuf_read_one(&fh->vidq, data, count, ppos,
856 file->f_flags & O_NONBLOCK);
857 case V4L2_BUF_TYPE_VBI_CAPTURE:
858 if (!res_get(fh->dev,fh,RESOURCE_VBI))
859 return -EBUSY;
860 return videobuf_read_stream(&fh->vbiq, data, count, ppos, 1,
861 file->f_flags & O_NONBLOCK);
862 default:
863 BUG();
864 return 0;
865 }
866}
867
868static unsigned int
869video_poll(struct file *file, struct poll_table_struct *wait)
870{
871 struct cx8800_fh *fh = file->private_data;
872 struct cx88_buffer *buf;
Figo.zhang9fd64182009-06-16 13:31:29 -0300873 unsigned int rc = POLLERR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874
875 if (V4L2_BUF_TYPE_VBI_CAPTURE == fh->type) {
876 if (!res_get(fh->dev,fh,RESOURCE_VBI))
877 return POLLERR;
878 return videobuf_poll_stream(file, &fh->vbiq, wait);
879 }
880
Figo.zhang9fd64182009-06-16 13:31:29 -0300881 mutex_lock(&fh->vidq.vb_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 if (res_check(fh,RESOURCE_VIDEO)) {
883 /* streaming capture */
884 if (list_empty(&fh->vidq.stream))
Figo.zhang9fd64182009-06-16 13:31:29 -0300885 goto done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886 buf = list_entry(fh->vidq.stream.next,struct cx88_buffer,vb.stream);
887 } else {
888 /* read() capture */
889 buf = (struct cx88_buffer*)fh->vidq.read_buf;
890 if (NULL == buf)
Figo.zhang9fd64182009-06-16 13:31:29 -0300891 goto done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892 }
893 poll_wait(file, &buf->vb.done, wait);
Brandon Philips0fc06862007-11-06 20:02:36 -0300894 if (buf->vb.state == VIDEOBUF_DONE ||
895 buf->vb.state == VIDEOBUF_ERROR)
Figo.zhang9fd64182009-06-16 13:31:29 -0300896 rc = POLLIN|POLLRDNORM;
897 else
898 rc = 0;
899done:
900 mutex_unlock(&fh->vidq.vb_lock);
901 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902}
903
Hans Verkuilbec43662008-12-30 06:58:20 -0300904static int video_release(struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905{
906 struct cx8800_fh *fh = file->private_data;
907 struct cx8800_dev *dev = fh->dev;
908
909 /* turn off overlay */
910 if (res_check(fh, RESOURCE_OVERLAY)) {
911 /* FIXME */
912 res_free(dev,fh,RESOURCE_OVERLAY);
913 }
914
915 /* stop video capture */
916 if (res_check(fh, RESOURCE_VIDEO)) {
917 videobuf_queue_cancel(&fh->vidq);
918 res_free(dev,fh,RESOURCE_VIDEO);
919 }
920 if (fh->vidq.read_buf) {
921 buffer_release(&fh->vidq,fh->vidq.read_buf);
922 kfree(fh->vidq.read_buf);
923 }
924
925 /* stop vbi capture */
926 if (res_check(fh, RESOURCE_VBI)) {
Brandon Philips053fcb62007-11-13 20:11:26 -0300927 videobuf_stop(&fh->vbiq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928 res_free(dev,fh,RESOURCE_VBI);
929 }
930
931 videobuf_mmap_free(&fh->vidq);
932 videobuf_mmap_free(&fh->vbiq);
933 file->private_data = NULL;
934 kfree(fh);
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700935
Devin Heitmueller06f837c2009-04-28 14:35:27 -0300936 mutex_lock(&dev->core->lock);
Darron Broad3e010842008-09-25 16:51:11 -0300937 if(atomic_dec_and_test(&dev->core->users))
Hans Verkuil7c9fc9d2009-04-01 03:49:59 -0300938 call_all(dev->core, tuner, s_standby);
Devin Heitmueller06f837c2009-04-28 14:35:27 -0300939 mutex_unlock(&dev->core->lock);
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -0700940
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941 return 0;
942}
943
944static int
945video_mmap(struct file *file, struct vm_area_struct * vma)
946{
947 struct cx8800_fh *fh = file->private_data;
948
949 return videobuf_mmap_mapper(get_queue(fh), vma);
950}
951
952/* ------------------------------------------------------------------ */
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -0300953/* VIDEO CTRL IOCTLS */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954
Mauro Carvalho Chehab54da49f2007-01-20 13:58:26 -0300955int cx88_get_control (struct cx88_core *core, struct v4l2_control *ctl)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956{
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -0300957 struct cx88_ctrl *c = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958 u32 value;
959 int i;
960
961 for (i = 0; i < CX8800_CTLS; i++)
962 if (cx8800_ctls[i].v.id == ctl->id)
963 c = &cx8800_ctls[i];
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -0300964 if (unlikely(NULL == c))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965 return -EINVAL;
966
967 value = c->sreg ? cx_sread(c->sreg) : cx_read(c->reg);
968 switch (ctl->id) {
969 case V4L2_CID_AUDIO_BALANCE:
Marcin Rudowski9f9c9072006-03-12 00:03:47 -0300970 ctl->value = ((value & 0x7f) < 0x40) ? ((value & 0x7f) + 0x40)
971 : (0x7f - (value & 0x7f));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972 break;
973 case V4L2_CID_AUDIO_VOLUME:
974 ctl->value = 0x3f - (value & 0x3f);
975 break;
976 default:
977 ctl->value = ((value + (c->off << c->shift)) & c->mask) >> c->shift;
978 break;
979 }
Ian Pickworth6457af52006-02-27 00:09:45 -0300980 dprintk(1,"get_control id=0x%X(%s) ctrl=0x%02x, reg=0x%02x val=0x%02x (mask 0x%02x)%s\n",
981 ctl->id, c->v.name, ctl->value, c->reg,
982 value,c->mask, c->sreg ? " [shadowed]" : "");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983 return 0;
984}
Mauro Carvalho Chehab54da49f2007-01-20 13:58:26 -0300985EXPORT_SYMBOL(cx88_get_control);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986
Mauro Carvalho Chehab54da49f2007-01-20 13:58:26 -0300987int cx88_set_control(struct cx88_core *core, struct v4l2_control *ctl)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989 struct cx88_ctrl *c = NULL;
Mauro Carvalho Chehab70f00042006-01-09 15:25:26 -0200990 u32 value,mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991 int i;
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -0300992
Mauro Carvalho Chehab70f00042006-01-09 15:25:26 -0200993 for (i = 0; i < CX8800_CTLS; i++) {
994 if (cx8800_ctls[i].v.id == ctl->id) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995 c = &cx8800_ctls[i];
Mauro Carvalho Chehab70f00042006-01-09 15:25:26 -0200996 }
997 }
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -0300998 if (unlikely(NULL == c))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999 return -EINVAL;
1000
1001 if (ctl->value < c->v.minimum)
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001002 ctl->value = c->v.minimum;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003 if (ctl->value > c->v.maximum)
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001004 ctl->value = c->v.maximum;
Mauro Carvalho Chehab70f00042006-01-09 15:25:26 -02001005 mask=c->mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006 switch (ctl->id) {
1007 case V4L2_CID_AUDIO_BALANCE:
Marcin Rudowski9f9c9072006-03-12 00:03:47 -03001008 value = (ctl->value < 0x40) ? (0x7f - ctl->value) : (ctl->value - 0x40);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009 break;
1010 case V4L2_CID_AUDIO_VOLUME:
1011 value = 0x3f - (ctl->value & 0x3f);
1012 break;
1013 case V4L2_CID_SATURATION:
1014 /* special v_sat handling */
Mauro Carvalho Chehab70f00042006-01-09 15:25:26 -02001015
1016 value = ((ctl->value - c->off) << c->shift) & c->mask;
1017
Mauro Carvalho Chehab63ab1bd2007-01-20 13:58:33 -03001018 if (core->tvnorm & V4L2_STD_SECAM) {
Mauro Carvalho Chehab70f00042006-01-09 15:25:26 -02001019 /* For SECAM, both U and V sat should be equal */
1020 value=value<<8|value;
1021 } else {
1022 /* Keeps U Saturation proportional to V Sat */
1023 value=(value*0x5a)/0x7f<<8|value;
1024 }
1025 mask=0xffff;
1026 break;
Frej Drejhammar6d042032008-03-23 22:43:21 -03001027 case V4L2_CID_CHROMA_AGC:
1028 /* Do not allow chroma AGC to be enabled for SECAM */
1029 value = ((ctl->value - c->off) << c->shift) & c->mask;
1030 if (core->tvnorm & V4L2_STD_SECAM && value)
1031 return -EINVAL;
1032 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033 default:
1034 value = ((ctl->value - c->off) << c->shift) & c->mask;
1035 break;
1036 }
Ian Pickworth6457af52006-02-27 00:09:45 -03001037 dprintk(1,"set_control id=0x%X(%s) ctrl=0x%02x, reg=0x%02x val=0x%02x (mask 0x%02x)%s\n",
1038 ctl->id, c->v.name, ctl->value, c->reg, value,
1039 mask, c->sreg ? " [shadowed]" : "");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040 if (c->sreg) {
Mauro Carvalho Chehab70f00042006-01-09 15:25:26 -02001041 cx_sandor(c->sreg, c->reg, mask, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042 } else {
Mauro Carvalho Chehab70f00042006-01-09 15:25:26 -02001043 cx_andor(c->reg, mask, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044 }
1045 return 0;
1046}
Mauro Carvalho Chehab54da49f2007-01-20 13:58:26 -03001047EXPORT_SYMBOL(cx88_set_control);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001049static void init_controls(struct cx88_core *core)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050{
Mauro Carvalho Chehab70f00042006-01-09 15:25:26 -02001051 struct v4l2_control ctrl;
1052 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053
Mauro Carvalho Chehab70f00042006-01-09 15:25:26 -02001054 for (i = 0; i < CX8800_CTLS; i++) {
1055 ctrl.id=cx8800_ctls[i].v.id;
Marcin Rudowski9f9c9072006-03-12 00:03:47 -03001056 ctrl.value=cx8800_ctls[i].v.default_value;
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001057
Mauro Carvalho Chehab54da49f2007-01-20 13:58:26 -03001058 cx88_set_control(core, &ctrl);
Mauro Carvalho Chehab70f00042006-01-09 15:25:26 -02001059 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060}
1061
1062/* ------------------------------------------------------------------ */
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001063/* VIDEO IOCTLS */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064
Hans Verkuil78b526a2008-05-28 12:16:41 -03001065static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001066 struct v4l2_format *f)
1067{
1068 struct cx8800_fh *fh = priv;
1069
1070 f->fmt.pix.width = fh->width;
1071 f->fmt.pix.height = fh->height;
1072 f->fmt.pix.field = fh->vidq.field;
1073 f->fmt.pix.pixelformat = fh->fmt->fourcc;
1074 f->fmt.pix.bytesperline =
1075 (f->fmt.pix.width * fh->fmt->depth) >> 3;
1076 f->fmt.pix.sizeimage =
1077 f->fmt.pix.height * f->fmt.pix.bytesperline;
1078 return 0;
1079}
1080
Hans Verkuil78b526a2008-05-28 12:16:41 -03001081static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082 struct v4l2_format *f)
1083{
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001084 struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core;
1085 struct cx8800_fmt *fmt;
1086 enum v4l2_field field;
1087 unsigned int maxw, maxh;
1088
1089 fmt = format_by_fourcc(f->fmt.pix.pixelformat);
1090 if (NULL == fmt)
1091 return -EINVAL;
1092
1093 field = f->fmt.pix.field;
1094 maxw = norm_maxw(core->tvnorm);
1095 maxh = norm_maxh(core->tvnorm);
1096
1097 if (V4L2_FIELD_ANY == field) {
1098 field = (f->fmt.pix.height > maxh/2)
1099 ? V4L2_FIELD_INTERLACED
1100 : V4L2_FIELD_BOTTOM;
1101 }
1102
1103 switch (field) {
1104 case V4L2_FIELD_TOP:
1105 case V4L2_FIELD_BOTTOM:
1106 maxh = maxh / 2;
1107 break;
1108 case V4L2_FIELD_INTERLACED:
1109 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110 default:
1111 return -EINVAL;
1112 }
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001113
1114 f->fmt.pix.field = field;
Trent Piepho4b899452009-05-30 21:45:46 -03001115 v4l_bound_align_image(&f->fmt.pix.width, 48, maxw, 2,
1116 &f->fmt.pix.height, 32, maxh, 0, 0);
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001117 f->fmt.pix.bytesperline =
1118 (f->fmt.pix.width * fmt->depth) >> 3;
1119 f->fmt.pix.sizeimage =
1120 f->fmt.pix.height * f->fmt.pix.bytesperline;
1121
1122 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123}
1124
Hans Verkuil78b526a2008-05-28 12:16:41 -03001125static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001126 struct v4l2_format *f)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127{
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001128 struct cx8800_fh *fh = priv;
Hans Verkuil78b526a2008-05-28 12:16:41 -03001129 int err = vidioc_try_fmt_vid_cap (file,priv,f);
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001130
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001131 if (0 != err)
1132 return err;
1133 fh->fmt = format_by_fourcc(f->fmt.pix.pixelformat);
1134 fh->width = f->fmt.pix.width;
1135 fh->height = f->fmt.pix.height;
1136 fh->vidq.field = f->fmt.pix.field;
1137 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138}
1139
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001140static int vidioc_querycap (struct file *file, void *priv,
1141 struct v4l2_capability *cap)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142{
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001143 struct cx8800_dev *dev = ((struct cx8800_fh *)priv)->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144 struct cx88_core *core = dev->core;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001146 strcpy(cap->driver, "cx8800");
Trent Piepho6a59d642007-08-15 14:41:57 -03001147 strlcpy(cap->card, core->board.name, sizeof(cap->card));
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001148 sprintf(cap->bus_info,"PCI:%s",pci_name(dev->pci));
1149 cap->version = CX88_VERSION_CODE;
1150 cap->capabilities =
1151 V4L2_CAP_VIDEO_CAPTURE |
1152 V4L2_CAP_READWRITE |
1153 V4L2_CAP_STREAMING |
1154 V4L2_CAP_VBI_CAPTURE;
Trent Piepho6a59d642007-08-15 14:41:57 -03001155 if (UNSET != core->board.tuner_type)
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001156 cap->capabilities |= V4L2_CAP_TUNER;
1157 return 0;
1158}
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001159
Hans Verkuil78b526a2008-05-28 12:16:41 -03001160static int vidioc_enum_fmt_vid_cap (struct file *file, void *priv,
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001161 struct v4l2_fmtdesc *f)
1162{
1163 if (unlikely(f->index >= ARRAY_SIZE(formats)))
1164 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001166 strlcpy(f->description,formats[f->index].name,sizeof(f->description));
1167 f->pixelformat = formats[f->index].fourcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001169 return 0;
1170}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171
Mauro Carvalho Chehab0dfa9ab2006-08-08 09:10:10 -03001172#ifdef CONFIG_VIDEO_V4L1_COMPAT
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001173static int vidiocgmbuf (struct file *file, void *priv, struct video_mbuf *mbuf)
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001174{
Mauro Carvalho Chehabc1accaa2007-08-23 16:37:49 -03001175 struct cx8800_fh *fh = priv;
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001176
Mauro Carvalho Chehabc1accaa2007-08-23 16:37:49 -03001177 return videobuf_cgmbuf (get_queue(fh), mbuf, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178}
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001179#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001181static int vidioc_reqbufs (struct file *file, void *priv, struct v4l2_requestbuffers *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182{
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001183 struct cx8800_fh *fh = priv;
1184 return (videobuf_reqbufs(get_queue(fh), p));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185}
1186
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001187static int vidioc_querybuf (struct file *file, void *priv, struct v4l2_buffer *p)
1188{
1189 struct cx8800_fh *fh = priv;
1190 return (videobuf_querybuf(get_queue(fh), p));
1191}
1192
1193static int vidioc_qbuf (struct file *file, void *priv, struct v4l2_buffer *p)
1194{
1195 struct cx8800_fh *fh = priv;
1196 return (videobuf_qbuf(get_queue(fh), p));
1197}
1198
1199static int vidioc_dqbuf (struct file *file, void *priv, struct v4l2_buffer *p)
1200{
1201 struct cx8800_fh *fh = priv;
1202 return (videobuf_dqbuf(get_queue(fh), p,
1203 file->f_flags & O_NONBLOCK));
1204}
1205
1206static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
1207{
1208 struct cx8800_fh *fh = priv;
1209 struct cx8800_dev *dev = fh->dev;
1210
Rafael Dinizb058e3f2008-10-24 23:07:57 -03001211 /* We should remember that this driver also supports teletext, */
1212 /* so we have to test if the v4l2_buf_type is VBI capture data. */
1213 if (unlikely((fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) &&
1214 (fh->type != V4L2_BUF_TYPE_VBI_CAPTURE)))
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001215 return -EINVAL;
Rafael Dinizb058e3f2008-10-24 23:07:57 -03001216
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001217 if (unlikely(i != fh->type))
1218 return -EINVAL;
1219
1220 if (unlikely(!res_get(dev,fh,get_ressource(fh))))
1221 return -EBUSY;
1222 return videobuf_streamon(get_queue(fh));
1223}
1224
1225static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
1226{
1227 struct cx8800_fh *fh = priv;
1228 struct cx8800_dev *dev = fh->dev;
1229 int err, res;
1230
Rafael Dinizb058e3f2008-10-24 23:07:57 -03001231 if ((fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) &&
1232 (fh->type != V4L2_BUF_TYPE_VBI_CAPTURE))
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001233 return -EINVAL;
Rafael Dinizb058e3f2008-10-24 23:07:57 -03001234
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001235 if (i != fh->type)
1236 return -EINVAL;
1237
1238 res = get_ressource(fh);
1239 err = videobuf_streamoff(get_queue(fh));
1240 if (err < 0)
1241 return err;
1242 res_free(dev,fh,res);
1243 return 0;
1244}
1245
Mauro Carvalho Chehab63ab1bd2007-01-20 13:58:33 -03001246static int vidioc_s_std (struct file *file, void *priv, v4l2_std_id *tvnorms)
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001247{
1248 struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core;
1249
1250 mutex_lock(&core->lock);
Mauro Carvalho Chehab63ab1bd2007-01-20 13:58:33 -03001251 cx88_set_tvnorm(core,*tvnorms);
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001252 mutex_unlock(&core->lock);
Mauro Carvalho Chehab63ab1bd2007-01-20 13:58:33 -03001253
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001254 return 0;
1255}
1256
1257/* only one input in this sample driver */
Mauro Carvalho Chehab54da49f2007-01-20 13:58:26 -03001258int cx88_enum_input (struct cx88_core *core,struct v4l2_input *i)
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001259{
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001260 static const char *iname[] = {
1261 [ CX88_VMUX_COMPOSITE1 ] = "Composite1",
1262 [ CX88_VMUX_COMPOSITE2 ] = "Composite2",
1263 [ CX88_VMUX_COMPOSITE3 ] = "Composite3",
1264 [ CX88_VMUX_COMPOSITE4 ] = "Composite4",
1265 [ CX88_VMUX_SVIDEO ] = "S-Video",
1266 [ CX88_VMUX_TELEVISION ] = "Television",
1267 [ CX88_VMUX_CABLE ] = "Cable TV",
1268 [ CX88_VMUX_DVB ] = "DVB",
1269 [ CX88_VMUX_DEBUG ] = "for debug only",
1270 };
Trent Piephof3334bc2009-03-04 01:21:03 -03001271 unsigned int n = i->index;
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001272
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001273 if (n >= 4)
1274 return -EINVAL;
Trent Piepho6a59d642007-08-15 14:41:57 -03001275 if (0 == INPUT(n).type)
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001276 return -EINVAL;
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001277 i->type = V4L2_INPUT_TYPE_CAMERA;
Trent Piepho6a59d642007-08-15 14:41:57 -03001278 strcpy(i->name,iname[INPUT(n).type]);
1279 if ((CX88_VMUX_TELEVISION == INPUT(n).type) ||
1280 (CX88_VMUX_CABLE == INPUT(n).type))
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001281 i->type = V4L2_INPUT_TYPE_TUNER;
Mauro Carvalho Chehab63ab1bd2007-01-20 13:58:33 -03001282 i->std = CX88_NORMS;
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001283 return 0;
1284}
Mauro Carvalho Chehab54da49f2007-01-20 13:58:26 -03001285EXPORT_SYMBOL(cx88_enum_input);
1286
1287static int vidioc_enum_input (struct file *file, void *priv,
1288 struct v4l2_input *i)
1289{
1290 struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core;
1291 return cx88_enum_input (core,i);
1292}
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001293
1294static int vidioc_g_input (struct file *file, void *priv, unsigned int *i)
1295{
1296 struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core;
1297
1298 *i = core->input;
1299 return 0;
1300}
1301
1302static int vidioc_s_input (struct file *file, void *priv, unsigned int i)
1303{
1304 struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core;
1305
1306 if (i >= 4)
1307 return -EINVAL;
1308
1309 mutex_lock(&core->lock);
1310 cx88_newstation(core);
Mauro Carvalho Chehabe90311a2007-01-20 13:58:29 -03001311 cx88_video_mux(core,i);
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001312 mutex_unlock(&core->lock);
1313 return 0;
1314}
1315
1316
1317
1318static int vidioc_queryctrl (struct file *file, void *priv,
1319 struct v4l2_queryctrl *qctrl)
1320{
Frej Drejhammar6d042032008-03-23 22:43:21 -03001321 struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core;
1322
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001323 qctrl->id = v4l2_ctrl_next(ctrl_classes, qctrl->id);
1324 if (unlikely(qctrl->id == 0))
1325 return -EINVAL;
Frej Drejhammar6d042032008-03-23 22:43:21 -03001326 return cx8800_ctrl_query(core, qctrl);
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001327}
1328
Mauro Carvalho Chehab54da49f2007-01-20 13:58:26 -03001329static int vidioc_g_ctrl (struct file *file, void *priv,
1330 struct v4l2_control *ctl)
1331{
1332 struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core;
1333 return
1334 cx88_get_control(core,ctl);
1335}
1336
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001337static int vidioc_s_ctrl (struct file *file, void *priv,
1338 struct v4l2_control *ctl)
1339{
1340 struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core;
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001341 return
Mauro Carvalho Chehab54da49f2007-01-20 13:58:26 -03001342 cx88_set_control(core,ctl);
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001343}
1344
1345static int vidioc_g_tuner (struct file *file, void *priv,
1346 struct v4l2_tuner *t)
1347{
1348 struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core;
1349 u32 reg;
1350
Trent Piepho6a59d642007-08-15 14:41:57 -03001351 if (unlikely(UNSET == core->board.tuner_type))
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001352 return -EINVAL;
Mauro Carvalho Chehab243d8c02007-01-20 13:58:36 -03001353 if (0 != t->index)
1354 return -EINVAL;
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001355
1356 strcpy(t->name, "Television");
1357 t->type = V4L2_TUNER_ANALOG_TV;
1358 t->capability = V4L2_TUNER_CAP_NORM;
1359 t->rangehigh = 0xffffffffUL;
1360
1361 cx88_get_stereo(core ,t);
1362 reg = cx_read(MO_DEVICE_STATUS);
1363 t->signal = (reg & (1<<5)) ? 0xffff : 0x0000;
1364 return 0;
1365}
1366
1367static int vidioc_s_tuner (struct file *file, void *priv,
1368 struct v4l2_tuner *t)
1369{
1370 struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core;
1371
Trent Piepho6a59d642007-08-15 14:41:57 -03001372 if (UNSET == core->board.tuner_type)
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001373 return -EINVAL;
1374 if (0 != t->index)
1375 return -EINVAL;
1376
1377 cx88_set_stereo(core, t->audmode, 1);
1378 return 0;
1379}
1380
1381static int vidioc_g_frequency (struct file *file, void *priv,
1382 struct v4l2_frequency *f)
1383{
1384 struct cx8800_fh *fh = priv;
1385 struct cx88_core *core = fh->dev->core;
1386
Trent Piepho6a59d642007-08-15 14:41:57 -03001387 if (unlikely(UNSET == core->board.tuner_type))
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001388 return -EINVAL;
1389
1390 /* f->type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; */
1391 f->type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
1392 f->frequency = core->freq;
1393
Hans Verkuilb8341e12009-03-29 08:26:01 -03001394 call_all(core, tuner, g_frequency, f);
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001395
1396 return 0;
1397}
1398
Mauro Carvalho Chehab54da49f2007-01-20 13:58:26 -03001399int cx88_set_freq (struct cx88_core *core,
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001400 struct v4l2_frequency *f)
1401{
Trent Piepho6a59d642007-08-15 14:41:57 -03001402 if (unlikely(UNSET == core->board.tuner_type))
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001403 return -EINVAL;
1404 if (unlikely(f->tuner != 0))
1405 return -EINVAL;
Mauro Carvalho Chehab54da49f2007-01-20 13:58:26 -03001406
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001407 mutex_lock(&core->lock);
1408 core->freq = f->frequency;
1409 cx88_newstation(core);
Hans Verkuilb8341e12009-03-29 08:26:01 -03001410 call_all(core, tuner, s_frequency, f);
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001411
1412 /* When changing channels it is required to reset TVAUDIO */
1413 msleep (10);
1414 cx88_set_tvaudio(core);
1415
1416 mutex_unlock(&core->lock);
Mauro Carvalho Chehab54da49f2007-01-20 13:58:26 -03001417
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001418 return 0;
1419}
Mauro Carvalho Chehab54da49f2007-01-20 13:58:26 -03001420EXPORT_SYMBOL(cx88_set_freq);
1421
1422static int vidioc_s_frequency (struct file *file, void *priv,
1423 struct v4l2_frequency *f)
1424{
1425 struct cx8800_fh *fh = priv;
1426 struct cx88_core *core = fh->dev->core;
1427
1428 if (unlikely(0 == fh->radio && f->type != V4L2_TUNER_ANALOG_TV))
1429 return -EINVAL;
1430 if (unlikely(1 == fh->radio && f->type != V4L2_TUNER_RADIO))
1431 return -EINVAL;
1432
1433 return
1434 cx88_set_freq (core,f);
1435}
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001436
Trent Piephodbbff482007-01-22 23:31:53 -03001437#ifdef CONFIG_VIDEO_ADV_DEBUG
1438static int vidioc_g_register (struct file *file, void *fh,
Hans Verkuilaecde8b2008-12-30 07:14:19 -03001439 struct v4l2_dbg_register *reg)
Trent Piephodbbff482007-01-22 23:31:53 -03001440{
1441 struct cx88_core *core = ((struct cx8800_fh*)fh)->dev->core;
1442
Hans Verkuilaecde8b2008-12-30 07:14:19 -03001443 if (!v4l2_chip_match_host(&reg->match))
Trent Piephodbbff482007-01-22 23:31:53 -03001444 return -EINVAL;
1445 /* cx2388x has a 24-bit register space */
Hans Verkuilaecde8b2008-12-30 07:14:19 -03001446 reg->val = cx_read(reg->reg & 0xffffff);
1447 reg->size = 4;
Trent Piephodbbff482007-01-22 23:31:53 -03001448 return 0;
1449}
1450
1451static int vidioc_s_register (struct file *file, void *fh,
Hans Verkuilaecde8b2008-12-30 07:14:19 -03001452 struct v4l2_dbg_register *reg)
Trent Piephodbbff482007-01-22 23:31:53 -03001453{
1454 struct cx88_core *core = ((struct cx8800_fh*)fh)->dev->core;
1455
Hans Verkuilaecde8b2008-12-30 07:14:19 -03001456 if (!v4l2_chip_match_host(&reg->match))
Trent Piephodbbff482007-01-22 23:31:53 -03001457 return -EINVAL;
Hans Verkuilaecde8b2008-12-30 07:14:19 -03001458 cx_write(reg->reg & 0xffffff, reg->val);
Trent Piephodbbff482007-01-22 23:31:53 -03001459 return 0;
1460}
1461#endif
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001462
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463/* ----------------------------------------------------------- */
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001464/* RADIO ESPECIFIC IOCTLS */
1465/* ----------------------------------------------------------- */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001467static int radio_querycap (struct file *file, void *priv,
1468 struct v4l2_capability *cap)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469{
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001470 struct cx8800_dev *dev = ((struct cx8800_fh *)priv)->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471 struct cx88_core *core = dev->core;
1472
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001473 strcpy(cap->driver, "cx8800");
Trent Piepho6a59d642007-08-15 14:41:57 -03001474 strlcpy(cap->card, core->board.name, sizeof(cap->card));
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001475 sprintf(cap->bus_info,"PCI:%s", pci_name(dev->pci));
1476 cap->version = CX88_VERSION_CODE;
1477 cap->capabilities = V4L2_CAP_TUNER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478 return 0;
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001479}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001481static int radio_g_tuner (struct file *file, void *priv,
1482 struct v4l2_tuner *t)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483{
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001484 struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core;
1485
1486 if (unlikely(t->index > 0))
1487 return -EINVAL;
1488
1489 strcpy(t->name, "Radio");
1490 t->type = V4L2_TUNER_RADIO;
1491
Hans Verkuilb8341e12009-03-29 08:26:01 -03001492 call_all(core, tuner, g_tuner, t);
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001493 return 0;
1494}
1495
1496static int radio_enum_input (struct file *file, void *priv,
1497 struct v4l2_input *i)
1498{
1499 if (i->index != 0)
1500 return -EINVAL;
1501 strcpy(i->name,"Radio");
1502 i->type = V4L2_INPUT_TYPE_TUNER;
1503
1504 return 0;
1505}
1506
1507static int radio_g_audio (struct file *file, void *priv, struct v4l2_audio *a)
1508{
1509 if (unlikely(a->index))
1510 return -EINVAL;
1511
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001512 strcpy(a->name,"Radio");
1513 return 0;
1514}
1515
1516/* FIXME: Should add a standard for radio */
1517
1518static int radio_s_tuner (struct file *file, void *priv,
1519 struct v4l2_tuner *t)
1520{
1521 struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core;
1522
1523 if (0 != t->index)
1524 return -EINVAL;
1525
Hans Verkuilb8341e12009-03-29 08:26:01 -03001526 call_all(core, tuner, s_tuner, t);
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001527
1528 return 0;
1529}
1530
1531static int radio_s_audio (struct file *file, void *fh,
1532 struct v4l2_audio *a)
1533{
1534 return 0;
1535}
1536
1537static int radio_s_input (struct file *file, void *fh, unsigned int i)
1538{
1539 return 0;
1540}
1541
1542static int radio_queryctrl (struct file *file, void *priv,
1543 struct v4l2_queryctrl *c)
1544{
1545 int i;
1546
1547 if (c->id < V4L2_CID_BASE ||
1548 c->id >= V4L2_CID_LASTP1)
1549 return -EINVAL;
1550 if (c->id == V4L2_CID_AUDIO_MUTE) {
1551 for (i = 0; i < CX8800_CTLS; i++)
1552 if (cx8800_ctls[i].v.id == c->id)
1553 break;
1554 *c = cx8800_ctls[i].v;
1555 } else
1556 *c = no_ctl;
1557 return 0;
1558}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001559
1560/* ----------------------------------------------------------- */
1561
1562static void cx8800_vid_timeout(unsigned long data)
1563{
1564 struct cx8800_dev *dev = (struct cx8800_dev*)data;
1565 struct cx88_core *core = dev->core;
1566 struct cx88_dmaqueue *q = &dev->vidq;
1567 struct cx88_buffer *buf;
1568 unsigned long flags;
1569
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001570 cx88_sram_channel_dump(core, &cx88_sram_channels[SRAM_CH21]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571
1572 cx_clear(MO_VID_DMACNTRL, 0x11);
1573 cx_clear(VID_CAPTURE_CONTROL, 0x06);
1574
1575 spin_lock_irqsave(&dev->slock,flags);
1576 while (!list_empty(&q->active)) {
1577 buf = list_entry(q->active.next, struct cx88_buffer, vb.queue);
1578 list_del(&buf->vb.queue);
Brandon Philips0fc06862007-11-06 20:02:36 -03001579 buf->vb.state = VIDEOBUF_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580 wake_up(&buf->vb.done);
1581 printk("%s/0: [%p/%d] timeout - dma=0x%08lx\n", core->name,
1582 buf, buf->vb.i, (unsigned long)buf->risc.dma);
1583 }
1584 restart_video_queue(dev,q);
1585 spin_unlock_irqrestore(&dev->slock,flags);
1586}
1587
Mauro Carvalho Chehab41ef7c12005-07-12 13:58:44 -07001588static char *cx88_vid_irqs[32] = {
1589 "y_risci1", "u_risci1", "v_risci1", "vbi_risc1",
1590 "y_risci2", "u_risci2", "v_risci2", "vbi_risc2",
1591 "y_oflow", "u_oflow", "v_oflow", "vbi_oflow",
1592 "y_sync", "u_sync", "v_sync", "vbi_sync",
1593 "opc_err", "par_err", "rip_err", "pci_abort",
1594};
1595
Linus Torvalds1da177e2005-04-16 15:20:36 -07001596static void cx8800_vid_irq(struct cx8800_dev *dev)
1597{
1598 struct cx88_core *core = dev->core;
1599 u32 status, mask, count;
1600
1601 status = cx_read(MO_VID_INTSTAT);
1602 mask = cx_read(MO_VID_INTMSK);
1603 if (0 == (status & mask))
1604 return;
1605 cx_write(MO_VID_INTSTAT, status);
1606 if (irq_debug || (status & mask & ~0xff))
1607 cx88_print_irqbits(core->name, "irq vid",
Mauro Carvalho Chehab66623a02007-03-29 08:47:04 -03001608 cx88_vid_irqs, ARRAY_SIZE(cx88_vid_irqs),
1609 status, mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610
1611 /* risc op code error */
1612 if (status & (1 << 16)) {
1613 printk(KERN_WARNING "%s/0: video risc op code error\n",core->name);
1614 cx_clear(MO_VID_DMACNTRL, 0x11);
1615 cx_clear(VID_CAPTURE_CONTROL, 0x06);
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001616 cx88_sram_channel_dump(core, &cx88_sram_channels[SRAM_CH21]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001617 }
1618
1619 /* risc1 y */
1620 if (status & 0x01) {
1621 spin_lock(&dev->slock);
1622 count = cx_read(MO_VIDY_GPCNT);
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001623 cx88_wakeup(core, &dev->vidq, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624 spin_unlock(&dev->slock);
1625 }
1626
1627 /* risc1 vbi */
1628 if (status & 0x08) {
1629 spin_lock(&dev->slock);
1630 count = cx_read(MO_VBI_GPCNT);
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001631 cx88_wakeup(core, &dev->vbiq, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632 spin_unlock(&dev->slock);
1633 }
1634
1635 /* risc2 y */
1636 if (status & 0x10) {
1637 dprintk(2,"stopper video\n");
1638 spin_lock(&dev->slock);
1639 restart_video_queue(dev,&dev->vidq);
1640 spin_unlock(&dev->slock);
1641 }
1642
1643 /* risc2 vbi */
1644 if (status & 0x80) {
1645 dprintk(2,"stopper vbi\n");
1646 spin_lock(&dev->slock);
1647 cx8800_restart_vbi_queue(dev,&dev->vbiq);
1648 spin_unlock(&dev->slock);
1649 }
1650}
1651
David Howells7d12e782006-10-05 14:55:46 +01001652static irqreturn_t cx8800_irq(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653{
1654 struct cx8800_dev *dev = dev_id;
1655 struct cx88_core *core = dev->core;
1656 u32 status;
1657 int loop, handled = 0;
1658
1659 for (loop = 0; loop < 10; loop++) {
Trent Piepho8ddac9e2007-08-18 06:57:55 -03001660 status = cx_read(MO_PCI_INTSTAT) &
1661 (core->pci_irqmask | PCI_INT_VIDINT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662 if (0 == status)
1663 goto out;
1664 cx_write(MO_PCI_INTSTAT, status);
1665 handled = 1;
1666
1667 if (status & core->pci_irqmask)
1668 cx88_core_irq(core,status);
Trent Piepho8ddac9e2007-08-18 06:57:55 -03001669 if (status & PCI_INT_VIDINT)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670 cx8800_vid_irq(dev);
1671 };
1672 if (10 == loop) {
1673 printk(KERN_WARNING "%s/0: irq loop -- clearing mask\n",
1674 core->name);
1675 cx_write(MO_PCI_INTMSK,0);
1676 }
1677
1678 out:
1679 return IRQ_RETVAL(handled);
1680}
1681
1682/* ----------------------------------------------------------- */
1683/* exported stuff */
1684
Hans Verkuilbec43662008-12-30 06:58:20 -03001685static const struct v4l2_file_operations video_fops =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001686{
1687 .owner = THIS_MODULE,
1688 .open = video_open,
1689 .release = video_release,
1690 .read = video_read,
1691 .poll = video_poll,
1692 .mmap = video_mmap,
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001693 .ioctl = video_ioctl2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694};
1695
Hans Verkuila3998102008-07-21 02:57:38 -03001696static const struct v4l2_ioctl_ops video_ioctl_ops = {
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001697 .vidioc_querycap = vidioc_querycap,
Hans Verkuil78b526a2008-05-28 12:16:41 -03001698 .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
1699 .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
1700 .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
1701 .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
1702 .vidioc_g_fmt_vbi_cap = cx8800_vbi_fmt,
1703 .vidioc_try_fmt_vbi_cap = cx8800_vbi_fmt,
1704 .vidioc_s_fmt_vbi_cap = cx8800_vbi_fmt,
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001705 .vidioc_reqbufs = vidioc_reqbufs,
1706 .vidioc_querybuf = vidioc_querybuf,
1707 .vidioc_qbuf = vidioc_qbuf,
1708 .vidioc_dqbuf = vidioc_dqbuf,
1709 .vidioc_s_std = vidioc_s_std,
1710 .vidioc_enum_input = vidioc_enum_input,
1711 .vidioc_g_input = vidioc_g_input,
1712 .vidioc_s_input = vidioc_s_input,
1713 .vidioc_queryctrl = vidioc_queryctrl,
1714 .vidioc_g_ctrl = vidioc_g_ctrl,
1715 .vidioc_s_ctrl = vidioc_s_ctrl,
1716 .vidioc_streamon = vidioc_streamon,
1717 .vidioc_streamoff = vidioc_streamoff,
1718#ifdef CONFIG_VIDEO_V4L1_COMPAT
1719 .vidiocgmbuf = vidiocgmbuf,
1720#endif
1721 .vidioc_g_tuner = vidioc_g_tuner,
1722 .vidioc_s_tuner = vidioc_s_tuner,
1723 .vidioc_g_frequency = vidioc_g_frequency,
1724 .vidioc_s_frequency = vidioc_s_frequency,
Trent Piephodbbff482007-01-22 23:31:53 -03001725#ifdef CONFIG_VIDEO_ADV_DEBUG
1726 .vidioc_g_register = vidioc_g_register,
1727 .vidioc_s_register = vidioc_s_register,
1728#endif
Hans Verkuila3998102008-07-21 02:57:38 -03001729};
1730
1731static struct video_device cx8800_vbi_template;
1732
1733static struct video_device cx8800_video_template = {
1734 .name = "cx8800-video",
Hans Verkuila3998102008-07-21 02:57:38 -03001735 .fops = &video_fops,
1736 .minor = -1,
1737 .ioctl_ops = &video_ioctl_ops,
Mauro Carvalho Chehab63ab1bd2007-01-20 13:58:33 -03001738 .tvnorms = CX88_NORMS,
Trent Piephodbbff482007-01-22 23:31:53 -03001739 .current_norm = V4L2_STD_NTSC_M,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740};
1741
Hans Verkuilbec43662008-12-30 06:58:20 -03001742static const struct v4l2_file_operations radio_fops =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743{
1744 .owner = THIS_MODULE,
1745 .open = video_open,
1746 .release = video_release,
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001747 .ioctl = video_ioctl2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001748};
1749
Hans Verkuila3998102008-07-21 02:57:38 -03001750static const struct v4l2_ioctl_ops radio_ioctl_ops = {
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001751 .vidioc_querycap = radio_querycap,
1752 .vidioc_g_tuner = radio_g_tuner,
1753 .vidioc_enum_input = radio_enum_input,
1754 .vidioc_g_audio = radio_g_audio,
1755 .vidioc_s_tuner = radio_s_tuner,
1756 .vidioc_s_audio = radio_s_audio,
1757 .vidioc_s_input = radio_s_input,
1758 .vidioc_queryctrl = radio_queryctrl,
1759 .vidioc_g_ctrl = vidioc_g_ctrl,
1760 .vidioc_s_ctrl = vidioc_s_ctrl,
1761 .vidioc_g_frequency = vidioc_g_frequency,
1762 .vidioc_s_frequency = vidioc_s_frequency,
Trent Piephoa75d2042007-08-01 00:13:28 -03001763#ifdef CONFIG_VIDEO_ADV_DEBUG
1764 .vidioc_g_register = vidioc_g_register,
1765 .vidioc_s_register = vidioc_s_register,
1766#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001767};
1768
Hans Verkuila3998102008-07-21 02:57:38 -03001769static struct video_device cx8800_radio_template = {
1770 .name = "cx8800-radio",
Hans Verkuila3998102008-07-21 02:57:38 -03001771 .fops = &radio_fops,
1772 .minor = -1,
1773 .ioctl_ops = &radio_ioctl_ops,
1774};
1775
Linus Torvalds1da177e2005-04-16 15:20:36 -07001776/* ----------------------------------------------------------- */
1777
1778static void cx8800_unregister_video(struct cx8800_dev *dev)
1779{
1780 if (dev->radio_dev) {
1781 if (-1 != dev->radio_dev->minor)
1782 video_unregister_device(dev->radio_dev);
1783 else
1784 video_device_release(dev->radio_dev);
1785 dev->radio_dev = NULL;
1786 }
1787 if (dev->vbi_dev) {
1788 if (-1 != dev->vbi_dev->minor)
1789 video_unregister_device(dev->vbi_dev);
1790 else
1791 video_device_release(dev->vbi_dev);
1792 dev->vbi_dev = NULL;
1793 }
1794 if (dev->video_dev) {
1795 if (-1 != dev->video_dev->minor)
1796 video_unregister_device(dev->video_dev);
1797 else
1798 video_device_release(dev->video_dev);
1799 dev->video_dev = NULL;
1800 }
1801}
1802
1803static int __devinit cx8800_initdev(struct pci_dev *pci_dev,
1804 const struct pci_device_id *pci_id)
1805{
1806 struct cx8800_dev *dev;
1807 struct cx88_core *core;
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001808
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809 int err;
1810
Panagiotis Issaris74081872006-01-11 19:40:56 -02001811 dev = kzalloc(sizeof(*dev),GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001812 if (NULL == dev)
1813 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814
1815 /* pci init */
1816 dev->pci = pci_dev;
1817 if (pci_enable_device(pci_dev)) {
1818 err = -EIO;
1819 goto fail_free;
1820 }
1821 core = cx88_core_get(dev->pci);
1822 if (NULL == core) {
1823 err = -EINVAL;
1824 goto fail_free;
1825 }
1826 dev->core = core;
1827
1828 /* print pci info */
1829 pci_read_config_byte(pci_dev, PCI_CLASS_REVISION, &dev->pci_rev);
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -08001830 pci_read_config_byte(pci_dev, PCI_LATENCY_TIMER, &dev->pci_lat);
1831 printk(KERN_INFO "%s/0: found at %s, rev: %d, irq: %d, "
Greg Kroah-Hartman228aef62006-06-12 15:16:52 -07001832 "latency: %d, mmio: 0x%llx\n", core->name,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001833 pci_name(pci_dev), dev->pci_rev, pci_dev->irq,
Greg Kroah-Hartman228aef62006-06-12 15:16:52 -07001834 dev->pci_lat,(unsigned long long)pci_resource_start(pci_dev,0));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835
1836 pci_set_master(pci_dev);
Yang Hongyang284901a2009-04-06 19:01:15 -07001837 if (!pci_dma_supported(pci_dev,DMA_BIT_MASK(32))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001838 printk("%s/0: Oops: no 32bit PCI DMA ???\n",core->name);
1839 err = -EIO;
1840 goto fail_core;
1841 }
1842
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001843 /* Initialize VBI template */
1844 memcpy( &cx8800_vbi_template, &cx8800_video_template,
1845 sizeof(cx8800_vbi_template) );
1846 strcpy(cx8800_vbi_template.name,"cx8800-vbi");
Mauro Carvalho Chehab8d87cb92007-01-20 13:58:17 -03001847
Linus Torvalds1da177e2005-04-16 15:20:36 -07001848 /* initialize driver struct */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849 spin_lock_init(&dev->slock);
Mauro Carvalho Chehab63ab1bd2007-01-20 13:58:33 -03001850 core->tvnorm = cx8800_video_template.current_norm;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001851
1852 /* init video dma queues */
1853 INIT_LIST_HEAD(&dev->vidq.active);
1854 INIT_LIST_HEAD(&dev->vidq.queued);
1855 dev->vidq.timeout.function = cx8800_vid_timeout;
1856 dev->vidq.timeout.data = (unsigned long)dev;
1857 init_timer(&dev->vidq.timeout);
1858 cx88_risc_stopper(dev->pci,&dev->vidq.stopper,
1859 MO_VID_DMACNTRL,0x11,0x00);
1860
1861 /* init vbi dma queues */
1862 INIT_LIST_HEAD(&dev->vbiq.active);
1863 INIT_LIST_HEAD(&dev->vbiq.queued);
1864 dev->vbiq.timeout.function = cx8800_vbi_timeout;
1865 dev->vbiq.timeout.data = (unsigned long)dev;
1866 init_timer(&dev->vbiq.timeout);
1867 cx88_risc_stopper(dev->pci,&dev->vbiq.stopper,
1868 MO_VID_DMACNTRL,0x88,0x00);
1869
1870 /* get irq */
1871 err = request_irq(pci_dev->irq, cx8800_irq,
Thomas Gleixner8076fe32006-07-01 19:29:37 -07001872 IRQF_SHARED | IRQF_DISABLED, core->name, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001873 if (err < 0) {
Trent Piepho5772f812007-08-15 14:41:59 -03001874 printk(KERN_ERR "%s/0: can't get IRQ %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875 core->name,pci_dev->irq);
1876 goto fail_core;
1877 }
1878 cx_set(MO_PCI_INTMSK, core->pci_irqmask);
1879
1880 /* load and configure helper modules */
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001881
Hans Verkuil38f9d302008-07-23 05:09:15 -03001882 if (core->board.audio_chip == V4L2_IDENT_WM8775)
Hans Verkuile6574f22009-04-01 03:57:53 -03001883 v4l2_i2c_new_subdev(&core->v4l2_dev, &core->i2c_adap,
Hans Verkuilb8341e12009-03-29 08:26:01 -03001884 "wm8775", "wm8775", 0x36 >> 1);
1885
1886 if (core->board.audio_chip == V4L2_IDENT_TVAUDIO) {
1887 /* This probes for a tda9874 as is used on some
1888 Pixelview Ultra boards. */
Hans Verkuil1792f682009-03-30 11:47:55 -03001889 v4l2_i2c_new_probed_subdev_addr(&core->v4l2_dev,
1890 &core->i2c_adap,
1891 "tvaudio", "tvaudio", 0xb0 >> 1);
Hans Verkuilb8341e12009-03-29 08:26:01 -03001892 }
Steven Toth30579062006-09-25 12:43:42 -03001893
Michael Krufky6fcecce2007-08-24 01:32:31 -03001894 switch (core->boardnr) {
1895 case CX88_BOARD_DVICO_FUSIONHDTV_5_GOLD:
Hans Verkuilb8341e12009-03-29 08:26:01 -03001896 case CX88_BOARD_DVICO_FUSIONHDTV_7_GOLD: {
1897 static struct i2c_board_info rtc_info = {
1898 I2C_BOARD_INFO("isl1208", 0x6f)
1899 };
1900
Michael Krufky6fcecce2007-08-24 01:32:31 -03001901 request_module("rtc-isl1208");
Hans Verkuilb8341e12009-03-29 08:26:01 -03001902 core->i2c_rtc = i2c_new_device(&core->i2c_adap, &rtc_info);
1903 }
Michael Krufky8efd2e22008-04-22 14:45:14 -03001904 /* break intentionally omitted */
1905 case CX88_BOARD_DVICO_FUSIONHDTV_5_PCI_NANO:
1906 request_module("ir-kbd-i2c");
Michael Krufky6fcecce2007-08-24 01:32:31 -03001907 }
1908
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909 /* register v4l devices */
1910 dev->video_dev = cx88_vdev_init(core,dev->pci,
1911 &cx8800_video_template,"video");
1912 err = video_register_device(dev->video_dev,VFL_TYPE_GRABBER,
1913 video_nr[core->nr]);
1914 if (err < 0) {
Trent Piepho5772f812007-08-15 14:41:59 -03001915 printk(KERN_ERR "%s/0: can't register video device\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001916 core->name);
1917 goto fail_unreg;
1918 }
1919 printk(KERN_INFO "%s/0: registered device video%d [v4l2]\n",
Hans Verkuilc6330fb2008-10-19 18:54:26 -03001920 core->name, dev->video_dev->num);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001921
1922 dev->vbi_dev = cx88_vdev_init(core,dev->pci,&cx8800_vbi_template,"vbi");
1923 err = video_register_device(dev->vbi_dev,VFL_TYPE_VBI,
1924 vbi_nr[core->nr]);
1925 if (err < 0) {
Trent Piepho5772f812007-08-15 14:41:59 -03001926 printk(KERN_ERR "%s/0: can't register vbi device\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001927 core->name);
1928 goto fail_unreg;
1929 }
1930 printk(KERN_INFO "%s/0: registered device vbi%d\n",
Hans Verkuilc6330fb2008-10-19 18:54:26 -03001931 core->name, dev->vbi_dev->num);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001932
Trent Piepho6a59d642007-08-15 14:41:57 -03001933 if (core->board.radio.type == CX88_RADIO) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001934 dev->radio_dev = cx88_vdev_init(core,dev->pci,
1935 &cx8800_radio_template,"radio");
1936 err = video_register_device(dev->radio_dev,VFL_TYPE_RADIO,
1937 radio_nr[core->nr]);
1938 if (err < 0) {
Trent Piepho5772f812007-08-15 14:41:59 -03001939 printk(KERN_ERR "%s/0: can't register radio device\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001940 core->name);
1941 goto fail_unreg;
1942 }
1943 printk(KERN_INFO "%s/0: registered device radio%d\n",
Hans Verkuilc6330fb2008-10-19 18:54:26 -03001944 core->name, dev->radio_dev->num);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001945 }
1946
1947 /* everything worked */
1948 list_add_tail(&dev->devlist,&cx8800_devlist);
1949 pci_set_drvdata(pci_dev,dev);
1950
1951 /* initial device configuration */
Ingo Molnar3593cab2006-02-07 06:49:14 -02001952 mutex_lock(&core->lock);
Mauro Carvalho Chehab63ab1bd2007-01-20 13:58:33 -03001953 cx88_set_tvnorm(core,core->tvnorm);
Mauro Carvalho Chehab70f00042006-01-09 15:25:26 -02001954 init_controls(core);
Mauro Carvalho Chehabe90311a2007-01-20 13:58:29 -03001955 cx88_video_mux(core,0);
Ingo Molnar3593cab2006-02-07 06:49:14 -02001956 mutex_unlock(&core->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001957
1958 /* start tvaudio thread */
Trent Piepho6a59d642007-08-15 14:41:57 -03001959 if (core->board.tuner_type != TUNER_ABSENT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001960 core->kthread = kthread_run(cx88_audio_thread, core, "cx88 tvaudio");
Cyrill Gorcunov32b78de2007-07-19 11:44:11 -03001961 if (IS_ERR(core->kthread)) {
1962 err = PTR_ERR(core->kthread);
Trent Piepho5772f812007-08-15 14:41:59 -03001963 printk(KERN_ERR "%s/0: failed to create cx88 audio thread, err=%d\n",
1964 core->name, err);
Cyrill Gorcunov32b78de2007-07-19 11:44:11 -03001965 }
1966 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001967 return 0;
1968
1969fail_unreg:
1970 cx8800_unregister_video(dev);
1971 free_irq(pci_dev->irq, dev);
1972fail_core:
1973 cx88_core_put(core,dev->pci);
1974fail_free:
1975 kfree(dev);
1976 return err;
1977}
1978
1979static void __devexit cx8800_finidev(struct pci_dev *pci_dev)
1980{
Mauro Carvalho Chehab4ac97912005-11-08 21:37:43 -08001981 struct cx8800_dev *dev = pci_get_drvdata(pci_dev);
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001982 struct cx88_core *core = dev->core;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001983
1984 /* stop thread */
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001985 if (core->kthread) {
1986 kthread_stop(core->kthread);
1987 core->kthread = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001988 }
1989
Marton Balintb12203d2008-03-26 02:07:35 -03001990 if (core->ir)
1991 cx88_ir_stop(core, core->ir);
1992
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07001993 cx88_shutdown(core); /* FIXME */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001994 pci_disable_device(pci_dev);
1995
1996 /* unregister stuff */
1997
1998 free_irq(pci_dev->irq, dev);
1999 cx8800_unregister_video(dev);
2000 pci_set_drvdata(pci_dev, NULL);
2001
2002 /* free memory */
2003 btcx_riscmem_free(dev->pci,&dev->vidq.stopper);
2004 list_del(&dev->devlist);
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07002005 cx88_core_put(core,dev->pci);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002006 kfree(dev);
2007}
2008
Alexey Dobriyan17bc98a2006-08-12 22:01:27 -03002009#ifdef CONFIG_PM
Linus Torvalds1da177e2005-04-16 15:20:36 -07002010static int cx8800_suspend(struct pci_dev *pci_dev, pm_message_t state)
2011{
Mauro Carvalho Chehabb45009b2005-06-23 22:05:03 -07002012 struct cx8800_dev *dev = pci_get_drvdata(pci_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002013 struct cx88_core *core = dev->core;
2014
2015 /* stop video+vbi capture */
2016 spin_lock(&dev->slock);
2017 if (!list_empty(&dev->vidq.active)) {
Trent Piepho5772f812007-08-15 14:41:59 -03002018 printk("%s/0: suspend video\n", core->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002019 stop_video_dma(dev);
2020 del_timer(&dev->vidq.timeout);
2021 }
2022 if (!list_empty(&dev->vbiq.active)) {
Trent Piepho5772f812007-08-15 14:41:59 -03002023 printk("%s/0: suspend vbi\n", core->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002024 cx8800_stop_vbi_dma(dev);
2025 del_timer(&dev->vbiq.timeout);
2026 }
2027 spin_unlock(&dev->slock);
2028
Mauro Carvalho Chehab13595a52007-10-01 08:51:39 -03002029 if (core->ir)
2030 cx88_ir_stop(core, core->ir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002031 /* FIXME -- shutdown device */
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07002032 cx88_shutdown(core);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002033
2034 pci_save_state(pci_dev);
2035 if (0 != pci_set_power_state(pci_dev, pci_choose_state(pci_dev, state))) {
2036 pci_disable_device(pci_dev);
2037 dev->state.disabled = 1;
2038 }
2039 return 0;
2040}
2041
2042static int cx8800_resume(struct pci_dev *pci_dev)
2043{
Mauro Carvalho Chehabb45009b2005-06-23 22:05:03 -07002044 struct cx8800_dev *dev = pci_get_drvdata(pci_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045 struct cx88_core *core = dev->core;
Mauro Carvalho Chehab08adb9e2005-09-09 13:03:55 -07002046 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047
2048 if (dev->state.disabled) {
Mauro Carvalho Chehab08adb9e2005-09-09 13:03:55 -07002049 err=pci_enable_device(pci_dev);
2050 if (err) {
Trent Piepho5772f812007-08-15 14:41:59 -03002051 printk(KERN_ERR "%s/0: can't enable device\n",
2052 core->name);
Mauro Carvalho Chehab08adb9e2005-09-09 13:03:55 -07002053 return err;
2054 }
2055
Linus Torvalds1da177e2005-04-16 15:20:36 -07002056 dev->state.disabled = 0;
2057 }
Mauro Carvalho Chehab08adb9e2005-09-09 13:03:55 -07002058 err= pci_set_power_state(pci_dev, PCI_D0);
2059 if (err) {
Trent Piepho5772f812007-08-15 14:41:59 -03002060 printk(KERN_ERR "%s/0: can't set power state\n", core->name);
Mauro Carvalho Chehab08adb9e2005-09-09 13:03:55 -07002061 pci_disable_device(pci_dev);
2062 dev->state.disabled = 1;
2063
2064 return err;
2065 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066 pci_restore_state(pci_dev);
2067
Linus Torvalds1da177e2005-04-16 15:20:36 -07002068 /* FIXME: re-initialize hardware */
Mauro Carvalho Chehabe52e98a2005-09-09 13:03:41 -07002069 cx88_reset(core);
Mauro Carvalho Chehab13595a52007-10-01 08:51:39 -03002070 if (core->ir)
2071 cx88_ir_start(core, core->ir);
2072
2073 cx_set(MO_PCI_INTMSK, core->pci_irqmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074
2075 /* restart video+vbi capture */
2076 spin_lock(&dev->slock);
2077 if (!list_empty(&dev->vidq.active)) {
Trent Piepho5772f812007-08-15 14:41:59 -03002078 printk("%s/0: resume video\n", core->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079 restart_video_queue(dev,&dev->vidq);
2080 }
2081 if (!list_empty(&dev->vbiq.active)) {
Trent Piepho5772f812007-08-15 14:41:59 -03002082 printk("%s/0: resume vbi\n", core->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002083 cx8800_restart_vbi_queue(dev,&dev->vbiq);
2084 }
2085 spin_unlock(&dev->slock);
2086
2087 return 0;
2088}
Alexey Dobriyan17bc98a2006-08-12 22:01:27 -03002089#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002090
2091/* ----------------------------------------------------------- */
2092
Adrian Bunk408b6642005-05-01 08:59:29 -07002093static struct pci_device_id cx8800_pci_tbl[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002094 {
2095 .vendor = 0x14f1,
2096 .device = 0x8800,
Mauro Carvalho Chehabb45009b2005-06-23 22:05:03 -07002097 .subvendor = PCI_ANY_ID,
2098 .subdevice = PCI_ANY_ID,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099 },{
2100 /* --- end of list --- */
2101 }
2102};
2103MODULE_DEVICE_TABLE(pci, cx8800_pci_tbl);
2104
2105static struct pci_driver cx8800_pci_driver = {
Mauro Carvalho Chehabb45009b2005-06-23 22:05:03 -07002106 .name = "cx8800",
2107 .id_table = cx8800_pci_tbl,
2108 .probe = cx8800_initdev,
2109 .remove = __devexit_p(cx8800_finidev),
Alexey Dobriyan17bc98a2006-08-12 22:01:27 -03002110#ifdef CONFIG_PM
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111 .suspend = cx8800_suspend,
2112 .resume = cx8800_resume,
Alexey Dobriyan17bc98a2006-08-12 22:01:27 -03002113#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002114};
2115
2116static int cx8800_init(void)
2117{
Trent Piepho5772f812007-08-15 14:41:59 -03002118 printk(KERN_INFO "cx88/0: cx2388x v4l2 driver version %d.%d.%d loaded\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002119 (CX88_VERSION_CODE >> 16) & 0xff,
2120 (CX88_VERSION_CODE >> 8) & 0xff,
2121 CX88_VERSION_CODE & 0xff);
2122#ifdef SNAPSHOT
2123 printk(KERN_INFO "cx2388x: snapshot date %04d-%02d-%02d\n",
2124 SNAPSHOT/10000, (SNAPSHOT/100)%100, SNAPSHOT%100);
2125#endif
2126 return pci_register_driver(&cx8800_pci_driver);
2127}
2128
2129static void cx8800_fini(void)
2130{
2131 pci_unregister_driver(&cx8800_pci_driver);
2132}
2133
2134module_init(cx8800_init);
2135module_exit(cx8800_fini);
2136
2137/* ----------------------------------------------------------- */
2138/*
2139 * Local variables:
2140 * c-basic-offset: 8
2141 * End:
Mauro Carvalho Chehabb45009b2005-06-23 22:05:03 -07002142 * 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 -07002143 */