[XFRM]: skb_cow_data() does not set proper owner for new skbs.
[linux-2.6/verdex.git] / drivers / media / video / hexium_orion.c
blob42a9414155c370dfc3afd8784c347317f40a648e
1 /*
2 hexium_orion.c - v4l2 driver for the Hexium Orion frame grabber cards
4 Visit http://www.mihu.de/linux/saa7146/ and follow the link
5 to "hexium" for further details about this card.
7 Copyright (C) 2003 Michael Hunold <michael@mihu.de>
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #define DEBUG_VARIABLE debug
26 #include <media/saa7146_vv.h>
28 static int debug = 0;
29 module_param(debug, int, 0);
30 MODULE_PARM_DESC(debug, "debug verbosity");
32 /* global variables */
33 static int hexium_num = 0;
35 #define HEXIUM_HV_PCI6_ORION 1
36 #define HEXIUM_ORION_1SVHS_3BNC 2
37 #define HEXIUM_ORION_4BNC 3
39 #define HEXIUM_INPUTS 9
40 static struct v4l2_input hexium_inputs[HEXIUM_INPUTS] = {
41 { 0, "CVBS 1", V4L2_INPUT_TYPE_CAMERA, 2, 0, V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 0 },
42 { 1, "CVBS 2", V4L2_INPUT_TYPE_CAMERA, 2, 0, V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 0 },
43 { 2, "CVBS 3", V4L2_INPUT_TYPE_CAMERA, 2, 0, V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 0 },
44 { 3, "CVBS 4", V4L2_INPUT_TYPE_CAMERA, 2, 0, V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 0 },
45 { 4, "CVBS 5", V4L2_INPUT_TYPE_CAMERA, 2, 0, V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 0 },
46 { 5, "CVBS 6", V4L2_INPUT_TYPE_CAMERA, 2, 0, V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 0 },
47 { 6, "Y/C 1", V4L2_INPUT_TYPE_CAMERA, 2, 0, V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 0 },
48 { 7, "Y/C 2", V4L2_INPUT_TYPE_CAMERA, 2, 0, V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 0 },
49 { 8, "Y/C 3", V4L2_INPUT_TYPE_CAMERA, 2, 0, V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 0 },
52 #define HEXIUM_AUDIOS 0
54 struct hexium_data
56 s8 adr;
57 u8 byte;
60 static struct saa7146_extension_ioctls ioctls[] = {
61 { VIDIOC_G_INPUT, SAA7146_EXCLUSIVE },
62 { VIDIOC_S_INPUT, SAA7146_EXCLUSIVE },
63 { VIDIOC_ENUMINPUT, SAA7146_EXCLUSIVE },
64 { VIDIOC_S_STD, SAA7146_AFTER },
65 { 0, 0 }
68 struct hexium
70 int type;
71 struct video_device *video_dev;
72 struct i2c_adapter i2c_adapter;
74 int cur_input; /* current input */
77 /* Philips SAA7110 decoder default registers */
78 static u8 hexium_saa7110[53]={
79 /*00*/ 0x4C,0x3C,0x0D,0xEF,0xBD,0xF0,0x00,0x00,
80 /*08*/ 0xF8,0xF8,0x60,0x60,0x40,0x86,0x18,0x90,
81 /*10*/ 0x00,0x2C,0x40,0x46,0x42,0x1A,0xFF,0xDA,
82 /*18*/ 0xF0,0x8B,0x00,0x00,0x00,0x00,0x00,0x00,
83 /*20*/ 0xD9,0x17,0x40,0x41,0x80,0x41,0x80,0x4F,
84 /*28*/ 0xFE,0x01,0x0F,0x0F,0x03,0x01,0x81,0x03,
85 /*30*/ 0x44,0x75,0x01,0x8C,0x03
88 static struct {
89 struct hexium_data data[8];
90 } hexium_input_select[] = {
92 { /* cvbs 1 */
93 { 0x06, 0x00 },
94 { 0x20, 0xD9 },
95 { 0x21, 0x17 }, // 0x16,
96 { 0x22, 0x40 },
97 { 0x2C, 0x03 },
98 { 0x30, 0x44 },
99 { 0x31, 0x75 }, // ??
100 { 0x21, 0x16 }, // 0x03,
102 }, {
103 { /* cvbs 2 */
104 { 0x06, 0x00 },
105 { 0x20, 0x78 },
106 { 0x21, 0x07 }, // 0x03,
107 { 0x22, 0xD2 },
108 { 0x2C, 0x83 },
109 { 0x30, 0x60 },
110 { 0x31, 0xB5 }, // ?
111 { 0x21, 0x03 },
113 }, {
114 { /* cvbs 3 */
115 { 0x06, 0x00 },
116 { 0x20, 0xBA },
117 { 0x21, 0x07 }, // 0x05,
118 { 0x22, 0x91 },
119 { 0x2C, 0x03 },
120 { 0x30, 0x60 },
121 { 0x31, 0xB5 }, // ??
122 { 0x21, 0x05 }, // 0x03,
124 }, {
125 { /* cvbs 4 */
126 { 0x06, 0x00 },
127 { 0x20, 0xD8 },
128 { 0x21, 0x17 }, // 0x16,
129 { 0x22, 0x40 },
130 { 0x2C, 0x03 },
131 { 0x30, 0x44 },
132 { 0x31, 0x75 }, // ??
133 { 0x21, 0x16 }, // 0x03,
135 }, {
136 { /* cvbs 5 */
137 { 0x06, 0x00 },
138 { 0x20, 0xB8 },
139 { 0x21, 0x07 }, // 0x05,
140 { 0x22, 0x91 },
141 { 0x2C, 0x03 },
142 { 0x30, 0x60 },
143 { 0x31, 0xB5 }, // ??
144 { 0x21, 0x05 }, // 0x03,
146 }, {
147 { /* cvbs 6 */
148 { 0x06, 0x00 },
149 { 0x20, 0x7C },
150 { 0x21, 0x07 }, // 0x03
151 { 0x22, 0xD2 },
152 { 0x2C, 0x83 },
153 { 0x30, 0x60 },
154 { 0x31, 0xB5 }, // ??
155 { 0x21, 0x03 },
157 }, {
158 { /* y/c 1 */
159 { 0x06, 0x80 },
160 { 0x20, 0x59 },
161 { 0x21, 0x17 },
162 { 0x22, 0x42 },
163 { 0x2C, 0xA3 },
164 { 0x30, 0x44 },
165 { 0x31, 0x75 },
166 { 0x21, 0x12 },
168 }, {
169 { /* y/c 2 */
170 { 0x06, 0x80 },
171 { 0x20, 0x9A },
172 { 0x21, 0x17 },
173 { 0x22, 0xB1 },
174 { 0x2C, 0x13 },
175 { 0x30, 0x60 },
176 { 0x31, 0xB5 },
177 { 0x21, 0x14 },
179 }, {
180 { /* y/c 3 */
181 { 0x06, 0x80 },
182 { 0x20, 0x3C },
183 { 0x21, 0x27 },
184 { 0x22, 0xC1 },
185 { 0x2C, 0x23 },
186 { 0x30, 0x44 },
187 { 0x31, 0x75 },
188 { 0x21, 0x21 },
193 static struct saa7146_standard hexium_standards[] = {
195 .name = "PAL", .id = V4L2_STD_PAL,
196 .v_offset = 16, .v_field = 288,
197 .h_offset = 1, .h_pixels = 680,
198 .v_max_out = 576, .h_max_out = 768,
199 }, {
200 .name = "NTSC", .id = V4L2_STD_NTSC,
201 .v_offset = 16, .v_field = 240,
202 .h_offset = 1, .h_pixels = 640,
203 .v_max_out = 480, .h_max_out = 640,
204 }, {
205 .name = "SECAM", .id = V4L2_STD_SECAM,
206 .v_offset = 16, .v_field = 288,
207 .h_offset = 1, .h_pixels = 720,
208 .v_max_out = 576, .h_max_out = 768,
212 /* this is only called for old HV-PCI6/Orion cards
213 without eeprom */
214 static int hexium_probe(struct saa7146_dev *dev)
216 struct hexium *hexium = NULL;
217 union i2c_smbus_data data;
218 int err = 0;
220 DEB_EE((".\n"));
222 /* there are no hexium orion cards with revision 0 saa7146s */
223 if (0 == dev->revision) {
224 return -EFAULT;
227 hexium = (struct hexium *) kmalloc(sizeof(struct hexium), GFP_KERNEL);
228 if (NULL == hexium) {
229 printk("hexium_orion: hexium_probe: not enough kernel memory.\n");
230 return -ENOMEM;
232 memset(hexium, 0x0, sizeof(struct hexium));
234 /* enable i2c-port pins */
235 saa7146_write(dev, MC1, (MASK_08 | MASK_24 | MASK_10 | MASK_26));
237 saa7146_write(dev, DD1_INIT, 0x01000100);
238 saa7146_write(dev, DD1_STREAM_B, 0x00000000);
239 saa7146_write(dev, MC2, (MASK_09 | MASK_25 | MASK_10 | MASK_26));
241 hexium->i2c_adapter = (struct i2c_adapter) {
242 .class = I2C_CLASS_TV_ANALOG,
243 .name = "hexium orion",
245 saa7146_i2c_adapter_prepare(dev, &hexium->i2c_adapter, SAA7146_I2C_BUS_BIT_RATE_480);
246 if (i2c_add_adapter(&hexium->i2c_adapter) < 0) {
247 DEB_S(("cannot register i2c-device. skipping.\n"));
248 kfree(hexium);
249 return -EFAULT;
252 /* set SAA7110 control GPIO 0 */
253 saa7146_setgpio(dev, 0, SAA7146_GPIO_OUTHI);
254 /* set HWControl GPIO number 2 */
255 saa7146_setgpio(dev, 2, SAA7146_GPIO_OUTHI);
257 mdelay(10);
259 /* detect newer Hexium Orion cards by subsystem ids */
260 if (0x17c8 == dev->pci->subsystem_vendor && 0x0101 == dev->pci->subsystem_device) {
261 printk("hexium_orion: device is a Hexium Orion w/ 1 SVHS + 3 BNC inputs.\n");
262 /* we store the pointer in our private data field */
263 dev->ext_priv = hexium;
264 hexium->type = HEXIUM_ORION_1SVHS_3BNC;
265 return 0;
268 if (0x17c8 == dev->pci->subsystem_vendor && 0x2101 == dev->pci->subsystem_device) {
269 printk("hexium_orion: device is a Hexium Orion w/ 4 BNC inputs.\n");
270 /* we store the pointer in our private data field */
271 dev->ext_priv = hexium;
272 hexium->type = HEXIUM_ORION_4BNC;
273 return 0;
276 /* check if this is an old hexium Orion card by looking at
277 a saa7110 at address 0x4e */
278 if (0 == (err = i2c_smbus_xfer(&hexium->i2c_adapter, 0x4e, 0, I2C_SMBUS_READ, 0x00, I2C_SMBUS_BYTE_DATA, &data))) {
279 printk("hexium_orion: device is a Hexium HV-PCI6/Orion (old).\n");
280 /* we store the pointer in our private data field */
281 dev->ext_priv = hexium;
282 hexium->type = HEXIUM_HV_PCI6_ORION;
283 return 0;
286 i2c_del_adapter(&hexium->i2c_adapter);
287 kfree(hexium);
288 return -EFAULT;
291 /* bring hardware to a sane state. this has to be done, just in case someone
292 wants to capture from this device before it has been properly initialized.
293 the capture engine would badly fail, because no valid signal arrives on the
294 saa7146, thus leading to timeouts and stuff. */
295 static int hexium_init_done(struct saa7146_dev *dev)
297 struct hexium *hexium = (struct hexium *) dev->ext_priv;
298 union i2c_smbus_data data;
299 int i = 0;
301 DEB_D(("hexium_init_done called.\n"));
303 /* initialize the helper ics to useful values */
304 for (i = 0; i < sizeof(hexium_saa7110); i++) {
305 data.byte = hexium_saa7110[i];
306 if (0 != i2c_smbus_xfer(&hexium->i2c_adapter, 0x4e, 0, I2C_SMBUS_WRITE, i, I2C_SMBUS_BYTE_DATA, &data)) {
307 printk("hexium_orion: failed for address 0x%02x\n", i);
311 return 0;
314 static int hexium_set_input(struct hexium *hexium, int input)
316 union i2c_smbus_data data;
317 int i = 0;
319 DEB_D((".\n"));
321 for (i = 0; i < 8; i++) {
322 int adr = hexium_input_select[input].data[i].adr;
323 data.byte = hexium_input_select[input].data[i].byte;
324 if (0 != i2c_smbus_xfer(&hexium->i2c_adapter, 0x4e, 0, I2C_SMBUS_WRITE, adr, I2C_SMBUS_BYTE_DATA, &data)) {
325 return -1;
327 printk("%d: 0x%02x => 0x%02x\n",input, adr,data.byte);
330 return 0;
333 static struct saa7146_ext_vv vv_data;
335 /* this function only gets called when the probing was successful */
336 static int hexium_attach(struct saa7146_dev *dev, struct saa7146_pci_extension_data *info)
338 struct hexium *hexium = (struct hexium *) dev->ext_priv;
340 DEB_EE((".\n"));
342 saa7146_vv_init(dev, &vv_data);
343 if (0 != saa7146_register_device(&hexium->video_dev, dev, "hexium orion", VFL_TYPE_GRABBER)) {
344 printk("hexium_orion: cannot register capture v4l2 device. skipping.\n");
345 return -1;
348 printk("hexium_orion: found 'hexium orion' frame grabber-%d.\n", hexium_num);
349 hexium_num++;
351 /* the rest */
352 hexium->cur_input = 0;
353 hexium_init_done(dev);
355 return 0;
358 static int hexium_detach(struct saa7146_dev *dev)
360 struct hexium *hexium = (struct hexium *) dev->ext_priv;
362 DEB_EE(("dev:%p\n", dev));
364 saa7146_unregister_device(&hexium->video_dev, dev);
365 saa7146_vv_release(dev);
367 hexium_num--;
369 i2c_del_adapter(&hexium->i2c_adapter);
370 kfree(hexium);
371 return 0;
374 static int hexium_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg)
376 struct saa7146_dev *dev = fh->dev;
377 struct hexium *hexium = (struct hexium *) dev->ext_priv;
379 struct saa7146_vv *vv = dev->vv_data;
381 switch (cmd) {
382 case VIDIOC_ENUMINPUT:
384 struct v4l2_input *i = arg;
385 DEB_EE(("VIDIOC_ENUMINPUT %d.\n", i->index));
387 if (i->index < 0 || i->index >= HEXIUM_INPUTS) {
388 return -EINVAL;
391 memcpy(i, &hexium_inputs[i->index], sizeof(struct v4l2_input));
393 DEB_D(("v4l2_ioctl: VIDIOC_ENUMINPUT %d.\n", i->index));
394 return 0;
396 case VIDIOC_G_INPUT:
398 int *input = (int *) arg;
399 *input = hexium->cur_input;
401 DEB_D(("VIDIOC_G_INPUT: %d\n", *input));
402 return 0;
404 case VIDIOC_S_INPUT:
406 int input = *(int *) arg;
408 if (input < 0 || input >= HEXIUM_INPUTS) {
409 return -EINVAL;
412 hexium->cur_input = input;
413 hexium_set_input(hexium, input);
415 return 0;
417 default:
419 DEB_D(("hexium_ioctl() does not handle this ioctl.\n"));
421 return -ENOIOCTLCMD;
423 return 0;
426 static int std_callback(struct saa7146_dev *dev, struct saa7146_standard *std)
428 return 0;
431 static struct saa7146_extension extension;
433 static struct saa7146_pci_extension_data hexium_hv_pci6 = {
434 .ext_priv = "Hexium HV-PCI6 / Orion",
435 .ext = &extension,
438 static struct saa7146_pci_extension_data hexium_orion_1svhs_3bnc = {
439 .ext_priv = "Hexium HV-PCI6 / Orion (1 SVHS/3 BNC)",
440 .ext = &extension,
443 static struct saa7146_pci_extension_data hexium_orion_4bnc = {
444 .ext_priv = "Hexium HV-PCI6 / Orion (4 BNC)",
445 .ext = &extension,
448 static struct pci_device_id pci_tbl[] = {
450 .vendor = PCI_VENDOR_ID_PHILIPS,
451 .device = PCI_DEVICE_ID_PHILIPS_SAA7146,
452 .subvendor = 0x0000,
453 .subdevice = 0x0000,
454 .driver_data = (unsigned long) &hexium_hv_pci6,
457 .vendor = PCI_VENDOR_ID_PHILIPS,
458 .device = PCI_DEVICE_ID_PHILIPS_SAA7146,
459 .subvendor = 0x17c8,
460 .subdevice = 0x0101,
461 .driver_data = (unsigned long) &hexium_orion_1svhs_3bnc,
464 .vendor = PCI_VENDOR_ID_PHILIPS,
465 .device = PCI_DEVICE_ID_PHILIPS_SAA7146,
466 .subvendor = 0x17c8,
467 .subdevice = 0x2101,
468 .driver_data = (unsigned long) &hexium_orion_4bnc,
471 .vendor = 0,
475 MODULE_DEVICE_TABLE(pci, pci_tbl);
477 static struct saa7146_ext_vv vv_data = {
478 .inputs = HEXIUM_INPUTS,
479 .capabilities = 0,
480 .stds = &hexium_standards[0],
481 .num_stds = sizeof(hexium_standards) / sizeof(struct saa7146_standard),
482 .std_callback = &std_callback,
483 .ioctls = &ioctls[0],
484 .ioctl = hexium_ioctl,
487 static struct saa7146_extension extension = {
488 .name = "hexium HV-PCI6/Orion",
489 .flags = 0, // SAA7146_USE_I2C_IRQ,
491 .pci_tbl = &pci_tbl[0],
492 .module = THIS_MODULE,
494 .probe = hexium_probe,
495 .attach = hexium_attach,
496 .detach = hexium_detach,
498 .irq_mask = 0,
499 .irq_func = NULL,
502 static int __init hexium_init_module(void)
504 if (0 != saa7146_register_extension(&extension)) {
505 DEB_S(("failed to register extension.\n"));
506 return -ENODEV;
509 return 0;
512 static void __exit hexium_cleanup_module(void)
514 saa7146_unregister_extension(&extension);
517 module_init(hexium_init_module);
518 module_exit(hexium_cleanup_module);
520 MODULE_DESCRIPTION("video4linux-2 driver for Hexium Orion frame grabber cards");
521 MODULE_AUTHOR("Michael Hunold <michael@mihu.de>");
522 MODULE_LICENSE("GPL");