[XFRM]: skb_cow_data() does not set proper owner for new skbs.
[linux-2.6/verdex.git] / drivers / media / video / saa7134 / saa7134-empress.c
blobfa1357336907cd6df71614e39f61d133b8428607
1 /*
2 * $Id: saa7134-empress.c,v 1.10 2005/02/03 10:24:33 kraxel Exp $
4 * (c) 2004 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include <linux/init.h>
22 #include <linux/list.h>
23 #include <linux/module.h>
24 #include <linux/moduleparam.h>
25 #include <linux/kernel.h>
26 #include <linux/slab.h>
27 #include <linux/delay.h>
29 #include "saa7134-reg.h"
30 #include "saa7134.h"
32 #include <media/saa6752hs.h>
34 /* ------------------------------------------------------------------ */
36 MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
37 MODULE_LICENSE("GPL");
39 static unsigned int empress_nr[] = {[0 ... (SAA7134_MAXBOARDS - 1)] = UNSET };
40 module_param_array(empress_nr, int, NULL, 0444);
41 MODULE_PARM_DESC(empress_nr,"ts device number");
43 static unsigned int debug = 0;
44 module_param(debug, int, 0644);
45 MODULE_PARM_DESC(debug,"enable debug messages");
47 #define dprintk(fmt, arg...) if (debug) \
48 printk(KERN_DEBUG "%s/empress: " fmt, dev->name , ## arg)
50 /* ------------------------------------------------------------------ */
52 static void ts_reset_encoder(struct saa7134_dev* dev)
54 if (!dev->empress_started)
55 return;
57 saa_writeb(SAA7134_SPECIAL_MODE, 0x00);
58 msleep(10);
59 saa_writeb(SAA7134_SPECIAL_MODE, 0x01);
60 msleep(100);
61 dev->empress_started = 0;
64 static int ts_init_encoder(struct saa7134_dev* dev)
66 ts_reset_encoder(dev);
67 saa7134_i2c_call_clients(dev, VIDIOC_S_MPEGCOMP, NULL);
68 dev->empress_started = 1;
69 return 0;
72 /* ------------------------------------------------------------------ */
74 static int ts_open(struct inode *inode, struct file *file)
76 int minor = iminor(inode);
77 struct saa7134_dev *h,*dev = NULL;
78 struct list_head *list;
79 int err;
81 list_for_each(list,&saa7134_devlist) {
82 h = list_entry(list, struct saa7134_dev, devlist);
83 if (h->empress_dev && h->empress_dev->minor == minor)
84 dev = h;
86 if (NULL == dev)
87 return -ENODEV;
89 dprintk("open minor=%d\n",minor);
90 err = -EBUSY;
91 if (down_trylock(&dev->empress_tsq.lock))
92 goto done;
93 if (dev->empress_users)
94 goto done_up;
96 dev->empress_users++;
97 file->private_data = dev;
98 err = 0;
100 done_up:
101 up(&dev->empress_tsq.lock);
102 done:
103 return err;
106 static int ts_release(struct inode *inode, struct file *file)
108 struct saa7134_dev *dev = file->private_data;
110 if (dev->empress_tsq.streaming)
111 videobuf_streamoff(&dev->empress_tsq);
112 down(&dev->empress_tsq.lock);
113 if (dev->empress_tsq.reading)
114 videobuf_read_stop(&dev->empress_tsq);
115 videobuf_mmap_free(&dev->empress_tsq);
116 dev->empress_users--;
118 /* stop the encoder */
119 ts_reset_encoder(dev);
121 up(&dev->empress_tsq.lock);
122 return 0;
125 static ssize_t
126 ts_read(struct file *file, char __user *data, size_t count, loff_t *ppos)
128 struct saa7134_dev *dev = file->private_data;
130 if (!dev->empress_started)
131 ts_init_encoder(dev);
133 return videobuf_read_stream(&dev->empress_tsq,
134 data, count, ppos, 0,
135 file->f_flags & O_NONBLOCK);
138 static unsigned int
139 ts_poll(struct file *file, struct poll_table_struct *wait)
141 struct saa7134_dev *dev = file->private_data;
143 return videobuf_poll_stream(file, &dev->empress_tsq, wait);
147 static int
148 ts_mmap(struct file *file, struct vm_area_struct * vma)
150 struct saa7134_dev *dev = file->private_data;
152 return videobuf_mmap_mapper(&dev->empress_tsq, vma);
156 * This function is _not_ called directly, but from
157 * video_generic_ioctl (and maybe others). userspace
158 * copying is done already, arg is a kernel pointer.
160 static int ts_do_ioctl(struct inode *inode, struct file *file,
161 unsigned int cmd, void *arg)
163 struct saa7134_dev *dev = file->private_data;
165 if (debug > 1)
166 saa7134_print_ioctl(dev->name,cmd);
167 switch (cmd) {
168 case VIDIOC_QUERYCAP:
170 struct v4l2_capability *cap = arg;
172 memset(cap,0,sizeof(*cap));
173 strcpy(cap->driver, "saa7134");
174 strlcpy(cap->card, saa7134_boards[dev->board].name,
175 sizeof(cap->card));
176 sprintf(cap->bus_info,"PCI:%s",pci_name(dev->pci));
177 cap->version = SAA7134_VERSION_CODE;
178 cap->capabilities =
179 V4L2_CAP_VIDEO_CAPTURE |
180 V4L2_CAP_READWRITE |
181 V4L2_CAP_STREAMING;
182 return 0;
185 /* --- input switching --------------------------------------- */
186 case VIDIOC_ENUMINPUT:
188 struct v4l2_input *i = arg;
190 if (i->index != 0)
191 return -EINVAL;
192 i->type = V4L2_INPUT_TYPE_CAMERA;
193 strcpy(i->name,"CCIR656");
194 return 0;
196 case VIDIOC_G_INPUT:
198 int *i = arg;
199 *i = 0;
200 return 0;
202 case VIDIOC_S_INPUT:
204 int *i = arg;
206 if (*i != 0)
207 return -EINVAL;
208 return 0;
210 /* --- capture ioctls ---------------------------------------- */
212 case VIDIOC_ENUM_FMT:
214 struct v4l2_fmtdesc *f = arg;
215 int index;
217 index = f->index;
218 if (index != 0)
219 return -EINVAL;
221 memset(f,0,sizeof(*f));
222 f->index = index;
223 strlcpy(f->description, "MPEG TS", sizeof(f->description));
224 f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
225 f->pixelformat = V4L2_PIX_FMT_MPEG;
226 return 0;
229 case VIDIOC_G_FMT:
231 struct v4l2_format *f = arg;
233 memset(f,0,sizeof(*f));
234 f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
236 saa7134_i2c_call_clients(dev, cmd, arg);
237 f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG;
238 f->fmt.pix.sizeimage = TS_PACKET_SIZE * dev->ts.nr_packets;
239 return 0;
242 case VIDIOC_S_FMT:
244 struct v4l2_format *f = arg;
246 if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
247 return -EINVAL;
249 saa7134_i2c_call_clients(dev, cmd, arg);
250 f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG;
251 f->fmt.pix.sizeimage = TS_PACKET_SIZE* dev->ts.nr_packets;
252 return 0;
255 case VIDIOC_REQBUFS:
256 return videobuf_reqbufs(&dev->empress_tsq,arg);
258 case VIDIOC_QUERYBUF:
259 return videobuf_querybuf(&dev->empress_tsq,arg);
261 case VIDIOC_QBUF:
262 return videobuf_qbuf(&dev->empress_tsq,arg);
264 case VIDIOC_DQBUF:
265 return videobuf_dqbuf(&dev->empress_tsq,arg,
266 file->f_flags & O_NONBLOCK);
268 case VIDIOC_STREAMON:
269 return videobuf_streamon(&dev->empress_tsq);
271 case VIDIOC_STREAMOFF:
272 return videobuf_streamoff(&dev->empress_tsq);
274 case VIDIOC_QUERYCTRL:
275 case VIDIOC_G_CTRL:
276 case VIDIOC_S_CTRL:
277 return saa7134_common_ioctl(dev, cmd, arg);
279 case VIDIOC_S_MPEGCOMP:
280 saa7134_i2c_call_clients(dev, VIDIOC_S_MPEGCOMP, arg);
281 ts_init_encoder(dev);
282 return 0;
283 case VIDIOC_G_MPEGCOMP:
284 saa7134_i2c_call_clients(dev, VIDIOC_G_MPEGCOMP, arg);
285 return 0;
287 default:
288 return -ENOIOCTLCMD;
290 return 0;
293 static int ts_ioctl(struct inode *inode, struct file *file,
294 unsigned int cmd, unsigned long arg)
296 return video_usercopy(inode, file, cmd, arg, ts_do_ioctl);
299 static struct file_operations ts_fops =
301 .owner = THIS_MODULE,
302 .open = ts_open,
303 .release = ts_release,
304 .read = ts_read,
305 .poll = ts_poll,
306 .mmap = ts_mmap,
307 .ioctl = ts_ioctl,
308 .llseek = no_llseek,
311 /* ----------------------------------------------------------- */
313 static struct video_device saa7134_empress_template =
315 .name = "saa7134-empress",
316 .type = 0 /* FIXME */,
317 .type2 = 0 /* FIXME */,
318 .hardware = 0,
319 .fops = &ts_fops,
320 .minor = -1,
323 static void empress_signal_update(void* data)
325 struct saa7134_dev* dev = (struct saa7134_dev*) data;
327 if (dev->nosignal) {
328 dprintk("no video signal\n");
329 ts_reset_encoder(dev);
330 } else {
331 dprintk("video signal acquired\n");
332 if (dev->empress_users)
333 ts_init_encoder(dev);
337 static void empress_signal_change(struct saa7134_dev *dev)
339 schedule_work(&dev->empress_workqueue);
343 static int empress_init(struct saa7134_dev *dev)
345 int err;
347 dprintk("%s: %s\n",dev->name,__FUNCTION__);
348 dev->empress_dev = video_device_alloc();
349 if (NULL == dev->empress_dev)
350 return -ENOMEM;
351 *(dev->empress_dev) = saa7134_empress_template;
352 dev->empress_dev->dev = &dev->pci->dev;
353 dev->empress_dev->release = video_device_release;
354 snprintf(dev->empress_dev->name, sizeof(dev->empress_dev->name),
355 "%s empress (%s)", dev->name,
356 saa7134_boards[dev->board].name);
358 INIT_WORK(&dev->empress_workqueue, empress_signal_update, (void*) dev);
360 err = video_register_device(dev->empress_dev,VFL_TYPE_GRABBER,
361 empress_nr[dev->nr]);
362 if (err < 0) {
363 printk(KERN_INFO "%s: can't register video device\n",
364 dev->name);
365 video_device_release(dev->empress_dev);
366 dev->empress_dev = NULL;
367 return err;
369 printk(KERN_INFO "%s: registered device video%d [mpeg]\n",
370 dev->name,dev->empress_dev->minor & 0x1f);
372 videobuf_queue_init(&dev->empress_tsq, &saa7134_ts_qops,
373 dev->pci, &dev->slock,
374 V4L2_BUF_TYPE_VIDEO_CAPTURE,
375 V4L2_FIELD_ALTERNATE,
376 sizeof(struct saa7134_buf),
377 dev);
379 empress_signal_update(dev);
380 return 0;
383 static int empress_fini(struct saa7134_dev *dev)
385 dprintk("%s: %s\n",dev->name,__FUNCTION__);
387 if (NULL == dev->empress_dev)
388 return 0;
389 flush_scheduled_work();
390 video_unregister_device(dev->empress_dev);
391 dev->empress_dev = NULL;
392 return 0;
395 static struct saa7134_mpeg_ops empress_ops = {
396 .type = SAA7134_MPEG_EMPRESS,
397 .init = empress_init,
398 .fini = empress_fini,
399 .signal_change = empress_signal_change,
402 static int __init empress_register(void)
404 return saa7134_ts_register(&empress_ops);
407 static void __exit empress_unregister(void)
409 saa7134_ts_unregister(&empress_ops);
412 module_init(empress_register);
413 module_exit(empress_unregister);
415 /* ----------------------------------------------------------- */
417 * Local variables:
418 * c-basic-offset: 8
419 * End: