blob: 0b64612e35b935cb8e174a9840fabdf3da394106 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Zoran zr36057/zr36067 PCI controller driver, for the
3 * Pinnacle/Miro DC10/DC10+/DC30/DC30+, Iomega Buz, Linux
4 * Media Labs LML33/LML33R10.
5 *
6 * This part handles card-specific data and detection
Mauro Carvalho Chehabd56410e2006-03-25 09:19:53 -03007 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 * Copyright (C) 2000 Serguei Miridonov <mirsev@cicese.mx>
9 *
10 * Currently maintained by:
11 * Ronald Bultje <rbultje@ronald.bitfreak.net>
12 * Laurent Pinchart <laurent.pinchart@skynet.be>
13 * Mailinglist <mjpeg-users@lists.sf.net>
14 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 */
29
Martin Samuelssonfbe60da2006-04-27 10:17:00 -030030#include <linux/delay.h>
31
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <linux/types.h>
33#include <linux/kernel.h>
34#include <linux/module.h>
35#include <linux/init.h>
36#include <linux/vmalloc.h>
37
38#include <linux/proc_fs.h>
39#include <linux/i2c.h>
40#include <linux/i2c-algo-bit.h>
41#include <linux/videodev.h>
Mauro Carvalho Chehab5e87efa2006-06-05 10:26:32 -030042#include <media/v4l2-common.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070043#include <linux/spinlock.h>
44#include <linux/sem.h>
45#include <linux/kmod.h>
46#include <linux/wait.h>
47
48#include <linux/pci.h>
49#include <linux/interrupt.h>
50#include <linux/video_decoder.h>
51#include <linux/video_encoder.h>
Ingo Molnar384c3682006-03-22 03:54:16 -030052#include <linux/mutex.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
54#include <asm/io.h>
55
56#include "videocodec.h"
57#include "zoran.h"
58#include "zoran_card.h"
59#include "zoran_device.h"
60#include "zoran_procfs.h"
61
Linus Torvalds1da177e2005-04-16 15:20:36 -070062extern const struct zoran_format zoran_formats[];
63
Trent Piepho45bdcef2009-01-12 13:09:46 -030064static int card[BUZ_MAX] = { [0 ... (BUZ_MAX-1)] = -1 };
Trent Piepho60e3cac2007-07-17 18:29:42 -030065module_param_array(card, int, NULL, 0444);
Trent Piepho45bdcef2009-01-12 13:09:46 -030066MODULE_PARM_DESC(card, "Card type");
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
Trent Piepho45bdcef2009-01-12 13:09:46 -030068static int encoder[BUZ_MAX] = { [0 ... (BUZ_MAX-1)] = -1 };
Trent Piepho60e3cac2007-07-17 18:29:42 -030069module_param_array(encoder, int, NULL, 0444);
Trent Piepho45bdcef2009-01-12 13:09:46 -030070MODULE_PARM_DESC(encoder, "Video encoder chip");
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
Trent Piepho45bdcef2009-01-12 13:09:46 -030072static int decoder[BUZ_MAX] = { [0 ... (BUZ_MAX-1)] = -1 };
Trent Piepho60e3cac2007-07-17 18:29:42 -030073module_param_array(decoder, int, NULL, 0444);
Trent Piepho45bdcef2009-01-12 13:09:46 -030074MODULE_PARM_DESC(decoder, "Video decoder chip");
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
76/*
77 The video mem address of the video card.
78 The driver has a little database for some videocards
79 to determine it from there. If your video card is not in there
80 you have either to give it to the driver as a parameter
81 or set in in a VIDIOCSFBUF ioctl
82 */
83
Douglas Schilling Landgrafff699e62008-04-22 14:41:48 -030084static unsigned long vidmem; /* default = 0 - Video memory base address */
Trent Piepho60e3cac2007-07-17 18:29:42 -030085module_param(vidmem, ulong, 0444);
86MODULE_PARM_DESC(vidmem, "Default video memory base address");
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
88/*
89 Default input and video norm at startup of the driver.
90*/
91
Douglas Schilling Landgrafff699e62008-04-22 14:41:48 -030092static unsigned int default_input; /* default 0 = Composite, 1 = S-Video */
Trent Piepho60e3cac2007-07-17 18:29:42 -030093module_param(default_input, uint, 0444);
Linus Torvalds1da177e2005-04-16 15:20:36 -070094MODULE_PARM_DESC(default_input,
95 "Default input (0=Composite, 1=S-Video, 2=Internal)");
96
Martin Samuelssonfbe60da2006-04-27 10:17:00 -030097static int default_mux = 1; /* 6 Eyes input selection */
Trent Piepho60e3cac2007-07-17 18:29:42 -030098module_param(default_mux, int, 0644);
Martin Samuelssonfbe60da2006-04-27 10:17:00 -030099MODULE_PARM_DESC(default_mux,
100 "Default 6 Eyes mux setting (Input selection)");
101
Douglas Schilling Landgrafff699e62008-04-22 14:41:48 -0300102static int default_norm; /* default 0 = PAL, 1 = NTSC 2 = SECAM */
Trent Piepho60e3cac2007-07-17 18:29:42 -0300103module_param(default_norm, int, 0444);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104MODULE_PARM_DESC(default_norm, "Default norm (0=PAL, 1=NTSC, 2=SECAM)");
105
Trent Piepho60e3cac2007-07-17 18:29:42 -0300106/* /dev/videoN, -1 for autodetect */
Trent Piepho45bdcef2009-01-12 13:09:46 -0300107static int video_nr[BUZ_MAX] = { [0 ... (BUZ_MAX-1)] = -1 };
Trent Piepho60e3cac2007-07-17 18:29:42 -0300108module_param_array(video_nr, int, NULL, 0444);
Trent Piepho45bdcef2009-01-12 13:09:46 -0300109MODULE_PARM_DESC(video_nr, "Video device number (-1=Auto)");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
111/*
112 Number and size of grab buffers for Video 4 Linux
113 The vast majority of applications should not need more than 2,
114 the very popular BTTV driver actually does ONLY have 2.
115 Time sensitive applications might need more, the maximum
116 is VIDEO_MAX_FRAME (defined in <linux/videodev.h>).
117
118 The size is set so that the maximum possible request
119 can be satisfied. Decrease it, if bigphys_area alloc'd
120 memory is low. If you don't have the bigphys_area patch,
121 set it to 128 KB. Will you allow only to grab small
122 images with V4L, but that's better than nothing.
123
124 v4l_bufsize has to be given in KB !
125
126*/
127
Hans Verkuil497d7d02009-02-18 18:33:35 -0300128int v4l_nbufs = 4;
129int v4l_bufsize = 810; /* Everybody should be able to work with this setting */
Trent Piepho60e3cac2007-07-17 18:29:42 -0300130module_param(v4l_nbufs, int, 0644);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131MODULE_PARM_DESC(v4l_nbufs, "Maximum number of V4L buffers to use");
Trent Piepho60e3cac2007-07-17 18:29:42 -0300132module_param(v4l_bufsize, int, 0644);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133MODULE_PARM_DESC(v4l_bufsize, "Maximum size per V4L buffer (in kB)");
134
135int jpg_nbufs = 32;
136int jpg_bufsize = 512; /* max size for 100% quality full-PAL frame */
Trent Piepho60e3cac2007-07-17 18:29:42 -0300137module_param(jpg_nbufs, int, 0644);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138MODULE_PARM_DESC(jpg_nbufs, "Maximum number of JPG buffers to use");
Trent Piepho60e3cac2007-07-17 18:29:42 -0300139module_param(jpg_bufsize, int, 0644);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140MODULE_PARM_DESC(jpg_bufsize, "Maximum size per JPG buffer (in kB)");
141
142int pass_through = 0; /* 1=Pass through TV signal when device is not used */
143 /* 0=Show color bar when device is not used (LML33: only if lml33dpath=1) */
Trent Piepho60e3cac2007-07-17 18:29:42 -0300144module_param(pass_through, int, 0644);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145MODULE_PARM_DESC(pass_through,
146 "Pass TV signal through to TV-out when idling");
147
Jean Delvare18b548c2007-07-17 18:29:41 -0300148int zr36067_debug = 1;
149module_param_named(debug, zr36067_debug, int, 0644);
150MODULE_PARM_DESC(debug, "Debug level (0-5)");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151
152MODULE_DESCRIPTION("Zoran-36057/36067 JPEG codec driver");
153MODULE_AUTHOR("Serguei Miridonov");
154MODULE_LICENSE("GPL");
155
Trent Piepho17faeb22009-01-12 13:09:46 -0300156#define ZR_DEVICE(subven, subdev, data) { \
157 .vendor = PCI_VENDOR_ID_ZORAN, .device = PCI_DEVICE_ID_ZORAN_36057, \
158 .subvendor = (subven), .subdevice = (subdev), .driver_data = (data) }
159
Mauro Carvalho Chehabdbdf03b2009-01-08 23:27:32 -0300160static struct pci_device_id zr36067_pci_tbl[] = {
Trent Piepho17faeb22009-01-12 13:09:46 -0300161 ZR_DEVICE(PCI_VENDOR_ID_MIRO, PCI_DEVICE_ID_MIRO_DC10PLUS, DC10plus),
162 ZR_DEVICE(PCI_VENDOR_ID_MIRO, PCI_DEVICE_ID_MIRO_DC30PLUS, DC30plus),
163 ZR_DEVICE(PCI_VENDOR_ID_ELECTRONICDESIGNGMBH, PCI_DEVICE_ID_LML_33R10, LML33R10),
164 ZR_DEVICE(PCI_VENDOR_ID_IOMEGA, PCI_DEVICE_ID_IOMEGA_BUZ, BUZ),
165 ZR_DEVICE(PCI_ANY_ID, PCI_ANY_ID, NUM_CARDS),
Mauro Carvalho Chehabdbdf03b2009-01-08 23:27:32 -0300166 {0}
167};
168MODULE_DEVICE_TABLE(pci, zr36067_pci_tbl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169
Trent Piepho601139e2009-01-12 13:09:46 -0300170static unsigned int zoran_num; /* number of cards found */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171
172/* videocodec bus functions ZR36060 */
173static u32
174zr36060_read (struct videocodec *codec,
175 u16 reg)
176{
177 struct zoran *zr = (struct zoran *) codec->master_data->data;
178 __u32 data;
179
180 if (post_office_wait(zr)
181 || post_office_write(zr, 0, 1, reg >> 8)
182 || post_office_write(zr, 0, 2, reg & 0xff)) {
183 return -1;
184 }
185
186 data = post_office_read(zr, 0, 3) & 0xff;
187 return data;
188}
189
190static void
191zr36060_write (struct videocodec *codec,
192 u16 reg,
193 u32 val)
194{
195 struct zoran *zr = (struct zoran *) codec->master_data->data;
196
197 if (post_office_wait(zr)
198 || post_office_write(zr, 0, 1, reg >> 8)
199 || post_office_write(zr, 0, 2, reg & 0xff)) {
200 return;
201 }
202
203 post_office_write(zr, 0, 3, val & 0xff);
204}
205
206/* videocodec bus functions ZR36050 */
207static u32
208zr36050_read (struct videocodec *codec,
209 u16 reg)
210{
211 struct zoran *zr = (struct zoran *) codec->master_data->data;
212 __u32 data;
213
214 if (post_office_wait(zr)
215 || post_office_write(zr, 1, 0, reg >> 2)) { // reg. HIGHBYTES
216 return -1;
217 }
218
219 data = post_office_read(zr, 0, reg & 0x03) & 0xff; // reg. LOWBYTES + read
220 return data;
221}
222
223static void
224zr36050_write (struct videocodec *codec,
225 u16 reg,
226 u32 val)
227{
228 struct zoran *zr = (struct zoran *) codec->master_data->data;
229
230 if (post_office_wait(zr)
231 || post_office_write(zr, 1, 0, reg >> 2)) { // reg. HIGHBYTES
232 return;
233 }
234
235 post_office_write(zr, 0, reg & 0x03, val & 0xff); // reg. LOWBYTES + wr. data
236}
237
238/* videocodec bus functions ZR36016 */
239static u32
240zr36016_read (struct videocodec *codec,
241 u16 reg)
242{
243 struct zoran *zr = (struct zoran *) codec->master_data->data;
244 __u32 data;
245
246 if (post_office_wait(zr)) {
247 return -1;
248 }
249
250 data = post_office_read(zr, 2, reg & 0x03) & 0xff; // read
251 return data;
252}
253
254/* hack for in zoran_device.c */
255void
256zr36016_write (struct videocodec *codec,
257 u16 reg,
258 u32 val)
259{
260 struct zoran *zr = (struct zoran *) codec->master_data->data;
261
262 if (post_office_wait(zr)) {
263 return;
264 }
265
266 post_office_write(zr, 2, reg & 0x03, val & 0x0ff); // wr. data
267}
268
269/*
270 * Board specific information
271 */
272
273static void
274dc10_init (struct zoran *zr)
275{
276 dprintk(3, KERN_DEBUG "%s: dc10_init()\n", ZR_DEVNAME(zr));
277
278 /* Pixel clock selection */
279 GPIO(zr, 4, 0);
280 GPIO(zr, 5, 1);
281 /* Enable the video bus sync signals */
282 GPIO(zr, 7, 0);
283}
284
285static void
286dc10plus_init (struct zoran *zr)
287{
288 dprintk(3, KERN_DEBUG "%s: dc10plus_init()\n", ZR_DEVNAME(zr));
289}
290
291static void
292buz_init (struct zoran *zr)
293{
294 dprintk(3, KERN_DEBUG "%s: buz_init()\n", ZR_DEVNAME(zr));
295
296 /* some stuff from Iomega */
297 pci_write_config_dword(zr->pci_dev, 0xfc, 0x90680f15);
298 pci_write_config_dword(zr->pci_dev, 0x0c, 0x00012020);
299 pci_write_config_dword(zr->pci_dev, 0xe8, 0xc0200000);
300}
301
302static void
303lml33_init (struct zoran *zr)
304{
305 dprintk(3, KERN_DEBUG "%s: lml33_init()\n", ZR_DEVNAME(zr));
306
307 GPIO(zr, 2, 1); // Set Composite input/output
308}
309
Martin Samuelssonfbe60da2006-04-27 10:17:00 -0300310static void
311avs6eyes_init (struct zoran *zr)
312{
313 // AverMedia 6-Eyes original driver by Christer Weinigel
314
315 // Lifted straight from Christer's old driver and
316 // modified slightly by Martin Samuelsson.
317
318 int mux = default_mux; /* 1 = BT866, 7 = VID1 */
319
320 GPIO(zr, 4, 1); /* Bt866 SLEEP on */
321 udelay(2);
322
323 GPIO(zr, 0, 1); /* ZR36060 /RESET on */
324 GPIO(zr, 1, 0); /* ZR36060 /SLEEP on */
325 GPIO(zr, 2, mux & 1); /* MUX S0 */
326 GPIO(zr, 3, 0); /* /FRAME on */
327 GPIO(zr, 4, 0); /* Bt866 SLEEP off */
328 GPIO(zr, 5, mux & 2); /* MUX S1 */
329 GPIO(zr, 6, 0); /* ? */
330 GPIO(zr, 7, mux & 4); /* MUX S2 */
331
332}
333
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334static char *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335codecid_to_modulename (u16 codecid)
336{
337 char *name = NULL;
338
339 switch (codecid) {
340 case CODEC_TYPE_ZR36060:
341 name = "zr36060";
342 break;
343 case CODEC_TYPE_ZR36050:
344 name = "zr36050";
345 break;
346 case CODEC_TYPE_ZR36016:
347 name = "zr36016";
348 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 }
350
351 return name;
352}
353
354// struct tvnorm {
355// u16 Wt, Wa, HStart, HSyncStart, Ht, Ha, VStart;
356// };
357
358static struct tvnorm f50sqpixel = { 944, 768, 83, 880, 625, 576, 16 };
359static struct tvnorm f60sqpixel = { 780, 640, 51, 716, 525, 480, 12 };
360static struct tvnorm f50ccir601 = { 864, 720, 75, 804, 625, 576, 18 };
361static struct tvnorm f60ccir601 = { 858, 720, 57, 788, 525, 480, 16 };
362
363static struct tvnorm f50ccir601_lml33 = { 864, 720, 75+34, 804, 625, 576, 18 };
364static struct tvnorm f60ccir601_lml33 = { 858, 720, 57+34, 788, 525, 480, 16 };
365
366/* The DC10 (57/16/50) uses VActive as HSync, so HStart must be 0 */
367static struct tvnorm f50sqpixel_dc10 = { 944, 768, 0, 880, 625, 576, 0 };
368static struct tvnorm f60sqpixel_dc10 = { 780, 640, 0, 716, 525, 480, 12 };
369
370/* FIXME: I cannot swap U and V in saa7114, so i do one
371 * pixel left shift in zoran (75 -> 74)
372 * (Maxim Yevtyushkin <max@linuxmedialabs.com>) */
373static struct tvnorm f50ccir601_lm33r10 = { 864, 720, 74+54, 804, 625, 576, 18 };
374static struct tvnorm f60ccir601_lm33r10 = { 858, 720, 56+54, 788, 525, 480, 16 };
375
Martin Samuelssonfbe60da2006-04-27 10:17:00 -0300376/* FIXME: The ks0127 seem incapable of swapping U and V, too, which is why I
377 * copy Maxim's left shift hack for the 6 Eyes.
378 *
379 * Christer's driver used the unshifted norms, though...
380 * /Sam */
381static struct tvnorm f50ccir601_avs6eyes = { 864, 720, 74, 804, 625, 576, 18 };
382static struct tvnorm f60ccir601_avs6eyes = { 858, 720, 56, 788, 525, 480, 16 };
383
Hans Verkuil0ab6e1c2009-02-19 16:18:23 -0300384static const unsigned short vpx3220_addrs[] = { 0x43, 0x47, I2C_CLIENT_END };
385static const unsigned short saa7110_addrs[] = { 0x4e, 0x4f, I2C_CLIENT_END };
386static const unsigned short saa7111_addrs[] = { 0x25, 0x24, I2C_CLIENT_END };
387static const unsigned short saa7114_addrs[] = { 0x21, 0x20, I2C_CLIENT_END };
388static const unsigned short adv717x_addrs[] = { 0x6a, 0x6b, 0x2a, 0x2b, I2C_CLIENT_END };
389static const unsigned short ks0127_addrs[] = { 0x6c, 0x6d, I2C_CLIENT_END };
390static const unsigned short saa7185_addrs[] = { 0x44, I2C_CLIENT_END };
391static const unsigned short bt819_addrs[] = { 0x45, I2C_CLIENT_END };
392static const unsigned short bt856_addrs[] = { 0x44, I2C_CLIENT_END };
393static const unsigned short bt866_addrs[] = { 0x44, I2C_CLIENT_END };
394
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395static struct card_info zoran_cards[NUM_CARDS] __devinitdata = {
396 {
397 .type = DC10_old,
398 .name = "DC10(old)",
Hans Verkuil0ab6e1c2009-02-19 16:18:23 -0300399 .i2c_decoder = "vpx3220a",
400 .mod_decoder = "vpx3220",
401 .addrs_decoder = vpx3220_addrs,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 .video_codec = CODEC_TYPE_ZR36050,
403 .video_vfe = CODEC_TYPE_ZR36016,
404
405 .inputs = 3,
406 .input = {
407 { 1, "Composite" },
408 { 2, "S-Video" },
409 { 0, "Internal/comp" }
410 },
Hans Verkuil107063c2009-02-18 17:26:06 -0300411 .norms = V4L2_STD_NTSC|V4L2_STD_PAL|V4L2_STD_SECAM,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 .tvn = {
413 &f50sqpixel_dc10,
414 &f60sqpixel_dc10,
415 &f50sqpixel_dc10
416 },
417 .jpeg_int = 0,
418 .vsync_int = ZR36057_ISR_GIRQ1,
419 .gpio = { 2, 1, -1, 3, 7, 0, 4, 5 },
420 .gpio_pol = { 0, 0, 0, 1, 0, 0, 0, 0 },
421 .gpcs = { -1, 0 },
422 .vfe_pol = { 0, 0, 0, 0, 0, 0, 0, 0 },
423 .gws_not_connected = 0,
Martin Samuelssonfbe60da2006-04-27 10:17:00 -0300424 .input_mux = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 .init = &dc10_init,
426 }, {
427 .type = DC10_new,
428 .name = "DC10(new)",
Hans Verkuil0ab6e1c2009-02-19 16:18:23 -0300429 .i2c_decoder = "saa7110",
430 .mod_decoder = "saa7110",
431 .addrs_decoder = saa7110_addrs,
432 .i2c_encoder = "adv7175",
433 .mod_encoder = "adv7175",
434 .addrs_encoder = adv717x_addrs,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 .video_codec = CODEC_TYPE_ZR36060,
436
437 .inputs = 3,
438 .input = {
439 { 0, "Composite" },
440 { 7, "S-Video" },
441 { 5, "Internal/comp" }
442 },
Hans Verkuil107063c2009-02-18 17:26:06 -0300443 .norms = V4L2_STD_NTSC|V4L2_STD_PAL|V4L2_STD_SECAM,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 .tvn = {
445 &f50sqpixel,
446 &f60sqpixel,
447 &f50sqpixel},
448 .jpeg_int = ZR36057_ISR_GIRQ0,
449 .vsync_int = ZR36057_ISR_GIRQ1,
450 .gpio = { 3, 0, 6, 1, 2, -1, 4, 5 },
451 .gpio_pol = { 0, 0, 0, 0, 0, 0, 0, 0 },
452 .gpcs = { -1, 1},
453 .vfe_pol = { 1, 1, 1, 1, 0, 0, 0, 0 },
454 .gws_not_connected = 0,
Martin Samuelssonfbe60da2006-04-27 10:17:00 -0300455 .input_mux = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 .init = &dc10plus_init,
457 }, {
458 .type = DC10plus,
459 .name = "DC10plus",
Hans Verkuil0ab6e1c2009-02-19 16:18:23 -0300460 .i2c_decoder = "saa7110",
461 .mod_decoder = "saa7110",
462 .addrs_decoder = saa7110_addrs,
463 .i2c_encoder = "adv7175",
464 .mod_encoder = "adv7175",
465 .addrs_encoder = adv717x_addrs,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 .video_codec = CODEC_TYPE_ZR36060,
467
468 .inputs = 3,
469 .input = {
470 { 0, "Composite" },
471 { 7, "S-Video" },
472 { 5, "Internal/comp" }
473 },
Hans Verkuil107063c2009-02-18 17:26:06 -0300474 .norms = V4L2_STD_NTSC|V4L2_STD_PAL|V4L2_STD_SECAM,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 .tvn = {
476 &f50sqpixel,
477 &f60sqpixel,
478 &f50sqpixel
479 },
480 .jpeg_int = ZR36057_ISR_GIRQ0,
481 .vsync_int = ZR36057_ISR_GIRQ1,
482 .gpio = { 3, 0, 6, 1, 2, -1, 4, 5 },
483 .gpio_pol = { 0, 0, 0, 0, 0, 0, 0, 0 },
484 .gpcs = { -1, 1 },
485 .vfe_pol = { 1, 1, 1, 1, 0, 0, 0, 0 },
486 .gws_not_connected = 0,
Martin Samuelssonfbe60da2006-04-27 10:17:00 -0300487 .input_mux = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 .init = &dc10plus_init,
489 }, {
490 .type = DC30,
491 .name = "DC30",
Hans Verkuil0ab6e1c2009-02-19 16:18:23 -0300492 .i2c_decoder = "vpx3220a",
493 .mod_decoder = "vpx3220",
494 .addrs_decoder = vpx3220_addrs,
495 .i2c_encoder = "adv7175",
496 .mod_encoder = "adv7175",
497 .addrs_encoder = adv717x_addrs,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 .video_codec = CODEC_TYPE_ZR36050,
499 .video_vfe = CODEC_TYPE_ZR36016,
500
501 .inputs = 3,
502 .input = {
503 { 1, "Composite" },
504 { 2, "S-Video" },
505 { 0, "Internal/comp" }
506 },
Hans Verkuil107063c2009-02-18 17:26:06 -0300507 .norms = V4L2_STD_NTSC|V4L2_STD_PAL|V4L2_STD_SECAM,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 .tvn = {
509 &f50sqpixel_dc10,
510 &f60sqpixel_dc10,
511 &f50sqpixel_dc10
512 },
513 .jpeg_int = 0,
514 .vsync_int = ZR36057_ISR_GIRQ1,
515 .gpio = { 2, 1, -1, 3, 7, 0, 4, 5 },
516 .gpio_pol = { 0, 0, 0, 1, 0, 0, 0, 0 },
517 .gpcs = { -1, 0 },
518 .vfe_pol = { 0, 0, 0, 0, 0, 0, 0, 0 },
519 .gws_not_connected = 0,
Martin Samuelssonfbe60da2006-04-27 10:17:00 -0300520 .input_mux = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 .init = &dc10_init,
522 }, {
523 .type = DC30plus,
524 .name = "DC30plus",
Hans Verkuil0ab6e1c2009-02-19 16:18:23 -0300525 .i2c_decoder = "vpx3220a",
526 .mod_decoder = "vpx3220",
527 .addrs_decoder = vpx3220_addrs,
528 .i2c_encoder = "adv7175",
529 .mod_encoder = "adv7175",
530 .addrs_encoder = adv717x_addrs,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 .video_codec = CODEC_TYPE_ZR36050,
532 .video_vfe = CODEC_TYPE_ZR36016,
533
534 .inputs = 3,
535 .input = {
536 { 1, "Composite" },
537 { 2, "S-Video" },
538 { 0, "Internal/comp" }
539 },
Hans Verkuil107063c2009-02-18 17:26:06 -0300540 .norms = V4L2_STD_NTSC|V4L2_STD_PAL|V4L2_STD_SECAM,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 .tvn = {
542 &f50sqpixel_dc10,
543 &f60sqpixel_dc10,
544 &f50sqpixel_dc10
545 },
546 .jpeg_int = 0,
547 .vsync_int = ZR36057_ISR_GIRQ1,
548 .gpio = { 2, 1, -1, 3, 7, 0, 4, 5 },
549 .gpio_pol = { 0, 0, 0, 1, 0, 0, 0, 0 },
550 .gpcs = { -1, 0 },
551 .vfe_pol = { 0, 0, 0, 0, 0, 0, 0, 0 },
552 .gws_not_connected = 0,
Martin Samuelssonfbe60da2006-04-27 10:17:00 -0300553 .input_mux = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 .init = &dc10_init,
555 }, {
556 .type = LML33,
557 .name = "LML33",
Hans Verkuil0ab6e1c2009-02-19 16:18:23 -0300558 .i2c_decoder = "bt819a",
559 .mod_decoder = "bt819",
560 .addrs_decoder = bt819_addrs,
561 .i2c_encoder = "bt856",
562 .mod_encoder = "bt856",
563 .addrs_encoder = bt856_addrs,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 .video_codec = CODEC_TYPE_ZR36060,
565
566 .inputs = 2,
567 .input = {
568 { 0, "Composite" },
569 { 7, "S-Video" }
570 },
Hans Verkuil107063c2009-02-18 17:26:06 -0300571 .norms = V4L2_STD_NTSC|V4L2_STD_PAL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 .tvn = {
573 &f50ccir601_lml33,
574 &f60ccir601_lml33,
575 NULL
576 },
577 .jpeg_int = ZR36057_ISR_GIRQ1,
578 .vsync_int = ZR36057_ISR_GIRQ0,
579 .gpio = { 1, -1, 3, 5, 7, -1, -1, -1 },
580 .gpio_pol = { 0, 0, 0, 0, 1, 0, 0, 0 },
581 .gpcs = { 3, 1 },
582 .vfe_pol = { 1, 1, 0, 0, 0, 1, 0, 0 },
583 .gws_not_connected = 1,
Martin Samuelssonfbe60da2006-04-27 10:17:00 -0300584 .input_mux = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 .init = &lml33_init,
586 }, {
587 .type = LML33R10,
588 .name = "LML33R10",
Hans Verkuil0ab6e1c2009-02-19 16:18:23 -0300589 .i2c_decoder = "saa7114",
590 .mod_decoder = "saa7115",
591 .addrs_decoder = saa7114_addrs,
592 .i2c_encoder = "adv7170",
593 .mod_encoder = "adv7170",
594 .addrs_encoder = adv717x_addrs,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 .video_codec = CODEC_TYPE_ZR36060,
596
597 .inputs = 2,
598 .input = {
599 { 0, "Composite" },
600 { 7, "S-Video" }
601 },
Hans Verkuil107063c2009-02-18 17:26:06 -0300602 .norms = V4L2_STD_NTSC|V4L2_STD_PAL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 .tvn = {
604 &f50ccir601_lm33r10,
605 &f60ccir601_lm33r10,
606 NULL
607 },
608 .jpeg_int = ZR36057_ISR_GIRQ1,
609 .vsync_int = ZR36057_ISR_GIRQ0,
610 .gpio = { 1, -1, 3, 5, 7, -1, -1, -1 },
611 .gpio_pol = { 0, 0, 0, 0, 1, 0, 0, 0 },
612 .gpcs = { 3, 1 },
613 .vfe_pol = { 1, 1, 0, 0, 0, 1, 0, 0 },
614 .gws_not_connected = 1,
Martin Samuelssonfbe60da2006-04-27 10:17:00 -0300615 .input_mux = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 .init = &lml33_init,
617 }, {
618 .type = BUZ,
619 .name = "Buz",
Hans Verkuil0ab6e1c2009-02-19 16:18:23 -0300620 .i2c_decoder = "saa7111",
621 .mod_decoder = "saa7115",
622 .addrs_decoder = saa7111_addrs,
623 .i2c_encoder = "saa7185",
624 .mod_encoder = "saa7185",
625 .addrs_encoder = saa7185_addrs,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 .video_codec = CODEC_TYPE_ZR36060,
627
628 .inputs = 2,
629 .input = {
630 { 3, "Composite" },
631 { 7, "S-Video" }
632 },
Hans Verkuil107063c2009-02-18 17:26:06 -0300633 .norms = V4L2_STD_NTSC|V4L2_STD_PAL|V4L2_STD_SECAM,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 .tvn = {
635 &f50ccir601,
636 &f60ccir601,
637 &f50ccir601
638 },
639 .jpeg_int = ZR36057_ISR_GIRQ1,
640 .vsync_int = ZR36057_ISR_GIRQ0,
641 .gpio = { 1, -1, 3, -1, -1, -1, -1, -1 },
642 .gpio_pol = { 0, 0, 0, 0, 0, 0, 0, 0 },
643 .gpcs = { 3, 1 },
644 .vfe_pol = { 1, 1, 0, 0, 0, 1, 0, 0 },
645 .gws_not_connected = 1,
Martin Samuelssonfbe60da2006-04-27 10:17:00 -0300646 .input_mux = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 .init = &buz_init,
Martin Samuelssonfbe60da2006-04-27 10:17:00 -0300648 }, {
649 .type = AVS6EYES,
650 .name = "6-Eyes",
651 /* AverMedia chose not to brand the 6-Eyes. Thus it
652 can't be autodetected, and requires card=x. */
Hans Verkuil0ab6e1c2009-02-19 16:18:23 -0300653 .i2c_decoder = "ks0127",
654 .mod_decoder = "ks0127",
655 .addrs_decoder = ks0127_addrs,
656 .i2c_encoder = "bt866",
657 .mod_encoder = "bt866",
658 .addrs_encoder = bt866_addrs,
Martin Samuelssonfbe60da2006-04-27 10:17:00 -0300659 .video_codec = CODEC_TYPE_ZR36060,
660
661 .inputs = 10,
662 .input = {
663 { 0, "Composite 1" },
664 { 1, "Composite 2" },
665 { 2, "Composite 3" },
666 { 4, "Composite 4" },
667 { 5, "Composite 5" },
668 { 6, "Composite 6" },
669 { 8, "S-Video 1" },
670 { 9, "S-Video 2" },
671 {10, "S-Video 3" },
672 {15, "YCbCr" }
673 },
Hans Verkuil107063c2009-02-18 17:26:06 -0300674 .norms = V4L2_STD_NTSC|V4L2_STD_PAL,
Martin Samuelssonfbe60da2006-04-27 10:17:00 -0300675 .tvn = {
676 &f50ccir601_avs6eyes,
677 &f60ccir601_avs6eyes,
678 NULL
679 },
680 .jpeg_int = ZR36057_ISR_GIRQ1,
681 .vsync_int = ZR36057_ISR_GIRQ0,
682 .gpio = { 1, 0, 3, -1, -1, -1, -1, -1 },// Validity unknown /Sam
683 .gpio_pol = { 0, 0, 0, 0, 0, 0, 0, 0 }, // Validity unknown /Sam
684 .gpcs = { 3, 1 }, // Validity unknown /Sam
685 .vfe_pol = { 1, 0, 0, 0, 0, 1, 0, 0 }, // Validity unknown /Sam
686 .gws_not_connected = 1,
687 .input_mux = 1,
688 .init = &avs6eyes_init,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 }
Martin Samuelssonfbe60da2006-04-27 10:17:00 -0300690
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691};
692
693/*
694 * I2C functions
695 */
696/* software I2C functions */
697static int
698zoran_i2c_getsda (void *data)
699{
700 struct zoran *zr = (struct zoran *) data;
701
702 return (btread(ZR36057_I2CBR) >> 1) & 1;
703}
704
705static int
706zoran_i2c_getscl (void *data)
707{
708 struct zoran *zr = (struct zoran *) data;
709
710 return btread(ZR36057_I2CBR) & 1;
711}
712
713static void
714zoran_i2c_setsda (void *data,
715 int state)
716{
717 struct zoran *zr = (struct zoran *) data;
718
719 if (state)
720 zr->i2cbr |= 2;
721 else
722 zr->i2cbr &= ~2;
723 btwrite(zr->i2cbr, ZR36057_I2CBR);
724}
725
726static void
727zoran_i2c_setscl (void *data,
728 int state)
729{
730 struct zoran *zr = (struct zoran *) data;
731
732 if (state)
733 zr->i2cbr |= 1;
734 else
735 zr->i2cbr &= ~1;
736 btwrite(zr->i2cbr, ZR36057_I2CBR);
737}
738
Jean Delvare62751632008-06-12 13:20:46 -0300739static const struct i2c_algo_bit_data zoran_i2c_bit_data_template = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 .setsda = zoran_i2c_setsda,
741 .setscl = zoran_i2c_setscl,
742 .getsda = zoran_i2c_getsda,
743 .getscl = zoran_i2c_getscl,
744 .udelay = 10,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 .timeout = 100,
746};
747
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748static int
749zoran_register_i2c (struct zoran *zr)
750{
751 memcpy(&zr->i2c_algo, &zoran_i2c_bit_data_template,
752 sizeof(struct i2c_algo_bit_data));
753 zr->i2c_algo.data = zr;
Jean Delvare62751632008-06-12 13:20:46 -0300754 zr->i2c_adapter.id = I2C_HW_B_ZR36067;
Jean Delvare62751632008-06-12 13:20:46 -0300755 strlcpy(zr->i2c_adapter.name, ZR_DEVNAME(zr),
756 sizeof(zr->i2c_adapter.name));
Hans Verkuil0ab6e1c2009-02-19 16:18:23 -0300757 i2c_set_adapdata(&zr->i2c_adapter, &zr->v4l2_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 zr->i2c_adapter.algo_data = &zr->i2c_algo;
Jean Delvare12a917f2007-02-13 22:09:03 +0100759 zr->i2c_adapter.dev.parent = &zr->pci_dev->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 return i2c_bit_add_bus(&zr->i2c_adapter);
761}
762
763static void
764zoran_unregister_i2c (struct zoran *zr)
765{
Jean Delvare32697112006-12-10 21:21:33 +0100766 i2c_del_adapter(&zr->i2c_adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767}
768
769/* Check a zoran_params struct for correctness, insert default params */
770
771int
772zoran_check_jpg_settings (struct zoran *zr,
Hans Verkuil0ba514d2009-02-18 17:11:17 -0300773 struct zoran_jpg_settings *settings,
774 int try)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775{
776 int err = 0, err0 = 0;
777
778 dprintk(4,
779 KERN_DEBUG
780 "%s: check_jpg_settings() - dec: %d, Hdcm: %d, Vdcm: %d, Tdcm: %d\n",
781 ZR_DEVNAME(zr), settings->decimation, settings->HorDcm,
782 settings->VerDcm, settings->TmpDcm);
783 dprintk(4,
784 KERN_DEBUG
785 "%s: check_jpg_settings() - x: %d, y: %d, w: %d, y: %d\n",
786 ZR_DEVNAME(zr), settings->img_x, settings->img_y,
787 settings->img_width, settings->img_height);
788 /* Check decimation, set default values for decimation = 1, 2, 4 */
789 switch (settings->decimation) {
790 case 1:
791
792 settings->HorDcm = 1;
793 settings->VerDcm = 1;
794 settings->TmpDcm = 1;
795 settings->field_per_buff = 2;
796 settings->img_x = 0;
797 settings->img_y = 0;
798 settings->img_width = BUZ_MAX_WIDTH;
799 settings->img_height = BUZ_MAX_HEIGHT / 2;
800 break;
801 case 2:
802
803 settings->HorDcm = 2;
804 settings->VerDcm = 1;
805 settings->TmpDcm = 2;
806 settings->field_per_buff = 1;
807 settings->img_x = (BUZ_MAX_WIDTH == 720) ? 8 : 0;
808 settings->img_y = 0;
809 settings->img_width =
810 (BUZ_MAX_WIDTH == 720) ? 704 : BUZ_MAX_WIDTH;
811 settings->img_height = BUZ_MAX_HEIGHT / 2;
812 break;
813 case 4:
814
815 if (zr->card.type == DC10_new) {
816 dprintk(1,
817 KERN_DEBUG
818 "%s: check_jpg_settings() - HDec by 4 is not supported on the DC10\n",
819 ZR_DEVNAME(zr));
820 err0++;
821 break;
822 }
823
824 settings->HorDcm = 4;
825 settings->VerDcm = 2;
826 settings->TmpDcm = 2;
827 settings->field_per_buff = 1;
828 settings->img_x = (BUZ_MAX_WIDTH == 720) ? 8 : 0;
829 settings->img_y = 0;
830 settings->img_width =
831 (BUZ_MAX_WIDTH == 720) ? 704 : BUZ_MAX_WIDTH;
832 settings->img_height = BUZ_MAX_HEIGHT / 2;
833 break;
834 case 0:
835
836 /* We have to check the data the user has set */
837
838 if (settings->HorDcm != 1 && settings->HorDcm != 2 &&
Hans Verkuil0ba514d2009-02-18 17:11:17 -0300839 (zr->card.type == DC10_new || settings->HorDcm != 4)) {
840 settings->HorDcm = clamp(settings->HorDcm, 1, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841 err0++;
Hans Verkuil0ba514d2009-02-18 17:11:17 -0300842 }
843 if (settings->VerDcm != 1 && settings->VerDcm != 2) {
844 settings->VerDcm = clamp(settings->VerDcm, 1, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845 err0++;
Hans Verkuil0ba514d2009-02-18 17:11:17 -0300846 }
847 if (settings->TmpDcm != 1 && settings->TmpDcm != 2) {
848 settings->TmpDcm = clamp(settings->TmpDcm, 1, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 err0++;
Hans Verkuil0ba514d2009-02-18 17:11:17 -0300850 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 if (settings->field_per_buff != 1 &&
Hans Verkuil0ba514d2009-02-18 17:11:17 -0300852 settings->field_per_buff != 2) {
853 settings->field_per_buff = clamp(settings->field_per_buff, 1, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854 err0++;
Hans Verkuil0ba514d2009-02-18 17:11:17 -0300855 }
856 if (settings->img_x < 0) {
857 settings->img_x = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858 err0++;
Hans Verkuil0ba514d2009-02-18 17:11:17 -0300859 }
860 if (settings->img_y < 0) {
861 settings->img_y = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 err0++;
Hans Verkuil0ba514d2009-02-18 17:11:17 -0300863 }
864 if (settings->img_width < 0 || settings->img_width > BUZ_MAX_WIDTH) {
865 settings->img_width = clamp(settings->img_width, 0, (int)BUZ_MAX_WIDTH);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866 err0++;
Hans Verkuil0ba514d2009-02-18 17:11:17 -0300867 }
868 if (settings->img_height < 0 || settings->img_height > BUZ_MAX_HEIGHT / 2) {
869 settings->img_height = clamp(settings->img_height, 0, BUZ_MAX_HEIGHT / 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870 err0++;
Hans Verkuil0ba514d2009-02-18 17:11:17 -0300871 }
872 if (settings->img_x + settings->img_width > BUZ_MAX_WIDTH) {
873 settings->img_x = BUZ_MAX_WIDTH - settings->img_width;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874 err0++;
Hans Verkuil0ba514d2009-02-18 17:11:17 -0300875 }
876 if (settings->img_y + settings->img_height > BUZ_MAX_HEIGHT / 2) {
877 settings->img_y = BUZ_MAX_HEIGHT / 2 - settings->img_height;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878 err0++;
Hans Verkuil0ba514d2009-02-18 17:11:17 -0300879 }
880 if (settings->img_width % (16 * settings->HorDcm) != 0) {
881 settings->img_width -= settings->img_width % (16 * settings->HorDcm);
882 if (settings->img_width == 0)
883 settings->img_width = 16 * settings->HorDcm;
884 err0++;
885 }
886 if (settings->img_height % (8 * settings->VerDcm) != 0) {
887 settings->img_height -= settings->img_height % (8 * settings->VerDcm);
888 if (settings->img_height == 0)
889 settings->img_height = 8 * settings->VerDcm;
890 err0++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891 }
892
Hans Verkuil0ba514d2009-02-18 17:11:17 -0300893 if (!try && err0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894 dprintk(1,
895 KERN_ERR
896 "%s: check_jpg_settings() - error in params for decimation = 0\n",
897 ZR_DEVNAME(zr));
898 err++;
899 }
900 break;
901 default:
902 dprintk(1,
903 KERN_ERR
904 "%s: check_jpg_settings() - decimation = %d, must be 0, 1, 2 or 4\n",
905 ZR_DEVNAME(zr), settings->decimation);
906 err++;
907 break;
908 }
909
910 if (settings->jpg_comp.quality > 100)
911 settings->jpg_comp.quality = 100;
912 if (settings->jpg_comp.quality < 5)
913 settings->jpg_comp.quality = 5;
914 if (settings->jpg_comp.APPn < 0)
915 settings->jpg_comp.APPn = 0;
916 if (settings->jpg_comp.APPn > 15)
917 settings->jpg_comp.APPn = 15;
918 if (settings->jpg_comp.APP_len < 0)
919 settings->jpg_comp.APP_len = 0;
920 if (settings->jpg_comp.APP_len > 60)
921 settings->jpg_comp.APP_len = 60;
922 if (settings->jpg_comp.COM_len < 0)
923 settings->jpg_comp.COM_len = 0;
924 if (settings->jpg_comp.COM_len > 60)
925 settings->jpg_comp.COM_len = 60;
926 if (err)
927 return -EINVAL;
928 return 0;
929}
930
931void
932zoran_open_init_params (struct zoran *zr)
933{
934 int i;
935
936 /* User must explicitly set a window */
937 zr->overlay_settings.is_set = 0;
938 zr->overlay_mask = NULL;
939 zr->overlay_active = ZORAN_FREE;
940
941 zr->v4l_memgrab_active = 0;
942 zr->v4l_overlay_active = 0;
943 zr->v4l_grab_frame = NO_GRAB_ACTIVE;
944 zr->v4l_grab_seq = 0;
945 zr->v4l_settings.width = 192;
946 zr->v4l_settings.height = 144;
Jean Delvarec014ec92008-09-07 05:21:34 -0300947 zr->v4l_settings.format = &zoran_formats[7]; /* YUY2 - YUV-4:2:2 packed */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948 zr->v4l_settings.bytesperline =
949 zr->v4l_settings.width *
950 ((zr->v4l_settings.format->depth + 7) / 8);
951
952 /* DMA ring stuff for V4L */
953 zr->v4l_pend_tail = 0;
954 zr->v4l_pend_head = 0;
955 zr->v4l_sync_tail = 0;
956 zr->v4l_buffers.active = ZORAN_FREE;
957 for (i = 0; i < VIDEO_MAX_FRAME; i++) {
958 zr->v4l_buffers.buffer[i].state = BUZ_STATE_USER; /* nothing going on */
959 }
960 zr->v4l_buffers.allocated = 0;
961
962 for (i = 0; i < BUZ_MAX_FRAME; i++) {
963 zr->jpg_buffers.buffer[i].state = BUZ_STATE_USER; /* nothing going on */
964 }
965 zr->jpg_buffers.active = ZORAN_FREE;
966 zr->jpg_buffers.allocated = 0;
967 /* Set necessary params and call zoran_check_jpg_settings to set the defaults */
968 zr->jpg_settings.decimation = 1;
969 zr->jpg_settings.jpg_comp.quality = 50; /* default compression factor 8 */
970 if (zr->card.type != BUZ)
971 zr->jpg_settings.odd_even = 1;
972 else
973 zr->jpg_settings.odd_even = 0;
974 zr->jpg_settings.jpg_comp.APPn = 0;
975 zr->jpg_settings.jpg_comp.APP_len = 0; /* No APPn marker */
976 memset(zr->jpg_settings.jpg_comp.APP_data, 0,
977 sizeof(zr->jpg_settings.jpg_comp.APP_data));
978 zr->jpg_settings.jpg_comp.COM_len = 0; /* No COM marker */
979 memset(zr->jpg_settings.jpg_comp.COM_data, 0,
980 sizeof(zr->jpg_settings.jpg_comp.COM_data));
981 zr->jpg_settings.jpg_comp.jpeg_markers =
982 JPEG_MARKER_DHT | JPEG_MARKER_DQT;
Hans Verkuil0ba514d2009-02-18 17:11:17 -0300983 i = zoran_check_jpg_settings(zr, &zr->jpg_settings, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984 if (i)
985 dprintk(1,
986 KERN_ERR
987 "%s: zoran_open_init_params() internal error\n",
988 ZR_DEVNAME(zr));
989
990 clear_interrupt_counters(zr);
991 zr->testing = 0;
992}
993
994static void __devinit
995test_interrupts (struct zoran *zr)
996{
997 DEFINE_WAIT(wait);
998 int timeout, icr;
999
1000 clear_interrupt_counters(zr);
1001
1002 zr->testing = 1;
1003 icr = btread(ZR36057_ICR);
1004 btwrite(0x78000000 | ZR36057_ICR_IntPinEn, ZR36057_ICR);
1005 prepare_to_wait(&zr->test_q, &wait, TASK_INTERRUPTIBLE);
1006 timeout = schedule_timeout(HZ);
1007 finish_wait(&zr->test_q, &wait);
1008 btwrite(0, ZR36057_ICR);
1009 btwrite(0x78000000, ZR36057_ISR);
1010 zr->testing = 0;
1011 dprintk(5, KERN_INFO "%s: Testing interrupts...\n", ZR_DEVNAME(zr));
1012 if (timeout) {
1013 dprintk(1, ": time spent: %d\n", 1 * HZ - timeout);
1014 }
Jean Delvare18b548c2007-07-17 18:29:41 -03001015 if (zr36067_debug > 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016 print_interrupts(zr);
1017 btwrite(icr, ZR36057_ICR);
1018}
1019
1020static int __devinit
1021zr36057_init (struct zoran *zr)
1022{
Jean Delvaredaf72f42006-03-22 03:48:37 -03001023 int j, err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024
1025 dprintk(1,
1026 KERN_INFO
1027 "%s: zr36057_init() - initializing card[%d], zr=%p\n",
1028 ZR_DEVNAME(zr), zr->id, zr);
1029
1030 /* default setup of all parameters which will persist between opens */
1031 zr->user = 0;
1032
1033 init_waitqueue_head(&zr->v4l_capq);
1034 init_waitqueue_head(&zr->jpg_capq);
1035 init_waitqueue_head(&zr->test_q);
1036 zr->jpg_buffers.allocated = 0;
1037 zr->v4l_buffers.allocated = 0;
1038
1039 zr->buffer.base = (void *) vidmem;
1040 zr->buffer.width = 0;
1041 zr->buffer.height = 0;
1042 zr->buffer.depth = 0;
1043 zr->buffer.bytesperline = 0;
1044
1045 /* Avoid nonsense settings from user for default input/norm */
1046 if (default_norm < VIDEO_MODE_PAL &&
1047 default_norm > VIDEO_MODE_SECAM)
1048 default_norm = VIDEO_MODE_PAL;
Hans Verkuil107063c2009-02-18 17:26:06 -03001049 if (default_norm == VIDEO_MODE_PAL) {
1050 zr->norm = V4L2_STD_PAL;
1051 zr->timing = zr->card.tvn[0];
1052 } else if (default_norm == VIDEO_MODE_NTSC) {
1053 zr->norm = V4L2_STD_NTSC;
1054 zr->timing = zr->card.tvn[1];
1055 } else {
1056 zr->norm = V4L2_STD_SECAM;
1057 zr->timing = zr->card.tvn[2];
1058 }
1059 if (zr->timing == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060 dprintk(1,
1061 KERN_WARNING
1062 "%s: zr36057_init() - default TV standard not supported by hardware. PAL will be used.\n",
1063 ZR_DEVNAME(zr));
Hans Verkuil107063c2009-02-18 17:26:06 -03001064 zr->norm = V4L2_STD_PAL;
1065 zr->timing = zr->card.tvn[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066 }
1067
Trent Piepho60e3cac2007-07-17 18:29:42 -03001068 if (default_input > zr->card.inputs-1) {
1069 dprintk(1,
1070 KERN_WARNING
1071 "%s: default_input value %d out of range (0-%d)\n",
1072 ZR_DEVNAME(zr), default_input, zr->card.inputs-1);
1073 default_input = 0;
1074 }
1075 zr->input = default_input;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077 /* default setup (will be repeated at every open) */
1078 zoran_open_init_params(zr);
1079
1080 /* allocate memory *before* doing anything to the hardware
1081 * in case allocation fails */
Jean Delvaredaf72f42006-03-22 03:48:37 -03001082 zr->stat_com = kzalloc(BUZ_NUM_STAT_COM * 4, GFP_KERNEL);
1083 zr->video_dev = kmalloc(sizeof(struct video_device), GFP_KERNEL);
1084 if (!zr->stat_com || !zr->video_dev) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085 dprintk(1,
1086 KERN_ERR
1087 "%s: zr36057_init() - kmalloc (STAT_COM) failed\n",
1088 ZR_DEVNAME(zr));
Jean Delvaredaf72f42006-03-22 03:48:37 -03001089 err = -ENOMEM;
1090 goto exit_free;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092 for (j = 0; j < BUZ_NUM_STAT_COM; j++) {
Al Viro9c169df2008-06-22 14:19:49 -03001093 zr->stat_com[j] = cpu_to_le32(1); /* mark as unavailable to zr36057 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094 }
1095
1096 /*
1097 * Now add the template and register the device unit.
1098 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099 memcpy(zr->video_dev, &zoran_template, sizeof(zoran_template));
Hans Verkuilaff88bc2009-02-18 13:52:24 -03001100 zr->video_dev->parent = &zr->pci_dev->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101 strcpy(zr->video_dev->name, ZR_DEVNAME(zr));
Trent Piepho60e3cac2007-07-17 18:29:42 -03001102 err = video_register_device(zr->video_dev, VFL_TYPE_GRABBER, video_nr[zr->id]);
Jean Delvaredaf72f42006-03-22 03:48:37 -03001103 if (err < 0)
Trent Piepho66aa66ea32009-01-11 12:02:54 -03001104 goto exit_free;
Trent Piepho601139e2009-01-12 13:09:46 -03001105 video_set_drvdata(zr->video_dev, zr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106
1107 zoran_init_hardware(zr);
Jean Delvare18b548c2007-07-17 18:29:41 -03001108 if (zr36067_debug > 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109 detect_guest_activity(zr);
1110 test_interrupts(zr);
1111 if (!pass_through) {
Hans Verkuil107063c2009-02-18 17:26:06 -03001112 struct v4l2_routing route = { 2, 0 };
1113
Hans Verkuil0ab6e1c2009-02-19 16:18:23 -03001114 decoder_call(zr, video, s_stream, 0);
1115 encoder_call(zr, video, s_routing, &route);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116 }
1117
1118 zr->zoran_proc = NULL;
1119 zr->initialized = 1;
1120 return 0;
Jean Delvaredaf72f42006-03-22 03:48:37 -03001121
Jean Delvaredaf72f42006-03-22 03:48:37 -03001122exit_free:
1123 kfree(zr->stat_com);
1124 kfree(zr->video_dev);
1125 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126}
1127
Trent Piepho66aa66ea32009-01-11 12:02:54 -03001128static void __devexit zoran_remove(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129{
Hans Verkuil0ab6e1c2009-02-19 16:18:23 -03001130 struct v4l2_device *v4l2_dev = dev_get_drvdata(&pdev->dev);
1131 struct zoran *zr = to_zoran(v4l2_dev);
Trent Piepho66aa66ea32009-01-11 12:02:54 -03001132
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133 if (!zr->initialized)
Jean Delvare85b9b8a2008-07-14 09:51:03 -03001134 goto exit_free;
Trent Piepho66aa66ea32009-01-11 12:02:54 -03001135
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136 /* unregister videocodec bus */
1137 if (zr->codec) {
1138 struct videocodec_master *master = zr->codec->master_data;
Jesper Juhl2ea75332005-11-07 01:01:31 -08001139
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140 videocodec_detach(zr->codec);
Jesper Juhl2ea75332005-11-07 01:01:31 -08001141 kfree(master);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142 }
1143 if (zr->vfe) {
1144 struct videocodec_master *master = zr->vfe->master_data;
Jesper Juhl2ea75332005-11-07 01:01:31 -08001145
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146 videocodec_detach(zr->vfe);
Jesper Juhl2ea75332005-11-07 01:01:31 -08001147 kfree(master);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148 }
1149
1150 /* unregister i2c bus */
1151 zoran_unregister_i2c(zr);
1152 /* disable PCI bus-mastering */
1153 zoran_set_pci_master(zr, 0);
1154 /* put chip into reset */
1155 btwrite(0, ZR36057_SPGPPCR);
1156 free_irq(zr->pci_dev->irq, zr);
1157 /* unmap and free memory */
Jean Delvaredaf72f42006-03-22 03:48:37 -03001158 kfree(zr->stat_com);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159 zoran_proc_cleanup(zr);
1160 iounmap(zr->zr36057_mem);
1161 pci_disable_device(zr->pci_dev);
1162 video_unregister_device(zr->video_dev);
Jean Delvare85b9b8a2008-07-14 09:51:03 -03001163exit_free:
Hans Verkuil0ab6e1c2009-02-19 16:18:23 -03001164 v4l2_device_unregister(&zr->v4l2_dev);
Jean Delvare85b9b8a2008-07-14 09:51:03 -03001165 kfree(zr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166}
1167
1168void
1169zoran_vdev_release (struct video_device *vdev)
1170{
1171 kfree(vdev);
1172}
1173
1174static struct videocodec_master * __devinit
1175zoran_setup_videocodec (struct zoran *zr,
1176 int type)
1177{
1178 struct videocodec_master *m = NULL;
1179
1180 m = kmalloc(sizeof(struct videocodec_master), GFP_KERNEL);
1181 if (!m) {
1182 dprintk(1,
1183 KERN_ERR
1184 "%s: zoran_setup_videocodec() - no memory\n",
1185 ZR_DEVNAME(zr));
1186 return m;
1187 }
1188
Mauro Carvalho Chehab22c4a4e2007-10-15 12:09:17 -03001189 /* magic and type are unused for master struct. Makes sense only at
1190 codec structs.
1191 In the past, .type were initialized to the old V4L1 .hardware
1192 value, as VID_HARDWARE_ZR36067
1193 */
1194 m->magic = 0L;
1195 m->type = 0;
1196
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197 m->flags = CODEC_FLAG_ENCODER | CODEC_FLAG_DECODER;
1198 strncpy(m->name, ZR_DEVNAME(zr), sizeof(m->name));
1199 m->data = zr;
1200
1201 switch (type)
1202 {
1203 case CODEC_TYPE_ZR36060:
1204 m->readreg = zr36060_read;
1205 m->writereg = zr36060_write;
1206 m->flags |= CODEC_FLAG_JPEG | CODEC_FLAG_VFE;
1207 break;
1208 case CODEC_TYPE_ZR36050:
1209 m->readreg = zr36050_read;
1210 m->writereg = zr36050_write;
1211 m->flags |= CODEC_FLAG_JPEG;
1212 break;
1213 case CODEC_TYPE_ZR36016:
1214 m->readreg = zr36016_read;
1215 m->writereg = zr36016_write;
1216 m->flags |= CODEC_FLAG_VFE;
1217 break;
1218 }
1219
1220 return m;
1221}
1222
1223/*
Joe Perchesc84e6032008-02-03 17:18:59 +02001224 * Scan for a Buz card (actually for the PCI controller ZR36057),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225 * request the irq and map the io memory
1226 */
Trent Piepho66aa66ea32009-01-11 12:02:54 -03001227static int __devinit zoran_probe(struct pci_dev *pdev,
1228 const struct pci_device_id *ent)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229{
1230 unsigned char latency, need_latency;
1231 struct zoran *zr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232 int result;
1233 struct videocodec_master *master_vfe = NULL;
1234 struct videocodec_master *master_codec = NULL;
1235 int card_num;
Hans Verkuil0ab6e1c2009-02-19 16:18:23 -03001236 char *codec_name, *vfe_name;
Trent Piepho66aa66ea32009-01-11 12:02:54 -03001237 unsigned int nr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001238
Trent Piepho66aa66ea32009-01-11 12:02:54 -03001239
Trent Piepho601139e2009-01-12 13:09:46 -03001240 nr = zoran_num++;
Trent Piepho66aa66ea32009-01-11 12:02:54 -03001241 if (nr >= BUZ_MAX) {
1242 dprintk(1,
1243 KERN_ERR
1244 "%s: driver limited to %d card(s) maximum\n",
1245 ZORAN_NAME, BUZ_MAX);
1246 return -ENOENT;
1247 }
1248
Trent Piepho66aa66ea32009-01-11 12:02:54 -03001249 zr = kzalloc(sizeof(struct zoran), GFP_KERNEL);
1250 if (!zr) {
1251 dprintk(1,
1252 KERN_ERR
1253 "%s: find_zr36057() - kzalloc failed\n",
1254 ZORAN_NAME);
Trent Piepho66aa66ea32009-01-11 12:02:54 -03001255 return -ENOMEM;
1256 }
Hans Verkuil0ab6e1c2009-02-19 16:18:23 -03001257 if (v4l2_device_register(&pdev->dev, &zr->v4l2_dev))
1258 goto zr_free_mem;
Trent Piepho66aa66ea32009-01-11 12:02:54 -03001259 zr->pci_dev = pdev;
1260 zr->id = nr;
1261 snprintf(ZR_DEVNAME(zr), sizeof(ZR_DEVNAME(zr)), "MJPEG[%u]", zr->id);
1262 spin_lock_init(&zr->spinlock);
1263 mutex_init(&zr->resource_lock);
1264 if (pci_enable_device(pdev))
Hans Verkuil0ab6e1c2009-02-19 16:18:23 -03001265 goto zr_unreg;
Trent Piepho66aa66ea32009-01-11 12:02:54 -03001266 pci_read_config_byte(zr->pci_dev, PCI_CLASS_REVISION, &zr->revision);
Trent Piepho17faeb22009-01-12 13:09:46 -03001267
1268 dprintk(1,
1269 KERN_INFO
Trent Piepho5e098b62009-01-12 13:09:46 -03001270 "%s: Zoran ZR360%c7 (rev %d), irq: %d, memory: 0x%08llx\n",
Trent Piepho17faeb22009-01-12 13:09:46 -03001271 ZR_DEVNAME(zr), zr->revision < 2 ? '5' : '6', zr->revision,
Trent Piepho5e098b62009-01-12 13:09:46 -03001272 zr->pci_dev->irq, (uint64_t)pci_resource_start(zr->pci_dev, 0));
Trent Piepho17faeb22009-01-12 13:09:46 -03001273 if (zr->revision >= 2) {
Trent Piepho66aa66ea32009-01-11 12:02:54 -03001274 dprintk(1,
1275 KERN_INFO
Trent Piepho17faeb22009-01-12 13:09:46 -03001276 "%s: Subsystem vendor=0x%04x id=0x%04x\n",
1277 ZR_DEVNAME(zr), zr->pci_dev->subsystem_vendor,
1278 zr->pci_dev->subsystem_device);
1279 }
Trent Piepho66aa66ea32009-01-11 12:02:54 -03001280
Trent Piepho17faeb22009-01-12 13:09:46 -03001281 /* Use auto-detected card type? */
1282 if (card[nr] == -1) {
1283 if (zr->revision < 2) {
Jean Delvare85b9b8a2008-07-14 09:51:03 -03001284 dprintk(1,
1285 KERN_ERR
Trent Piepho17faeb22009-01-12 13:09:46 -03001286 "%s: No card type specified, please use the card=X module parameter\n",
1287 ZR_DEVNAME(zr));
1288 dprintk(1,
1289 KERN_ERR
1290 "%s: It is not possible to auto-detect ZR36057 based cards\n",
Trent Piepho66aa66ea32009-01-11 12:02:54 -03001291 ZR_DEVNAME(zr));
Hans Verkuil0ab6e1c2009-02-19 16:18:23 -03001292 goto zr_unreg;
Trent Piepho66aa66ea32009-01-11 12:02:54 -03001293 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294
Trent Piepho17faeb22009-01-12 13:09:46 -03001295 card_num = ent->driver_data;
1296 if (card_num >= NUM_CARDS) {
1297 dprintk(1,
1298 KERN_ERR
1299 "%s: Unknown card, try specifying card=X module parameter\n",
Trent Piepho66aa66ea32009-01-11 12:02:54 -03001300 ZR_DEVNAME(zr));
Hans Verkuil0ab6e1c2009-02-19 16:18:23 -03001301 goto zr_unreg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302 }
Trent Piepho17faeb22009-01-12 13:09:46 -03001303 dprintk(3,
1304 KERN_DEBUG
1305 "%s: %s() - card %s detected\n",
1306 ZR_DEVNAME(zr), __func__, zoran_cards[card_num].name);
1307 } else {
1308 card_num = card[nr];
1309 if (card_num >= NUM_CARDS || card_num < 0) {
1310 dprintk(1,
1311 KERN_ERR
1312 "%s: User specified card type %d out of range (0 .. %d)\n",
1313 ZR_DEVNAME(zr), card_num, NUM_CARDS - 1);
Hans Verkuil0ab6e1c2009-02-19 16:18:23 -03001314 goto zr_unreg;
Trent Piepho17faeb22009-01-12 13:09:46 -03001315 }
Trent Piepho66aa66ea32009-01-11 12:02:54 -03001316 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317
Trent Piepho66aa66ea32009-01-11 12:02:54 -03001318 /* even though we make this a non pointer and thus
1319 * theoretically allow for making changes to this struct
1320 * on a per-individual card basis at runtime, this is
1321 * strongly discouraged. This structure is intended to
1322 * keep general card information, no settings or anything */
1323 zr->card = zoran_cards[card_num];
1324 snprintf(ZR_DEVNAME(zr), sizeof(ZR_DEVNAME(zr)),
1325 "%s[%u]", zr->card.name, zr->id);
1326
Trent Piepho5e098b62009-01-12 13:09:46 -03001327 zr->zr36057_mem = pci_ioremap_bar(zr->pci_dev, 0);
Trent Piepho66aa66ea32009-01-11 12:02:54 -03001328 if (!zr->zr36057_mem) {
1329 dprintk(1,
1330 KERN_ERR
Trent Piepho5e098b62009-01-12 13:09:46 -03001331 "%s: %s() - ioremap failed\n",
1332 ZR_DEVNAME(zr), __func__);
Hans Verkuil0ab6e1c2009-02-19 16:18:23 -03001333 goto zr_unreg;
Trent Piepho66aa66ea32009-01-11 12:02:54 -03001334 }
1335
1336 result = request_irq(zr->pci_dev->irq, zoran_irq,
1337 IRQF_SHARED | IRQF_DISABLED, ZR_DEVNAME(zr), zr);
1338 if (result < 0) {
1339 if (result == -EINVAL) {
1340 dprintk(1,
1341 KERN_ERR
1342 "%s: find_zr36057() - bad irq number or handler\n",
1343 ZR_DEVNAME(zr));
1344 } else if (result == -EBUSY) {
1345 dprintk(1,
1346 KERN_ERR
1347 "%s: find_zr36057() - IRQ %d busy, change your PnP config in BIOS\n",
1348 ZR_DEVNAME(zr), zr->pci_dev->irq);
1349 } else {
1350 dprintk(1,
1351 KERN_ERR
1352 "%s: find_zr36057() - can't assign irq, error code %d\n",
1353 ZR_DEVNAME(zr), result);
1354 }
1355 goto zr_unmap;
1356 }
1357
1358 /* set PCI latency timer */
1359 pci_read_config_byte(zr->pci_dev, PCI_LATENCY_TIMER,
1360 &latency);
1361 need_latency = zr->revision > 1 ? 32 : 48;
1362 if (latency != need_latency) {
1363 dprintk(2,
1364 KERN_INFO
1365 "%s: Changing PCI latency from %d to %d\n",
1366 ZR_DEVNAME(zr), latency, need_latency);
1367 pci_write_config_byte(zr->pci_dev, PCI_LATENCY_TIMER,
1368 need_latency);
1369 }
1370
1371 zr36057_restart(zr);
1372 /* i2c */
1373 dprintk(2, KERN_INFO "%s: Initializing i2c bus...\n",
1374 ZR_DEVNAME(zr));
1375
Trent Piepho66aa66ea32009-01-11 12:02:54 -03001376 if (zoran_register_i2c(zr) < 0) {
1377 dprintk(1,
1378 KERN_ERR
1379 "%s: find_zr36057() - can't initialize i2c bus\n",
1380 ZR_DEVNAME(zr));
1381 goto zr_free_irq;
1382 }
1383
Hans Verkuil0ab6e1c2009-02-19 16:18:23 -03001384 zr->decoder = v4l2_i2c_new_probed_subdev(&zr->i2c_adapter,
1385 zr->card.mod_decoder, zr->card.i2c_decoder, zr->card.addrs_decoder);
1386
1387 if (zr->card.mod_encoder)
1388 zr->encoder = v4l2_i2c_new_probed_subdev(&zr->i2c_adapter,
1389 zr->card.mod_encoder, zr->card.i2c_encoder,
1390 zr->card.addrs_encoder);
1391
Trent Piepho66aa66ea32009-01-11 12:02:54 -03001392 dprintk(2,
1393 KERN_INFO "%s: Initializing videocodec bus...\n",
1394 ZR_DEVNAME(zr));
1395
1396 if (zr->card.video_codec) {
1397 codec_name = codecid_to_modulename(zr->card.video_codec);
1398 if (codec_name) {
1399 result = request_module(codec_name);
1400 if (result) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401 dprintk(1,
1402 KERN_ERR
1403 "%s: failed to load modules %s: %d\n",
1404 ZR_DEVNAME(zr), codec_name, result);
1405 }
1406 }
Trent Piepho66aa66ea32009-01-11 12:02:54 -03001407 }
1408 if (zr->card.video_vfe) {
1409 vfe_name = codecid_to_modulename(zr->card.video_vfe);
1410 if (vfe_name) {
1411 result = request_module(vfe_name);
1412 if (result < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413 dprintk(1,
1414 KERN_ERR
1415 "%s: failed to load modules %s: %d\n",
1416 ZR_DEVNAME(zr), vfe_name, result);
1417 }
1418 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419 }
Alan Coxe491cbc2006-10-03 20:44:12 -03001420
Trent Piepho66aa66ea32009-01-11 12:02:54 -03001421 /* reset JPEG codec */
1422 jpeg_codec_sleep(zr, 1);
1423 jpeg_codec_reset(zr);
1424 /* video bus enabled */
1425 /* display codec revision */
1426 if (zr->card.video_codec != 0) {
1427 master_codec = zoran_setup_videocodec(zr, zr->card.video_codec);
1428 if (!master_codec)
1429 goto zr_unreg_i2c;
1430 zr->codec = videocodec_attach(master_codec);
1431 if (!zr->codec) {
1432 dprintk(1,
1433 KERN_ERR
1434 "%s: find_zr36057() - no codec found\n",
1435 ZR_DEVNAME(zr));
1436 goto zr_free_codec;
1437 }
1438 if (zr->codec->type != zr->card.video_codec) {
1439 dprintk(1,
1440 KERN_ERR
1441 "%s: find_zr36057() - wrong codec\n",
1442 ZR_DEVNAME(zr));
1443 goto zr_detach_codec;
1444 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445 }
Trent Piepho66aa66ea32009-01-11 12:02:54 -03001446 if (zr->card.video_vfe != 0) {
1447 master_vfe = zoran_setup_videocodec(zr, zr->card.video_vfe);
1448 if (!master_vfe)
1449 goto zr_detach_codec;
1450 zr->vfe = videocodec_attach(master_vfe);
1451 if (!zr->vfe) {
1452 dprintk(1,
1453 KERN_ERR
1454 "%s: find_zr36057() - no VFE found\n",
1455 ZR_DEVNAME(zr));
1456 goto zr_free_vfe;
1457 }
1458 if (zr->vfe->type != zr->card.video_vfe) {
1459 dprintk(1,
1460 KERN_ERR
1461 "%s: find_zr36057() = wrong VFE\n",
1462 ZR_DEVNAME(zr));
1463 goto zr_detach_vfe;
1464 }
1465 }
Trent Piepho66aa66ea32009-01-11 12:02:54 -03001466
1467 /* take care of Natoma chipset and a revision 1 zr36057 */
1468 if ((pci_pci_problems & PCIPCI_NATOMA) && zr->revision <= 1) {
1469 zr->jpg_buffers.need_contiguous = 1;
1470 dprintk(1,
1471 KERN_INFO
1472 "%s: ZR36057/Natoma bug, max. buffer size is 128K\n",
1473 ZR_DEVNAME(zr));
1474 }
1475
1476 if (zr36057_init(zr) < 0)
1477 goto zr_detach_vfe;
1478
1479 zoran_proc_init(zr);
1480
Trent Piepho66aa66ea32009-01-11 12:02:54 -03001481 return 0;
1482
1483zr_detach_vfe:
1484 videocodec_detach(zr->vfe);
1485zr_free_vfe:
1486 kfree(master_vfe);
1487zr_detach_codec:
1488 videocodec_detach(zr->codec);
1489zr_free_codec:
1490 kfree(master_codec);
1491zr_unreg_i2c:
1492 zoran_unregister_i2c(zr);
1493zr_free_irq:
1494 btwrite(0, ZR36057_SPGPPCR);
1495 free_irq(zr->pci_dev->irq, zr);
1496zr_unmap:
1497 iounmap(zr->zr36057_mem);
Hans Verkuil0ab6e1c2009-02-19 16:18:23 -03001498zr_unreg:
1499 v4l2_device_unregister(&zr->v4l2_dev);
Trent Piepho66aa66ea32009-01-11 12:02:54 -03001500zr_free_mem:
1501 kfree(zr);
1502
1503 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504}
1505
Trent Piepho66aa66ea32009-01-11 12:02:54 -03001506static struct pci_driver zoran_driver = {
1507 .name = "zr36067",
1508 .id_table = zr36067_pci_tbl,
1509 .probe = zoran_probe,
1510 .remove = zoran_remove,
1511};
1512
1513static int __init zoran_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514{
Trent Piepho66aa66ea32009-01-11 12:02:54 -03001515 int res;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517 printk(KERN_INFO "Zoran MJPEG board driver version %d.%d.%d\n",
1518 MAJOR_VERSION, MINOR_VERSION, RELEASE_VERSION);
1519
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520 /* check the parameters we have been given, adjust if necessary */
1521 if (v4l_nbufs < 2)
1522 v4l_nbufs = 2;
1523 if (v4l_nbufs > VIDEO_MAX_FRAME)
1524 v4l_nbufs = VIDEO_MAX_FRAME;
1525 /* The user specfies the in KB, we want them in byte
1526 * (and page aligned) */
1527 v4l_bufsize = PAGE_ALIGN(v4l_bufsize * 1024);
1528 if (v4l_bufsize < 32768)
1529 v4l_bufsize = 32768;
1530 /* 2 MB is arbitrary but sufficient for the maximum possible images */
1531 if (v4l_bufsize > 2048 * 1024)
1532 v4l_bufsize = 2048 * 1024;
1533 if (jpg_nbufs < 4)
1534 jpg_nbufs = 4;
1535 if (jpg_nbufs > BUZ_MAX_FRAME)
1536 jpg_nbufs = BUZ_MAX_FRAME;
1537 jpg_bufsize = PAGE_ALIGN(jpg_bufsize * 1024);
1538 if (jpg_bufsize < 8192)
1539 jpg_bufsize = 8192;
1540 if (jpg_bufsize > (512 * 1024))
1541 jpg_bufsize = 512 * 1024;
1542 /* Use parameter for vidmem or try to find a video card */
1543 if (vidmem) {
1544 dprintk(1,
1545 KERN_INFO
1546 "%s: Using supplied video memory base address @ 0x%lx\n",
1547 ZORAN_NAME, vidmem);
1548 }
1549
1550 /* random nonsense */
Jean Delvare18b548c2007-07-17 18:29:41 -03001551 dprintk(6, KERN_DEBUG "Jotti is een held!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552
1553 /* some mainboards might not do PCI-PCI data transfer well */
Alan Coxe3558802006-09-14 11:47:55 -03001554 if (pci_pci_problems & (PCIPCI_FAIL|PCIAGP_FAIL|PCIPCI_ALIMAGIK)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555 dprintk(1,
1556 KERN_WARNING
Alan Coxe3558802006-09-14 11:47:55 -03001557 "%s: chipset does not support reliable PCI-PCI DMA\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558 ZORAN_NAME);
1559 }
1560
Trent Piepho66aa66ea32009-01-11 12:02:54 -03001561 res = pci_register_driver(&zoran_driver);
1562 if (res) {
1563 dprintk(1,
1564 KERN_ERR
1565 "%s: Unable to register ZR36057 driver\n",
1566 ZORAN_NAME);
1567 return res;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568 }
1569
1570 return 0;
1571}
1572
Trent Piepho66aa66ea32009-01-11 12:02:54 -03001573static void __exit zoran_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574{
Trent Piepho66aa66ea32009-01-11 12:02:54 -03001575 pci_unregister_driver(&zoran_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576}
1577
Trent Piepho66aa66ea32009-01-11 12:02:54 -03001578module_init(zoran_init);
1579module_exit(zoran_exit);